Received: by 2002:ab2:7407:0:b0:1f4:b336:87c4 with SMTP id e7csp20148lqn; Thu, 11 Apr 2024 12:23:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWkkPf5/EwenrJo+/NyqSXSqGjOa68tO7x2gdt+HIPXZf0rAK5QuCZdRMqCh5G/jaZQIVC5cfmwHxGT68i0oIpOYEEd92oUC1NqUncbHA== X-Google-Smtp-Source: AGHT+IGs7uqeUancDbynJRGl6t+OeFhCWgwgaqMcH/WKTfBXHSm4FEKv0G9Ar2sA6wUDgEZEmxp0 X-Received: by 2002:a05:6a00:ac2:b0:6ea:7981:d40b with SMTP id c2-20020a056a000ac200b006ea7981d40bmr785617pfl.16.1712863385697; Thu, 11 Apr 2024 12:23:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712863385; cv=pass; d=google.com; s=arc-20160816; b=ayajMjXWfdWbfg2gyYO6BOOMEkx5FEDy7qtJNsZS17UhJH630uOmSbt3Ql8YJPeAqP y+U6Om2Vb0WPCVsVjYtdnuoATiKANL2bhlW3JzcYiMhI+F8tdiS+fJjYD4MdprmMcW7u DQRIAcCnodIm7mh+9H9Ll1oYFresMpVuUciNvJS6l3H3hgxkGlI4d/Pn064/P2G429GT K+R3OCk5NL5VCcHfmcept71MBCh0F4mFjt+TEmLUu85iDp7qLcI7RqI+aiA3rvyExuOO XY+P+CxwJ5Wod+bzcJaun5AV77xisLZoj1T1j49PDApM2Mhx6mtM1UKZ1ogxINQRG+mr Y46A== 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=IuZWM+vvGhXI111nZezq7YkDGfyo2NaCVPFqmlVhiZg=; fh=Ao5XkbzN6tcmxNoyyiTrrtmn6iJN/C88b0v9+LJGWvk=; b=NQM3zWTdSLEdGDPY1B0emxH+JVLvU5L86ng37JEA7sZXYyAFrX5T/3mgNHjynCpBYD dbagPrv1Q1FOMR5P0yGWXnns56geqYz1T+BbmnzpYMtkWapapXRuTsbqm2J7CR4RXpbi 6QgUPsr4DPJU22zNXii1gAT1WEmU5UQwNaLjQzOSl/gm6jo3nEa9BRJeG7403CVp9cKw zWiIORfdwYZ0GU8jPyxwh7tQ5/oZEZRZqJqJ+3f4jo9Kd2sCabQam7rcQocMZ3y0odMF viNtFnE7/8zORhFAlWtQCqDiJOp5IUpVYO0SxmJANlqlCVsrXhW0n6/tx80d1vtr9z3i 1E1g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=HV0dDten; 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-141522-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141522-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. [139.178.88.99]) by mx.google.com with ESMTPS id gq43-20020a056a003beb00b006ee2557baecsi20832pfb.282.2024.04.11.12.23.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 12:23:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-141522-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=HV0dDten; 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-141522-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141522-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 AC074285B35 for ; Thu, 11 Apr 2024 19:21:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BF3DA134B0; Thu, 11 Apr 2024 19:21:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="HV0dDten" Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 BAFF4168B9 for ; Thu, 11 Apr 2024 19:21:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712863294; cv=none; b=qyMmu5zMtDOp97b6nWHswlCTp+835PWSyAsQTHNb5jFicGHgOeVRI8Z7ubqtjL9UstTXPFKPDEQyszdwt9Xdr+kvxbALuFZ4zeQDRWKzhS/TD4BFgJYPXErgrF5wKUaLBmv43i2we2JJGcFp90dJ4bL22HNxWpq7hDRZmMup2Hg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712863294; c=relaxed/simple; bh=0iDrj2AwfZPdpvbdX9zswaCeouu1E0y3S0A8fzExlVM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=NEXB2p7x4sDWu3g7NbDw4Fm9s5K/GssrtSjjB+s71gHpOLHO9Un7O2Kv/xbgj12XnhGIySskG/UTCSyAtWgp8LmJQERNfgB7eh4K1XPTOTi8CqooIo96m6eKbiqOF5/q4hGQHBHqu7yv9z+SjA5Ab6QjY6pgaB+fbnykGDxGsQg= 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=HV0dDten; arc=none smtp.client-ip=209.85.216.73 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-f73.google.com with SMTP id 98e67ed59e1d1-2a2d197ac0aso109942a91.2 for ; Thu, 11 Apr 2024 12:21:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712863292; x=1713468092; 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=IuZWM+vvGhXI111nZezq7YkDGfyo2NaCVPFqmlVhiZg=; b=HV0dDtenLo7xoWt3tuGE+MsFQMFI68O+g88NMlCmQKr+x8ZRiUGCECNYs/6jKKwChQ JJXYDL7g+4v7xePFR0ZkxgAVUyYMR4F88GyBMSltXoz757Z0li4V93dpKTLmc0NeGWpP TLSYY3cTGxAIKRQUwBI2pWU8VaLGCygpmrAQK7tZx/de+8DRt4dZUnUcB6HRxtH++iXI 5fR+HxsBgfm+CZ+En9OCBJYk7z0Bn+ingwGHgrwRUCFvbX4GDJFC2nFNrMATfF6oya0c b1ir/jaxDMz3zFtMwB9kP9LZjoj47DyjRkvhOMcnx+Ui2Kw8CRY+ZbfypYQUQiirvjWy A8jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712863292; x=1713468092; 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=IuZWM+vvGhXI111nZezq7YkDGfyo2NaCVPFqmlVhiZg=; b=MYSa4I4CcqgT6WxRey08nGrUPrzog8/hd1tv2Et8TYVPhIIFkBz7UcMfwZjmu9++KW AaDwR1+xK/+K1EYLUe1BVOdV16MthwsX9+T7NslxriOoI/8DQgef2rjzYq03zEWIw94U V3v/WAGeFSP7rLyz9zrOc5FOfcUqx0oxxGfNQLiegZkqoWpD4boCiDsl+Uz7PA5keldj NFusw0F7LJmVh1pJ7YpP74bkyTtQZvaGPdMKeGF+h1wrHdXS7jLiXMdQFcLzDSdskZ5n Hnw0dZ1r/rB5FJz0ydqoHGR5361HzeCxUb9lI2cUj38B1hfP/tJe2FzSgn915rebHjqD CCXA== X-Forwarded-Encrypted: i=1; AJvYcCVFl9Z2Vw7QBIg6g+FC7kCrl3wlaRAgbfyPFyDJzzN6JEWJUMWPEnOlwHE7RLrGFkwZK+s9X/Y+IJvxHUD6KgybSAxSzh5D/2OEFgzH X-Gm-Message-State: AOJu0Yzt82IEgaPY8M5pLdCUiVNXauap1SDoE/kemry0N0L6racygce8 XAAqK8NHEtEC5SY8RthVKec9Z+jzwbABPU9/EXDWgSmndNYfg2YWTaXKSMdN0xEI/7epp95eKAs djQ== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:90a:fb94:b0:2a5:2428:2253 with SMTP id cp20-20020a17090afb9400b002a524282253mr1232pjb.8.1712863291990; Thu, 11 Apr 2024 12:21:31 -0700 (PDT) Date: Thu, 11 Apr 2024 12:21:30 -0700 In-Reply-To: <20240126085444.324918-8-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-8-xiong.y.zhang@linux.intel.com> Message-ID: Subject: Re: [RFC PATCH 07/41] perf/x86: Add interface to reflect virtual LVTPC_MASK bit onto HW 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: Xiong Zhang > > When guest clear LVTPC_MASK bit in guest PMI handler at PMU passthrough > mode, this bit should be reflected onto HW, otherwise HW couldn't generate > PMI again during VM running until it is cleared. This fixes a bug in the previous patch, i.e. this should not be a standalone patch. > > This commit set HW LVTPC_MASK bit at PMU vecctor switching to KVM PMI > vector. > > Signed-off-by: Xiong Zhang > Signed-off-by: Mingwei Zhang > --- > arch/x86/events/core.c | 9 +++++++-- > arch/x86/include/asm/perf_event.h | 2 +- > arch/x86/kvm/lapic.h | 1 - > 3 files changed, 8 insertions(+), 4 deletions(-) > > diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c > index 3f87894d8c8e..ece042cfb470 100644 > --- a/arch/x86/events/core.c > +++ b/arch/x86/events/core.c > @@ -709,13 +709,18 @@ void perf_guest_switch_to_host_pmi_vector(void) > } > EXPORT_SYMBOL_GPL(perf_guest_switch_to_host_pmi_vector); > > -void perf_guest_switch_to_kvm_pmi_vector(void) > +void perf_guest_switch_to_kvm_pmi_vector(bool mask) > { > lockdep_assert_irqs_disabled(); > > - apic_write(APIC_LVTPC, APIC_DM_FIXED | KVM_VPMU_VECTOR); > + if (mask) > + apic_write(APIC_LVTPC, APIC_DM_FIXED | KVM_VPMU_VECTOR | > + APIC_LVT_MASKED); > + else > + apic_write(APIC_LVTPC, APIC_DM_FIXED | KVM_VPMU_VECTOR); > } Or more simply: void perf_guest_enter(u32 guest_lvtpc) { ... apic_write(APIC_LVTPC, APIC_DM_FIXED | KVM_VPMU_VECTOR | (guest_lvtpc & APIC_LVT_MASKED)); } and then on the KVM side: perf_guest_enter(kvm_lapic_get_reg(vcpu->arch.apic, APIC_LVTPC)); because an in-kernel APIC should be a hard requirement for the mediated PMU.