Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp21783464ybl; Mon, 6 Jan 2020 11:10:04 -0800 (PST) X-Google-Smtp-Source: APXvYqxBTyGbXk2qDmUF1P4SKgSXaHLJzPr/wN2fqQ6FSQWPcNR6A5Bg+Qv0KO84J1YWuKYWfPE9 X-Received: by 2002:aca:758a:: with SMTP id q132mr6514257oic.162.1578337804736; Mon, 06 Jan 2020 11:10:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578337804; cv=none; d=google.com; s=arc-20160816; b=UnRy3FJTzgdwys/pXUUlHyBmgJipxnYE1OBNcwD4Adtm1JFHoCIf3oLF2BnzvJcn67 jJo4bIT7PJgCiX2nICfdKEvOeF9PwkkzuoFG4AJncn6m3EiwILohNvubtQgsRrvRyj0j G4rcIGrElKsZFfMChNFD3KEEYUtguONEhXs7b6Kx+iHVtAI2sCBIX4iKGMwxrarFAGge fVs25Qs6c9DhcGVIQJ7i1mK5bnk/gkgvXSpwb5cYZIImMhcti33GnAp9UUAgvehBRfrj B8mBiw+qQCqmhdz+Mf4L2UASUBSOek53L67uF3WyXjbunH8G2PK0uQUIAwtz6qwU0itZ AjnA== 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=zIl8A6TLdf+oAfGFrNNrc51On1qmddpUPuBxgyxcrHc=; b=fmc10iRvpq93MJy7tdZ6c0E8PkAUAvvb8ztMmUdq1um6i4a+BRKa+f32QgArSXgAPZ CqVJk/1rcbIxkgplvrmUmG/DL+KqdZbHzMADP4OuMcSSG8av/KjeDM2EP7/OrOEQJ1Me esrL+vPvah/NEsUtJ4ZqEzMPPenFIRufVe8PfvwQ1cgWbmE8LEea4K2/z3+ghwAfbQxb 1Reb1uuFVO8xvG1+zX6V5rNTGO/w7stKilqD7x2zjmwHUCO3JSBJmkSQQJ8r0ZoU9i7A Lm9bL5Rwfy1rU9ILMdfw9sGNaHjlxiUuKGMqLE6zMDIDIqSRxjAEYBZABEeCbXigfdcZ 6pxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=fJUEqMcu; 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 f15si28645045oij.160.2020.01.06.11.09.50; Mon, 06 Jan 2020 11:10:04 -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=@efficios.com header.s=default header.b=fJUEqMcu; 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 S1726797AbgAFTIk (ORCPT + 99 others); Mon, 6 Jan 2020 14:08:40 -0500 Received: from mail.efficios.com ([167.114.142.138]:39180 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726569AbgAFTIj (ORCPT ); Mon, 6 Jan 2020 14:08:39 -0500 Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id C360A6943FD; Mon, 6 Jan 2020 14:08:37 -0500 (EST) Received: from mail.efficios.com ([IPv6:::1]) by localhost (mail02.efficios.com [IPv6:::1]) (amavisd-new, port 10032) with ESMTP id SgWCljRP6-DE; Mon, 6 Jan 2020 14:08:37 -0500 (EST) Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id 47AB26943F4; Mon, 6 Jan 2020 14:08:37 -0500 (EST) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 47AB26943F4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1578337717; bh=zIl8A6TLdf+oAfGFrNNrc51On1qmddpUPuBxgyxcrHc=; h=Date:From:To:Message-ID:MIME-Version; b=fJUEqMcuOQR9R4stWSeQpFZsC1yybi+vm8zlyDWg8+St9OU5sHJ96AP59kr0Lo/DA qddq8zq9XLjRyv2Ta3p5dY35hh9aEO22y+q4LpTM3/3Bn2rB+TSEuRL27oKqJzb2u5 wRVytGfKXlJA34j5yO9XGF+cZfg0OGtavdPXbu1ycbfDIOyj5obMnQ1EF/ZJQ2pY8w X2uhizfuUDVWHoR9zSgCa2kcB0YdIWcuu+Kv2kqkRuFiKC1Qz86Cjx2lV3IDSO5qRn UZzos+NJkY7WQGZEwfc++cWjGQGDK+8FcTxhWFpXYD3vec10TcwqR/lnn/7O5J6An/ 7jvBuJ0zo9vvg== X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([IPv6:::1]) by localhost (mail02.efficios.com [IPv6:::1]) (amavisd-new, port 10026) with ESMTP id zsiBdNTc3Ll9; Mon, 6 Jan 2020 14:08:37 -0500 (EST) Received: from mail02.efficios.com (mail02.efficios.com [167.114.142.138]) by mail.efficios.com (Postfix) with ESMTP id 32ADA6943DE; Mon, 6 Jan 2020 14:08:37 -0500 (EST) Date: Mon, 6 Jan 2020 14:08:37 -0500 (EST) From: Mathieu Desnoyers To: Florian Weimer Cc: Thomas Gleixner , linux-kernel , Peter Zijlstra , paulmck , Boqun Feng , "H. Peter Anvin" , Paul Turner , linux-api , stable , Dmitry Vyukov , Neel Natu Message-ID: <1025393027.850.1578337717165.JavaMail.zimbra@efficios.com> In-Reply-To: <669061171.14506.1576876500152.JavaMail.zimbra@efficios.com> References: <20191220201207.17389-1-mathieu.desnoyers@efficios.com> <87imman36g.fsf@mid.deneb.enyo.de> <173832695.14381.1576875253374.JavaMail.zimbra@efficios.com> <875zian2a2.fsf@mid.deneb.enyo.de> <669061171.14506.1576876500152.JavaMail.zimbra@efficios.com> Subject: Re: [PATCH for 5.5 1/2] rseq: Fix: Clarify rseq.h UAPI rseq_cs memory reclaim requirements MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [167.114.142.138] X-Mailer: Zimbra 8.8.15_GA_3894 (ZimbraWebClient - FF71 (Linux)/8.8.15_GA_3890) Thread-Topic: rseq: Fix: Clarify rseq.h UAPI rseq_cs memory reclaim requirements Thread-Index: lBXaukfByKp9TejsCTqcOtGiErTiYOyBdIyh Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- On Dec 20, 2019, at 4:15 PM, Mathieu Desnoyers mathieu.desnoyers@effi= cios.com wrote: > ----- On Dec 20, 2019, at 3:57 PM, Florian Weimer fw@deneb.enyo.de wrote: >=20 >> * Mathieu Desnoyers: >>=20 >>> ----- On Dec 20, 2019, at 3:37 PM, Florian Weimer fw@deneb.enyo.de wrot= e: >>> >>>> * Mathieu Desnoyers: >>>>=20 >>>>> diff --git a/include/uapi/linux/rseq.h b/include/uapi/linux/rseq.h >>>>> index 9a402fdb60e9..6f26b0b148a6 100644 >>>>> --- a/include/uapi/linux/rseq.h >>>>> +++ b/include/uapi/linux/rseq.h >>>>> @@ -100,7 +100,9 @@ struct rseq { >>>>> =09 * instruction sequence block, as well as when the kernel detects= that >>>>> =09 * it is preempting or delivering a signal outside of the range >>>>> =09 * targeted by the rseq_cs. Also needs to be set to NULL by user-= space >>>>> -=09 * before reclaiming memory that contains the targeted struct rse= q_cs. >>>>> +=09 * before reclaiming memory that contains the targeted struct rse= q_cs >>>>> +=09 * or reclaiming memory that contains the code refered to by the >>>>> +=09 * start_ip and post_commit_offset fields of struct rseq_cs. >>>>=20 >>>> Maybe mention that it's good practice to clear rseq_cs before >>>> returning from a function that contains a restartable sequence? >>> >>> Unfortunately, clearing it is not free. Considering that rseq is meant = to >>> be used in very hot code paths, it would be preferable that application= s >>> clear it in the very infrequent case where the rseq_cs or code will >>> vanish (e.g. dlclose or JIT reclaim), and not require it to be cleared >>> after each critical section. I am therefore reluctant to document the >>> behavior you describe as a "good practice" for rseq. >>=20 >> You already have to write to rseq_cs before entering the critical >> section, right? Then you've already determined the address, and the >> cache line is already hot, so it really should be close to zero cost. >=20 > Considering that overall rseq executes in fraction of nanoseconds on > some architectures, adding an extra store is perhaps close to zero, > but still significantly degrades performance. >=20 >>=20 >> I mean, you can still discard the advice, but you do so ad your own >> peril =E2=80=A6 >=20 > I am also uncomfortable leaving this to the end user. One possibility > would be to extend rseq or membarrier to add a kind of "rseq-clear" > barrier, which would ensure that the kernel will have cleared the > rseq_cs field for each thread belonging to the current process. glibc > could then call this barrier before dlclose. >=20 > This is slightly different from another rseq-barrier that has been > requested by Paul Turner: a way to ensure that all previously > running rseq critical sections have completed or aborted. >=20 > AFAIU, the desiderata for each of the 2 use-cases is as follows: >=20 > rseq-barrier: guarantee that all prior rseq critical sections have > completed or aborted for the current process or for a set of registered > processes. Allows doing RCU-like algorithms within rseq critical sections= . >=20 > rseq-clear: guarantee that the rseq_cs field is cleared for each thread > belonging to the current process before the barrier system call returns > to the caller. Aborts currently running rseq critical sections for all > threads belonging to the current process. The use-case is to allow > dlclose and JIT reclaim to clear any leftover reference to struct > rseq_cs or code which are going to be reclaimed. Just to clarify: should the discussion here prevent the UAPI documentation change from being merged into the Linux kernel ? Our discussion seems to be related to integration of rseq into glibc, rather than the kernel UAPI per = se. Thanks, Mathieu --=20 Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com