Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp853009imm; Wed, 13 Jun 2018 09:15:26 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKZAlfE9lHqY1p/LItr6B1CRB8p5URC2cmgl+xqtVWV9J3HA/C/PSSbzgMKXdqPWjvu9tHp X-Received: by 2002:a62:458a:: with SMTP id n10-v6mr5543029pfi.215.1528906526751; Wed, 13 Jun 2018 09:15:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528906526; cv=none; d=google.com; s=arc-20160816; b=FhJyesB3gN1+5s3Sv8MOumOUzgmz7ADkan31YBabKkhyUJPm3rJmCTUP6/6/QkE5KJ uMRg0buwczJnjJ2Mbg1c3r2CgEfmwrnrnxeOMNM9Vfrp7A46z1RnyA+MbvxHT1w0ZCOG wsDZ4+wlD0jdmPqn8jOMcI0K0JH531LJEJGlpiwG1hAiQKHx8oSO0YCxEPfzTmP5vy+l Cdu6d1t05Eoj17wr19YPMDK/gd2Je/UPpRIKCsBWX7CwL2maxIB3XcaAcO/nz98cwlT0 4Au6D3K1rlRDR5AfVynGEFeh/rsgebIOYbOKXqLGS+pv5HABLDiHlMgz/1dBGG8Orcrv 0nww== 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 :arc-authentication-results; bh=pHgN/cEVkus3vReyCzHkOHy3ZSDDsYE8eCigiIxac+s=; b=mMh+A9nI16rBER6/fkxgGnPBv3A8HV957CKapZVWbjCK4S5oPRMiGOzC8YC/g04g+C xewExLS+ug5zS8zIyClDP4ThDNVxERI0BT6uxL9CxMDCf2+1NbXIxj6mAWdbFtT1wPtm 79j5DHvI6TRXgxW+C3+w3jzEJHqejHQd+5l91K89EdGGT9of2YgF9O9QmDqi9Q4tUOCo LlvD+WgHjbtwF5Tc49Ducl31QbefrRyl/DnRygV2ycSjCMIIDh+NQexctIcOzIsJXN3W Iz2yxNnAK4g8X8xAvVIbX5qNG2JJGS2JOMIs3vTfJivhz4fDSDom+b65EeYde17GhWjI jGjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b="SfCx/xSP"; 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 t62-v6si2567583pgb.582.2018.06.13.09.14.48; Wed, 13 Jun 2018 09:15:26 -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="SfCx/xSP"; 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 S1754544AbeFMQOV (ORCPT + 99 others); Wed, 13 Jun 2018 12:14:21 -0400 Received: from mail.efficios.com ([167.114.142.138]:60876 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754509AbeFMQOU (ORCPT ); Wed, 13 Jun 2018 12:14:20 -0400 Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id A032A229AF0; Wed, 13 Jun 2018 12:14:19 -0400 (EDT) Received: from mail.efficios.com ([IPv6:::1]) by localhost (mail02.efficios.com [IPv6:::1]) (amavisd-new, port 10032) with ESMTP id Lzwka1r-98HG; Wed, 13 Jun 2018 12:14:19 -0400 (EDT) Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id 350EE229AED; Wed, 13 Jun 2018 12:14:19 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 350EE229AED DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1528906459; bh=pHgN/cEVkus3vReyCzHkOHy3ZSDDsYE8eCigiIxac+s=; h=Date:From:To:Message-ID:MIME-Version; b=SfCx/xSPyt+9OBl9An+vsmoif8QMZlwALV3SuKAX9u5QFyo58EWyhdssfxLy9972n KlRZeF48rSOAC0zPmbDRRf8vVYs2V6e1jbmUv/9t3XmwpxnbELZLup6pos2H2tYzPe jrl+8eYfVzUKGeQCudlcaBn8Gr9o76ayN10FVelftYBDpfFJMp7J/J8LdseT8mx8XJ Btjuyah13oSMxRBtfqKxtBBxvZmVijzslB5yNIIlQwJahCjkjX0Uqvorzo8Ib8mmVM 8VF6fVSM8NWUM5DSVNVaK5AvTbup0WV4f6l4O2mz/w/tWxF0ll+bm3JfOkxoAHqoMA byjJSxtjgVQ7g== 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 fOmiMVeQ7EWw; Wed, 13 Jun 2018 12:14:19 -0400 (EDT) Received: from mail02.efficios.com (mail02.efficios.com [167.114.142.138]) by mail.efficios.com (Postfix) with ESMTP id 1DA25229AE6; Wed, 13 Jun 2018 12:14:19 -0400 (EDT) Date: Wed, 13 Jun 2018 12:14:18 -0400 (EDT) From: Mathieu Desnoyers To: heiko carstens Cc: carlos , Florian Weimer , Peter Zijlstra , "Paul E. McKenney" , Boqun Feng , Thomas Gleixner , linux-kernel , libc-alpha Message-ID: <1904010978.12481.1528906458944.JavaMail.zimbra@efficios.com> In-Reply-To: <20180613114811.GC4342@osiris> References: <1084280721.10859.1528746558696.JavaMail.zimbra@efficios.com> <20180613114811.GC4342@osiris> Subject: Re: Restartable Sequences system call merged into Linux MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [167.114.142.138] X-Mailer: Zimbra 8.8.8_GA_2096 (ZimbraWebClient - FF52 (Linux)/8.8.8_GA_1703) Thread-Topic: Restartable Sequences system call merged into Linux Thread-Index: 03097Zs90n0PWzBVhsrdocLBo0GNPw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- On Jun 13, 2018, at 7:48 AM, heiko carstens heiko.carstens@de.ibm.com wrote: > On Mon, Jun 11, 2018 at 03:49:18PM -0400, Mathieu Desnoyers wrote: >> Hi! >> >> Good news! The restartable sequences (rseq) system call is now merged into the >> master >> branch of the Linux kernel within the 4.18 merge window: >> >> https://github.com/torvalds/linux/commit/d82991a8688ad128b46db1b42d5d84396487a508 >> >> It would be important to discuss how we should proceed to integrate the library >> part >> of rseq (see tools/testing/selftests/rseq/rseq*.{ch}) into glibc, or if it >> should >> live in a standalone project. > > Is there any documentation available of what is the exact semantics of the > functions that have to be implemented for additional architectures? It's documented on top of kernel/rseq.c: /* * * Restartable sequences are a lightweight interface that allows * user-level code to be executed atomically relative to scheduler * preemption and signal delivery. Typically used for implementing * per-cpu operations. * * It allows user-space to perform update operations on per-cpu data * without requiring heavy-weight atomic operations. * * Detailed algorithm of rseq user-space assembly sequences: * * init(rseq_cs) * cpu = TLS->rseq::cpu_id_start * [1] TLS->rseq::rseq_cs = rseq_cs * [start_ip] ---------------------------- * [2] if (cpu != TLS->rseq::cpu_id) * goto abort_ip; * [3] * [post_commit_ip] ---------------------------- * * The address of jump target abort_ip must be outside the critical * region, i.e.: * * [abort_ip] < [start_ip] || [abort_ip] >= [post_commit_ip] * * Steps [2]-[3] (inclusive) need to be a sequence of instructions in * userspace that can handle being interrupted between any of those * instructions, and then resumed to the abort_ip. * * 1. Userspace stores the address of the struct rseq_cs assembly * block descriptor into the rseq_cs field of the registered * struct rseq TLS area. This update is performed through a single * store within the inline assembly instruction sequence. * [start_ip] * * 2. Userspace tests to check whether the current cpu_id field match * the cpu number loaded before start_ip, branching to abort_ip * in case of a mismatch. * * If the sequence is preempted or interrupted by a signal * at or after start_ip and before post_commit_ip, then the kernel * clears TLS->__rseq_abi::rseq_cs, and sets the user-space return * ip to abort_ip before returning to user-space, so the preempted * execution resumes at abort_ip. * * 3. Userspace critical section final instruction before * post_commit_ip is the commit. The critical section is * self-terminating. * [post_commit_ip] * * 4. * * On failure at [2], or if interrupted by preempt or signal delivery * between [1] and [3]: * * [abort_ip] * F1. */ > I could look at rseq-skip.h and e.g. rseq-x86.h and try to figure out what > would be the correct implementation for s390. But having that somewhere > written down, e.g. as comments in one of the implementations, would be very > helpful. The first architecture implemented was rseq-x86.h. Boqun derived rseq-ppc.h from it, and I derived rseq-arm.h from it. Feel free to start from whichever architecture has the instruction set which is most similar to yours. Thanks! Mathieu -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com