From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A51C2D640F; Thu, 28 Aug 2025 07:24:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756365870; cv=none; b=gt/WgYvxKS7bCgEvRifkHP0zUbXENKHmPUskZrsH81k+Zg+zRYCRt8CX/cUJkSgM15u9yCbMIXGdULxGVdF18UnYAS0kI/5vpdf4BTPRuEnWjq8tHRL77Kfm7UuVlQIaCBk4Q21uK5/Y6orILfqHO0Lie4Nq9EaNZxJU73uDSLY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756365870; c=relaxed/simple; bh=kQG38cYM4JRE1WeFJ56W/++Qh87E6kimOZt0OksguyY=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:Subject:From:To: References:In-Reply-To; b=ETMqAV8g4JXSrgeTE5Ht3hh0CcsGLN75iMbIhjJDGgExnhiA7K/sFkE4uUmXtPnexyQ8jTdAtx3gUuFJyN63h4BOOypx2dT8LXfhfMpC+KjiTScpo5OT0tH1XMbKbJZp7FAjY4p4o8M/Zxh7ZRid264R5Z/0k1Drqa5gjgwLJEs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mezRO6x0; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mezRO6x0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6982C4CEEB; Thu, 28 Aug 2025 07:24:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756365868; bh=kQG38cYM4JRE1WeFJ56W/++Qh87E6kimOZt0OksguyY=; h=Date:Cc:Subject:From:To:References:In-Reply-To:From; b=mezRO6x0xwzQ0vmC6QNKbYumTfS+3CrobdOo9gPvJ74sShwJrBkTPJdXl+egE+Bfx ju4q4nmU1TkaSjdLR0rXxw3cVbVFA48SbB3MOuiIomFfCnwTN7kIIPffJFPqLqozYU RETK1ALs/EmzE6iWB96RLWMO9f69VnaqUOQ+BobASqskVQI1W6V/gYW2V2t9HThsfC wreAGw4VATkziaoU8ahLKELTUPRDrlzV6ZwBYFDXDPle0miWtNJWTOSR19RfpPf3l9 syFsfKeDHzf7CQzx3aFL8HSVOgYNVSP5wVkkXaLXk3OPsQIwbbcDYQVL5A5+Hwybzf 4OxGxBugduf3A== Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Thu, 28 Aug 2025 09:24:24 +0200 Message-Id: Cc: "Jens Axboe" , "Caleb Sander Mateos" , "Miguel Ojeda" , "Arnd Bergmann" , "Greg Kroah-Hartman" , , , Subject: Re: [RFC PATCH v3 3/5] rust: io_uring: introduce rust abstraction for io-uring cmd From: "Benno Lossin" To: "Daniel Almeida" , "Sidong Yang" X-Mailer: aerc 0.20.1 References: <20250822125555.8620-1-sidong.yang@furiosa.ai> <20250822125555.8620-4-sidong.yang@furiosa.ai> <713667D6-8001-408D-819D-E9326FC3AFD5@collabora.com> In-Reply-To: <713667D6-8001-408D-819D-E9326FC3AFD5@collabora.com> On Wed Aug 27, 2025 at 10:41 PM CEST, Daniel Almeida wrote: >> On 22 Aug 2025, at 09:55, Sidong Yang wrote: >> + } >> + >> + let mut out: MaybeUninit =3D MaybeUninit::uninit(); >> + let ptr =3D &raw mut inner.pdu as *const c_void; >> + >> + // SAFETY: >> + // * The `ptr` is valid pointer from `self.inner` that is guara= nteed by type invariant. >> + // * The `out` is valid pointer that points `T` which impls `Fr= omBytes` and checked >> + // size of `T` is smaller than pdu size. >> + unsafe { >> + core::ptr::copy_nonoverlapping(ptr, out.as_mut_ptr().cast::= (), len); > > I don=E2=80=99t think you need to manually specify c_void here. In fact using `c_void` as the pointee type is wrong, since it's a ZST and thus this call copies no bytes whatsoever. > Benno, can=E2=80=99t we use core::mem::zeroed() or something like that to= avoid this unsafe? > > The input was zeroed in prep() and the output can just be a zeroed T on t= he > stack, unless I missed something? Hmm I'm not sure I follow, I don't think that `mem::zeroed` will help (it also is an unsafe function). We have a helper in flight that might be useful in this case: https://lore.kernel.org/all/20250826-nova_firmware-v2-1-93566252fe3a@nv= idia.com --- Cheers, Benno