Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp271096lqt; Thu, 18 Apr 2024 14:54:54 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX8OkNCCwZnZuntLOGqOcAdmKpo4nyDAZoyX5yYqjImTcx6jwOpPg4Gredmj3Cw2uFTU1uSHz+nevB0J5ZMcOhwGg85fgMlAiEkcHgDKA== X-Google-Smtp-Source: AGHT+IFtf+FpbCfiBkZWWf458ZRtF4629rR9G5//z7Z+5DV9wu9YuN292OtOu6VzgoYJqXLmKULw X-Received: by 2002:a25:2c5:0:b0:dcb:fb49:cb96 with SMTP id 188-20020a2502c5000000b00dcbfb49cb96mr147210ybc.31.1713477293915; Thu, 18 Apr 2024 14:54:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713477293; cv=pass; d=google.com; s=arc-20160816; b=fZjaAhvG9d8+H7Qvx+9TZcprrXvcsGhiS/0B2i3CTdEswCbHpTYtrLYcNk0ISFnFUY EIvfJNyDRBORbwjZ+LlrVLqf2MNozlJzRO17RLeD/YTMi4fMsv+x84Qw5GB40JZSmGcH YJ1YEWureKkquDb12tVj4wRsxOnOb06z8de/TsZgFbtIIxI26yVYk3YO1Nmz3kts9qZK tkerYkb3/UqZE2rjjDlZayYQjqvXw5lqBk1y0W2gkPndWuIMxKxZp2ZHHb1rBRvt6awM XCbQatNdVD9hjDDlCXVcWd5zWtpfvp/s7OfY4/Xk6IJweB5g2x6xQZQZxYsEVjfq9FFm TteQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=UzoUB/DlZEEpnQQocpp8LNj0cC4Hbh3hYFeNjb1gymQ=; fh=vLb0Evupu0xvmwbsstuUg4IsffvmOPS1KHAzBjA8QGc=; b=v/0p2yK6j61PGQjBPVMm9AarbLIpnGgVp3wTuGtfHLrVY0IBVQT2vUwyMWNpzKPUvB ftqJvA93TBFgpTDCqtXcd54cIqJjTuVQLx9nEFQRItbpRL25Vru+ZHQvsBmjXZOW0VH/ Xy4+NbbtROx9rNfFY/0ZMmHF6H9yvauLh+Li+zQXuFRhWs4zRhQRlciEf+LeLK04yzYY XhtpuJWi2TjHoHbRKs6H7iDj8Ih0CsFZN7X8zvNhGy6iTft9npI5Z6uhZOzJdJqXJHk4 QLDzUAWYnPZryPoPA9PQ0m8DvUvYgjWw8YEijdJDWVLwicMnK5BJbsa0Z9cX2fa+5p9J J6Vw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=X9CCQAGP; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-150817-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150817-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id c2-20020ad45ae2000000b0069b6b410474si2431772qvh.126.2024.04.18.14.54.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 14:54:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-150817-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=X9CCQAGP; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-150817-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150817-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 8F7401C20F98 for ; Thu, 18 Apr 2024 21:54:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5CB14199EA8; Thu, 18 Apr 2024 21:54:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="X9CCQAGP" Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (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 AF199199E82 for ; Thu, 18 Apr 2024 21:54:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713477279; cv=none; b=S6GQ5MBFTK0QNVUlbjTl/pW8V9OkjByOrQS0TNRn127t262spuRa0Dwqbc8W8ypwtGDvK7TDyhrDqjCCElWtK8BO8yI8fEP+64tRGmpKal3YZYGtpdS1GiGSEcP5PXvT8CJwm98G3qY9yoxlPnVYPLIgWMQADn0XY3j9Q3HzfWE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713477279; c=relaxed/simple; bh=/fIZnrTgxkprElJlF6zWXgMXsg0CVEGbxuta0DCFlM4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=KIBVZJWcDlfqXfRpLC9VY0/EsKcHOoY5rDrDus2Z3JwrVoaaFfMIYQeXkmn4zU+KBQklPtv+rjWdojhQEL4qseJx3cVuNAuZFMtPGk28Z1myiIaY0m2ELuq7WezIJ/g9msLeUu98QsQEapdW+EIztozEdKrmrlNKN06w60/oSfk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=X9CCQAGP; arc=none smtp.client-ip=209.85.210.178 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=google.com Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-6edc61d0ff6so1397610b3a.2 for ; Thu, 18 Apr 2024 14:54:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713477277; x=1714082077; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=UzoUB/DlZEEpnQQocpp8LNj0cC4Hbh3hYFeNjb1gymQ=; b=X9CCQAGPZ99SN2MkP9S6gDKVi6ocby6DNLHtZcj6MwvEp1nmeacQZb++EMmDCHE9+W aOvPUB4UsnBY0lgm7Zr7IlzW1DKehF5DXMEEMvXGFzYiquQWqHxaQen37pQB8PqD4T7N 7PaE8vS0VkI31dEtGCbF3lUZeUvQ8kQ2r3ZOmmYyuEJXqI+04C5SRJiVk8fF+HTyFeDm h/kK/06ygZ+cPhZm5RBpMPsMZWf50zSVeEVOv9qlX7rD3Pj/gIyAGjjNDHxyQ8mNy+qV KAHXfbwEsbEBJJI8GKuoDyNPL2wJmeePkJKyP5NELwmOIWWbtjKgynB8UyjEgHdSuJqN /xNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713477277; x=1714082077; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=UzoUB/DlZEEpnQQocpp8LNj0cC4Hbh3hYFeNjb1gymQ=; b=mtM8op+BPwRckXzmUPcMSy0L3RziUU/9A+2D8CcjlH8hmRJ1SLZeL101QtGSPvAxCb iB3KY1d77SCb/toEw16MuGyIUd9oQsb9pgeuNASK91JCudMN3uHBodRfzqqA0ST+I02A fomZo9p/u4uVlSzcTi06aSOIx3wdrQo0rLyqDqv/J4dpzQU81f/9C/efQJ2Kr3ufDWAt KQ2Ww2DA7SYXWC05TCstkexOVjJutvSUHNfWbKQ+4CH9ntBmxR203EsZ6Jgax1JBcZ88 P+lj2T72nDKt3tVKjvD/xi4Dh7WXH3+9wTKw1pI4t02SKcw0BXPjlvPjRvG96C47b1Pk wimQ== X-Forwarded-Encrypted: i=1; AJvYcCXy/SxhmzZtbG3n0deEEx4cYurUDXNMPIzhyKPbWslsFtj/VhttgQlE5lvRj/+cGU/vznnxdxGE7PJCiR1MELKmmm49q7Cc8YKmGRND X-Gm-Message-State: AOJu0Yyv9ouXvv90OKMGW33ZI/QT9sDLkd2I9GVXvscgHCelCkUpx3M5 2IOGYA91xjxau3eZIamo8obQrxkBXnJdTZPVQ1gdL3DXjysOiXGAh3bnHOH2iQ== X-Received: by 2002:a05:6a00:2e8f:b0:6ea:86f2:24fb with SMTP id fd15-20020a056a002e8f00b006ea86f224fbmr541761pfb.25.1713477276564; Thu, 18 Apr 2024 14:54:36 -0700 (PDT) Received: from google.com (176.13.105.34.bc.googleusercontent.com. [34.105.13.176]) by smtp.gmail.com with ESMTPSA id z8-20020a056a00240800b006ecf6417a9bsm1970815pfh.29.2024.04.18.14.54.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 14:54:35 -0700 (PDT) Date: Thu, 18 Apr 2024 21:54:32 +0000 From: Mingwei Zhang To: Sean Christopherson Cc: Xiong Zhang , pbonzini@redhat.com, peterz@infradead.org, 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 Subject: Re: [RFC PATCH 40/41] KVM: x86/pmu: Separate passthrough PMU logic in set/get_msr() from non-passthrough vPMU Message-ID: References: <20240126085444.324918-1-xiong.y.zhang@linux.intel.com> <20240126085444.324918-41-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 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Thu, Apr 11, 2024, Sean Christopherson wrote: > On Fri, Jan 26, 2024, Xiong Zhang wrote: > > From: Mingwei Zhang > > > > Separate passthrough PMU logic from non-passthrough vPMU code. There are > > two places in passthrough vPMU when set/get_msr() may call into the > > existing non-passthrough vPMU code: 1) set/get counters; 2) set global_ctrl > > MSR. > > > > In the former case, non-passthrough vPMU will call into > > pmc_{read,write}_counter() which wires to the perf API. Update these > > functions to avoid the perf API invocation. > > > > The 2nd case is where global_ctrl MSR writes invokes reprogram_counters() > > which will invokes the non-passthrough PMU logic. So use pmu->passthrough > > flag to wrap out the call. > > > > Signed-off-by: Mingwei Zhang > > --- > > arch/x86/kvm/pmu.c | 4 +++- > > arch/x86/kvm/pmu.h | 10 +++++++++- > > 2 files changed, 12 insertions(+), 2 deletions(-) > > > > diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c > > index 9e62e96fe48a..de653a67ba93 100644 > > --- a/arch/x86/kvm/pmu.c > > +++ b/arch/x86/kvm/pmu.c > > @@ -652,7 +652,9 @@ int kvm_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) > > if (pmu->global_ctrl != data) { > > diff = pmu->global_ctrl ^ data; > > pmu->global_ctrl = data; > > - reprogram_counters(pmu, diff); > > + /* Passthrough vPMU never reprogram counters. */ > > + if (!pmu->passthrough) > > This should probably be handled in reprogram_counters(), otherwise we'll be > playing whack-a-mole, e.g. this misses MSR_IA32_PEBS_ENABLE, which benign, but > only because PEBS isn't yet supported. > > > + reprogram_counters(pmu, diff); > > } > > break; > > case MSR_CORE_PERF_GLOBAL_OVF_CTRL: > > diff --git a/arch/x86/kvm/pmu.h b/arch/x86/kvm/pmu.h > > index 0fc37a06fe48..ab8d4a8e58a8 100644 > > --- a/arch/x86/kvm/pmu.h > > +++ b/arch/x86/kvm/pmu.h > > @@ -70,6 +70,9 @@ static inline u64 pmc_read_counter(struct kvm_pmc *pmc) > > u64 counter, enabled, running; > > > > counter = pmc->counter; > > + if (pmc_to_pmu(pmc)->passthrough) > > + return counter & pmc_bitmask(pmc); > > Won't perf_event always be NULL for mediated counters? I.e. this can be dropped, > I think. yeah. I double checked and seems when perf_event == NULL, the logic is correct. If so, we can drop that. Thanks. -Mingwei