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 8B0F0EE49A6 for ; Wed, 11 Sep 2024 13:26:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 044D2940038; Wed, 11 Sep 2024 09:26:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F36D2940021; Wed, 11 Sep 2024 09:26:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E4C69940038; Wed, 11 Sep 2024 09:26:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id C7219940021 for ; Wed, 11 Sep 2024 09:26:42 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 38661AACC3 for ; Wed, 11 Sep 2024 13:26:42 +0000 (UTC) X-FDA: 82552532244.18.E5C43B4 Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) by imf11.hostedemail.com (Postfix) with ESMTP id 67BD54000F for ; Wed, 11 Sep 2024 13:26:40 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=proton.me header.s=protonmail header.b=OWTe8+Za; spf=pass (imf11.hostedemail.com: domain of benno.lossin@proton.me designates 185.70.43.22 as permitted sender) smtp.mailfrom=benno.lossin@proton.me; dmarc=pass (policy=quarantine) header.from=proton.me ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1726061096; 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=J6IXT1iZln99Z1mMtpC22DQ9PHW+aiWMF/43PDKIl5o=; b=Qgjmk6UopxemBwFs8Aw+1Nd2DdkpTUfkkfVb1wwf9JkujOKJJVbCiwZ+DH0iztTUrmRA/M uBkTRE3robf8nQcg0xxZNWZYRdCGGHBhhHZ5ctdm5nCsk40CNVoeoYseHcyuRKkLQU0mVA mfqZcYrDRx6YFUfXUVj3+MeeER798sc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726061096; a=rsa-sha256; cv=none; b=D546328TX3IgWzR+WssahFF10qmc218N4Z/u6iAI3A/nxpNQKFMPW9wgC+khq2L8VK6q47 tdPq1y2FzjMU98MrhgMayl2fth+eGjCngSdGzg/K33oGQf7rbeSsw9m+Q38yGUD6V2LUOF +Ccn/vxr5dpvsQBfTdeI5zv3kVZULAQ= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=proton.me header.s=protonmail header.b=OWTe8+Za; spf=pass (imf11.hostedemail.com: domain of benno.lossin@proton.me designates 185.70.43.22 as permitted sender) smtp.mailfrom=benno.lossin@proton.me; dmarc=pass (policy=quarantine) header.from=proton.me DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1726061198; x=1726320398; bh=J6IXT1iZln99Z1mMtpC22DQ9PHW+aiWMF/43PDKIl5o=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=OWTe8+Zacu+2pKXJFf6kbs3SyVbwAT9BpOmPh6uTE9T4aZsxDqT1+jZmhStMBjOSv DvxnBP2PbBeMaTck4M4kNQXAAcf8oNBiQF6erNKShmWMP278lnhRO4v5T2PnvRtkwU j1gORkWe4RLMKkf2pbxI0c5hU1erjpSTyRRAj08zAmqhA6regLcImzMO9O7gGZ0pf3 6S+Zs2Ar7Cf6wFrGWV2RcnLbdIszZNwgIjA7x0sKawwHiuXz9rD+YK+9AAhO8rzFuI Tc5S7gBUD2KdGBGBpzKvu68iijC8pPVxWn6bI0WAyhK4C7jiyf17334xWU8RMsbNQg QEe8A6uMVxFeQ== Date: Wed, 11 Sep 2024 13:26:32 +0000 To: Danilo Krummrich From: Benno Lossin Cc: ojeda@kernel.org, alex.gaynor@gmail.com, wedsonaf@gmail.com, boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, a.hindborg@samsung.com, aliceryhl@google.com, akpm@linux-foundation.org, daniel.almeida@collabora.com, faith.ekstrand@collabora.com, boris.brezillon@collabora.com, lina@asahilina.net, mcanal@igalia.com, zhiw@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 Subject: Re: [PATCH v6 09/26] rust: alloc: implement kernel `Box` Message-ID: In-Reply-To: References: <20240816001216.26575-1-dakr@kernel.org> <20240816001216.26575-10-dakr@kernel.org> <0146cb78-5a35-4d6b-bc75-fed1fc0c270c@proton.me> <19d81a27-9600-4990-867c-624104e3ad83@proton.me> <77b91448-a21e-4e1b-9a8e-3d2052d79a78@proton.me> Feedback-ID: 71780778:user:proton X-Pm-Message-ID: 151627c16fe706231a6a0e475a335428846fcd46 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 67BD54000F X-Stat-Signature: tt6sjenzh1rhhe3qpsum6ftdu1ixx1qa X-HE-Tag: 1726061200-892860 X-HE-Meta: U2FsdGVkX19+61WycrR/clo7fIjHcCA7i11mJbepfTn1MS7dn8lRn34YBEi8H9t4GQ+X1Tpp6YpfbnVyLKR+qmpiavv7Nys3yWfs5dxnhKsmM71cAmGbeXgQsxKGaYhbH554rBrxJcgcTG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0uUeeojN61oxukkNvBE0Myds+ed2NVsbjrsRFxQ1OO/w/Le0Hg+Rhzoc2QL3yMTIK/+HltymZHRAeNq1aKkiMipbgyXoutX4xnMLMSlK3C5XQdgOq7sPWKjkXDQ66ndrd18ZzVUV7O14I57kqUbG0fCYXwpW9S7N1PMzOI7g87a5SawOFy0eTBINXjKXU7HaQN43EAokma+oTSaMLWWKYhy6p2EYcZff35GmX9+v6ClJR2F4uZkkv1QcVxcs3fxeY= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, 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 11.09.24 13:02, Danilo Krummrich wrote: > On Wed, Sep 11, 2024 at 08:36:38AM +0000, Benno Lossin wrote: >> On 11.09.24 01:25, Danilo Krummrich wrote: >>> On Tue, Sep 10, 2024 at 07:49:42PM +0000, Benno Lossin wrote: >>>> On 10.09.24 19:40, Danilo Krummrich wrote: >>>>> On Sat, Aug 31, 2024 at 05:39:07AM +0000, Benno Lossin wrote: >>>>>> On 16.08.24 02:10, Danilo Krummrich wrote: >>>>>>> +/// >>>>>>> +/// ``` >>>>>>> +/// # use kernel::bindings; >>>>>>> +/// const SIZE: usize =3D bindings::KMALLOC_MAX_SIZE as usize + 1; >>>>>>> +/// struct Huge([u8; SIZE]); >>>>>>> +/// >>>>>>> +/// assert!(KVBox::::new_uninit(GFP_KERNEL).is_ok()); >>>>>>> +/// ``` >>>>>> >>>>>> Similarly, you could then say above this one "Instead use either `VB= ox` >>>>>> or `KVBox`:" >>>>>> >>>>>>> +/// >>>>>>> +/// # Invariants >>>>>>> +/// >>>>>>> +/// The [`Box`]' pointer is always properly aligned and either poi= nts to memory allocated with `A` >>>>>> >>>>>> Please use `self.0` instead of "[`Box`]'". >>>>>> >>>>>>> +/// or, for zero-sized types, is a dangling pointer. >>>>>> >>>>>> Probably "dangling, well aligned pointer.". >>>>> >>>>> Does this add any value? For ZSTs everything is "well aligned", isn't= it? >>>> >>>> ZSTs can have alignment and then unaligned pointers do exist for them >>>> (and dereferencing them is UB!): >>> >>> Where is this documented? The documentation says: >>> >>> "For operations of size zero, *every* pointer is valid, including the n= ull >>> pointer. The following points are only concerned with non-zero-sized ac= cesses." >>> [1] >> >> That's a good point, the documentation looks a bit outdated. I found >> this page in the nomicon: https://doc.rust-lang.org/nomicon/vec/vec-zsts= .html >> The first iterator implementation has an alignment issue. (Nevertheless, >> that chapter of the nomicon is probably useful to you, since it goes >> over implementing `Vec`, but maybe you already saw it) >> >>> [1] https://doc.rust-lang.org/std/ptr/index.html >> >> Might be a good idea to improve/complain about this at the rust project. >=20 > Well, my point is how do we know? There's no language specification and t= he > documentation is (at least) ambiguous. So I went through the unsafe-coding-guidelines issues list and only found this one: https://github.com/rust-lang/unsafe-code-guidelines/issues/= 93 Maybe I missed something. You could also try to ask at the rust zulip in the t-opsem channel for further clarification. I think we should just be on the safe side and assume that ZSTs require alignment. But if you get a convincing answer and if they say that they will document it, then I don't mind removing the alignment requirement. --- Cheers, Benno