Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp59391ybb; Thu, 19 Mar 2020 11:38:13 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvC754uO8uQVHpkRQ/gDZMoXEvGIpOP1bCTgWw0BsBP5izoIIaDo8fDRO/hbuMXOZwXdewJ X-Received: by 2002:aca:cdcd:: with SMTP id d196mr3512136oig.16.1584643093373; Thu, 19 Mar 2020 11:38:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584643093; cv=none; d=google.com; s=arc-20160816; b=U7PVYdTfptsvL956yrG3V5ZwSmmp7KYWry4SRTrLbYCHygXXk942IWVgDPrQNqs1MC FZ157k0mA67d1TSg+TbADLOgSXyGTJH3crfeh7MSXDvKKgZH1gOLSYdKNQT6fJnOWnEp bcKzL9iyktZu4NXTVw987Ft5yGvjusVPB8ub6Pry08RLpX73gLpToOradqv/kaVQQ6bI 9McY7L5t+gZwORUGEEKw8YXn7CA2CMzuiQEdYPdbWhEsrXmyZRy1Y+YkYx3czW4ueYc0 WpTTGtlfpQfDJKrt0XvuW3lClhKDzw3pdXJaN5ifGLqBntsQg+VLJHBrNFGKj7LXNVnO 2ICw== 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=X1F556ySrolLxsvL0jhUllvjGoin2i3Zub69/qs1TOs=; b=PECfBCNgvMuQm5A275113AmRfsPe+2bR5XyzQ8MdmNudAjxBZmeiW9OL+9fTcAivRo QOfjh0Pgi3s+Yf5z6MEWCW1UH2up+SPInijiqk2VhNj0sYSXUGnQg8N06AInlAYP9ArS R+jSSfoNfRAZg23uqhI5tmGFQ0PYHJJWrnHm+b+KjJWybCDVnHw/i5mwNNKr32WPUdgG kIlGlcqfJcN2u+nn3DiLsB1iRl47NrrKEXCS49ruOqxWtizRrtUP+VA5BzNbfAwftZKr FEuw5CwfTcbxvHl20K2jiVWwuic6P+XCWqqxd/Iu+EY7EDqHuHHak8c/0JtfwhLK7IQP thZg== 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 i19si1643094otp.177.2020.03.19.11.37.59; Thu, 19 Mar 2020 11:38:13 -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 S1727432AbgCSSg3 (ORCPT + 99 others); Thu, 19 Mar 2020 14:36:29 -0400 Received: from albireo.enyo.de ([37.24.231.21]:52338 "EHLO albireo.enyo.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725787AbgCSSg2 (ORCPT ); Thu, 19 Mar 2020 14:36:28 -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 1jF01j-0001Sy-Qw; Thu, 19 Mar 2020 18:36:19 +0000 Received: from fw by deneb.enyo.de with local (Exim 4.92) (envelope-from ) id 1jF00G-0006ml-Aj; Thu, 19 Mar 2020 19:34:48 +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> <20200319144110.3733-5-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> Date: Thu, 19 Mar 2020 19:34:48 +0100 In-Reply-To: <1103782439.4046.1584642531222.JavaMail.zimbra@efficios.com> (Mathieu Desnoyers's message of "Thu, 19 Mar 2020 14:28:51 -0400 (EDT)") Message-ID: <87k13ggpmf.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: > ----- On Mar 19, 2020, at 2:16 PM, Florian Weimer fw@deneb.enyo.de wrote: > >> * Mathieu Desnoyers: >> >>>> You also need to add an assert that the compiler supports >>>> __attribute__ ((aligned)) because ignoring it produces an >>>> ABI-incompatible header. >>> >>> Are you aware of some helper macro I should use to do this, or >>> is it done elsewhere in glibc ? >> >> I don't think we have any such GCC-only types yet. max_align_t is >> provided by GCC itself. > > I was thinking of adding the following to > > sysdeps/unix/sysv/linux/rseq-internal.h: rseq_register_current_thread() > > + /* Ensure the compiler supports __attribute__ ((aligned)). */ > + _Static_assert (__alignof__ (struct rseq_cs) >= 4 * sizeof(uint64_t), > + "alignment"); > + _Static_assert (__alignof__ (struct rseq) >= 4 * sizeof(uint64_t), > + "alignment"); > + Something like it would have to go into the *public* header. Inside glibc, you can assume __attribute__ support. >>>> 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 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. >>> 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.