Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1160038rdg; Fri, 13 Oct 2023 12:02:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHH/hHGTHY06Atgrkt04jIa2jre6n+NWYxMEKh0tgK9PlsHD/b3yTCxF6NUtgkbdnzGYvgY X-Received: by 2002:a17:902:d4c7:b0:1c8:9d32:3396 with SMTP id o7-20020a170902d4c700b001c89d323396mr13759507plg.60.1697223747803; Fri, 13 Oct 2023 12:02:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697223747; cv=none; d=google.com; s=arc-20160816; b=SYS8MrZ3lQHO36lgoMb5cX9tMU4YMWmlxXwweTSgKlbwKUcuL/TKnVic+jLtsG1+EN kusYHAdTSCWGBW3K4HEaq4EZOLlzsiNixEZKOwqLyXg4hamTufadbrf8ivRYPZg9lZV2 kXP1hVyvhNr6yyoXopnEerOVFlC/ISVCGOHHHqZHzpY8kje/RJYb0HEG0OYniVX74ZFG P/yCSqUqiNMB3wDQuwrG+Oqj+6P9ZrchPZZEjKBdRExszEks4QHyPH7BcKZwnInuaPaS XBMdE7zuMrrAdmUtfR9zTLbgKue4SaSJtZzcXbfiyFzsCSC16BMqOJwIDKAtCGJWL+IH TpiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:references:in-reply-to:user-agent:subject:cc:to:from :date:dkim-signature:dkim-filter; bh=T1PyI12qkzl7tC8w46EdkMYBVYGjCYpIgqARTxewv6c=; fh=aAmYIU9A64fU2KcICYY2P+Vr3nsv9MLo6uFLWhQ2cCo=; b=z961BLWNdyYmOF6TqfHDwcwgiwBbKcWsjfkBUN0iE9mTiWDzpTpBiYyxpo465YCKTA H/uehWyAdMrMDCwZcge/9LBSmZtK5xXSkzqZkQIHki0aaCGT53zk1jRSUbWDE9MV7qIu gtshcAJpcvYi4hy8N9sJmu1SXdQg4HDtVON6e0TpZ1NF3nL7UmbJRajtM4wRdnOONd0Z AqFCzWXAZTdH4U7neL2+TPlofylWnQUs1hQAwSj1CvTbHmpHlWY1Xdqvpd5dVH+0WXkL wuVhsrA+cZBq41/RIJEN3goFXtBmgkM8T/b+DfvrknFcuihRcOmeAawD5sC30oNwjL9U JKTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zytor.com header.s=2023091101 header.b=uV8K0ah0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id y13-20020a17090322cd00b001bdd35033efsi5579708plg.374.2023.10.13.12.02.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 12:02:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@zytor.com header.s=2023091101 header.b=uV8K0ah0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id DD5DD823CD25; Fri, 13 Oct 2023 12:02:24 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231465AbjJMTCP (ORCPT + 99 others); Fri, 13 Oct 2023 15:02:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231336AbjJMTCO (ORCPT ); Fri, 13 Oct 2023 15:02:14 -0400 Received: from mail.zytor.com (unknown [IPv6:2607:7c80:54:3::138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 389D2A9; Fri, 13 Oct 2023 12:02:13 -0700 (PDT) Received: from [127.0.0.1] ([98.35.210.218]) (authenticated bits=0) by mail.zytor.com (8.17.1/8.17.1) with ESMTPSA id 39DJ09gY2258410 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NO); Fri, 13 Oct 2023 12:00:09 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 39DJ09gY2258410 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2023091101; t=1697223611; bh=T1PyI12qkzl7tC8w46EdkMYBVYGjCYpIgqARTxewv6c=; h=Date:From:To:CC:Subject:In-Reply-To:References:From; b=uV8K0ah0Z4rbshQs+Czco0l8mB3q3iMcNvCm1pFyMA5KNzw6uq5eHqrr/l3Wj56I+ LWIyHctEy0tPK17/dZT2XQ0k635l+scnK0GbWt26cVgut5wpkHokSpe2FMNcYxVajY Gv5rejcpqLJo3qm0Bn0hGIf3CV/VJc/AJ5ymm+vWHt45Job1rg5iHElHRTzdmCymml fuzEWHWZpgw6WoCKpa8a8qBXT4ja3TPzCTB/2ELv8u75GnBmGU9FWVFacpSB3IaeuC 4IDxdaHk5P3sETW5QYJxU2gFbtPVuy4wSRK3DeVYC7FyXI+K2+h6i6vrbIpOBE37RE wluBPN3GuXb4g== Date: Fri, 13 Oct 2023 12:00:06 -0700 From: "H. Peter Anvin" To: Linus Torvalds , Ramon de C Valle CC: Peter Zijlstra , Kees Cook , Sami Tolvanen , Miguel Ojeda , Miguel Ojeda , Greg Kroah-Hartman , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, patches@lists.linux.dev, Jarkko Sakkinen , Alex Gaynor , Wedson Almeida Filho , David Gow , Boqun Feng , Gary Guo , =?ISO-8859-1?Q?Bj=F6rn_Roy_Baron?= , Jonathan Corbet , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, linux-doc@vger.kernel.org Subject: Re: [PATCH v10 25/27] x86: enable initial Rust support User-Agent: K-9 Mail for Android In-Reply-To: References: <20220927131518.30000-1-ojeda@kernel.org> <20220927131518.30000-26-ojeda@kernel.org> <20231012104741.GN6307@noisy.programming.kicks-ass.net> <202310121130.256F581823@keescook> <20231013075005.GB12118@noisy.programming.kicks-ass.net> Message-ID: <5D8CA5EF-F5B0-4911-85B8-A363D9344FA7@zytor.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 13 Oct 2023 12:02:25 -0700 (PDT) On October 13, 2023 11:54:46 AM PDT, Linus Torvalds wrote: >On Fri, 13 Oct 2023 at 05:18, Ramon de C Valle wro= te: >> >> Both C and repr(C) Rust structs have this encoding, but I understand >> the problems with doing this in C since it doesn't have >> repr(transparent) structs so there would be a lot of casting back and >> forth=2E Maybe there is an alternative or this could be done for less >> used function pairs? > >We actually have some C variations of what I think people want to use >"repr(transparent) struct" for in Rust=2E > >Of course, that is depending on what kind of context you want to use >it for, and I might have lost some background=2E But I'm assuming you're >talking about the situation where you want to treat two or more types >as being "compatible" within certain contexts=2E > >There's the actual standard C "_Generic()" alternative, which allows >you to make macros etc that use different types transparently=2E > >It's not very widely used in the kernel, because we only fairly >recently moved to require recent enough compiler versions, but we do >use it now in a couple of places=2E > >And there's the much more traditional gcc extension in the form of the >__attribute__((__transparent_union__)) thing=2E In the kernel, that one >is even less used, and that one use is likely going away since the >need for it is going away=2E > >But while it's not standard C, it's actually been supported by >relevant compilers for much longer than "_Generic" has, and is >designed exactly for the "I have a function that can take arguments of >different types", either because the types are bitwise identical (even >if _conceptually_ not the same), or simply because you have a >different argument that describes the type (the traditional C union >model)=2E > >I suspect, for example, that we *should* have used those transparent >unions for the "this function can take either a folio or a page" case, >instead of duplicating functions for the two uses=2E > >But probably because few people aren familiar with the syntax, that's >not what happened=2E > > Linus Transparent unions have been standard C since C99=2E