Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp198947ybi; Tue, 16 Jul 2019 19:04:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqyWgv9Ah1BP/Lm1UX1ZnG2tFKWzpAMCjg4rv+S6UICHrociQ8KcXr2hozgoeqkhjV/qSo31 X-Received: by 2002:a63:9245:: with SMTP id s5mr38309877pgn.123.1563329049344; Tue, 16 Jul 2019 19:04:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563329049; cv=none; d=google.com; s=arc-20160816; b=L9SaAR5+9REAr7nbObAMrGD4cVFOZsASQegnzs+enzqcuRXPP8+hloYLj935EOSwl7 PDrXI5IbB8gP/rVY45V6ZFQ6nB3VWbxMHdmoXWj73Rvae+swv5puLpdccNoVlOVY9Ibt ZqlndcLm914mm5yyriq+AyIDad3qAaKvzic9KGW6IL+YhsBndospmzKZWODEBfTlRj3v dVJde7pJ3JCEcXSMzLAFh0+hn9jkTcDYvqI0PmoCwHKNNCL7f8c48BPn4MLW3d815ShK MkVT6uarKfDXX76JptVeAIl18u5KM+3VoYGuQJU7t04yCdaNn3gxe30Sr4pgmqSXssUi 1CfQ== 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:references:cc:to:from:subject; bh=77iGygP6zw8rhQw7Y9ykNeAEqLAYXJtk13lGKJPn4hA=; b=xORoxxEjuqF4M5xB5s1cqVhQ93uioeLYyvxNbMeRYgVdXa2V6Re9qjIAKWTgHY/Yrt /vSy/nX+VKCxXk3VwzJJQ7c3lxu0CkkHAOQGYO/ytoDT/gcl8vev1cEvMsCOgkCMdmLN U6KW58ukROUKrteuO1gxajdM7tKuJ8Vg5VMlarg/8VVA5YuNwJnl5mjqr4lieGRTmytt 7QGlFTh/k0nD2ZsimnTRs6O2xzDzUUw3RnaI95hRndJH3pWoNHD221lusLQrcuaJ0+92 1uJfX756HM3eoa6j8r5CcTqSul70vj7cLo0UD8iH404atSDrgqcP4W4WSdIFDyTisQtq 8K4w== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c190si9403419pfb.192.2019.07.16.19.03.51; Tue, 16 Jul 2019 19:04:09 -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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727691AbfGQCDb (ORCPT + 99 others); Tue, 16 Jul 2019 22:03:31 -0400 Received: from mga06.intel.com ([134.134.136.31]:45638 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727430AbfGQCDb (ORCPT ); Tue, 16 Jul 2019 22:03:31 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Jul 2019 19:03:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,272,1559545200"; d="scan'208";a="366860947" Received: from txu2-mobl.ccr.corp.intel.com (HELO [10.239.196.165]) ([10.239.196.165]) by fmsmga006.fm.intel.com with ESMTP; 16 Jul 2019 19:03:28 -0700 Subject: Re: [PATCH v7 2/3] KVM: vmx: Emulate MSR IA32_UMWAIT_CONTROL From: Tao Xu To: Eduardo Habkost Cc: pbonzini@redhat.com, rkrcmar@redhat.com, corbet@lwn.net, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, sean.j.christopherson@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, fenghua.yu@intel.com, xiaoyao.li@linux.intel.com, jingqi.liu@intel.com References: <20190712082907.29137-1-tao3.xu@intel.com> <20190712082907.29137-3-tao3.xu@intel.com> <20190716160358.GE26800@habkost.net> Message-ID: Date: Wed, 17 Jul 2019 10:03:27 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/17/2019 9:17 AM, Tao Xu wrote: > On 7/17/2019 12:03 AM, Eduardo Habkost wrote: >> On Fri, Jul 12, 2019 at 04:29:06PM +0800, Tao Xu wrote: >>> UMWAIT and TPAUSE instructions use IA32_UMWAIT_CONTROL at MSR index E1H >>> to determines the maximum time in TSC-quanta that the processor can >>> reside >>> in either C0.1 or C0.2. >>> >>> This patch emulates MSR IA32_UMWAIT_CONTROL in guest and differentiate >>> IA32_UMWAIT_CONTROL between host and guest. The variable >>> mwait_control_cached in arch/x86/power/umwait.c caches the MSR value, so >>> this patch uses it to avoid frequently rdmsr of IA32_UMWAIT_CONTROL. >>> >>> Co-developed-by: Jingqi Liu >>> Signed-off-by: Jingqi Liu >>> Signed-off-by: Tao Xu >>> --- >> [...] >>> +static void atomic_switch_umwait_control_msr(struct vcpu_vmx *vmx) >>> +{ >>> +    if (!vmx_has_waitpkg(vmx)) >>> +        return; >>> + >>> +    if (vmx->msr_ia32_umwait_control != umwait_control_cached) >>> +        add_atomic_switch_msr(vmx, MSR_IA32_UMWAIT_CONTROL, >>> +            vmx->msr_ia32_umwait_control, >>> +            umwait_control_cached, false); >> >> How exactly do we ensure NR_AUTOLOAD_MSRS (8) is still large enough? >> >> I see 3 existing add_atomic_switch_msr() calls, but the one at >> atomic_switch_perf_msrs() is in a loop.  Are we absolutely sure >> that perf_guest_get_msrs() will never return more than 5 MSRs? >> > > Quote the code of intel_guest_get_msrs: > > static struct perf_guest_switch_msr *intel_guest_get_msrs(int *nr) > { > [...] >     arr[0].msr = MSR_CORE_PERF_GLOBAL_CTRL; >     arr[0].host = x86_pmu.intel_ctrl & ~cpuc->intel_ctrl_guest_mask; >     arr[0].guest = x86_pmu.intel_ctrl & ~cpuc->intel_ctrl_host_mask; >     if (x86_pmu.flags & PMU_FL_PEBS_ALL) >         arr[0].guest &= ~cpuc->pebs_enabled; >     else >         arr[0].guest &= ~(cpuc->pebs_enabled & PEBS_COUNTER_MASK); >     *nr = 1; > >     if (x86_pmu.pebs && x86_pmu.pebs_no_isolation) { > [...] >         arr[1].msr = MSR_IA32_PEBS_ENABLE; >         arr[1].host = cpuc->pebs_enabled; >         arr[1].guest = 0; >         *nr = 2; > [...] > > There are most 2 msrs now. By default umwait is disabled in KVM. So by > default there is no MSR_IA32_UMWAIT_CONTROL added into > add_atomic_switch_msr(). > > Thanks. And for old hardware, kvm use core_guest_get_msrs, but umwait is for now hardware, and if hardware in host doesn't have the cpuid, there is no MSR_IA32_UMWAIT_CONTROL in kvm as well. >> >>> +    else >>> +        clear_atomic_switch_msr(vmx, MSR_IA32_UMWAIT_CONTROL); >>> +} >>> + >>>   static void vmx_arm_hv_timer(struct vcpu_vmx *vmx, u32 val) >>>   { >>>       vmcs_write32(VMX_PREEMPTION_TIMER_VALUE, val); >> [...] >> >> >