Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4438688ybi; Mon, 3 Jun 2019 10:52:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqzAP/gm8c/1F40G8QHMzG6oPWVCHbyL9kturrTwEjLFk8uTLixg+Can9yHkDyKQM8JijgHQ X-Received: by 2002:a17:90a:336e:: with SMTP id m101mr30642270pjb.5.1559584321917; Mon, 03 Jun 2019 10:52:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559584321; cv=none; d=google.com; s=arc-20160816; b=b+c6aPL6mMErT25C2qdM6ON0Z0FkG8iKD/fDY36bkugVB+KhaMDD8Hv6oov4SMs42E cPff0k7SLEHLkdV/bGWYwm0hQvTKbwMOkqkWnPqgJeR2jt8VBWM1NXGX6X0SasOLPE0F LeLDF6XGbsxA4d/uy1+O+MOU2cZ36XfYyDdL+/ECUGaGvcR8670QJ9WobD6XSvwEhCN8 v7bTyAhYrElO2SBGtFKnAHO2tZLnGSXXWQWG8nCaE3AKJaLcZEuhPDHkslYrzxW2LlEL 2ix9YgBt9CzQIMlNiUm/1P1AoIlcGuV6d0l+YiogfId+7rP70oyJToPqvUA/bWdt3cZG TQ1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=h3Ja00BbWjTds9gLVY34uk5W952Gfgdpijb1g0bkj4Y=; b=eHi+G2nvB1FIKeA2K45qqObkoh3oKoVSeSHAZqRCdVmbaUcCVn+UAhyur3RDYZ/oiM Tp4mFypJypXgGTGY8UXafekn+nfDA3P8In3iV9FAivtoryBPgbTN82CH/+h/K5s5/6ND EL6xUFEu9iODI+M+jAjTDJfhdkTaCYtEHp3YTPDbKYj9CrN2jFthFtcaEyFPs9a500Rb dHpGK0SK6g+ahfxFRUmvQKYVseQroiZGG/J6t9tcYFSzClXVGpirSQ2kXou/iN02rCIF DM3NpgFVe2i5LwVnvwvxDT8Ya+3UQG88hbjRhRKKz2tdIcGNaAzR5TUOFHOXhjWCRdqk 67oQ== 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u9si19133378pls.145.2019.06.03.10.51.46; Mon, 03 Jun 2019 10:52:01 -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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729780AbfFCQ43 (ORCPT + 99 others); Mon, 3 Jun 2019 12:56:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58690 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727866AbfFCQ41 (ORCPT ); Mon, 3 Jun 2019 12:56:27 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 683FE8B947; Mon, 3 Jun 2019 16:56:22 +0000 (UTC) Received: from flask (unknown [10.43.2.83]) by smtp.corp.redhat.com (Postfix) with SMTP id 456101017E3E; Mon, 3 Jun 2019 16:56:17 +0000 (UTC) Received: by flask (sSMTP sendmail emulation); Mon, 03 Jun 2019 18:56:17 +0200 Date: Mon, 3 Jun 2019 18:56:17 +0200 From: Radim =?utf-8?B?S3LEjW3DocWZ?= To: Like Xu Cc: Paolo Bonzini , kvm@vger.kernel.org, Ingo Molnar , linux-kernel@vger.kernel.org Subject: Re: [RESEND PATCH v3] KVM: x86: Add Intel CPUID.1F cpuid emulation support Message-ID: <20190603165616.GA11101@flask> References: <20190526133052.4069-1-like.xu@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190526133052.4069-1-like.xu@linux.intel.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 03 Jun 2019 16:56:27 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2019-05-26 21:30+0800, Like Xu: > Add support to expose Intel V2 Extended Topology Enumeration Leaf for > some new systems with multiple software-visible die within each package. > > Per Intel's SDM, when CPUID executes with EAX set to 1FH, the processor > returns information about extended topology enumeration data. Software > must detect the presence of CPUID leaf 1FH by verifying (a) the highest > leaf index supported by CPUID is >= 1FH, and (b) CPUID.1FH:EBX[15:0] > reports a non-zero value. > > Co-developed-by: Xiaoyao Li > Signed-off-by: Xiaoyao Li > Signed-off-by: Like Xu > Reviewed-by: Sean Christopherson > --- > ==changelog== > v3: > - Refine commit message and comment > > v2: https://lkml.org/lkml/2019/4/25/1246 > > - Apply cpuid.1f check rule on Intel SDM page 3-222 Vol.2A > - Add comment to handle 0x1f anf 0xb in common code > - Reduce check time in a descending-break style > > v1: https://lkml.org/lkml/2019/4/22/28 > > arch/x86/kvm/cpuid.c | 11 ++++++++++- > 1 file changed, 10 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c > index 80a642a0143d..f9b41f0103b3 100644 > --- a/arch/x86/kvm/cpuid.c > +++ b/arch/x86/kvm/cpuid.c > @@ -426,6 +426,11 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, > > switch (function) { > case 0: > + /* Check if the cpuid leaf 0x1f is actually implemented */ > + if (entry->eax >= 0x1f && (cpuid_ebx(0x1f) & 0x0000ffff)) { > + entry->eax = 0x1f; Sorry for my late reply, but I think this check does more harm than good. We'll need to change it if we ever add leaf above 0x1f, which also puts burden on the new submitter to check that exposing it by an unrelated feature doesn't break anything. Just like you had to see whether the leaf 0x14 is still ok when exposing it without f_intel_pt. Also, I don't see anything that would make 0x1f worthy of protection when enabling it also exposes unimplemented leaves (0x14;0x1f). Zeroing 0x1f.ebx disables it and that is implicitly being done if the presence check above would fail. > + break; > + } > entry->eax = min(entry->eax, (u32)(f_intel_pt ? 0x14 : 0xd)); Similarly in the existing code. If we don't have f_intel_pt, then we should make sure that leaf 0x14 is not being filled, but we don't really have to limit the maximal index. Adding a single clamping like /* Limited to the highest leaf implemented in KVM. */ entry->eax = min(entry->eax, 0x1f); seems sufficient. (Passing the hardware value is ok in theory, but it is a cheap way to avoid future leaves that cannot be simply zeroed for some weird reason.) Thanks.