From patchwork Thu Aug 1 00:02:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 13749344 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 A78C1C3DA7F for ; Thu, 1 Aug 2024 00:07:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 37BA76B0099; Wed, 31 Jul 2024 20:07:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2DFF86B009A; Wed, 31 Jul 2024 20:07:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 159606B009B; Wed, 31 Jul 2024 20:07:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id EBBE06B0099 for ; Wed, 31 Jul 2024 20:07:22 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A63038082A for ; Thu, 1 Aug 2024 00:07:22 +0000 (UTC) X-FDA: 82401737124.14.8E5F7B3 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf19.hostedemail.com (Postfix) with ESMTP id 0939F1A000F for ; Thu, 1 Aug 2024 00:07:20 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="Qnbk/8bq"; spf=pass (imf19.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=1722470813; 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=Ktja1Qz4V2ENHBxtk5PtFAadBKLEPzG193jzgSKbVBA=; b=YPnQSekQKNsAt8LbJWcbAV+OcUqZf/nCrxyMDTyfUoZqmjzcwAvuIEbtkLFo/vFa9xQCCh VgYrTXsQsx2c4rNXl0R7bx535bBzGtZCVjx6RQunJ3h1MNGWy4KnDzbjNq0A7twsXENUa/ bmeP/CL6/RoywS0XVmMdrrgAG87on34= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="Qnbk/8bq"; spf=pass (imf19.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=1722470813; a=rsa-sha256; cv=none; b=2uLm1qe/Luxf+coHiKYi6LHaIP7I+UM2LtIO0kbXSkw3drdDnD51XcetO/1NJroDEjolk4 0Os50+iMOa8bFSVWa9tEPE4+6LlPcGBfYIRpvlzsEQjp7KEwlrWwjTZuR58DzNQ4meAiyE A06TVlw0fByaGeYvr0wpsUQMOAH5r1M= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 1E2F56265B; Thu, 1 Aug 2024 00:07:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8539C4AF0F; Thu, 1 Aug 2024 00:07:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722470839; bh=NhoXQc/3NsMmnAPcZ6sxE5qBH2rG1UwJKGQPjBzD4UQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qnbk/8bqEz+f7vIQkgZF3ii1t/44Pt0IyVAeduPEsyw15aUBIunIRCTOcLkj/4tFg UioDGgVy1iZi90grH4zYgsok1EQjaBYAXqmCCK9fo83geupijgvjO384a+8MtpK4B0 gWUo5nulw0azUB6RH4NohTHVjRW+jR/6peGuZQUJM2+JCvHGfY8MR481XpDvXig6IZ Bm1J547kzWyUWiGfNhfol3gYMjEEcEdIe1qajTqXxvZcKwigeC3EDtuuawQYo1g29M E1p6il6mkzvIMyqZ9qRtLlAhB8SkvbsxdpfK1nUo8WEtoY8NkbXIEM9y8C8guyxzhY rPB3gdike6Apw== 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 v3 05/25] rust: alloc: add module `allocator_test` Date: Thu, 1 Aug 2024 02:02:04 +0200 Message-ID: <20240801000641.1882-6-dakr@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240801000641.1882-1-dakr@kernel.org> References: <20240801000641.1882-1-dakr@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 0939F1A000F X-Stat-Signature: mrnqpu3gswq5tby5ciebejtb3zfrpow6 X-HE-Tag: 1722470840-490207 X-HE-Meta: U2FsdGVkX1/aWZTP0TRGVa4ojYhpO/JD6lJMlk3Fh7vNqajY+mI9ztOB+SaBtZifN7NU6QWAqcnHrZRkltw+vWadjz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g3YbFyhUrTjX+enAmU7dSP7q66QumtzsiwYep4CxTJSnXTeMgYvvj2Ti+GzDa9e1wOjh6W1Kz0EzHkGy5DkieRvR759cXaRk1HWGnDaZk2LiuL3m6O0IrqLocCG0WZlnM7gKIlNqSwwDcbgw8WJTBuRcDjWI2UElW090hz2Cg2TeDMRPJVD02cfotOQ4= 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 Reviewed-by: Alice Ryhl --- 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 8cabc888393b..90f4452b146a 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!(); + } +}