Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp214906iob; Wed, 11 May 2022 12:48:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3QMz6gV67vXrcFHXZCyoQtJWWe3Q5ZdFWHKNF+HaeYPGNaVzaCz5f1ubKjrr8V0f186/q X-Received: by 2002:a05:6a00:2282:b0:50e:552:973a with SMTP id f2-20020a056a00228200b0050e0552973amr25989060pfe.79.1652298485092; Wed, 11 May 2022 12:48:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652298485; cv=none; d=google.com; s=arc-20160816; b=RQbDNhn7UxJDTCqb/U9HiPLyJL+40CeYTA+90bczNl1cumeXl4mUCFwPqXF/yssPxS D9NQYYE4MwnpFiDcAudxiodCRuznDh2OjiGQ+c+m9ERp/3xYmgvOJV428tISTn45Qsoc 7sz7bQUuRx+fFUqMyVmtWI0gT4TyhERarXVhZ9mLpYC5FrkTYv2AwcTfyPpQ2Pn4GFkO hp5rQx00LETtNIobGL9JsfbFJK+HogcD/qzLt9PPNxw0UJxANwyTDnJc3vmLXnWxs6Bw DcYeoAGtKskQzj4BaQLf5NHURm8r3E+qbTwuYjHjcla3J3hzfvTDz8aSECWFBgxyzYOQ OC/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=wsALrmg81reRYjusfhpQJi5XuwMynf7MqUJQVdaBvHw=; b=bHrLhgtTRePxMPKwNfr3Y635QS3fF1849KeswqET6obA9bsyuyxRbsM2xARnbbgoxH 1dsd7P3x0uJ5nC4wmBpKNYbk8IeJDea/XdejmX7sa3bNwxz6EYdC+3DvGOjd6RlRoGo2 0zSaLsvsbpw/e7WZ7c6mthP7KAl/sPAaWVhgXMuAPIT2SYGfxbvNreocMbKBahZOuYip X96dMT6qA3qtfjeoNhYopzvx5a5v5ZPCzyIQI9tLC4tYYPNmkhTw4KYQtfHEdKJ1FLfs 68rENjWgUoMMOhAhYh9iQurXrPFrwZawsw6CUExP9xt7NP9pYy25evRlxVo/+DDN0Y2H bX/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=OiBTGgjV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j5-20020a635945000000b003c637999d7bsi549028pgm.842.2022.05.11.12.47.36; Wed, 11 May 2022 12:48:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=OiBTGgjV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238785AbiEKQqx (ORCPT + 99 others); Wed, 11 May 2022 12:46:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344964AbiEKQqu (ORCPT ); Wed, 11 May 2022 12:46:50 -0400 Received: from mail-oa1-x33.google.com (mail-oa1-x33.google.com [IPv6:2001:4860:4864:20::33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B4594A914 for ; Wed, 11 May 2022 09:46:49 -0700 (PDT) Received: by mail-oa1-x33.google.com with SMTP id 586e51a60fabf-e2fa360f6dso3520027fac.2 for ; Wed, 11 May 2022 09:46:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=wsALrmg81reRYjusfhpQJi5XuwMynf7MqUJQVdaBvHw=; b=OiBTGgjVA2lJSpPdzWVWyduwfMWVgS3jcA03WIu9eLReYnjSMcZJlIyJKyeRgO5krA r9ea6y6JudBS7Kn3X87k0vglWNIeOU1ZbpxwzgRp0gPXMe2qk+Wr1WHDptWY8aW97bOB IHI5WravnVge1twk44jV/GaM4hH9tAS0QwyNt8gUcvXqPd46MNcfFFPcoN9dOozTheJr JIqgPTicoH6Qnb6gRUflB1wldcRQfY3LFJX6HsFfFfC13bxNc8W8c81R5yTBhkvhw4aR nxluWjLCGQEa5ps2SyESVR8UjmNJIV4X5NyoitNyD/7k/blHjjYdyIh4TqYkJk0i2oAW 8dGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=wsALrmg81reRYjusfhpQJi5XuwMynf7MqUJQVdaBvHw=; b=LbkntS3ra7xCUi0uBnqZdHT+DYCe9vCppbzj/82vd8l45BvP7Ixn9dMYCqE5Pyvuf6 RvPv4imd8LTzyJKUyZjcYtQmx6/g1OEFJGlMpPO51BF1sU4znSxH2nJDWA13XMHIJHhd hgknN+pXnNsNwcBKYTSVqgOYmQ2HVjOohMbiRCkRTEBXhhQQW/11B90fApOf7ykwV66K bThYo4W4HHle2jEP2cx59lx91L1ZOZJ/W5oiD2JtAoTbCTUG63qtjUucTq4fvOHskvUS 1/hCbYZ2NDCD1Vi3K6H/WaGiHwoULJVvkJAunBjyPeP61jdn4scXZH+2D61YNAQt1DqB opOA== X-Gm-Message-State: AOAM533K2ZcDFBXQcF689c/m1ia5q2mjzLsIkxg4sF1Ml9m9uafqAzbj 4yEYLg/GPEOcFHRJdWVYASVQJwCUXgkF7HrBSopZoQ== X-Received: by 2002:a05:6870:f719:b0:d6:e0c0:af42 with SMTP id ej25-20020a056870f71900b000d6e0c0af42mr3050194oab.165.1652287608355; Wed, 11 May 2022 09:46:48 -0700 (PDT) MIME-Version: 1.0 References: <20220412195846.3692374-1-zhanwei@google.com> <20220412195846.3692374-2-zhanwei@google.com> In-Reply-To: From: Wei Zhang Date: Wed, 11 May 2022 18:45:00 +0200 Message-ID: Subject: Re: [PATCH 1/2] KVM: x86: allow guest to send its _stext for kvm profiling To: Sean Christopherson Cc: Suleiman Souhlal , Sangwhan Moon , Ingo Molnar , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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 On Tue, May 10, 2022 at 1:55 AM Sean Christopherson wrote: > > On Tue, Apr 12, 2022, Wei Zhang wrote: > > The profiling buffer is indexed by (pc - _stext) in do_profile_hits(), > > which doesn't work for KVM profiling because the pc represents an address > > in the guest kernel. readprofile is broken in this case, unless the guest > > kernel happens to have the same _stext as the host kernel. > > > > This patch adds a new hypercall so guests could send its _stext to the > > host, which will then be used to adjust the calculation for KVM profiling. > > Disclaimer, I know nothing about using profiling. > > Why not just omit the _stext adjustment and profile the raw guest RIP? It seems > like userspace needs to know about the guest layout in order to make use of profling > info, so why not report raw info and let host userspace do all adjustments? It's hard to store raw IPs if we want to reuse the existing profiling facility. The profiling function is initially used to store the current IP at each clock tick for the host kernel. The original design avoided the trouble of storing raw IPs by creating a buffer array with a length of (_etext - _stext) and do buffer[IP - _stext]++ at each clock tick. In the user space, the readprofile command could read it from /proc/profile and tell us roughly how many ticks occurred in each kernel function with a map file. (IP - _stext) has a clear meaning here since it gives us an offset with respect to the start of the text segment. This gets tricky after the profile=kvm boot option was introduced (https://github.com/torvalds/linux/commit/07031e14) because (IP - _stext) is no longer meaningful. I think raw guest IPs are easy to consume by userspace tools. But we probably need to go with a different approach if we want to store raw guest IPs.