Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1430974imm; Tue, 3 Jul 2018 11:00:07 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc9zE5cf0qcIU0+sYXK66Yu2UYE1S0IVBDn3mSd4yF3VnZBDL/qtYEy169loLAREEDOfLz/ X-Received: by 2002:aa7:850b:: with SMTP id v11-v6mr3599337pfn.165.1530640807207; Tue, 03 Jul 2018 11:00:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530640807; cv=none; d=google.com; s=arc-20160816; b=YturmGrIlXWJZ46Q0uOfs0otrXa9EMnaICJ/rpMmgKxC/W97iDQUW/ShkfupGRnyk1 tS5GHU8TX6Wq8EwdcB6gkkCg++Ljs4nqnGgvYJocS8uabXnR8f0tVpWYGBR+yh/0Wah7 /n22BYN76QhQm+3OZiUbfXDdx3s4DjAEyGi7eRogszYvK/WN4RmOq8+U2WFiMsB4nhox tEzd6hckqFv7YLzYbuGZd7bezsHr/veza6JQ4M+j8y4yk6JbSwXc8k02wa2f7J9RaD8N d+8yYtCUHxKdHWdcrLqGK5p4A7NGxWiNBwtkwPjtKaIGh3giNFGWdrSTgKh9wGkQPbKq khQw== 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=QcS7yCbkT8TT4SKz7LTEzJemkpNiJcXtHzR2En3GBzY=; b=YMK8CR+S+K5ljFoo+JLRZmQWCpLXORMr5W2Ag+hfwdrLDuolcHqnWstZAFzoBQm3xQ RIi5LcAdyDU1pjT90nYdGccvKKsy/sjMTCUitI7ngqTKPUtwymHdQeWULbhkA0/RAUHN iAyjtlozqxYbVo21fMVFr73/aHTI/KPH/LsJ6AyIjGMCMhZp0eYS0Ts7iVhJS09jWEz9 Q9G0+uify8cCoNmQ99cW0IE1ugacJhfZlGrFk5l/xAMuJ7IZGFaX5J0C5IzAGI6ZepnX NSUWEcfYZNNSHJiZ69SnT/x1OWAz0LyAE1bVDHdNcD7/yhFbB1rcuw/CEIALV4TiXgwv 3oIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=Gvi5aTna; 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 w123-v6si1434819pgw.360.2018.07.03.10.59.52; Tue, 03 Jul 2018 11:00:07 -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=Gvi5aTna; 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 S934381AbeGCR6l (ORCPT + 99 others); Tue, 3 Jul 2018 13:58:41 -0400 Received: from mail.efficios.com ([167.114.142.138]:57994 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934194AbeGCR6j (ORCPT ); Tue, 3 Jul 2018 13:58:39 -0400 Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id AE3A7230B57; Tue, 3 Jul 2018 13:58:38 -0400 (EDT) Received: from mail.efficios.com ([IPv6:::1]) by localhost (mail02.efficios.com [IPv6:::1]) (amavisd-new, port 10032) with ESMTP id mHMxNb1nyohs; Tue, 3 Jul 2018 13:58:38 -0400 (EDT) Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id 21B28230B54; Tue, 3 Jul 2018 13:58:38 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 21B28230B54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1530640718; bh=QcS7yCbkT8TT4SKz7LTEzJemkpNiJcXtHzR2En3GBzY=; h=Date:From:To:Message-ID:MIME-Version; b=Gvi5aTna2aYoJLMgXX/WLgt9GhJA7CEePLT/Ef1vLurY0TTsO5P+JtcBbkAKzMmoi TVKLa4PK8ln94NeOsFu+yNEilQFeDux/9mT8iHN5qQoZK/Z3oJP00HrPpYhmpoqWD+ M+LwoJdhdMggMcMGXee9rUKVECWHo75nq3MwsHQOKLvNvnJCXba+jUT5pGrzvm6aG7 n68Lah6YqZd8c9A9+mP8Ym5ZzQ9+qZWskH6jDc5n1GBvO8c2E6yEaE857WWzgPInOn QKncDraQmqsx+Njpo3MlO+nFHM9eH+k89Ht0mV+sX51fOT8rywI9o3q9IqirDHtvKg B8Dt9ac79uHYg== 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 KhcRl4Z08dv3; Tue, 3 Jul 2018 13:58:38 -0400 (EDT) Received: from mail02.efficios.com (mail02.efficios.com [167.114.142.138]) by mail.efficios.com (Postfix) with ESMTP id 03B2C230B4D; Tue, 3 Jul 2018 13:58:38 -0400 (EDT) Date: Tue, 3 Jul 2018 13:58:37 -0400 (EDT) From: Mathieu Desnoyers To: Peter Zijlstra Cc: Linus Torvalds , Andi Kleen , heiko carstens , Andy Lutomirski , Thomas Gleixner , linux-kernel , linux-api , "Paul E. McKenney" , Boqun Feng , Dave Watson , Paul Turner , Andrew Morton , Russell King , Ingo Molnar , "H. Peter Anvin" , Chris Lameter , Ben Maurer , rostedt , Josh Triplett , Catalin Marinas , Will Deacon , Michael Kerrisk , Joel Fernandes , Michal Simek , schwidefsky , gor Message-ID: <1048940999.11846.1530640717837.JavaMail.zimbra@efficios.com> In-Reply-To: <20180703174833.GZ2494@hirez.programming.kicks-ass.net> References: <858886246.10882.1530583291379.JavaMail.zimbra@efficios.com> <20180703085546.GJ3704@osiris> <20180703092113.GV2494@hirez.programming.kicks-ass.net> <20180703164048.i2te5gjemcafqzwf@two.firstfloor.org> <20180703173451.GX2494@hirez.programming.kicks-ass.net> <399697782.11820.1530639539750.JavaMail.zimbra@efficios.com> <20180703174833.GZ2494@hirez.programming.kicks-ass.net> Subject: Re: [RFC PATCH for 4.18] rseq: use __u64 for rseq_cs fields, validate user inputs 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: rseq: use __u64 for rseq_cs fields, validate user inputs Thread-Index: iuuWVjAu2z6iRXS9/u0IY59Kxde0hw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- On Jul 3, 2018, at 1:48 PM, Peter Zijlstra peterz@infradead.org wrote: > On Tue, Jul 03, 2018 at 01:38:59PM -0400, Mathieu Desnoyers wrote: >> ----- On Jul 3, 2018, at 1:34 PM, Peter Zijlstra peterz@infradead.org wrote: >> >> > On Tue, Jul 03, 2018 at 10:10:37AM -0700, Linus Torvalds wrote: >> >> On Tue, Jul 3, 2018 at 9:40 AM Andi Kleen wrote: >> >> > >> >> > So it sounds like architectures that don't have an instruction atomic u64 >> >> > *_user need to disable interrupts during the access, and somehow handle that >> >> > case when a page fault happens? >> >> >> >> No. It's actually the store by *user* space that is the critical one. >> >> Not the whole 64-bit value, just the low pointer part. >> >> >> >> The kernel could do it as a byte-by-byte load, really. It's >> >> per-thread, and once the kernel is running, it's not going to change. >> >> The kernel never changes the value, it just loads it from user space. >> > >> > The kernel doesn't change _this_ value, but the kernel does change other >> > values, like for instance rseq->cpu_id. But even there, it could use >> > byte stores and it is again the userspace load of that field that is >> > critical again and needs to be a single op. >> >> I can simply document that loads/stores from/to all struct rseq fields >> should be thread-local then ? > > I'm not sure that covers things sufficiently. You really want the > userspace load/stores to be single instructions. Yes, of course. More specifically, I would document that those need to be single-copy atomicity load/store performed by the local thread. > Also, I think it was rseq_update_cpu_id() where we wanted to use a > single u64 store if possible but you worried about the stores. With this added bit of restriction on thread-local loads, indeed we can then update them without caring about atomicity at kernel level. I can modify the ABI to put the cpu_id_start and cpu_id fields inside a union, and update it with a single store. Thoughts ? Thanks, Mathieu -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com