From patchwork Wed Sep 11 22:52:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 13801178 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 7D532EE57D7 for ; Wed, 11 Sep 2024 22:55:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0E6696B0095; Wed, 11 Sep 2024 18:55:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 06DED6B0096; Wed, 11 Sep 2024 18:55:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E51636B0098; Wed, 11 Sep 2024 18:55:30 -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 C4E8C6B0095 for ; Wed, 11 Sep 2024 18:55:30 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6C85F141343 for ; Wed, 11 Sep 2024 22:55:30 +0000 (UTC) X-FDA: 82553965620.26.2D36604 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf17.hostedemail.com (Postfix) with ESMTP id BFD5A40009 for ; Wed, 11 Sep 2024 22:55:28 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="RXwms/Q1"; spf=pass (imf17.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=1726095300; 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=5oPPMmxauRhXV8pigZ+6XeLCWIciB7fh8ZmFec/R0tI=; b=qncYBW1QjHW+DOEnYv85Mc9TPurEM4fCTmgblAkUgtx8MRUTDiGJAz4e6x8pAqYdsJNEy0 8PQBmY8MRSUFCIkq45AJ4mfRTQqV0vR+gw6TE7bQYOmeG+MZIQxoo4JaJenl0/SMCPX1af PqTgGJ0kaeal95eI2KzFnw+tuYQEzDE= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="RXwms/Q1"; spf=pass (imf17.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=1726095300; a=rsa-sha256; cv=none; b=YxgnQ/cdW0oh5uQm6UOVImP5AAA9Y98TzqXOX0zsc8+nnkoGLBJocbGsJsLd+UjcrFR4Vm LmjRtUB8yU7at+BCy6875z17fFDCE0xQFN8R2Iz50AXI2iWXQbFDAirX0SCitVbeKf9k3O yaalWhCNJD4lzlkLWpNpuxKtJ1bQ3jg= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 502C55C0532; Wed, 11 Sep 2024 22:55:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A98B6C4CED0; Wed, 11 Sep 2024 22:55:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726095327; bh=6UhtPHghMdWoDtF9TGoHZC9u3Z5IdMcvwYnLuoTa2qc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RXwms/Q1IYeTrOVyS8N6rmwVkuedlR7RrzOdigur1Nqg3fVvLpdjdpt87ycrYgBak UL4Us49SUfm6lzmfl286zvwwQQ6+fZJvTwTCQOoT+Rmc98EoIWGzN9YVgQd9GRJQj7 PjiLKvK5hZ8yXT4bPvuwFG/9I7iyeWLqE5RN8Ij81osBIQ9csfmWVxmb5HyMvzjAvB Y+MhH4C9XSnTyz48Ul81QJ092J0832DhYYkhm29zar+vQO3eVBU9nHURmuXisch9zy bb4hNzvrwTD+0uwAH36Id9zHlpN3/ayuyyHlhEvLDHQogD8XYcVbHi96wwOaChS528 frujahViF8gvQ== 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 v7 05/26] rust: alloc: add module `allocator_test` Date: Thu, 12 Sep 2024 00:52:41 +0200 Message-ID: <20240911225449.152928-6-dakr@kernel.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911225449.152928-1-dakr@kernel.org> References: <20240911225449.152928-1-dakr@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: jngmcb5amz5epn7rfubfkgyh7sszjtnm X-Rspamd-Queue-Id: BFD5A40009 X-Rspamd-Server: rspam11 X-HE-Tag: 1726095328-16210 X-HE-Meta: U2FsdGVkX197jWZrn6pg4TgMHB4C53gmp+q86I35wK3GJNhJSVF1nac351/wCzY18hfMNtIhAdD011oK/uO2vBTWNiJhCU1Wey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M4vmb4OOzXsYWrtYThho2vlpFqiMxRSpF3vve5jlZQGrumJVPIPDkwNTqAcZAy2/8sSakj0vx7c9D3VNOTvnNrsWvoJENn+HjtbYITJrBNioz2xuMf92/zlrtzvpQ343Cg2jcADGASarwstZgeezCJQ7891zYOKhLO0OOajFB9Dta+wAHd1qKHRy/kM4H+lpdQPQ8FcVESF8AloaWgKCw/TzZKIuSOfysQngFIrHwgvfRYw== 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 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 535ed1527034..da025faf07f8 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!(); + } +}