From patchwork Mon Aug 5 15:19:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 13753714 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 9A050C3DA7F for ; Mon, 5 Aug 2024 15:20:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 37FD36B0096; Mon, 5 Aug 2024 11:20:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 308E76B0098; Mon, 5 Aug 2024 11:20:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A9FA6B0099; Mon, 5 Aug 2024 11:20:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id EFC136B0096 for ; Mon, 5 Aug 2024 11:20:43 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A95011A042A for ; Mon, 5 Aug 2024 15:20:43 +0000 (UTC) X-FDA: 82418553966.26.6B2ED32 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf22.hostedemail.com (Postfix) with ESMTP id 1BC33C0006 for ; Mon, 5 Aug 2024 15:20:41 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=MoML3ZgK; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf22.hostedemail.com: domain of dakr@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=dakr@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722871192; a=rsa-sha256; cv=none; b=SUmb9HF1dbmSmGZNj855A2JiZtz5WcBoERyTp/h9O03zW+3HLLbN6HB7DWqY4V4dZ2wTKR QxIOgOZ1J6RgE3Ml461TMthm0IXk2r8TwiUxllN1lha9b1YPsj0EYk4ErAYY4jphQwEY6L 21U4cK4JauHjdAreQKq8WMletJojLYk= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=MoML3ZgK; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf22.hostedemail.com: domain of dakr@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=dakr@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722871192; 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=1Tl/yfknUaCdVxWC9+TOlAZFtemlmU3kI8IoOJXIu0A=; b=cqfnk4gMSSVoq4Q1pddOLIw4tr/Lzpu2KzDXqCtwH2y58FsHBLePpQGNa7vRuNNB+VEOve wvjYd8zVoV4HtNqLloKfLdsTDlO+bLkdvp0mYyaMuC7Rgst+4fxnVAJd4W/Q45B0MU7mE9 w2uMzz+9Fo6wE3yB7stGfmXKW20VgwA= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 5D1B260C8F; Mon, 5 Aug 2024 15:20:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EBDF7C4AF0C; Mon, 5 Aug 2024 15:20:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722871241; bh=/7W8GCJx8ZaHy6t5I1ObMJj1vrI+veTwVNr/WbX4NOU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MoML3ZgKxFmsuOSbgCE56/itM8cvkuK//0MYyC4C4aunRsn7Dl8fWhcGWz2EqaJyp iHmE9IwsJtEQ+EHgu7FFHPV8ZnWnUXwA3+lh0gbW7Gkz97Saj+UQ1ofrBSyD+ZQUo3 pXNgjDlKvZFkzNmoyhI7ay9CSn95HVw7vMzY9GS8rJ39uNMYW0RinE+hhJ369gKnk3 K2RjcUnjvR1xVZL/IS3DK/iAjMJ5gw4T/18OQCFeghsNoP9FzgX2br/uRV43bDHpMv jIID+fqZFGd148UqPzOEokjka8CVFv71Ml3Ma+1USIivms//SQzAIrG+TPd8bivRVa l2P/zx6yd+lAA== 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, acurrid@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 v4 05/28] rust: alloc: add module `allocator_test` Date: Mon, 5 Aug 2024 17:19:24 +0200 Message-ID: <20240805152004.5039-6-dakr@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240805152004.5039-1-dakr@kernel.org> References: <20240805152004.5039-1-dakr@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 1BC33C0006 X-Stat-Signature: 68bxrgcsgbbuxedeynmzym5c9hhjnb97 X-Rspam-User: X-HE-Tag: 1722871241-144 X-HE-Meta: U2FsdGVkX19DwwG8SPhAEXpbdleztTeOWSW4l6PfX8xycKyCvYxG+wQEtXeLwhXIxJ722MuSrApJ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XWAFxKxOpY/vdeKjsIdyROPTGpgeYWBA7dL+aOLOB10Yy0RJe+K4LWnwYonupvjx8v7qOoe2qkRUpD+mCyqUwCLE1xHPewri6s6yX3FzfTRhO19sCWkF/yAycWLbf+oEF7mVgUvoeLLRbmjTMqJBpZeQUWqKPEboko+mEwWLPtwsbb7GCkZS6GzbIQ6Dbq+qoAo2bzi/MvHTZVS5s6W97 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000009, 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 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 bc01a17df5e0..942e2755f217 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!(); + } +}