Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp14179imu; Fri, 14 Dec 2018 13:29:42 -0800 (PST) X-Google-Smtp-Source: AFSGD/Xfmt2aP/S1uuh4zlCWLH7GzgaBVo57j36wXAOYTj2TF3x4cLJZAc+zUPJBq9qXnR+9wmfj X-Received: by 2002:a17:902:2dc3:: with SMTP id p61mr4268147plb.166.1544822982708; Fri, 14 Dec 2018 13:29:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544822982; cv=none; d=google.com; s=arc-20160816; b=benRYM5JONxVsvH3f3HLHi2UA0rONf6yBuyLHTHtwz0oJUKrqKzr0Nv0rWjaV/X1Ym odlxbqHEl9hsa2LJ9tBgQ/HmLocbp7Sv9W4jqRJgXt637Ex95y8NjkutGGyV1Us14QVs 787iYwOBOVRaddWlVZw0fXWsd0uUM7gr+wE74iGugLG4K0No5YTMivHde4nedQFK553t UAwuQw6nmelva+E5EjnJOVzcz41N947pHmXgxHTAU/8Ljelw17mF+gb+4Kglz16FI+u8 pNldOoOtetBTvS9E+TuLzl6A1bXqr8oNet+NcoytLqg6MQJVQFUUC0zGYcDXmelUNNde rY5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=8/NqAApcCj5C7OqdoJV1FeqKlCpZrbbhYFysE31uuj0=; b=iqaAFHKfTpg3T4cZagM4t7Zv/8ZTML+QZ+ecEJ0fniyMPC0xD9LLTGODBtefoX4ghJ BHv7V6TGBnRc6tBbEj4afOd4+gNt/NLy8APo9MVeNWxWevHRNDqf4V0Ldwth0QGlKdWB UhDTrmclvYsqZdnzi1UFgp8MRGzLCGkpwpksjzk2D0N70BdQVK3n6cyzrFJNPkaRH0lX n0OLBfDL9mrnjbBA2FvZWxPpWCRvMVXUG+R9Ggc3dk2K8sH4GGYtBxqenepVLuGaDrc0 8ZA6wKU8dVZuHgaz6O/ny1MwkwHBK/7jmIkTnt1GNRMRFyJt8UscChYPISTrCveIHsjt xWfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=a6CTSq7Q; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q70si4884910pgq.526.2018.12.14.13.29.27; Fri, 14 Dec 2018 13:29:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=a6CTSq7Q; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731106AbeLNV14 (ORCPT + 99 others); Fri, 14 Dec 2018 16:27:56 -0500 Received: from mail.kernel.org ([198.145.29.99]:35844 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731002AbeLNV14 (ORCPT ); Fri, 14 Dec 2018 16:27:56 -0500 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EFA82208D6 for ; Fri, 14 Dec 2018 21:27:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544822875; bh=HK4EZoN/x8yhV5AMLAZsG+bi63RBmNN8mPffPJvdlSc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=a6CTSq7QRqje6V8sWpr5qRD9dEjHxW8RZ5XtANKfhAKxgr8lLsf3jbRWwkZq8kfSW AEzoh5NYmUR53vSJR3xT9Weh2ryTR6OZ0ifb1coL5KR0fngAdF95GuvMVeGE8vj44P LTCL+wVC3oAIyRnVCv3qS5Bqn461OR5HaTqqI7bA= Received: by mail-wm1-f52.google.com with SMTP id c126so7114226wmh.0 for ; Fri, 14 Dec 2018 13:27:54 -0800 (PST) X-Gm-Message-State: AA+aEWZ4N54pRh/8zvnTEyPGovOctAFoOjeC2w3JC+vUPWIilTbZlx5n dIg9smFr+6FtNv0gbw9uHj0u5x2nKvgmlFlDTygE6w== X-Received: by 2002:a1c:aa0f:: with SMTP id t15mr4382647wme.108.1544822872875; Fri, 14 Dec 2018 13:27:52 -0800 (PST) MIME-Version: 1.0 References: <70bb54b2-8ed3-b5ee-c02d-6ef66c4f27eb@physik.fu-berlin.de> <20181213160242.GV23599@brightrain.aerifal.cx> <20181214161732.GY23599@brightrain.aerifal.cx> <87mup8gj1y.fsf@oldenburg2.str.redhat.com> <20181214165535.GZ23599@brightrain.aerifal.cx> In-Reply-To: From: Andy Lutomirski Date: Fri, 14 Dec 2018 13:27:40 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Can we drop upstream Linux x32 support? To: Linus Torvalds Cc: Rich Felker , Florian Weimer , Bernd Petrovitsch , John Paul Adrian Glaubitz , Andrew Lutomirski , X86 ML , LKML , Linux API , "H. Peter Anvin" , Peter Zijlstra , Borislav Petkov , Mike Frysinger , "H. J. Lu" , x32@buildd.debian.org, Arnd Bergmann , Will Deacon , Catalin Marinas Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 14, 2018 at 12:13 PM Linus Torvalds wrote: > > On Fri, Dec 14, 2018 at 10:58 AM Andy Lutomirski wr= ote: > > > > Does anyone know *why* Linux=E2=80=99s x32 has __kernel_long_t defined = as long long? > > It *needs* to be long long, since the headers are used for builds in > user mode using ILP32. > > Since __kernel_long_t is a 64-bit (the _kernel_ is not ILP32), you > need to use "long long" when building in ILP32. > > Obviously, it could be something like > > #ifdef __KERNEL__ > typedef long __kernel_long_t; > #else > typedef long long __kernel_long_t; > #endif > > or similar to make it more obvious what's going on. > > Or we could encourage all the uapi header files to always just use > explicit sizing like __u64, but some of the structures really end up > being "kernel long size" for sad historical reasons. Not lovely, but > there we are.. > This is probably water under the bridge, but I disagree with you here. Or rather, I agree with you in principle but I really don't like the way it turned out. For legacy uapi structs (and probably some new ones too, sigh), as a practical matter, user code is going to shove them at the C compiler, and the C compiler is going to interpret them in the usual way, and either we need a usermode translation layer or the kernel needs to deal with the result. It's a nice thought that, by convincing an x32 compiler that __kernel_long_t is 64 bits, we end up with the x32 struct being compatible with the native Linux struct, but it only works for structs where the only ABI-dependent type is long. But the real structs in uapi aren't all like this. We have struct iovec: struct iovec { void __user *iov_base; /* BSD uses caddr_t (1003.1g requires void = *) */ __kernel_size_t iov_len; /* Must be size_t (1003.1g) */ }; Whoops, this one looks the same on x32 and i386, but neither one of them match x86_64, and, just randomly grepping around a bit, I see: struct snd_hwdep_dsp_image { unsigned int index; /* W: DSP index */ unsigned char name[64]; /* W: ID (e.g. file name) */ unsigned char __user *image; /* W: binary image */ size_t length; /* W: size of image in bytes */ unsigned long driver_data; /* W: driver-specific data */ }; struct __sysctl_args { int __user *name; int nlen; void __user *oldval; size_t __user *oldlenp; void __user *newval; size_t newlen; unsigned long __unused[4]; }; If these had been switched from "unsigned long" to __kernel_ulong_t, they would have had three different layouts on i386, x32, and x86_64. So now we have a situation where, if we were to make x32 work 100%, the whole kernel would need to recognize that there are three possible ABIs, not two. And this sucks. So I think it would have been a better choice to let long be 32-bit on x32 and to therefore make x32 match the x86_32 "compat" layout as much as possible. Sure, this would make x32 be more of a second-class citizen, but I think it would have worked better, had fewer bugs, and been more maintainable. --Andy