Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5797028rwd; Mon, 5 Jun 2023 08:40:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ50ef4zPrBbQX554eAzCkNyraMoqbbNw/6gFfSzRbZTuGzwGrvp/GsLeWYfI33JzB/dkkoy X-Received: by 2002:aa7:88ca:0:b0:64f:ad7c:70fb with SMTP id k10-20020aa788ca000000b0064fad7c70fbmr17812pff.17.1685979658068; Mon, 05 Jun 2023 08:40:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685979658; cv=none; d=google.com; s=arc-20160816; b=0QvVSJ1RNB3UK1tqLfpRqFwOjw6x/DXDhREZmQxefLUo1KEbMjhWIJBK1MCwfNfbHd eZGFNd+EJPIcFGTTiGx9i8mHlDIkMdy4e7EzdeR7QQONNGOijbxpheht53NpQ67/9doH VultEumN0wl4dSclErTo3E5+cXseHoreI4m4tKg5OmPXMXDVkBnSx0NeJlzC4z7TsdYb AMzuCpvCufJGciKaafHtzTLNynPP+StbdSkTtcMEX9MQs+GvgqcwZXiS0F+Xqm3aXMof 4BghMEj5O8Y4rRZrndAltVq2mayet2lANMa7BAKrhxAcOx3ClsXKHsgkjanDN0JNtapg rw0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:feedback-id :dkim-signature; bh=+eTZJaesQgEddfhUw6/wmzf8jeBxuOms7oai97sQq2k=; b=LQXA8KJ12d0EurjNVJQql+LZpg4i9ChHw2c6LrDjjRoJEl0X6zSrauJr+YmgCz46z2 mqx4CB4FJkpOrIWHMwnysxVar1zNggwxIyRsTMJRd1aavLG9rTfAA98uiqeZi1YIu37R 7erBuLt0kEbTqwNfeTsemU/R1ncwiTXJsupphPMxsvpnYginvpFRz8UHs6e6po282soK 152Z7XvblWiMf+js1Z4lmTtBZbpf16f9mCODyYIHsxVJmHwzXMxKfIs57OTMqJmnSBnZ SVOZfnzHoquddpf+R+BuwOA/kVaQh0zLhGnZ5qBe6o7WVZTOBOtoBT8DBH8fM+MD8ekU Z/pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=NHZtSRQ5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 19-20020a631753000000b005346bd7dee9si5561838pgx.682.2023.06.05.08.40.41; Mon, 05 Jun 2023 08:40:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=NHZtSRQ5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233884AbjFEP0P (ORCPT + 99 others); Mon, 5 Jun 2023 11:26:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233691AbjFEP0N (ORCPT ); Mon, 5 Jun 2023 11:26:13 -0400 Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 424DED2; Mon, 5 Jun 2023 08:26:09 -0700 (PDT) Received: by mail-qv1-xf2f.google.com with SMTP id 6a1803df08f44-6261cb1208eso34291456d6.0; Mon, 05 Jun 2023 08:26:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685978768; x=1688570768; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:from:to:cc:subject:date :message-id:reply-to; bh=+eTZJaesQgEddfhUw6/wmzf8jeBxuOms7oai97sQq2k=; b=NHZtSRQ5uU4okMdEGz/dEAMNO96gXzngsu05M1NcMhqGCbTngUE/ZJ958d1h1OJqv2 N6x/RSWGDm/fMJ86LJpVUB9GJ3jcK+V91MPWbMv3ciUgsk7O+ren3Wiwn0egy0a2kngu zg6pPpIcTw1QdC+r8QIEsdG/lll2wY22o/Hj05VWQM50PSNZQsStuo+VwNVLLGPYCr+g jjLfg9FZGJWiFOQyqtvK6qw2ooZT/3FGcLWKmVHRYU9SWZbBVHW6orxnfUT1tqPf0Mfq +rh3ShbY4uPRLjueiK++Lwby7PwkiaFHA70sCo9eiWPiqMEQ0MMvRcyMP5SJRfM5C5MR T2PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685978768; x=1688570768; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+eTZJaesQgEddfhUw6/wmzf8jeBxuOms7oai97sQq2k=; b=bacFGcsuQaATwjWVsmH4TOLtSmObsUfZZvPO0G+1YXfRHb6emj5RsuALlfEaB0eXmq 4dLMXHWSKnjyQ6/leKvFvbIlek+IoIYrNVb0DsCp0RG1Kugl4CqAtclM9i89f56M4lsf iQMKQislY2FE4zeWYL2pQeBlgR3AlE3IW7DgNwem0OMVM5qjc6VXFSob+GNBKon2vMF+ wyGZT+vxD48W1azU/lpJ+XJm3ZSf+HRtf397lpq9Ns0auYgswxkmlitoZU8uvuBkaWrm 8MG4uI0PO3xKH3GhEu0PvSrnqqmMzqAup34DN1jg7bCD8dTLeoFHt0dFDUXa5V5EZCrn QN1g== X-Gm-Message-State: AC+VfDwo/UvuyGcv1bSmewxYMu9kGU/bm+5LtiJPPnw9tGi7+1Hj1VcB 1QvGurAA+GuyW5fIaGsFOc0= X-Received: by 2002:a05:6214:5194:b0:61b:714f:73f8 with SMTP id kl20-20020a056214519400b0061b714f73f8mr7360816qvb.0.1685978768343; Mon, 05 Jun 2023 08:26:08 -0700 (PDT) Received: from auth2-smtp.messagingengine.com (auth2-smtp.messagingengine.com. [66.111.4.228]) by smtp.gmail.com with ESMTPSA id n1-20020a0cec41000000b00619adb4b66asm4725098qvq.95.2023.06.05.08.26.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jun 2023 08:26:07 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id 4D17C27C0054; Mon, 5 Jun 2023 11:26:07 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Mon, 05 Jun 2023 11:26:07 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeelledgkeelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepuehoqhhu nhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrg htthgvrhhnpeejiefhtdeuvdegvddtudffgfegfeehgfdtiedvveevleevhfekhefftdek ieehvdenucffohhmrghinheprhhushhtqdhlrghnghdrohhrghenucevlhhushhtvghruf hiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegsohhquhhnodhmvghsmhhtphgr uhhthhhpvghrshhonhgrlhhithihqdeiledvgeehtdeigedqudejjeekheehhedvqdgsoh hquhhnrdhfvghngheppehgmhgrihhlrdgtohhmsehfihigmhgvrdhnrghmvg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 5 Jun 2023 11:26:05 -0400 (EDT) Date: Mon, 5 Jun 2023 08:26:04 -0700 From: Boqun Feng To: Qingsong Chen Cc: linux-kernel@vger.kernel.org, =?utf-8?B?55Sw5rSq5Lqu?= , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , Martin Rodriguez Reboredo , Alice Ryhl , Asahi Lina , rust-for-linux@vger.kernel.org Subject: Re: [PATCH v2 1/3] rust: kernel: add ScatterList abstraction Message-ID: References: <20230602101819.2134194-1-changxian.cqs@antgroup.com> <20230602101819.2134194-2-changxian.cqs@antgroup.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230602101819.2134194-2-changxian.cqs@antgroup.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 02, 2023 at 06:18:17PM +0800, Qingsong Chen wrote: [...] > +impl<'a> ScatterList<'a> { > + /// Construct a new initializer. > + pub fn new(buf: &'a Pin<&mut [u8]>) -> impl PinInit> { > + // SAFETY: `slot` is valid while the closure is called, the memory > + // buffer is pinned and valid. > + unsafe { > + init::pin_init_from_closure(move |slot: *mut Self| { > + (*slot).set_buf(buf); > + (*slot).mark_end(); Benno can provide more information, but you cannot dereference or create a reference to `*slot`, since `slot` points to an uninitialized object (see `try_pin_init` implementations), and referencing uninitialized objects is UB (or may cause UB). Note that you could do the following for `set_buf`: // `addr_of!`[1] is special since it won't create references // (even temporary onces). let opaque = addr_of!((*slot).opaque); // <- *const Opaque let ptr = Opaque::raw_get(opaque); // <- *mut bindings::scatterlist // Maybe this can be wrapped as a Rust function with a // parameter: *mut bindings::scatterlist. unsafe { bindings::sg_set_buf(ptr, buf.as_ptr(), buf.len()); } [1]: https://doc.rust-lang.org/core/ptr/macro.addr_of.html Regards, Boqun > + Ok(()) > + }) > + } > + } > + [...]