Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp6019379ybf; Thu, 5 Mar 2020 11:27:20 -0800 (PST) X-Google-Smtp-Source: ADFU+vvMgo6QCWY8sjmJjkD781ZNvkrzW6nadl0Kes8CnOwZ3BQfMecgmGNfyqlMvhIyo5G+LLCU X-Received: by 2002:a9d:3e89:: with SMTP id b9mr22834otc.3.1583436440473; Thu, 05 Mar 2020 11:27:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583436440; cv=none; d=google.com; s=arc-20160816; b=aHuZHZ0080LcAys5WsoD/QtxkkbiOaFG0PSxKl1Lisx1d+gW9wF6SJrGe7EluNeayK s5lIb2UToL0iNHHWascx0Cmps6P3+emunv2mNRTWNfjJA0IAh/0NoS5/qoXEug13p2b0 WLWgmML9CfPa+4Xt1DMz0kSRNZV1NWMgmDdRWnmEAXz/n3V0FJTx0g9Y7720aLn+fLW0 CPSzmpWdnNNmXfkPkJnRUIuiZjF/XHsVsSBYGbdMnsay5AyKJkl0fwJeCLKN5qxE2WkN FAmznBeSebVE7p7laU1pesdJHzrJSdDYlP+qyBHg8qsesNhNFncSp2DtSrWxoL3epAZ9 oVqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=b/Vrb6yYQh9J/6pVeXne9bDcS3XVSFgD8AWWZ9TMBCQ=; b=AYJHNMTTYKDQZhEQLSq5Iq4ZqZlzMmXKM3mWMlq2Y8w70x4Z+/6aCr0GEtQlq421tB jsVfuZ3+JSnowH81mKfnoRRLtPueNd9+Bm+rmIExAZDbSO/rtuEPKJhpb7gGduEcD2kU qTzWOT0av6DrWyXQUm9o9ZKt7f7fhOruc6+BHHG9Mea/7ZdY58UvnuE+V0zsHL4VvaeO VfxScYXvIquo8uYqYeaYX+ZLsrX0DdC1IBlG9xvCFysuLxMhGs6lphemHfrLZsuzvqUF tUQCE8sql6mYLuog1tn+s49ib6JRBXMJayokwRirty47MAFbGdO2r7AL70/qrCB3JzV2 SfKw== 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 b68si3759198oii.117.2020.03.05.11.27.08; Thu, 05 Mar 2020 11:27:20 -0800 (PST) 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 S1726191AbgCETZd (ORCPT + 99 others); Thu, 5 Mar 2020 14:25:33 -0500 Received: from mga02.intel.com ([134.134.136.20]:59653 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725963AbgCETZd (ORCPT ); Thu, 5 Mar 2020 14:25:33 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Mar 2020 11:25:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,519,1574150400"; d="scan'208";a="413628452" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.202]) by orsmga005.jf.intel.com with ESMTP; 05 Mar 2020 11:25:32 -0800 Date: Thu, 5 Mar 2020 11:25:32 -0800 From: Sean Christopherson To: Jim Mattson Cc: Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Joerg Roedel , kvm list , LKML , Pu Wen Subject: Re: [PATCH v2 4/7] KVM: x86: Fix CPUID range checks for Hypervisor and Centaur classes Message-ID: <20200305192532.GN11500@linux.intel.com> References: <20200305013437.8578-1-sean.j.christopherson@intel.com> <20200305013437.8578-5-sean.j.christopherson@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 05, 2020 at 10:43:51AM -0800, Jim Mattson wrote: > On Wed, Mar 4, 2020 at 5:34 PM Sean Christopherson > wrote: > > > > Rework the masking in the out-of-range CPUID logic to handle the > > Hypervisor sub-classes, as well as the Centaur class if the guest > > virtual CPU vendor is Centaur. > > > > Masking against 0x80000000 only handles basic and extended leafs, which > > results in Hypervisor range checks being performed against the basic > > CPUID class, and Centuar range checks being performed against the > > Extended class. E.g. if CPUID.0x40000000.EAX returns 0x4000000A and > > there is no entry for CPUID.0x40000006, then function 0x40000006 would > > be incorrectly reported as out of bounds. > > > > While there is no official definition of what constitutes a class, the > > convention established for Hypervisor classes effectively uses bits 31:8 > > as the mask by virtue of checking for different bases in increments of > > 0x100, e.g. KVM advertises its CPUID functions starting at 0x40000100 > > when HyperV features are advertised at the default base of 0x40000000. > > > > The bad range check doesn't cause functional problems for any known VMM > > because out-of-range semantics only come into play if the exact entry > > isn't found, and VMMs either support a very limited Hypervisor range, > > e.g. the official KVM range is 0x40000000-0x40000001 (effectively no > > room for undefined leafs) or explicitly defines gaps to be zero, e.g. > > Qemu explicitly creates zeroed entries up to the Cenatur and Hypervisor > > limits (the latter comes into play when providing HyperV features). > > > > The bad behavior can be visually confirmed by dumping CPUID output in > > the guest when running Qemu with a stable TSC, as Qemu extends the limit > > of range 0x40000000 to 0x40000010 to advertise VMware's cpuid_freq, > > without defining zeroed entries for 0x40000002 - 0x4000000f. > > > > Note, documentation of Centaur/VIA CPUs is hard to come by. Designating > > 0xc0000000 - 0xcfffffff as the Centaur class is a best guess as to the > > behavior of a real Centaur/VIA CPU. > > Don't forget Transmeta's CPUID range at 0x80860000 through 0x8086FFFF! Hmm, is it actually needed here? KVM doesn't advertise support for that range in KVM_GET_SUPPORTED_CPUID. That's also why I limited the Centaur range to vendor==CENTAUR, as KVM_GET_SUPPORTED_CPUID enumerates the Centaur range if and only if the host CPU is Centaur.