Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp644649ybt; Wed, 8 Jul 2020 08:19:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbCBPHOlDTz+EZX8IPjYnYZLzP1YF7lQ/BoChZaN2BPsASsD/0ikaM/elG9oqpcxK0Y6Xv X-Received: by 2002:aa7:d341:: with SMTP id m1mr54198849edr.50.1594221585864; Wed, 08 Jul 2020 08:19:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594221585; cv=none; d=google.com; s=arc-20160816; b=t5DTlfcv+Pxg+xGMOqnLNaQ1DWg5kQPpgBWcgksOx5q0QBFTQ9NWM8g5OEwJxMATr0 Mxk4wAvknnAhriJWz88JxVLp0ZLIXvoQ/q2mLwFS99LoHr0lgGYO4I7V4VFLMZyBxgQO cehzbtbtBKmB+dPdO727sP2ohYuLmKE5Gkr7J/5KW6uLtIa+ZkYAX82UlogDjhyGHY45 KBdQz74ohi1zfnYc14Ejtv2Zw+BuVlIOtLlMhevN3ft6il7VVcxvw4DYgBcVJ/00RVMS j94UBw84UicDvKRdNFpIfRr8tZ4Z0Lj1/ArPsAtO3iPgSVYo0cGtdIo6UnscqoQM4pO8 ci4g== 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:ironport-sdr:ironport-sdr; bh=LcSPd3Y4OBV1RUpZTBELmalrqQi4jK4PGic8+ZyVHDE=; b=X5NY6GSVGlsN+1L0mZ9UM0kzHR+C9jP+lzxmP4afKE7G4s6pD1sJzO2dPOfKQjd6Qp rdCrsD2yiZz5mVXhI68yKR2+es+6vbXLcZbr6hQyPYjIk1eRS0dkkfLOsAYdGOPkUTGx Iq8T7DXFHabL9QSw1WsWPDOh0JrxaSFMg7rdAGT4ywtD2s6/Fr6o6REGnuPrW0duuRNn 74llKQvmZsKQSVYWgjzcalb74sJ62xpfos4+7w0/sNrkO5gtJrBBICGe4xoDjaKxYqds jL5e1yU/hvn24oqj1gm+3TPhNZTipEQYePmxu5MU6lOeG9B7XlsJAQWVZL4wofNjzXd8 TmpA== 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 f16si172120edq.307.2020.07.08.08.19.22; Wed, 08 Jul 2020 08:19:45 -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 S1730113AbgGHPSv (ORCPT + 99 others); Wed, 8 Jul 2020 11:18:51 -0400 Received: from mga06.intel.com ([134.134.136.31]:11387 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729022AbgGHPSu (ORCPT ); Wed, 8 Jul 2020 11:18:50 -0400 IronPort-SDR: z73uPgLersv5Cdg5BARF6cxuNDRnYRox5UsPeNyYWpoh8bPVvFGmVw96iyHcmFys4ls3vH/f9V rEKbcXE2zH1Q== X-IronPort-AV: E=McAfee;i="6000,8403,9676"; a="209354562" X-IronPort-AV: E=Sophos;i="5.75,327,1589266800"; d="scan'208";a="209354562" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2020 08:18:25 -0700 IronPort-SDR: B0EmdemkkNL93R+ZMLys9ThuGln41bIodaP0X/oBHEdPyFe+7e9L2OXcUcf/vPkP1phGNvtGDS GlrQwyrN/ezg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,327,1589266800"; d="scan'208";a="483918610" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.152]) by fmsmga005.fm.intel.com with ESMTP; 08 Jul 2020 08:18:25 -0700 Date: Wed, 8 Jul 2020 08:18:25 -0700 From: Sean Christopherson To: Like Xu Cc: Paolo Bonzini , kvm@vger.kernel.org, Wanpeng Li , Jim Mattson , Vitaly Kuznetsov , Joerg Roedel , linux-kernel@vger.kernel.org Subject: Re: [PATCH] KVM/x86: pmu: Fix #GP condition check for RDPMC emulation Message-ID: <20200708151824.GA22737@linux.intel.com> References: <20200708074409.39028-1-like.xu@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200708074409.39028-1-like.xu@linux.intel.com> 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 Wed, Jul 08, 2020 at 03:44:09PM +0800, Like Xu wrote: > 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. Wrapping at ~58 characters is a bit aggressive. checkpatch enforces 75 chars, something near that would be prefereable. > 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)) This reads CR4 but checks CR0.PE. And maybe put the X86_CR4_PCE check first so that it's the focus of the statement? > + return 1; > + > *data = pmc_read_counter(pmc) & mask; > return 0; > } > -- > 2.21.3 >