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 091F9CEF17A for ; Tue, 8 Oct 2024 14:28:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7F3D06B007B; Tue, 8 Oct 2024 10:28:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A3F76B0082; Tue, 8 Oct 2024 10:28:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 66BF46B0083; Tue, 8 Oct 2024 10:28:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 48D416B007B for ; Tue, 8 Oct 2024 10:28:51 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id B6B4612013D for ; Tue, 8 Oct 2024 14:28:49 +0000 (UTC) X-FDA: 82650666420.10.F5FF8E7 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf06.hostedemail.com (Postfix) with ESMTP id 2DF50180013 for ; Tue, 8 Oct 2024 14:28:48 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Swn+8EiC; spf=pass (imf06.hostedemail.com: domain of dakr@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=dakr@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728397686; 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=USDXMzjCWz4ZfQdjlJ4Iv1QAz++W4+srDjHFrd+vyOQ=; b=21UDZWdATDn9vnwV8reFpLZvAJuGbLHEnARvkxe/ftJKglhz3NzwzQurGorRmpE+swweNE 48GGoiSzpltuFBbTOMHBkmnRxnClb9FIUwXrSeIB94eOLmiLxb2d2I+OU0hczhzKPS5kNw MrWv1wzgeFqPoLXe3dqglnABXtZux4A= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Swn+8EiC; spf=pass (imf06.hostedemail.com: domain of dakr@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=dakr@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728397686; a=rsa-sha256; cv=none; b=P9GcbxAiiD/O4+Y0bs3fTnEquIpSTrAge4rysidVNtqIdk9oc8SezFmrq9xwyhEcDKkr4v 397SGZTohWqcSKEKpQeHa1Q6B8X6ysYEhp50PUNxAxV85D4PeZDh1D37Lio+CFvIfQeSJa 1SEjrV42JNRpmT2/2jdVb/nD0acE5L8= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 92F385C5AC6; Tue, 8 Oct 2024 14:28:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F499C4CEC7; Tue, 8 Oct 2024 14:28:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728397727; bh=BtF+69VuIRUK1uTxBr4lzaNIIAyljbKUCyvoyJAl0BU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Swn+8EiCXtFOKeIG+2gplGfRpU2qKSBgOMOi1MaAoqX/MYCsE2fKRSTcv+GvnX+zo wXnDUPnv7ND9HtZcfUc4T36rZGIq++EjaIUcWOlN22eIgyhybOZ67fEwrurw4PEPl6 Av+owJjgIGE/JuxPYxGnxcFgq+mY5Z7kBwWDYHfthDh0cbIcmrqrYn9HBrr/mjsvdH M7Ckaso6eaenNnSBFZHD6HiL0tO4z9VGpiAnKXg30tfD1kZZB9WHTxauGiUepvQKGq EzIJ4ZILwvioZ4E47z3YwcR3ZcIgjMrhkfCABJWOfSuc/hogPGliPs1ClQ1ZzC2R/Z lMhUC1HgVSgWw== Date: Tue, 8 Oct 2024 16:28:38 +0200 From: Danilo Krummrich To: Boqun Feng 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 v9 07/29] rust: alloc: add module `allocator_test` Message-ID: References: <20241004154149.93856-1-dakr@kernel.org> <20241004154149.93856-8-dakr@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Stat-Signature: exnpoc8cxqzsr9xfudb5yrw9dnxxnc7o X-Rspamd-Queue-Id: 2DF50180013 X-Rspamd-Server: rspam11 X-HE-Tag: 1728397728-317949 X-HE-Meta: U2FsdGVkX1/xF/jRrZIIwu4hv3A4MzA8JmQqq46k01fpC5IDQudaRjDj7OvBrIe7sZ1f8SjO6noWLaWFY5I5wPd4ukoIr7fcIXk/7n+T6SAKV//X4xW3OzXFC5WETP5vyKJJmXxLCxrn9GZuw0Yqj10AhsWvn1DkXLKVAjmK9DUswoLawe8ambfQ+E7jo3b1R15Kzjv1El7o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IlMy5GftdvoI9Wz52plQlYObQeuZyP7KZvR5S/BCb1gm/aeeBPh8NCFtR7Ooi2Fnv2TIMsX+GDoyeiHZE1YxpEhdMh4sGqT1UJYHTDNV6cKv7fO//KbaH25sT+XnmwnkJANGi/lcLS8GMEMrm/5RLQ3NvNyFpFom1liFQBkSW5ijkGtcKJiA979OZpXJeOkP2om01 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 Tue, Oct 08, 2024 at 06:10:39AM -0700, Boqun Feng wrote: > On Fri, Oct 04, 2024 at 05:41:11PM +0200, Danilo Krummrich wrote: > > `Allocator`s, such as `Kmalloc`, will be used by e.g. `Box` and `Vec` in > > subsequent patches, and hence this dependency propagates throughout the > > whole kernel. > > > > Add the `allocator_test` module that provides an empty implementation > > for all `Allocator`s in the kernel, such that we don't break the > > `rusttest` make target in subsequent patches. > > > > Reviewed-by: Alice Ryhl > > Reviewed-by: Benno Lossin > > Reviewed-by: Gary Guo > > Signed-off-by: Danilo Krummrich > > --- > > rust/kernel/alloc.rs | 9 +++++++-- > > rust/kernel/alloc/allocator_test.rs | 19 +++++++++++++++++++ > > 2 files changed, 26 insertions(+), 2 deletions(-) > > create mode 100644 rust/kernel/alloc/allocator_test.rs > > > > diff --git a/rust/kernel/alloc.rs b/rust/kernel/alloc.rs > > index 91b2a26faf3d..f8ddc8d96da9 100644 > > --- a/rust/kernel/alloc.rs > > +++ b/rust/kernel/alloc.rs > > @@ -2,12 +2,17 @@ > > > > //! Extensions to the [`alloc`] crate. > > > > -#[cfg(not(test))] > > -#[cfg(not(testlib))] > > +#[cfg(not(any(test, testlib)))] > > pub mod allocator; > > pub mod box_ext; > > pub mod vec_ext; > > > > +#[cfg(any(test, testlib))] > > +pub mod allocator_test; > > + > > +#[cfg(any(test, testlib))] > > +pub use self::allocator_test as allocator; > > + > > /// Indicates an allocation error. > > #[derive(Copy, Clone, PartialEq, Eq, Debug)] > > pub struct AllocError; > > diff --git a/rust/kernel/alloc/allocator_test.rs b/rust/kernel/alloc/allocator_test.rs > > new file mode 100644 > > index 000000000000..4785efc474a7 > > --- /dev/null > > +++ b/rust/kernel/alloc/allocator_test.rs > > @@ -0,0 +1,19 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > + > > +#![allow(missing_docs)] > > + > > +use super::{AllocError, Allocator, Flags}; > > +use core::alloc::Layout; > > +use core::ptr::NonNull; > > + > > +pub struct Kmalloc; > > + > > +unsafe impl Allocator for Kmalloc { > > + unsafe fn realloc( > > + _ptr: Option>, > > + _layout: Layout, > > The `old_layout` parameter is missing here. Thanks, good catch. diff --git a/rust/kernel/alloc.rs b/rust/kernel/alloc.rs index f8ddc8d96da9..28281d600492 100644 --- a/rust/kernel/alloc.rs +++ b/rust/kernel/alloc.rs @@ -193,6 +193,7 @@ unsafe fn free(ptr: NonNull, layout: Layout) { } } +#[allow(dead_code)] /// Returns a properly aligned dangling pointer from the given `layout`. pub(crate) fn dangling_from_layout(layout: Layout) -> NonNull { let ptr = layout.align() as *mut u8; diff --git a/rust/kernel/alloc/allocator_test.rs b/rust/kernel/alloc/allocator_test.rs index 4785efc474a7..c5d325506f0c 100644 --- a/rust/kernel/alloc/allocator_test.rs +++ b/rust/kernel/alloc/allocator_test.rs @@ -12,6 +12,7 @@ unsafe impl Allocator for Kmalloc { unsafe fn realloc( _ptr: Option>, _layout: Layout, + _old_layout: Layout, _flags: Flags, ) -> Result, AllocError> { panic!(); We also have to fix an intermediate dead code warning for `dangling_from_layout` in the `rusttest` target, until we start using it when we implement `Cmalloc` in this module.