Received: by 2002:ab2:7407:0:b0:1f4:b336:87c4 with SMTP id e7csp12479lqn; Thu, 11 Apr 2024 12:08:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUpnS6/ff2qbTkpwZZGx/y8eswJYqwIZTEkWFKkmL6iW7ZkArKfZpCRQcDeTgzKm+jh7nmN1xz7mjePj6KOPdBe8jPFvRK2+FM3y+C6vQ== X-Google-Smtp-Source: AGHT+IEhEG2qzuciYl9TqwiWlK8vCsIsAJq+475SMIrxvYqFpa7uHEFlTCWmsEzeUYUcDDJhg1Sw X-Received: by 2002:a17:907:31c9:b0:a51:dc32:ffd0 with SMTP id xf9-20020a17090731c900b00a51dc32ffd0mr450556ejb.63.1712862488931; Thu, 11 Apr 2024 12:08:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712862488; cv=pass; d=google.com; s=arc-20160816; b=lgdQrLG4WcJ1jxe2yBr1W92M6U67peXtJP3+zExmwF1kE86f98efpuIu9u70jwVT5l 8p9cnw4Kj0W+DDocVFk8IAYLdVkoGpxoTk4evdc6RhlT4nJyhlYnSAfW/lYCznCXt2FV FtWsmMunmg2iKH/HD7ErHLJdrhAlfEmbEf/gL2ew82sgpLWkULRZQa/B8MFyFfGDn9ij GA7g8Xh6sZjTsO10+ADq0ht5t/LUBSfP/AfW3uf/TeAsLCMpqztIg2xZIwZ1jMce+lOF EHiVNmUo+MLFGM9/ybE6gkchqUp5CRBynumH3fbG2ULhIdODr2xxMtcUjkz8t25uZwHf tbEg== 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=NcJF+KC6MHAw0xXKqx6sflzbfRynihMrB3htgV72+eA=; fh=+QVHBRboKz57O3NDITZbR9rz5cfdEr1PpNxdNcGYQx4=; b=OnbQmx9QQF0NqywlA1USTEdixSKwv8p32qZUnAHuURKfrYA5n+odjAlW+FBksivvwq J5cFd6sOA3mRpjhjV7PKun9vNtymdoPFzR6xuD7HSFLnsTlwtu4GmZvd7N+R7nYzSsef 40tsD/CJm0IMvjK+Oxc2rcHjWhlB2TePm2Ep+xisWtALttiw/3JYV1I89tTc9tp8LO6l 8vBCmOF0lBn7vKnZ7cU+cuA30Q7mmbo6d/WWZtXwdQRptUPuce6dvC3pGo47Fq364xNd BxyRgYyRdpQB7NiZvOn33gbiNXzD6PP+YZRelyNriUqJOWYKWcrbMBF8huwugAPcosOR HNWQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=f0kynmDk; 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-141502-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141502-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id l22-20020a170906795600b00a51d90e48edsi1097247ejo.721.2024.04.11.12.08.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 12:08:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-141502-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=f0kynmDk; 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-141502-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141502-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 24B621F22C44 for ; Thu, 11 Apr 2024 19:07:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 629E71427E; Thu, 11 Apr 2024 19:07:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="f0kynmDk" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 ED376205E2D for ; Thu, 11 Apr 2024 19:07:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712862465; cv=none; b=BoHo92ZT+ckrhyIBUV34U7OhOFHOhOZVPLhSMdbtPVFIM/MZwpM5BVdDZUE1n7Txd0+OFC0PibH8eFfj4rYDz785fSjMNUgZYlaQQYeNjtuLeorEmpScerVilQfrolvUuKwGMY/hkYoQt29cOZ90f59EcK1GNR0KcRSaxZRE07g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712862465; c=relaxed/simple; bh=K+2mLJIg465ypUQJI5giyc0VIu85pZleLQxiFXuwW4Q=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=CZjsVP46GLdF7khUu1kmsHhYYkHVOWga0KWfmxJgOLA9Dd4k7Pd9LPxyIhNdUlzde+wCWitThz9a6YzyfcEyzunkpTIauqm5sJUoXDb0jYGRDWazCREX3yRAHznEsU7WGl2BkdgyGCDy7Z5E/l6djaMSyXyEoIjRazDCJHy+SQY= 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=f0kynmDk; arc=none smtp.client-ip=209.85.219.201 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-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc6b26ce0bbso256910276.1 for ; Thu, 11 Apr 2024 12:07:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712862462; x=1713467262; 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=NcJF+KC6MHAw0xXKqx6sflzbfRynihMrB3htgV72+eA=; b=f0kynmDkNZPv77oCffRn+KoJ3tdkglIylhkS65IiPp7z2BFEx/rE7+OWoeL6f/SwLy r6F5Bel9eLCxP/0EX5S4KJExzuH6LEsfCuGcckKZpC0YnaidqzO3kV4zdzz9Pny5CvqL BLTbC+nQaNAWBOLsqAzZD7q7agMKrv0peXCtC10BrdJstg8+me2ObLsvBJsyQChUSxjI +9OvKdG4NNoLTmYH3D74Y/GiCCcdhlaCXKOQqI80azuclLd/G6rhbRvwa4UFkpItjjBQ /lOfujifD5xEic3PMQO/Nu3O9oJXVzOMBNR4pooqy6ao+/auEQ6yqLfNDAAClrrXAXTX d56g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712862462; x=1713467262; 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=NcJF+KC6MHAw0xXKqx6sflzbfRynihMrB3htgV72+eA=; b=Xe0ve7enpXxqgPTDzDJYJ4E+nsFQxxdPMf2DKZva64HV3F3tQ5kQjRDLwrf0q0z+yv Qu09crNiQIlkd34HTf9orE3p3sgk/P6XXseGH1//tdrWeVnym+ytVJNXnrtK69yM4XL1 5RsfRPOI/rocn8gIRbHjnHsbHyor/9QG38jA5vooOvu79cMel5VfLVmIoX+IpWEd47RG FruKy7ETpoDHYvXyuuNSVtjzz1N61yztAjSWh1Dlbc8Wlvdp6w50oOIcUXmo82DBSvT+ VViN7j8lai2QKlCkeUmtse8amLtV41UFNRzp5umveV+uFJXt+BE1F8cE4idl2SD++2es 0fnQ== X-Forwarded-Encrypted: i=1; AJvYcCU2ttF6bDYpsPPU4lNusYWm4F+v8+bSFavEJdlV7uWhsQ15kILJ6lMlWA1DIxhBG47HKwMUdgB53aPhKOEGNIuN18gOC/D7wmlsNs32 X-Gm-Message-State: AOJu0Yxms/JXIDSX0OU/v1sQpWp6uKAIKKbHoOJfcJqUJ74/SMUOJaBz cjtZXRa1jfBHLcQcd96pDCIIlf0nrwW/8lFhCvEk6xIyTVpXk7I7SVY9mhZaTtw/0avAt92NUTG XZA== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:188f:b0:ddd:7581:1825 with SMTP id cj15-20020a056902188f00b00ddd75811825mr121974ybb.8.1712862462048; Thu, 11 Apr 2024 12:07:42 -0700 (PDT) Date: Thu, 11 Apr 2024 12:07:40 -0700 In-Reply-To: <20240126085444.324918-6-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-6-xiong.y.zhang@linux.intel.com> Message-ID: Subject: Re: [RFC PATCH 05/41] KVM: x86/pmu: Register PMI handler for passthrough PMU 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 > > Add function to register/unregister PMI handler at KVM module > initialization and destroy time. This allows the host PMU with passthough > capability enabled switch PMI handler at PMU context switch time. > > Signed-off-by: Xiong Zhang > Signed-off-by: Mingwei Zhang > --- > arch/x86/kvm/x86.c | 14 ++++++++++++++ > 1 file changed, 14 insertions(+) > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 2c924075f6f1..4432e736129f 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -10611,6 +10611,18 @@ void __kvm_request_immediate_exit(struct kvm_vcpu *vcpu) > } > EXPORT_SYMBOL_GPL(__kvm_request_immediate_exit); > > +void kvm_passthrough_pmu_handler(void) s/pmu/pmi, and this needs a verb. Maybe kvm_handle_guest_pmi()? Definitely open to other names. > +{ > + struct kvm_vcpu *vcpu = kvm_get_running_vcpu(); > + > + if (!vcpu) { > + pr_warn_once("%s: no running vcpu found!\n", __func__); Unless I misunderstand the code, this can/should be a full WARN_ON_ONCE. If a PMI skids all the way past vcpu_put(), we've got big problems. > + return; > + } > + > + kvm_make_request(KVM_REQ_PMI, vcpu); > +} > + > /* > * Called within kvm->srcu read side. > * Returns 1 to let vcpu_run() continue the guest execution loop without > @@ -13815,6 +13827,7 @@ static int __init kvm_x86_init(void) > { > kvm_mmu_x86_module_init(); > mitigate_smt_rsb &= boot_cpu_has_bug(X86_BUG_SMT_RSB) && cpu_smt_possible(); > + kvm_set_vpmu_handler(kvm_passthrough_pmu_handler); Hmm, a few patches late, but the "kvm" scope is weird. This calls a core x86 function, not a KVM function. And to reduce exports and copy+paste, what about something like this? void x86_set_kvm_irq_handler(u8 vector, void (*handler)(void)) { if (!handler) handler = dummy_handler; if (vector == POSTED_INTR_WAKEUP_VECTOR) kvm_posted_intr_wakeup_handler = handler; else if (vector == KVM_GUEST_PMI_VECTOR) kvm_guest_pmi_handler = handler; else WARN_ON_ONCE(1); if (handler == dummy_handler) synchronize_rcu(); } EXPORT_SYMBOL_GPL(x86_set_kvm_irq_handler);