From patchwork Tue Jul 23 18:09:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 13740249 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 6078BC3DA7E for ; Tue, 23 Jul 2024 18:11:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EA4496B0095; Tue, 23 Jul 2024 14:11:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E04536B0096; Tue, 23 Jul 2024 14:11:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C80276B0098; Tue, 23 Jul 2024 14:11:24 -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 A6A646B0095 for ; Tue, 23 Jul 2024 14:11:24 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 41EC51402C9 for ; Tue, 23 Jul 2024 18:11:24 +0000 (UTC) X-FDA: 82371809688.27.C5A46DF Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf11.hostedemail.com (Postfix) with ESMTP id 9D5F94000D for ; Tue, 23 Jul 2024 18:11:22 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=KMGsYeNW; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf11.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=1721758244; a=rsa-sha256; cv=none; b=21sHuW36RDmGkDSuuIvYcR/666dBgZF3/VAooN80OLk5DfuXuZM/O3xtr2fbIwVyz/ObQz IQ2krRpFiw/4Hw+NqUfJG8y6oHEMruHg8IgZfUlZ1XMsHJ9SIpjgOuzvQcgnSIwgTH0oQS aj/oPCQXJd0DUr6zEfRGKxrltjbi1OQ= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=KMGsYeNW; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf11.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=1721758244; 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=eAoPkOZLW05v6G+jAaln6NWstcFkluicyLaP4RGhw2k=; b=K+VXcNxEALddGhnNrkrvIlRUrDl538y8Bz6JhywcdE0klWhfW/1zJqJcn7ISERGg8d3f/c PQzArq0hQKfOQ5smFYVWwl8+YSi9VTJV6W/f5NBzWldS04Xr/agN4OfsuHl+1iLpvj1T/x 3SAblE95P0QlIAgp1HVJ6n212A8IwPQ= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id B3DBC60E15; Tue, 23 Jul 2024 18:11:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3A874C4AF0F; Tue, 23 Jul 2024 18:11:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721758281; bh=/CAVj622i+EjUqJe9C6/xiYM7R6rhnj9Rb056J9W4L4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KMGsYeNW8i1peerLA/ZxLTXTQB9autbiVJPYjR+Z7R/ZSaXPgKMAOX82xJwY94ndK j6uF99PhRxWMBTW3xVh6hAyjUH8iSWR3Cqu5/pc6UVffMXJNCJyumJIBn131wOrlSe 8IFbhkCh1ORfxDTu/EGVqEmc0BgLW48bdJCypLh3aA4tHsvMaozfT/A9AYXOqgXpXJ 0cCRVVFRxfthxcjIODCObO9cZyV1r1/dBPiDqkIOB8F2MzBQ+PF3MQcjZCmS0SNVoV 1lYsPT8UEgprnAIv+APz1a2AhuCoGmxgUNwnbYiYShoWixYfSwlOobf+7ER2pcFhn8 DMVAdjIiCdnHA== 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 v2 05/23] rust: alloc: add module `allocator_test` Date: Tue, 23 Jul 2024 20:09:54 +0200 Message-ID: <20240723181024.21168-6-dakr@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240723181024.21168-1-dakr@kernel.org> References: <20240723181024.21168-1-dakr@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 9D5F94000D X-Stat-Signature: dma1pzswhrm35xwj4k8am5srk91nmjd8 X-Rspam-User: X-HE-Tag: 1721758282-291898 X-HE-Meta: U2FsdGVkX19u35HPgdu9snNKzrwKPxHmQyBi9WD7+hdBYtU20zGBmi4Qjn6x04E5l88IjoX6GgI+LNY7Dyf7J/NOW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Y2oAw4M4JVSBkK9Xb917+ywztezUOdJsPizWgtBFLgSRDNbgm9oeMWPqSOoKbwVBNAtkMRQLI7h/thc1WTiXN+0eNebvC+758yEhWG20eHTaWYBQTbaN+7vM4Ho46LwPs0H3MiWfaPyih9FILteMtDq7TLMeOZu8+wFxkbbb9OBwgWUOSjZCn08= 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. Signed-off-by: Danilo Krummrich --- rust/kernel/alloc.rs | 9 +++++++-- rust/kernel/alloc/allocator_test.rs | 21 +++++++++++++++++++++ 2 files changed, 28 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 bf739ce65387..90ebe79e86cb 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..3a0abe65491d --- /dev/null +++ b/rust/kernel/alloc/allocator_test.rs @@ -0,0 +1,21 @@ +// 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( + &self, + _old_ptr: *mut u8, + _old_size: usize, + _layout: Layout, + _flags: Flags, + ) -> Result, AllocError> { + panic!(); + } +}