From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 77CE223E354 for ; Sat, 9 Aug 2025 12:53:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754744021; cv=none; b=WKCLpj3V3SWS0MUwftFCqDTCnTBxhx48rObxkI/lB88Z8YO1R+YQ/dTKGYLZnNJS27VyAtuPNRMxccw2HWTTmaz7CmUeXFLnEcvOJSmxEBUVVJ4zfEhcsZUo3DmlBXYYoqpr3qmPbYWUB0JDe81PJe+eLnL0l5X4Kwd8iQVn/0E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754744021; c=relaxed/simple; bh=fx1Rl2XN14tk+BtEc41p90+jXDudqi7LnVoEeN8UTn4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=EYK9X0PiRB3NefNm3XVj+ZdA1IJ4vjtv7V4gU6fde6CufcgkCDYFbtpWXukogYyO/SQ5jErzMSfY0d2QADGp1OhYn6lGbAjT1c+9ze669iytavn06YGXOMtzzuxvdL3mlDUw6t26Ob/CuR4CDB3Ryn9g53aKXa/TZq+2s8gk9+s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=furiosa.ai; spf=none smtp.mailfrom=furiosa.ai; dkim=pass (1024-bit key) header.d=furiosa.ai header.i=@furiosa.ai header.b=fZsbyABi; arc=none smtp.client-ip=209.85.216.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=furiosa.ai Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=furiosa.ai Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=furiosa.ai header.i=@furiosa.ai header.b="fZsbyABi" Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-31effad130bso2409587a91.3 for ; Sat, 09 Aug 2025 05:53:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=furiosa.ai; s=google; t=1754744020; x=1755348820; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=l6ld1uqa+Y0Ptl6MvYRH/7bNpbs5gzVTJqHHdh4KG+0=; b=fZsbyABiD2Vl1ej9G+3ddCDD8ZE1kpI8dtpAlGfM0wr+bXwNcHvbMkgwSitds+Jzy8 p4VoRogEBvnvd0iNuYJ2WphvrvMmF5l0OkRPB9FSnhV39LsdUpmqs1G55mPhWwbnpsjz v6gTKmY+VRgYbkgegD+CtXabuhrp7v2ygbWks= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754744020; x=1755348820; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=l6ld1uqa+Y0Ptl6MvYRH/7bNpbs5gzVTJqHHdh4KG+0=; b=tzwRbbOsgZwrj6dBo2897r0gEJmQ8BKIK9FCnDNj7buOLBR7CCqVoB5kouWn4pYv35 GPa78YHpkJ0Y2a6yjAqO6t+pn00RmhWPtn/km2drjBNhM3JNal/XyRBuxnau84RSZ2on Z4BqwDTm2zTDkXz3moUE0LtPBCoMbIg+K+mKWHzqamCKmqe1ZhBK0StNRzrnMub6yrpc EXLfqJ16MmkyT9OjHlH+/JwhTqya1XiUOaFj/L98NXhNUy2LLkGYf3f2LqNFHcGgMz+/ 9je91gZBCMMLdRlhhVhLR7jB1bEe3oM1XcoIzEGgX1wZgD8Ll4eZMRgRCtHlqwASxW+E sz3A== X-Forwarded-Encrypted: i=1; AJvYcCVvdpS8oDadOSmoqTyZnIhHXWXUVFnHYa8ZXFBNdNGGTkcVR/HYEfY7Jp7e2xKnUpPVlLpuTuYBxev+3ToJlA==@vger.kernel.org X-Gm-Message-State: AOJu0YxQRt1BcP5kkUc7MNhUTuhQVLMxN5DsTmlsTUVO4szsE7PHqqfF wW7mCKgYxct+k6ZyNIIyZGs92a/wKy1ct3lOqTMF08rSOPiobAXPmUXp24EU2OsiKw4= X-Gm-Gg: ASbGncut9R0pWH01DfdWzu6NgSVrZL+g5M8SH8oqwpVfRzybPCoMYiJLqvt6YSUVlBR 1uB+xzl97i03AqyMc6iikJj3pY8riNDmCIHjO+MCwNcuDm7Go6B9jV0i+5sYIw8k1HPBcB3msa9 +Wuh/BmYkdpKz1NZUzVfDFdslV+t7Qgc22Vi58+nTk5hVkk65TnngNTT0FbHW1zSNlJOmxiBIoQ HUjCDOT249V2/5PhK4X+qysFAlMwZr6SGeUyxG1ybmZ8r4ONVOEyoXNARIMOJx5KnSwRuzvs3rZ ph4zAsPQG9GhVXq3feRUHCZtgcGhbt0XCAeccHJQ5cLx1ybtDVcLNOLElzP0vQ1f/iH7UV2meiO V2Zc4lzXN44q3Pef1VkZDvYB9j7ifUVJSGCgCkPuicBXgqXyaUANRy8fO2HAu1w== X-Google-Smtp-Source: AGHT+IGh8dSlzi3tIj0AQRFc46haMuqZOjOj19eAYcc5a4BffBcr0JUb8WW+MLPjBW9qywnxDaMQvA== X-Received: by 2002:a17:90b:17d0:b0:311:ef19:824d with SMTP id 98e67ed59e1d1-321839d39b2mr9575683a91.2.1754744019796; Sat, 09 Aug 2025 05:53:39 -0700 (PDT) Received: from sidongui-MacBookPro.local ([175.195.128.78]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-32161294ee4sm10490104a91.32.2025.08.09.05.53.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Aug 2025 05:53:39 -0700 (PDT) Date: Sat, 9 Aug 2025 21:53:34 +0900 From: Sidong Yang To: Caleb Sander Mateos Cc: Benno Lossin , Daniel Almeida , Miguel Ojeda , Arnd Bergmann , Jens Axboe , Greg Kroah-Hartman , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, io-uring@vger.kernel.org Subject: Re: [RFC PATCH v2 2/4] rust: io_uring: introduce rust abstraction for io-uring cmd Message-ID: References: <20250727150329.27433-1-sidong.yang@furiosa.ai> <20250727150329.27433-3-sidong.yang@furiosa.ai> <949A27C5-1535-48D1-BE7E-F7E366A49A52@collabora.com> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Fri, Aug 08, 2025 at 09:55:22AM -0400, Caleb Sander Mateos wrote: > On Fri, Aug 8, 2025 at 2:56 AM Sidong Yang wrote: > > > > On Wed, Aug 06, 2025 at 03:38:24PM +0200, Benno Lossin wrote: > > > On Wed Aug 6, 2025 at 2:38 PM CEST, Daniel Almeida wrote: > > > > Hi Benno, > > > > > > > >> On 2 Aug 2025, at 07:52, Benno Lossin wrote: > > > >> > > > >> On Fri Aug 1, 2025 at 3:48 PM CEST, Daniel Almeida wrote: > > > >>>> On 27 Jul 2025, at 12:03, Sidong Yang wrote: > > > >>>> + #[inline] > > > >>>> + pub fn pdu(&mut self) -> &mut MaybeUninit<[u8; 32]> { > > > >>> > > > >>> Why MaybeUninit? Also, this is a question for others, but I don´t think > > > >>> that `u8`s can ever be uninitialized as all byte values are valid for `u8`. > > > >> > > > >> `u8` can be uninitialized. Uninitialized doesn't just mean "can take any > > > >> bit pattern", but also "is known to the compiler as being > > > >> uninitialized". The docs of `MaybeUninit` explain it like this: > > > >> > > > >> Moreover, uninitialized memory is special in that it does not have a > > > >> fixed value ("fixed" meaning "it won´t change without being written > > > >> to"). Reading the same uninitialized byte multiple times can give > > > >> different results. > > > >> > > > >> But the return type probably should be `&mut [MaybeUninit; 32]` > > > >> instead. > > > > > > > > > > > > Right, but I guess the question then is why would we ever need to use > > > > MaybeUninit here anyways. > > > > > > > > It's a reference to a C array. Just treat that as initialized. > > > > > > AFAIK C uninitialized memory also is considered uninitialized in Rust. > > > So if this array is not properly initialized on the C side, this would > > > be the correct type. If it is initialized, then just use `&mut [u8; 32]`. > > > > pdu field is memory chunk for driver can use it freely. The driver usually > > saves a private data and read or modify it on the other context. using > > just `&mut [u8;32]` would be simple and easy to use. > > MaybeUninit is correct. The io_uring/uring_cmd layer doesn't > initialize the pdu field. struct io_uring_cmd is overlaid with struct > io_kiocb's cmd field. struct io_kiocb's are allocated using > kmem_cache_alloc(_bulk)() in __io_alloc_req_refill(). io_preinit_req() > is called to initialize each struct io_kiocb but doesn't initialize > the cmd field. As Sidong said, it's uninitialized memory for the > ->uring_cmd() implementation to use however it wants for the duration > of the command. Agreed. Thanks. Thanks, Sidong > > Best, > Caleb