Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp2980268ybf; Mon, 2 Mar 2020 20:12:51 -0800 (PST) X-Google-Smtp-Source: ADFU+vsRmz/UjFwLlUObjyS/AZYsVYBa/h1SmIjcT0w/Nx0+Ke8ThFhVEfBUkX+kEWK0W+HtoJ2L X-Received: by 2002:aca:d68a:: with SMTP id n132mr1269391oig.40.1583208771656; Mon, 02 Mar 2020 20:12:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583208771; cv=none; d=google.com; s=arc-20160816; b=VlDAt6b2aKjZVWcpH0PQXn/5p0XXvQgq7oJxuMKSvJwqEDc9No1hAB++CypzwcyiA/ eUe/hiYVjOboP4r5k/cp5KTS/9QwjOPvZ7/jcnyXrmEF5dN2+BiqCYFLKJecaFVK1peP YcdCpjRO66145HkSsJZrgWtfUcxPnFCm4n0ymlzekJDkOr7aGY6CMWt/fO6/cHn4b5Hq uCI7YJM0odLkX/SBEzSEmSD9a4RbxiD3vto+QoJT+Bt76ixKnvJOnsh77cpXlW0uTEwS klcJWMoZIPqQM9TCJ3r55Wl7H6BvktU/29rrBC50dDQY2hxkRpz9eyyzH0FlbySorziZ KPQw== 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=tcSiK81Ik+hn3TkY9+F0UmHDR0fDj3o1B/C3G+qEJnY=; b=xoK/RaYvAtHcYKRacaAImk17jHCPRHXv2XCFIXfJM4eNn6jmzJ+/xrPQiUuom4Ias8 WQX5IuqVI9B8MbfzNSaTqGTHjZkKBlwxC/UeCvGGX08yQmipGwB8W1h5iEwVTgg6K/fr 8MCg4oZAg5kKhuN1lMF3XO1NQKJygHCAB8mYgZ4f0biKSyKHUhFYus5kUzxGalrmpB6o QrwCFOZzc/P7M0eZkpemBOE79ntFA1dXrxxb3wyU5B9YAckUreeo2D1FigLysBAkna0S n3WMacKDTLUPxdP/BebMucwky5GpdmGo2EmT5WR6PrrURWc7uTh7OnHOzvUg0C7ksxce 1Dtg== 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 l145si1065504oih.44.2020.03.02.20.12.38; Mon, 02 Mar 2020 20:12:51 -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 S1727228AbgCCEMJ (ORCPT + 99 others); Mon, 2 Mar 2020 23:12:09 -0500 Received: from mga12.intel.com ([192.55.52.136]:10034 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726990AbgCCEMJ (ORCPT ); Mon, 2 Mar 2020 23:12:09 -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 fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Mar 2020 20:12:08 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,510,1574150400"; d="scan'208";a="412601038" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.202]) by orsmga005.jf.intel.com with ESMTP; 02 Mar 2020 20:12:08 -0800 Date: Mon, 2 Mar 2020 20:12:08 -0800 From: Sean Christopherson To: Xiaoyao Li Cc: Jan Kiszka , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/6] KVM: x86: Fix tracing of CPUID.function when function is out-of-range Message-ID: <20200303041208.GE27842@linux.intel.com> References: <20200302195736.24777-1-sean.j.christopherson@intel.com> <20200302195736.24777-2-sean.j.christopherson@intel.com> <188dc96a-6a3b-4021-061a-0f11cbb9f177@siemens.com> <20200302204940.GG6244@linux.intel.com> <16e902a8-7883-0b67-d4ee-73e8fe22f955@intel.com> <20200303034532.GC27842@linux.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 Tue, Mar 03, 2020 at 12:02:39PM +0800, Xiaoyao Li wrote: > On 3/3/2020 11:45 AM, Sean Christopherson wrote: > >On Tue, Mar 03, 2020 at 10:27:47AM +0800, Xiaoyao Li wrote: > >>Sorry I cannot catch you. Why it's a violation of Intel's SDM? > > > >The case being discussed above would look like: > > > >KVM CPUID Entries: > > Function Index Output > > 0x00000000 0x00: eax=0x0000000b ebx=0x756e6547 ecx=0x6c65746e edx=0x49656e69 > > 0x00000001 0x00: eax=0x000906ea ebx=0x03000800 ecx=0xfffa3223 edx=0x0f8bfbff > > 0x00000002 0x00: eax=0x00000001 ebx=0x00000000 ecx=0x0000004d edx=0x002c307d > > 0x00000003 0x00: eax=0x00000000 ebx=0x00000000 ecx=0x00000000 edx=0x00000000 > > 0x00000004 0x00: eax=0x00000121 ebx=0x01c0003f ecx=0x0000003f edx=0x00000001 > > 0x00000004 0x01: eax=0x00000122 ebx=0x01c0003f ecx=0x0000003f edx=0x00000001 > > 0x00000004 0x02: eax=0x00000143 ebx=0x03c0003f ecx=0x00000fff edx=0x00000001 > > 0x00000004 0x03: eax=0x00000163 ebx=0x03c0003f ecx=0x00003fff edx=0x00000006 > > 0x00000005 0x00: eax=0x00000000 ebx=0x00000000 ecx=0x00000003 edx=0x00000000 > > 0x00000006 0x00: eax=0x00000004 ebx=0x00000000 ecx=0x00000000 edx=0x00000000 > > 0x00000007 0x00: eax=0x00000000 ebx=0x009c4fbb ecx=0x00000004 edx=0x84000000 > > 0x00000008 0x00: eax=0x00000000 ebx=0x00000000 ecx=0x00000000 edx=0x00000000 > > 0x00000009 0x00: eax=0x00000000 ebx=0x00000000 ecx=0x00000000 edx=0x00000000 > > 0x0000000a 0x00: eax=0x07300402 ebx=0x00000000 ecx=0x00000000 edx=0x00000603 > >--> MISSING CPUID.0xB.0 > > 0x0000000b 0x01: eax=0x00000000 ebx=0x00000001 ecx=0x00000201 edx=0x00000003 > > > >CPUID.0xB.0 does not exist, so output.ECX=0, which indicates an invalid > >level-type. > > > >The SDM states (for CPUID.0xB): > > > > If an input value n in ECX returns the invalid level-type of 0 in ECX[15:8], > > other input values with ECX > n also return 0 in ECX[15:8] > > > >That means returning a valid level-type in CPUID.0xB.1 as above violates > >the SDM's definition of how leaf 0xB works. I'm arguing we can ignore the > >adjustments that would be done on output.E{C,D} for an out of range leaf > >because the model is bogus. > > Right. > > So we'd better do something in KVM_SET_CPUID* , to avoid userspace set bogus > cpuid. > > >>Supposing the max basic is 0x1f, and it queries cpuid(0x20, 0x5), > >>it should return cpuid(0x1f, 0x5). > >> > >>But based on this patch, it returns all zeros. > > > >Have you tested the patch, or is your comment based on the above discussion > >and/or code inspection? Honest question, because I've thoroughly tested > >the above scenario and it works as you describe, but now I'm worried I > >completely botched my testing. > > > > No, I didn't test. > > Leaf 0xB and 0x1f are special cases when they are the maximum basic leaf, > because no matter what subleaf is, there is always a non-zero E[CX,DX]. > > If cpuid.0 returns maximum basic leaf as 0xB/0x1F, when queried leaf is > greater, it should always return a non-zero value. Yes, and that's userspace's responsibility to not screw up. E.g. if userspace didn't create CPUID.0xB.0 (as above) then it's not KVM's fault for returning zeros when the guest executes CPUID.0xB.0.