Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp4303238pxv; Mon, 5 Jul 2021 20:09:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1J08cUWNyhH9nRZ5JpG5+mmMD/1BVflDOsb/HFIqGul+4RYWTQemSrKdO38hoi76tvjCk X-Received: by 2002:a17:907:3c81:: with SMTP id gl1mr16343727ejc.48.1625540995176; Mon, 05 Jul 2021 20:09:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625540995; cv=none; d=google.com; s=arc-20160816; b=uHUylihAn0NS/RzkRwB1tl0/53ujnuWxMgImgVq7St73EeRkp3BBl7AM5E1qlU+VXm vKetqypvnyyT9VhSIXX8Wj67S4eal1TbFEyJpw2L9RlZlw7QG4JOMfgq2gK2BBtxj112 yHuexB6p3UBl3IwnpFCjPTp05ksoGgBBFQlD/TgDOCL+Q7DM5oQZzkrfLaXtujdk/mK7 c++juZSw2Rynt2k0fd/5FTrJdENZxtpS2QriDMmexp7phgDvewd4YvELLoKfVr5qCsfr SvCw8loSBqGeS/S1yFheSXb1ymi7fen7uugRaFJF/WGMZoDwqUwhG8jwJi6fqAdtTeWR FxKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :dlp-product:dlp-reaction:dlp-version:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from; bh=QuIWxSmub2qlsYOXwyscKbe9MGvVtTWepVerAUifyfc=; b=COsCVrU+nYeAPkNYUzINpCzcCy7lfQgYZIyLj9hGWyRe8R069w9/i/A0whJLL8fx7n dQ5A64cd+ZU270Y7Z/nSiBoEd65c6k3ZN5LaiQWMZDg2J5zMhMIxkDAoDyuKSE/OhCMz OvUOVbC07eIkrGgfzg07tZq5Qy6kedxcMpWxdlnRKzGcXmH1A/UD4oJq016oSlThWyHP E/679EqFobYySNwAwKivSy91+Y0i29oJ1H1LAFKS4J3ESP6bsUxkuccRIJ3salXyH/Le XkbmsvqZ9NLFZ0xAP3h08ydMdjOBV+59rq0PObatTrEukq5cTBGpa5WnfgDMJFNXOEcV YfEw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id n8si14271940edy.347.2021.07.05.20.09.32; Mon, 05 Jul 2021 20:09:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S229989AbhGFDIR convert rfc822-to-8bit (ORCPT + 99 others); Mon, 5 Jul 2021 23:08:17 -0400 Received: from mga06.intel.com ([134.134.136.31]:44953 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229919AbhGFDIR (ORCPT ); Mon, 5 Jul 2021 23:08:17 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10036"; a="270168143" X-IronPort-AV: E=Sophos;i="5.83,327,1616482800"; d="scan'208";a="270168143" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2021 20:05:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,327,1616482800"; d="scan'208";a="647080111" Received: from fmsmsx604.amr.corp.intel.com ([10.18.126.84]) by fmsmga005.fm.intel.com with ESMTP; 05 Jul 2021 20:05:38 -0700 Received: from shsmsx602.ccr.corp.intel.com (10.109.6.142) by fmsmsx604.amr.corp.intel.com (10.18.126.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.10; Mon, 5 Jul 2021 20:05:37 -0700 Received: from shsmsx603.ccr.corp.intel.com (10.109.6.143) by SHSMSX602.ccr.corp.intel.com (10.109.6.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4; Tue, 6 Jul 2021 11:05:35 +0800 Received: from shsmsx603.ccr.corp.intel.com ([10.109.6.143]) by SHSMSX603.ccr.corp.intel.com ([10.109.6.143]) with mapi id 15.01.2242.008; Tue, 6 Jul 2021 11:05:35 +0800 From: "Hu, Robert" To: Sean Christopherson , Paolo Bonzini CC: Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH] KVM: nVMX: Dynamically compute max VMCS index for vmcs12 Thread-Topic: [PATCH] KVM: nVMX: Dynamically compute max VMCS index for vmcs12 Thread-Index: AQHXZIuB9zPySR3qkk2RxIcrlGLzAKseKLEAgAAIJYCAFyq6oA== Date: Tue, 6 Jul 2021 03:05:35 +0000 Message-ID: References: <20210618214658.2700765-1-seanjc@google.com> In-Reply-To: Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-version: 11.5.1.3 dlp-reaction: no-action dlp-product: dlpe-windows x-originating-ip: [10.239.127.36] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > -----Original Message----- > From: Sean Christopherson > Sent: Tuesday, June 22, 2021 01:08 > To: Paolo Bonzini > Cc: Vitaly Kuznetsov ; Wanpeng Li > ; Jim Mattson ; Joerg > Roedel ; kvm@vger.kernel.org; linux-kernel@vger.kernel.org > Subject: Re: [PATCH] KVM: nVMX: Dynamically compute max VMCS index for > vmcs12 > > On Mon, Jun 21, 2021, Paolo Bonzini wrote: > > On 18/06/21 23:46, Sean Christopherson wrote: > > > Calculate the max VMCS index for vmcs12 by walking the array to find > > > the actual max index. Hardcoding the index is prone to bitrot, and > > > the calculation is only done on KVM bringup (albeit on every CPU, > > > but there aren't _that_ many null entries in the array). > > > > > > Fixes: 3c0f99366e34 ("KVM: nVMX: Add a TSC multiplier field in > > > VMCS12") > > > Signed-off-by: Sean Christopherson > > > --- > > > > > > Note, the vmx test in kvm-unit-tests will still fail using stock > > > QEMU, as QEMU also hardcodes and overwrites the MSR. The test > > > passes if I hack KVM to ignore userspace (it was easier than rebuilding > QEMU). > > > > Queued, thanks. Without having checked the kvm-unit-tests sources > > very thoroughly, this might be a configuration issue in > > kvm-unit-tests; in theory "-cpu host" (unlike "-cpu > > host,migratable=no") should not enable TSC scaling. > > As noted in the code comments, KVM allows VMREAD/VMWRITE to all defined > fields, whether or not the field should actually exist for the vCPU model doesn't > enter into the equation. That's technically wrong as there are a number of > fields that the SDM explicitly states exist iff a certain feature is supported. To > fix that we'd need to add a "feature flag" to vmcs_field_to_offset_table that is > checked against the vCPU model, though updating the MSR would probably fall > onto userspace's shoulders? [Hu, Robert] Perhaps more easier and proper to do this in KVM side. QEMU sets actual feature set down to KVM, and KVM updates IA32_VMX_VMCS_ENUM MSR accordingly. We don't see a channel that QEMU constructs a VMCS and sets a whole to KVM. > > And FWIW, this is the QEMU code: > > #define VMCS12_MAX_FIELD_INDEX (0x17) > > static void kvm_msr_entry_add_vmx(X86CPU *cpu, FeatureWordArray f) > { > ... > > /* > * Just to be safe, write these with constant values. The CRn_FIXED1 > * MSRs are generated by KVM based on the vCPU's CPUID. > */ > kvm_msr_entry_add(cpu, MSR_IA32_VMX_CR0_FIXED0, > CR0_PE_MASK | CR0_PG_MASK | CR0_NE_MASK); > kvm_msr_entry_add(cpu, MSR_IA32_VMX_CR4_FIXED0, > CR4_VMXE_MASK); > kvm_msr_entry_add(cpu, MSR_IA32_VMX_VMCS_ENUM, > VMCS12_MAX_FIELD_INDEX << 1); > }