From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (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 8E5E427CCE0 for ; Sat, 9 Aug 2025 12:53:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754744021; cv=none; b=VeTe7wv3t1yzXpg+1DGff7MIPwaAgLaCR5ArXYx89VlLfaZ46eGea86O3WNFp6KToWjCnp9AF63qFIKWZy/6XUpEchpSOuKH5O8GlKnaajSJ8MsNTKpAUZMCGRzMfyY3JnZbRm0ojeRSBn5pgeHhEpS9sgw84C1PXfZTu/5XQmc= 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.41 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-f41.google.com with SMTP id 98e67ed59e1d1-31f325c1bc1so2723127a91.1 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=V+D7aZwCcPdP97ntrZqONd6af86jx99mT1jdU3ACQxzYcyj72XG99UZS3zR1tQ7WP+ 4dVuJn8HpnY7ZlND0fNMN1wJl4S1uJArelYZYgJ/kW/bLfeImax0s8AbbjrdPece/cTV xQXsDKZVmW9gdMn5QFQrSwSbdnrKgWmSktXCrI9dGR+MK4pQthY1sUgGwOD6OI97D72m LMVU9hhLPptksNw45qJ/5MJJ27J4JU7B1HCNQcHRf+sIkPbHK/Vl9Cw3zf4OpDEZbCn5 Q5nNwI4X5iZVUuzJo7/YUzUuI6JymWDitx8SRUxXEq0d+xQfM/ydV7DlBn2ItCajEL2w yxog== X-Forwarded-Encrypted: i=1; AJvYcCW17gLjsoGt4yfkX9omBRSlApcTTnautXtlHnkthXUrp6D0sq1asF4Tanu7wEFH8KmpsjC+ah+k+j+pewE=@vger.kernel.org X-Gm-Message-State: AOJu0Yw/EKdFemDXHIeGYTEZiTh4BkzdF3q0SRPbqH8PFCVMf35Hkvfi UreBr1UYS3May7h+Yd+7TUZUj/oX4AJd2XJiJ1Oz/f33TSIwoGUfRWgp4r9ni9ubSHE= X-Gm-Gg: ASbGncu3dYnjXsjMYuWIWc5J42mx3v30O90lecn1Vfrcm+oJPIaR24VArlu1c1wff0J 9Plrs9do1JCVg5VnclJkwbE68hg9owIa/RXN91IV6wYZLp0PKn5kcZOh/prL52Sw75KhtFhTU2+ jyX1wx+zlZeQzgR/wG2nfwmfcqX05v2bgBS6sYLi2Yi7SL5JNJs3SAifWxblAL2f/ktPe9miqiV 9dlApqQUpTfc6aytfrFVwTe6qo9VZSDn0eTilp37nGSP9Aeas4PdT+bmUj25KdTSLpHniiHeN9U ZDbk+QTde4cK4i0bEaOQoPxwiybPEPJtW0aPa24VKoxK5w8npZ9P70+94n6DoKdu1EW6DyHgjdV GefxY44WjAgvVOHdP5kiF1gYjHhw0eFmmeRcgXnl921zEzkJbylrjPbrlli3Yfw== 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: linux-kernel@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