From patchwork Fri Aug 16 00:10:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 13765286 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 8CA78C52D7D for ; Fri, 16 Aug 2024 00:12:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D34B28D0015; Thu, 15 Aug 2024 20:12:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CE5CE8D0002; Thu, 15 Aug 2024 20:12:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B38688D0015; Thu, 15 Aug 2024 20:12:54 -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 988EF8D0002 for ; Thu, 15 Aug 2024 20:12:54 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 4A56C14187D for ; Fri, 16 Aug 2024 00:12:54 +0000 (UTC) X-FDA: 82456183068.11.0BE7DF0 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf03.hostedemail.com (Postfix) with ESMTP id A3B9420005 for ; Fri, 16 Aug 2024 00:12:52 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Mptd4JKJ; spf=pass (imf03.hostedemail.com: domain of dakr@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=dakr@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723767136; 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=NctXb/9T9ONoA/cLwLRShaTVahD2/X5m2M9L3dXU834=; b=Bc7Ez6OJkuCwa2jLtMzQ/f19F5Bg2CPAkKpDTNRHuc820un2z/NIKDB/tlbrrmN4uXiOOT 1YiPsocwdFUL7PR8xdQZHq2GUdMdQ5EJtPj48p7GHtk5kshpHaFHldL7RT2v9e09gKeY92 tKEWfHiynaU1jvRaKAxhlmcOXG9+J9o= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Mptd4JKJ; spf=pass (imf03.hostedemail.com: domain of dakr@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=dakr@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723767136; a=rsa-sha256; cv=none; b=rojqPKGkgpfvqVBY8UM0071rWV3cKbjJC5QN4WTsqtUaHSo6zq9xekpiSBz8re/YFZ6c1t DcuCd/UDyAGrU0I4C3MzpjvVYpgNzRl3oH+ifghPRd3UvpgCTxuZpiUoCY4G1WLLsz/dt7 KTO++unrbGpMtOOmmdtYgXBnjAN7FAE= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id CE74262058; Fri, 16 Aug 2024 00:12:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4F9EC4AF09; Fri, 16 Aug 2024 00:12:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723767171; bh=xS2F4hvF8mQiKszeCLTojdsU+ekVrYxlxLHbB2WYsV8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Mptd4JKJ0SXQrCoV8gnzgZkaEtUMDY/zq8KAdqLxmuHAr+VEXXfnxdn07L95hCM67 SWTm9DEjWk0wyzn0DbQqZl5Na9O0xmMlVfXgNkToVSCWEHS1EINnBk4LdgsAIKwa5q BDVi5OFRjMsFLkqHYLpL+GSWXpkRTCtq0PtHFFmg8dIVl+VVwAJJ0abKIGiFzTSMN3 KGVHzEBANNSiKdAuP4Vpwj+rf6PycMC11jrBydPUox2Q77Fn2WNmU0ATOeSDqls5vr DuFr1l/NjUXF4gUitfym1UN5IUlYiFYaU3JHjG0plvJYkIXzTV5K0roUB1hNS0/c3b kgJza8BKjQlnQ== 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 v6 05/26] rust: alloc: add module `allocator_test` Date: Fri, 16 Aug 2024 02:10:47 +0200 Message-ID: <20240816001216.26575-6-dakr@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240816001216.26575-1-dakr@kernel.org> References: <20240816001216.26575-1-dakr@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: A3B9420005 X-Stat-Signature: uf1cpjdoyeuskrab5z5k8aau36oq65q3 X-HE-Tag: 1723767172-581567 X-HE-Meta: U2FsdGVkX19OQBAaSJ3WDfgl+0i9NV4xr3WPHIIRwB3CFeAUT/LUcoV8/ShnIQAntLNup0Z9vYbDKAPICcbG5fHj9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LEC9O60YqDT4HHsthbNAspzWbkDez6uW61BF0hjg7E3xVnmQE77o40+HiT6ZRf9DiZ07sTHMk2WRJxgm9eNaMJq8agOxZpmeRp5+XPR73U9trmlf+nw+FGS4dM6kVLRGFKYOq9C0K4jPIryWoVikmrjAq2+CMQvkVKafr5aoCxb+saByB6rFA9zSIA8IlzQFeZYYwJpyyeAcFmoIPuqr 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 Reviewed-by: Benno Lossin Signed-off-by: Danilo Krummrich Reviewed-by: Gary Guo --- 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 477dbe3c5a2f..91a367a58f36 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!(); + } +}