Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2890613rdb; Wed, 4 Oct 2023 15:06:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF2CXcrEmPjixIIPYuf4Mcw6eVlGJ9B/i+jH8VIXwe9LQVohbePMe3SWx8Ukh1kpItmXBO7 X-Received: by 2002:a05:6a20:a11f:b0:15d:d250:d240 with SMTP id q31-20020a056a20a11f00b0015dd250d240mr3942865pzk.50.1696457172961; Wed, 04 Oct 2023 15:06:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696457172; cv=none; d=google.com; s=arc-20160816; b=OjPZ5pIahxYL20ONrp3MAtx+e3gaF/i8r8+ok2VA8ugSSyIdXonlcrRDpzA3DHNbRt v/lB3SMc88jcqC7U0qQMRvHJ7KnCeUxRk2s1e5WTPjCp7UQL7sSla/dq75sha4aNpZLy cXa+zVGfs6ToViDw2IWVXEPkcGfZtiNhjw3GtVB3YeyPYmbmgJ5azB7OfQXH4jrk+prw kcegt6PKnwW6GPjtWTMPOdCVFBTjmGxGpw6WlDM5C6GtqKGAx/0YItnUaNtfGAV0TqhV BH1OrNi3NM/qgKSVjCYjfOlftMKwcmufcXsNNR2pTzDTWQAT4qbs1XUjIUJp0XpcJSqV z/Og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=JQhr64Gt8dKyHZjOzMcheFeKf4AHIRHG09SiFUQfy3g=; fh=z73Nw6ZnROKujOlha8ONdOw7siSFOjDnwUvdk4jMB50=; b=QEhiq8X7jr4byKueWAuXWYc607JZlQiaIixU2X3LMnGYy8ftqUWCahVNSPzAVhnkfI /t78j/F0VxBydShHdrP39KxAOo5ZrcPSenyI8rGDJNILeh4KpMGNEfQ2WhtqO1w2nAwS Qn/tCe0xpx15e3vjUSi/NTtEeQpH/78H8DI8hQOQ8nW/F4v1SuT6zNDFsopF5AW83qIt eWUQSsqYNqdYvO8Nw1hJhh0o0IwWSbQMvB427eoeXz1FHd67HDJ35zrHTSyWnJxu1zac gApS1YrkUA/PwWxUQndkDMWABoyukRbiVqwibm2uJ329GbP25v0SMB3HqmrYOfVp9Ftz Ozng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=fzdBXODe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id cv13-20020a056a0044cd00b0068e41f07f33si33634pfb.94.2023.10.04.15.06.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 15:06:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=fzdBXODe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id DB1C6801B49E; Wed, 4 Oct 2023 15:06:11 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231513AbjJDWGJ (ORCPT + 99 others); Wed, 4 Oct 2023 18:06:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229973AbjJDWGH (ORCPT ); Wed, 4 Oct 2023 18:06:07 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7286BD8 for ; Wed, 4 Oct 2023 15:06:01 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d816fa2404aso460838276.0 for ; Wed, 04 Oct 2023 15:06:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696457160; x=1697061960; 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=JQhr64Gt8dKyHZjOzMcheFeKf4AHIRHG09SiFUQfy3g=; b=fzdBXODevY/Q3gIWKFCdoVcO9SGfxtkiGP37f+mR5qKBcufPII7Y9XDYfwsHPuAemX eqPiNW9os3uQ4MDVaL04sMwGlhzeOS8WbL6z2RmTdiuAqkMeXyAKZh7HjWBcfazWzDbM iohmEcSKia7Wh7NeYWXImcjh0ripNjWgO4Z47KV5yNUPWvc1awLFXQ52LPps81S4eHh5 bGWf0Ug0Woc9q5f3QA1jpbGknb1hK+HRgyWNAxLl4mGWUwo5wVnIUloCMVVQTE8zKKc5 JdYTYPW93EuI+xGT9KuBgaGCFl/tN2LuJ8bqS6H+5Jq+Oj7qJxP/MpjSon1oUgBa/9/S ik+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696457160; x=1697061960; 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=JQhr64Gt8dKyHZjOzMcheFeKf4AHIRHG09SiFUQfy3g=; b=aB2ruQ3e7dwNB0fY0uStNPNjhTbnj1rWAGUV3Z4V8HWRLLtIK5DsoDviK1ZsDe6NMW y1pGt0ppvmmQjPvmN4nl7xjexAiYyjQQ6shJ+8Gu3j6xsQlxH5gDMFl53yybJ5T7Jjmc C4UneQn5N/vyVS3xXgJ4QzNWUHl9UYTnPl/E2/DX0h72sNWBYX0he9Kv6SoSzl9o17Qs QD4l81iyZfdYTCoH53dcm/Ua4iDDT3xgYseBE7XOUon8z7is0KbV185JhO0Ft0vkah8M Tb3as/n766sJvQXkiKkjEXper7tgpIaZVAdLPGa4S/yWX4ZJt3peCJWJmZInoOoh92UT 7cQg== X-Gm-Message-State: AOJu0YwpYfuSuMma/nvS2OdQt8zbcDWAsgdjBwOKHr7Ujfr18L9BpeWT jomUN+Pn2dlmPufysgYkqMYXnY2NIdU= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:5f01:0:b0:d77:f7c3:37db with SMTP id t1-20020a255f01000000b00d77f7c337dbmr62293ybb.8.1696457160665; Wed, 04 Oct 2023 15:06:00 -0700 (PDT) Date: Wed, 4 Oct 2023 15:05:59 -0700 In-Reply-To: Mime-Version: 1.0 References: <20231002115718.GB13957@noisy.programming.kicks-ass.net> <20231002204017.GB27267@noisy.programming.kicks-ass.net> <20231003081616.GE27267@noisy.programming.kicks-ass.net> <20231004112152.GA5947@noisy.programming.kicks-ass.net> Message-ID: Subject: Re: [Patch v4 07/13] perf/x86: Add constraint for guest perf metrics event From: Sean Christopherson To: Mingwei Zhang Cc: Peter Zijlstra , Ingo Molnar , Dapeng Mi , Paolo Bonzini , Arnaldo Carvalho de Melo , Kan Liang , Like Xu , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , kvm@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Zhenyu Wang , Zhang Xiong , Lv Zhiyuan , Yang Weijiang , Dapeng Mi , Jim Mattson , David Dunn , Thomas Gleixner Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 04 Oct 2023 15:06:12 -0700 (PDT) On Wed, Oct 04, 2023, Sean Christopherson wrote: > Thinking about this more, what if we do a blend of KVM's FPU swapping and debug > register swapping? > > A. Load guest PMU state in vcpu_enter_guest() after IRQs are disabled > B. Put guest PMU state (and load host state) in vcpu_enter_guest() before IRQs > are enabled, *if and only if* the current CPU has one or perf events that > wants to use the hardware PMU > C. Put guest PMU state at vcpu_put() > D. Add a perf callback that is invoked from IRQ context when perf wants to > configure a new PMU-based events, *before* actually programming the MSRs, > and have KVM's callback put the guest PMU state > > If there are host perf events that want to use the PMU, then KVM will swap fairly > aggressively and the "downtime" of the host perf events will be limited to the > small window around VM-Enter/VM-Exit. > > If there are no such host events, KVM will swap on the first entry to the guest, > and keep the guest PMU loaded until the vCPU is put. > > The perf callback in (D) would allow perf to program system-wide events on all > CPUs without clobbering guest PMU state. > > I think that would make everyone happy. As long as our hosts don't create perf > events, then we get the "swap as little as possible" behavior without significantly > impacting the host's ability to utilize perf. If our host screws up and creates > perf events on CPUs that are running vCPUs, then the degraded vCPU performance is > on us. > > Rough sketch below, minus the perf callback or any of actual swapping logic. Another reason to go for an approach that doesn't completely kill off host PMU usage: just because we don't plan on enable perf events in *production*, there will undoubtedly be times where we want to enable perf events to debug issues (outside of prod) in the host kernel/KVM that affect VMs with a passthrough PMU. So I'll add a self-NAK to the idea of completely disabling the host PMU, I think that would burn us quite badly at some point.