From patchwork Sun Dec 10 08:12:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyi Liu X-Patchwork-Id: 176304 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp6413931vqy; Sun, 10 Dec 2023 00:13:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IGD/kuV6QckIOUGMs7MPOBwNuJ1Z5CCPuBuxEaccKkhaDDtzWPkJK91Emo9oxMRdtxLfwy+ X-Received: by 2002:a05:6871:a50d:b0:1fb:648:520e with SMTP id wc13-20020a056871a50d00b001fb0648520emr3283562oab.6.1702195992724; Sun, 10 Dec 2023 00:13:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1702195992; cv=pass; d=google.com; s=arc-20160816; b=dfb3R/lF0VLENzJWQnYWqv1wmldft9tsgN8LpMJm0IqH86N3mNNquPjh/JqL0Hmfdn IPxDvzRdGZvcyB8GDTDRGRxI7GU4GjnDe4N17l5ekILl2hoe6ly5bYeLUDm8ep290jnf NpYBykSLtMhvUlMcHzUHj87LILh5YuFcF9zSfBFLAzFSCUIYqyjSURvVJyePiVv9ROr2 zzVuQAY9vWIxSBU6+yZqG4JcWt0q6tkrtn63o7wTZJSWLRpjSLcwfBc8lgAI9QQuy69T mjK8uJ79q7kXMqdUhAxa9zfe5tWH+4JKEFv++c6TDLiEZwej9pa0Lt9ry7nXff6Lh3K9 TXUQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QPuHegOvjI1Wqy9bawitz85TcVTd7dRsokA5lEbAaHg=; fh=HIpGW3XNt20YYDdrqGWTdutDMTXUX2EnMhGwR8EwV4c=; b=iPLc49hHOsIs2XB63YefJpRjqWZvPQHD+OYM8gYIGFXQBH8zZ0oHKuRlQoTpbJnbVT MPYl5tSRwRSksPldoCok1NpRQzvkY2aobdAGf8FTyQOQ/BBJ7W+EBF4lVjeiGU0s4kF0 amIYBHmYZDdWX6U7P93nEb6qJPq9qfjYJfr5yJy0xbq5qbrHJpzqRSCA//buDLTYlhJP n3BNnPKeilEhHI6geWxh5cxxDVYkeHfmQzcX0DkVxJcZFFNpM75glix63+Mb0MwEngPi fdav6HgxhqcqAxOn8Ynlel0L8kmm+5tJfyJslgc8nqDIsRDrH3hQnPmfwdr4lzq3LEqj f+bw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=pR+oypzw; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id bw9-20020a056a02048900b005c674eb1cb4si4270999pgb.477.2023.12.10.00.13.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Dec 2023 00:13:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=pR+oypzw; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 71A648087214; Sun, 10 Dec 2023 00:13:08 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231653AbjLJIMz (ORCPT + 99 others); Sun, 10 Dec 2023 03:12:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229482AbjLJIMy (ORCPT ); Sun, 10 Dec 2023 03:12:54 -0500 Received: from AUS01-SY4-obe.outbound.protection.outlook.com (mail-sy4aus01olkn2175.outbound.protection.outlook.com [40.92.62.175]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06A9EC5; Sun, 10 Dec 2023 00:13:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ksGonCfeaPwR6l5GxKxoTf6pnuz1Bjt0wtGjUOpjJf6cj4uLUkoo7i9+iZU069MuRND+1EMuEymxCokQ3aV/PXa7nFGpKj2mTN1fYNx4U9fI7E89R6P8RQA936lUW8mjzyV9LYXLfc0+yS2lAgzVqQnKUtfVHwFrSKDQhY4KXs5wwj+zzsDHpa8/zxBq/99Z+FqKs/+KFMFT3hF673nI5vaN+KvBNJBGKjdb42c5rm6ec0PiP7lTeJ3DKBupa1L+FbhF85Ocb/IIB42yOSlMwDq9YzMYUGm4apaiyWOKCvIWZHLOwR/Li/ich7zfIg7vCoSW8mz9lCoOrn90oMuNKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=QPuHegOvjI1Wqy9bawitz85TcVTd7dRsokA5lEbAaHg=; b=CJJHfaihp31VcOb8dRdNImfqLJftgWnv8kkScbTIFaeSvgoh1/avnwQx38q+XkMMXlIPwsQmV8SC3a4ORVwHUubl3+Lqbq3VZcZCiA7JRgeCKJtxr7xXxunGCUHIdXRu41CHdH2Q2eGQCozVkOTOcWlvhhDqU3jWQGDsxSBv4sPyFni+Yr2lnfcCiijbs6/UeQXVtfiP9aPBmrquG0pW1nTKAXcO0PIjl8OsTxcDJfnsTD18Zh4QPnE85ZKgLNr/AYpja/XXsxJFDRCokptrgEzkK+J7VX0IqspcE4Pvzytg4hMzDrlUkm/ftXOS/9Y8IjwjwgtVO9fUoXLVRDwf5Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QPuHegOvjI1Wqy9bawitz85TcVTd7dRsokA5lEbAaHg=; b=pR+oypzw3XWu2MtJ9PWqLyoJXpzYdwiWXRfzQoGX014y3p2dqrcyjSL2EBeHqLD1vEZtVAos/eVyYkRWKlWLHvsIHdv2cadY1a1AFthCw3Kddg2r+I5tnDOtdht9xAT70t3XseQXoeSjM/uWUi1gEpi9DNGJBkjSv2Hvw0+mfEhSPjcNmABUwkwai2eHlzUj9+/Hj0j5zpKMzvQCWxZefL2BKsVXtacDKYgOI+NAN24nCZyBtpWYoTfZ49y8vCgacGCBykd509lQMgjfUDjm+KxA3103CmrL2Out2aP8J2KqDVxrC7OJNBECn22Q0R+d66PnDcDgOCEU3vkmfX2EGA== Received: from SYBPR01MB6870.ausprd01.prod.outlook.com (2603:10c6:10:13d::10) by MEYPR01MB7339.ausprd01.prod.outlook.com (2603:10c6:220:15f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.31; Sun, 10 Dec 2023 08:12:53 +0000 Received: from SYBPR01MB6870.ausprd01.prod.outlook.com ([fe80::be5a:160f:5418:9deb]) by SYBPR01MB6870.ausprd01.prod.outlook.com ([fe80::be5a:160f:5418:9deb%5]) with mapi id 15.20.7068.030; Sun, 10 Dec 2023 08:12:53 +0000 From: Tianyi Liu To: seanjc@google.com, pbonzini@redhat.com, peterz@infradead.org, mingo@redhat.com, acme@kernel.org Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, kvm@vger.kernel.org, x86@kernel.org, mark.rutland@arm.com, mlevitsk@redhat.com, maz@kernel.org, alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org, irogers@google.com, adrian.hunter@intel.com, Tianyi Liu Subject: [PATCH v3 1/5] KVM: Add arch specific interfaces for sampling guest callchains Date: Sun, 10 Dec 2023 16:12:18 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: X-TMN: [QSggTfQqFdbZg1h9Gs/NfozjCC3waagQZgTkdujY8Bxzr5XF3x6M1A==] X-ClientProxiedBy: SG2PR01CA0125.apcprd01.prod.exchangelabs.com (2603:1096:4:40::29) To SYBPR01MB6870.ausprd01.prod.outlook.com (2603:10c6:10:13d::10) X-Microsoft-Original-Message-ID: <20231210081218.2226-1-i.pear@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SYBPR01MB6870:EE_|MEYPR01MB7339:EE_ X-MS-Office365-Filtering-Correlation-Id: e6e3b1ce-4bc6-4d46-15a7-08dbf957cec1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: F3LN9hyPvN0CAVmU+CwhB+XgRrUEjHa4HI1zqe9BR1NM6xasWGUEsY21KafHRI3J6udF87Jntl/23EfJtc/Opb+vhobD14RLba1BTrlHBKYOmzbqq2koxkZRQyO47EL/bpUvwwpJs82XwF97jlhkabhXYL6QpsIGVVtU9lpA10RjaSs21fXg0BN0joIj17O6dK3xewzJ3XS8prVTjc6jURKdavKVp4MtSwUkCxXYXTcfMoFlZfpAgJUcjB64nhmc4a4vVp4s0GhSDaum5OMaz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UZTS1y7nukBk2PnlNdXxQ2YuzUVRW3EjOn8p7cXE3PZgLsTX7WAMNO/yXN5SKhPqpmQH4pPQNOax0EujHor/8aRPEK47rYrGW4rIJ31MBTuFs5Xmaw/SQYDIpGTeFjal0mMrPF0F+dlkrRO5uRf9irmJz+E13bXrKIfHtxMzvAvlxzxnFAGjomXzGlLCvykaq4KEmdBJOD4PK4OM9olx8GjBypIVsNCx1CznBHZvhM5A1m5YLZyB3QC+/Gre5VNyFdhuSMQtnIVlkwigUwSf1j9NjeChFKTXd7K4/B/hPRMa7XU8bgBRxNWBvhIyMeRQ3IaVbLBcl7O734I9D0RkV4LTul6ebVJ4h9s4JtbKxCDx27lwSqItG36eMojY/u+ux7wm78BUNJbvaPx0kp/odVsYv4lI/6K1ajjmPgKAOu5ilBDYqaWRtm2FivhJo5mlyJvTy+TvaGeo9Yk3kjjWGB6HQV63LoU+oYF+yPTxyQDZIoI4os49NP8tgvMnS9fRQTXyA1cyeV1WamQW4eIXQ9SufosCwL7XNF3jSwER7xay8v8Z46Fg1kCAsjn46YpMrZcRhsm/r69oYsuiqnU5C3g/Rv2dTFAh8nf4ZuhvQKY2o X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: e6e3b1ce-4bc6-4d46-15a7-08dbf957cec1 X-MS-Exchange-CrossTenant-AuthSource: SYBPR01MB6870.ausprd01.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2023 08:12:53.2638 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MEYPR01MB7339 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Sun, 10 Dec 2023 00:13:08 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784881865247308596 X-GMAIL-MSGID: 1784881865247308596 This patch adds two architecture specific interfaces used by `perf kvm`: - kvm_arch_vcpu_get_unwind_info: Return required data for unwinding at once; including ip address, frame pointer, whether the guest vCPU is running in 32 or 64 bits, and possibly the base addresses of the segments. - kvm_arch_vcpu_read_virt: Read data from a virtual address of the guest vm. `perf_kvm.h` has been added to the `include/linux/` directory to store the interface structures between the perf events subsystem and the KVM subsystem. Since arm64 hasn't provided some foundational infrastructure, stub the arm64 implementation for now because it's a bit complex. The above interfaces require architecture support for `CONFIG_GUEST_PERF_EVENTS`, which is only implemented by x86 and arm64 currently. For more architectures, they need to implement these interfaces when enabling `CONFIG_GUEST_PERF_EVENTS`. In terms of safety, guests are designed to be read-only in this feature, and we will never inject page faults into the guests, ensuring that the guests are not interfered by profiling. In extremely rare cases, if the guest is modifying the page table, there is a possibility of reading incorrect data. Additionally, if certain programs running in the guest OS do not support frame pointers, it may also result in some erroneous data. These erroneous data will eventually appear as `[unknown]` entries in the report. It is sufficient as long as most of the records are correct for profiling. Signed-off-by: Tianyi Liu --- MAINTAINERS | 1 + arch/arm64/kvm/arm.c | 12 ++++++++++++ arch/x86/kvm/x86.c | 24 ++++++++++++++++++++++++ include/linux/kvm_host.h | 5 +++++ include/linux/perf_kvm.h | 18 ++++++++++++++++++ 5 files changed, 60 insertions(+) create mode 100644 include/linux/perf_kvm.h diff --git a/MAINTAINERS b/MAINTAINERS index 788be9ab5b73..5ee36b4a9701 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -16976,6 +16976,7 @@ F: arch/*/kernel/*/perf_event*.c F: arch/*/kernel/perf_callchain.c F: arch/*/kernel/perf_event*.c F: include/linux/perf_event.h +F: include/linux/perf_kvm.h F: include/uapi/linux/perf_event.h F: kernel/events/* F: tools/lib/perf/ diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index e5f75f1f1085..5ae74b5c263a 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -574,6 +574,18 @@ unsigned long kvm_arch_vcpu_get_ip(struct kvm_vcpu *vcpu) { return *vcpu_pc(vcpu); } + +bool kvm_arch_vcpu_get_unwind_info(struct kvm_vcpu *vcpu, struct perf_kvm_guest_unwind_info *info) +{ + /* TODO: implement */ + return false; +} + +bool kvm_arch_vcpu_read_virt(struct kvm_vcpu *vcpu, gva_t addr, void *dest, unsigned int length) +{ + /* TODO: implement */ + return false; +} #endif static int kvm_vcpu_initialized(struct kvm_vcpu *vcpu) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 2c924075f6f1..9341cd80f665 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -13039,6 +13039,30 @@ unsigned long kvm_arch_vcpu_get_ip(struct kvm_vcpu *vcpu) return kvm_rip_read(vcpu); } +bool kvm_arch_vcpu_get_unwind_info(struct kvm_vcpu *vcpu, struct perf_kvm_guest_unwind_info *info) +{ + info->ip_pointer = kvm_rip_read(vcpu); + info->frame_pointer = kvm_register_read_raw(vcpu, VCPU_REGS_RBP); + + info->is_guest_64bit = is_64_bit_mode(vcpu); + if (info->is_guest_64bit) { + info->segment_cs_base = 0; + info->segment_ss_base = 0; + } else { + info->segment_cs_base = get_segment_base(vcpu, VCPU_SREG_CS); + info->segment_ss_base = get_segment_base(vcpu, VCPU_SREG_SS); + } + return true; +} + +bool kvm_arch_vcpu_read_virt(struct kvm_vcpu *vcpu, gva_t addr, void *dest, unsigned int length) +{ + struct x86_exception e; + + /* Return true on success */ + return kvm_read_guest_virt(vcpu, addr, dest, length, &e) == X86EMUL_CONTINUE; +} + int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu) { return kvm_vcpu_exiting_guest_mode(vcpu) == IN_GUEST_MODE; diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 4944136efaa2..6f5ff4209b0c 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -1595,6 +1596,10 @@ static inline bool kvm_arch_intc_initialized(struct kvm *kvm) #ifdef CONFIG_GUEST_PERF_EVENTS unsigned long kvm_arch_vcpu_get_ip(struct kvm_vcpu *vcpu); +bool kvm_arch_vcpu_get_unwind_info(struct kvm_vcpu *vcpu, + struct perf_kvm_guest_unwind_info *info); +bool kvm_arch_vcpu_read_virt(struct kvm_vcpu *vcpu, gva_t addr, void *dest, + unsigned int length); void kvm_register_perf_callbacks(unsigned int (*pt_intr_handler)(void)); void kvm_unregister_perf_callbacks(void); diff --git a/include/linux/perf_kvm.h b/include/linux/perf_kvm.h new file mode 100644 index 000000000000..e77eeebddabb --- /dev/null +++ b/include/linux/perf_kvm.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_PERF_KVM_H +#define _LINUX_PERF_KVM_H + +/* + * Structures as interface between Perf Event and KVM subsystem. + * Add more members for new architectures if necessary. + */ + +struct perf_kvm_guest_unwind_info { + unsigned long ip_pointer; + unsigned long frame_pointer; + bool is_guest_64bit; + unsigned long segment_cs_base; + unsigned long segment_ss_base; +}; + +#endif /* _LINUX_PERF_KVM_H */ From patchwork Sun Dec 10 08:14:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyi Liu X-Patchwork-Id: 176307 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp6414887vqy; Sun, 10 Dec 2023 00:16:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IECg/WyBDH1zQU1V0bf04e8pDylBGADq2YkPuvW6KNJWxGAiyzM6GzdCh2Pglv5ArJCY5+s X-Received: by 2002:a17:902:b197:b0:1d1:ce10:d703 with SMTP id s23-20020a170902b19700b001d1ce10d703mr2995917plr.91.1702196196009; Sun, 10 Dec 2023 00:16:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1702196195; cv=pass; d=google.com; s=arc-20160816; b=esFo+h7VV/NIckifNRY7bRbiNDlrFlOTQMEaiwAkmy1RwVxOVHDJ9DRWfMIhYqfLFv GZztlvjdcWioRypmCCkNktaC5vuInk5RLeBA2lbHmWOLkFoeZZmxYPTpjbIdz5gcj3q6 X7d1cXQTi7iTTYuZE5WDsDnYMRxY4+LJ9sse9JSrQ9wlNSQyQS0c84Q3CiimOemlso/S 2/QKTeuEzsTfVaP99EFcbivp1v6tofeZ5GLRa6srgAtEHdhhPG/e5AC57olXtI1lTep7 t0HryeuoGL/abT3FkTwk7Vp4vj1Z3/4oxbGVkoF0rNGkuFH9Ic31nprLiScFrGWqyr0v NNaw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=pxF+R4s6Cw2cH1iWqjVrs90ajnNFMMq5vaqUa7oXs9o=; fh=HIpGW3XNt20YYDdrqGWTdutDMTXUX2EnMhGwR8EwV4c=; b=IkXBvYmDFCmDSJezaYeIo41+ja27uK0JEaUSY1hBB4YknNt0jIUn0sbb51KP7e/4JG llwYgWknyhilEvt7PX+3+DfPixo8cVjfOPKpQnb2Pr7PNoRGaGMoWY+eKOeA9Vc5ap4w yc+/fAKiXJRhliX1FJUujXlZR735ZayqiiB9kIHgJ618utBjyzJeKK2jIQubq7ttnLsO DkuKvlrHjOVUFsBL1HFw5zQYKKSkdnVKdodUBy7STVJ3g06v29b51J9feeky8jQFZmhR UMA/z+g3ma0+n0WiLvpbWAN1S+0PhfsxmdROEtN4VpiKCDf/tV/emMGvwHN0DXOJCbUp 1swg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=QHGF6j0P; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id x7-20020a170902ec8700b001d09249f030si4372156plg.415.2023.12.10.00.16.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Dec 2023 00:16:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=QHGF6j0P; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id B774B8068E13; Sun, 10 Dec 2023 00:15:25 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231653AbjLJIPQ (ORCPT + 99 others); Sun, 10 Dec 2023 03:15:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229518AbjLJIPP (ORCPT ); Sun, 10 Dec 2023 03:15:15 -0500 Received: from AUS01-SY4-obe.outbound.protection.outlook.com (mail-sy4aus01olkn2156.outbound.protection.outlook.com [40.92.62.156]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51F8AC6; Sun, 10 Dec 2023 00:15:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=REW2+iW1lTE75brGn8JouBVk/ZYBBezUKtXsXdoXh7HHSl7bbOMfSps7F61q+LPk/sA8xzWjYMykBJn9g9wzXwJ1r0U+YUzq5hcZvdexSeNOKH1o0GeTwLCFOCv1JakuIqvWlYyiHPYp6ujvHVUFT/PQYUDZXoe2ee8xqVkLOS2cxef3raMt3Pl4mnRa2fHK10l1qQbejFrL07vb2e+I1Lf6xtJGNK0xMdGdtRpzrLiqY6Hqly4PG4GayNdDchwTH3vDcw9h5EZcn47muq2WGaJ6RldbE8qCHxtkLzLH4i5xLba+nLhg+AZxkpbUT4T63WcejrDxKpJno2CJnQVNzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=pxF+R4s6Cw2cH1iWqjVrs90ajnNFMMq5vaqUa7oXs9o=; b=UyiEV0Kbb3VTdQCVKXufdYwaGT2C6WjSVey/l4LsceGpsUTT2H9xTd9qDFZP49OIW/Pp4zI7Lu3bksS6wzkNBRgWGS3TkkMSd6LKCYceWYhypwJSH6qOf1nCn+g2bjmi1PGo/Yd0+4h2ZbLiEyOrSegVRKhwOnNjya0gT1zvsZxIFKy3vEuyWIYWvDVQvESP9cbPMUGhuIyHEclXrMbM+odId313zym2HWHpblqN+GAptfjPd2qkFblNEaUoy9XcWCyfBMiTBATWjOZYr/wC+Ysbjsy+mHgiH/64LBcNY+LuI4BHKqS+xQYqnnNmMiIR9LKLciimQ0oz0L4yUp021g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pxF+R4s6Cw2cH1iWqjVrs90ajnNFMMq5vaqUa7oXs9o=; b=QHGF6j0PJzjvlRgm0+Ia6OdgsHGKpmuB9GAfHxO6C2wXpeEQ7ZdNkJHybBkYPPSDtu9J8Uw7EAepOuJ+RbXAaeHWQPMB+KocJbszJ9EIPgVVoNZHOtxGNEBurpPhQNUXw2Uvi3EWM/muru1e2X3jh5vlkkY8xQB0zaV9LKFQeF5ujFzNsdPFZ/MuylNZJZpmo6QF/BJe9Gct0XsrxBqm2EcGUyjCg1Gxf5g/7njttglVq3isTl7vU19VsbjflSz8l2MbWJInIc8FRSHuq9ZvyAx1EPXgMZyoYhAY/pRHhIK8LsDPx9XB2PGlGQZ8prBgru1owTe6rAFHkaCCxXKo2g== Received: from SYBPR01MB6870.ausprd01.prod.outlook.com (2603:10c6:10:13d::10) by MEYPR01MB7339.ausprd01.prod.outlook.com (2603:10c6:220:15f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.31; Sun, 10 Dec 2023 08:15:12 +0000 Received: from SYBPR01MB6870.ausprd01.prod.outlook.com ([fe80::be5a:160f:5418:9deb]) by SYBPR01MB6870.ausprd01.prod.outlook.com ([fe80::be5a:160f:5418:9deb%5]) with mapi id 15.20.7068.030; Sun, 10 Dec 2023 08:15:12 +0000 From: Tianyi Liu To: seanjc@google.com, pbonzini@redhat.com, peterz@infradead.org, mingo@redhat.com, acme@kernel.org Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, kvm@vger.kernel.org, x86@kernel.org, mark.rutland@arm.com, mlevitsk@redhat.com, maz@kernel.org, alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org, irogers@google.com, adrian.hunter@intel.com, Tianyi Liu Subject: [PATCH v3 2/5] perf kvm: Introduce guest interfaces for sampling callchains Date: Sun, 10 Dec 2023 16:14:52 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: X-TMN: [tNQOTVHnuDQwQkpUy9i9+/3gTNGARQA5x7xlGvNEgKG54CKGU5CETA==] X-ClientProxiedBy: SG2PR03CA0107.apcprd03.prod.outlook.com (2603:1096:4:7c::35) To SYBPR01MB6870.ausprd01.prod.outlook.com (2603:10c6:10:13d::10) X-Microsoft-Original-Message-ID: <20231210081452.2312-1-i.pear@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SYBPR01MB6870:EE_|MEYPR01MB7339:EE_ X-MS-Office365-Filtering-Correlation-Id: 80c8c0ea-93a6-4a93-9b4c-08dbf95821c3 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: V2lVPkeEVw0TXhPSNndJFgrUfQfWQhe97/3dWJAom8I8E5xwvpRVo0D4oa1wpDtNYLTXvE6LrN2JpZ2K04UUo7cnjLbfZwnhbVv6n4sknlJ9kA2KeT77ZtZaPxjdCYBoQodjqkrR9Y+TSvYe1bHNeA0r9eJSB/u37ZR3RkI/kowuinjWLGm0MjPJ8lMEdb2KvXMW0WPoP5t4WTAYXxWymURvuPa7LDqE3HEu+hXJkNjN5MC/lTVatkDAkooWfuKh2nRsOw/x/LgeTcTyziGKAi18iUuJYOTjMD0KJrwjKcEueimehowQa0z/9k/gMLNZQHqwGT81EoiQMp6KOUZ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dg6ERsj/8pFuiw4K71LoEdO2hqQdGnf5qaAd382uEODi58wf1WLg7V2NSh6+wyVi4LcOASjJcf0288FMcyBXaMFcNA/W5JKzII5N/AoKEYRBPwjPPOLKmSgegMK7kh7ovY6pgsiWhfn1NgDtE9DAXVGik80PMFh9F2tIipQKvbFF/X/9EH8UW/ZFG+HoRMqzxfXPY6/WWOU2OK3XijDsCKk66rwvgKG7fG+mvuTzfRt2DMtOW/GaRBcKgcUu8PPZkrLQyQCuylgY9XSKGAqxeqR9xXmd0BJfvM8OJcxXJs9mMXHbpxG1PalBZ3TLyj8SJuzkRb9pq5HTqfl9tR1FWMCCSP1HdtxmUopb1rkpleE73Lfe73zR3qK9498hNRrfSIUe5P0iYwc+6tBjLbSeexDpwYM9SBAmiVhzvj10A2SG39KZfzZOLTniVhDnIxvp0tnFkk37u+JH/MuxbTjtgHQ3gn/5Td8l7a0biU7WfMkt+6qvBUjPgsIDAS7mePxp5Fl6WPUoRqE0k4MT/NGx7MPDY6+utJlbrK0sqrq X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 80c8c0ea-93a6-4a93-9b4c-08dbf95821c3 X-MS-Exchange-CrossTenant-AuthSource: SYBPR01MB6870.ausprd01.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2023 08:15:12.4656 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MEYPR01MB7339 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Sun, 10 Dec 2023 00:15:25 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784882078443132444 X-GMAIL-MSGID: 1784882078443132444 This patch introduces two callback interfaces used between perf and KVM: - get_unwind_info: Return required data for unwinding at once; including ip address, frame pointer, whether the guest vCPU is running in 32 or 64 bits, and possibly the base addresses of the segments. - read_virt: Read data from a virtual address of the guest vm, used for reading the stack frames from the guest. Signed-off-by: Tianyi Liu --- include/linux/perf_event.h | 17 +++++++++++++++++ kernel/events/core.c | 10 ++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 5547ba68e6e4..dacc1623dcaa 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -17,6 +17,8 @@ #include #include +#include + /* * Kernel-internal data types and definitions: */ @@ -32,6 +34,9 @@ struct perf_guest_info_callbacks { unsigned int (*state)(void); unsigned long (*get_ip)(void); + bool (*get_unwind_info)(struct perf_kvm_guest_unwind_info *info); + bool (*read_virt)(unsigned long addr, void *dest, + unsigned int len); unsigned int (*handle_intel_pt_intr)(void); }; @@ -1500,6 +1505,8 @@ extern struct perf_guest_info_callbacks __rcu *perf_guest_cbs; DECLARE_STATIC_CALL(__perf_guest_state, *perf_guest_cbs->state); DECLARE_STATIC_CALL(__perf_guest_get_ip, *perf_guest_cbs->get_ip); +DECLARE_STATIC_CALL(__perf_guest_get_unwind_info, *perf_guest_cbs->get_unwind_info); +DECLARE_STATIC_CALL(__perf_guest_read_virt, *perf_guest_cbs->read_virt); DECLARE_STATIC_CALL(__perf_guest_handle_intel_pt_intr, *perf_guest_cbs->handle_intel_pt_intr); static inline unsigned int perf_guest_state(void) @@ -1510,6 +1517,14 @@ static inline unsigned long perf_guest_get_ip(void) { return static_call(__perf_guest_get_ip)(); } +static inline bool perf_guest_get_unwind_info(struct perf_kvm_guest_unwind_info *info) +{ + return static_call(__perf_guest_get_unwind_info)(info); +} +static inline bool perf_guest_read_virt(unsigned long addr, void *dest, unsigned int length) +{ + return static_call(__perf_guest_read_virt)(addr, dest, length); +} static inline unsigned int perf_guest_handle_intel_pt_intr(void) { return static_call(__perf_guest_handle_intel_pt_intr)(); @@ -1519,6 +1534,8 @@ extern void perf_unregister_guest_info_callbacks(struct perf_guest_info_callback #else static inline unsigned int perf_guest_state(void) { return 0; } static inline unsigned long perf_guest_get_ip(void) { return 0; } +static inline bool perf_guest_get_unwind_info(struct perf_kvm_guest_unwind_info *) { return 0; } +static inline bool perf_guest_read_virt(unsigned long, void*, unsigned int) { return 0; } static inline unsigned int perf_guest_handle_intel_pt_intr(void) { return 0; } #endif /* CONFIG_GUEST_PERF_EVENTS */ diff --git a/kernel/events/core.c b/kernel/events/core.c index b704d83a28b2..4c5e35006217 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -6807,6 +6807,8 @@ struct perf_guest_info_callbacks __rcu *perf_guest_cbs; DEFINE_STATIC_CALL_RET0(__perf_guest_state, *perf_guest_cbs->state); DEFINE_STATIC_CALL_RET0(__perf_guest_get_ip, *perf_guest_cbs->get_ip); +DEFINE_STATIC_CALL_RET0(__perf_guest_get_unwind_info, *perf_guest_cbs->get_unwind_info); +DEFINE_STATIC_CALL_RET0(__perf_guest_read_virt, *perf_guest_cbs->read_virt); DEFINE_STATIC_CALL_RET0(__perf_guest_handle_intel_pt_intr, *perf_guest_cbs->handle_intel_pt_intr); void perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *cbs) @@ -6818,6 +6820,12 @@ void perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *cbs) static_call_update(__perf_guest_state, cbs->state); static_call_update(__perf_guest_get_ip, cbs->get_ip); + if (cbs->get_unwind_info) + static_call_update(__perf_guest_get_unwind_info, cbs->get_unwind_info); + + if (cbs->read_virt) + static_call_update(__perf_guest_read_virt, cbs->read_virt); + /* Implementing ->handle_intel_pt_intr is optional. */ if (cbs->handle_intel_pt_intr) static_call_update(__perf_guest_handle_intel_pt_intr, @@ -6833,6 +6841,8 @@ void perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *cbs) rcu_assign_pointer(perf_guest_cbs, NULL); static_call_update(__perf_guest_state, (void *)&__static_call_return0); static_call_update(__perf_guest_get_ip, (void *)&__static_call_return0); + static_call_update(__perf_guest_get_unwind_info, (void *)&__static_call_return0); + static_call_update(__perf_guest_read_virt, (void *)&__static_call_return0); static_call_update(__perf_guest_handle_intel_pt_intr, (void *)&__static_call_return0); synchronize_rcu(); From patchwork Sun Dec 10 08:15:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyi Liu X-Patchwork-Id: 176305 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp6414836vqy; Sun, 10 Dec 2023 00:16:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IEXCodjinn5f5DJUM2TVnAIOHabwO98rShWEDiu4DH/3tzrn6wc1tvufpN2wd/hvevM1H4u X-Received: by 2002:a17:902:ea0b:b0:1d0:8e08:35be with SMTP id s11-20020a170902ea0b00b001d08e0835bemr2477131plg.7.1702196182585; Sun, 10 Dec 2023 00:16:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1702196182; cv=pass; d=google.com; s=arc-20160816; b=VlBFljl47uCCoJfKPd00j9ID2fGEoLFSRYInsh5KOxSqCpC0dvl3OaIcLTfJNBfM+3 Edhz8nORErlaebQ7yMkqIsRajNgpHTIvgndylD/ckgVr2neSrf2LRg8BATWQXxxdL+V8 Pecd7PDcWM/vEniThUwbp/Pg2CyrxSXHZ1o1kaZh6rHGWwIwWbIc8+/EAAtJFJu+jSD2 SJ2IQlbcgRnyjg17TkGW62HFhpmqtP+St1daqqhYMMHQ6JK/C/JjooqRd1c8s0CVguhx f+VgszUUR/4CtzNA6Ajvk8hngtlyZ/JttlAHxFH55JW4McfBLVibcapNyaVv/IOmmvcZ YR5Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=N1i26DJnKwIxg92MeUs8Z6WMsFGvM3406uFpBVomlXY=; fh=HIpGW3XNt20YYDdrqGWTdutDMTXUX2EnMhGwR8EwV4c=; b=wsFYsbvtjD3/CFQBzRBFDsG9tetLzLdhV1TSSsPoRr8NKUqOT89yW3Cnv1F97vgqRV H89ZNl/Hc5NPG3l/9OEPZYoDYtM9s+aP7fvyt0ps63PnLqQxwuRgKfrIhKesdFUo3kjB CsNX+8GdcdpprvH4z6rIsCfkIT+k+TOZ6oISRTWDO7j4c8EM/vacKfGEKs33Z1HHZ1c2 80x3E4UgWhQsFhgHtENJzNb5eHR9VZWCJ0PuT9wYx50GI8Y516mHBzD3cflwJo02UbG2 NxbrwfY5KXF1g4P9iEh3lFttezycbloQvZNA8kahAAW6fShZebXIqJWk/gA+129/qAGe ex9A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=cUETqePm; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id be3-20020a170902aa0300b001cf8d044c2asi4197533plb.544.2023.12.10.00.16.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Dec 2023 00:16:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=cUETqePm; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id E1953807E447; Sun, 10 Dec 2023 00:15:53 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231681AbjLJIPp (ORCPT + 99 others); Sun, 10 Dec 2023 03:15:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229482AbjLJIPn (ORCPT ); Sun, 10 Dec 2023 03:15:43 -0500 Received: from AUS01-SY4-obe.outbound.protection.outlook.com (mail-sy4aus01olkn2154.outbound.protection.outlook.com [40.92.62.154]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2BB3CB; Sun, 10 Dec 2023 00:15:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=APBNDeChfwMh/HYVKhasrfaaR3luvMG36xMw4L7TxhwDNxSZgS924tl0v6/QV1zpDVbEOKS+4ge23yAUqsM9lxCeWM6l5YWWA0Y9Ro270nC5P4zO8uhLpe1cWX0YD064ozQckE482iAzMf4lLg4zR+WLVWJC/0A3qUZDDZLwwF/Sn5YFb5X49ms0RXkqIrR4fs5B83riF5ywGAwizIHG4jkNgdlRfa2a3BbIL3iZz5Oj7eVeB9LeK9YJexVd5WVxouwtXydjb9HLOZ5+W/BGI5wDsWf5Ci24gXZC3JVaZJ/3GJUrSXgJe5c3HZA8LFUA471+QJJU0c8pGmnF2K6sEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=N1i26DJnKwIxg92MeUs8Z6WMsFGvM3406uFpBVomlXY=; b=F4cojM3r6QaxB8USzKJ3l24gKvOrzQW2t5FesoMShpETcsTnl0PQI0Um9cxZZTlR4WhK9y+OMrRVoy4TAj7WLYQpw509lkekKPW128lW+NJxHpMvSKp9U3XDQ07zT/7xOE51PT2vc0OOvjbRXFXyCqn2gf1wLdTumtE1Q8+ehqKL0jL2Rx/Uqh9oijfsc6LA2g72OUtntB3tcz4TSA5eLeHwS8ItGONzFMtEfU78HEngcSZ34qWo71MiVimBgdtpBkpDA22uTN+9U5Nt1JBfWStU2hVHQelrDeGexz4SJlZT12UWAQhZDmPzLQK4+HETrHPISctmdjieSV0JXK6knA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=N1i26DJnKwIxg92MeUs8Z6WMsFGvM3406uFpBVomlXY=; b=cUETqePmG755InfSZkpI8kyawLtZ00ft0n/rLwuSYpd9GOq2ur1ru5G18zQu7j26IN1NxEFeS3wTPAn4hpLKWepFlctqqVMOQQVteWjGkFWgyGW4QTUAJ9ed5fo0Cdfyg2aP3HDbodRwjj0YRBdpTNVVtNDtVdXZ5qxFlDoybvXWd4MJBsGTz4DtIlXgyXZC8r53grOk2D4o8Qcx1EetWxs90cNGO6WtaDQ9EYKscesvOiAZ/YZosyEQHJTr9CRzWN5KIZAFmkHPu0foU+k8eJ2JzJb1jucLSCfoLrEwK4dTTTTmnZei/fNFrhFSrBTPriuvIsZnA4Gak54i80hnBQ== Received: from SYBPR01MB6870.ausprd01.prod.outlook.com (2603:10c6:10:13d::10) by MEYPR01MB7339.ausprd01.prod.outlook.com (2603:10c6:220:15f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.31; Sun, 10 Dec 2023 08:15:42 +0000 Received: from SYBPR01MB6870.ausprd01.prod.outlook.com ([fe80::be5a:160f:5418:9deb]) by SYBPR01MB6870.ausprd01.prod.outlook.com ([fe80::be5a:160f:5418:9deb%5]) with mapi id 15.20.7068.030; Sun, 10 Dec 2023 08:15:42 +0000 From: Tianyi Liu To: seanjc@google.com, pbonzini@redhat.com, peterz@infradead.org, mingo@redhat.com, acme@kernel.org Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, kvm@vger.kernel.org, x86@kernel.org, mark.rutland@arm.com, mlevitsk@redhat.com, maz@kernel.org, alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org, irogers@google.com, adrian.hunter@intel.com, Tianyi Liu Subject: [PATCH v3 3/5] KVM: implement new perf callback interfaces Date: Sun, 10 Dec 2023 16:15:24 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: X-TMN: [v6yvaF+JLPh+PCgNnetddSJEklpOTVwqI2vcLPFcfPuR5Ao+D0+oBw==] X-ClientProxiedBy: SG2PR06CA0207.apcprd06.prod.outlook.com (2603:1096:4:68::15) To SYBPR01MB6870.ausprd01.prod.outlook.com (2603:10c6:10:13d::10) X-Microsoft-Original-Message-ID: <20231210081524.2358-1-i.pear@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SYBPR01MB6870:EE_|MEYPR01MB7339:EE_ X-MS-Office365-Filtering-Correlation-Id: 959e30c7-68cf-46c7-ed7a-08dbf9583383 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DTWdeCFFWhDPIiCSiU2WhdHULaHA/1d9PaCApNoqxEqZiBgBKu5ooVtxpIxW4RpGaPr7PJ1nDB75vbH2y9QBwDEcHa2Up4VOGoAzIXCpNoh52L7385Fkvi/5KLcek1P328aSvBmwnv+dovEHSVOdyuf+MRHTpeqaHVBK/ZzYSyM59H5Ny5dAJL5HX9tUVqUofJGMYzaj6lD4vaecx8R9O4BG3y+FT0Uuo6uyPDHz3N2OdH4X94t4JwLRKCFtvCGT6VSP1rt7nzCjOVv6+c87+VUQAyoyk0KSWb+qwAHTgtIXyI3QM1fQplz8zr9/Wa2xNsI6TM8g62IWDrxYr9TSHOgUhdmP+KPXWq+eo5Q0jDHiKika9yxJC5LSJDZ8nOHNiFkrTmsHVZ8vOrqHFzypKemeiZQqD27ZvsLTAniCrO/h6zAHbpuKMR+4lUqWgoxUo5+CGpI/vPzV+BsXbfGNJJmTqilmOocu1sp1/sb/+t06ZFeDeC6WK3N+LxyC4IaOpWar+krvZEOMUbUCUwzjYHoR6QlLbnrC1JfTaGoa3Ml590bhrBfpV9DRB73yxWai1myPWshePip52SCPbdhtbO/SKAd5WnepLsdn1YgkZxNzRZomRyrHqAE10Gl/nVFN X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: O+3hlnb0oA++e28XlMGGv/Ma7t9Hx7Ixj99e0izFdqv8qZHYSo/xmO7mJsqI9M1XcrJzR43q5M0duQMIVjFLuqDgR+fo6JbZc9R5eFDEZwCn6+qkeOSb+mkGtmPl1xkqHtJMhfxO5y/cg2CSOVbIRIYKIR6/E45vx+YM/l10NrVQvtIxFGGht0Vnuw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uvs2MWWPX X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 959e30c7-68cf-46c7-ed7a-08dbf9583383 X-MS-Exchange-CrossTenant-AuthSource: SYBPR01MB6870.ausprd01.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2023 08:15:42.2392 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MEYPR01MB7339 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Sun, 10 Dec 2023 00:15:54 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784882064487056597 X-GMAIL-MSGID: 1784882064487056597 This patch provides two KVM implementations for the following two new perf interfaces, just redirecting them to the arch-specific implementations: - get_unwind_info - read_virt Signed-off-by: Tianyi Liu --- virt/kvm/kvm_main.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 486800a7024b..c47b6c0f8e94 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -6032,9 +6032,31 @@ static unsigned long kvm_guest_get_ip(void) return kvm_arch_vcpu_get_ip(vcpu); } +static bool kvm_guest_get_unwind_info(struct perf_kvm_guest_unwind_info *info) +{ + struct kvm_vcpu *vcpu = kvm_get_running_vcpu(); + + if (WARN_ON_ONCE(!kvm_arch_pmi_in_guest(vcpu))) + return false; + + return kvm_arch_vcpu_get_unwind_info(vcpu, info); +} + +static bool kvm_guest_read_virt(unsigned long addr, void *dest, unsigned int length) +{ + struct kvm_vcpu *vcpu = kvm_get_running_vcpu(); + + if (WARN_ON_ONCE(!kvm_arch_pmi_in_guest(vcpu))) + return false; + + return kvm_arch_vcpu_read_virt(vcpu, addr, dest, length); +} + static struct perf_guest_info_callbacks kvm_guest_cbs = { .state = kvm_guest_state, .get_ip = kvm_guest_get_ip, + .get_unwind_info = kvm_guest_get_unwind_info, + .read_virt = kvm_guest_read_virt, .handle_intel_pt_intr = NULL, }; From patchwork Sun Dec 10 08:15:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyi Liu X-Patchwork-Id: 176306 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp6414846vqy; Sun, 10 Dec 2023 00:16:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IGPT/8HUhMuH9YuTZd4TPqjQELabCMEAr8bxO62csfX2SxFpiez+weN0yGAz7z/o4oPZ8XR X-Received: by 2002:a17:902:be17:b0:1d0:6ffe:9ee with SMTP id r23-20020a170902be1700b001d06ffe09eemr2360909pls.76.1702196183656; Sun, 10 Dec 2023 00:16:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1702196183; cv=pass; d=google.com; s=arc-20160816; b=WCdLyrn5SNoG/z8kUs5Y+pk3Uo+rH4O/0GOEUZaP5fsqIr+OX/s/9hkR/7EkNaIUba 73m8FqqQq6FwqfxmkuiKS/kyKXTZaeli0ywzvRV9M2oszyr0dLPRSvmgGaAzbbE/lCdb i1Uz+0agT8+8q7aKIzVJ/ikt62czzGciR/zUkZzXXHug+ZH9j08+08uo641jylbOr/Cf aBUEe+RfdLqAV8Yzwl2odOFBjNb8BeAXbJpqQQGw4vOaCiw3Xuz8LbT4tO0ivC84xJBX W8nA/khzu2tK+v9c4RQkmX8uC/eQSEpeDdgGH9HlRVwFuQL1SUTT6vMCmH9KA+f7+y9B ijFg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0Dm06ddVNFaxYjCFCM3kfRfk86yrs5hrGvGUIaB4XIQ=; fh=HIpGW3XNt20YYDdrqGWTdutDMTXUX2EnMhGwR8EwV4c=; b=bZuO4BM8l+ob3u1YEKvaAhxkisOqNXlx2zs/Ko2pDmhRNkxyvjdLhY+NUxb6AFx41r UOkymXnWe1G+iXhp3Vq8Q+IAqLZ1ojLiiMu1AbNbN1qeD/iHfrywg2KVb6TPlNyQ+EY7 iyEwjA1i5d3S8h9I6pj5rJWJDgW69pAj+JjkV9TjtHwhz0khOPsQdTJz6v/KYGaMun9Z 6P1WLZ7VIiA7rYsfolzN2k9a5nEfwfa5AEIIk0whzA65+A+mnmMk7jfvQenBGL9AL08t CQGCFPnFG6Gqw9skh+HRXNvT6nX/ISwtfxvxfP52zp4lyDf5RuzUhu4HbvXwlB8Qequd eFHg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=cF2dG0Hq; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id v22-20020a17090a899600b002887d884223si5621547pjn.138.2023.12.10.00.16.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Dec 2023 00:16:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=cF2dG0Hq; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 4E63E805ECE6; Sun, 10 Dec 2023 00:16:22 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231698AbjLJIQM (ORCPT + 99 others); Sun, 10 Dec 2023 03:16:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231642AbjLJIQK (ORCPT ); Sun, 10 Dec 2023 03:16:10 -0500 Received: from AUS01-SY4-obe.outbound.protection.outlook.com (mail-sy4aus01olkn2173.outbound.protection.outlook.com [40.92.62.173]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 873BBC6; Sun, 10 Dec 2023 00:16:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mj0hX3eJ9ZuLGB/elM4zySzuVt0TNhPdFikrBqJnjUpsni6fkF2e0iIop3Y2Q8KZP+DbjNtKY42LWqJ+0AjfDy6XZADwZ2VrN9wUCQ44sWPlsrsLZXM8LzNACFt3hV8WIxj98Bc/wmMemAtuhhtGAh7Xxe0OVLcsMb/JFGJ4uz3dbqDn1Fz/R6CAt1DCQvEJjPqt2UoxeXf6ngDduifHyhBploOv4Vfav4khvyjBfKJ1glYA0UUxQLkSPR0yyAPMx7z+jlnAkJ+enl/OQMkqT4i2hMm5VLX33zEJUlNKAhtPAiUvU7rvkoLFYL29g+hYBJPY7TTTDYPOC+6W2cYaZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=0Dm06ddVNFaxYjCFCM3kfRfk86yrs5hrGvGUIaB4XIQ=; b=H5m3CRJ+h2jkPh1ujCOy/kKiS1guOB3ld9IqmULfn7jXkJrr2oAvx+JTKdvzSWVDmittOziJpSo7X/QwWhuTBoTVjjF72rPjS4RCpk5arW9ERrkbnMlL7c4cp8AMnn5gqUQL6CW6Z6uz/lxYnqZvS9bFbfk0V/ltNRtU9aYNfUcGDBiKh4zn5GTrRhf+PYhd4al7L6uZjohhExfo1aC/am9TOOoXCoPWlJtfPvfXs0w2J6UjJQnN9TKald9pt6hm/+gbJnV9dE2QeirAJEDZdc4OHX6KouEVzJpkM3THYqlDEEf+vUUUD/WgP+ai5hVwylr5lyCIxJu4yPdXSpRshg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0Dm06ddVNFaxYjCFCM3kfRfk86yrs5hrGvGUIaB4XIQ=; b=cF2dG0Hq01NqygOCJrHGxHm0Xu//oOJLuGLcSqLcnLRcu1ZMsSbbieibiiU/rJ2ukhH3TQvWkU6Xv+hfMr473I85ujQ2+uXKDhZkq+yC+9z+l1QgDiyGnrf6fakfp97/Gf1fzXtsC1qp6zeizlqPQ0H1gfiGNMlAI9WEw8XkuaTVVr6Dtf+xPGibq5a3SYC57vy8XqEHK8siD2mDGtS0a9IrRYkLF9gPt1orfw3hTX1JrG2EJ5qASdOka9ui50FIIL+zF9jo+/hpLSUVD69S5MlPHxti7m21iVS3sYJF6iT4tiYg/BcCfW8Gh+qt0HgTocjSXM0TWNlreyZ7JB7Fkw== Received: from SYBPR01MB6870.ausprd01.prod.outlook.com (2603:10c6:10:13d::10) by MEYPR01MB7339.ausprd01.prod.outlook.com (2603:10c6:220:15f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.31; Sun, 10 Dec 2023 08:16:08 +0000 Received: from SYBPR01MB6870.ausprd01.prod.outlook.com ([fe80::be5a:160f:5418:9deb]) by SYBPR01MB6870.ausprd01.prod.outlook.com ([fe80::be5a:160f:5418:9deb%5]) with mapi id 15.20.7068.030; Sun, 10 Dec 2023 08:16:08 +0000 From: Tianyi Liu To: seanjc@google.com, pbonzini@redhat.com, peterz@infradead.org, mingo@redhat.com, acme@kernel.org Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, kvm@vger.kernel.org, x86@kernel.org, mark.rutland@arm.com, mlevitsk@redhat.com, maz@kernel.org, alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org, irogers@google.com, adrian.hunter@intel.com, Tianyi Liu Subject: [PATCH v3 4/5] perf kvm: Support sampling guest callchains Date: Sun, 10 Dec 2023 16:15:48 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: X-TMN: [nxBWVOlGmlQ1xJ5XQuc0c+ocO9VbnVgbjQH4feY1jj5utdNLizQTHA==] X-ClientProxiedBy: SG2PR02CA0030.apcprd02.prod.outlook.com (2603:1096:3:18::18) To SYBPR01MB6870.ausprd01.prod.outlook.com (2603:10c6:10:13d::10) X-Microsoft-Original-Message-ID: <20231210081548.2393-1-i.pear@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SYBPR01MB6870:EE_|MEYPR01MB7339:EE_ X-MS-Office365-Filtering-Correlation-Id: 7d39b20f-c1d9-4f08-bba9-08dbf95842da X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VhPLNFUfwgorjBnkLaWC5U1szG1SdKQi6pcJe1PewNYQZSkE6BXUaCcxPdkMq3mbvQeYKlOWLWsn0LqLfdkKMdMAetIfSFttTlmUGoKV1Tvsx+koV04M1BqzZLbUWbySzg9xGduQX8yah1csehOEhrHhNfKQ+UtvhwkDRHqlULo/cQBsr6rPlwjuPxm3+EggnCewLEN+FcfHVi4qTjiVGfHVZv0EsEg7sZYVQhXRjP97x6rdqXNNHggnQ9VsBEp1NUzvg9wIMwCHBxZD3/K2BLzPM1tUV+sdwYrd9uYhtZuHrLKzEupgL6Jz0Vqrn1N1wkZh3my/0IONp7QkNu4DE5YFg7myIVm2gkdyGnM3u0IqEcEw5Voq28mfXVekltLyjF7I/NJVyrVLqxzYE4ECf2bfc7qchqdmEeYdG9VO24V2Pc00LCon5owPPGF1+ShcxSHJOULNdWbw6OTlGSkuJid+MiBH/eWHB43wqQ2dj3jbOYr+SzHey+KzJ2jyfmfqeqQ3JDKh/4BpgdTpu5Ls5hQCzDwBMgg7GVoIdbeRqyBA3tGEyuK+0QdtgmmB5Ds2gqbokmEnY1IQHbLcWGquZHSf6Aw2AjUs4j27q7GMo+Q= X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +WtLDFreWex/oyTB+gwN0IGw+9NNRbtghoEoDiHw6KMiHj+/oXnrLrNnyaJvAjF7gn3zMR0uzkrW/4nhSzPpXLLE402wCO/Yhh/uuSP4BmhUrI8aUm2f5Sf0ja2v1Pp86BA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/W+MBK/JE4jRCreNZ82coyUdO9EJnEPMpN8nwKb72PHAY8jkwq2H3ftlJxIJX X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7d39b20f-c1d9-4f08-bba9-08dbf95842da X-MS-Exchange-CrossTenant-AuthSource: SYBPR01MB6870.ausprd01.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2023 08:16:07.9711 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MEYPR01MB7339 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 10 Dec 2023 00:16:22 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784882065855820775 X-GMAIL-MSGID: 1784882065855820775 This patch provides support for sampling guests' callchains. The signature of `get_perf_callchain` has been modified to explicitly specify whether it needs to sample the host or guest callchain. Based on the context, `get_perf_callchain` will distribute each sampling request to one of `perf_callchain_user`, `perf_callchain_kernel`, or `perf_callchain_guest`. The reason for separately implementing `perf_callchain_user` and `perf_callchain_kernel` is that the kernel may utilize special unwinders like `ORC`. However, for the guest, we only support stackframe-based unwinding, so the implementation is generic and only needs to be separately implemented for 32-bit and 64-bit. Signed-off-by: Tianyi Liu --- arch/x86/events/core.c | 63 ++++++++++++++++++++++++++++++++------ include/linux/perf_event.h | 3 +- kernel/bpf/stackmap.c | 8 ++--- kernel/events/callchain.c | 27 +++++++++++++++- kernel/events/core.c | 7 ++++- 5 files changed, 91 insertions(+), 17 deletions(-) diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index 40ad1425ffa2..4ff412225217 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -2758,11 +2758,6 @@ perf_callchain_kernel(struct perf_callchain_entry_ctx *entry, struct pt_regs *re struct unwind_state state; unsigned long addr; - if (perf_guest_state()) { - /* TODO: We don't support guest os callchain now */ - return; - } - if (perf_callchain_store(entry, regs->ip)) return; @@ -2778,6 +2773,59 @@ perf_callchain_kernel(struct perf_callchain_entry_ctx *entry, struct pt_regs *re } } +static inline void +perf_callchain_guest32(struct perf_callchain_entry_ctx *entry, + const struct perf_kvm_guest_unwind_info *unwind_info) +{ + unsigned long ss_base, cs_base; + struct stack_frame_ia32 frame; + const struct stack_frame_ia32 *fp; + + cs_base = unwind_info->segment_cs_base; + ss_base = unwind_info->segment_ss_base; + + fp = (void *)(ss_base + unwind_info->frame_pointer); + while (fp && entry->nr < entry->max_stack) { + if (!perf_guest_read_virt((unsigned long)&fp->next_frame, + &frame.next_frame, sizeof(frame.next_frame))) + break; + if (!perf_guest_read_virt((unsigned long)&fp->return_address, + &frame.return_address, sizeof(frame.return_address))) + break; + perf_callchain_store(entry, cs_base + frame.return_address); + fp = (void *)(ss_base + frame.next_frame); + } +} + +void +perf_callchain_guest(struct perf_callchain_entry_ctx *entry) +{ + struct stack_frame frame; + const struct stack_frame *fp; + struct perf_kvm_guest_unwind_info unwind_info; + + if (!perf_guest_get_unwind_info(&unwind_info)) + return; + + perf_callchain_store(entry, unwind_info.ip_pointer); + + if (unwind_info.is_guest_64bit) { + fp = (void *)unwind_info.frame_pointer; + while (fp && entry->nr < entry->max_stack) { + if (!perf_guest_read_virt((unsigned long)&fp->next_frame, + &frame.next_frame, sizeof(frame.next_frame))) + break; + if (!perf_guest_read_virt((unsigned long)&fp->return_address, + &frame.return_address, sizeof(frame.return_address))) + break; + perf_callchain_store(entry, frame.return_address); + fp = (void *)frame.next_frame; + } + } else { + perf_callchain_guest32(entry, &unwind_info); + } +} + static inline int valid_user_frame(const void __user *fp, unsigned long size) { @@ -2861,11 +2909,6 @@ perf_callchain_user(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs struct stack_frame frame; const struct stack_frame __user *fp; - if (perf_guest_state()) { - /* TODO: We don't support guest os callchain now */ - return; - } - /* * We don't know what to do with VM86 stacks.. ignore them for now. */ diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index dacc1623dcaa..483578672868 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -1552,9 +1552,10 @@ DECLARE_PER_CPU(struct perf_callchain_entry, perf_callchain_entry); extern void perf_callchain_user(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs); extern void perf_callchain_kernel(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs); +extern void perf_callchain_guest(struct perf_callchain_entry_ctx *entry); extern struct perf_callchain_entry * get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user, - u32 max_stack, bool crosstask, bool add_mark); + bool host, bool guest, u32 max_stack, bool crosstask, bool add_mark); extern int get_callchain_buffers(int max_stack); extern void put_callchain_buffers(void); extern struct perf_callchain_entry *get_callchain_entry(int *rctx); diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c index d6b277482085..5ca41ca08d8a 100644 --- a/kernel/bpf/stackmap.c +++ b/kernel/bpf/stackmap.c @@ -294,8 +294,8 @@ BPF_CALL_3(bpf_get_stackid, struct pt_regs *, regs, struct bpf_map *, map, if (max_depth > sysctl_perf_event_max_stack) max_depth = sysctl_perf_event_max_stack; - trace = get_perf_callchain(regs, 0, kernel, user, max_depth, - false, false); + trace = get_perf_callchain(regs, 0, kernel, user, true, false, + max_depth, false, false); if (unlikely(!trace)) /* couldn't fetch the stack trace */ @@ -420,8 +420,8 @@ static long __bpf_get_stack(struct pt_regs *regs, struct task_struct *task, else if (kernel && task) trace = get_callchain_entry_for_task(task, max_depth); else - trace = get_perf_callchain(regs, 0, kernel, user, max_depth, - false, false); + trace = get_perf_callchain(regs, 0, kernel, user, true, false, + max_depth, false, false); if (unlikely(!trace)) goto err_fault; diff --git a/kernel/events/callchain.c b/kernel/events/callchain.c index 1273be84392c..7e80729e95d0 100644 --- a/kernel/events/callchain.c +++ b/kernel/events/callchain.c @@ -45,6 +45,10 @@ __weak void perf_callchain_user(struct perf_callchain_entry_ctx *entry, { } +__weak void perf_callchain_guest(struct perf_callchain_entry_ctx *entry) +{ +} + static void release_callchain_buffers_rcu(struct rcu_head *head) { struct callchain_cpus_entries *entries; @@ -178,11 +182,12 @@ put_callchain_entry(int rctx) struct perf_callchain_entry * get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user, - u32 max_stack, bool crosstask, bool add_mark) + bool host, bool guest, u32 max_stack, bool crosstask, bool add_mark) { struct perf_callchain_entry *entry; struct perf_callchain_entry_ctx ctx; int rctx; + unsigned int guest_state; entry = get_callchain_entry(&rctx); if (!entry) @@ -194,6 +199,26 @@ get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user, ctx.contexts = 0; ctx.contexts_maxed = false; + guest_state = perf_guest_state(); + if (guest_state) { + if (!guest) + goto exit_put; + if (user && (guest_state & PERF_GUEST_USER)) { + if (add_mark) + perf_callchain_store_context(&ctx, PERF_CONTEXT_GUEST_USER); + perf_callchain_guest(&ctx); + } + if (kernel && !(guest_state & PERF_GUEST_USER)) { + if (add_mark) + perf_callchain_store_context(&ctx, PERF_CONTEXT_GUEST_KERNEL); + perf_callchain_guest(&ctx); + } + goto exit_put; + } + + if (unlikely(!host)) + goto exit_put; + if (kernel && !user_mode(regs)) { if (add_mark) perf_callchain_store_context(&ctx, PERF_CONTEXT_KERNEL); diff --git a/kernel/events/core.c b/kernel/events/core.c index 4c5e35006217..3dea3fe840e6 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -7607,6 +7607,8 @@ perf_callchain(struct perf_event *event, struct pt_regs *regs) { bool kernel = !event->attr.exclude_callchain_kernel; bool user = !event->attr.exclude_callchain_user; + bool host = !event->attr.exclude_host; + bool guest = !event->attr.exclude_guest; /* Disallow cross-task user callchains. */ bool crosstask = event->ctx->task && event->ctx->task != current; const u32 max_stack = event->attr.sample_max_stack; @@ -7615,7 +7617,10 @@ perf_callchain(struct perf_event *event, struct pt_regs *regs) if (!kernel && !user) return &__empty_callchain; - callchain = get_perf_callchain(regs, 0, kernel, user, + if (!host && !guest) + return &__empty_callchain; + + callchain = get_perf_callchain(regs, 0, kernel, user, host, guest, max_stack, crosstask, true); return callchain ?: &__empty_callchain; } From patchwork Sun Dec 10 08:16:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyi Liu X-Patchwork-Id: 176308 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp6414993vqy; Sun, 10 Dec 2023 00:16:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IGA/nJdhAxw53WIj40mCpex1c/2tFDL38gULkSuRDVlXld125UQQboiTVTao5vB9odKFlor X-Received: by 2002:a05:6358:e820:b0:170:40e5:c420 with SMTP id gi32-20020a056358e82000b0017040e5c420mr2724657rwb.45.1702196215530; Sun, 10 Dec 2023 00:16:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1702196215; cv=pass; d=google.com; s=arc-20160816; b=MdcYNdMcyRPCkm3LxyWJEN/+d9n81rpi3Yt7sRf1U0RWxG8GFrFKwy01uPVJmsg0eY 39Bx9AfcDusbh9BGDWGpNZJyHDVWBt5m352y2iKt6qFk0PLeQg8wqIlZNcfuUciPr95k cM8J1Wrok3pjVY3GGXUnocABWdjc8b2gtAp8tBJyy87cNaeedhkly035YIH5/F3mjSyv /5S2bqx8ACp2JT9EHHMPAIoulBPs5JEif6QrddvHIHqROdebcXvxNC+nF94ExTpXETE8 7epLhwl1s/6jzDcwy3FsVDTEVbmY83m6DgHHweCBhoS8NzVBnu0ffIbnPx74gQ5d7N+m 4ZWw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Mhds1yoBbjrhkjhv8XPbO4OPO72aaoNMvMxayRbgsR4=; fh=HIpGW3XNt20YYDdrqGWTdutDMTXUX2EnMhGwR8EwV4c=; b=0HZQ8/GjK1jjZk31YJ6/Eu+rOYXu+bdAQiLj4rdvUrQ0s11sT6QigksIFo9FvIBIG6 tX13eGE8dvH9e6rp6Q5T4j9TgRKK35gKFemNoHqFm91Pt1jzHlGSeoezkyEDyEvDZ/aV L7Wo3e+bDGcvHN2HDHnnUfh5sb35e/wi+FXiUaZi4YbS6oO8ZFfYtX3XckWD7QHAvJTH 6rgJdFf+2yDixNOdCMwhamMCcYm+4UV3xbFYH3WEMDkp8GD6X0lzIQAO1Bk2vlGhxGiC +3EAq8AzdkKWDqNz/aGo1H/RGlA2idEr4EbtCEqHNlWWgNFCuke5dPmQeP8jJ1Eq0HD5 jI4w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=czuqyxI+; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id fy8-20020a17090b020800b00280072b397csi5590297pjb.30.2023.12.10.00.16.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Dec 2023 00:16:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=czuqyxI+; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 886708060511; Sun, 10 Dec 2023 00:16:50 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231868AbjLJIQl (ORCPT + 99 others); Sun, 10 Dec 2023 03:16:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231653AbjLJIQk (ORCPT ); Sun, 10 Dec 2023 03:16:40 -0500 Received: from AUS01-SY4-obe.outbound.protection.outlook.com (mail-sy4aus01olkn2174.outbound.protection.outlook.com [40.92.62.174]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A88D7E3; Sun, 10 Dec 2023 00:16:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Mj7clTcRpmfwzuRoAM2B6W3luIjSu7oVWJ08o0LokHbqJWcbKerHEzHo2+uduiaaHohLMg/FFiUoq7u+k1dCAvXFCuaBRJRtlAkEYe2PJpBgA6VVPWK6ilkRk6cIp6pK9b7H02u4WVNQ/UUQo1b1ULotD03+qqRh5NLpTqqr0LdcOvApLk3aMfpzbKeB4nTWmwUDdw9t4400LuygtROOH/tgHCG1zwPCUp7HHW6HKEBnCXe4YaKgEkiUvcd1DI6WecfNZC1Qg7z5+KKsFcFjlOtCq/wYUD9s9ZVzvk0RfH/wKxr1AjD0CV25h3wbnyOpUEUmaZHWGhjkih0/3ghaMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Mhds1yoBbjrhkjhv8XPbO4OPO72aaoNMvMxayRbgsR4=; b=MRClbKtrKhZpjDdAAOpgwOjwoU8o3wE5WJveyCYqWIpUX1rONUmCyFPvbRTg48/ilYO73ZYqZn1iqLO6+NK57/cEc6HdgHjOBM2im2TVUnuQBW0m5ewtGGkUBURMTNpZKU2xWpEdELGo7sQY4cJyw6JF/DG1I/AkF+2y3Dumg0ihmAH58amWObIYMvSfC1JQeUB6gWBZKLnZJPA66WSwvtLdLT0mSHFE2KuI8fWFq2hNJx6E3adFZdW1WDRFbx001y9LlrYg3iZAqbsysMYOXMwEd2rDI1pLcBm96sbeZeJhyV7/bfe1B8vbhXl8uu2hJ3aZF6o6+7VKINSzRJZZpg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Mhds1yoBbjrhkjhv8XPbO4OPO72aaoNMvMxayRbgsR4=; b=czuqyxI+/jLrCtACYpUdol1ZJojbdl0voVkq3eixcteJ/IE90MsP6luwZCfzcMzdvTlKYVTLbi5tJb+h9aNfrVOFxJnH69DNtENmv6KffJaUTdtGodx0F49pTD4Dzcip3O1KqcGcKmlT5mycXGQMnohF+kTO1Qf1L+EnrwUNk0sh62pgFgjjjSbLWXJ+lr7Nl+J/gy5BSRK7yEOzl9t52m+9lBpceHVArMqZjv1Ic68R2Y+A7mmvQvwd3fS/tnoSjD4f8Fga9Lom5WRg9u8wILwMvi8lg4WBYpPrXsbKSCYTtSAwfKqIF61Rtvi0pE1LjckqfSW8kxu8aSHGSAefmw== Received: from SYBPR01MB6870.ausprd01.prod.outlook.com (2603:10c6:10:13d::10) by MEYPR01MB7339.ausprd01.prod.outlook.com (2603:10c6:220:15f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.31; Sun, 10 Dec 2023 08:16:38 +0000 Received: from SYBPR01MB6870.ausprd01.prod.outlook.com ([fe80::be5a:160f:5418:9deb]) by SYBPR01MB6870.ausprd01.prod.outlook.com ([fe80::be5a:160f:5418:9deb%5]) with mapi id 15.20.7068.030; Sun, 10 Dec 2023 08:16:38 +0000 From: Tianyi Liu To: seanjc@google.com, pbonzini@redhat.com, peterz@infradead.org, mingo@redhat.com, acme@kernel.org Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, kvm@vger.kernel.org, x86@kernel.org, mark.rutland@arm.com, mlevitsk@redhat.com, maz@kernel.org, alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org, irogers@google.com, adrian.hunter@intel.com, Tianyi Liu Subject: [PATCH v3 5/5] perf tools: Support PERF_CONTEXT_GUEST_* flags Date: Sun, 10 Dec 2023 16:16:14 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: X-TMN: [8UVhiSmk+ilYe9quhayyz4kLLAPhV41H68ne61CRE+RkAwuHwNnW+A==] X-ClientProxiedBy: SG2P153CA0040.APCP153.PROD.OUTLOOK.COM (2603:1096:4:c6::9) To SYBPR01MB6870.ausprd01.prod.outlook.com (2603:10c6:10:13d::10) X-Microsoft-Original-Message-ID: <20231210081614.2435-1-i.pear@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SYBPR01MB6870:EE_|MEYPR01MB7339:EE_ X-MS-Office365-Filtering-Correlation-Id: ea4a1d05-76d7-4776-7e34-08dbf958554b X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8KlL61KGK3844bxqcw2mjgws6tBrdbjGDYJLTUij/sCbrkbRQ9yEaxqamA5ScAvluCCmn5N/sVhI7etP8Grtx20mq9nYuREuuIRcf7sQoX35ZkFcaWWTmEmAolzKfhhy9YTa3GIow3x1DrR26RpnEDOhFOMuNMT9ndbUXrdTO1tijtCixldnQ+sEU1TotpzLEfbkByd1J5N5n4yiWMs+LTR0D6uwehA8ypOw9t3SYl8abVWwTxPQkS4YrvIIATv+9isVIdC8MNnxmTY2280yuRPce74WnF9T1W6rPo8+yS5+vNHkEhbetC/Lt8RDf4siTWmeqNdKmPSYoaeuVUIW2x5S4MlENHlbHaRHC6tOLHLGst5kQ86nkYnRruEa/IxMhtVNxPEog3mqZCQWl9afEWTHWlYUXVaDiIJvvTo5SDyIJMmEdHSrMpw9R9ZA+PGiPQVN+gxvxTXjbLm6VZHR++BtBLVp07kbNUeRS1ars6DErcgqyl2y/9SaBJSa3VmT14knUt5Inqj5VSzg5BafYp52mJMIA9vQOCFZAj8EnIbdDW1QwkW5Y2NZ3L/XYz4hUGYPnkkZA7vcVqOWF4SDWoTJShlOFbq/upMwa0P1dF5kFlTg6UvWHSspWoE7MIEv X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: KfEbjl6a6Sqms5Et/MeX36Qw/8VPmzfQ/l24QGo9AzUEAYvEhe/XKQFi0HiUuLdJtjjeWxkV9CbU16DjwhY4NJvTyKQ2Q1IwcOMgnwl9RxhfJfr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cEBxiRkc7HmKWmPnZoQAHa6LqhotUe9DY2aYNWhHlxUjKUz7vDGFn/3Wl25fqPQiWOUZndr1zJsdvrZZY0uAS9VZqthVg+h498A6Ddnq7 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: ea4a1d05-76d7-4776-7e34-08dbf958554b X-MS-Exchange-CrossTenant-AuthSource: SYBPR01MB6870.ausprd01.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2023 08:16:38.9013 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MEYPR01MB7339 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Sun, 10 Dec 2023 00:16:50 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784882099026630371 X-GMAIL-MSGID: 1784882099026630371 The `perf` util currently has an incomplete implementation for the following event flags. Events with these flags will be dropped or be identified as unknown types: `PERF_CONTEXT_GUEST_KERNEL` `PERF_CONTEXT_GUEST_USER` This patch makes `perf script`, `perf timechart` and `perf data` to correctly identify these flags. Signed-off-by: Tianyi Liu --- tools/perf/builtin-timechart.c | 6 ++++++ tools/perf/util/data-convert-json.c | 6 ++++++ tools/perf/util/machine.c | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c index 19d4542ea18a..6a368b6a323e 100644 --- a/tools/perf/builtin-timechart.c +++ b/tools/perf/builtin-timechart.c @@ -536,6 +536,12 @@ static const char *cat_backtrace(union perf_event *event, case PERF_CONTEXT_USER: cpumode = PERF_RECORD_MISC_USER; break; + case PERF_CONTEXT_GUEST_KERNEL: + cpumode = PERF_RECORD_MISC_GUEST_KERNEL; + break; + case PERF_CONTEXT_GUEST_USER: + cpumode = PERF_RECORD_MISC_GUEST_USER; + break; default: pr_debug("invalid callchain context: " "%"PRId64"\n", (s64) ip); diff --git a/tools/perf/util/data-convert-json.c b/tools/perf/util/data-convert-json.c index 5bb3c2ba95ca..62686f78d973 100644 --- a/tools/perf/util/data-convert-json.c +++ b/tools/perf/util/data-convert-json.c @@ -205,6 +205,12 @@ static int process_sample_event(struct perf_tool *tool, case PERF_CONTEXT_USER: cpumode = PERF_RECORD_MISC_USER; break; + case PERF_CONTEXT_GUEST_KERNEL: + cpumode = PERF_RECORD_MISC_GUEST_KERNEL; + break; + case PERF_CONTEXT_GUEST_USER: + cpumode = PERF_RECORD_MISC_GUEST_USER; + break; default: pr_debug("invalid callchain context: %" PRId64 "\n", (s64) ip); diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 90c750150b19..28eac11d0f61 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -2343,6 +2343,12 @@ static int add_callchain_ip(struct thread *thread, case PERF_CONTEXT_USER: *cpumode = PERF_RECORD_MISC_USER; break; + case PERF_CONTEXT_GUEST_KERNEL: + *cpumode = PERF_RECORD_MISC_GUEST_KERNEL; + break; + case PERF_CONTEXT_GUEST_USER: + *cpumode = PERF_RECORD_MISC_GUEST_USER; + break; default: pr_debug("invalid callchain context: " "%"PRId64"\n", (s64) ip);