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 1EEC8C83F17 for ; Tue, 15 Jul 2025 16:00:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8FB566B0095; Tue, 15 Jul 2025 12:00:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8AB926B0096; Tue, 15 Jul 2025 12:00:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7C1776B009A; Tue, 15 Jul 2025 12:00:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 6D30E6B0095 for ; Tue, 15 Jul 2025 12:00:22 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id EE4D5804FF for ; Tue, 15 Jul 2025 16:00:21 +0000 (UTC) X-FDA: 83666961042.10.4A126F1 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf28.hostedemail.com (Postfix) with ESMTP id 44BD9C0020 for ; Tue, 15 Jul 2025 16:00:20 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=jGaf+6DZ; spf=pass (imf28.hostedemail.com: domain of lossin@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=lossin@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=1752595220; 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=cHYhq28lvyUpon9eHP4iwGZJUP49oJExV/WlWaGZcoY=; b=JL9e6dQaWE7BIyczxFVVILlUWG9Z0nQRsaYIFXxKezQn0nUlm3ZnVx987xAa8umKa100x7 6neeCldEvluOxVsKq2JcNRyjj6UhTBzYA4b8Dt2PERh8lFwL4acrMnw+N0SY4VcXmlhjCs Xucqx1nin6nRd+a/Cel/WKnC+g6bl/s= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1752595220; a=rsa-sha256; cv=none; b=fYV+FOC0u0ckg/IniWm2ZGMfScp1GeCUR5q4Wn1sxYewtblFVVP4BOkr3eSDYKQfbY3NzU f+yUPl+xgOcTJsH66Sb7Wp6CRbg9+kiCxYlp05fmepude/y6+hvYQYEelf6nw9FhOqLAa7 M5l/gUR/1L7SVDN3ftsvRtRQ1W2KipE= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=jGaf+6DZ; spf=pass (imf28.hostedemail.com: domain of lossin@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=lossin@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 8EBAFA57181; Tue, 15 Jul 2025 16:00:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28EDFC4CEF1; Tue, 15 Jul 2025 16:00:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1752595219; bh=NFRRAPbroRcvQO7QrkrwIOxWqkuN0ik8gVTjoc3MuBU=; h=Date:Cc:Subject:From:To:References:In-Reply-To:From; b=jGaf+6DZBhfFDtMRlzIuwww6S27E7wxGMCcofLroSTG1Ehn//IjQfvrM7iYnaRAQt pzIXQhxzzIFeilFzRhmPpUDNRztCwE/0YnH5oY1xLvpRMrFr46+UiU5iUJvSSh+0v7 9sMk0zr40AFePOi9hTnsUflJEWKXEASkox+ivR16tJ16FrGu8vbbMuwx1iDmzuznVn NWScGbnGI2DIY973GiIVaWPMaWXPx7wJJ6MOmEtXbS56c/IaoophlBlwjIhSUncALw b5MQkdC8qGpK/mnrKNLHEZT/5SUGIN1v/eUcHrLKFbbUumh5rjJm9j8RLZ1vwoaN6C pdqglOeP3JCNQ== Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Tue, 15 Jul 2025 18:00:14 +0200 Message-Id: Cc: "Boqun Feng" , "Gary Guo" , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , "Trevor Gross" , , , Subject: Re: [PATCH 2/2] rust: alloc: take the allocator into account for FOREIGN_ALIGN From: "Benno Lossin" To: "Alice Ryhl" , "Lorenzo Stoakes" , "Liam R. Howlett" , "Andrew Morton" , "Danilo Krummrich" , "Matthew Wilcox" , "Tamir Duberstein" , "Andreas Hindborg" , "Miguel Ojeda" X-Mailer: aerc 0.20.1 References: <20250715-align-min-allocator-v1-0-3e1b2a5516c0@google.com> <20250715-align-min-allocator-v1-2-3e1b2a5516c0@google.com> In-Reply-To: <20250715-align-min-allocator-v1-2-3e1b2a5516c0@google.com> X-Rspamd-Queue-Id: 44BD9C0020 X-Stat-Signature: pf7qpus4xaeukk366igng3xsifwzbr1k X-Rspam-User: X-Rspamd-Server: rspam07 X-HE-Tag: 1752595220-952345 X-HE-Meta: U2FsdGVkX1+srLIucE9fPvcigS9onJmY5wx+qqNiEf6RAUNljNPDu4QMXsySOYzy85QeoBHD4J/alT8M/1IVOtRdJeQDmQ30GwWMIS8xxQrEQyfnvQZhRdcBPbvuBKlez46QSmvcma3P4Iw7wfxlrbXfXkSWOFfmaaLYWplQIPStWM9y2GKG2YhYfQWeY8mHRdCN1LTFPdX5+LTHDcsxhRjgl3GaD4OA/bVbgj1mO5bHbYC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TIR2U23ybbrbTN2gYnDbfyk3uNjadZDmFeK9COjW0CksPe5nsaMCAfJGEwokggYkkK/nhtyA+UfiXdrZauyyUJhLsTQIx78Eyj76Rgqx 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: On Tue Jul 15, 2025 at 3:46 PM CEST, Alice Ryhl wrote: > When converting a Box into a void pointer, the allocator might > guarantee a higher alignment than the type itself does, and in that case > it is guaranteed that the void pointer has that higher alignment. > > This is quite useful when combined with the XArray, which you can only > create using a ForeignOwnable whose FOREIGN_ALIGN is at least 4. This > means that you can now always use a Box with the XArray no matter the > alignment of T. > > Signed-off-by: Alice Ryhl Hey this is cool! Reviewed-by: Benno Lossin One question below. > --- > rust/kernel/alloc/kbox.rs | 15 +++++++++++---- > rust/kernel/sync/arc.rs | 6 +++--- > 2 files changed, 14 insertions(+), 7 deletions(-) > diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs > index 63a66761d0c7d752e09ce7372bc230661b2f7c6d..74121cf935f364c16799b5c31= cc88714dfd6b702 100644 > --- a/rust/kernel/sync/arc.rs > +++ b/rust/kernel/sync/arc.rs > @@ -373,10 +373,10 @@ pub fn into_unique_or_drop(self) -> Option>> { > } > } > =20 > -// SAFETY: The pointer returned by `into_foreign` comes from a well alig= ned > -// pointer to `ArcInner`. > +// SAFETY: The pointer returned by `into_foreign` was originally allocat= ed as an > +// `KBox>`, so that type is what determines the alignment. > unsafe impl ForeignOwnable for Arc { > - const FOREIGN_ALIGN: usize =3D core::mem::align_of::>(); > + const FOREIGN_ALIGN: usize =3D > as ForeignOwnable>= ::FOREIGN_ALIGN; Do we at some point also want to give people the option to use vmalloc for `Arc`? --- Cheers, Benno > =20 > type Borrowed<'a> =3D ArcBorrow<'a, T>; > type BorrowedMut<'a> =3D Self::Borrowed<'a>;