From nobody Sat Nov 30 03:26:59 2024 Received: from mail-il1-f201.google.com (mail-il1-f201.google.com [209.85.166.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 372831B532D for ; Wed, 11 Sep 2024 22:25:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726093512; cv=none; b=szrt2LWMU2NBF6eTPVy+R2mMV7G6puwe74TlTqTZXB458jUReKJqS1J1ZxCwWmiDjQYYsdF9BNIzNQ6GokX2n0UifDO5z3+laXaylR8ld0xuVJtwNQ4UFCc0z32Zeu+pbxZY2UnTJfua40VPzCkIbdvzcVQeCgAHeK7wKQfPaYA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726093512; c=relaxed/simple; bh=BVvwBjCzkHKlE+Z/Vr8hTBCRhDHp8hUrZYi0cVtEGEY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mOFrfVEKGNepJqlpGMnhmyargngmCjhhkFejqYvVS0Y19wGkiND+s0rjC9LQIOh4MBIDxFDtpdDQdx9/dUMuqQeqjoLCNOdNzKigz8H76agDiE9kiw8o9Fb4or2JNi1VfuwVq4yaPARG8+pxUCvYPI1QlQ2Dg8+rvtw8IbqLz4s= 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=RDT6xQKX; arc=none smtp.client-ip=209.85.166.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="RDT6xQKX" Received: by mail-il1-f201.google.com with SMTP id e9e14a558f8ab-39f53125f4eso5421255ab.2 for ; Wed, 11 Sep 2024 15:25:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726093510; x=1726698310; 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=98KHHfZAU1dotPbU8K3avps0YbHY8rCmN7CSHv68LAQ=; b=RDT6xQKXlgU1IU55uKT3Oe6xVaZjalM81e8wCsCSoW85vvLpGJ9LfP3+lH8HKP5bCM zaOapyjJaXj04+PK5got56QDBb1l9rZFNgsMXDCB2vhAjr4WkZ6xBwxK+muVANwINjH3 nDA1asHFRGmie+eO6hqlmFoOlO0eGEEuMYRNeufFjpUkGI6bzvJMwu9PKeXpjp3qJ0yr nhjB1Pp1HkRpkedBOHT5fx1o0W/p0TBeCMkJCfJa9DI96nCfZpF82fEbdZfkApEv4uu7 S+75XBCIiK2UkZ805m9Bx8uM/YmzNzpnRP4LHwoWQxiN4mDfBjX2tqIJ5DzT8fk24tgk kdWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726093510; x=1726698310; 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=98KHHfZAU1dotPbU8K3avps0YbHY8rCmN7CSHv68LAQ=; b=f7hGRnF6QISuYxDRqW5pPPCcY2irbbHsyiFWjW8fwer27Mni0Lm+rYWU1FUvWOAdVx Quyvchz1UZ4mTAlDU7u7qksSaqVV5OxJhwgx0ehLe8erzZa/bnCLcV8EuDcByU82LaJc VstiNHP44iW9JObspi9YSAw73AINg9Wb/gr31YyIIh5R5K9V92Pr9/EdyXVN710piNZ8 iQAg1kLEDOlbjaLdaBPO82BhcspcL+mpEt9YOhz3A8pRt7GW6mpSpLL+eriJjx50l/my Z1QXz5ADahP6hBhlxJwTQ62g3vVG4V+ycj6P4EjME9rdfcpwht+qdbWJx7cZKRyeac/Q e09Q== X-Forwarded-Encrypted: i=1; AJvYcCX+B2L+oBinwtsfGUYNDDvM3h0jzumY+2uWcvLHqQ84qmc6SAdUjEGISi2t3D9P6kIU07+7c5DfBIG+H9M=@vger.kernel.org X-Gm-Message-State: AOJu0Yy/mjX5+OsFAsa3NLuicxHcscmU6atF9mM8ezKN8ePh2VKzadwp u+z3mXH682ic95tfN+clkvZIwYB+NLXVvbe6rdEWkrw5VBvPsm9ZDoRTHLYxtSm4KJGn9+G9Luy 5lTgPc2nvuHhXvnn7rzAg4Q== X-Google-Smtp-Source: AGHT+IHezO/FS6DrvjzqydPLEapvMWYoVJd9AX1NthmyW6WKSgM57sEvRhPyRtAfj2mQLXNB4v5VRUm4UvpIqG0BYA== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a05:6e02:1c48:b0:39f:549d:e39d with SMTP id e9e14a558f8ab-3a084967570mr302085ab.5.1726093510446; Wed, 11 Sep 2024 15:25:10 -0700 (PDT) Date: Wed, 11 Sep 2024 22:24:28 +0000 In-Reply-To: <20240911222433.3415301-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: <20240911222433.3415301-1-coltonlewis@google.com> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog Message-ID: <20240911222433.3415301-2-coltonlewis@google.com> Subject: [PATCH v2 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 --- 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.598.g6f2099f65c-goog From nobody Sat Nov 30 03:26:59 2024 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 9B3C21BA263 for ; Wed, 11 Sep 2024 22:25:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726093515; cv=none; b=tWEvUtYTdI+SIRZRH2sbQvcxaAaEROMhB86gIgZonKb8SEs32pfDv/VxF4lwEmfQou/1OMsRytMYXUpvrKiLgjeNm9tOMYD/YAk3e2VCQJsa0JVJ8WprExSz7qYbmb5mY3w/h08gLdjIm+4xXDOy+Eb2rlfSa+iQDqlVhWATLd4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726093515; c=relaxed/simple; bh=Jqt1TbYvZkNPQVLU4D7ibSVM3+HcRjvb0Is6Dl19O60=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=o9diWcmwZrfYjs1PSOcvubJRjjhZSpcvVPmQCcsqWBzeerAo+L0jj7hzctuizHO80PWjlRkN0K5vxcf4smouc3/TFih86WmHuaKDhgwp/zH00aO0hNApuPYPBuAfQj9ACTQebM9rv5a01toEU9ThC38upa/dkwOq+dmat2YCAQ8= 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=zWzDbT0r; arc=none smtp.client-ip=209.85.128.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="zWzDbT0r" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6db791c42e3so13133047b3.1 for ; Wed, 11 Sep 2024 15:25:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726093511; x=1726698311; 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=crmhw2mLEZ3+RGHHnhBbhpz6G/wxlsr9F/cDgMbCNx0=; b=zWzDbT0rxHnhOPzYNvnApBaXQzh9f5nIK78XMnivwxdcP9NJNXJOqrgHANZPZ39tff mvaYcqdsMjVqkaGnZ2vI0X7RVzFldolAGDiSSYDf55eBiQOseyU7T49iroyqwj/ft9tt 0xzezGqj8XYdHePW2wcNLyapnJdhHhJ+hbV/TDZXsu3rDh7GjHQ2Mpam1q0LqyZY9OZj z7mv+cfIYXitkckLwCn474HV/ROsfbmpEg0qDgzupfCT632tdn14WyLYizrSCfdaY3UP l9MAbeDHqhjZTFWhc3Z1H1pXf6mkeRGmxWzst3Pvhx3RDjUuAWDqz2QiVQNWri8FxDrh /+wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726093511; x=1726698311; 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=crmhw2mLEZ3+RGHHnhBbhpz6G/wxlsr9F/cDgMbCNx0=; b=gb1JZ8zoQMGkCETko0MgI7RIWDa/rW2Or+4Khfr+FrxgHQO7KHdKNb/N+Bqv9v7EUS Pf7RRAUJg9fag4h/bJiCX4bEfVBBIsCQx8KuwFXKjwzCjzAK8pqYa/n894L9sPnkgfgY VvexIdu03cIY5JCgU/FhIqMTIQj2fZ2i9BE8A0zvci0rtid4qTxqDQlxxI34fHqK05mx XR2DtbDpsZXbmVVuGCh0PemA8VV3X0dOljzVSh6b2QlUU7hfSg1M5xoh9VYLVsZCKt52 5DZUa9Gnojq2fn9PKpglTC79LWyRiG6aJaJu7tUGncBE8Vt/4Xg1UcbHWYTVC55tEWSO QX9g== X-Forwarded-Encrypted: i=1; AJvYcCW1LXzICKnI3cA8gvbCo0rGl7bM50wjsKwgyuPt06p3R+OFs8KVzlG6FyTAbpD5o/Wn39rgz67eoBU7zY8=@vger.kernel.org X-Gm-Message-State: AOJu0YyX6oJSDQuyD1SMBYUXJyteUqc4by9RVYMqUHaM2lkAXthdWAfV RoV/vkoDx9+v7q0YnKip6PDcR73NJGZETS9ix/buQAbY+DRv954LVb97N1ZxTt1VV/gZfY2z7md TzIEjT7puGQ7P7NqMaxmaGw== X-Google-Smtp-Source: AGHT+IG/kcNrSc00DiV0Ogd+lp7Te7joIo9TjDes3ay3ZaxS7IQuZ1/VH3N+WObF+/ClPQF8BfSZxNsumtK7iHDYfg== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a05:690c:6c8f:b0:6ad:e9c1:fc4f with SMTP id 00721157ae682-6dbb6b8c62bmr380167b3.5.1726093511584; Wed, 11 Sep 2024 15:25:11 -0700 (PDT) Date: Wed, 11 Sep 2024 22:24:29 +0000 In-Reply-To: <20240911222433.3415301-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: <20240911222433.3415301-1-coltonlewis@google.com> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog Message-ID: <20240911222433.3415301-3-coltonlewis@google.com> Subject: [PATCH v2 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 --- 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.598.g6f2099f65c-goog From nobody Sat Nov 30 03:26:59 2024 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 D446E1BB6B0 for ; Wed, 11 Sep 2024 22:25:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726093515; cv=none; b=j37mB4clbB4mjOoRBqSi7hHGOydUcUettCVqIB8W41j21duk8026gpH48PhYfc6PXnRTvUcT3Dt2lfzXVZ9ejdczT9fIW8aYw/CE/V+LxFmIhY8i/QEsUAXMAv7wgFsmaGizjoE2dbzq6Nw68rMrzl2V0WBXyW7Mi0GEHuU5fy8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726093515; c=relaxed/simple; bh=Qe6ZURpmPiYgTTi7nxbvffzfT5qXIMw8HIC3oO1Vo3I=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=srb7Yyu19AZ56hyMWPHdEv+tXS53xXKl19jM0cgw5X4GGYj4FV0qxigfPLdbnLfEUS/EUsSqw6AK0c3tRuG1qmgVcRyBCyrMr/DNqrvYsMZmtcQUXS4grxW91U4N79YpTmDic0oBWqR9Ucxh6Qe8PY4nAyfXD3frHvofmtPTmEE= 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=lN07+KR0; arc=none smtp.client-ip=209.85.128.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="lN07+KR0" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6db7a8c6831so17486427b3.3 for ; Wed, 11 Sep 2024 15:25:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726093513; x=1726698313; 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=l4XmBjdboaUqTeMgRqbSdf4DSeJIVFEq/lNcpwN1ftE=; b=lN07+KR076rJbAvNKbHXlC+K9jYGDh/m0feLEKennZiE7o/4IMwdIfJpXLgi8ga3fc 7HG+6DHe+N20ufjbGFaJCGo4ZhHvQUvApUUQZMgOVlTtfDYh2yL+U+QzjE1ihb6YID7f 3249cpFumZ40IBNEjertayqY9aCkRVVUUJu8aawI3ZNtZqGxHul60PWWHbXu3NcWfiqx HKWcTyjOlLDjx+w52vlECO3oRs+nUjOVi4f5YNKb97pEw65Duv13Jzg/dWYojxgoqpfj sPTdlpFyCaCPVtryq+GT2FFi10HcazjGsIjDsjPlyDsTQSocaIk+eAHvfiy0c+Tv26JP 0EXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726093513; x=1726698313; 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=l4XmBjdboaUqTeMgRqbSdf4DSeJIVFEq/lNcpwN1ftE=; b=izoJPKg9oWLlw67lFY14JBCRxVUAbgqVHwn/e+cvefW4ki2Z4qa+gIgRbyMHfyBR4C Ft56S3lo3xomA2knBHVIJjgyO9gJ0sHs5IEHu584GjVlZZE+oR+K60Qzujxw58RouwHC 8MK50Crr+2vPm2T7qBejgn/8bemMDAh+S77Yl7mWoFYcKXnr5D9HrI1rvdA1s3LBo0lA drgd8TAAgV3jI3Qvgn6tFpP/nGUhS/FBgi2HuKMe0Wc9e47G6Yx+dN311ZBCDggrOJC6 uJPi1Ogbjnj6m67hxChvXNGSyHKeplWQadMZSLgj8qRHd2l5tN/fKjG1pEnx1mH/0rdj 4IiA== X-Forwarded-Encrypted: i=1; AJvYcCWPBXHxawhxiDqL8LpOQmi89dMBUEk44FVU6EP3mxNtbVeanW+JfI+aNU+CFq+wId9qY5fHnaMMgJOegzk=@vger.kernel.org X-Gm-Message-State: AOJu0YyrOqMq0lLvNQ/oNYWpVdLLBpDsNpuphwRlb8Bc8wPdErRkWkYV FxUCDX1xSr9d1hupXNNtDYNIQ/n3J0lYnWgpOO4czOmJ30UnxSY1sA/rwj9Vb7bd7zwC3SMBmJd bEllk/emcOnQXIgQuTcNaTg== X-Google-Smtp-Source: AGHT+IHahPlfxq0OnDlBxbNh4kFfba2/NbBP9j+SjDxLZau6fx+NZ8cgucf9q6YqSrrkRp98eVZcQ/vy+HEi7ntE2A== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a05:690c:6083:b0:6c3:e9e5:e6a with SMTP id 00721157ae682-6dbb6ba1041mr322647b3.8.1726093512763; Wed, 11 Sep 2024 15:25:12 -0700 (PDT) Date: Wed, 11 Sep 2024 22:24:30 +0000 In-Reply-To: <20240911222433.3415301-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: <20240911222433.3415301-1-coltonlewis@google.com> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog Message-ID: <20240911222433.3415301-4-coltonlewis@google.com> Subject: [PATCH v2 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 --- 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.598.g6f2099f65c-goog From nobody Sat Nov 30 03:26:59 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 272151BBBE6 for ; Wed, 11 Sep 2024 22:25:14 +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=1726093516; cv=none; b=SClBBwGPEd1E6BStuOO3l8OmjXXJK24f6SS8ZQBiQJ+yq4c9Vxyh+C9JxRN0Ra3gBM/oh3RcfVVhERMpD3OAa28qLO8HaXGi5MixepiMyVSujP9+GjEQl2Hc1FdYyndSVtMl2EZY6Pw1obPbreuWzy33vq4ZKQOPTmLPDTYaz3U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726093516; c=relaxed/simple; bh=Aav80nw+Oj48/H0OfvSqZnp5S221N6H/skMuhsyP0SY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ih+xktlSv6RAQEtwRAflqyP89FVeEKgZv6rWgleyL/SY2rg45Z5+KjZysD+vDlGZiFwxx+mmp3k5G02+QIsdFQGqzfuARwtjTOVwN/rNv5oYFZ2MJODnPjcU56qu7Eog4YUojPrEyxgXitOiUV+R2Vx4dU3tw9go7n5OLvmW7S4= 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=oqaIBLh1; 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="oqaIBLh1" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e0353b731b8so799957276.2 for ; Wed, 11 Sep 2024 15:25:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726093514; x=1726698314; 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=qY7jazBJP8pJhg0f/dQ9sIJIXrzux0tRJtWLf7xpCl4=; b=oqaIBLh1F8VtMse8EnrBoVRex59kZw6XAZv2ohMMLtReSM8F2bldrwdzIfFXiNK0hL 4InH02T6Dg/wdUWkanSqAcWpeI755R6TkUUrCIgH/mFFJ+i/glt9N3ZvTlTlUe422cNv RFzN6TBQ6gf8sM3OSur9+CtTgx82aZilHRnDVQLkXRrBcea6ZhGkCWJwdWyqWMF0Op6K cokS2LfUS7ZgS8Dxkz0R/Lz5nHaZ+ttENoUBCV4Eg9LR3pnh5wSOZRjHeggewpEwApKY s2mbThuBr6bkzY4F5TIbjhHihVih/2uEPNsfAH9kKjxm4sxl+0qJiy/z3uLTL3PbgvBI YjMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726093514; x=1726698314; 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=qY7jazBJP8pJhg0f/dQ9sIJIXrzux0tRJtWLf7xpCl4=; b=QSF3dKcEAZSl1TD32IksdKi0XYRspbp0RFIMC19OrfAiCeetb62MXnZ0U4qDRclMNg G9SL+QWktLq7FwHwq1ZmkyQmc08UJZ3WW7171Gd1Kz/o4yk6jEss74Mx7MotXTzCNWnP ZFuYbzglUhWAKilWHKG2gXgz1qxsYlsmZQqBaHIkokKTNbbwJfk4XP4KvF5q6/gUxlnf MuA6BzdOG4bcpeDbTPz0JPUcYPRYqxsYsHTUKD5HLBwG6b+VNNExBqqfTysGgZr9+Oyr GtI1tbadwIIotrKoEz25p3qKNcfumpm0rxsWY4eIyB+ygeizZHTmESFs18cLcna/3Dwd NeQg== X-Forwarded-Encrypted: i=1; AJvYcCWtVut11hfaG58YwNBgs3bSbLGiizwZodkfox4q9dZ+2r8K2gPkyCPgJNgqLaRBX04UaEOumMRNBdTr1b8=@vger.kernel.org X-Gm-Message-State: AOJu0Yy8Vr9tCxF5xtBwtghl+8rzDRAIgNzgQ7zz3V2sEash01HLw5am RJRYzyPcfAF3DIov1/wLtFV4HdvXUCjjEGyLA/dxNF8U0pnbj2ESBR9Su4MGpVYbdXKQ+8bicgM e5bKbD4IlKDMm9OqrgBgdMg== X-Google-Smtp-Source: AGHT+IEJ4qXFa/RnEyqgs+UMl0d9RUxwmlrJg7JrBYtR4wSiyNcS6y1wcbWXE0ormIQyuX+hDspZQAPbFzn+ORG1EA== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a05:6902:27c1:b0:e1a:22d5:d9eb with SMTP id 3f1490d57ef6-e1d9db894c5mr1072276.1.1726093513931; Wed, 11 Sep 2024 15:25:13 -0700 (PDT) Date: Wed, 11 Sep 2024 22:24:31 +0000 In-Reply-To: <20240911222433.3415301-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: <20240911222433.3415301-1-coltonlewis@google.com> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog Message-ID: <20240911222433.3415301-5-coltonlewis@google.com> Subject: [PATCH v2 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 --- 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.598.g6f2099f65c-goog From nobody Sat Nov 30 03:26:59 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 16FBD1BC088 for ; Wed, 11 Sep 2024 22:25:16 +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=1726093517; cv=none; b=K1+aYxs+/hOQoltpF9TJMZJIGEN86c7desOFxNK2TZ38LKGbG2jdctixs8OJtGbGC3VYp569vKiD0FLagnwJuWAUI++lm+FB+qZlI2PuPO/OBgLnC69QmOB/uHcFUiN9KZzMaQiSaQb+0/tX/Mi3xghhvZTJqsti28FNCAZnZPo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726093517; c=relaxed/simple; bh=u9LWUfym3XyKHaJy7fqC/Vhj7o7HAbNr5zui4ChS7LE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=R6suCazbXJLCXaYfVjo1iTPhyI6Gt+S1kTdCBBb0GhxOT2CYzes4ylw9HGrIuPNL45r/UswPInCJmtv8lufZ3yIRtx9VdDh7wPiCo5bOgcMBQ1E663r07qJz2g4iflJ1Kxxc0bO6duQr8PdI+DN+s7ixqi7S5gdV7s3KIiGPIYc= 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=h3tg2C79; 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="h3tg2C79" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e1a7ef9eb78so830638276.3 for ; Wed, 11 Sep 2024 15:25:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726093515; x=1726698315; 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=anqmPTOCFLWtYH4INX466EMjOxNIdwCN/nyhNcnm/nY=; b=h3tg2C79/k5wlX4nWbFINtvN2lcwUR9r3GVeizNYjg2aNWVxB+LKZGHvHCsWPvU7SZ HPURSOJFIYO2tyctPoeQrT/z++FfdCiDD2AFbFaqTdukIDFbNg+diTbzw07zJd8FsWXL OHlsKtURoE41cUD6GpR91vxVg4lPEjz6Xxui6qTqgWQAL2lMiZvGKiw7PdVXhHu3IFjk 2MwQxNpjWyHDLJy2SAX7KAQg4/2gA6DJlOSRAK04itUjWbA3vqh6kAYp/y8wwjn//0VW hrcAv7x1ZHL8r5Z+pJvT3aYPHZY2beKfXN78mBQ9ZDNRqy2ZzQG+Q64QnbZiNNml9sK5 bezA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726093515; x=1726698315; 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=anqmPTOCFLWtYH4INX466EMjOxNIdwCN/nyhNcnm/nY=; b=rusHlWqWfPlrBdjrLZEM4ajBDI06ZO3FastVbEEK0qGTHGmjSdhLDeo6aShSOuUeto GvXBLo+TCD45ctYgKbl6y9JUkR3c0kobOyry9ZP3qEdPJIeKP2UYNbUwrbZUJ6ExAyUP yIK9LQwCVqSogm7Bm0KVa7tKTJMcDSR124Paefq8K2M6b/b4IyGJ5x5RudHdzJ5XiFqn YrYjo3LYtNK3rkQ+w79uSg6V6cFu3DFv2m55jBWxbxvx/rScwiJX6QOp3TTQNdQA7P6t HpKUAFxVYUtKs8LarQAWKAKuyMmHxa1VVN+5PM6TIftVmNvgnySYEh+NSG6mmNh5CI/1 XAIw== X-Forwarded-Encrypted: i=1; AJvYcCX4KR+heNvvLZaz4IpCaaYkl1eSerCjyudjBcRXl+I0/5ZXtWLpEGnVe1oRCUVbwPczugbbPuI3byXWCnU=@vger.kernel.org X-Gm-Message-State: AOJu0Yyk2ReskWI4RTR7D9X/COLXVtxzLJJhISDwOrEx2VFHSl+87pF7 btQIl1DP5gr1FB2Ksii4T6guSfjDxQ8PpyuNxlxwEr4AyPRP+Giv/xTWNaKsX11DxZOy48PjQ4Y 8fZZa/nU/H6i6IBNuxwWLfQ== X-Google-Smtp-Source: AGHT+IG/v34+rc6eLaOGVWlOE43Zx45msmHQv1J2ivFD+GxJdG/Q3VFoefy68ei4cpHyCypXn3PaKYm2Ons1cxS0+w== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a25:e812:0:b0:e16:51f9:59da with SMTP id 3f1490d57ef6-e1d9dc1b42emr3306276.6.1726093515114; Wed, 11 Sep 2024 15:25:15 -0700 (PDT) Date: Wed, 11 Sep 2024 22:24:32 +0000 In-Reply-To: <20240911222433.3415301-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: <20240911222433.3415301-1-coltonlewis@google.com> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog Message-ID: <20240911222433.3415301-6-coltonlewis@google.com> Subject: [PATCH v2 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 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. Signed-off-by: Colton Lewis --- arch/arm64/include/asm/perf_event.h | 4 ---- arch/arm64/kernel/perf_callchain.c | 28 ---------------------------- arch/x86/events/core.c | 15 ++++----------- include/linux/perf_event.h | 21 +++++++++++++++++++-- kernel/events/core.c | 21 +++++++++++++++++---- 5 files changed, 40 insertions(+), 49 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..5f119b9516dc 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 @@ -2974,14 +2971,10 @@ 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.598.g6f2099f65c-goog