Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp797436imm; Mon, 21 May 2018 14:39:46 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqhPZCVCJZyM4x8Drtum/TLjB0MfILgLg+JnFn7INzBPLhl/8Olk2u5PzA+F9xU48Bv3fHT X-Received: by 2002:a17:902:64d0:: with SMTP id y16-v6mr21563401pli.349.1526938786568; Mon, 21 May 2018 14:39:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526938786; cv=none; d=google.com; s=arc-20160816; b=t6Qrg/A6DUZeJnPL+abGV8Vjt5uDsEF2pCROMrpOsriuUyeHvPSxGwCszdfGqnmNr2 SaH6XsXEyRfS3ozs4Fn8gBozpU/QL62iIMbxW1/iKSOKWsbVSMAYDsAv2yyJQfX4R5c7 Kz/44sIjzcP4HOUxa7mYponz+9l0qqrnKHWbQwTtSQG9c0DcY31k/wc0NYwOmDEsptbd qXUUo6SziweyGHpkpq0UrqPW3v4Dz2DT986aZTvdx9KJwkLZl6afksrhEe48dr9OJJXB nkvy0xRPQ8xogymTmzOCEl9WFrfDGPs2uwE1GCtdV47FTYbL8tj+IxS3IHNiKF8BUu+t wDdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=8BusgR7UX/ileAW+5yEe/c1qYnHORHi/kfMJ1sdEfAw=; b=DP4MUYla6S0E030Mt5V+poPAG9cQfJ7z8vPPu3VtYuNCoOSamc1HPJG/PsTl+RfTW6 QZm5eBAqQC8rzqmOFJt23Ao0pGwUWuiTcBA5TCmBRt7LG1TdGxP1GBwY161PTPpaMNPY O1FDejqvhYV6kcHMDxv69YxkvHOj0HlY20uGp2TZdjMtA8zEG42lPyyfIu5lI/vp9G6N wZ87fnhASBMDJTEXGXFpubccFygKVmA/oE0jQbf15B4r/UyInoatZEOVj3GrXdJx3916 s/92y/Yk4+r980WraRjRtBT9Nr+7FxXgTyOZa8Mn5uN0z4z3tx0+bAFAV7pnyR7rsqK+ AePQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rnKTNHpO; 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 bj6-v6si14812360plb.405.2018.05.21.14.39.32; Mon, 21 May 2018 14:39:46 -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=@kernel.org header.s=default header.b=rnKTNHpO; 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 S932355AbeEUVY6 (ORCPT + 99 others); Mon, 21 May 2018 17:24:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:39728 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932302AbeEUVYv (ORCPT ); Mon, 21 May 2018 17:24:51 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7E33F2075C; Mon, 21 May 2018 21:24:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1526937891; bh=dd88K4VJiQJ16ogAkBXmu6phYbCG9Qs+3IQOqTw9v98=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rnKTNHpOC/QigI29YZ9f0eJR4WRXR5xh2iQ11+9WBSBcvd20qaa17w0d2BZYqtA72 P1B4gDUyr5eg1S845/Qc1RFdvKPoqzy0nhRrg/TiLe3hh0nD0Wn/pWU1kLmJggTwjR YDgn/HG3BFNmPpD3LGBUd7Q7rNc0R4RCNT9wBv4g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Linus Torvalds , Thomas Gleixner , Ingo Molnar Subject: [PATCH 4.16 062/110] x86/nospec: Simplify alternative_msr_write() Date: Mon, 21 May 2018 23:11:59 +0200 Message-Id: <20180521210511.622233431@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180521210503.823249477@linuxfoundation.org> References: <20180521210503.823249477@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Linus Torvalds commit 1aa7a5735a41418d8e01fa7c9565eb2657e2ea3f upstream The macro is not type safe and I did look for why that "g" constraint for the asm doesn't work: it's because the asm is more fundamentally wrong. It does movl %[val], %%eax but "val" isn't a 32-bit value, so then gcc will pass it in a register, and generate code like movl %rsi, %eax and gas will complain about a nonsensical 'mov' instruction (it's moving a 64-bit register to a 32-bit one). Passing it through memory will just hide the real bug - gcc still thinks the memory location is 64-bit, but the "movl" will only load the first 32 bits and it all happens to work because x86 is little-endian. Convert it to a type safe inline function with a little trick which hands the feature into the ALTERNATIVE macro. Signed-off-by: Linus Torvalds Signed-off-by: Thomas Gleixner Reviewed-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/nospec-branch.h | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -241,15 +241,16 @@ static inline void vmexit_fill_RSB(void) #endif } -#define alternative_msr_write(_msr, _val, _feature) \ - asm volatile(ALTERNATIVE("", \ - "movl %[msr], %%ecx\n\t" \ - "movl %[val], %%eax\n\t" \ - "movl $0, %%edx\n\t" \ - "wrmsr", \ - _feature) \ - : : [msr] "i" (_msr), [val] "i" (_val) \ - : "eax", "ecx", "edx", "memory") +static __always_inline +void alternative_msr_write(unsigned int msr, u64 val, unsigned int feature) +{ + asm volatile(ALTERNATIVE("", "wrmsr", %c[feature]) + : : "c" (msr), + "a" (val), + "d" (val >> 32), + [feature] "i" (feature) + : "memory"); +} static inline void indirect_branch_prediction_barrier(void) {