From mboxrd@z Thu Jan 1 00:00:00 1970 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 B1BE3C83F17 for ; Tue, 15 Jul 2025 14:05:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 51AB68D000A; Tue, 15 Jul 2025 10:05:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4CBB28D0001; Tue, 15 Jul 2025 10:05:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4089B8D000A; Tue, 15 Jul 2025 10:05:31 -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 31CDA8D0001 for ; Tue, 15 Jul 2025 10:05:31 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 023A6B9C63 for ; Tue, 15 Jul 2025 14:05:30 +0000 (UTC) X-FDA: 83666671662.15.D9EABC1 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf20.hostedemail.com (Postfix) with ESMTP id 562501C001A for ; Tue, 15 Jul 2025 14:05:29 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Z8Cx702X; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf20.hostedemail.com: domain of dakr@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=dakr@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1752588329; a=rsa-sha256; cv=none; b=ulEjtyE/cHPWDLJJndu1aFN8JXqsoe2MmwQazg2myLuwYfItgvpTE+6Umu3AnBbpT9BLWD 3zQVESMaObIBENuOEhNuQEBq5o+Xd5qHZlS8J/eLQORiQB78KL52IlZXA/Em7PZ26EVv/8 jaha3x8N847yrr2mKeulnoVrB1GiXw4= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Z8Cx702X; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf20.hostedemail.com: domain of dakr@kernel.org designates 147.75.193.91 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=1752588329; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=+HcS4IFmWASZU3avWsk79GFP308Esvyr7oLcGipJbLU=; b=4kkR+6PWXYJIgN9BoE9oFhM3YSc3SotGQlt4nTbbbfc1P8dmkC/zbFC5kUytDoA140NtFA /gLnfHfpw8tK6OmTZsxE2HjkUvmr/9rhgVrCOiRwBa1YDWi4mvuPaza1ikTahkgFt5gafR +OiC+AQPBzjF5uq3J3c+qmVM12qGKuo= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id BAEC6A57119; Tue, 15 Jul 2025 14:05:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 63CCFC4CEE3; Tue, 15 Jul 2025 14:05:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1752588328; bh=I3uWJic5PlcugyOwNoTXQW2P5Q0NMSqDZK8jdTD0Xjk=; h=Date:To:From:Subject:Cc:References:In-Reply-To:From; b=Z8Cx702XURCbhLzdgLEEQoJ6/u0vlVw4gNkJjrkGVcexyEOgcIx8EoUnCtJmDFoCs aq6VFKRfpz3Y1pzMUFiUnmfju+Nkye2nVZzAMcJZAD2KO/QDCzwYYWl3jMWj1KsiaA rY3nFRWp9Lu2hhryjvs+ck7KI7CuDW6CVyuh2N4iI2sEfTK8KyZP2INlKsyxgLDYHG G4Q2zoFw08+G52KYyAyuXw/oQiB///SohWlfJC9zeKH1MSLf5Qx54g9ym4z001AJfS EWzPvNcGYjZT3ryPIX8rMOvFGtvCTwIjL+JADM+k1iCj2vdl2p357bwo5EYDPuWNYS R1J+yd4r3e9tw== Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Tue, 15 Jul 2025 16:05:23 +0200 Message-Id: To: "Alice Ryhl" From: "Danilo Krummrich" Subject: Re: [PATCH 1/2] rust: alloc: specify the minimum alignment of each allocator Cc: "Lorenzo Stoakes" , "Liam R. Howlett" , "Andrew Morton" , "Matthew Wilcox" , "Tamir Duberstein" , "Andreas Hindborg" , "Miguel Ojeda" , "Boqun Feng" , "Gary Guo" , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , "Benno Lossin" , "Trevor Gross" , , , References: <20250715-align-min-allocator-v1-0-3e1b2a5516c0@google.com> <20250715-align-min-allocator-v1-1-3e1b2a5516c0@google.com> In-Reply-To: <20250715-align-min-allocator-v1-1-3e1b2a5516c0@google.com> X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 562501C001A X-Stat-Signature: 1sozi1o36fsz6jidp58rktp5zers37ut X-HE-Tag: 1752588329-906092 X-HE-Meta: U2FsdGVkX18nMhD4MUQCSezh6kcl+IXczSx9xmYCDB4suffMSnThUcP6TiOIchIibATSi0G4jtakTRJnRnxIE0mnxpQLyWk1aB659uvnuskVMYOwaicIAadXC6t0iQAWcnZn323dMsmt8SGDd4iW50RtP0h6BaL+5kxgm99S5jPxpQcrVZ+w7wK2wiZr9XzXuUCasGj14SUqKonX8jcHgu43qyDuPc4yQLrbBSPOy/9l5E891b0ouBa+k4MbGXNXM/Oa/Do0Zb+9d7SjfTV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, 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: On Tue Jul 15, 2025 at 3:46 PM CEST, Alice Ryhl wrote: > diff --git a/rust/kernel/alloc.rs b/rust/kernel/alloc.rs > index a2c49e5494d334bfde67328464dafcdb31052947..c12753a5fb1c7423a40635536= 74b537a775c860e 100644 > --- a/rust/kernel/alloc.rs > +++ b/rust/kernel/alloc.rs > @@ -137,6 +137,14 @@ pub mod flags { > /// - Implementers must ensure that all trait functions abide by the gua= rantees documented in the > /// `# Guarantees` sections. > pub unsafe trait Allocator { > + /// The minimum alignment satisfied by all allocations from this all= ocator. > + /// > + /// # Guarantees > + /// > + /// Any pointer allocated by this allocator must be aligned to `MIN_= ALIGN` even if the > + /// requested layout has a smaller alignment. I'd say "is guaranteed to be aligned to" instead, "must be" reads like a requirement. Speaking of which, I think this also needs to be expressed as a safety requirement of the Allocator trait itself, which the specific allocator implementations need to justify. > + const MIN_ALIGN: usize; > + > /// Allocate memory based on `layout` and `flags`. > /// > /// On success, returns a buffer represented as `NonNull<[u8]>` that= satisfies the layout > diff --git a/rust/kernel/alloc/allocator.rs b/rust/kernel/alloc/allocator= .rs > index aa2dfa9dca4c309e5a9eafc7da6a8a9bd7b54b11..25fc9f9ae3b4e471a08d77130= b374bd1397f7384 100644 > --- a/rust/kernel/alloc/allocator.rs > +++ b/rust/kernel/alloc/allocator.rs > @@ -17,6 +17,8 @@ > use crate::bindings; > use crate::pr_warn; > =20 > +const ARCH_KMALLOC_MINALIGN: usize =3D bindings::ARCH_KMALLOC_MINALIGN a= s usize; > + > /// The contiguous kernel allocator. > /// > /// `Kmalloc` is typically used for physically contiguous allocations up= to page size, but also > @@ -128,6 +130,8 @@ unsafe fn call( > // - passing a pointer to a valid memory allocation is OK, > // - `realloc` satisfies the guarantees, since `ReallocFunc::call` has t= he same. > unsafe impl Allocator for Kmalloc { > + const MIN_ALIGN: usize =3D ARCH_KMALLOC_MINALIGN; > + > #[inline] > unsafe fn realloc( > ptr: Option>, > @@ -145,6 +149,8 @@ unsafe fn realloc( > // - passing a pointer to a valid memory allocation is OK, > // - `realloc` satisfies the guarantees, since `ReallocFunc::call` has t= he same. > unsafe impl Allocator for Vmalloc { > + const MIN_ALIGN: usize =3D kernel::page::PAGE_SIZE; > + > #[inline] > unsafe fn realloc( > ptr: Option>, > @@ -169,6 +175,8 @@ unsafe fn realloc( > // - passing a pointer to a valid memory allocation is OK, > // - `realloc` satisfies the guarantees, since `ReallocFunc::call` has t= he same. > unsafe impl Allocator for KVmalloc { > + const MIN_ALIGN: usize =3D ARCH_KMALLOC_MINALIGN; > + > #[inline] > unsafe fn realloc( > ptr: Option>,