Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp509397rdb; Sat, 30 Sep 2023 13:41:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGBX/LTYajFtn2V+6kBqUQPuz+QLdGWKRm/fJHwqc7JC2DZSPQ5lhoJA8pD+BF07jACAaGP X-Received: by 2002:a05:6a21:33a2:b0:15d:c86d:27a6 with SMTP id yy34-20020a056a2133a200b0015dc86d27a6mr8322991pzb.55.1696106462134; Sat, 30 Sep 2023 13:41:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696106462; cv=none; d=google.com; s=arc-20160816; b=mrIRD72bejqFGYtqI3y2yDX/K+LFpmJNz0JaTO/afpjngVjZh0Ll2LxKQf820GVdQ4 Vo1+/zRbf8ZjRytOhXvsta2w+Vjj/WiJMs4s1wpEKfWKwDnNN2eTz2p63cjIdLOlGH/w U2+FVcEs5CAF6UkndKbzlmPa/YbCN/uwAASuyCXKlVrS92zjj/Sy5+ts53arM5bzf4OZ iJqrQWh5CV+0vNMFGGB/Chd4icUrt0OUOG9Wx00UtfqzXiiWkviyJkd8FOqhwcl0VMIC gKl5WWY4p8hAUu1FYD9iTUqwtu/xC0FLkIwSsdopJJVJDtk6kvFFJyIiVG7EkJ7x0n79 O7dA== 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=G8/Q+35NLYw9HySOsQs1oSfJaoZjiMzWGb8dDgdqnZo=; fh=JXgaadKFZ+I+hbRBjJa5K1mcTc9jF4rkb7zd7yv3RO8=; b=jUXpUERrZKdTLS9c+9gebfG7OFoXSlEwVh7sRVtRG1DX5DOYQGpZU8eVWFtXjpjuii vDIrbT0rWhXuZ9Cqi6jxzbqAiHM0cSx6+YnfeR0Wlx7aCpblRpudRfvfA4JI18imVIgp mccLwJcWtmdVpFk7lTDdpy20y8kFtFp+Y/0fZshUPdq/tp28MDr/rVF8IzgjoFiXFv6j A/TNj1P+2WxFXarTWeM05An7GbHi6mAQEaOImWTPxkkA/pgYBgqxxXaP2jpAFw1UyObt /qGUxAfdPZxKbfabmzbIBzPOEaAYWhVducupifFedC3ZDWo56/fq27yJ1jYcR11Qi2FF uU2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=jziUi6xB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id l10-20020a170902f68a00b001c446b59c8dsi26975467plg.271.2023.09.30.13.41.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Sep 2023 13:41:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=jziUi6xB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 82BB6809779D; Fri, 29 Sep 2023 08:47:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233548AbjI2PrC (ORCPT + 99 others); Fri, 29 Sep 2023 11:47:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233280AbjI2PrB (ORCPT ); Fri, 29 Sep 2023 11:47:01 -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 8C4B9B4 for ; Fri, 29 Sep 2023 08:46:58 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d81a47e12b5so22617772276.0 for ; Fri, 29 Sep 2023 08:46:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696002417; x=1696607217; 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=G8/Q+35NLYw9HySOsQs1oSfJaoZjiMzWGb8dDgdqnZo=; b=jziUi6xB8ypUEC0p4dqLf6jNxDlVcFw8Y3ol00ABDWcdJztVTkyBAdFpNM4XnbiGJP yKfXTA11xFEcgRiMuaD3CpugnnRw8JxVNn17kt3GCVqEQKAejJO+ZYwpdsPvGWc6dKi8 OX4/PHUjGZkt3E4xQYIv+WCPJF4nVo36z+PEpMp9cKHCyaWfhvKArU79XXw56XmOS2jU Bl/DRBrTFFKIfhOD5bc4pKUhO7mV+q58R3BH3dGdKxfwAHbAArF8fq6DXnYiB31vcK1H WWhIqvCfElWbQpZmgLhsmzqDtu2I6YwbRjoEW8Lp2APzSYA10FCSNtm8iaZCyTE8xrcE HUbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696002417; x=1696607217; 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=G8/Q+35NLYw9HySOsQs1oSfJaoZjiMzWGb8dDgdqnZo=; b=ANQlA0Lxn1EtQk51GXxsfR9EA7WWWsWptvKciS4muLUKAjzHaUeb6UQXcS9jJmI+O7 E40zoVDesqzebXTAFJNWiW3vzU891TQxM/tpW7t4MKlImSN1B7yftd5WO7Wr+2QwpcyN OcU8veZe2ZBsFxBhGWpZnbm3aQCiWvWH0dwk16hRbp5Waez/ClE8fbz4WV27HAnMbSVF ldrMHwXPHHuYjy/Kov4t8/bPpZ/Ntu+HjHER49XZ7GRO5aQk/10ZBMOGnR/1llWod7Ow W9nUSOyuKA6svPX09t1y1ZOzjGTd+ZlQ4AhETJjbISsDkO7MFM06qVppphDbvWrrtKfv iOTw== X-Gm-Message-State: AOJu0YwWPaxVnhdY7wu0We4ngs8rrtgepDB2q2GxeRysn0mfN3M9VRxJ WGjd3S3E3HS17EukaJV1Nsbx33e4iic= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:730d:0:b0:d85:ac12:aadb with SMTP id o13-20020a25730d000000b00d85ac12aadbmr71182ybc.9.1696002417694; Fri, 29 Sep 2023 08:46:57 -0700 (PDT) Date: Fri, 29 Sep 2023 15:46:55 +0000 In-Reply-To: <20230929115344.GE6282@noisy.programming.kicks-ass.net> Mime-Version: 1.0 References: <20230927033124.1226509-1-dapeng1.mi@linux.intel.com> <20230927033124.1226509-8-dapeng1.mi@linux.intel.com> <20230927113312.GD21810@noisy.programming.kicks-ass.net> <20230929115344.GE6282@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: Peter Zijlstra Cc: 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 , Mingwei Zhang , Thomas Gleixner , Ingo Molnar 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_BLOCKED,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 (howler.vger.email [0.0.0.0]); Fri, 29 Sep 2023 08:47:07 -0700 (PDT) On Fri, Sep 29, 2023, Peter Zijlstra wrote: > On Wed, Sep 27, 2023 at 10:27:07AM -0700, Sean Christopherson wrote: > > Jumping the gun a bit (we're in the *super* early stages of scraping together a > > rough PoC), but I think we should effectively put KVM's current vPMU support into > > maintenance-only mode, i.e. stop adding new features unless they are *very* simple > > to enable, and instead pursue an implementation that (a) lets userspace (and/or > > the kernel builder) completely disable host perf (or possibly just host perf usage > > of the hardware PMU) and (b) let KVM passthrough the entire hardware PMU when it > > has been turned off in the host. > > I don't think you need to go that far, host can use PMU just fine as > long as it doesn't overlap with a vCPU. Basically, if you force > perf_attr::exclude_guest on everything your vCPU can haz the full thing. Complexity aside, my understanding is that the overhead of trapping and emulating all of the guest counter and MSR accesses results in unacceptably degraded functionality for the guest. And we haven't even gotten to things like arch LBRs where context switching MSRs between the guest and host is going to be quite costly. > > Note, a similar idea was floated and rejected in the past[*], but that failed > > proposal tried to retain host perf+PMU functionality by making the behavior dynamic, > > which I agree would create an awful ABI for the host. If we make the "knob" a > > Kconfig > > Must not be Kconfig, distros would have no sane choice. Or not only a Kconfig? E.g. similar to how the kernel has CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS and nopku. > > or kernel param, i.e. require the platform owner to opt-out of using perf > > no later than at boot time, then I think we can provide a sane ABI, keep the > > implementation simple, all without breaking existing users that utilize perf in > > the host to profile guests. > > It's a shit choice to have to make. At the same time I'm not sure I have > a better proposal. > > It does mean a host cannot profile one guest and have pass-through on the > other. Eg. have a development and production guest on the same box. This > is pretty crap. > > Making it a guest-boot-option would allow that, but then the host gets > complicated again. I think I can make it trivially work for per-task > events, simply error the creation of events without exclude_guest for > affected vCPU tasks. But the CPU events are tricky. > > > I will firmly reject anything that takes the PMU away from the host > entirely through. Why? What is so wrong with supporting use cases where the platform owner *wants* to give up host PMU and NMI watchdog functionality? If disabling host PMU usage were complex, highly invasive, and/or difficult to maintain, then I can understand the pushback. But if we simply allow hiding hardware PMU support, then isn't the cost to perf just a few lines in init_hw_perf_events()? And if we put a stake in the ground and say that exposing "advanced" PMU features to KVM guests requires a passthrough PMU, i.e. the PMU to be hidden from the host, that will significantly reduce our maintenance and complexity. The kernel allows disabling almost literally every other feature that is even remotely optional, I don't understand why the hardware PMU is special.