Received: by 2002:ab2:7407:0:b0:1f4:b336:87c4 with SMTP id e7csp73538lqn; Thu, 11 Apr 2024 14:23:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX7H323TmjFzST3C7iky2i8DqO8QCn8cb6VnNse4Q6Jp8E1o1G2kESML3PPtsygOiWbMN1k9f85E4wlXh81XorwoqETpaKOfxtgEkvdbA== X-Google-Smtp-Source: AGHT+IH7+18LyyUScH5NDjvYcn5d2vZZtHPIHRqKj6RXshsrk9Tt7zsWMXaE1/MG26InVcH+woiE X-Received: by 2002:a17:902:cf41:b0:1e3:e249:41eb with SMTP id e1-20020a170902cf4100b001e3e24941ebmr1157845plg.32.1712870620804; Thu, 11 Apr 2024 14:23:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712870620; cv=pass; d=google.com; s=arc-20160816; b=wGArKDk/FJ4JthPNzwNmYHtVhIYIab4DC2KEkQu4LjYxx86cDbC1l2qO1whQwqfG90 4AJvLRgRDG2lIBKFXLmfg/zWMovRo8UH8n+Tm8KZpP3A+V1fVpMTH3NcgTgZkhX49Le5 pEZF6HsrYxGIRKNTx8lqAxjos+8ivi9eWj6rvCmNZ4KP01uWHYnJLXhcU1jktFb2JOMN cOkcVHjqn/+CSTwZNMxpRnndoVofuIatDPXnRi4zkfXxd2Cq2r20Knvibf9PfZB/ZGO6 qU2gMqKNQHtXks2v1pZr7gO7JdNHkzRixQOCOMrq58VPLAhIa/GvSpv0x1s8TyY2A8f3 aEkQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=f4sYynhcMrBtwb48cfVkTJ5DoHsaKANS6hAxyOyilKo=; fh=P1yMa6DD9zAZQzFumsDDr2/1ldC8VAHaYHIg3SB3cm4=; b=DJz97IDyEvdH68H6ebZIPddqr2OSxnVDuN6K7UnsGXgof8R4k7KnC1gHChX2NOs73f 2VyWvIHebq6CZDeMQx7jda3GAdLZZBB6c4OfDfiJ5G1XgxZD4DAgFT/PPOjHig0qioeK BWZ5y78gbw3R/sIvplnwGivLQhiWM+GARPtgXanHgcKyIHv0Rwn747qPRALhYAqaUbxh KlucNXbYD0FFJ6P+DF+jScWrN22tkPTIbMTmJOqIUOjhl+3y/jWJ0EfPH5lPL6g/3u30 YZ8DiPN68AoF/WxYEqi2/9b7PffubeXCfJhoMByQ2cCw2IBjjCsLJPHGhJ/u4vjQC+4i uAHw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=XFm20QOy; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-141626-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141626-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id e13-20020a170902ef4d00b001e55d0f42c5si1591636plx.168.2024.04.11.14.23.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 14:23:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-141626-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=XFm20QOy; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-141626-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141626-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 76BAF283FAA for ; Thu, 11 Apr 2024 21:23:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A82C438388; Thu, 11 Apr 2024 21:23:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="XFm20QOy" Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3B683BBE3 for ; Thu, 11 Apr 2024 21:23:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712870605; cv=none; b=O0b9z7GtysL4mo4/hv31xK1qfS6bXqg8MyEQf3aLUOTEj44dGquvhMMEjhcU0ZPDCpGgiOxLq00dn0LqzjQ42ESSpctlSP69TurUdtd/eVr/APycfFlnZNENkOTykhWgUo49XFBIUJ4x8RSH91gOJtVEXxrZ2Dae3loNObvX/fU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712870605; c=relaxed/simple; bh=+D2gqeHElRX7BXeeD1K9fckk7QQ7DkL0FOAQt6ybymU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=XDjt24S9E+P2syAykJAKCW1UN6fGK+GnKkh6AxVMKtuABqn/NkR1+iGAwGtUdL/CNn2i/eG7GCnlT/ZsQMjteEaXGjr2nsUfPZhiyMgEYzNzU7+HkojEy6OvT9EshSPyq63u304HVTV4TCmeAaw3qF+rp65KJ53gjG3gbscvyPg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=XFm20QOy; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2a2c4a28e43so182103a91.2 for ; Thu, 11 Apr 2024 14:23:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712870604; x=1713475404; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=f4sYynhcMrBtwb48cfVkTJ5DoHsaKANS6hAxyOyilKo=; b=XFm20QOy/jSp8lW2aAR1UhriMz5YlZh9GILImy2itFB9NLKz0smphMXgcSAbjjFQvU PbLdAs11yFZDPu7PcKWKdxdiOrmcrgGO5n8QUeV6NQwa9V+Mf3XJEwtkbOVtLoGggRZ8 mCy3sRiwR3LRSZivYti1JvcguV0K+eHjtXKFy03zMqaoG05cPWQTZ9CGQ2Fxejl5f9YX TTJE3o7AYJAylMX5FUYhBQOzqBLdv1gl+t1rsVhOiJACdL+Ddv2103TFagu8f86OtidM gXWlFwvDiU47gQgelhH8fxayK8/OWoqRTDzYXXG7ROvWHuGhod40Vd6OWhEWe7pvE/oM pbuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712870604; x=1713475404; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=f4sYynhcMrBtwb48cfVkTJ5DoHsaKANS6hAxyOyilKo=; b=OWi/k3ptgfyUBrXBL4dCA1ltBTbM1sE6Poq12IYXG3fBAcdNSlFCaoBPcJOI+tBT90 U+0coY2H/hr6gq1XFM4HSz7USIFqfMAINAz5XXKY54xBa+HtwVMwTkDXKPSJtDEoaVVM RcbxtyjAL9lGZZJQf04SkBAqmG1LHXjB+ioz0nr4yB93WmBig+Ov5jCmH71n0G/uZDkG U+DjsJ2+ZxcyJjrrvo2aT1zB/gkoxI91YUEG6LkhnGrc/TRpslFjIOU6P4wbjxicEgNk 12bII0clFeQYCm9KCDzazNzuUGAHsPOSl9C537pfRasElNTkNkJAeOV9An1ZVWQmlSLt X+vQ== X-Forwarded-Encrypted: i=1; AJvYcCXQBXrLmN0e93pHGKp8tpbwq6JyDYaXFqoEhI4nW55bDiuquoUeiwOI8M0c75zE5EA22uf9lAT8s3vtFUITGj9AhWF/VhubY/acG5nx X-Gm-Message-State: AOJu0YypSc3NkYzEKAC/LQ7mhUoJ2ZBAKEW8bIZPKnhg/ei1IKIvqwno feytinbCUbzVvvfnb3CQeEOvEthfmsGidpXJZEL1r11i8LoPpi56Pxjxj3gKnysrqqKKYr6v8eq gJg== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:90a:e213:b0:2a5:c05e:6e3d with SMTP id a19-20020a17090ae21300b002a5c05e6e3dmr2191pjz.0.1712870603948; Thu, 11 Apr 2024 14:23:23 -0700 (PDT) Date: Thu, 11 Apr 2024 14:23:22 -0700 In-Reply-To: <20240126085444.324918-19-xiong.y.zhang@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240126085444.324918-1-xiong.y.zhang@linux.intel.com> <20240126085444.324918-19-xiong.y.zhang@linux.intel.com> Message-ID: Subject: Re: [RFC PATCH 18/41] KVM: x86/pmu: Intercept full-width GP counter MSRs by checking with perf capabilities From: Sean Christopherson To: Xiong Zhang Cc: pbonzini@redhat.com, peterz@infradead.org, mizhang@google.com, kan.liang@intel.com, zhenyuw@linux.intel.com, dapeng1.mi@linux.intel.com, jmattson@google.com, kvm@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, zhiyuan.lv@intel.com, eranian@google.com, irogers@google.com, samantha.alt@intel.com, like.xu.linux@gmail.com, chao.gao@intel.com, Xiong Zhang Content-Type: text/plain; charset="us-ascii" On Fri, Jan 26, 2024, Xiong Zhang wrote: > From: Mingwei Zhang > > Intercept full-width GP counter MSRs in passthrough PMU if guest does not > have the capability to write in full-width. In addition, opportunistically > add a warning if non-full-width counter MSRs are also intercepted, in which > case it is a clear mistake. > > Co-developed-by: Xiong Zhang > Signed-off-by: Xiong Zhang > Signed-off-by: Mingwei Zhang > --- > arch/x86/kvm/vmx/pmu_intel.c | 10 +++++++++- > 1 file changed, 9 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c > index 7f6cabb2c378..49df154fbb5b 100644 > --- a/arch/x86/kvm/vmx/pmu_intel.c > +++ b/arch/x86/kvm/vmx/pmu_intel.c > @@ -429,6 +429,13 @@ static int intel_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) > default: > if ((pmc = get_gp_pmc(pmu, msr, MSR_IA32_PERFCTR0)) || > (pmc = get_gp_pmc(pmu, msr, MSR_IA32_PMC0))) { > + if (is_passthrough_pmu_enabled(vcpu) && > + !(msr & MSR_PMC_FULL_WIDTH_BIT) && > + !msr_info->host_initiated) { > + pr_warn_once("passthrough PMU never intercepts non-full-width PMU counters\n"); > + return 1; This is broken, KVM must be prepared to handle WRMSR (and RDMSR and RDPMC) that come in through the emulator.