From patchwork Tue Nov 5 19:55:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colton Lewis X-Patchwork-Id: 13863498 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B58B5D36121 for ; Tue, 5 Nov 2024 20:00:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=EPb0hqOBb6kblWxXXARI3ocpeztWq9KwTirxTPs2l4Y=; b=x/RgupM5Nm0Bsrm6Q4MqoeUNKo o/hR4SUOfUoUL9n/BHYB8Z7/6SoGJyfimzgpB63PnLIl3LU6wLXGOKVu+RLndPXuLlzhX1nuqCFTh MX4YbjLC+yecQIolOlkK9Crg6qQIkcOZZcVlr9+1bMpakPmdwEemEfM5O8rK1Dt7LUHpbwOvcL8QA ltnmcuPHoKWIXkmv7mL/geq3kSvMzZR+Oa3zRvkfCzRhLwX1Vq3Ws2h4QpLLntUHDvlORMjaPDFs+ /VKAccy6i52Nv8a0Dy8s5LeHTm+0eJPfSbjRAuhqFhCJu6NsPfJbli8kCvWLIEsq+VwJTjV7Z0+Zp 9wTKOvhQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8Pil-00000000dZQ-0i4y; Tue, 05 Nov 2024 20:00:11 +0000 Received: from mail-il1-x14a.google.com ([2607:f8b0:4864:20::14a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t8PfE-00000000cV7-0Bpj for linux-arm-kernel@lists.infradead.org; Tue, 05 Nov 2024 19:56:33 +0000 Received: by mail-il1-x14a.google.com with SMTP id e9e14a558f8ab-3a3c5a6c5e1so76049855ab.2 for ; Tue, 05 Nov 2024 11:56:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730836590; x=1731441390; darn=lists.infradead.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=EPb0hqOBb6kblWxXXARI3ocpeztWq9KwTirxTPs2l4Y=; b=LVf7hQsLmrMSD+AskhkSkN3QLEGHXA1cDzVKqRc8NN188DU9uCTACj/bPOcCoXtXET HoD4Io1EY+SZSFd7lrNuxm26A9dqS/1y2uyWJriO7LwpfApB+8VvtXtExqFO9kVzOvUu 1jUu1w3IhxjWdqOXq0vJYWl1yOSLPUjH/luiwFoEagFSBed1ubLWaKy3Sxrp0EvwRULq 17mKRyswr9s7Eyfek5SBsg4i0AQOBKIgmII5y34nqh5TfYYiXzOQBNH0auwdFOnP7NHD uDZUgZqQTWipFa7g7tmXSZsAAAPgF3QzoGUOLdE5587T/pYYlfXcVjh/AOVuJmFZ7xlU dbXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730836590; x=1731441390; 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=EPb0hqOBb6kblWxXXARI3ocpeztWq9KwTirxTPs2l4Y=; b=XdqRyV+B81xKW75sEsLGyCvqiJz68hboeW12ICUvkzknn4mCkPSQQjYwssP+eonrH3 ndgS9Rg6jyMziHDErjdC+rdWkyoChvGgFHLAjrDZpFo8jNgS0jKBcbHghdfbUkC7U32u iZ8D3ZsvQMet/VoOTEDx+YmV7s7E1ig/EieInWenoqJ4bnQe2mVeti65Rkns8KriAyQl 5LWqrRAr1o8kXqa6TDNVHS+u2yXzk5fC9GRKra0KonVDwhr75TLGLZF2hcqsXJQqetNL w211aem3qSdD2p+bcu7UtTBYam1R8OYkyEe59HhPpYdiovMSjLbzb7NPbWwV75+kjRMA FoEA== X-Forwarded-Encrypted: i=1; AJvYcCWGD5vlZC8u/KWMAntlY2JMpNBXDhRAF4AKja3iEMk20ZtbpJ82DcjqjakeVogDzmp8Vu+xolF9ekE5IkbtAU+O@lists.infradead.org X-Gm-Message-State: AOJu0Yxen5kWtG/4jJNcGa63uE67Nfqs9dNTC524LZZKy46O4chcMU6Z bzOwvcKN+DxbgAmBuvgnwucWtIhpQrtAh25FrZ0w+d4cZEXCNc+RsAiTVOw4uixiahbMnWmWqpr kTeMXuN92bCubrJoxzZ0Dzw== X-Google-Smtp-Source: AGHT+IHah6Nqgqq9N69ws0DKUP/HTUx1alzkcwBsGSQWk19UCQk0MEnTOVuN0lF159yK8HSXoS8zbdDz2TvwiOw9WA== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a92:d702:0:b0:3a6:ca09:6d48 with SMTP id e9e14a558f8ab-3a6ca09715emr1563885ab.2.1730836590276; Tue, 05 Nov 2024 11:56:30 -0800 (PST) Date: Tue, 5 Nov 2024 19:55:58 +0000 In-Reply-To: <20241105195603.2317483-1-coltonlewis@google.com> Mime-Version: 1.0 References: <20241105195603.2317483-1-coltonlewis@google.com> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog Message-ID: <20241105195603.2317483-2-coltonlewis@google.com> Subject: [PATCH v6 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241105_115632_366285_E8167334 X-CRM114-Status: GOOD ( 11.51 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 Acked-by: Will Deacon --- 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 = (__ip); \ frame_pointer((regs)) = (unsigned long) __builtin_frame_address(0); \ diff --git a/arch/arm/kernel/perf_callchain.c b/arch/arm/kernel/perf_callchain.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 *entry, 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 = 0; - - if (user_mode(regs)) - misc |= PERF_RECORD_MISC_USER; - else - misc |= PERF_RECORD_MISC_KERNEL; - - return misc; -} From patchwork Tue Nov 5 19:55:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colton Lewis X-Patchwork-Id: 13863499 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EB120D36122 for ; Tue, 5 Nov 2024 20:02:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=lW2hnUZ08ySVaaKZC/4iu7cWmp25J7OzTnpA90UyACk=; b=LYFHPqkuipp9ifEnAqL7F6wcEQ ZAGHD4hkaL8bKaV7Ibi6GGksw/adQFq5sHnd4VoO9NZBCRH9l4uMuWdHURhRQNQyXxGlbfxk1/HR+ LTOayGqJ1s+Gb4ujH4TiC1Cy5EXTNq8Cz1YPdbi6/vTRCfsCSdeQVj2fSn0kNuXP1S46sd3CnkTPe xQirlwMGcEHqIKhDXOb4SlDhgytWbCXtJr+aeXZDAWthhtjcfrgQnBfHNprhia628x7jLn+f1aJTR Ioxor5Vx7RUruga0dWs4syDfDN9buvQW0Yq2uvkFfRORsk6CrIgqIQCIppmfzZ1REtvXrEn67n6v1 AxCug0DA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8Pka-00000000e0f-0P0G; Tue, 05 Nov 2024 20:02:04 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t8PfF-00000000cVR-1jCV for linux-arm-kernel@lists.infradead.org; Tue, 05 Nov 2024 19:56:34 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-6ea82a5480fso65075087b3.0 for ; Tue, 05 Nov 2024 11:56:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730836591; x=1731441391; darn=lists.infradead.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=lW2hnUZ08ySVaaKZC/4iu7cWmp25J7OzTnpA90UyACk=; b=LtCEaolR7D3CF7YJdVK/bT5TZZO1yypqXn5CCaSeLluvAanQCsk+1ckN7H02w6wOsi F4QeOUd6eXyW530X5og2qcsEgxKExFqZcD7B4g2lHCLMK5E1C3MEH3w082XdGz7jEAN9 xGgpwcCTjxxprHdRiLyM7Vyubrfd1g7XcX1pz6P6a4fJOfyJOAF7httzb+cmfa2CTOim MkNDBjZ5AQe5twbdLCPMZZhhKvhboZa33qhfvyyJIXcOq0iVha7WzpB4HR5zHMmjWoCu rX161E6l5oGCZeAqVwqO+Q/3UOpczyEgb9XBvlgjKP/AukMIrcGvOSUhUtY0WSRWDIoL rfkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730836591; x=1731441391; 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=lW2hnUZ08ySVaaKZC/4iu7cWmp25J7OzTnpA90UyACk=; b=CtuRsdBqmlMs+IA+nsxxsILv7FKIDF8Jq1nIXTbVMEhnAfrUu+QfT0GHF7UNi770a1 JjJ4v7ua+vUfMTTplp8Hn9KrIplTX42iQAeK0ZVx2b/uPNHXpjCw+dCq+cu+DHpsT7DB l97pOu0UnK8JwmxVFiN7O5rztbXFcR1Mu8X95aKCj3vJeCHMmxbKXM7kWQd3QOIHOjYT 6fyWvXa9ff27QbV1Xm8LpJuXv/F7TIOSM381soA7Gjfd/C/sdJGyFlIhQ3lde6uEAgbb 65Bhhnb9K+/o0aa6pbgEDi2iOHKUVm+0LeDW57WQDB358gFAiB+uWu0ynRRHY62a09aV EI+Q== X-Forwarded-Encrypted: i=1; AJvYcCXLI/vZ8rwgQ7El2mF9Epsyl+TQvoY4ZgflVo2XcHYmVgz/ZbUkpZQPd7aCLSsvKAO2SoWNnRYbipnJ8dWeEIgR@lists.infradead.org X-Gm-Message-State: AOJu0Yw2CG4HAywabIY4u5mMfX0jjN7NMopV/sW6iR4msKTyimcKEYE2 ccIuit/urwJZkZ9Svn84n0aLGphkgsJNV8m7lSJB6320G0B4wLgo2ex+RoRvNRjhJbDQxkRCe3l A8fQEHJ6/VH5Oo2YQgsWezg== X-Google-Smtp-Source: AGHT+IEiTrVSWVdbBHruxNgcosSV6u9mlFrXHqLs4GJ39SmBXoHMQUH72lnNFzg3J+Krrje+KBYNpkQ7INqPc+ge4w== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a5b:bc7:0:b0:e16:68fb:f261 with SMTP id 3f1490d57ef6-e33025817a8mr11774276.5.1730836591154; Tue, 05 Nov 2024 11:56:31 -0800 (PST) Date: Tue, 5 Nov 2024 19:55:59 +0000 In-Reply-To: <20241105195603.2317483-1-coltonlewis@google.com> Mime-Version: 1.0 References: <20241105195603.2317483-1-coltonlewis@google.com> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog Message-ID: <20241105195603.2317483-3-coltonlewis@google.com> Subject: [PATCH v6 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 , Thomas Richter , Madhavan Srinivasan X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241105_115633_501037_64022E10 X-CRM114-Status: GOOD ( 20.22 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 Acked-by: Thomas Richter Acked-by: Mark Rutland Acked-by: Madhavan Srinivasan 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/perf_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 @@ #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 diff --git a/arch/arm64/kernel/perf_callchain.c b/arch/arm64/kernel/perf_callchain.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_ctx *entry, arch_stack_walk(callchain_trace, entry, current, regs); } -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 *regs) return instruction_pointer(regs); } -unsigned long perf_misc_flags(struct pt_regs *regs) +unsigned long perf_arch_misc_flags(struct pt_regs *regs) { unsigned int guest_state = perf_guest_state(); int misc = 0; diff --git a/arch/powerpc/include/asm/perf_event_server.h b/arch/powerpc/include/asm/perf_event_server.h index 5995614e9062..af0f46e2373b 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); 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); /* @@ -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_arch_misc_flags(regs) #endif /* diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.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 *event, 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 = perf_get_misc_flags(regs); @@ -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 = mfspr(SPRN_SIAR); diff --git a/arch/s390/include/asm/perf_event.h b/arch/s390/include/asm/perf_event.h index 29ee289108c5..e53894cedf08 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, /* 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_arch_misc_flags(regs) #define perf_arch_bpf_user_pt_regs(regs) ®s->user_regs /* 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; } -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 *regs) return flags; } -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 65ab6460aed4..d19e939f3998 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -3003,7 +3003,7 @@ static unsigned long code_segment_base(struct pt_regs *regs) return 0; } -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(); @@ -3011,7 +3011,7 @@ unsigned long perf_instruction_pointer(struct pt_regs *regs) return regs->ip + code_segment_base(regs); } -unsigned long perf_misc_flags(struct pt_regs *regs) +unsigned long perf_arch_misc_flags(struct pt_regs *regs) { unsigned int guest_state = perf_guest_state(); int misc = 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; }; -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) #include /* - * 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 = (__ip); \ diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index fb908843f209..772ad352856b 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -1655,10 +1655,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); -#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 df27d08a7232..2c44ffd6f4d8 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -7022,6 +7022,16 @@ void perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *cbs) EXPORT_SYMBOL_GPL(perf_unregister_guest_info_callbacks); #endif +unsigned long perf_misc_flags(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) From patchwork Tue Nov 5 19:56:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colton Lewis X-Patchwork-Id: 13863525 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 38AE4D36121 for ; Tue, 5 Nov 2024 20:03:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=sW1pAHD8RX7fvQhBgDL/ivZoJ4MMiFBudzlwbhbqZhM=; b=Bm0faihHkWQG6A2zClIlZ+/Gdt LObfeVcTJZiNua0wVXKtJo9L0rpjiH0+kbmpjl3DN7O2u/2m5f85QyhKYV0J1Jbfu8Nny+RCNIHZq G+4Wv22HX6qPLIoa6RhNznDALUEcW9VNTlONKhf7ryvNeWXA9vjZ1x0PzAxKK2qlQAeigvg9Op9+V KuUq+SkWUrKdzyggJvgGgW2Ftg7IxOS6H7H7p2JRYjKG7klGmXIjlmEaD73ps+ax0iQ8i4rFoTCLq 3JasBaZG5mPX2/R1r5nybthgv58fQ6xZ2fxJEuuymdQdiJ9B+AIRKz1NuDMlGzCt0PFw6Vjnnt33X UucJWqnQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8PmH-00000000eIT-24KU; Tue, 05 Nov 2024 20:03:49 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t8PfG-00000000cVn-1jWZ for linux-arm-kernel@lists.infradead.org; Tue, 05 Nov 2024 19:56:35 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-6e38fabff35so103802877b3.0 for ; Tue, 05 Nov 2024 11:56:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730836592; x=1731441392; darn=lists.infradead.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=sW1pAHD8RX7fvQhBgDL/ivZoJ4MMiFBudzlwbhbqZhM=; b=NI5klDlu+GAhWUq3wX5doN7MqFWuF5dmZj5O5N7E/Y5LKHaYQmUxDThmRr+t/2bMoH 0HlsByLQh3mFLAJMP3KFdrm0m5YjFVajNKOvx6h3qrSHC1ZJoIC0AcJpKEzuvg9u1jTX bUtiiBCvww2NNTx89snwvpfiohj7sjCkZ+4bhFMvq7bN0e3f66PC7kwz+wVxy399zkxo ZG+PL2y9d3EgmEKvsGa9C2rNpgt5oUOUg1FUcFH5pXWApTjTfkNjdUpAuOhoR6Wi66zo ooQ6xl66GBbXSwILLm+r50mykuRCywvwaEorEF153hIY7NVmrRxkGmTw17OXGr+MksiH yKfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730836592; x=1731441392; 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=sW1pAHD8RX7fvQhBgDL/ivZoJ4MMiFBudzlwbhbqZhM=; b=X+/GjQ7g+1k8GHqZtN7jSeLuF47wAj+2a5vxIlTO7ywSfKBCchA9HThoM3nUSQAWAc gbdbzRQNIoqtiEzpr5MRtC/2Z4u9QHI6RNFb4x7e6lp2o3fs+l8PWUF7DEl3D7ZewSp7 +JYYAW8+qpDAXV/3I1pUoxVarLDrc8tSpp27S4Ds5j73ctcUErqYtwH+ptWnAL2sjmZG 35Ovccjroj/T8dutPMu6+qp+3Pslsg7i3VDhn59/Y5TiyG4clP3/ZBW474YvUvA2D6i4 4cGnPoYHIeTnQoN18sVMqXJPi1byxkvDoyn9oeloit+o8PSKmgbHSmesLzXFwfleTI1P fwuw== X-Forwarded-Encrypted: i=1; AJvYcCUGUudpgRBlPZ9RIC4RXUi8jSHoIUn1bOjYPGKFgmdcVEINFCkTcTfyA1fhV0CP6F7P8Fw0zefJS2NkliXIBc+1@lists.infradead.org X-Gm-Message-State: AOJu0YzKjr4OkLNwruTU5fGTrpnBiiUCOYJvV4GlI4ZZsFCeicub75E5 BimAkRYbE+2+rLY1vI52bUhDVBVTYbO6Lzl/zi9EphjzIaVDcfExhnhcqo9CzGA+xjQWieN68RN qNxXSQJ4smNHijTJOn4FZ5w== X-Google-Smtp-Source: AGHT+IFe5esZfmV8PpNtTKhf67GNSznritdlgCuivBreGx7Lwrw/eQ/PIB8HLPh/Mq6jxCM85J+7ZrWnfVuJw3jbsg== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a05:690c:4489:b0:6db:c6eb:bae9 with SMTP id 00721157ae682-6e9d898f08bmr17263797b3.2.1730836592357; Tue, 05 Nov 2024 11:56:32 -0800 (PST) Date: Tue, 5 Nov 2024 19:56:00 +0000 In-Reply-To: <20241105195603.2317483-1-coltonlewis@google.com> Mime-Version: 1.0 References: <20241105195603.2317483-1-coltonlewis@google.com> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog Message-ID: <20241105195603.2317483-4-coltonlewis@google.com> Subject: [PATCH v6 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 , Madhavan Srinivasan X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241105_115634_535665_61EE23B5 X-CRM114-Status: GOOD ( 13.66 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Make sure powerpc uses the arch-specific function now that those have been reorganized. Signed-off-by: Colton Lewis Acked-by: Madhavan Srinivasan 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 *entry, struct pt_regs *re lr = regs->link; sp = regs->gpr[1]; - perf_callchain_store(entry, perf_instruction_pointer(regs)); + perf_callchain_store(entry, perf_arch_instruction_pointer(regs)); 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 = 0; unsigned int __user *fp, *uregs; - next_ip = perf_instruction_pointer(regs); + next_ip = perf_arch_instruction_pointer(regs); lr = regs->link; sp = 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_ctx *entry, struct signal_frame_64 __user *sigframe; unsigned long __user *fp, *uregs; - next_ip = perf_instruction_pointer(regs); + next_ip = perf_arch_instruction_pointer(regs); lr = regs->link; sp = regs->gpr[1]; perf_callchain_store(entry, next_ip); From patchwork Tue Nov 5 19:56:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colton Lewis X-Patchwork-Id: 13863526 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CFAFFD36121 for ; Tue, 5 Nov 2024 20:05:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=g+A/E6dh30+B+DuVgwcV18/qvNhG5j8MCeVP9K0OnPU=; b=jdP848FogDoYDbtAAJmorOJq77 LPtjrs5t7rGC7MYPqQlS0LVJTSHrjowIcsAcRRESNYW77JyTSSwlKpxgblIV4qbtBQpmx3wtfGKox Q24GeNEQks0ne00S6WhHRHN6yCLE0/utANYCDJlaEdv0LBPPI3QnIDo8KXISRVte/PUDEeE2aTncA xzSaiXCg68EWPxYsP7t3y/PiLSq35hlukmFh0CCELkK8mNKARmPjL1AaD8EyBjAfpyQkzg5XKYiGx ha/SA1mgDY2T3KxaRZ3vA5fTfihsz/HMPlqmhBRxWiP0AtkCZ+AmBopmdn0o4PgjNoTWIFjv0c/pe nbsxnlvQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8Po6-00000000exT-28Ol; Tue, 05 Nov 2024 20:05:42 +0000 Received: from mail-io1-xd49.google.com ([2607:f8b0:4864:20::d49]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t8PfH-00000000cWO-0rwN for linux-arm-kernel@lists.infradead.org; Tue, 05 Nov 2024 19:56:36 +0000 Received: by mail-io1-xd49.google.com with SMTP id ca18e2360f4ac-83aa904b231so626142839f.1 for ; Tue, 05 Nov 2024 11:56:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730836593; x=1731441393; darn=lists.infradead.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=g+A/E6dh30+B+DuVgwcV18/qvNhG5j8MCeVP9K0OnPU=; b=dlXZQpe/iiewsrMCdl58q/gqSbFQs1ui/bd0lRmYtoqnX/OQk8HOESaEq4kaEhBzZv 71fIWlk6gpDqvaBhuOCEJ3/qfMv/8gq+FgbXIuzXahtngAn0Ocof42RBq5wbKunc3rLQ Fo3dUA3VJMwSHLuopuj0JjLzKiljPoNdMEpQZuuC/QXn6DHkEfl2AJF9F/jm1DauN5DG gkCYbozMpYWW8bW+HLg5+kT2qWYx9/+Xo0icBeQ9FmmjFBT4GU4Q4cFcYu4WZxbyY3ne 40WRYEW4Yi9MCznn+riSJTojkH4M4Psop1TVOYiabB4AD1bIPqygrJCHxrf8KxtquIu6 2SnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730836593; x=1731441393; 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=g+A/E6dh30+B+DuVgwcV18/qvNhG5j8MCeVP9K0OnPU=; b=jZ13/TTIdW8YoBj9/xwlgrcICKyzkuWeJhV9mimOWh84yCY2MqB+ub9e1QA704gHpB W6GBW5C/zWlBmotZ18s4KFWAOJvd4/DvE1+4cQehdjfJG5l/gO5/tuhYTi/RZdqCGzwB W0wwjeOoWlfxRRkgjgydsYjS0kq42CZqAvJNSYG968dym/J0HrhzjfCfX0C6VOpzh+5h 3V0ujcwts4DifDYM3fGYc97C+Y7yvp6rNBcJWc2I9nuE5C9gyY9rdV2YEaUjwJbhteHZ u8lcjW8zQX16dlUeJ+DjB/5m8PLhfX9iKZ+8q8+WQAcbWrsXFRoUa+GgGrzMj2oO8HnV Heuw== X-Forwarded-Encrypted: i=1; AJvYcCU09ZlL2Lx2RcKHiHxefqfBJ5bDw+Ktu0YowsfY1gNTr8k/b1jS9/6j0v4j/aiZwN5txkGPtE9jKgtYtBDIUmrV@lists.infradead.org X-Gm-Message-State: AOJu0YxFJWwv8E2wmiJKqa+EyxcZoCkmpdIlwUeBn64C/YuK2eiYTLSe hJnpY4ZJOwbO4Cx880jxQmG+3BgjjQP5jTWoB5xjKv8NoLaD0QsJuaCxabp2wCFKtD4rO28ih7W aEE7uvUrNIdwOKey+UcIBMQ== X-Google-Smtp-Source: AGHT+IHwq3hF4ElsT4RerqS5KSh2j8l+o/SOi33LC2KdnD9j/u2Nkb6pf++GYEETuSfSuC1nI4Yu4HiUAJoPcaH3GQ== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a05:6638:210d:b0:4db:e5f0:ceaf with SMTP id 8926c6da1cb9f-4de0257ba11mr134988173.0.1730836593213; Tue, 05 Nov 2024 11:56:33 -0800 (PST) Date: Tue, 5 Nov 2024 19:56:01 +0000 In-Reply-To: <20241105195603.2317483-1-coltonlewis@google.com> Mime-Version: 1.0 References: <20241105195603.2317483-1-coltonlewis@google.com> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog Message-ID: <20241105195603.2317483-5-coltonlewis@google.com> Subject: [PATCH v6 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241105_115635_344684_F0922E76 X-CRM114-Status: GOOD ( 15.44 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 d19e939f3998..24910c625e3d 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -3011,16 +3011,34 @@ unsigned long perf_arch_instruction_pointer(struct pt_regs *regs) return regs->ip + code_segment_base(regs); } +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 = perf_guest_state(); + unsigned long flags = common_misc_flags(regs); + + if (guest_state & PERF_GUEST_USER) + flags |= PERF_RECORD_MISC_GUEST_USER; + else if (guest_state & PERF_GUEST_ACTIVE) + flags |= PERF_RECORD_MISC_GUEST_KERNEL; + + return flags; +} + unsigned long perf_arch_misc_flags(struct pt_regs *regs) { unsigned int guest_state = perf_guest_state(); - int misc = 0; + unsigned long misc = common_misc_flags(regs); if (guest_state) { - if (guest_state & PERF_GUEST_USER) - misc |= PERF_RECORD_MISC_GUEST_USER; - else - misc |= PERF_RECORD_MISC_GUEST_KERNEL; + misc |= perf_arch_guest_misc_flags(regs); } else { if (user_mode(regs)) misc |= PERF_RECORD_MISC_USER; @@ -3028,9 +3046,6 @@ unsigned long perf_arch_misc_flags(struct pt_regs *regs) misc |= PERF_RECORD_MISC_KERNEL; } - if (regs->flags & PERF_EFLAGS_EXACT) - misc |= PERF_RECORD_MISC_EXACT_IP; - return misc; } 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 { 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) #include From patchwork Tue Nov 5 19:56:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colton Lewis X-Patchwork-Id: 13863527 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F15B2D36122 for ; Tue, 5 Nov 2024 20:07:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=m4LSX7jp2Qk0unPMxnSvbmTUvnRmwzrHBbuAe/XVNyI=; b=fBc56j2pPOykrd1VJK5iXBxkvo ypwJwzW/q2jduE8qUBCsR5lUoeKp618OMSfErtLhLk2jESd+imF2dhATzFHifojzGXWfsbtEBpSH4 IatMeK0+vJrsSd0kEOrPZEElpiNUYU+B8rXkX3BrrUSQ7UIzyp7LbsyEfOmeQE46ILe+5gZEoCk2u XPRN2jR2rWUw/e4D2VyEPgXud/2Mzz6rJz1rEzUNNwArvqv9FQdTvVoIQuxaLKyc8rowe+rKmz8ov paUKPz8bVLY2fClcoaL3boaDhlvyfJa2xh2Jb2s1IXvtULPkjkGfBZ2O6kPPcvqlHo355YNzzf9q7 IL6ES0zw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8Ppv-00000000fdU-13CD; Tue, 05 Nov 2024 20:07:35 +0000 Received: from mail-io1-xd4a.google.com ([2607:f8b0:4864:20::d4a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t8PfH-00000000cWw-2vvR for linux-arm-kernel@lists.infradead.org; Tue, 05 Nov 2024 19:56:38 +0000 Received: by mail-io1-xd4a.google.com with SMTP id ca18e2360f4ac-83ac1f28d2bso613258839f.0 for ; Tue, 05 Nov 2024 11:56:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730836594; x=1731441394; darn=lists.infradead.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=m4LSX7jp2Qk0unPMxnSvbmTUvnRmwzrHBbuAe/XVNyI=; b=VX1I5B6w6+T0exDBBqPpSMP5lPFqq7EnMXF4e6BRQM5gnj/ErVxny2qRDE2e1CQaxT kRqix4BvtxSVEYSRrARhmLKJlzEyrAY7CLHrAwUbxwAQyT5oX52aiKD7cnJLT1he0eRx Y8Cy6vg5VVvQq6LPmMG4xXYPrLv/RPqFpq4BArjYs9N0O4WMnOUqfmmOSUj+FwczH7T4 FRwgmRRdNNCOtp5SgYeg443Z0B0EOHnnQHzhhoNr3LlPTkbetTRtaOxzX7uxVcJtwbDa CGJ2ZxcI2G9Yq37AJaJZJIY0DRxr8EZGWeMYvf8x4BODfMUpgqEqPNsEnX9Blo63DS/e yiGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730836594; x=1731441394; 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=m4LSX7jp2Qk0unPMxnSvbmTUvnRmwzrHBbuAe/XVNyI=; b=F3P9UkiIYkmgcleeNwwLp1wn4ofj+8kc+Lrn/3fbW2uLJTMHs9yMhvNcHYKrfI7nJ/ EUHdtln2QXZJZ9YfM9k47ENsw95f4HV+zwiuwnnGxsN226R36Hs0H2hVzCNN/TwwzTGA X9oCOA4VeHyrgmNaAmaqxVJ7bvDB5gYUHmaC7mZ+2HMwL1F4X/ipUfVwZY8UsxVLFyK5 Qr0S/JhlWeHsZUZKEpyMD3Jd4sCgF0p7qfjH1V0BxiOVwzEm7pLBaTssOxbslE2Y3UqN VgG8OUqf51tW5OqbfKm9Gx5u9gWvFvgS03yyalMv/mMz+W4W7lDJPrbcgUQlq1lU9nKX rYOw== X-Forwarded-Encrypted: i=1; AJvYcCUiWo/6eHnfjx7eUHpYycL2nGHV1jYiYaOFjkVOIoUFjah5WuGM8ardMFX0eRmXjKtpxNvS59iqbQLLAb08xn6R@lists.infradead.org X-Gm-Message-State: AOJu0YxwZyRvUO1PdpET3KGKixZCd2OA4BUYAp/6OAWFXQPKjkb58rBE rFfToVdSZMnkgUtzGofa8uOPpHhn/p23nMiKUgNnmQVm6iihA1/xChHcgSPxeCSEu+7pZgIYom1 40sHsRTWnEV/IzKThQR5s0w== X-Google-Smtp-Source: AGHT+IGFWv6Kn3TvX6dXV3OFqthDQLbL+dvhQJb9vkUUge7jztFf2TETEHNZy98hndWREoqhSt0rcXIvqTH5LIwoGQ== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a05:6602:3f81:b0:82d:821:96a7 with SMTP id ca18e2360f4ac-83b1c4c870cmr11455439f.3.1730836594061; Tue, 05 Nov 2024 11:56:34 -0800 (PST) Date: Tue, 5 Nov 2024 19:56:02 +0000 In-Reply-To: <20241105195603.2317483-1-coltonlewis@google.com> Mime-Version: 1.0 References: <20241105195603.2317483-1-coltonlewis@google.com> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog Message-ID: <20241105195603.2317483-6-coltonlewis@google.com> Subject: [PATCH v6 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241105_115635_860352_58BAF73B X-CRM114-Status: GOOD ( 21.30 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 = 0. This way any host-only events with exclude_guest set will never see unexpected guest samples. The behaviour of events with exclude_guest = 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 Acked-by: Mark Rutland 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/perf_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 #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 diff --git a/arch/arm64/kernel/perf_callchain.c b/arch/arm64/kernel/perf_callchain.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_ctx *entry, 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 = perf_guest_state(); - int misc = 0; - - if (guest_state) { - if (guest_state & PERF_GUEST_USER) - misc |= PERF_RECORD_MISC_GUEST_USER; - else - misc |= PERF_RECORD_MISC_GUEST_KERNEL; - } else { - if (user_mode(regs)) - misc |= PERF_RECORD_MISC_USER; - else - misc |= PERF_RECORD_MISC_KERNEL; - } - - return misc; -} diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index 24910c625e3d..aae0c5eabf09 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -3005,9 +3005,6 @@ static unsigned long code_segment_base(struct pt_regs *regs) 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); } @@ -3034,17 +3031,12 @@ unsigned long perf_arch_guest_misc_flags(struct pt_regs *regs) unsigned long perf_arch_misc_flags(struct pt_regs *regs) { - unsigned int guest_state = perf_guest_state(); unsigned long misc = common_misc_flags(regs); - if (guest_state) { - misc |= perf_arch_guest_misc_flags(regs); - } else { - if (user_mode(regs)) - misc |= PERF_RECORD_MISC_USER; - else - misc |= PERF_RECORD_MISC_KERNEL; - } + if (user_mode(regs)) + misc |= PERF_RECORD_MISC_USER; + else + misc |= PERF_RECORD_MISC_KERNEL; return misc; } diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 772ad352856b..e207acdd9e73 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -1655,8 +1655,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); -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_regs *regs); +extern unsigned long perf_instruction_pointer(struct perf_event *event, + struct pt_regs *regs); #ifndef perf_arch_misc_flags # define perf_arch_misc_flags(regs) \ @@ -1667,6 +1668,22 @@ extern unsigned long perf_instruction_pointer(struct pt_regs *regs); # define perf_arch_bpf_user_pt_regs(regs) regs #endif +#ifndef perf_arch_guest_misc_flags +static inline unsigned long perf_arch_guest_misc_flags(struct pt_regs *regs) +{ + unsigned long guest_state = 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 2c44ffd6f4d8..c62164a2ff23 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -7022,13 +7022,26 @@ void perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *cbs) EXPORT_SYMBOL_GPL(perf_unregister_guest_info_callbacks); #endif -unsigned long perf_misc_flags(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); } -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); } @@ -7849,7 +7862,7 @@ void perf_prepare_sample(struct perf_sample_data *data, __perf_event_header__init_id(data, event, filtered_sample_type); if (filtered_sample_type & PERF_SAMPLE_IP) { - data->ip = perf_instruction_pointer(regs); + data->ip = perf_instruction_pointer(event, regs); data->sample_flags |= PERF_SAMPLE_IP; } @@ -8013,7 +8026,7 @@ void perf_prepare_header(struct perf_event_header *header, { header->type = PERF_RECORD_SAMPLE; header->size = perf_sample_data_size(data, event); - header->misc = perf_misc_flags(regs); + header->misc = perf_misc_flags(event, regs); /* * If you're adding more sample types here, you likely need to do