Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp3055246imb; Mon, 4 Mar 2019 23:04:04 -0800 (PST) X-Google-Smtp-Source: APXvYqxzyK/9akHAIw7wEeNE1bNLg/si0pFlWdvXSed46ViB3PR5VeSCSMDHojY2GILu1hoUlW0A X-Received: by 2002:a17:902:4a0c:: with SMTP id w12mr24114590pld.174.1551769444228; Mon, 04 Mar 2019 23:04:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551769444; cv=none; d=google.com; s=arc-20160816; b=Wwa02VEjpXdUe2eHU0gVc9/TCsen4IA6F2XFdaYealnL95GBKBCNy8TRQKpUSyyPoy WIGb51LqH7s5/I9B//oULaw6DcaDLSU/8/avloc169NSjsoxc6DL98G7ERL0CtQhsjrH HWcV8auZGWJzRhLJiLAjaoKJjJuijamvcGXZcXa//duJKS4fwnlGydfx/KBrcYPAus3s C2IgYNVirlTbUESKmo46KqX2inY5NzpROUr0US+21B1PsaFgFS/71qFc93BsQGZI4NZp Agv1NKIHS0p0lET7DlMO4fFxkDfXAa00zq5FTLrCtDEG/1sNxguCXgW/ejgCWY/sjBG8 yflg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id; bh=ImUHq9/CR4DfmdN6/nO5PaTaIVhdpQDytRs8euDO0UQ=; b=SzCeGaOCGOfTsrRrZyD4e/cOC742Lb/n0NRcoFb18bsSbSq/UWongo/JJsrMNS4f6T T+hgwqkerxRmKk3SOl9FEmMisC9Hb2RdzjrLXKXYvuNIBgMviFeKhWnw9/EP7gstF++G UhZy6EbbAOrEJ5KnJLwHSqEjH1Mh3wLSZBT0+zLu5aT28tBdVYwZVbfjbWf46FpHbO0/ RU3eqhafXoy63epYx8xiBgkGM7qHIJUsFhZsYNmMPLu5fQ8kPhR5atByLvN1MDm/lc9z H5ia5Cv2hp4kVqGHcJvNLmKKhqvDUZVGDuHRGHbOBrF9d7KiIVMnmiYQ1zgnCAqkMLlN el1w== 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 e13si7035200pgu.102.2019.03.04.23.03.49; Mon, 04 Mar 2019 23:04:04 -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 S1727019AbfCEHD3 (ORCPT + 99 others); Tue, 5 Mar 2019 02:03:29 -0500 Received: from mga11.intel.com ([192.55.52.93]:34062 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725909AbfCEHD2 (ORCPT ); Tue, 5 Mar 2019 02:03:28 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Mar 2019 23:03:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,442,1544515200"; d="scan'208";a="131665009" Received: from lxy-dell.sh.intel.com ([10.239.159.147]) by fmsmga007.fm.intel.com with ESMTP; 04 Mar 2019 23:03:26 -0800 Message-ID: <42b45a5bc4dfa5ffdf908cb3e1b95839a2b6b596.camel@linux.intel.com> Subject: Re: [PATCH v4 15/17] kvm: x86: Report CORE_CAPABILITY on GET_SUPPORTED_CPUID From: Xiaoyao Li To: Paolo Bonzini , Fenghua Yu , Thomas Gleixner , Ingo Molnar , Borislav Petkov , H Peter Anvin , Dave Hansen , Ashok Raj , Peter Zijlstra , Ravi V Shankar Cc: linux-kernel , x86 , kvm@vger.kernel.org Date: Tue, 05 Mar 2019 15:03:28 +0800 In-Reply-To: References: <1551494711-213533-1-git-send-email-fenghua.yu@intel.com> <1551494711-213533-16-git-send-email-fenghua.yu@intel.com> <697ee0bd-a5f6-7712-017e-455eed5bc185@redhat.com> <79b659fb-1c16-463d-aa74-f1b3d8a9db5d@redhat.com> <08b44b2b7aede11a350f234768d5c17f8445984e.camel@linux.intel.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5 (3.28.5-2.el7) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2019-03-04 at 12:14 +0100, Paolo Bonzini wrote: > On 04/03/19 12:10, Xiaoyao Li wrote: > > Like you said before, I think we don't need the condition judgment > > "if(boot_cpu_has(X86_FEATURE_SPLIT_LOCK_DETECT))", but to set > > F(CORE_CAPABILITY) > > always for guest since MSR_IA32_CORE_CAPABILITY is emulated. > > > > And we should set the right emulated value of MSR_IA32_CORE_CAPABILITY for > > guest > > in function kvm_get_core_capability() based on whether > > boot_cpu_has(X86_FEATURE_SPLIT_LOCK_DETECT) just as you commented in the > > next > > patch. > > Yes, that would certainly be better. However, you'd also have to move > MSR_IA32_CORE_CAPABILITY handling to x86.c, because you'd have to enable > X86_FEATURE_CORE_CAPABILITY for AMD. > > Paolo Hi, Paolo I just notice that F(ARCH_CAPABILITIES) is set unconditionally. However the handling of MSR_IA32_ARCH_CAPABILITIES only exists with vmx, and the emulation of this MSR is in vmx->arch_capabilities. These will cause #GP when guest kernel rdmsr(MSR_IA32_ARCH_CAPABILITES) with AMD CPU since there is handling for svm. Maybe what I think is not correct due to my limit knowledge of MSR_IA32_ARCH_CAPABILITIES and how kernel handles its related features. If what I said above is true and it's indeed an issue. So based on the fact that both MSR_IA32_ARCH_CAPABILITIES and MSR_IA32_CORE_CAPABILITY are feature- enumerating MSR and we emulate them in KVM, there are 2 choices for us to handle it: 1. we unconditionally set F(ARCH_CAPABILITIES) and F(CORE_CAPABILITY) for guest, move the emulation of these 2 MSRs to vcpu->arch.***, and move all the handling of these 2 MSRs to x86.c. 2. we conditionally set F(ARCH_CAPABILITIES) and F(CORE_CAPABILITY) only if it is intel CPU. So we just need to emulate these 2 MSRs in vmx->*** for intel CPU. I prefer option 2 personally for CORE_CAPABILITY since it makes no sense to expose MSR_IA32_CORE_CAPABILITY to other x86 vendors. About ARCH_CAPABILITIES, it seems that we emulate it for generic x86 cpus that !x86_match_cpu(cpu_no_speculation). So we should choose option 1, to move the emulation and handling to x86.c? Xiaoyao