Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp336185ybt; Wed, 8 Jul 2020 00:54:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4KI9LqB9mSlwAFjlho47wRjeeze2yRsgbzRHXSYHvVwqzWN/ckLae79N3n5YxqkKdlG9Q X-Received: by 2002:a17:906:1c05:: with SMTP id k5mr49254156ejg.320.1594194895771; Wed, 08 Jul 2020 00:54:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594194895; cv=none; d=google.com; s=arc-20160816; b=ipP8hkAOW+5UZSlhGpmg9BfmfyizhkjBPQqUuSq3VRstpUBW4wa/E40Q31SlNiq24p NmIE7VeW+LFU4SSFdoqakOBFbotdH2/4tarJY4uzfyJlqI20Po73oxhlqyg4nVOYOc2p 8wNpviql2dEUjwySvK78zjffSrF4f+jSTK9D+HQHKGNJweHswWm69cedAwAkXX6kv7VK Z6itmz9E8VhkPxFRjzu8t8naX5xVCKKdPflmNNx5aEdksllTE2ULZcBzsVj6oNVg9goT CPXrzB+9qtL1CQE9KDhlZL9QRdfuRNAnDIIzuoz/N9Mjv6gDsdgOZ/DRijApwIXW2Pp9 i1Og== 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 :message-id:date:subject:cc:to:from:ironport-sdr:ironport-sdr; bh=UDxwCUDJG+4ME8WVYlQ+NHuQBjoC7cBYjxVKGKy01WM=; b=qE8vsZKXuNehbgINUiI19vAa6SQTKFfPksFf8uAEC8DUof6Q/Znq5BrTndZu2p+Teo nObZYuw9sazGtwj7b9uOPQiCd9m3NRaW+enmZDVXuHYi6mKRPsTVMHVg1yO/pVvW7ku5 88ch7pF7in/ipfmtytPIbfed9R8/7KYCFmXutLEX+BSU1c4TnjrV+JT8+F0pUlO/OV/2 CWrIJ4tIaPkjGAegvGmz99WWosagbG3LkQPIvDHJrkDzXn5d8YAz/xd/3mEx4j3huk4+ w+QK1eQMELEvbkuGZcmiTrRvbxG7s5NfhOfkQz3fzf/tkxYThWrWzBdlKeeiRwInOQ3o GVJw== ARC-Authentication-Results: i=1; mx.google.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 jp14si16658866ejb.93.2020.07.08.00.54.32; Wed, 08 Jul 2020 00:54:55 -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; 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 S1726928AbgGHHpr (ORCPT + 99 others); Wed, 8 Jul 2020 03:45:47 -0400 Received: from mga14.intel.com ([192.55.52.115]:6526 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726281AbgGHHpr (ORCPT ); Wed, 8 Jul 2020 03:45:47 -0400 IronPort-SDR: 1TH7ZiWnXz6YvyaMjkgMNMKMejproPQnhzLcO2RnaFkmQgl5xtfkO/qmT+fLGejoAWS9CEQUnP u/EfmfqJ/o+g== X-IronPort-AV: E=McAfee;i="6000,8403,9675"; a="146824183" X-IronPort-AV: E=Sophos;i="5.75,327,1589266800"; d="scan'208";a="146824183" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2020 00:45:46 -0700 IronPort-SDR: FipVNnyyiizItsTNhBtmRKLVSIErnlGiOOG8ZI0gQZC9cTVjabJ14eM0tmizH7RYE6Zxi1gFS0 ljEjTumUXPBQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,327,1589266800"; d="scan'208";a="358029182" Received: from sqa-gate.sh.intel.com (HELO clx-ap-likexu.tsp.org) ([10.239.48.212]) by orsmga001.jf.intel.com with ESMTP; 08 Jul 2020 00:45:44 -0700 From: Like Xu To: Paolo Bonzini , kvm@vger.kernel.org Cc: Sean Christopherson , Wanpeng Li , Jim Mattson , Vitaly Kuznetsov , Joerg Roedel , linux-kernel@vger.kernel.org, Like Xu Subject: [PATCH] KVM/x86: pmu: Fix #GP condition check for RDPMC emulation Date: Wed, 8 Jul 2020 15:44:09 +0800 Message-Id: <20200708074409.39028-1-like.xu@linux.intel.com> X-Mailer: git-send-email 2.21.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In guest protected mode, if the current privilege level is not 0 and the PCE flag in the CR4 register is cleared, we will inject a #GP for RDPMC usage. Signed-off-by: Like Xu --- arch/x86/kvm/pmu.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c index b86346903f2e..d080d475c808 100644 --- a/arch/x86/kvm/pmu.c +++ b/arch/x86/kvm/pmu.c @@ -372,6 +372,11 @@ int kvm_pmu_rdpmc(struct kvm_vcpu *vcpu, unsigned idx, u64 *data) if (!pmc) return 1; + if ((kvm_x86_ops.get_cpl(vcpu) != 0) && + !(kvm_read_cr4(vcpu) & X86_CR4_PCE) && + (kvm_read_cr4(vcpu) & X86_CR0_PE)) + return 1; + *data = pmc_read_counter(pmc) & mask; return 0; } -- 2.21.3