Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp87861ybb; Thu, 19 Mar 2020 12:09:05 -0700 (PDT) X-Google-Smtp-Source: ADFU+vt1fAHTH2RXcGC0QRIZ5Hq3C9Ms0yQA7H5dEAa7yXPkdHCBTwDIRepfjxiUkTIrz0ifnj5K X-Received: by 2002:aca:47c8:: with SMTP id u191mr3717543oia.170.1584644945396; Thu, 19 Mar 2020 12:09:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584644945; cv=none; d=google.com; s=arc-20160816; b=NdjDCTEr5Kdx6pYOlhPSPKYz9h7hlyckz4/wTZY6LU1xvCsHjU15uUZQ0k9ET9UlbE 9EXhYPG9v04wajQnUgcmvYVeriPZMnUtReQvoII4e303sUhY2YkfHf3G0w4QzzoXE5jM uKa4k1X+xOPQ+9+Dr4PDq8fZVy4r32lU4VVPeDe54Bj088SQpEgqZ8OUgGzBbOU+YNEW hxK2E6wuY+9TyPb2ywhg1RkKdP1Z2SfXfqwJxuO8VEcK1dfk8HPrTnUVc5Sb/Ai/bc6a NAqka3wS1h7/5I3EgMwuncc/JwHT/AUbEeUEPLDXj6XRiBoXyMjzonYRZrWBgut/JbW2 D4hA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:in-reply-to:date :references:subject:cc:to:from; bh=OgwR/EyEnn6C5Iq59wCiSx1Fgh2TDv8F/jqzE1OpWYI=; b=dWUgZWMWvnDPC6qWvIO2k5mJX7XIDgtx/QxsbB4KZtLP5kD6c6idlUX67f+t3WXUQQ c67+nvvvC4DqNePVgaAr+hmOpKLwzD4eTyPa9tbDslwKU+oUhTaj9nKjvja+gg1fjB5I I7dBJ0NnWZTjf1P+VMZaZXUgk3S29OP9LU3M07CIoqqhVIYYkB7Fmdn2tkNjVpB2k7JP Z3RU8rA55ResxW0toYlKBdg5wYMi927GroVSbOBxmZ0Mrw8Onl6bKQjDhRZorawwD8Ly Ju9bzvZo/WL57wBp9QXPtXsHKpfIl9KYQzlHbmAfatEDiwPnNMl1+xTd+u3ESbb+dWlC yYBA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l11si1430564oib.32.2020.03.19.12.08.51; Thu, 19 Mar 2020 12:09:05 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727433AbgCSTHS (ORCPT + 99 others); Thu, 19 Mar 2020 15:07:18 -0400 Received: from albireo.enyo.de ([37.24.231.21]:52842 "EHLO albireo.enyo.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727256AbgCSTHR (ORCPT ); Thu, 19 Mar 2020 15:07:17 -0400 Received: from [172.17.203.2] (helo=deneb.enyo.de) by albireo.enyo.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) id 1jF0VY-00029N-1A; Thu, 19 Mar 2020 19:07:08 +0000 Received: from fw by deneb.enyo.de with local (Exim 4.92) (envelope-from ) id 1jF0UB-00083N-Mg; Thu, 19 Mar 2020 20:05:43 +0100 From: Florian Weimer To: Mathieu Desnoyers Cc: libc-alpha , carlos , Rich Felker , linux-api , Boqun Feng , Will Deacon , linux-kernel , Peter Zijlstra , Ben Maurer , Dave Watson , Thomas Gleixner , Paul , Paul Turner , Joseph Myers Subject: Re: [RFC PATCH glibc 4/8] glibc: Perform rseq(2) registration at C startup and thread creation (v15) References: <20200319144110.3733-1-mathieu.desnoyers@efficios.com> <874kukpf9f.fsf@mid.deneb.enyo.de> <2147217200.3240.1584633395285.JavaMail.zimbra@efficios.com> <87r1xo5o2s.fsf@mid.deneb.enyo.de> <1302331358.3965.1584641354569.JavaMail.zimbra@efficios.com> <87sgi4gqhf.fsf@mid.deneb.enyo.de> <1103782439.4046.1584642531222.JavaMail.zimbra@efficios.com> <87k13ggpmf.fsf@mid.deneb.enyo.de> <900536577.4062.1584644126425.JavaMail.zimbra@efficios.com> Date: Thu, 19 Mar 2020 20:05:43 +0100 In-Reply-To: <900536577.4062.1584644126425.JavaMail.zimbra@efficios.com> (Mathieu Desnoyers's message of "Thu, 19 Mar 2020 14:55:26 -0400 (EDT)") Message-ID: <87fte4go6w.fsf@mid.deneb.enyo.de> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Mathieu Desnoyers: >> Inside glibc, you can assume __attribute__ support. > > OK, so the _Static_assert () could sit in sys/rseq.h It requires a C11 compiler. In this case, you could use _Alignas. > >> >>>>>> The struct rseq/struct rseq_cs definitions >>>>>> are broken, they should not try to change the alignment. >>>>> >>>>> AFAIU, this means we should ideally not have used __attribute__((aligned)) >>>>> in the uapi headers in the first place. Why is it broken ? >>>> >>>> Compilers which are not sufficiently GCC-compatible define >>>> __attribute__(X) as the empty expansion, so you silently get a >>>> different ABI. >>> >>> It is worth noting that rseq.h is not the only Linux uapi header >>> which uses __attribute__ ((aligned)), so this ABI problem exists today >>> anyway for those compilers. >> >> Yuck. Even with larger-than-16 alignment? > > There are two: > > target_core_user.h > 45:#define ALIGN_SIZE 64 /* Should be enough for most CPUs */ > 58: __u32 cmd_tail __attribute__((__aligned__(ALIGN_SIZE))); That one is tough to figure out: struct tcmu_mailbox { __u16 version; __u16 flags; __u32 cmdr_off; __u32 cmdr_size; __u32 cmd_head; /* Updated by user. On its own cacheline */ __u32 cmd_tail __attribute__((__aligned__(ALIGN_SIZE))); } __attribute__((packed)); Apparently, the expectation is that the compiler ignores __attribute__ ((packed) in this context. Ugh. > netfilter_bridge/ebtables.h:90: char data[0] __attribute__ ((aligned (__alignof__(struct ebt_replace)))); > netfilter_bridge/ebtables.h:132: unsigned char data[0] __attribute__ ((aligned (__alignof__(struct ebt_replace)))); > netfilter_bridge/ebtables.h:145: unsigned char data[0] __attribute__ ((aligned (__alignof__(struct ebt_replace)))); > netfilter_bridge/ebtables.h:158: unsigned char data[0] __attribute__ ((aligned (__alignof__(struct ebt_replace)))); > netfilter_bridge/ebtables.h:191: unsigned char elems[0] __attribute__ ((aligned (__alignof__(struct ebt_replace)))); I think these values are lower than max_align_t, so uncritical. >>>> There is really no need to specify 32-byte alignment here. Is not >>>> even the size of a standard cache line. It can result in crashes if >>>> these structs are heap-allocated using malloc, when optimizing for >>>> AVX2. >>> >>> Why would it be valid to allocate those with malloc ? Isn't it the >>> purpose of posix_memalign() ? >> >> It would not be valid, but I don't think we have diagnostics for C >> like we have them for C++'s operator new. > > We could at least make an effort to let people know that alignment is > required here when allocating struct rseq and struct rseq_cs on the > heap by adding some comments to that effect in linux/rseq.h ? We could use different types on the glibc side, then no special programmer action will be needed. >>>>> However, now that it is in the wild, it's a bit late to change that. >>>> >>>> I had forgotten about the alignment crashes. I think we should >>>> seriously consider changing the types. 8-( >>> >>> I don't think this is an option at this stage given that it is part >>> of the Linux kernel UAPI. I am not convinced that it is valid at all >>> to allocate struct rseq or struct rseq_cs with malloc(), because it >>> does not guarantee any alignment. >> >> The kernel ABI doesn't change. The kernel cannot use the alignment >> information anyway. Userspace struct layout may change in subtle >> ways, though. > > Considering the amount of pain this can cause in user-space, and because > it can break userspace, this is not a UAPI change I am willing to consider. > I'm not sure why we are even discussing the possibility of breaking a Linux > UAPI considering that those are set in stone. Again, the kernel interface is NOT affected. Only if the struct is used in a non-top-level fashion across an ABI boundary in userspace. I think making the change now is better than dealing with the breakage in rseq users when they are built with -mavx2.