From patchwork Thu Sep 12 20:51:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colton Lewis X-Patchwork-Id: 13802675 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 1FB03EEE25C for ; Thu, 12 Sep 2024 20:57:15 +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=3HOlQ/b1Vqnby1HRrJAa+4JPh1tcBF4UxpW0vveqy4M=; b=EC0vpNhyv6k70QictcFSSc+VCq 1HDV1W5cLII9sXZuwcbRpnFhky7FowATZpiaNQHu6OGjV7vhoKm9V2iJBI8Bt2eiZ9Ng8pvJybGDB hpDbh4bzEl5CRy8Hq4Dt0UCAz6+eBINxzZoWx7UPUS2ripqI5re0nfwgwUDwAdzz54hE1MMgcJ3p4 OsvJbSdOlOd3IVToSLE2jO6vhG/pS76AktGc8riqja7jSLdcofFbYzEY7uJUTP6PfQ8NEOIzw1EF0 xe1MTo3KqaiA/6KI3gCX0gajQNNxlwHWAkyDDqn/WBoFff2v6ZKZf5UHnRqm0rPcnxBnJsMqo5eCX gYuKt3gg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soqsC-0000000EEJC-0hGz; Thu, 12 Sep 2024 20:57:04 +0000 Received: from mail-io1-xd4a.google.com ([2607:f8b0:4864:20::d4a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soqmz-0000000EDBk-3Rt1 for linux-arm-kernel@lists.infradead.org; Thu, 12 Sep 2024 20:51:43 +0000 Received: by mail-io1-xd4a.google.com with SMTP id ca18e2360f4ac-82aa67b1101so172609239f.1 for ; Thu, 12 Sep 2024 13:51:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726174300; x=1726779100; darn=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=3HOlQ/b1Vqnby1HRrJAa+4JPh1tcBF4UxpW0vveqy4M=; b=JcBEMjPYt7CPk+p6dd9yHo6M74P7TQAvjiQlkqeZSJaG0vSpA8VgVRn6XHnB316ZGl 30/fx6dVnLszpLLPEI6RjeAveWbZaEZCTBcW/lZXL0Iy3CyGUJzmXj8Vwgfk9DfHXYjC 4/vgXnPW5AOKf4LxJS1Qw2Ro43kshoP8777ZJBbknmEf5kaU4e53idNHxGequj2mbI92 qq/i7o8Z9fGVdAviq+U4cGZDsbcyiWDKBxVi/KU7eh/5pD6TdXks6eaymKCAlCHeRkx3 rjy4fTvrpq4rKsLuU0e3Urjo0y5bl6/VsuNEcEFw96wDU4e03sHtJ/bn5NQTjQZeKdKT cnLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726174300; x=1726779100; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=3HOlQ/b1Vqnby1HRrJAa+4JPh1tcBF4UxpW0vveqy4M=; b=BqJlwpOwdT5S2yQYs7Q+cATqEGKZpuQfQCpncWmeh1daNmy1LL2JaLyaovKQAmwmQp 3OJBeoRHt/2D5AJVrpcXLxG1Lz8ZDvo0CcSIICniYYYLZwhS7Hds8T6HVWDzrarwJuC8 7BEGuPtQHqosjwPFsMWuB7dy4F32JLa6ROcniL4PUEYTc/kIwqbbC8bfR8HT87CPyaL1 TwBrY3ROOeEWAwEiRtZX39+qVuqxLpJWtat5RQ7ku44IDjr2T2QKh4UKSv7rp9mxWPFv qbmAbTwj7+RWqVC+8rNfCBsirGZoJSvzgjCDFFkSDFGCUf7thz0+iOY4EV/3AT0fQE3z rs7g== X-Forwarded-Encrypted: i=1; AJvYcCXplvWv8P1c2Gl0nMKuMEaKiTNrkIadt20EPdgixcFzPhIVoFp3RGRBfbm3DlbJqbqhNUOsLj4UO882BDXFimJQ@lists.infradead.org X-Gm-Message-State: AOJu0YxCoUsN80iWqw2DtCNPR7jPle0aVnTdMPBOfbMC3HwEBcELeswG +e5DQsSiqlf+LuggCUBUAfyMtJf0brRYOjB3iGxKp8xm4xabevzCSA230G1Bj54Zp4rdI/K4U82 zB/l/2a6SLfcrwGgDZunwvw== X-Google-Smtp-Source: AGHT+IH+tyLe1qQliN4X6ik9ZMj1aIgWQ7X0DXUSN8bntx8eM08UGo31hDfdaqtl4MXbxod/0+xFT0h7PePUGuXbpA== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a05:6602:2d86:b0:82c:eb15:1aae with SMTP id ca18e2360f4ac-82d1f8b0c0amr3300039f.1.1726174300197; Thu, 12 Sep 2024 13:51:40 -0700 (PDT) Date: Thu, 12 Sep 2024 20:51:32 +0000 In-Reply-To: <20240912205133.4171576-1-coltonlewis@google.com> Mime-Version: 1.0 References: <20240912205133.4171576-1-coltonlewis@google.com> X-Mailer: git-send-email 2.46.0.662.g92d0881bb0-goog Message-ID: <20240912205133.4171576-5-coltonlewis@google.com> Subject: [PATCH v3 4/5] x86: perf: Refactor misc flag assignments From: Colton Lewis To: kvm@vger.kernel.org Cc: Oliver Upton , Sean Christopherson , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Will Deacon , Russell King , Catalin Marinas , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Thomas Gleixner , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, Colton Lewis X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240912_135141_895168_2508C013 X-CRM114-Status: GOOD ( 16.21 ) 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 --- 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); } +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; @@ -2965,9 +2983,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