From patchwork Mon Aug 12 18:22:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 13760922 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 C595EC52D7C for ; Mon, 12 Aug 2024 18:24:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5ADA06B00AB; Mon, 12 Aug 2024 14:24:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 55DD26B00AC; Mon, 12 Aug 2024 14:24:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3FE946B00AD; Mon, 12 Aug 2024 14:24:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 238656B00AB for ; Mon, 12 Aug 2024 14:24:38 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D66E9140327 for ; Mon, 12 Aug 2024 18:24:37 +0000 (UTC) X-FDA: 82444418994.13.47E57ED Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf01.hostedemail.com (Postfix) with ESMTP id 4103740022 for ; Mon, 12 Aug 2024 18:24:36 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=m5lNQLNQ; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf01.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=1723487024; a=rsa-sha256; cv=none; b=KcRQrCOKgPiVtlwLzBR2NHoomxZmmv72w/NjzRksLWLf+kZJGbxu9RGczRulUO7AvYTAwf cmDdHAIC60Jffeulao+lQx/mGoxRKFTvu9jxDhWYxavBhmRdQEbdiCbHi+xtkaSsZAzKtJ Rd7bgVygdqaPPO9O94BMF5gMs8XHr2I= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=m5lNQLNQ; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf01.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=1723487024; 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=H4dMpm/FiIvf86JDYd7aqkcxKnslTyBQ7n0iwYbXGS4=; b=snNVoItm5MU+psEgcwXfZFEWcQL4tTkvoVLTW7zA+9juGfqWY3llExCPBUNHuwGxteHdg7 qNYs+z3QcJo5TOFl4Co6rrP8crEq+AT2bmXhzkz0sKyQcbWTq9yPEuWTEaJ5u3RkhIkr76 bNCgaERpuC61D5t8Y82PTnfBdLAt/UM= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 73378611FD; Mon, 12 Aug 2024 18:24:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 370A7C4AF12; Mon, 12 Aug 2024 18:24:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723487075; bh=qBBwndXchuTUBdgsnYPoDfZNxNBpxLvVcMvZVRMmc6s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m5lNQLNQYt0Ppd0yuQfm7lGeTmotnrWGIWreHjtdouOP5zlDu/8/lEW1TJFBFN/hs 62DOmFEz4VvqDZ+mYVc/8des9VGhvZBbhKuMl9lUNT76ZKWEHKiG+QfD7Zb0j6ea/e aIa3mtkwEY/YoNKIxouC4NSrLYhRpyXdj2kZHOotMcS4y/TKI7JRKiEuUcmX5+0j8J 8ANlNtS+jIWN1IOkNw5Ajw4S3wij2VvAWr8CVuGFfiA3ueyEFcNhiiLgAHdeF4jhJW CH3DBtylU1WYpSPJL2kmykV28Pue4pqbsXKFAoXIK0AjVfw6pC2Dk4KaVLd3FhTPlm Ynb7j8zyApx7A== 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 v5 05/26] rust: alloc: add module `allocator_test` Date: Mon, 12 Aug 2024 20:22:51 +0200 Message-ID: <20240812182355.11641-6-dakr@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240812182355.11641-1-dakr@kernel.org> References: <20240812182355.11641-1-dakr@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4103740022 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: oxniihqrodjbjnc99sitdjkp4k16isgr X-HE-Tag: 1723487076-637922 X-HE-Meta: U2FsdGVkX19FmcAiniYP9bF2aRO1wHG2TGfhHWF9x9DV6zcYT1C+9cQk3VEOzM/DSzxX7WUCJDNvwm6LX9lfKxOZRbgmcG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hX7QTrh2tY3/tMXg1vX2QG6vV7Q2gCPp0ibZnyi1xrsGmIyx1IUr92YBEFHJ61VkAUmYymh6f+HjNUfpMrvSkeCmF/rd6Zi1hasF+efZP2erNdVAKLUgw1qDrnm3ElGflS2Qqa/b/wXgzdzQWtG9v1OaXH3KrTShJyfCU5H9NWW4yJxuPsOAfV3ZKa8P8X5zTsNtCYSRaeI 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: `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 Reviewed-by: Benno Lossin --- 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 b732720cfb95..f0c80ab78602 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!(); + } +}