From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 314601D12E2 for ; Wed, 21 Aug 2024 11:31:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.43.16 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724239902; cv=none; b=IIZJY7CvlaR7qWH6wkXZw5Xry1eWNnCugO0VFv8aOu5eRyT1bLSXfzpHNZg3bdxqA32IcXGmY4hqKrkpUU5c/cvxH6HsJGSb/0hw9E2d42xJ7jmXwnSvAvOhvBH0bD29dCyr0hWWtJxD1O0bgGXvYSq1xen2vhMyEEhW8rt1Tvc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724239902; c=relaxed/simple; bh=RzmfVrWUhBr3jHRQaWjPRIQ5gWenH0/n2KaMEw1Uu7I=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UWmuLsEmbE2bP68cEwZ5yD3gCr5RLgNFV34AhaTRgNUFMWbEFW4KJXlJgFUzhebXRYKX6Mj5FnK6m54ZBjhcqlHDDZCzy2Ph1F8ljyAPxZw3kmf07CQASPrSEanvw3rV4Qkz3kJ/ldE2xBIav0lECg3RrzL8jKHY1R+rRGGKtPY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me; spf=pass smtp.mailfrom=proton.me; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b=eypalCqS; arc=none smtp.client-ip=185.70.43.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="eypalCqS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=b5zllgnbznfshfdmc3hqiefzqa.protonmail; t=1724239892; x=1724499092; bh=6e+KrV8eK1jYjXKD3gCoNRPU6HnobC3E51PBNfGSs0M=; 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=eypalCqS/3lcRKIK7Itf6QjrE8EkvGixvbUpDqFJK6fAlt8FJgW+ITFZMWlthTOz6 xSroeFZZ7GsNugNqDWeOQnWPyBkTvZZkl4is5J5KPDeNuqjhCmHVrb0emAlYQgmCfB vWnCUuhW7d507QFUztq5qX4AvzRXLfzn/CQdaAW8L7Bo5r3/tfi3lKGrq6l6S7bLbx 5hq6vUKYxBctn+CTihezafbFoo/6L+2gm2CKmTYrLaJ/mhg5U7CXFXecS6UHWBOzLD N19zht4joffrjgFFsNoVvdW/caih+kcyqxj4pxwRnz/h4HZbe38aANWZLFoxmDtreM PrBiEq1ZKPflQ== Date: Wed, 21 Aug 2024 11:31:25 +0000 To: Matthew Maurer , Sami Tolvanen From: Benno Lossin Cc: Greg Kroah-Hartman , Masahiro Yamada , Luis Chamberlain , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Gary Guo , Petr Pavlu , Neal Gompa , Hector Martin , Janne Grunau , Asahi Linux , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, rust-for-linux@vger.kernel.org Subject: Re: [PATCH v2 16/19] gendwarfksyms: Add support for reserved structure fields Message-ID: In-Reply-To: References: <20240815173903.4172139-21-samitolvanen@google.com> <20240815173903.4172139-37-samitolvanen@google.com> <2024081600-grub-deskwork-4bae@gregkh> <2024081705-overarch-deceptive-6689@gregkh> <20240819193851.GA4809@google.com> Feedback-ID: 71780778:user:proton X-Pm-Message-ID: 6a5a4130b8ba58dcb7d4dbdbde33889b843fe919 Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 20.08.24 22:03, Matthew Maurer wrote: >>> The way `KAbiReserved` is implemented is via a `union` (maybe a bit >>> ironic, considering what I said in my other replies, but in this case, >>> we would provide a safe abstraction over this `union`, thus avoiding >>> exposing users of this type to `unsafe`): >>> >>> #[repr(C)] >>> pub union KAbiReserved { >>> value: T, >>> _reserved: R, >>> } >> >> I like this approach even better, assuming any remaining issues with >> ownership etc. can be sorted out. This would also look identical to >> the C version in DWARF if you rename _reserved in the union to >> __kabi_reserved. Of course, we can always change gendwarfksyms to >> support a different scheme for Rust code if a better solution comes >> along later. Yeah sure, that should also then work directly with this patch, right? >> Sami >=20 > Agreement here - this seems like a good approach to representing > reserved in Rust code. A few minor adjustments we discussed off-list > which aren't required for gendwarfksyms to know about: > 1. Types being added to reserved fields have to be `Copy`, e.g. they > must be `!Drop`. > 2. Types being added to reserved fields must be legal to be > represented by all zeroes. > 3. Reserved fields need to be initialized to zero before having their > union set to the provided value when constructing them. > 4. It may be helpful to have delegating trait implementations to avoid > the couple places where autoderef won't handle the conversion. >=20 > While I think this is the right solution, esp. since it can share a > representation with C, I wanted to call out one minor shortfall - a > reserved field can only be replaced by one type. We could still > indicate a replacement by two fields the same as in C, by using a > tuple which will look like an anonymous struct. The limitation will be > that if two or more new fields were introduced, we'd need to edit the > patches accessing them to do foo.x.y and foo.x.z for their accesses > instead of simply foo.y and foo.z - the autoref trick only works for a > single type. We will have to see how often multiple fields are added to a struct. If they are infrequent and it's fine for those patches to then touch the field accesses, then I think we can just stick with this approach. If there are problems with that, we can also try the following: all fields of kABI structs must be private and must only be accessed through setters/getters. We can then modify the body the setters/getters to handle the additional indirection. If that also sounds too much work compared to the C side, then we can get in touch with the Rust language folks and see if they can provide us with a better solution. --- Cheers, Benno