Received: by 10.213.65.68 with SMTP id h4csp3945255imn; Tue, 3 Apr 2018 13:34:55 -0700 (PDT) X-Google-Smtp-Source: AIpwx49SCby2j8i3m/RQuDqnZwoj2fUF4G9yTrEfLeTzm7aOldj4zZIlw8cW3gDdZqhxXeURiGaj X-Received: by 2002:a17:902:a9c4:: with SMTP id b4-v6mr15896142plr.333.1522787695145; Tue, 03 Apr 2018 13:34:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522787695; cv=none; d=google.com; s=arc-20160816; b=UJFX5gyXmYGhkkHlTX3+mv/uDVZJc8HMoTTFHp93do/85jCarHaduOhXzmct+4EJ6V PjFBcpE85ztb3cCF4X0c1vMS+GAmnczpcJ+jhrFyH9x+lndp44VIK9ntaGlC89foq7DJ Mai518ml5wOM5XST2sYv2KqP3JtFHpiEBaV7tGMHSzqegKvz0jer1NwuwtWa/VLY0+O4 DachvGwqxZuG/coUw6aZPZkhGI7rFUFqdeE1XrgWONY3VFGAWEBvAzQSGJrYyu2yQX4+ At+AiprmdtTLQfM66HF7CjUUQW65bYJiapayc4ThtSSUkN2csHMCNg398XtboayqMC0z WbzQ== 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:arc-authentication-results; bh=7ia9ab8S99OTu0KKctXs9H7Np3RLhMqQYr1FKQ4GpUE=; b=u6veQ3qQdbQC5Onrdm6lGIDa4D060UsbE5XtMaZPul+l32UfHbsyUqzCtX0yxrZGy3 IpCknmCzUCPNQmW16pOZe6jJWl4bDRUbeOn/tDS5irQ6nxOqTzvkAbOo6gJGdCR68cmi nPCzf/CEnZRoqpui49ra8S7cTPFRbPvn4fFx7iJy8O/FNEKxIowDjjtwDoFAuE2ETHpR pEgtyy/ml6QslTLPbvhXkP4mLa/dgtrnzkSetPxAHllc4YjmCVW+oUQy/0T3kr4y5BSB zQM0eYnf1q3QUf0cw4fJ30BaLuoqpKz3vDhjibnBTquLvOHZEc7Ii2q88p/L/t8FlEq5 MHGw== 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 c20si2758916pfi.18.2018.04.03.13.34.28; Tue, 03 Apr 2018 13:34:55 -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 S1752949AbeDCUcb (ORCPT + 99 others); Tue, 3 Apr 2018 16:32:31 -0400 Received: from mail.efficios.com ([167.114.142.138]:45932 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752454AbeDCUc2 (ORCPT ); Tue, 3 Apr 2018 16:32:28 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id ACDD71AB873; Tue, 3 Apr 2018 16:32:27 -0400 (EDT) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail02.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id rxkuYNr1vqzC; Tue, 3 Apr 2018 16:32:26 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id CBDD71AB86C; Tue, 3 Apr 2018 16:32:26 -0400 (EDT) X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail02.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id gzXS3DLUhnt4; Tue, 3 Apr 2018 16:32:26 -0400 (EDT) Received: from mail02.efficios.com (mail02.efficios.com [167.114.142.138]) by mail.efficios.com (Postfix) with ESMTP id AE91E1AB864; Tue, 3 Apr 2018 16:32:26 -0400 (EDT) Date: Tue, 3 Apr 2018 16:32:26 -0400 (EDT) From: Mathieu Desnoyers To: One Thousand Gnomes Cc: Peter Zijlstra , "Paul E. McKenney" , Boqun Feng , Andy Lutomirski , Dave Watson , linux-kernel , linux-api , Paul Turner , Andrew Morton , Russell King , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Andrew Hunter , Andi Kleen , Chris Lameter , Ben Maurer , rostedt , Josh Triplett , Linus Torvalds , Catalin Marinas , Will Deacon , Michael Kerrisk , Alexander Viro Message-ID: <1649799886.2451.1522787546557.JavaMail.zimbra@efficios.com> In-Reply-To: <17439540.2334.1522773387555.JavaMail.zimbra@efficios.com> References: <20180327160542.28457-1-mathieu.desnoyers@efficios.com> <20180327160542.28457-3-mathieu.desnoyers@efficios.com> <20180401171356.085a2a33@alans-desktop> <1890356924.1736.1522683188833.JavaMail.zimbra@efficios.com> <17439540.2334.1522773387555.JavaMail.zimbra@efficios.com> Subject: Re: [RFC PATCH for 4.17 02/21] rseq: Introduce restartable sequences system call (v12) 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.7_GA_1964 (ZimbraWebClient - FF52 (Linux)/8.8.7_GA_1964) Thread-Topic: rseq: Introduce restartable sequences system call (v12) Thread-Index: ZlI8yYRhtR4Zm8XQBnk6z8Kg2ePiGrPMLD+wVMwzSuE= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- On Apr 3, 2018, at 12:36 PM, Mathieu Desnoyers mathieu.desnoyers@efficios.com wrote: > ----- On Apr 2, 2018, at 11:33 AM, Mathieu Desnoyers > mathieu.desnoyers@efficios.com wrote: > >> ----- On Apr 1, 2018, at 12:13 PM, One Thousand Gnomes >> gnomes@lxorguk.ukuu.org.uk wrote: >> [...] >>> I still like the idea it's just the latencies concern me. >> [...] > > Looking into this a bit more, I notice the following: The pgprot_noncached > (_PAGE_NOCACHE on x86) pgprot is part of the vma->vm_page_prot. Therefore, > in order to have userspace provide pointers to noncached pages as input > to cpu_opv, they need to be part of a userspace vma which has a > pgprot_noncached vm_page_prot. > > The cpu_opv system call uses get_user_pages_fast() to grab the struct page > from the userspace addresses, and then passes those pages to vm_map_ram(), > with a PAGE_KERNEL pgprot. This creates a temporary kernel mapping to those > pages, which is then used to read/write from/to those pages with preemption > disabled. > > Therefore, with the proposed cpu_opv implementation, the kernel is not > touching noncached mappings with preemption disabled, which should take > care of your latency concern. [...] The following extra check should let userspace know it's trying to provide a pointer to noncached memory by returning -1, errno=EFAULT. Is the approach acceptable ? Thanks, Mathieu diff --git a/include/linux/mm.h b/include/linux/mm.h index ad06d42..0245481 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2425,6 +2425,18 @@ static inline struct page *follow_page(struct vm_area_struct *vma, return follow_page_mask(vma, address, foll_flags, &unused_page_mask); } +static inline bool is_vma_noncached(struct vm_area_struct *vma) +{ + pgprot_t pgprot = vma->vm_page_prot; + + /* Check whether architecture implements noncached pages. */ + if (pgprot_val(pgprot_noncached(PAGE_KERNEL)) == pgprot_val(PAGE_KERNEL)) + return false; + if (pgprot_val(pgprot) != pgprot_val(pgprot_noncached(pgprot))) + return false; + return true; +} + #define FOLL_WRITE 0x01 /* check pte is writable */ #define FOLL_TOUCH 0x02 /* mark page accessed */ #define FOLL_GET 0x04 /* do get_page on page */ diff --git a/kernel/cpu_opv.c b/kernel/cpu_opv.c index 197339e..e4395b4 100644 --- a/kernel/cpu_opv.c +++ b/kernel/cpu_opv.c @@ -362,7 +362,19 @@ static int cpu_op_pin_pages(unsigned long addr, unsigned long len, int ret, nr_pages, nr_put_pages, n; unsigned long _vaddr; struct vaddr *va; + struct vm_area_struct *vma; + vma = find_vma_intersection(current->mm, addr, addr + len); + if (!vma) + return -EFAULT; + /* + * cpu_opv() accesses its own cached mapping of the userspace pages. + * Considering that concurrent noncached and cached accesses may yield + * to unexpected results in terms of memory consistency, explicitly + * disallow cpu_opv on noncached memory. + */ + if (is_vma_noncached(vma)) + return -EFAULT; nr_pages = cpu_op_count_pages(addr, len); if (!nr_pages) return 0; -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com