From patchwork Thu Aug 1 00:02:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 13749360 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 78E7DC3DA7F for ; Thu, 1 Aug 2024 00:08:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EC9866B00BA; Wed, 31 Jul 2024 20:08:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E79706B00BC; Wed, 31 Jul 2024 20:08:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D1B446B00BD; Wed, 31 Jul 2024 20:08:50 -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 B1A5F6B00BA for ; Wed, 31 Jul 2024 20:08:50 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 7A3911A083A for ; Thu, 1 Aug 2024 00:08:50 +0000 (UTC) X-FDA: 82401740820.03.48014E3 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf20.hostedemail.com (Postfix) with ESMTP id CC4F71C0003 for ; Thu, 1 Aug 2024 00:08:48 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Qi8MBrs4; spf=pass (imf20.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=1722470901; 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=yLl6nSqaJL4J1JLoizhVMMWA8rjQy+MNayRc9dzj7U0=; b=Gd5IJURZaLgBkOZJat0Tv/8+LR1FE6Q2CRxBn9uvwiT0nuTViOjLfezSp9ZDxAzN1jmi7v Q/pRGOJwgNxk2ihmX66FGtIJP2IxuhYUImZX4+/vAehJnBrZrqXeegBU6On7Jbz9ebw0Jv 0zcRSbn8PItYTUm1ZaSXBS3ReH3L1IU= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Qi8MBrs4; spf=pass (imf20.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=1722470901; a=rsa-sha256; cv=none; b=5OvLvWcyYWz2yoOt13rz0QnLbCIK0NeZ8XbZ0DfX7KdQFAXrMgaI6gGhqJvCjLnXrPWU06 5gH/83A+ZepxxoQz3TVeWlOJpARzbnPp9ITADJkfo8fc4SmRHgwnlvvTcWHUWtKbcMN9Ed HPzJ1+Bgrr+VOPA6vHYKqr31ONj8xjE= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 0CD3162646; Thu, 1 Aug 2024 00:08:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BA256C4AF0E; Thu, 1 Aug 2024 00:08:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722470927; bh=hs6yx2vsssnsC1cMGPjQ8GCbMEe+TcUfgVzllRdmHcQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qi8MBrs4TK3ypoC035nwRtxZmqKOxMEzojXeMd25cO+4CUFXRmQO7ThgKpbjtikcV YGbp9dUOlqTlw1s76GzTmW34h/Im39OUf2w1FE4ltRWUIOGUYvB7P4R/4x9PUoQslE ochEnnxMM+QLZxg/fs7fe48NtEc92gXHDwB+F2ldYLXrYcZSOq06Xw6SsZObmLCgFU iMF0TK0sR9f32LnvsBN9G3DRj12GKGm/l2ai6sXvki9jInqTIJV8U1l8y6irmWXtWC FyJLf78lg1CsOrLnljsDyuxz8y3D8xXhrlCWMdKqT3Lyms/9Emh0ruTfxXHrFofzsg lVWbm0OqlK10w== 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 21/25] rust: alloc: remove `GlobalAlloc` and `krealloc_aligned` Date: Thu, 1 Aug 2024 02:02:20 +0200 Message-ID: <20240801000641.1882-22-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: CC4F71C0003 X-Stat-Signature: 1fkjn7z4johct3ibgx3ac4yf15uitgk9 X-HE-Tag: 1722470928-503055 X-HE-Meta: U2FsdGVkX19JeRtWnwh+HrelpxzF2Fl3sgWle/VF7+alvGhR9GnU5gP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qhYb1rsn2uci1oBz7qF8K3ddNVVfdRPZuYsCjwRS/lDyw0NbKgGfL3shVmA2S32JbZIDhcwJKYyj3HXaqirSkvPITWMct7EHnsara91KcgyaLjCUFY5oB1gvkFG6MaLp1HQSCPs+TVEeZytWx5WdmJpbeQsj/SMAVHzut8H38rhIHN0HcjYTYjQ1xslxrhS3O0W8mxwtz1vxcmUuF5h0msEMti6bR2eg/if0QILz8A1V 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: Now that we have all the `Allocator`s and the kernel `Box` and `Vec` implementations in place, remove `GlobalAlloc` and `krealloc_aligned`. Signed-off-by: Danilo Krummrich --- rust/kernel/alloc/allocator.rs | 63 ++-------------------------------- 1 file changed, 2 insertions(+), 61 deletions(-) diff --git a/rust/kernel/alloc/allocator.rs b/rust/kernel/alloc/allocator.rs index 1e53f149db96..fbee89ac3be4 100644 --- a/rust/kernel/alloc/allocator.rs +++ b/rust/kernel/alloc/allocator.rs @@ -2,8 +2,8 @@ //! Allocator support. -use super::{flags::*, Flags}; -use core::alloc::{GlobalAlloc, Layout}; +use super::Flags; +use core::alloc::Layout; use core::ptr; use core::ptr::NonNull; @@ -39,27 +39,6 @@ fn aligned_size(new_layout: Layout) -> usize { layout.size() } -/// Calls `krealloc` with a proper size to alloc a new object. -/// -/// # Safety -/// -/// - `ptr` can be either null or a pointer which has been allocated by this allocator. -/// - `new_layout` must have a non-zero size. -pub(crate) unsafe fn krealloc_aligned(ptr: *mut u8, new_layout: Layout, flags: Flags) -> *mut u8 { - // SAFETY: - // - `ptr` is either null or a pointer returned from a previous `k{re}alloc()` by the - // function safety requirement. - // - `size` is greater than 0 since it's from `layout.size()` (which cannot be zero according - // to the function safety requirement) - unsafe { - bindings::krealloc( - ptr as *const core::ffi::c_void, - aligned_size(new_layout), - flags.0, - ) as *mut u8 - } -} - struct ReallocFunc( // INVARIANT: One of the following `krealloc`, `vrealloc`, `kvrealloc`. unsafe extern "C" fn(*const core::ffi::c_void, usize, u32) -> *mut core::ffi::c_void, @@ -121,41 +100,6 @@ unsafe fn realloc( } } -unsafe impl GlobalAlloc for Kmalloc { - unsafe fn alloc(&self, layout: Layout) -> *mut u8 { - // SAFETY: `ptr::null_mut()` is null and `layout` has a non-zero size by the function safety - // requirement. - unsafe { krealloc_aligned(ptr::null_mut(), layout, GFP_KERNEL) } - } - - unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) { - unsafe { - bindings::kfree(ptr as *const core::ffi::c_void); - } - } - - unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { - // SAFETY: - // - `new_size`, when rounded up to the nearest multiple of `layout.align()`, will not - // overflow `isize` by the function safety requirement. - // - `layout.align()` is a proper alignment (i.e. not zero and must be a power of two). - let layout = unsafe { Layout::from_size_align_unchecked(new_size, layout.align()) }; - - // SAFETY: - // - `ptr` is either null or a pointer allocated by this allocator by the function safety - // requirement. - // - the size of `layout` is not zero because `new_size` is not zero by the function safety - // requirement. - unsafe { krealloc_aligned(ptr, layout, GFP_KERNEL) } - } - - unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { - // SAFETY: `ptr::null_mut()` is null and `layout` has a non-zero size by the function safety - // requirement. - unsafe { krealloc_aligned(ptr::null_mut(), layout, GFP_KERNEL | __GFP_ZERO) } - } -} - unsafe impl Allocator for Vmalloc { unsafe fn realloc( ptr: Option>, @@ -184,9 +128,6 @@ unsafe fn realloc( } } -#[global_allocator] -static ALLOCATOR: Kmalloc = Kmalloc; - // See . #[no_mangle] static __rust_no_alloc_shim_is_unstable: u8 = 0;