Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp162158ybi; Tue, 16 Jul 2019 18:18:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqwM/3FDW4MvQzysvX6eD6+O7yDMQ6H217qoHRENFs2oTpbWzaPOugBroUy3Q/+q9R13/cEf X-Received: by 2002:a17:902:7407:: with SMTP id g7mr39824565pll.214.1563326311471; Tue, 16 Jul 2019 18:18:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563326311; cv=none; d=google.com; s=arc-20160816; b=v7bH+AX3ifPhai1E3YqmqW4/2TV4TRev2PL/MWlnWoHOF8YLZyUd7bhl+kE/+gxPlZ fyN5FNLXYoBjL9ESNYA6DcgTNTQJzoGYWpSo3R21xmSRCdaTomDxcf7xjZ+/TksLssRe Wtp+ZoP0B/trn2csQ/Q0VWfRNVQdPnxv6X7XqOhggvX5rg3tNldysODvmCgYYN4mV/fA Oi5EybNEi80VIKhxhhU7HKUnAAr5ZkDAWhLCHl3GpOzYUtkXTuFX2IQ92Dx46ovEuGiF +v2aNqYYggdJOS97H8/CwKWsDcPIQbTPAXvPUNZPeAWLMTIThSXVexq7BVjE0LA/pduN k1Pg== 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:from:references:cc:to:subject; bh=13AoURf1qB0lioWY1QKIase6MNNi6S8hUWTQIG2ZXVY=; b=GIJaSfRA1PaAygJCJ9l6m+iGdjGy9yACLtKBFxS03ciI0n4np8AB3wnK9N8nb9tq0j vt9KLBYfk3aJ7o7nr5LZyE2b2qI+caep/xdVHBV1CZfbrzqcPt31wCvU9AcoHP3C2a85 c02nMQ7pH0XFp8MPFv3zvNGJc+xR5KCpTqR7FSmiqk/x7BDKJo5tFmvtfy/7RKTKKb1J OlRyvykShzupGGZ8htLIXwXAFN+fNJB9ID2BghaaC98BDe/f53ZfFi4mi9vhSD7YQZ/t qk3oqTkXYlWNv+QbAw4xr0Vx0u/bY4ehRqUJejWudPCjUNmP593JtNBETxSeMHbXvvzz 65Eg== 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 a9si20908019plm.295.2019.07.16.18.18.00; Tue, 16 Jul 2019 18:18:31 -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 S1725951AbfGQBRb (ORCPT + 99 others); Tue, 16 Jul 2019 21:17:31 -0400 Received: from mga09.intel.com ([134.134.136.24]:48554 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725850AbfGQBRb (ORCPT ); Tue, 16 Jul 2019 21:17: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 orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Jul 2019 18:17:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,272,1559545200"; d="scan'208";a="366853507" 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 18:17:28 -0700 Subject: Re: [PATCH v7 2/3] KVM: vmx: Emulate MSR IA32_UMWAIT_CONTROL 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> From: Tao Xu Message-ID: Date: Wed, 17 Jul 2019 09:17: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: <20190716160358.GE26800@habkost.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > >> + 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); > [...] > >