Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3065973imu; Sun, 9 Dec 2018 16:29:36 -0800 (PST) X-Google-Smtp-Source: AFSGD/VSNYAk41fsDSVkz6+HQQB9X2NhZ2FXsLda8T7pPbw2ZJi0SjcoigfwVSdPiixUiBMNTW1k X-Received: by 2002:a63:790e:: with SMTP id u14mr9071409pgc.452.1544401776683; Sun, 09 Dec 2018 16:29:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544401776; cv=none; d=google.com; s=arc-20160816; b=KwC3mtcSNpyPLw8RO/p6mrhU1LbTpPlwR3XESR7Qlx0qa+Qry+iOkZb8moUvxWx190 wLvDPjnHb8PeqQRy7mSfDriEw5qCbVCQK9dDAsnJ44tOCuEiXtzwbbD71z6Gg/L9BaKD COc4GhhF6Am/mzMxZIeRmE7H/YDsqu2LN5/9N02RXTNvXzplooafEK8kHcX/RWqclxEr /EcrO1GiOROz43qJcYkbVJvF4IY89NOOhOWJP6hgbCZL2+dDQcGPcia+hjOVK81oCuwy /Vm1JoJW2b/hvM8v9sNlC4QEevPeHJK6a2QlJa7aS47npC/SOdEKbKzmTT9uLJg4Mz7L Wciw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=2Kq2zZFJJjb8OBca5wcT/HQ6pswUdSnK6xyF9HWTu74=; b=HUSrclCDMmwBYpOueVUcaBjUa8dbNqCzU+moJR7upGTx+AxcWSHULxbGZahvZPKJD0 lr3ZX/Vu9VCSUbm1dM1qzJcMzBrhpqJvotkZ5opxs2Qhf7OJTJCSg9d25/gRFnjflckd 5kfdFBDDT/izGCQR02RxM11LaK6gmkmsi0uB9yTBzpWB/xwT7JbPNm5Aw5RQ0FV7OLaj dpLHJW0cprzZ+AJRU4PtiBwyZjp9Oelum2oOVAQJVMb5PLNvf3jaEw7p730eNylamfwW OgRNqlMXi5IJJUEhchRLPxyxFvI7jLttlYTRjJy5qblVPppTBpsVN74joBvp0qxULrVD xdJA== 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 o1si8500275pgq.13.2018.12.09.16.29.21; Sun, 09 Dec 2018 16:29:36 -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; 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 S1727471AbeLIWEQ (ORCPT + 99 others); Sun, 9 Dec 2018 17:04:16 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:35780 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726634AbeLIVza (ORCPT ); Sun, 9 Dec 2018 16:55:30 -0500 Received: from pub.yeoldevic.com ([81.174.156.145] helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gW72t-0002pr-Me; Sun, 09 Dec 2018 21:55:27 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gW72k-0003de-6c; Sun, 09 Dec 2018 21:55:18 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Andy Lutomirski" , "Thomas Gleixner" Date: Sun, 09 Dec 2018 21:50:33 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 286/328] x86/vdso: Fix asm constraints on vDSO syscall fallbacks In-Reply-To: X-SA-Exim-Connect-IP: 81.174.156.145 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.62-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Andy Lutomirski commit 715bd9d12f84d8f5cc8ad21d888f9bc304a8eb0b upstream. The syscall fallbacks in the vDSO have incorrect asm constraints. They are not marked as writing to their outputs -- instead, they are marked as clobbering "memory", which is useless. In particular, gcc is smart enough to know that the timespec parameter hasn't escaped, so a memory clobber doesn't clobber it. And passing a pointer as an asm *input* does not tell gcc that the pointed-to value is changed. Add in the fact that the asm instructions weren't volatile, and gcc was free to omit them entirely unless their sole output (the return value) is used. Which it is (phew!), but that stops happening with some upcoming patches. As a trivial example, the following code: void test_fallback(struct timespec *ts) { vdso_fallback_gettime(CLOCK_MONOTONIC, ts); } compiles to: 00000000000000c0 : c0: c3 retq To add insult to injury, the RCX and R11 clobbers on 64-bit builds were missing. The "memory" clobber is also unnecessary -- no ordering with respect to other memory operations is needed, but that's going to be fixed in a separate not-for-stable patch. Fixes: 2aae950b21e4 ("x86_64: Add vDSO for x86-64 with gettimeofday/clock_gettime/getcpu") Signed-off-by: Andy Lutomirski Signed-off-by: Thomas Gleixner Link: https://lkml.kernel.org/r/2c0231690551989d2fafa60ed0e7b5cc8b403908.1538422295.git.luto@kernel.org [bwh: Backported to 3.16: adjust filename] Signed-off-by: Ben Hutchings --- arch/x86/vdso/vclock_gettime.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) --- a/arch/x86/vdso/vclock_gettime.c +++ b/arch/x86/vdso/vclock_gettime.c @@ -50,8 +50,9 @@ extern u8 pvclock_page notrace static long vdso_fallback_gettime(long clock, struct timespec *ts) { long ret; - asm("syscall" : "=a" (ret) : - "0" (__NR_clock_gettime), "D" (clock), "S" (ts) : "memory"); + asm ("syscall" : "=a" (ret), "=m" (*ts) : + "0" (__NR_clock_gettime), "D" (clock), "S" (ts) : + "memory", "rcx", "r11"); return ret; } @@ -59,8 +60,9 @@ notrace static long vdso_fallback_gtod(s { long ret; - asm("syscall" : "=a" (ret) : - "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "memory"); + asm ("syscall" : "=a" (ret), "=m" (*tv), "=m" (*tz) : + "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : + "memory", "rcx", "r11"); return ret; } @@ -143,12 +145,12 @@ notrace static long vdso_fallback_gettim { long ret; - asm( + asm ( "mov %%ebx, %%edx \n" "mov %2, %%ebx \n" "call __kernel_vsyscall \n" "mov %%edx, %%ebx \n" - : "=a" (ret) + : "=a" (ret), "=m" (*ts) : "0" (__NR_clock_gettime), "g" (clock), "c" (ts) : "memory", "edx"); return ret; @@ -158,12 +160,12 @@ notrace static long vdso_fallback_gtod(s { long ret; - asm( + asm ( "mov %%ebx, %%edx \n" "mov %2, %%ebx \n" "call __kernel_vsyscall \n" "mov %%edx, %%ebx \n" - : "=a" (ret) + : "=a" (ret), "=m" (*tv), "=m" (*tz) : "0" (__NR_gettimeofday), "g" (tv), "c" (tz) : "memory", "edx"); return ret;