Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp3396461rdb; Sun, 10 Dec 2023 04:16:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IFLipoIK9/dDKAWhpn577JPcGOtTnb4x5VavgR6DQcanIezdUJvF02Mu3oDg8aJl5ud0XqY X-Received: by 2002:a17:90b:384e:b0:286:6cc1:3f1c with SMTP id nl14-20020a17090b384e00b002866cc13f1cmr2001719pjb.83.1702210609269; Sun, 10 Dec 2023 04:16:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702210609; cv=none; d=google.com; s=arc-20160816; b=EHF0t0aKLY4/Lfd6P5uFtHmKdw8vzjZrKpb/1uVa24aMkhu2Pded5fIUrsbTZ+RPIT 6EZ4h6vFJ0a1obuJcKOJPjG+LiM2TWZt1p3zbfpG+4FpG13XXO3V5sL1CsG8yCDAL0yD 30NEM9qFvs60PdP4ElvJ7QzRUPLDkn7PFWhmHm0jp88Uan4ktYSskyUAvhTGlXpTl4uF HEu0d58CYwwOXSS++LR9dwgk5HF57hEDYoLKTwokG6os9HUocxTCcU8gOfHsyICYl+12 79TVcppfgX/RhkpEbqMhD8RRdR50NeZ+EyA+ypzDDrElDG6+MmDdySdx9fHgzvt+iLXu sSYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature; bh=8ArnvuyoQrBRXgz/NxX9GQDWGcoRO59ZQ9LaupBjsHo=; fh=4o1gjo4DiEltjq+nQLnGXxyiZ2gjsRvJqnWUtbIQ2Uo=; b=UUw/5d1OWI4ysQcnWAyvZ4wHQW8UZFPKD4j7i4MJ8H8Svm63wAkWGJpenUwtReUjWw u0CmV0V56bqH/idoWxq7C4R769AdEUoby41+2brNTInEeKnMYDqHYdtIC/Ji5t+sVmQm ykvkJ7O26k4MXzAq7my/Zk3rsrJH8ZfmegW79Hxn/O1NYe2rTiv6E7NXTuQAr3dhCF1u 5puimpgPb5QOlXFB47bzim1Xjr1YqEj5PVDAY2lH/YdULY5H1k5mSGXEuQhoc2j1oiKU 1A5Rn/5E7dUiA7atDt6bjAjsFLFjgcxdUNM+qkY5tP6OdDj58X/3GOaSOt2JFWh4XjUe mAPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XNGPxpqM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id y8-20020a17090a86c800b0028a4fd5e0aesi2835555pjv.63.2023.12.10.04.16.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Dec 2023 04:16:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XNGPxpqM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id B75FA806BC38; Sun, 10 Dec 2023 04:16:46 -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 S231778AbjLJMQc (ORCPT + 99 others); Sun, 10 Dec 2023 07:16:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229482AbjLJMQb (ORCPT ); Sun, 10 Dec 2023 07:16:31 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BE47101 for ; Sun, 10 Dec 2023 04:16:37 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF365C433C9; Sun, 10 Dec 2023 12:16:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702210596; bh=zI/jeFRyjHplsqmull7ZiNDfoFDcHnPQwoXdDnLIe58=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=XNGPxpqMpKbxiZDIIwqaAP4vnfVrNqeUImkpUgaTvVibWyF+2Td6NYdBTgGCG8ACy eXA05rq0mJvnlQ7bT6gFshJKSrDZ4rRxoaTWphSdn0dyipzHpkw3agwiO4oRHtBnD7 XdrNR6lyCoQZdaOWT6KN330vSSuhzLMDIw7VHQVZNG1PW9RPfHNniNnkap6e+aI6M5 sUdbMPxuS88tY+Ql086/6F63E7KcTUMRyDs0Kxi7qFZyt46iJ4X5z5zftq1SAiXQyX CwA9Nh7Xs5MLIRJvzRv+zGsx2zYl5k+gNoRbrnoZgDDskHAaZyCWViXyAjstMkwJJ4 2EEHczNzYYg+g== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rCIja-002tai-3P; Sun, 10 Dec 2023 12:16:34 +0000 Date: Sun, 10 Dec 2023 12:16:32 +0000 Message-ID: <865y16b6cf.wl-maz@kernel.org> From: Marc Zyngier To: Tianyi Liu Cc: seanjc@google.com, pbonzini@redhat.com, peterz@infradead.org, mingo@redhat.com, acme@kernel.org, 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, alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org, irogers@google.com, adrian.hunter@intel.com Subject: Re: [PATCH v3 1/5] KVM: Add arch specific interfaces for sampling guest callchains In-Reply-To: References: User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/29.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: i.pear@outlook.com, seanjc@google.com, pbonzini@redhat.com, peterz@infradead.org, mingo@redhat.com, acme@kernel.org, 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, alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org, irogers@google.com, adrian.hunter@intel.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 04:16:46 -0800 (PST) On Sun, 10 Dec 2023 08:12:18 +0000, Tianyi Liu wrote: > > 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. It's not complex. It is *unsafe*. Do you see the difference? > > 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; > +} I don't do it very often, but the only thing I can say about this is *NAK*. You have decided to ignore the previous review comments, which is your prerogative. However, I absolutely refuse to add half baked and *dangerous* stuff to the arm64's version of KVM. If you can convince the x86 folks that they absolutely want this, fine by me. But this need to be a buy-in interface, not something that is required for each and every architecture to have stubs, wrongly suggesting that extra work is needed. For arm64, the way to go is to have this in userspace. Which is both easy to implement and safe. And until we have such a userspace implementation as a baseline, I will not consider a kernel version. M. -- Without deviation from the norm, progress is not possible.