From patchwork Tue Oct 1 14:59:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 13818226 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 8E716CEACDC for ; Tue, 1 Oct 2024 15:00:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1EE6D68000A; Tue, 1 Oct 2024 11:00:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 14DA5280068; Tue, 1 Oct 2024 11:00:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F311468000A; Tue, 1 Oct 2024 11:00:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D569C280068 for ; Tue, 1 Oct 2024 11:00:57 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 91901ACB85 for ; Tue, 1 Oct 2024 15:00:57 +0000 (UTC) X-FDA: 82625345754.25.8665560 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf13.hostedemail.com (Postfix) with ESMTP id B720A2002B for ; Tue, 1 Oct 2024 15:00:55 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=nburJpip; spf=pass (imf13.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=1727794790; a=rsa-sha256; cv=none; b=trqK7ZmAnMH6DkJ7mj9/P3wymGB51psg+W0E4f3Ck5AxH1iHc8YsDak6DpGoPOLihEgnyA XJ4nmRnXGl5mAGRvDQNVnDex1KWUSqP2qD4RVj72bLQ226aLWCKtaYRcOhGz6xl+KBpRpt 90DsqQXc2YNnrkftawYs7fcrKFdruAU= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=nburJpip; spf=pass (imf13.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=1727794790; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=EX4TD+JjJBRwfO1wVqGhdkQ8i5QCl+pKthOi/HJZgzA=; b=Qr89309DnBYDSPh5/nCTa8oGoOq9g0xx7+J+A0L5Lt8ZFRef0p4t1nPrMn3Kf6AZPBjw5T KzoCAxotoGntLLOYeRo/AsWpKzi0gVzvX6OKyrp/IVSHt5dA/IBGRekgR5P2uD3SFBP4s7 Iuouc0XRchDaxX9KQ/367+JdIb9I700= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 686085C4BDF; Tue, 1 Oct 2024 15:00:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 63E80C4CED4; Tue, 1 Oct 2024 15:00:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727794854; bh=qlNC8elt2DUs+OwvKv1BnkmPQ4QqoPQad7Orfyq3Sws=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nburJpipekwBNlmE6dN8wfGmOc2kFh4n72pl9CpCALXem0j8JOwKAFG77QHaZvEQY 3CemEpvBKNVUSjy11W4O2PLdpLUiY14++u33wr/yxPRJ3EWQi72+mhnZPIdoyuI3Wg W0bG+JLdTIQ6cfYScfymaSNHJeqQwQ4fqw6Zl4jHg/wn7mgj9/oMx9+pFgI+hI+BB1 arM/cnIZQOmB72mh6dTqEXQkwKqhlnEuJ5gt83e/j4RkGrVqFM411vN+qNI35VUvoX YkCtJuNDfaUMUPb/SjEK42U/gf8cbtmcJ67hiv1Q81+mlyMInW1qsJ6TVa/6a1BUwX /CP7sio9x81KA== From: Danilo Krummrich To: ojeda@kernel.org, alex.gaynor@gmail.com, wedsonaf@gmail.com, boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, benno.lossin@proton.me, a.hindborg@samsung.com, aliceryhl@google.com, akpm@linux-foundation.org Cc: 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, Danilo Krummrich Subject: [PATCH v8 07/29] rust: alloc: add module `allocator_test` Date: Tue, 1 Oct 2024 16:59:42 +0200 Message-ID: <20241001150008.183102-8-dakr@kernel.org> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20241001150008.183102-1-dakr@kernel.org> References: <20241001150008.183102-1-dakr@kernel.org> MIME-Version: 1.0 X-Stat-Signature: w3f5mhh1gti4xd5cc9kwngjbiy967qmx X-Rspamd-Queue-Id: B720A2002B X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1727794855-746398 X-HE-Meta: U2FsdGVkX18qt+A5Bo2cdudJlhoWXjOIumYRbBttKCHIX8L+2y+gCuXukx60q2IJQoGb/RyPLJMX8tKWXNIWvmJ2BhC/xu2026MNMEgoD6c1j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qolHym0Hm/5fGz8ymPUcV233KEPj0CMupwlh5DtV0xs1Yl2uMD/T+D8LxYUkxZhz0Z01xKK30MEVONuthrCbI8EpNQK8FGQhCk7nbbPW2ugiRMHyqpu/1INSYTrPEC9bO2XT+QHN/iEOWstn+vu3u2WAz+xUMciAGSLXh8oYa6fZ9Z2K2+BA9qucTWwRcAfCFIShwS0HStu4Qsz7I07ESBkit6Mqdeb9dME0hQLi7gFyPfM2Q== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: `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, + _flags: Flags, + ) -> Result, AllocError> { + panic!(); + } +}