Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp75878ybb; Thu, 19 Mar 2020 11:57:16 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsvIwqJQm7B+Y20OrWxBYxoB8cfs3FT0G86eTxsuDQwfl7XIv2hFEaEu8zLY+c+kMMyXM1w X-Received: by 2002:a05:6830:60a:: with SMTP id w10mr3724014oti.292.1584644236184; Thu, 19 Mar 2020 11:57:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584644236; cv=none; d=google.com; s=arc-20160816; b=OEnJ11uwtKKPOru6HseeoMNVoTTaqf5jNkhMzd4mU7qZP6f84xsLOwdIP05RntQUyl +62uSa0xf0rDtGuf4LCeqkVDqZtM2j0vnJ5bLWPH+Q9xhnh1q5++a86cxTjaEJnJdxIk B8DYjP1mgs/35JF+YHPvuUzO9OQS0Sh+ZNNwF+bF+tv062GS26yvMy7tojc/XZnkX4eP 2hPfWtCVqGVQjqYCKmftzOczo0RNIvtp6pOmdZU2qHoNnJNFRot1hL4t+QM2Lkx/6BKz 9v4DJk960csSarD09xXf1S0D83lHGqasN7kRVzNrOrP/Yp/GjHwLQTN4nfdFxO5r6m+c /kkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:dkim-signature:dkim-filter; bh=ZWNiGqU2Ab0xVGCjTKpkcmtfdONYw9vZUUAGyB1yU84=; b=em3LCEbRdHw9MZi54vF1v0L2Mk1AYcZtLMayBtitY2WJ3zU0ocjUPVClzM/J4wL/FS oCQ4C+ABcEbKM41KD20+Jyj6u5I61pTAelaOphWsXH2oBNn9NVRPr1F0ibFwJlllUu9e uBh2JpTMrEJaDhrx8VBRxAseqxugK1lhyMEkJ1tBOuWXUIUOdrby+1AJFWYMtfPNw/np p0Ln8hhYbNt7xjeYgTLn9yx15x3nogJxfM3nrQYKGYniRhp+BS2ES+3jWEp41F+wuf7b 1ZZvEFg8MznthJPvyKfiy4wf5RMafB4L56QpWoJ/ptyDJzJSjtHAGUXlia/OQ3BLzgnr By0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=A4UXQGkT; 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=efficios.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p12si1549808oti.313.2020.03.19.11.57.04; Thu, 19 Mar 2020 11:57:16 -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; dkim=pass header.i=@efficios.com header.s=default header.b=A4UXQGkT; 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=efficios.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727192AbgCSSz2 (ORCPT + 99 others); Thu, 19 Mar 2020 14:55:28 -0400 Received: from mail.efficios.com ([167.114.26.124]:59908 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726867AbgCSSz2 (ORCPT ); Thu, 19 Mar 2020 14:55:28 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 43E0727AA9C; Thu, 19 Mar 2020 14:55:27 -0400 (EDT) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id YZvzRANsrTpZ; Thu, 19 Mar 2020 14:55:26 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 9AA7827A93F; Thu, 19 Mar 2020 14:55:26 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 9AA7827A93F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1584644126; bh=ZWNiGqU2Ab0xVGCjTKpkcmtfdONYw9vZUUAGyB1yU84=; h=Date:From:To:Message-ID:MIME-Version; b=A4UXQGkT0v97L9oJ7OGXaT+UczjRmvuOJhXj7Aj+hT+RqMjAQUVGsVcTNjzel/Zwk 65JA8jEI61fHGqUj3Q4Z96Vf0wMb2MWFElu5mivA3uiTZEpaqO395hdvF93nbiACbp Epv2VUOQV/QRyDcrpTpk2DdLl2kFMQbpkysSYGpgcSrlB7QDG5NXUglAji+52xSxXv L+ohqYyC6LaR6B6vggWs2l713w1Iub7haBQzOtC7qXnmntKuYsCAe23JRdPwXyCH4S zeq1prOFAHPEj2V909SaV7KLnGiHqXdPhpEOKyficJkXNCTBtE639JMJ7qa3Ypd3zk E6vYrVnGDT3AA== X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 5P-5zr0GCowB; Thu, 19 Mar 2020 14:55:26 -0400 (EDT) Received: from mail03.efficios.com (mail03.efficios.com [167.114.26.124]) by mail.efficios.com (Postfix) with ESMTP id 87BA327AB97; Thu, 19 Mar 2020 14:55:26 -0400 (EDT) Date: Thu, 19 Mar 2020 14:55:26 -0400 (EDT) From: Mathieu Desnoyers To: Florian Weimer 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 Message-ID: <900536577.4062.1584644126425.JavaMail.zimbra@efficios.com> In-Reply-To: <87k13ggpmf.fsf@mid.deneb.enyo.de> 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> Subject: Re: [RFC PATCH glibc 4/8] glibc: Perform rseq(2) registration at C startup and thread creation (v15) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [167.114.26.124] X-Mailer: Zimbra 8.8.15_GA_3918 (ZimbraWebClient - FF73 (Linux)/8.8.15_GA_3895) Thread-Topic: glibc: Perform rseq(2) registration at C startup and thread creation (v15) Thread-Index: R1unvLHgJY+0+0/DqhqCog6T/iuOvg== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- On Mar 19, 2020, at 2:34 PM, Florian Weimer fw@deneb.enyo.de wrote: > * 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. OK, so the _Static_assert () could sit in sys/rseq.h > >>>>> 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))); 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)))); > >>> 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 ? > >>>> 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. Thanks, Mathieu -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com