From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C7E3CD37AB for ; Tue, 3 Sep 2024 19:08:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 16EA08D01CE; Tue, 3 Sep 2024 15:08:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0F73F8D016E; Tue, 3 Sep 2024 15:08:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EB2978D01CE; Tue, 3 Sep 2024 15:08:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id CBC598D016E for ; Tue, 3 Sep 2024 15:08:57 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 72144120962 for ; Tue, 3 Sep 2024 19:08:57 +0000 (UTC) X-FDA: 82524364314.17.ABFFB74 Received: from mail-oa1-f45.google.com (mail-oa1-f45.google.com [209.85.160.45]) by imf20.hostedemail.com (Postfix) with ESMTP id 3FB931C0018 for ; Tue, 3 Sep 2024 19:08:55 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Lb0Ty42r; spf=pass (imf20.hostedemail.com: domain of boqun.feng@gmail.com designates 209.85.160.45 as permitted sender) smtp.mailfrom=boqun.feng@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725390460; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=UbOQUlni+K3mU+VT36wyrqeCHc06ganEEsHZCUl3X20=; b=C6JaGNzmLcL10GaomA+sXJCd9XUyzPKmbjK+bZUv2tpOWWYDHoYp1PqwXA+AF/nlWOJZil v+CAVmQwwDCdyxCfszwhjg/jAWRLceLobHC+acnhKZ9afC24bgfjUd+SXcSGdA1VWskYmt hrehl4sbg+qPO7i7OgC9Ihjng2C99aY= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Lb0Ty42r; spf=pass (imf20.hostedemail.com: domain of boqun.feng@gmail.com designates 209.85.160.45 as permitted sender) smtp.mailfrom=boqun.feng@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725390460; a=rsa-sha256; cv=none; b=QAKJgzDQwmQZF1HUTxh/82yxD3mXWtM5iRs1rJDCfaOrEgFweJ35c0yXIKa3nTCEipRZPk ZBTRaOW2VYwFW2REsXAfmOuNBZFIi+1DE1Gx680hZDnPp5i4RLorG7TDZJ3usi8CW8Vlj+ m1nJ3VKE5HWtO8tKBF50ioO3u+h5jC8= Received: by mail-oa1-f45.google.com with SMTP id 586e51a60fabf-277f0540c3aso1322901fac.3 for ; Tue, 03 Sep 2024 12:08:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725390534; x=1725995334; darn=kvack.org; 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=UbOQUlni+K3mU+VT36wyrqeCHc06ganEEsHZCUl3X20=; b=Lb0Ty42r1KWAz9A5pQloxx7osvdFo01UDs/uIetIbXJesCQRb4kOr658x8An7op2ru wjbK7P6cBEPaWBgKUmomIur8pLVXp2AN5TGmr6yxjIwskbmNnbPATN6+5UbVEApRxtCj GKipfGZKc3+xYppXPCVItlcneno7vZeSlA/21MHgp09BCOuW+nWIRpehiR3mYr+lXn5v HK1ATREui6pZCDJyKPqgdPYzeByREgI1NTlB6er6/Hpao12m++pQ0sjodZOaUU7Ux3Co 6bYLtsDWpYFWuNrq6lCuuuUmolhskw9SlAyg2KBAbAlFwA76+1doK7fJJ1GqewYIbV75 wdZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725390534; x=1725995334; 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=UbOQUlni+K3mU+VT36wyrqeCHc06ganEEsHZCUl3X20=; b=jRzgowtaRhaDdUECI/k8gofrXJhAWzuRTzNgIQLURx1X0G4yn2fhM6GjQslWSTFPGu EneGke3MDN3fM+f+HJxT7I5UWLb+kZsQg7fKruzlXYbh0LBJXfjMUOeEbEGRMvSB2LlQ kyOG6vMvpNaq1KeYOBZbDyI+LzMxvmbFntXcoM4Zlyzfh6M4hkMOWh7oUgDqD0cdqjLU kt/GEbkMh+nlO2MTTAp/HFYHeMFwJC82hxHG97RbbH42nztl8vpjoKg07a/6ToUpBghQ tQft0fbQg8uBYpph2lbEJcK+YLtw4LIuTgZOvuMMWNAYc7228IwmXFLnIHAu6xy02vQx p+kQ== X-Forwarded-Encrypted: i=1; AJvYcCXNThlqVPOdCCVR7UnaNsDyqKPB7xiu+KEBYKDbQ58JHwtmyauW/d6qrq7ZtO6G29Kg+H2/fZHqAw==@kvack.org X-Gm-Message-State: AOJu0Yzl+sFH2nNxO+miMLhvWSEmUa6Jny7YPAM2Pdhw+IHqExpO4B+9 fsYbSQrRpZeEQMieQXMnHvs5x8IV/IZVYa1kIAr9d+/4zI2pb4rc X-Google-Smtp-Source: AGHT+IGtCzQWoZOtKA3syrQPJGzUcBg/Ps85zPwRD229jSRfHPmnAAhoD8+rYvbPIs4FoggfBXP+Ow== X-Received: by 2002:a05:6870:c110:b0:278:986:1e44 with SMTP id 586e51a60fabf-2780986204amr6402016fac.18.1725390534144; Tue, 03 Sep 2024 12:08:54 -0700 (PDT) Received: from pfauth1-smtp.messagingengine.com (fauth1-smtp.messagingengine.com. [103.168.172.200]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7a806bfb8f5sm552822085a.12.2024.09.03.12.08.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 12:08:53 -0700 (PDT) Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfauth.phl.internal (Postfix) with ESMTP id F0E191200087; Tue, 3 Sep 2024 15:08:52 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-03.internal (MEProxy); Tue, 03 Sep 2024 15:08:53 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudehhedgudefgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddv necuhfhrohhmpeeuohhquhhnucfhvghnghcuoegsohhquhhnrdhfvghnghesghhmrghilh drtghomheqnecuggftrfgrthhtvghrnhephfekudfhfeffvdfhhfdvtefhveffhfeftdef vdehjeegkeeftdeggfevfffhveeknecuffhomhgrihhnpehpthhrrdgrshenucevlhhush htvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegsohhquhhnodhmvghs mhhtphgruhhthhhpvghrshhonhgrlhhithihqdeiledvgeehtdeigedqudejjeekheehhe dvqdgsohhquhhnrdhfvghngheppehgmhgrihhlrdgtohhmsehfihigmhgvrdhnrghmvgdp nhgspghrtghpthhtohepvdehpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopegurg hkrheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepohhjvggurgeskhgvrhhnvghlrdho rhhgpdhrtghpthhtoheprghlvgigrdhgrgihnhhorhesghhmrghilhdrtghomhdprhgtph htthhopeifvggushhonhgrfhesghhmrghilhdrtghomhdprhgtphhtthhopehgrghrhies ghgrrhihghhuohdrnhgvthdprhgtphhtthhopegsjhhorhhnfegpghhhsehprhhothhonh hmrghilhdrtghomhdprhgtphhtthhopegsvghnnhhordhlohhsshhinhesphhrohhtohhn rdhmvgdprhgtphhtthhopegrrdhhihhnuggsohhrghesshgrmhhsuhhnghdrtghomhdprh gtphhtthhopegrlhhitggvrhihhhhlsehgohhoghhlvgdrtghomh X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 3 Sep 2024 15:08:52 -0400 (EDT) Date: Tue, 3 Sep 2024 12:08:08 -0700 From: Boqun Feng To: Danilo Krummrich Cc: ojeda@kernel.org, alex.gaynor@gmail.com, wedsonaf@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, benno.lossin@proton.me, a.hindborg@samsung.com, aliceryhl@google.com, akpm@linux-foundation.org, daniel.almeida@collabora.com, faith.ekstrand@collabora.com, boris.brezillon@collabora.com, lina@asahilina.net, mcanal@igalia.com, zhiw@nvidia.com, cjia@nvidia.com, jhubbard@nvidia.com, airlied@redhat.com, ajanulgu@redhat.com, lyude@redhat.com, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v6 13/26] rust: alloc: implement kernel `Vec` type Message-ID: References: <20240816001216.26575-1-dakr@kernel.org> <20240816001216.26575-14-dakr@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240816001216.26575-14-dakr@kernel.org> X-Stat-Signature: m417o6nuq7wmsfc69e7ah4kqaa18ienk X-Rspam-User: X-Rspamd-Queue-Id: 3FB931C0018 X-Rspamd-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oLLWoBzo9aq37hqK7s2x9tzh/Qq0sw8lTpSA/u70c7ujICXMcmApBv+N0CaemVM9FYSN6TeEXcpqpNT9GVsrGs8UvkhN/yxLUzJvhJriDHHg2RiDdGkO9dOsCZn9I8ny8PLt53gXHguIx9ai4vTBKuah38Ub1fNYle7BXf741b9Coe55tfaE5lakjY5ZQzF2kttVd6Dl/Js5FLpsfBif/5R8ERekZNifpyqnw8LnozyLV9ePfigeZd9ADAlDXsM6GA45hsSiQXgfqHu8w4gcKM9gw9Jrh9e/xYvCeFcB9icRJj+FWi1u7pCrfwCclyHolVaGZgcNSurbpKpG+vAvvpCh2JJcykWgaEtgQ30ufNODCjz3Mo/AeK+3xRtNm2UkEnm21D+76IVxu2UqdyO8OlC/MbtgxFH77WN05weFBGmhGh0Rs5t5HHcZXNT+Ta X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Fri, Aug 16, 2024 at 02:10:55AM +0200, Danilo Krummrich wrote: > `Vec` provides a contiguous growable array type (such as `Vec`) with > contents allocated with the kernel's allocators (e.g. `Kmalloc`, > `Vmalloc` or `KVmalloc`). > > In contrast to Rust's `Vec` type, the kernel `Vec` type considers the > kernel's GFP flags for all appropriate functions, always reports > allocation failures through `Result<_, AllocError>` and remains > independent from unstable features. > > Signed-off-by: Danilo Krummrich > --- [...] > + > +impl Vec > +where > + A: Allocator, > +{ [...] > + /// Forcefully sets `self.len` to `new_len`. > + /// > + /// # Safety > + /// > + /// - `new_len` must be less than or equal to [`Self::capacity`]. > + /// - If `new_len` is greater than `self.len`, all elements within the interval > + /// [`self.len`,`new_len`] must be initialized. Maybe use "[`self.len`, `new_len`)" to indicate `new_len` side is open? Also `self.len` may confuse people whether it's the old length or new length, could you use `old_len` and add note saying "`old_len` is the length before `set_len()`? > + #[inline] > + pub unsafe fn set_len(&mut self, new_len: usize) { > + self.len = new_len; > + } > + > + /// Returns a slice of the entire vector. > + /// > + /// Equivalent to `&s[..]`. "s" is used here without pre-definition, it's a bit confusing. Either we use an example here, or we can just avoid mentioning it at all? > + #[inline] > + pub fn as_slice(&self) -> &[T] { > + self > + } > + > + /// Returns a mutable slice of the entire vector. > + /// > + /// Equivalent to `&mut s[..]`. Ditto. > + #[inline] > + pub fn as_mut_slice(&mut self) -> &mut [T] { > + self > + } > + > + /// Returns a mutable raw pointer to the vector's backing buffer, or, if `T` is a ZST, a > + /// dangling raw pointer. > + #[inline] > + pub fn as_mut_ptr(&self) -> *mut T { I think this function needs to take a `&mut self` to mirror the `as_mut_ptr` of a slice. Regards, Boqun > + self.ptr.as_ptr() > + } > + > + /// Returns a raw pointer to the vector's backing buffer, or, if `T` is a ZST, a dangling raw > + /// pointer. > + #[inline] > + pub fn as_ptr(&self) -> *const T { > + self.as_mut_ptr() > + } > + [...]