From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 50DEACD5BA6 for ; Thu, 5 Sep 2024 11:02:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=0I+vYz8UkJxcnFtcjyD4u+rUxXugQFGuDfHrR5zjsYs=; b=jZeZO/F9ctrS14fyK6TBVJ13ud nmdc4Uru4jMUs0qpQ+BnzESBYsTHpv1/GW/53kcA8Lbu15GAgyv9xsEgJyXxxb/umIJlqnLs2ORLq Bxa3nQccEJ5mURy4WgXVzxCkSawJQrwvaBfrI9HmmTqCjyeCYH+GFEol/Q4PfOsVsf115G/pdncvx WQkAwD7Z61iItUScSAvh8nFZ0rKdcRZFoFyyxNBFIs0OdAcbPtPISSNet2/iB64B21JKb3n2nhLLI HmyRqxMT6sPmJeQ+owM2HH/E5wZpCp0gNr6gOqhNcJcPs039o46Xxps4fKJo3p/dKj+q9Vkul/srA lHOqffog==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1smAFZ-000000083o0-0gLx; Thu, 05 Sep 2024 11:02:05 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1smA92-000000082Ja-2QSE for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 10:55:24 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 53A49FEC; Thu, 5 Sep 2024 03:55:46 -0700 (PDT) Received: from J2N7QTR9R3 (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0C85F3F66E; Thu, 5 Sep 2024 03:55:14 -0700 (PDT) Date: Thu, 5 Sep 2024 11:55:12 +0100 From: Mark Rutland To: Colton Lewis Cc: kvm@vger.kernel.org, Oliver Upton , Sean Christopherson , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Will Deacon , Russell King , Catalin Marinas , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Thomas Gleixner , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org Subject: Re: [PATCH 5/5] perf: Correct perf sampling with guest VMs Message-ID: References: <20240904204133.1442132-1-coltonlewis@google.com> <20240904204133.1442132-6-coltonlewis@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240904204133.1442132-6-coltonlewis@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240905_035520_689682_FA5FFE21 X-CRM114-Status: GOOD ( 16.84 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Sep 04, 2024 at 08:41:33PM +0000, Colton Lewis wrote: > Previously any PMU overflow interrupt that fired while a VCPU was > loaded was recorded as a guest event whether it truly was or not. This > resulted in nonsense perf recordings that did not honor > perf_event_attr.exclude_guest and recorded guest IPs where it should > have recorded host IPs. > > Reorganize that plumbing to record perf events correctly even when > VCPUs are loaded. It'd be good if we could make that last bit a little more explicit, e.g. Rework the sampling logic to only record guest samples for events with exclude_guest clear. This way any host-only events with exclude_guest set will never see unexpected guest samples. The behaviour of events with exclude_guest clear is unchanged. [...] > diff --git a/kernel/events/core.c b/kernel/events/core.c > index 4384f6c49930..e1a66c9c3773 100644 > --- a/kernel/events/core.c > +++ b/kernel/events/core.c > @@ -6915,13 +6915,26 @@ void perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *cbs) > EXPORT_SYMBOL_GPL(perf_unregister_guest_info_callbacks); > #endif > > -unsigned long perf_misc_flags(unsigned long pt_regs *regs) > +static bool is_guest_event(struct perf_event *event) > { > + return !event->attr.exclude_guest && perf_guest_state(); > +} Could we name this something like "should_sample_guest()"? Calling this "is_guest_event()" makes it should like it's checking a static property of the event (and not other conditions like perf_guest_state()). Otherwise this all looks reasonable to me, modulo Ingo's comments. I'll happily test a v2 once those have been addressed. Mark.