Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5344834pxv; Wed, 21 Jul 2021 03:14:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxSTpmArBv2Ib0ioafFeR0SXa8JAuF416NDLimbZTI446hgWY7+lVjgctrwEUCRDDZgj117 X-Received: by 2002:a17:907:2717:: with SMTP id w23mr23781428ejk.377.1626862473692; Wed, 21 Jul 2021 03:14:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1626862473; cv=pass; d=google.com; s=arc-20160816; b=YOFCIogh0c6xK3v+ndfXyO9YZ0mi77Hi61NX3U47yvaAIfh3S1DoFAtRRXDvM6ICFf DTwih2jTOHxcQuJOpzgB+qh7+OfnqxuQdAi+4ep/tbAm3UxSg3WIBedgvkJtZHMF5asT zZph99JCXLHnqCIiTDklE958qsKDtdQPGFMmSn/wD+NCYmo2E21egsmzr4jXbLdJbju3 e1fC28eufXsoXxB2h2y2x919ClAgv3htGnypxd16EOO7JOEZ6p1guJkLSh5/sZ2SpGGB 2yO98oZlRpg8Ce9vw6GXkYtzNcuWX3Kcf6L1KM74q97HVJo5+WNhttBRoj3tmNN67aEJ y2mg== ARC-Message-Signature: i=2; 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:dkim-signature; bh=zAWjP+Vp2B+XLtJjxmEvx5hz2qErRTfk/uA2/Lc5QlQ=; b=X2OCUIq6VRNY3gU1p2rDUUple1ZSOFkmfdMzFip4RHwHmM2VyRPe5kBAXmUjm4DWMG fCyhuBySHl655wteyS1+7NixSRo+1bJtN4QHr3oTpT7R1V2aIN737Ax7xhjmbmiVTvLC 2t2UFuMl9EhU0YU4keuECU9J6xdZiVtG6yKrF8kUIuK5WZTSjotRyv4eXIhxg17oRC2Z mX6trR2hlTu6uKZlGINb5SzFTZNjY1FOq7aWVLhAZqFs44V7vhqUKqQ6fqBjSdNF6cRJ mMCOrPugZzG1OKeVqmwbS2lZY+VZY+ZRApySo0nNpIaJxzkmzauZIu9bnHDBvntBRi7k Leyg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b="QVkS/OLL"; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.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 s11si24973808ejr.369.2021.07.21.03.14.10; Wed, 21 Jul 2021 03:14:33 -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; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b="QVkS/OLL"; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.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 S237495AbhGUJbE (ORCPT + 99 others); Wed, 21 Jul 2021 05:31:04 -0400 Received: from mga06.intel.com ([134.134.136.31]:58471 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237919AbhGUJVh (ORCPT ); Wed, 21 Jul 2021 05:21:37 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10051"; a="272521459" X-IronPort-AV: E=Sophos;i="5.84,257,1620716400"; d="scan'208";a="272521459" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jul 2021 03:02:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,257,1620716400"; d="scan'208";a="470107477" Received: from fmsmsx606.amr.corp.intel.com ([10.18.126.86]) by fmsmga008.fm.intel.com with ESMTP; 21 Jul 2021 03:02:06 -0700 Received: from fmsmsx607.amr.corp.intel.com (10.18.126.87) by fmsmsx606.amr.corp.intel.com (10.18.126.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.10; Wed, 21 Jul 2021 03:02:05 -0700 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx607.amr.corp.intel.com (10.18.126.87) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.10 via Frontend Transport; Wed, 21 Jul 2021 03:02:05 -0700 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.173) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2242.10; Wed, 21 Jul 2021 03:02:05 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O7tnOp0+vwjT9+RdxvgxXbmT1y+T1iNg0k0V2J+55JBKkwL05QSKx0KtFnuVA5bVXu2VCjqz0URQcOdGAR1N+IRiI0LdkEXPuWDvZ7fGQ7lIH7h1rKfFtbZaO8p0JL8pxQBhKeWMjnDm96sgq+X0Gj4BMnObg90das37WGqo1UoeG6H8C8eMh++/IJ1MERc+IMJ5d4Wp2zOc276kki2Sbz73HZy/KnVKLIymm++jT7gNwiuPI16ViFy3KndMsF0rAcqw73Xu0AZko2quDt4aj85FiorZK6W/MZCeM3H5MZ2vL6ccNIOwIAhP9s7UomzezWnC9TIAZK+GZhADIpQQXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zAWjP+Vp2B+XLtJjxmEvx5hz2qErRTfk/uA2/Lc5QlQ=; b=GgYYHrGLXn5zIhFHUaPYCufPt8qRWUBJNiXycJI+RipFdKlZ+eSUMRihZi4RR+lrg3gz0lHQyrgio38bptVup0PFxm/gdyNj0WFTRSJmWIemRekm5vQ7XMi2cAd6pEqXBa8rwffiQpLMmsLMQRckWC/NajQ4PUARUpm3rBHU+MBG6W2cREHlsNwmajgsheR1OHS6cdkyeC1CQYEKjpS9NJ4PsBJN4FCYmbwmwrvBO86ujNFmm//A+Z+EjXPxafVYkf5bHAe4OKVGmaP9tBCUxWaysokytkrU3E0UngRGUEHrJ787xUWmgbJJkXa/mUlPfLZ6K36NyjnwxYnMr1vfsQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zAWjP+Vp2B+XLtJjxmEvx5hz2qErRTfk/uA2/Lc5QlQ=; b=QVkS/OLLdCwMNvDua6aLZuyWN6jKuNsQxzZXRQm0TS3sA+ZaC1IA0Kzjkk73trS3DvagyQgc64YQGAZMRLufs1h5EsQajQoOeW5QKTOqBaXhNIGKgsT/fGmxFVTnHJ1UicaPC6IKl3DBrulyOB7rjnWgT6DXlKV3mFPfKxX9fFA= Received: from DM4PR11MB5453.namprd11.prod.outlook.com (2603:10b6:5:398::15) by DM4PR11MB5551.namprd11.prod.outlook.com (2603:10b6:5:392::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.32; Wed, 21 Jul 2021 10:02:04 +0000 Received: from DM4PR11MB5453.namprd11.prod.outlook.com ([fe80::38aa:9c52:efcd:4652]) by DM4PR11MB5453.namprd11.prod.outlook.com ([fe80::38aa:9c52:efcd:4652%3]) with mapi id 15.20.4331.034; Wed, 21 Jul 2021 10:02:03 +0000 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" , Robert Hoo 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: AQHXZIuB9zPySR3qkk2RxIcrlGLzAKseKLEAgAAIJYCALy/4cA== Date: Wed, 21 Jul 2021 10:02:03 +0000 Message-ID: References: <20210618214658.2700765-1-seanjc@google.com> In-Reply-To: Accept-Language: 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-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 4be4a210-c5f7-49b2-d3fb-08d94c2e9745 x-ms-traffictypediagnostic: DM4PR11MB5551: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: PqqWt4jY924UDURcYdVHyztEhtp/h57Ma2BDCv24bsQbI5uC2Wy9FYHCAYAGmfyTpuFCWlKUrGneFqY5bGNMUosLRhleRk5x3Y/lz5hCNdvnduu4choGAbYb+Zwok6UQgh+7cOFv1E5URz7OCRxVCSTRzTL8i7PDYlaPnrHUv+g8owN62ltVe0QIWcpXc5yzHDYTMeepopctmtoitmjNYi3QN1EVjJjpH82+cMTBFC5ekMmEv3P77XOgmIzjtCdhHytxPLBTVRNUclLflUfBWJjmNUUL894xuF/w7YiK1BW1QZgjheV2bc5Z++VeDSAoRAq/MRsJ23QjYoT/81ZWpmraiNRWhFk4wDEwvruvnVHa4T1LmO6ZyWfFdEWgGowhiUyBXtzoGe7DfDbrfZQqJBfE5ywwA/HxD1wxEGPlk+/9+Xtl59ujGrC8IA2NbEcCcdzOj8BU9FGp6W7nqMwuJXKxSiGY0Gtn7w8mD+4jiX3QBS3IYEsjSoufkxDH4v9NbtzwJKhzIZvTQnu354aUdkbpT0nUu0wYcHpKLYC5yOapM4q+PV8PPKef71qWKNMZf9SimLVywqaYR/oaM5Sfjci6C0Rwo7M/bmMGsdxf9axGi9jrLyOZku1ynwp7tBx4z2CSZVXRua1v/jGDDx1z565WVhMTeIWMWnrsJDveI6hI3aNTp9tirrQZnAAqZI2RwRS9jd5Sm8M+UcatMOqO0w== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM4PR11MB5453.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(346002)(136003)(366004)(39860400002)(376002)(7696005)(8936002)(8676002)(186003)(55016002)(83380400001)(52536014)(71200400001)(86362001)(110136005)(54906003)(5660300002)(64756008)(66446008)(6506007)(66556008)(4326008)(66476007)(76116006)(26005)(53546011)(316002)(66946007)(122000001)(38100700002)(478600001)(2906002)(9686003)(33656002)(38070700004);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?tu+6aGt0+DQwt0K4atvtuMnGSnqvyGn7Ba7pHY2z4TiBjXs+qR5VmdBAmRk6?= =?us-ascii?Q?Z8DIgg8W3bkrwMiNlaiNXm83Aj+w+W+LvIqxDH/ZjM2Om+W8YITG9zL0KlsE?= =?us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KrvS5MPTIwwRbvMggjIrX1s/LW5GhChxJ?= =?us-ascii?Q?5+6pIZ3JUVDRzHmnSmvghyV2NpJMfgQ4QI4wukxqD+3ijOYnvAbH29khVsMT?= =?us-ascii?Q?HPYA2tnn6Ri207DZ8Z5tD+VHGcqN9AZWpBbT0gqWxdeBMAbDjaiTqCLvvXI1?= =?us-ascii?Q?e8dqZYBHrjaQGHwNxZbxYFKSSVRlZ8eul4/7PtJmhzTNnGCL83hUorfrUhef?= =?us-ascii?Q?7XWaO6IhNYJ1bmlLMncEqAV7nBWbt2MonLHa3uEsMHgceuqbeiVXg4YZDvBD?= =?us-ascii?Q?FY6EqZCYpLuDeJeB4BGrJBaRghd6VTCeQL3zobiEOJ2lGrP3DDnRcK0OTLJm?= =?us-ascii?Q?p+cR6iBdrwuwjlpuaUjYZOnE?= x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5453.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4be4a210-c5f7-49b2-d3fb-08d94c2e9745 X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Jul 2021 10:02:03.8513 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: /e6MpeGZ+cI+mZ/rXVQ//TPjz8ALt2LbMibJomJJVkICEugJoi91zNCZRHDOAnrCpMHLW6cCGu2RQLHFxxs3MQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR11MB5551 X-OriginatorOrg: intel.com 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.o= rg > Subject: Re: [PATCH] KVM: nVMX: Dynamically compute max VMCS index for > vmcs12 >=20 > 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 rebuildi= ng > 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=3Dno") should not enable TSC scaling. >=20 > 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 supp= orted. =20 [Hu, Robert]=20 It's right that a number of fields' existence depends on some certain featu= re. Meanwhile, "IA32_VMX_VMCS_ENUM indicates to software the highest index value used in the encoding of any field *supported* by the processor", rath= er than *existed*. So my understanding is no matter what VMCS exec control field's value is se= t, value of IA32_VMX_VMCS_ENUM shall not be affected, as it reports the physical CPU= 's capability rather than runtime VMCS configuration. Back to nested case, L1's VMCS configuration lays the "physical" capability= for L2, right? nested_vmx_msrs or at least nested_vmx_msrs.vmcs_enum shall be put to vcpu scope, rather than current kvm global. Current nested_vmx_calc_vmcs_enum_msr() is invoked at early stage, before v= cpu features are settled. I think should be moved to later stage as well. =20 > To fix that we'd need to add a "feature flag" to vmcs_field_to_offset_tab= le that is > checked against the vCPU model, though updating the MSR would probably fa= ll > onto userspace's shoulders? >=20 > And FWIW, this is the QEMU code: >=20 > #define VMCS12_MAX_FIELD_INDEX (0x17) >=20 > static void kvm_msr_entry_add_vmx(X86CPU *cpu, FeatureWordArray f) > { > ... >=20 > /* > * Just to be safe, write these with constant values. The CRn_FIXE= D1 > * 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); > }