Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp1101290imc; Mon, 11 Mar 2019 06:33:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqzYn3/39FszZrJR/FxiYvtf5J83BIfL2UNBFubj0OEbcC4b8rKlbP10eCCm2QmrmzksFp/u X-Received: by 2002:a63:d703:: with SMTP id d3mr30281487pgg.167.1552311205382; Mon, 11 Mar 2019 06:33:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552311205; cv=none; d=google.com; s=arc-20160816; b=VQXP3Yd47/uZ93mO93lzuPfC6Lnra5k22/ju28IIeC6vDuOqiPBo1PfoZvKAz66k7O Nt40Z1VilREwS8mQHUgM2nu843r9Q+4Tdms5JSy4e3I/DevKwzf7dV60qzq7lRP+jhDA nUCrZyTi7QtJ84pX6km3ji2jQPfeqsn9umXBEwvj6HNJ1NqQclaBac1j1oyKlHWeSQfx idx9fBpp3I+6OATAODcl6Np9ZIUt6bSjQ2cipCWqeoHW2tjZ9svdPaOETnXm7UJap/mz 3NUjymcVZTOxfgHMsS/icIt1ko7OrCXos03VLKY+oTiFg9xqQbEhqtOO6aTR53/XqDm7 cWIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:cc:to:subject; bh=dRRLnlCJbBRp2Z0UKm/LfnIq4EnUI4SlK/0Bo9xHzJ4=; b=XrReX0QlWshMBve3W/WLGYRX5fgje/zeBPN16lCiDgl6qb8ZQcXJqRTVffNQAO7RuW MyQb9aQy4e55WHwv2LK2I6eQZPADMKtyz5FdD9wP1o4jNf+x7/z/k1vDn8rNtI5XNNvt 1dPxJb9cRIj6+NLMyyPBLIdPyE5p9gWfPWDK8sm1F46sNyXYNUW0aZEIZ+ZA6N4uK+ZQ vPcmF4ysnrmJggNMiIcZyWLTmtRGum28+PbF2tnUtFxDrynbYALrmYqRI1+dA0KZ96vm VCk3tsl5Z1C3bBZ8OVa7COGByPXbenOzju+kF/TIoocMlpDpNmEhAvgB4F1CYlbfJIMw DueQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p4si5150976pfi.93.2019.03.11.06.33.09; Mon, 11 Mar 2019 06:33:25 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727940AbfCKNbt (ORCPT + 99 others); Mon, 11 Mar 2019 09:31:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41448 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727673AbfCKNbr (ORCPT ); Mon, 11 Mar 2019 09:31:47 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 33339307E04C; Mon, 11 Mar 2019 13:31:47 +0000 (UTC) Received: from [10.36.112.64] (ovpn-112-64.ams2.redhat.com [10.36.112.64]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BFA146013A; Mon, 11 Mar 2019 13:31:43 +0000 (UTC) Subject: Re: [PATCH v4 17/17] kvm: vmx: Emulate TEST_CTL MSR To: Xiaoyao Li Cc: linux-kernel , x86 , kvm@vger.kernel.org References: <1551494711-213533-1-git-send-email-fenghua.yu@intel.com> <1551494711-213533-18-git-send-email-fenghua.yu@intel.com> <58653d477d78b2a69927d8707522d91f091bcb52.camel@linux.intel.com> From: Paolo Bonzini Openpgp: preference=signencrypt Autocrypt: addr=pbonzini@redhat.com; prefer-encrypt=mutual; keydata= mQHhBFRCcBIBDqDGsz4K0zZun3jh+U6Z9wNGLKQ0kSFyjN38gMqU1SfP+TUNQepFHb/Gc0E2 CxXPkIBTvYY+ZPkoTh5xF9oS1jqI8iRLzouzF8yXs3QjQIZ2SfuCxSVwlV65jotcjD2FTN04 hVopm9llFijNZpVIOGUTqzM4U55sdsCcZUluWM6x4HSOdw5F5Utxfp1wOjD/v92Lrax0hjiX DResHSt48q+8FrZzY+AUbkUS+Jm34qjswdrgsC5uxeVcLkBgWLmov2kMaMROT0YmFY6A3m1S P/kXmHDXxhe23gKb3dgwxUTpENDBGcfEzrzilWueOeUWiOcWuFOed/C3SyijBx3Av/lbCsHU Vx6pMycNTdzU1BuAroB+Y3mNEuW56Yd44jlInzG2UOwt9XjjdKkJZ1g0P9dwptwLEgTEd3Fo UdhAQyRXGYO8oROiuh+RZ1lXp6AQ4ZjoyH8WLfTLf5g1EKCTc4C1sy1vQSdzIRu3rBIjAvnC tGZADei1IExLqB3uzXKzZ1BZ+Z8hnt2og9hb7H0y8diYfEk2w3R7wEr+Ehk5NQsT2MPI2QBd wEv1/Aj1DgUHZAHzG1QN9S8wNWQ6K9DqHZTBnI1hUlkp22zCSHK/6FwUCuYp1zcAEQEAAbQj UGFvbG8gQm9uemluaSA8cGJvbnppbmlAcmVkaGF0LmNvbT6JAg0EEwECACMFAlRCcBICGwMH CwkIBwMCAQYVCAIJCgsEFgIDAQIeAQIXgAAKCRB+FRAMzTZpsbceDp9IIN6BIA0Ol7MoB15E 11kRz/ewzryFY54tQlMnd4xxfH8MTQ/mm9I482YoSwP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Ew6jqi1oeZzGvfmxarUmS0uRuffAb589AJW50kkQK9VD/9 QC2FJISSUDnRC0PawGSZDXhmvITJMdD4TjYrePYhSY4uuIV02v028TVAaYbIhxvDY0hUQE4r 8ZbGRLn52bEzaIPgl1p/adKfeOUeMReg/CkyzQpmyB1TSk8lDMxQzCYHXAzwnGi8WU9iuE1P 0wARAQABiQHzBBgBAgAJBQJUQnHuAhsMAAoJEH4VEAzNNmmxp1EOoJy0uZggJm7gZKeJ7iUp eX4eqUtqelUw6gU2daz2hE/jsxsTbC/w5piHmk1H1VWDKEM4bQBTuiJ0bfo55SWsUNN+c9hh IX+Y8LEe22izK3w7mRpvGcg+/ZRG4DEMHLP6JVsv5GMpoYwYOmHnplOzCXHvmdlW0i6SrMsB Dl9rw4AtIa6bRwWLim1lQ6EM3PWifPrWSUPrPcw4OLSwFk0CPqC4HYv/7ZnASVkR5EERFF3+ 6iaaVi5OgBd81F1TCvCX2BEyIDRZLJNvX3TOd5FEN+lIrl26xecz876SvcOb5SL5SKg9/rCB ufdPSjojkGFWGziHiFaYhbuI2E+NfWLJtd+ZvWAAV+O0d8vFFSvriy9enJ8kxJwhC0ECbSKF Y+W1eTIhMD3aeAKY90drozWEyHhENf4l/V+Ja5vOnW+gCDQkGt2Y1lJAPPSIqZKvHzGShdh8 DduC0U3xYkfbGAUvbxeepjgzp0uEnBXfPTy09JGpgWbg0w91GyfT/ujKaGd4vxG2Ei+MMNDm S1SMx7wu0evvQ5kT9NPzyq8R2GIhVSiAd2jioGuTjX6AZCFv3ToO53DliFMkVTecLptsXaes uUHgL9dKIfvpm+rNXRn9wAwGjk0X/A== Message-ID: <7a10bb11-e9bf-f49c-6575-25c3da08cfac@redhat.com> Date: Mon, 11 Mar 2019 14:31:38 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <58653d477d78b2a69927d8707522d91f091bcb52.camel@linux.intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Mon, 11 Mar 2019 13:31:47 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/03/19 03:31, Xiaoyao Li wrote: > Hi, Paolo, > > Do you have any comments on this patch? > > We are preparing v5 patches for split lock detection, if you have any comments > about this one, please let me know. No, my only comment is that it should be placed _before_ the other two for bisectability. I think I have already sent that small remark. Thanks, Paolo > Thanks, > Xiaoyao > > On Fri, 2019-03-01 at 18:45 -0800, Fenghua Yu wrote: >> From: Xiaoyao Li >> >> A control bit (bit 29) in TEST_CTL MSR 0x33 will be introduced in >> future x86 processors. When bit 29 is set, the processor causes #AC >> exception for split locked accesses at all CPL. >> >> Please check the latest Intel Software Developer's Manual >> for more detailed information on the MSR and the split lock bit. >> >> 1. Since the kernel chooses to enable AC split lock by default, which >> means if we don't emulate TEST_CTL MSR for guest, guest will run with >> this feature enable while does not known it. Thus existing guests with >> buggy firmware (like OVMF) and old kernels having the cross cache line >> issues will fail the boot due to #AC. >> >> So we should emulate TEST_CTL MSR, and set it zero to disable AC split >> lock by default. Whether and when to enable it is left to guest firmware >> and guest kernel. >> >> 2. Host and guest can enable AC split lock independently, so using >> msr autoload to switch it during VM entry/exit. >> >> Signed-off-by: Xiaoyao Li >> Signed-off-by: Fenghua Yu >> --- >> arch/x86/kvm/vmx/vmx.c | 35 +++++++++++++++++++++++++++++++++++ >> arch/x86/kvm/vmx/vmx.h | 1 + >> 2 files changed, 36 insertions(+) >> >> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c >> index 3e03c6e1e558..c0c5e8621afa 100644 >> --- a/arch/x86/kvm/vmx/vmx.c >> +++ b/arch/x86/kvm/vmx/vmx.c >> @@ -1659,6 +1659,12 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, struct >> msr_data *msr_info) >> u32 index; >> >> switch (msr_info->index) { >> + case MSR_TEST_CTL: >> + if (!msr_info->host_initiated && >> + !(vmx->core_capability & CORE_CAP_SPLIT_LOCK_DETECT)) >> + return 1; >> + msr_info->data = vmx->msr_test_ctl; >> + break; >> #ifdef CONFIG_X86_64 >> case MSR_FS_BASE: >> msr_info->data = vmcs_readl(GUEST_FS_BASE); >> @@ -1805,6 +1811,14 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct >> msr_data *msr_info) >> u32 index; >> >> switch (msr_index) { >> + case MSR_TEST_CTL: >> + if (!(vmx->core_capability & CORE_CAP_SPLIT_LOCK_DETECT)) >> + return 1; >> + >> + if (data & ~TEST_CTL_ENABLE_SPLIT_LOCK_DETECT) >> + return 1; >> + vmx->msr_test_ctl = data; >> + break; >> case MSR_EFER: >> ret = kvm_set_msr_common(vcpu, msr_info); >> break; >> @@ -4108,6 +4122,9 @@ static void vmx_vcpu_setup(struct vcpu_vmx *vmx) >> >> vmx->arch_capabilities = kvm_get_arch_capabilities(); >> >> + /* disable AC split lock by default */ >> + vmx->msr_test_ctl = 0; >> + >> vm_exit_controls_init(vmx, vmx_vmexit_ctrl()); >> >> /* 22.2.1, 20.8.1 */ >> @@ -4145,6 +4162,7 @@ static void vmx_vcpu_reset(struct kvm_vcpu *vcpu, bool >> init_event) >> >> vmx->rmode.vm86_active = 0; >> vmx->spec_ctrl = 0; >> + vmx->msr_test_ctl = 0; >> >> vcpu->arch.microcode_version = 0x100000000ULL; >> vmx->vcpu.arch.regs[VCPU_REGS_RDX] = get_rdx_init_val(); >> @@ -6344,6 +6362,21 @@ static void atomic_switch_perf_msrs(struct vcpu_vmx >> *vmx) >> msrs[i].host, false); >> } >> >> +static void atomic_switch_msr_test_ctl(struct vcpu_vmx *vmx) >> +{ >> + u64 host_msr_test_ctl; >> + >> + if (!boot_cpu_has(X86_FEATURE_SPLIT_LOCK_DETECT)) >> + return; >> + >> + rdmsrl(MSR_TEST_CTL, host_msr_test_ctl); >> + if (host_msr_test_ctl == vmx->msr_test_ctl) >> + clear_atomic_switch_msr(vmx, MSR_TEST_CTL); >> + else >> + add_atomic_switch_msr(vmx, MSR_TEST_CTL, vmx->msr_test_ctl, >> + host_msr_test_ctl, false); >> +} >> + >> static void vmx_arm_hv_timer(struct vcpu_vmx *vmx, u32 val) >> { >> vmcs_write32(VMX_PREEMPTION_TIMER_VALUE, val); >> @@ -6585,6 +6618,8 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu) >> >> atomic_switch_perf_msrs(vmx); >> >> + atomic_switch_msr_test_ctl(vmx); >> + >> vmx_update_hv_timer(vcpu); >> >> /* >> diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h >> index cc22379991f3..e8831609c6c3 100644 >> --- a/arch/x86/kvm/vmx/vmx.h >> +++ b/arch/x86/kvm/vmx/vmx.h >> @@ -191,6 +191,7 @@ struct vcpu_vmx { >> u64 msr_guest_kernel_gs_base; >> #endif >> >> + u64 msr_test_ctl; >> u64 core_capability; >> u64 arch_capabilities; >> u64 spec_ctrl; >