Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5763496imm; Mon, 23 Jul 2018 05:47:15 -0700 (PDT) X-Google-Smtp-Source: AAOMgpceNt8b8/ycuJvoAZtyLw3aIiU1y34Z4y3tK9HlUnhrJ+k6PyqUZEOaYbClSPEQIvZ2ACKz X-Received: by 2002:a65:4d05:: with SMTP id i5-v6mr11970045pgt.58.1532350035110; Mon, 23 Jul 2018 05:47:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532350035; cv=none; d=google.com; s=arc-20160816; b=c6uZdfBUicZ4mkUaxZApOBJ6h7vzPOfcA5WUVIRMq0UzT7YMUv0Rn42ub+XlmOYZoj J/r62e0T44y6GyAjtjGse2LijS2cnKz51zXh4IfuXxRK1McoSEK0LDs5t7ttIh/a5JEN mPpxj7Hkak/bR7zAClCpcgGds+uh9re8lPXMOYl8LxpEr+gr662pPJpo7RhZXQ7kzc1l sJDbHo4PV+r2mdNdMCI7TFh3uZ1RarNharTAwrqTXHSfIyBwds3cThBOfBBS4Ia2BB9j xRLAtur8K/iauVWiOt57VsDAKnrs41mIlO4dGlHCeueTSlncjmjwWHnkNYla8rAPWpoK ZV8w== 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 :arc-authentication-results; bh=WbsOuxM0T1xlETmGM+NiS7la7N53yDnej8y3LUycAZQ=; b=u3bQmjtYDwb/36jqGnirgyv5tGeeKKeDkqoJXVNBW4z/uY5d7sMR/I3oxbLmevvH7t MP3b9XAciji+h1LcFCkn5JHsoyllE5Hun4B3w5eogQJX3dh+R1iFUhp/DfLsnxEgXZUK 7RKr6m8GQ7YuuVhMF43dZGfUPsRpRe1lqWza1Bv88Jb4SUy3JYFVSvudWU306YnNwMs0 DgzLYw8D+E1t/s6bP5LMNKQ0CY1IuI1foKccW8aB75IJBTCF2wRqtMNmAVsR+PndP3OI sUIw3hisThru3yYbr2JD7km+9LVIia+pAGUGbr/B5HW3Ef67RUKI6WqLTgELsRWOEjCq TODw== 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 k11-v6si7990166pgm.154.2018.07.23.05.47.00; Mon, 23 Jul 2018 05:47:15 -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 S2388768AbeGWNqL (ORCPT + 99 others); Mon, 23 Jul 2018 09:46:11 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:50088 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388102AbeGWNqK (ORCPT ); Mon, 23 Jul 2018 09:46:10 -0400 Received: from localhost (LFbn-1-12238-233.w90-92.abo.wanadoo.fr [90.92.53.233]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 51B16BCF; Mon, 23 Jul 2018 12:44:39 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Linus Torvalds , Thomas Gleixner , Ingo Molnar , David Woodhouse , "Srivatsa S. Bhat" , "Matt Helsley (VMware)" , Alexey Makhalov , Bo Gan Subject: [PATCH 4.4 048/107] x86/nospec: Simplify alternative_msr_write() Date: Mon, 23 Jul 2018 14:41:42 +0200 Message-Id: <20180723122415.293766993@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180723122413.003644357@linuxfoundation.org> References: <20180723122413.003644357@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.4-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: David Woodhouse Signed-off-by: Greg Kroah-Hartman Signed-off-by: Srivatsa S. Bhat Reviewed-by: Matt Helsley (VMware) Reviewed-by: Alexey Makhalov Reviewed-by: Bo Gan 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 @@ -195,15 +195,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) {