From nobody Sat Nov 30 03:39:47 2024 Received: from mail-io1-f74.google.com (mail-io1-f74.google.com [209.85.166.74]) (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 289051C0DEB for ; Thu, 12 Sep 2024 20:51:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726174299; cv=none; b=NnPtXR756KnkLWLSid7bBsUANYo9XpAGKrZPlqe488iU31VF1GopvWmZMnO8trli3RgSH7FpHyukS7k3TScwt0SFQJZB4sApypq+hwAR+u16xLBANjQVVtJNFHo+zGJWgEXS3+T5e7JpFTAEkxIRcWuyHMJ0ViD3nCB/F3I+01U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726174299; c=relaxed/simple; bh=kaODB7epwl9nHxQDNWBzHwOw47KDaa/Ux/Yg5uk1CV4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=iF1fBtGdG1rtaDRBJQPi2ijE1CFMk9J76PMD/DnXJXXqTxexih+6V80fu98XAlRDy3Y/r2wrHJRUmSLMbWa1v9ryoD4gK/PGYEV4GTr1sJZjX6gB6C8GrQukKNH/gWOaVG81mZv/JlIokpk7fNxQVjqHOGUVw9iFZjHNHsZ/ZxU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--coltonlewis.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=1G8kQddr; arc=none smtp.client-ip=209.85.166.74 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--coltonlewis.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="1G8kQddr" Received: by mail-io1-f74.google.com with SMTP id ca18e2360f4ac-82cda24c462so32657839f.0 for ; Thu, 12 Sep 2024 13:51:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726174297; x=1726779097; 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=qgNa1Xt6FnUSigDEF0LKTlfU3qkapsIsHTMTckjKajA=; b=1G8kQddr7iVoMgnXxRXB0y0npd2iM02NnCPHPKVnsljahSGSc2cO+aJIUmruvtO44X T17qacGJkebdvfKCqyDy4kTsslh4k1YFejivboBEL3v0oiYZ6qqcaJoO9IobQhjsByTz eDmYWEJfJ0GTv7QTVmUofNgSiTdjnutz+25vrF8ux3V4qvysOurnvyqdPdgTvC03G+gb hQxDVTFzV/V6SFe3eHzfUC43MwGGL4DJKdQLQ3ajPSWr66ERaylD9Wl+82T0Kfpt0VAM 4pagemF7Ls5FhF6CxV+Spjoun9bAWPRXIg3V0hUBSTXy2VW6ofQ/lgFUNf5G/9QS4KiD vrxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726174297; x=1726779097; 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=qgNa1Xt6FnUSigDEF0LKTlfU3qkapsIsHTMTckjKajA=; b=UebBuKC/YH9iyyBo2IMITAA9nUAgyv7WwDzeQDnpYR10Y1k6KvzGrrmqOQiNeRAAP0 JPlSflx7mfrTk8fpWw0gY4jlrGeFmCF5p7Cq//tHSf7WV1RDglIW/vNARr7w3xbaGgQC PqolkxHItNpWziziIG6K0ASRBqcX/ivorOCBnY3ZacbYjpmuFGMI8yo9KsM/HgULYQYa 8mS1RT6Fpu7Le013zscZE3p8JHWR2lSxQ67C8qaaO5n063ps159tbWwf7IcmTLed2Wot 4ZS4IkOZ+YFb2PjVtrPYozVXWWYSdfitahOFFkn6eJxRyTE9hdQ2DEd+B3lvD0y/OzMf 1TuQ== X-Forwarded-Encrypted: i=1; AJvYcCX6xASmHk/8Bwcse6/xyPMrxbqXrglaEW5BSXXA1hqo6DmLTbowjVJ12jjUqkC8eQKMoE+BBoNwdIMNtpM=@vger.kernel.org X-Gm-Message-State: AOJu0YwpcoXdlaMrClscMpa1NWkgR2sneSxCA1TuCYvgmpzKoDhj1UGv 3EyqzD6cfJEpkIzeJ0j5XqGWlX4jtjarzxUNrT775NDl6SDkwbFi4J4Trrpnl3zsQF1arf9xK2v 5t/Ox+NZLGemsj+sfXeHPDQ== X-Google-Smtp-Source: AGHT+IHFcuQ/5a/hhlw1GFJJYrc3if7U/QuDvmMiMeVXDMjRO3Gjmvd8L1tjO+zUGwBFmEAgEN40MjfIHW+YAT2pgQ== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a05:6638:860c:b0:4d2:27c:18f8 with SMTP id 8926c6da1cb9f-4d36e33a768mr13751173.1.1726174297086; Thu, 12 Sep 2024 13:51:37 -0700 (PDT) Date: Thu, 12 Sep 2024 20:51:29 +0000 In-Reply-To: <20240912205133.4171576-1-coltonlewis@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240912205133.4171576-1-coltonlewis@google.com> X-Mailer: git-send-email 2.46.0.662.g92d0881bb0-goog Message-ID: <20240912205133.4171576-2-coltonlewis@google.com> Subject: [PATCH v3 1/5] arm: perf: Drop unused functions From: Colton Lewis To: kvm@vger.kernel.org Cc: Oliver Upton , Sean Christopherson , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , 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, Colton Lewis Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For arm's implementation, perf_instruction_pointer() and perf_misc_flags() are equivalent to the generic versions in include/linux/perf_event.h so arch/arm doesn't need to provide its own versions. Drop them here. Signed-off-by: Colton Lewis Reviewed-by: Oliver Upton --- arch/arm/include/asm/perf_event.h | 7 ------- arch/arm/kernel/perf_callchain.c | 17 ----------------- 2 files changed, 24 deletions(-) diff --git a/arch/arm/include/asm/perf_event.h b/arch/arm/include/asm/perf_= event.h index bdbc1e590891..c08f16f2e243 100644 --- a/arch/arm/include/asm/perf_event.h +++ b/arch/arm/include/asm/perf_event.h @@ -8,13 +8,6 @@ #ifndef __ARM_PERF_EVENT_H__ #define __ARM_PERF_EVENT_H__ -#ifdef CONFIG_PERF_EVENTS -struct pt_regs; -extern unsigned long perf_instruction_pointer(struct pt_regs *regs); -extern unsigned long perf_misc_flags(struct pt_regs *regs); -#define perf_misc_flags(regs) perf_misc_flags(regs) -#endif - #define perf_arch_fetch_caller_regs(regs, __ip) { \ (regs)->ARM_pc =3D (__ip); \ frame_pointer((regs)) =3D (unsigned long) __builtin_frame_address(0); \ diff --git a/arch/arm/kernel/perf_callchain.c b/arch/arm/kernel/perf_callch= ain.c index 1d230ac9d0eb..a2601b1ef318 100644 --- a/arch/arm/kernel/perf_callchain.c +++ b/arch/arm/kernel/perf_callchain.c @@ -96,20 +96,3 @@ perf_callchain_kernel(struct perf_callchain_entry_ctx *e= ntry, struct pt_regs *re arm_get_current_stackframe(regs, &fr); walk_stackframe(&fr, callchain_trace, entry); } - -unsigned long perf_instruction_pointer(struct pt_regs *regs) -{ - return instruction_pointer(regs); -} - -unsigned long perf_misc_flags(struct pt_regs *regs) -{ - int misc =3D 0; - - if (user_mode(regs)) - misc |=3D PERF_RECORD_MISC_USER; - else - misc |=3D PERF_RECORD_MISC_KERNEL; - - return misc; -} -- 2.46.0.662.g92d0881bb0-goog From nobody Sat Nov 30 03:39:47 2024 Received: from mail-io1-f74.google.com (mail-io1-f74.google.com [209.85.166.74]) (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 D8A4613CFB7 for ; Thu, 12 Sep 2024 20:51:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726174300; cv=none; b=rgVCO50UgUHeijkH/+j8bmo01DzbO4W9d19bMlgncoWiQvD9AY0ugkm7F09fgRnqiudORH7ssvmlnkV3J2PncND2wIj8ruuCuk+gL4MJxm3FkA5lU08sMQwCwEKP+LrP04qxojp45An+eU6OhrEdf1CXSUh6Zs9Tw7V1VzvNoaM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726174300; c=relaxed/simple; bh=JATInXK4+393CVhAVmz8NOucOf+k5AS+0xX7YEVtGkE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=kIRJIkoNeDx+mm7dKI2GeTaLsWgua95b0hQiq/2q52NZKstXV90YuB6QKVXi0kKIMVul3rcUCSNR22MrFWClTesIxYQJJCqq020OZxU+JuEpWHbKfNBZBgg4WnEZfx6gG3ZPfRTFTiv3/fXeFK9ZZlA9ZP4si1IuSUs6asvYxW8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--coltonlewis.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Dxey1vKT; arc=none smtp.client-ip=209.85.166.74 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--coltonlewis.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Dxey1vKT" Received: by mail-io1-f74.google.com with SMTP id ca18e2360f4ac-82cf28c74efso217351139f.1 for ; Thu, 12 Sep 2024 13:51:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726174298; x=1726779098; 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=bBuBduG209Jab8XMLtuQHzsmOY9s44tUcmK5TPfdVN4=; b=Dxey1vKTcbiSv+QIuOXMc+uLkxLz9MQ6VhLO4Ru90gKZmRfUVnVGpGe+300Q7mu0lt aa73Oup9Wr3SVOCTeLc3jGXEoRu2q7RSQ4trjQb2mhZndaDTe2Byu2Gaz6L+VbGpB39h DUBXXJ7s8Mn5kAmanI09ehnEXKyd8zkPKPlIlfBYHK6j8rN2bSpkjBgBj3fM7UWe4Alq arvl8uGsq+pPY5W+TZSbjiFdBb6sdQdIdrEPZs2v5wJ/GljDnHj7y/yN8ObtfdquFNN2 jJmzw+TdDUdzMgfIHrcHhJyrCVXpqgObxrDcM6JXXq9LHjW3h0mztLD8cl1JoBGWRxy8 60Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726174298; x=1726779098; 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=bBuBduG209Jab8XMLtuQHzsmOY9s44tUcmK5TPfdVN4=; b=nCmDqqV2vjanAmGZEWkF7iIoFc5bbEoc4pAOOG5KUsLFhv2+OdHH1bHKWvE8u8kHvM B+F8x7YUC6YNT3vTmxvCKbuDujOZvyJMzPMTjeM4rLqH64oy+/ThAPv/+ah2BqAIPkBr xt5cHyULIkyK55BLvkKOaqZ5cc/K08CF0hZ7O2SlXedBbN1dFN2C2Oe72/6TcUYlgvO8 8uYrDZmyXDlfjaNZtU9yBpPuYKfPLnIvTfnwKJxNaRzfAHlwfyft6nb/kVVSl2K9caVj AEZv51qKS827atouaxlOKot9/AzNL+sTmKqrXYsxW5SNSFfTQ9Y4iUlGdah5D91P+ZO9 RDvA== X-Forwarded-Encrypted: i=1; AJvYcCW5+0EAhmyCrD2sH1zPbps1EIJRIeQbRZBLkyWBsUMFIYHzqAj34Y4PGlp7bBq+/fXUMidu+5eF9MEWqhY=@vger.kernel.org X-Gm-Message-State: AOJu0YzVX0Wc4bY04HL6Wk6LndjEEIT7n0fTnqqv9oqLSZNjF8E9ovVO VjGP+di31XcptMCoSkc17c0+a0m0yHleNhMXrr/00N1OTOVsDeS4oMZpqE/DZkbxiaGCswOpo+J s/kI4Z0LZASeFV5CaZ+cw2w== X-Google-Smtp-Source: AGHT+IHuyxoF1O+4DvTuzFh/ZZP8349qH8nbD/zqC3/tkxgPNCvBr0r1+e3VqEUG1lpnklg0vGHAk+SStZ+us7ma2A== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a05:6602:60c8:b0:82d:581:8867 with SMTP id ca18e2360f4ac-82d1f980157mr5857639f.3.1726174298132; Thu, 12 Sep 2024 13:51:38 -0700 (PDT) Date: Thu, 12 Sep 2024 20:51:30 +0000 In-Reply-To: <20240912205133.4171576-1-coltonlewis@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240912205133.4171576-1-coltonlewis@google.com> X-Mailer: git-send-email 2.46.0.662.g92d0881bb0-goog Message-ID: <20240912205133.4171576-3-coltonlewis@google.com> Subject: [PATCH v3 2/5] perf: Hoist perf_instruction_pointer() and perf_misc_flags() From: Colton Lewis To: kvm@vger.kernel.org Cc: Oliver Upton , Sean Christopherson , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , 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, Colton Lewis Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For clarity, rename the arch-specific definitions of these functions to perf_arch_* to denote they are arch-specifc. Define the generic-named functions in one place where they can call the arch-specific ones as needed. Signed-off-by: Colton Lewis Reviewed-by: Oliver Upton --- arch/arm64/include/asm/perf_event.h | 6 +++--- arch/arm64/kernel/perf_callchain.c | 4 ++-- arch/powerpc/include/asm/perf_event_server.h | 6 +++--- arch/powerpc/perf/core-book3s.c | 4 ++-- arch/s390/include/asm/perf_event.h | 6 +++--- arch/s390/kernel/perf_event.c | 4 ++-- arch/x86/events/core.c | 4 ++-- arch/x86/include/asm/perf_event.h | 10 +++++----- include/linux/perf_event.h | 9 ++++++--- kernel/events/core.c | 10 ++++++++++ 10 files changed, 38 insertions(+), 25 deletions(-) diff --git a/arch/arm64/include/asm/perf_event.h b/arch/arm64/include/asm/p= erf_event.h index eb7071c9eb34..31a5584ed423 100644 --- a/arch/arm64/include/asm/perf_event.h +++ b/arch/arm64/include/asm/perf_event.h @@ -11,9 +11,9 @@ =20 #ifdef CONFIG_PERF_EVENTS struct pt_regs; -extern unsigned long perf_instruction_pointer(struct pt_regs *regs); -extern unsigned long perf_misc_flags(struct pt_regs *regs); -#define perf_misc_flags(regs) perf_misc_flags(regs) +extern unsigned long perf_arch_instruction_pointer(struct pt_regs *regs); +extern unsigned long perf_arch_misc_flags(struct pt_regs *regs); +#define perf_arch_misc_flags(regs) perf_misc_flags(regs) #define perf_arch_bpf_user_pt_regs(regs) ®s->user_regs #endif =20 diff --git a/arch/arm64/kernel/perf_callchain.c b/arch/arm64/kernel/perf_ca= llchain.c index e8ed5673f481..01a9d08fc009 100644 --- a/arch/arm64/kernel/perf_callchain.c +++ b/arch/arm64/kernel/perf_callchain.c @@ -39,7 +39,7 @@ void perf_callchain_kernel(struct perf_callchain_entry_ct= x *entry, arch_stack_walk(callchain_trace, entry, current, regs); } =20 -unsigned long perf_instruction_pointer(struct pt_regs *regs) +unsigned long perf_arch_instruction_pointer(struct pt_regs *regs) { if (perf_guest_state()) return perf_guest_get_ip(); @@ -47,7 +47,7 @@ unsigned long perf_instruction_pointer(struct pt_regs *re= gs) return instruction_pointer(regs); } =20 -unsigned long perf_misc_flags(struct pt_regs *regs) +unsigned long perf_arch_misc_flags(struct pt_regs *regs) { unsigned int guest_state =3D perf_guest_state(); int misc =3D 0; diff --git a/arch/powerpc/include/asm/perf_event_server.h b/arch/powerpc/in= clude/asm/perf_event_server.h index 5995614e9062..41587d3f8446 100644 --- a/arch/powerpc/include/asm/perf_event_server.h +++ b/arch/powerpc/include/asm/perf_event_server.h @@ -102,8 +102,8 @@ struct power_pmu { int __init register_power_pmu(struct power_pmu *pmu); =20 struct pt_regs; -extern unsigned long perf_misc_flags(struct pt_regs *regs); -extern unsigned long perf_instruction_pointer(struct pt_regs *regs); +extern unsigned long perf_arch_misc_flags(struct pt_regs *regs); +extern unsigned long perf_arch_instruction_pointer(struct pt_regs *regs); extern unsigned long int read_bhrb(int n); =20 /* @@ -111,7 +111,7 @@ extern unsigned long int read_bhrb(int n); * if we have hardware PMU support. */ #ifdef CONFIG_PPC_PERF_CTRS -#define perf_misc_flags(regs) perf_misc_flags(regs) +#define perf_arch_misc_flags(regs) perf_misc_flags(regs) #endif =20 /* diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3= s.c index 42867469752d..dc01aa604cc1 100644 --- a/arch/powerpc/perf/core-book3s.c +++ b/arch/powerpc/perf/core-book3s.c @@ -2332,7 +2332,7 @@ static void record_and_restart(struct perf_event *eve= nt, unsigned long val, * Called from generic code to get the misc flags (i.e. processor mode) * for an event_id. */ -unsigned long perf_misc_flags(struct pt_regs *regs) +unsigned long perf_arch_misc_flags(struct pt_regs *regs) { u32 flags =3D perf_get_misc_flags(regs); =20 @@ -2346,7 +2346,7 @@ unsigned long perf_misc_flags(struct pt_regs *regs) * Called from generic code to get the instruction pointer * for an event_id. */ -unsigned long perf_instruction_pointer(struct pt_regs *regs) +unsigned long perf_arch_instruction_pointer(struct pt_regs *regs) { unsigned long siar =3D mfspr(SPRN_SIAR); =20 diff --git a/arch/s390/include/asm/perf_event.h b/arch/s390/include/asm/per= f_event.h index 9917e2717b2b..f2d83289ec7a 100644 --- a/arch/s390/include/asm/perf_event.h +++ b/arch/s390/include/asm/perf_event.h @@ -37,9 +37,9 @@ extern ssize_t cpumf_events_sysfs_show(struct device *dev, =20 /* Perf callbacks */ struct pt_regs; -extern unsigned long perf_instruction_pointer(struct pt_regs *regs); -extern unsigned long perf_misc_flags(struct pt_regs *regs); -#define perf_misc_flags(regs) perf_misc_flags(regs) +extern unsigned long perf_arch_instruction_pointer(struct pt_regs *regs); +extern unsigned long perf_arch_misc_flags(struct pt_regs *regs); +#define perf_arch_misc_flags(regs) perf_misc_flags(regs) #define perf_arch_bpf_user_pt_regs(regs) ®s->user_regs =20 /* Perf pt_regs extension for sample-data-entry indicators */ diff --git a/arch/s390/kernel/perf_event.c b/arch/s390/kernel/perf_event.c index 5fff629b1a89..f9000ab49f4a 100644 --- a/arch/s390/kernel/perf_event.c +++ b/arch/s390/kernel/perf_event.c @@ -57,7 +57,7 @@ static unsigned long instruction_pointer_guest(struct pt_= regs *regs) return sie_block(regs)->gpsw.addr; } =20 -unsigned long perf_instruction_pointer(struct pt_regs *regs) +unsigned long perf_arch_instruction_pointer(struct pt_regs *regs) { return is_in_guest(regs) ? instruction_pointer_guest(regs) : instruction_pointer(regs); @@ -84,7 +84,7 @@ static unsigned long perf_misc_flags_sf(struct pt_regs *r= egs) return flags; } =20 -unsigned long perf_misc_flags(struct pt_regs *regs) +unsigned long perf_arch_misc_flags(struct pt_regs *regs) { /* Check if the cpum_sf PMU has created the pt_regs structure. * In this case, perf misc flags can be easily extracted. Otherwise, diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index be01823b1bb4..760ad067527c 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -2940,7 +2940,7 @@ static unsigned long code_segment_base(struct pt_regs= *regs) return 0; } =20 -unsigned long perf_instruction_pointer(struct pt_regs *regs) +unsigned long perf_arch_instruction_pointer(struct pt_regs *regs) { if (perf_guest_state()) return perf_guest_get_ip(); @@ -2948,7 +2948,7 @@ unsigned long perf_instruction_pointer(struct pt_regs= *regs) return regs->ip + code_segment_base(regs); } =20 -unsigned long perf_misc_flags(struct pt_regs *regs) +unsigned long perf_arch_misc_flags(struct pt_regs *regs) { unsigned int guest_state =3D perf_guest_state(); int misc =3D 0; diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_= event.h index 91b73571412f..feb87bf3d2e9 100644 --- a/arch/x86/include/asm/perf_event.h +++ b/arch/x86/include/asm/perf_event.h @@ -536,15 +536,15 @@ struct x86_perf_regs { u64 *xmm_regs; }; =20 -extern unsigned long perf_instruction_pointer(struct pt_regs *regs); -extern unsigned long perf_misc_flags(struct pt_regs *regs); -#define perf_misc_flags(regs) perf_misc_flags(regs) +extern unsigned long perf_arch_instruction_pointer(struct pt_regs *regs); +extern unsigned long perf_arch_misc_flags(struct pt_regs *regs); +#define perf_arch_misc_flags(regs) perf_arch_misc_flags(regs) =20 #include =20 /* - * We abuse bit 3 from flags to pass exact information, see perf_misc_flags - * and the comment with PERF_EFLAGS_EXACT. + * We abuse bit 3 from flags to pass exact information, see + * perf_arch_misc_flags() and the comment with PERF_EFLAGS_EXACT. */ #define perf_arch_fetch_caller_regs(regs, __ip) { \ (regs)->ip =3D (__ip); \ diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 1a8942277dda..d061e327ad54 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -1633,10 +1633,13 @@ extern void perf_tp_event(u16 event_type, u64 count= , void *record, struct task_struct *task); extern void perf_bp_event(struct perf_event *event, void *data); =20 -#ifndef perf_misc_flags -# define perf_misc_flags(regs) \ +extern unsigned long perf_misc_flags(struct pt_regs *regs); +extern unsigned long perf_instruction_pointer(struct pt_regs *regs); + +#ifndef perf_arch_misc_flags +# define perf_arch_misc_flags(regs) \ (user_mode(regs) ? PERF_RECORD_MISC_USER : PERF_RECORD_MISC_KERNEL) -# define perf_instruction_pointer(regs) instruction_pointer(regs) +# define perf_arch_instruction_pointer(regs) instruction_pointer(regs) #endif #ifndef perf_arch_bpf_user_pt_regs # define perf_arch_bpf_user_pt_regs(regs) regs diff --git a/kernel/events/core.c b/kernel/events/core.c index 8a6c6bbcd658..eeabbf791a8c 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -6921,6 +6921,16 @@ void perf_unregister_guest_info_callbacks(struct per= f_guest_info_callbacks *cbs) EXPORT_SYMBOL_GPL(perf_unregister_guest_info_callbacks); #endif =20 +unsigned long perf_misc_flags(struct pt_regs *regs) +{ + return perf_arch_misc_flags(regs); +} + +unsigned long perf_instruction_pointer(struct pt_regs *regs) +{ + return perf_arch_instruction_pointer(regs); +} + static void perf_output_sample_regs(struct perf_output_handle *handle, struct pt_regs *regs, u64 mask) --=20 2.46.0.662.g92d0881bb0-goog From nobody Sat Nov 30 03:39:47 2024 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 23FB11C1AD8 for ; Thu, 12 Sep 2024 20:51:40 +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=1726174301; cv=none; b=defUcCddTMJPFUvHOmzria+Lv+TYIJzIF5xJgdqKEQvJ8Tn+Attshs+INQgTw90QFB8YX9skbjPVouI4OlNMQecRPr/Rf3xhFVLCC0LvPQoPBl4nfQC/Fm5GQFf+SyIo1yBZE8agHr+23yO127iDu9hYdZsBAhHpTxy30rBE3TY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726174301; c=relaxed/simple; bh=pmE1v3lPafn5e/IdEGvJX2LgNHvxAhIJEOQCTre4Ijg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Nlhs6DNT05aO+i1VFmFAcXvjsX6DYiSx+Lase9SPH4e7ynqiHadR6aztVHW/YlaT3hdyFJr6jhpMeap67UfU9OzWZJcK0qSQIeoCCMMhBpm3s/ucTNkQh9zUCE2BBULguXkJDPY3mzv6buJt4ED2+VPp/kExPUZjGcwwnpNc2Mw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--coltonlewis.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=4KA/Wsqr; 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--coltonlewis.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="4KA/Wsqr" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e1a892d8438so2802902276.3 for ; Thu, 12 Sep 2024 13:51:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726174299; x=1726779099; 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=2R8Y3DFBOrXpT6Dp+2pnByuz3JsPwrzU4P/6bkl9CfA=; b=4KA/WsqroocPgEf/Kvn1/+NAsnFqu4g+y+EoP5K884ge0R2EhUY2p/Bc66jAEjNg1/ 37WqiJ3J4/y55PhgPCmkESjikU9t+l/LLuk54JX6mRGNKKm5jw+asQkztQ/i+HtNrb1Z j5egYrDvG8Lq82fgfzpVao98Q6DrIg43u2D+WnGhWNayX7N0KaKPDcFpPgSN+/yWq91T 6aHTmxebgGiW3HA6wOjVnWoB93MVEPUNSPsvA+w2lSvbOVXRP/w9nPB2SWvphpUFLTwT afyM0U/BtG09tzQZyhFDD3LDYvRezDGv6AOkIyOq3m5E+6e6oNJ3aehC+OLfQDu+B3Gq vM5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726174299; x=1726779099; 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=2R8Y3DFBOrXpT6Dp+2pnByuz3JsPwrzU4P/6bkl9CfA=; b=tXSeVItQI3hYYoqPQdiq2z5+N3Q530DnaHgWKjMZOPI0KLSoETv3w4hrLnjPqUG4w5 uE6FUJfS63XEM23/J6upudlMmX9+Mn1wQOV0yDkeRaQe/oEo5igWFmo9j0FXSn654ZO6 9k5dHRi0Lp7iBZykpXZx+Wl/wuHznmS4QdnWJ6TRYzGYOY82IP6sDDZbaGfXoPYKFpGl oaEHKob39xOkZkoGbQEkim+hWbcaJbESp90mRSqbAcwndPxrPJox09fz0dQRcE1X6eI6 Mzj+i7nn5kWVPGiEtKPYkNSr/D4HhjbqhJ7kgd9kIWbbW1QxbgusznKBJB876N9jkJL+ XZ/Q== X-Forwarded-Encrypted: i=1; AJvYcCUSGwofDPRrPDOGt3Kndi6V1w8SIumF4vADmJbl/tWssfDtp91JBvNxLzfyeMNc9wLEpwRp0Q0XX7PVWL8=@vger.kernel.org X-Gm-Message-State: AOJu0YwTqG17wtp62EJ/YymoqkB8/kmMIm+qrdk3zjr90mPA6TQwIT2k CAt4VN4IWPtrkNLyME1o8fMeu2/KgRcdeMrsbtEJnZ4wTb9epQA+RxFphaCeKK9tMuS5/f8VuqN Tb8uLljIQdGkp041PxmniOA== X-Google-Smtp-Source: AGHT+IFV1m07CCTdDWX2FOgecLasTDjDmm3XH/XZUgTEGDR6/YrsS27OTSnLSt+SciKeVBgsQCat9dX1tnl2/VgIOw== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a05:6902:1743:b0:e03:3cfa:1aa7 with SMTP id 3f1490d57ef6-e1d9db9e1b8mr5314276.1.1726174299130; Thu, 12 Sep 2024 13:51:39 -0700 (PDT) Date: Thu, 12 Sep 2024 20:51:31 +0000 In-Reply-To: <20240912205133.4171576-1-coltonlewis@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240912205133.4171576-1-coltonlewis@google.com> X-Mailer: git-send-email 2.46.0.662.g92d0881bb0-goog Message-ID: <20240912205133.4171576-4-coltonlewis@google.com> Subject: [PATCH v3 3/5] powerpc: perf: Use perf_arch_instruction_pointer() From: Colton Lewis To: kvm@vger.kernel.org Cc: Oliver Upton , Sean Christopherson , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , 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, Colton Lewis Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Make sure powerpc uses the arch-specific function now that those have been reorganized. Signed-off-by: Colton Lewis Reviewed-by: Oliver Upton --- arch/powerpc/perf/callchain.c | 2 +- arch/powerpc/perf/callchain_32.c | 2 +- arch/powerpc/perf/callchain_64.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/perf/callchain.c b/arch/powerpc/perf/callchain.c index 6b4434dd0ff3..26aa26482c9a 100644 --- a/arch/powerpc/perf/callchain.c +++ b/arch/powerpc/perf/callchain.c @@ -51,7 +51,7 @@ perf_callchain_kernel(struct perf_callchain_entry_ctx *en= try, struct pt_regs *re =20 lr =3D regs->link; sp =3D regs->gpr[1]; - perf_callchain_store(entry, perf_instruction_pointer(regs)); + perf_callchain_store(entry, perf_arch_instruction_pointer(regs)); =20 if (!validate_sp(sp, current)) return; diff --git a/arch/powerpc/perf/callchain_32.c b/arch/powerpc/perf/callchain= _32.c index ea8cfe3806dc..ddcc2d8aa64a 100644 --- a/arch/powerpc/perf/callchain_32.c +++ b/arch/powerpc/perf/callchain_32.c @@ -139,7 +139,7 @@ void perf_callchain_user_32(struct perf_callchain_entry= _ctx *entry, long level =3D 0; unsigned int __user *fp, *uregs; =20 - next_ip =3D perf_instruction_pointer(regs); + next_ip =3D perf_arch_instruction_pointer(regs); lr =3D regs->link; sp =3D regs->gpr[1]; perf_callchain_store(entry, next_ip); diff --git a/arch/powerpc/perf/callchain_64.c b/arch/powerpc/perf/callchain= _64.c index 488e8a21a11e..115d1c105e8a 100644 --- a/arch/powerpc/perf/callchain_64.c +++ b/arch/powerpc/perf/callchain_64.c @@ -74,7 +74,7 @@ void perf_callchain_user_64(struct perf_callchain_entry_c= tx *entry, struct signal_frame_64 __user *sigframe; unsigned long __user *fp, *uregs; =20 - next_ip =3D perf_instruction_pointer(regs); + next_ip =3D perf_arch_instruction_pointer(regs); lr =3D regs->link; sp =3D regs->gpr[1]; perf_callchain_store(entry, next_ip); --=20 2.46.0.662.g92d0881bb0-goog From nobody Sat Nov 30 03:39:47 2024 Received: from mail-io1-f74.google.com (mail-io1-f74.google.com [209.85.166.74]) (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 127771C232D for ; Thu, 12 Sep 2024 20:51:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726174304; cv=none; b=p+ne5gsu0GSms88rXpzK/2dYQWPzjWOZQWI3Yl0fP5ehC7Ou3JTH1f4eeMXwmve0odDZVlE251ZooaaksVAWlplBjdleQ2TweaNvWNsoCHl9GPLg8pWNR5gBMCc/V7WBmcJU+6VTAGtXI+UxN3QfSrUPr29+X0h+X8l6CjEeTRU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726174304; c=relaxed/simple; bh=i95QDLsU5GaO2Xej2TBOmg9Wex/kOoppvJv8vIvwjAQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=I2aWWaB5m4+dlF0HjZSpKFPESWzHPoMhslT49wMk1avkwCjMcgco01Kxe3laKUS8J/mR86ngdGOxKHpYcvR09Zy+IMatfOYh+k4tWvyyj0fOhMrfP5alpj+7Z9iZ6187DMFoWHksc8NiIrmCbw7XmAD9+URtQLV0SCdzd3BFcx8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--coltonlewis.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=VCXewt1C; arc=none smtp.client-ip=209.85.166.74 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--coltonlewis.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="VCXewt1C" Received: by mail-io1-f74.google.com with SMTP id ca18e2360f4ac-82aad3fa5edso170087439f.2 for ; Thu, 12 Sep 2024 13:51:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726174300; x=1726779100; 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=3HOlQ/b1Vqnby1HRrJAa+4JPh1tcBF4UxpW0vveqy4M=; b=VCXewt1CC9UaN5dOanDSbbVO3yQwrg2Vn2SGqCNZ27+DR4GNcap4uwBDbtyGUNeQBv kIcP3Wb0nJ8AoeNWHVUl/eJ6q4c4n4FXg68SnFACIfCy7hLvMAWmeIwx9Tb4Eeft4wF/ 5OC8/YjI+xdGf/4hTE986GVf6criVXw3YYZPB/wVSVODdODfj0C8hwHLSlWROcneRjnm Ch/wImqL67EQefOyfc4f7tuajtv7KPacrzdLl2t8XEQc4uFBIw2ePHzXwUavjF1MIz08 A8Q3hVk/Zuiigmk2xqmwhOev9pB7slONM/vWcpdp+2LJxoem/gU4WCqPGdoJbmliYTsW bg+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726174300; x=1726779100; 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=3HOlQ/b1Vqnby1HRrJAa+4JPh1tcBF4UxpW0vveqy4M=; b=Ff1yJmjbLSExn169Xtpwz0AxfpKdbTJKBUoKnzfqxIdIFQeNz2CNLlcMdcVgMq0C2t kecnR6OqskBtlHAj/NObdcLIkWcij4tOfN7bBkMemsYHTeunto74FFBMK/V3NLU8aEnH FsVTTlRRiIn80Q4YajJ3Rwe0iy0UjCj0h/CWvQYigHAT6Sq23DRtzYGQ7cFmh6tzmlt9 vRIlTlhf1UbsSYG8TYKmd9LeUdAIUK19QdcnRz4U+u5t2AuSpbWPEjCdyS7sJKjAvl6+ 1tSrgqMv9opf3Eucu5hYHeKHXMBxWq8ZfXunnQgGgzs3J9oxofBCjWrOOHMrahIDkbz9 eYDw== X-Forwarded-Encrypted: i=1; AJvYcCXiVlcyF2vTa4e/BMjiDxPFemDuFpg4pl77z6XS8YHyf5HvFJF6e1t+FcW0ZOUzvQCuAhOECQWYsI9G3FA=@vger.kernel.org X-Gm-Message-State: AOJu0YwbcfpwfG8A6YPBPRztrvYOcLfTXEKjhlbbuc3AdJgWyicSYs4G o9+btQyt7qNZeYR+yryKvWYqyNvsfsKZbVg7W1NRCtORJ5m0w51XNgwGEs7827XqTEJ7jkyezQw qSmTMLei2JV3gq28PGOsq4Q== X-Google-Smtp-Source: AGHT+IH+tyLe1qQliN4X6ik9ZMj1aIgWQ7X0DXUSN8bntx8eM08UGo31hDfdaqtl4MXbxod/0+xFT0h7PePUGuXbpA== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a05:6602:2d86:b0:82c:eb15:1aae with SMTP id ca18e2360f4ac-82d1f8b0c0amr3300039f.1.1726174300197; Thu, 12 Sep 2024 13:51:40 -0700 (PDT) Date: Thu, 12 Sep 2024 20:51:32 +0000 In-Reply-To: <20240912205133.4171576-1-coltonlewis@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240912205133.4171576-1-coltonlewis@google.com> X-Mailer: git-send-email 2.46.0.662.g92d0881bb0-goog Message-ID: <20240912205133.4171576-5-coltonlewis@google.com> Subject: [PATCH v3 4/5] x86: perf: Refactor misc flag assignments From: Colton Lewis To: kvm@vger.kernel.org Cc: Oliver Upton , Sean Christopherson , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , 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, Colton Lewis Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Break the assignment logic for misc flags into their own respective functions to reduce the complexity of the nested logic. Signed-off-by: Colton Lewis Reviewed-by: Oliver Upton --- arch/x86/events/core.c | 31 +++++++++++++++++++++++-------- arch/x86/include/asm/perf_event.h | 2 ++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index 760ad067527c..d51e5d24802b 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -2948,16 +2948,34 @@ unsigned long perf_arch_instruction_pointer(struct = pt_regs *regs) return regs->ip + code_segment_base(regs); } =20 +static unsigned long common_misc_flags(struct pt_regs *regs) +{ + if (regs->flags & PERF_EFLAGS_EXACT) + return PERF_RECORD_MISC_EXACT_IP; + + return 0; +} + +unsigned long perf_arch_guest_misc_flags(struct pt_regs *regs) +{ + unsigned long guest_state =3D perf_guest_state(); + unsigned long flags =3D common_misc_flags(regs); + + if (guest_state & PERF_GUEST_USER) + flags |=3D PERF_RECORD_MISC_GUEST_USER; + else if (guest_state & PERF_GUEST_ACTIVE) + flags |=3D PERF_RECORD_MISC_GUEST_KERNEL; + + return flags; +} + unsigned long perf_arch_misc_flags(struct pt_regs *regs) { unsigned int guest_state =3D perf_guest_state(); - int misc =3D 0; + unsigned long misc =3D common_misc_flags(regs); =20 if (guest_state) { - if (guest_state & PERF_GUEST_USER) - misc |=3D PERF_RECORD_MISC_GUEST_USER; - else - misc |=3D PERF_RECORD_MISC_GUEST_KERNEL; + misc |=3D perf_arch_guest_misc_flags(regs); } else { if (user_mode(regs)) misc |=3D PERF_RECORD_MISC_USER; @@ -2965,9 +2983,6 @@ unsigned long perf_arch_misc_flags(struct pt_regs *re= gs) misc |=3D PERF_RECORD_MISC_KERNEL; } =20 - if (regs->flags & PERF_EFLAGS_EXACT) - misc |=3D PERF_RECORD_MISC_EXACT_IP; - return misc; } =20 diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_= event.h index feb87bf3d2e9..d95f902acc52 100644 --- a/arch/x86/include/asm/perf_event.h +++ b/arch/x86/include/asm/perf_event.h @@ -538,7 +538,9 @@ struct x86_perf_regs { =20 extern unsigned long perf_arch_instruction_pointer(struct pt_regs *regs); extern unsigned long perf_arch_misc_flags(struct pt_regs *regs); +extern unsigned long perf_arch_guest_misc_flags(struct pt_regs *regs); #define perf_arch_misc_flags(regs) perf_arch_misc_flags(regs) +#define perf_arch_guest_misc_flags(regs) perf_arch_guest_misc_flags(regs) =20 #include =20 --=20 2.46.0.662.g92d0881bb0-goog From nobody Sat Nov 30 03:39:47 2024 Received: from mail-il1-f202.google.com (mail-il1-f202.google.com [209.85.166.202]) (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 2EE371C244C for ; Thu, 12 Sep 2024 20:51:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726174304; cv=none; b=cey7cPs1FHmMQWsgLMzXxOmcnBczUwWb9zQnUzIFusXmd5N6QdxyeJ5fDJZtKzluOeqTY9I3ss+BQ3RdNNkEtp5CpL+cqULY5WWT6lg4lczQAV1puGo8BUmNCPdcrceJafJiooCzgMZbuKMq5MswnBbSNYSaQvEQjlh/mrYvJwM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726174304; c=relaxed/simple; bh=PKSFMxsLHH0l845bvs4l3OWGTbpYpevrNa7/4HkPfdk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=amb22Q9/uu3kUzqyO3Pafj6nkGvqGLwi0U4LkiR++RTd+sM7VJjR2/XM+tOYKTEgHrmesCpdOf/xiOEd4P6DoXAuRhEKFMHXge1lf642l+KN3xf938OlDPaxpK3njioL7LtbdUpUIKOUCBD5N1FCsIk1xrNGT9SsC7LKLgbjIl4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--coltonlewis.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=XajVO5P5; arc=none smtp.client-ip=209.85.166.202 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--coltonlewis.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="XajVO5P5" Received: by mail-il1-f202.google.com with SMTP id e9e14a558f8ab-39f56ac8d88so3423875ab.2 for ; Thu, 12 Sep 2024 13:51:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726174301; x=1726779101; 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=pN3motQEuLoryG8c/qRFsCpEmHTVQN30TnUfjf1L05Y=; b=XajVO5P5g5BZUL7ckQFGkufjmewMMohoxmQ7sbHCziy97LMGuThUWi+AJrfQuHHkMr LKLOQ2VAZ6bynJwIWdwbr6PI+IRxZ6+RmY+RSe/JJskzXjvu1/fOWBTGO5sFmMDmo5bM rj8X8J2YPpC1DD4vSYWVlelX1akZZBM16ViFCSwqKuOdLcAaM9LEAkiZZSF0epYZkzRX ipahVi4dxhnJT+7T2+dbzfVklnVqJwPvpVxccNRq7QhSrDYZNuVn5zNaOZQT7KZSkZIH Bb8gXuh3G5MxtMfY/XCZJL7YOXEejLC+sz2t3+7Rmx61Kurl8i+cx1JXnNHg5Bm3JEMk zNwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726174301; x=1726779101; 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=pN3motQEuLoryG8c/qRFsCpEmHTVQN30TnUfjf1L05Y=; b=cVa62xhjjjzZrYOpHlB3ppPZ1/6aY4RiCgI7wH9tKYwS/QsHoxHB3iw8UkMsb+oDww AodckSw4jsCa2K6lBIspm2Bj0rCQTqvK5Q/DuVEKPKnxHxb/FM/Q9uWPMNDCVq0QOvkN p9gAVe71YVIcB7K2JdmvGFudma0l0MPRmm4f5Nd1nTybXyGk3kt2oCdK2e2wi9D1PcRf rtomBMrPvdg/9U+Nf7LFYeUUCxW+1weazvsaF3BYab9bGxApDIsqBIlswaBAuXSCap1x OKikuyi/yO6hw+M4dZgddViom+recjQBmivPvkAAVWyNmZoHv6INpDyCP4Eeai4x+6Nb B9Xw== X-Forwarded-Encrypted: i=1; AJvYcCVAuCkBGafE93Xk90LLeLws98KEvzmYxT6ZRzOS+ZvfqfOnVL5bqMN7aHDvRqHBpbBpBCQRl4tV3MswVmc=@vger.kernel.org X-Gm-Message-State: AOJu0YziqkReSeJkRWW2SoTDSood+xxyxsAzH34JL5X79UwlB350IIug KPHbbF61kLuoxNFHmBvc6yoOFCS2cT/KD2LxiV4m8uiOafb9AW4C/lQ0XziE3EUputcCUy6Hzgy q3jxiKwpw0ipTihHmylYJpw== X-Google-Smtp-Source: AGHT+IE5uBnbPCKzOwkMC48JVFthRmj9q9RybjWG1vwJiuOPIIxum8Gar8GGRDZP2nZfvTS3r0HkOT/glreBt/EPvw== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a92:cd83:0:b0:397:b509:6441 with SMTP id e9e14a558f8ab-3a08b72994amr15335ab.2.1726174301380; Thu, 12 Sep 2024 13:51:41 -0700 (PDT) Date: Thu, 12 Sep 2024 20:51:33 +0000 In-Reply-To: <20240912205133.4171576-1-coltonlewis@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240912205133.4171576-1-coltonlewis@google.com> X-Mailer: git-send-email 2.46.0.662.g92d0881bb0-goog Message-ID: <20240912205133.4171576-6-coltonlewis@google.com> Subject: [PATCH v3 5/5] perf: Correct perf sampling with guest VMs From: Colton Lewis To: kvm@vger.kernel.org Cc: Oliver Upton , Sean Christopherson , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , 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, Colton Lewis Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Rework the sampling logic to only record guest samples for events with exclude_guest =3D 0. This way any host-only events with exclude_guest set will never see unexpected guest samples. The behaviour of events with exclude_guest =3D 0 is unchanged. Note that events configured to sample both host and guest may still misattribute a PMI that arrived in the host as a guest event depending on KVM arch and vendor behavior. Signed-off-by: Colton Lewis Reviewed-by: Oliver Upton --- arch/arm64/include/asm/perf_event.h | 4 ---- arch/arm64/kernel/perf_callchain.c | 28 ---------------------------- arch/x86/events/core.c | 16 ++++------------ include/linux/perf_event.h | 21 +++++++++++++++++++-- kernel/events/core.c | 21 +++++++++++++++++---- 5 files changed, 40 insertions(+), 50 deletions(-) diff --git a/arch/arm64/include/asm/perf_event.h b/arch/arm64/include/asm/p= erf_event.h index 31a5584ed423..ee45b4e77347 100644 --- a/arch/arm64/include/asm/perf_event.h +++ b/arch/arm64/include/asm/perf_event.h @@ -10,10 +10,6 @@ #include =20 #ifdef CONFIG_PERF_EVENTS -struct pt_regs; -extern unsigned long perf_arch_instruction_pointer(struct pt_regs *regs); -extern unsigned long perf_arch_misc_flags(struct pt_regs *regs); -#define perf_arch_misc_flags(regs) perf_misc_flags(regs) #define perf_arch_bpf_user_pt_regs(regs) ®s->user_regs #endif =20 diff --git a/arch/arm64/kernel/perf_callchain.c b/arch/arm64/kernel/perf_ca= llchain.c index 01a9d08fc009..9b7f26b128b5 100644 --- a/arch/arm64/kernel/perf_callchain.c +++ b/arch/arm64/kernel/perf_callchain.c @@ -38,31 +38,3 @@ void perf_callchain_kernel(struct perf_callchain_entry_c= tx *entry, =20 arch_stack_walk(callchain_trace, entry, current, regs); } - -unsigned long perf_arch_instruction_pointer(struct pt_regs *regs) -{ - if (perf_guest_state()) - return perf_guest_get_ip(); - - return instruction_pointer(regs); -} - -unsigned long perf_arch_misc_flags(struct pt_regs *regs) -{ - unsigned int guest_state =3D perf_guest_state(); - int misc =3D 0; - - if (guest_state) { - if (guest_state & PERF_GUEST_USER) - misc |=3D PERF_RECORD_MISC_GUEST_USER; - else - misc |=3D PERF_RECORD_MISC_GUEST_KERNEL; - } else { - if (user_mode(regs)) - misc |=3D PERF_RECORD_MISC_USER; - else - misc |=3D PERF_RECORD_MISC_KERNEL; - } - - return misc; -} diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index d51e5d24802b..3c5f512d2bcf 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -2942,9 +2942,6 @@ static unsigned long code_segment_base(struct pt_regs= *regs) =20 unsigned long perf_arch_instruction_pointer(struct pt_regs *regs) { - if (perf_guest_state()) - return perf_guest_get_ip(); - return regs->ip + code_segment_base(regs); } =20 @@ -2971,17 +2968,12 @@ unsigned long perf_arch_guest_misc_flags(struct pt_= regs *regs) =20 unsigned long perf_arch_misc_flags(struct pt_regs *regs) { - unsigned int guest_state =3D perf_guest_state(); unsigned long misc =3D common_misc_flags(regs); =20 - if (guest_state) { - misc |=3D perf_arch_guest_misc_flags(regs); - } else { - if (user_mode(regs)) - misc |=3D PERF_RECORD_MISC_USER; - else - misc |=3D PERF_RECORD_MISC_KERNEL; - } + if (user_mode(regs)) + misc |=3D PERF_RECORD_MISC_USER; + else + misc |=3D PERF_RECORD_MISC_KERNEL; =20 return misc; } diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index d061e327ad54..968f3edd95e4 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -1633,8 +1633,9 @@ extern void perf_tp_event(u16 event_type, u64 count, = void *record, struct task_struct *task); extern void perf_bp_event(struct perf_event *event, void *data); =20 -extern unsigned long perf_misc_flags(struct pt_regs *regs); -extern unsigned long perf_instruction_pointer(struct pt_regs *regs); +extern unsigned long perf_misc_flags(struct perf_event *event, struct pt_r= egs *regs); +extern unsigned long perf_instruction_pointer(struct perf_event *event, + struct pt_regs *regs); =20 #ifndef perf_arch_misc_flags # define perf_arch_misc_flags(regs) \ @@ -1645,6 +1646,22 @@ extern unsigned long perf_instruction_pointer(struct= pt_regs *regs); # define perf_arch_bpf_user_pt_regs(regs) regs #endif =20 +#ifndef perf_arch_guest_misc_flags +static inline unsigned long perf_arch_guest_misc_flags(struct pt_regs *reg= s) +{ + unsigned long guest_state =3D perf_guest_state(); + + if (guest_state & PERF_GUEST_USER) + return PERF_RECORD_MISC_GUEST_USER; + + if (guest_state & PERF_GUEST_ACTIVE) + return PERF_RECORD_MISC_GUEST_KERNEL; + + return 0; +} +# define perf_arch_guest_misc_flags(regs) perf_arch_guest_misc_flags(regs) +#endif + static inline bool has_branch_stack(struct perf_event *event) { return event->attr.sample_type & PERF_SAMPLE_BRANCH_STACK; diff --git a/kernel/events/core.c b/kernel/events/core.c index eeabbf791a8c..c5e57c024d9a 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -6921,13 +6921,26 @@ void perf_unregister_guest_info_callbacks(struct pe= rf_guest_info_callbacks *cbs) EXPORT_SYMBOL_GPL(perf_unregister_guest_info_callbacks); #endif =20 -unsigned long perf_misc_flags(struct pt_regs *regs) +static bool should_sample_guest(struct perf_event *event) { + return !event->attr.exclude_guest && perf_guest_state(); +} + +unsigned long perf_misc_flags(struct perf_event *event, + struct pt_regs *regs) +{ + if (should_sample_guest(event)) + return perf_arch_guest_misc_flags(regs); + return perf_arch_misc_flags(regs); } =20 -unsigned long perf_instruction_pointer(struct pt_regs *regs) +unsigned long perf_instruction_pointer(struct perf_event *event, + struct pt_regs *regs) { + if (should_sample_guest(event)) + return perf_guest_get_ip(); + return perf_arch_instruction_pointer(regs); } =20 @@ -7743,7 +7756,7 @@ void perf_prepare_sample(struct perf_sample_data *dat= a, __perf_event_header__init_id(data, event, filtered_sample_type); =20 if (filtered_sample_type & PERF_SAMPLE_IP) { - data->ip =3D perf_instruction_pointer(regs); + data->ip =3D perf_instruction_pointer(event, regs); data->sample_flags |=3D PERF_SAMPLE_IP; } =20 @@ -7907,7 +7920,7 @@ void perf_prepare_header(struct perf_event_header *he= ader, { header->type =3D PERF_RECORD_SAMPLE; header->size =3D perf_sample_data_size(data, event); - header->misc =3D perf_misc_flags(regs); + header->misc =3D perf_misc_flags(event, regs); =20 /* * If you're adding more sample types here, you likely need to do --=20 2.46.0.662.g92d0881bb0-goog