Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp949161rdg; Wed, 11 Oct 2023 09:46:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFtZ006HOxP0BpxoMiLdJGjibjJTcUDNCd8+IC6Cpj+NtBgp7LA8J6HqcIr2zCeY7OlniNu X-Received: by 2002:a05:6a20:4422:b0:16b:d137:dfb3 with SMTP id ce34-20020a056a20442200b0016bd137dfb3mr20471174pzb.59.1697042786895; Wed, 11 Oct 2023 09:46:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697042786; cv=none; d=google.com; s=arc-20160816; b=L7UEO7/D+CezamPuVhop/Rlb6rIuzRegBm1mUNXTZ5Um2fBq3cbZ2uDyBuNUFlSpdL QdwGqEvLShBrEj4hKe8kEmxGSIiRR6WiVRuerbT6QQ4FD710/qs+meDk9q8wkHqdGoJy 3sSj9X2w7DxTxA913vm2p3GfBTfCq88Yy3FFz9UNIiH0rlmkrdzCna1OV26EzAjgVU2q zNjHE2pDi7XrF6N6rItL6/ckc+c/a/A5esJUOkDOwMg3bae8H+wiF5mJhc0Z3z3lWbWx GuwZp/M6HGYOsmiq/HktfPKYjKu0XWpYE2IViaa39tmq5dDRbc/k0ndoaVz+03IdAkiu Gs3A== 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=Ptm2E8sbP0SyENLiEqQSfBH23UIjB1d/sSa2bA82XC8=; fh=kbqw29EMVG0lbm/9uiNfEq4oD//qDM89O87SZPiYi6o=; b=UwpZgrzWztZ+mkCNn2VVkaKhKIR7bZwdlq6a8tr0Z4Ad7Q5bUU1cX5MlkJ4FgRvUOi 5ndvREb/E+TQLTWHsnCmxzf7+bLlm22RWE6XewwB2OnAr16k7XcSVlz3HwDirbkiXq1b qtlaPmuSFHuhEGGtFbJhVEZ5Rm8HrC6HWIR2QzluPNTD8HT/WgFKjF8b/ye1fjJo7f6d J0ZRs4LxH3B25gPqyvhyuszFvtXt3dl9q0CcX+EM/zCkLX76tpnxVPQCWFB8gTsdND76 ZennIaPD7MwioVCfgGdq4yvEvDfXw72PWCxyG23GcbIWRjH8yoF8yzrLuwXzoQRCSH6i 1haQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dtxmhkay; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id g10-20020a63dd4a000000b005a1d88169casi149741pgj.189.2023.10.11.09.46.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 09:46:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dtxmhkay; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id 1E647807BED8; Wed, 11 Oct 2023 09:46:24 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235136AbjJKQpp (ORCPT + 99 others); Wed, 11 Oct 2023 12:45:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235114AbjJKQpk (ORCPT ); Wed, 11 Oct 2023 12:45:40 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EB60B7; Wed, 11 Oct 2023 09:45:38 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2CC1EC433C7; Wed, 11 Oct 2023 16:45:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697042738; bh=Gszkr6ytwYAWj77761HPc4xxX6XKWbdeQEVhpa208hM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=dtxmhkayGxf0TZptHCQp2gsnsvH2XldyeRAADcrby7Ysmpyl05/MP5u9QgwOA2o1P DbRv0VeNO+P7UFFRxSMDOTTK4j213srQCPgK4OQjOuBM17Lz/Yq+6djsegBECYCi9z 8i9dJ1K5qKXeOYlMwUeAohGPHNeW3ZmwEM3WWMFz5jz81V7z77a7umSHScM083mgmS SG1xL3eEjuLWPsHm8PxGJn60d+dAWe03wsyNWeSs+K4Hz1L1ZSH1Hs+l9HqLJnGFak +Jy2abvU6Ig10vflOk7hganeEUNBbh1oKJFB0fltA2MmUkYjO9/RSoY1M5oDw5Z6Q0 P2KEF0Itn0vKQ== Received: from [104.132.1.97] (helo=wait-a-minute.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 1qqcL1-003DWa-8a; Wed, 11 Oct 2023 17:45:35 +0100 Date: Wed, 11 Oct 2023 17:45:29 +0100 Message-ID: <8734yhm7km.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, alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org, irogers@google.com, adrian.hunter@intel.com Subject: Re: [PATCH v2 0/5] perf: KVM: Enable callchains for guests 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/28.2 (x86_64-pc-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: 104.132.1.97 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, 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=2.4 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Wed, 11 Oct 2023 09:46:24 -0700 (PDT) X-Spam-Level: ** On Sun, 08 Oct 2023 15:48:17 +0100, Tianyi Liu wrote: > > Hi there, > > This series of patches enables callchains for guests (used by perf kvm), > which holds the top spot on the perf wiki TODO list [1]. This allows users > to perform guest OS callchain or performance analysis from external > using PMU events. > > The event processing flow is as follows (shown as backtrace): > #0 kvm_arch_vcpu_get_frame_pointer / kvm_arch_vcpu_read_virt (per arch) > #1 kvm_guest_get_frame_pointer / kvm_guest_read_virt > > #2 perf_guest_get_frame_pointer / perf_guest_read_virt > #3 perf_callchain_guest > #4 get_perf_callchain > #5 perf_callchain > > Between #0 and #1 is the interface between KVM and the arch-specific > impl, while between #1 and #2 is the interface between Perf and KVM. > The 1st patch implements #0. The 2nd patch extends interfaces between #1 > and #2, while the 3rd patch implements #1. The 4th patch implements #3 > and modifies #4 #5. The last patch is for userspace utils. > > Since arm64 hasn't provided some foundational infrastructure (interface > for reading from a virtual address of guest), the arm64 implementation > is stubbed for now because it's a bit complex, and will be implemented > later. I hope you realise that such an "interface" would be, by definition, fragile and very likely to break in a subtle way. The only existing case where we walk the guest's page tables is for NV, and even that is extremely fragile. Given that, I really wonder why this needs to happen in the kernel. Userspace has all the required information to interrupt a vcpu and walk its current context, without any additional kernel support. What are the bits here that cannot be implemented anywhere else? > > Tested with both 32-bit and 64-bit guest operating systems / unikernels, > that `perf script` could correctly show the certain callchains. > FlameGraphs can also be generated with this series of patches and [2]. > > Any feedback will be greatly appreciated. > > [1] https://perf.wiki.kernel.org/index.php/Todo > [2] https://github.com/brendangregg/FlameGraph > > v1: > https://lore.kernel.org/kvm/SYYP282MB108686A73C0F896D90D246569DE5A@SYYP282MB1086.AUSP282.PROD.OUTLOOK.COM/ > > Changes since v1: > - v1 only includes partial KVM modifications, while v2 is a complete > implementation. Also updated based on Sean's feedback. > > Tianyi Liu (5): > KVM: Add arch specific interfaces for sampling guest callchains > perf kvm: Introduce guest interfaces for sampling callchains > KVM: implement new perf interfaces > perf kvm: Support sampling guest callchains > perf tools: Support PERF_CONTEXT_GUEST_* flags > > arch/arm64/kvm/arm.c | 17 +++++++++ Given that there is more to KVM than just arm64 and x86, I suggest that you move the lack of support for this feature into the main KVM code. Thanks, M. -- Without deviation from the norm, progress is not possible.