Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934084AbeALPOR (ORCPT + 1 other); Fri, 12 Jan 2018 10:14:17 -0500 Received: from mail-by2nam01on0068.outbound.protection.outlook.com ([104.47.34.68]:10160 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933866AbeALPOP (ORCPT ); Fri, 12 Jan 2018 10:14:15 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; Subject: Re: [PATCH 4/5] x86/svm: Direct access to MSR_IA32_SPEC_CTRL To: Ashok Raj , linux-kernel@vger.kernel.org, Thomas Gleixner , Tim Chen , Andy Lutomirski , Linus Torvalds , Greg KH Cc: Paolo Bonzini , Dave Hansen , Andrea Arcangeli , Andi Kleen , Arjan Van De Ven , David Woodhouse , Peter Zijlstra , Dan Williams , Jun Nakajima , Asit Mallick References: <1515720739-43819-1-git-send-email-ashok.raj@intel.com> <1515720739-43819-5-git-send-email-ashok.raj@intel.com> From: Tom Lendacky Message-ID: <02726248-dd84-310a-7121-063eec2dcd7e@amd.com> Date: Fri, 12 Jan 2018 09:14:07 -0600 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <1515720739-43819-5-git-send-email-ashok.raj@intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: DM3PR12CA0085.namprd12.prod.outlook.com (10.161.151.157) To CY4PR12MB1143.namprd12.prod.outlook.com (10.168.164.135) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 850bebb5-09c9-4924-d13d-08d559cf2313 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020083)(4652020)(48565401081)(5600026)(4604075)(2017052603307)(7153060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BCwedUHHny6tmvlPXVGuyiqXS+kT0NhJxjJjOUY4fpZ1KuM+B5/7Gp509AtNk0vP6OVmRa1jEuURdQ97IgYSxN0gvUen0pb8zLRYSAA1bOkcNjGduqi7QdCQbNQdazt6fZFsIXkZJj+cXPyRwN7B7pCu0p+IbM9e4aoxlI8y4lxZpyaUuAS/C6qN3VTwtiOYSkxIaK9YzMdA5TDbo/9WsKvBQsuBa0q1a1o69Gfff+cRcfqq1V0vXfYnmCZWfBGQkVr5/zbL0mLPQXxK4gbmGfsLrcXvvRf5nde2JWf96bW+k35FAHb1WGHqse+hOwQBNZX/XApcQy8kuQmLZC6g/8CKrvMnCabSeWpAU/IpV2NHsNgE61H/LFpd57WUn6a0aykBctL1E2Aa+WuoMM8WA96WBJkgRl;4:ztQ85vTmKx8zWihsgW1g25mcT0g3OVnf8U/6K/2K2tLEXC3zNffKGjbfkNgsLpDPzESpYazv8N3GZEyNLfRsSUhy5O26+7amfyyoKOZBi+S10pBP2vvGQH8RV3rlKR9UYH6WJyRRJrCDe9vM1+c1Hb7I3XZlEbMHnn9atu6WpZN2umAZFOy+7AgaFU0LbWMU7OeD3F8/QWedfn/uGTZMiOeFV1tmfwWjeJIGxMLjFpXipWLY7eK+HU7TZGgdDePvvhnwJiEoVnQcZeAQTAbxazWd4cUR+8MzggHxG/GgJTR+/hbrZys7Gx5ozgQDWVwj X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(228905959029699); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040470)(2401047)(5005006)(8121501046)(3002001)(10201501046)(3231023)(944501075)(93006095)(93001095)(6055026)(6041268)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123564045)(20161123558120)(6072148)(201708071742011);SRVR:CY4PR12MB1143;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:CY4PR12MB1143; X-Forefront-PRVS: 0550778858 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6049001)(396003)(39860400002)(39380400002)(376002)(366004)(346002)(189003)(199004)(24454002)(15760500003)(2906002)(5660300001)(478600001)(6116002)(7736002)(16576012)(2486003)(316002)(23676004)(66066001)(16526018)(36756003)(52146003)(83506002)(229853002)(65826007)(25786009)(106356001)(52116002)(58126008)(4326008)(72206003)(3260700006)(65956001)(31696002)(110136005)(3846002)(54906003)(65806001)(105586002)(386003)(53546011)(6246003)(59450400001)(47776003)(31686004)(305945005)(8936002)(230700001)(90366009)(6486002)(7416002)(97736004)(68736007)(76176011)(86362001)(2950100002)(575784001)(8676002)(53936002)(6666003)(81156014)(50466002)(81166006)(64126003)(77096006);DIR:OUT;SFP:1101;SCL:1;SRVR:CY4PR12MB1143;H:[10.236.65.116];FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtDWTRQUjEyTUIxMTQzOzIzOkVEK09HVVNUc1UzOWMyR0xjM3oya1N0U1lT?= =?utf-8?B?M3pqL1JqUnFUSW1EU3Iwa1FmamtZTzVmL21LVkxBZ2t3TjFlMENxUEs5Q3di?= =?utf-8?B?dG5lNFdmUDFZbG9IeFNuUzJvYVV2TGJaWU9lZ2Z5YTJPSUtHNldXRldNWHQr?= =?utf-8?B?b3hjVVpMWHhudWVjK1dHQmtkVkQ1cHdONWNjdnVwQmtFOXE2L3B6TzdKZzQ0?= =?utf-8?B?YURrdUVPRzlCQitpdHVqM0kxNi9KSDlMT1d2MWN1YVVudTdJbURkbzNNZjBZ?= =?utf-8?B?RnRsNnlZelhDRUtJZlRjeXlmY1BUVFhPTERKcGQ1aVI1VlY4cWh5L00rdU1Z?= =?utf-8?B?Y3Eva2M2U21sd3k3Mkc5Rmx0MFRBT2F0MGRBd2hTdnFJU3dzOG9uVExFdzJH?= =?utf-8?B?ZzlKVHNmc1BkMnVKakxOYUh5WkJleGhrL1kwMkZnR0d3VExWUDZkbXZUdzRH?= =?utf-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X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jan 2018 15:14:11.4240 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 850bebb5-09c9-4924-d13d-08d559cf2313 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1143 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: On 1/11/2018 7:32 PM, Ashok Raj wrote: > From: Paolo Bonzini > > Direct access to MSR_IA32_SPEC_CTRL is important > for performance. Allow load/store of MSR_IA32_SPEC_CTRL, restore guest > IBRS on VM entry and set restore host values on VM exit. > it yet). > > TBD: need to check msr's can be passed through even if feature is not > emuerated by the CPU. > > [Ashok: Modified to reuse V3 spec-ctrl patches from Tim] > > Signed-off-by: Paolo Bonzini > Signed-off-by: Ashok Raj > --- > arch/x86/kvm/svm.c | 35 +++++++++++++++++++++++++++++++++++ > 1 file changed, 35 insertions(+) > > diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c > index 0e68f0b..7c14471a 100644 > --- a/arch/x86/kvm/svm.c > +++ b/arch/x86/kvm/svm.c > @@ -183,6 +183,8 @@ struct vcpu_svm { > u64 gs_base; > } host; > > + u64 spec_ctrl; > + > u32 *msrpm; > > ulong nmi_iret_rip; > @@ -248,6 +250,7 @@ static const struct svm_direct_access_msrs { > { .index = MSR_CSTAR, .always = true }, > { .index = MSR_SYSCALL_MASK, .always = true }, > #endif > + { .index = MSR_IA32_SPEC_CTRL, .always = true }, > { .index = MSR_IA32_LASTBRANCHFROMIP, .always = false }, > { .index = MSR_IA32_LASTBRANCHTOIP, .always = false }, > { .index = MSR_IA32_LASTINTFROMIP, .always = false }, > @@ -917,6 +920,9 @@ static void svm_vcpu_init_msrpm(u32 *msrpm) > > set_msr_interception(msrpm, direct_access_msrs[i].index, 1, 1); > } > + > + if (boot_cpu_has(X86_FEATURE_SPEC_CTRL)) > + set_msr_interception(msrpm, MSR_IA32_SPEC_CTRL, 1, 1); This isn't needed. The entry in the direct_access_msrs will do this in the loop above. Thanks, Tom > } > > static void add_msr_offset(u32 offset) > @@ -3576,6 +3582,9 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) > case MSR_VM_CR: > msr_info->data = svm->nested.vm_cr_msr; > break; > + case MSR_IA32_SPEC_CTRL: > + msr_info->data = svm->spec_ctrl; > + break; > case MSR_IA32_UCODE_REV: > msr_info->data = 0x01000065; > break; > @@ -3724,6 +3733,9 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr) > case MSR_VM_IGNNE: > vcpu_unimpl(vcpu, "unimplemented wrmsr: 0x%x data 0x%llx\n", ecx, data); > break; > + case MSR_IA32_SPEC_CTRL: > + svm->spec_ctrl = data; > + break; > case MSR_IA32_APICBASE: > if (kvm_vcpu_apicv_active(vcpu)) > avic_update_vapic_bar(to_svm(vcpu), data); > @@ -4871,6 +4883,19 @@ static void svm_cancel_injection(struct kvm_vcpu *vcpu) > svm_complete_interrupts(svm); > } > > + > +/* > + * Save guest value of spec_ctrl and also restore host value > + */ > +static void save_guest_spec_ctrl(struct vcpu_svm *svm) > +{ > + if (boot_cpu_has(X86_FEATURE_SPEC_CTRL)) { > + svm->spec_ctrl = spec_ctrl_get(); > + spec_ctrl_restriction_on(); > + } else > + rmb(); > +} > + > static void svm_vcpu_run(struct kvm_vcpu *vcpu) > { > struct vcpu_svm *svm = to_svm(vcpu); > @@ -4910,6 +4935,14 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu) > > clgi(); > > + if (boot_cpu_has(X86_FEATURE_SPEC_CTRL)) { > + /* > + * FIXME: lockdep_assert_irqs_disabled(); > + */ > + WARN_ON_ONCE(!irqs_disabled()); > + spec_ctrl_set(svm->spec_ctrl); > + } > + > local_irq_enable(); > > asm volatile ( > @@ -4985,6 +5018,8 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu) > #endif > ); > > + save_guest_spec_ctrl(svm); > + > #ifdef CONFIG_X86_64 > wrmsrl(MSR_GS_BASE, svm->host.gs_base); > #else >