Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp5562225iob; Mon, 9 May 2022 20:48:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2mo9TVf2wlAxTaZ6pQd7bwyXyoDaf24jo0mESR2itbjNeGdk+UtvDDgq/mxzMF0U05O7U X-Received: by 2002:a17:907:60d4:b0:6f5:2d67:4828 with SMTP id hv20-20020a17090760d400b006f52d674828mr16332241ejc.216.1652154483132; Mon, 09 May 2022 20:48:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652154483; cv=none; d=google.com; s=arc-20160816; b=dXmiDWnRuO6X6NkTHdQx93PxhlDFeVuTtN5+W6MixFM2Jz7axwvcq8lbPZwdMMCIku aEXywlNC7H5j0GuU777TsDIMHTzha8xtoBGQNGrUtLS1SNI/yvgZnozfg2JT8RqLpFMq jOp+efznZZ3K/2+gTHj6vm+hhiRUMuiwW8dquVPSI/B8G8MalF0PgUWLOSlFbp7ynGAZ U6womjctHdNOwBj7MgZpVGPwtHXKnDf/LAb2tbi/xcJwvcXYVYv2KxfVay8UvImXL0lZ c4X8MjkaT+0t7vxRFVdHQNiGqm37aJDguFHsK1Urjui6NFI1GzM5FMjtwFhTvB6ZQGee UJlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=O78xywV/WeUMZw6P+ZnHpCQ7tZ+vR8qII19ouyYA5rU=; b=GZf61WH+8bHspIFPI4XLidcOUvzJEApHoVlgitLyZR4Pz2B8AE4RjYkyYWL10TPBzA OyP8do3Y+O8+Scjwvj6kIFxKarQo+Wq5UB4lX4Q4VhS7NNHiLWDXlq7MBfQAHBbLCOVp 6yUVCWCEMxTy1Lbf0lVwWy9+HZLpA8vlxFnXDEIT03AdKnLq67J12u6K3HJzvMcA4pB8 +Qfbbqzc1jiok4IkQy7UEZVEvAcUA8id82QQcLK4VFWXa040Hj96l4IrbQFVBdS7nRO1 mGdMyFAhr7nce5Fd8hM5gDWxNyxKl3w5EVcJyr/LBKq8Izulq2TZkAHZHLuV1bte8ss9 sOGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Es7HhFKC; 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 k6-20020a170906128600b006f4fc3e2c3esi13703965ejb.878.2022.05.09.20.47.39; Mon, 09 May 2022 20:48:03 -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=Es7HhFKC; 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 S233160AbiEIX7G (ORCPT + 99 others); Mon, 9 May 2022 19:59:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232632AbiEIX7E (ORCPT ); Mon, 9 May 2022 19:59:04 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2366529B81A for ; Mon, 9 May 2022 16:55:09 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id s14so15321996plk.8 for ; Mon, 09 May 2022 16:55:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=O78xywV/WeUMZw6P+ZnHpCQ7tZ+vR8qII19ouyYA5rU=; b=Es7HhFKCIeaWF1sF/V4rHwVPw2S15afmHGuDUtoTm3zrXHozb/yFik/SGvyGUaGNeR TnOcaBofWYugjbi8ZXo5H9XHRgDHmcSLL09mIW0fOS/u6NHz4rY7S79agxEZF9llteML Q0rw+LCw9kWNiksl3g4o6ky3qE2GkvUh02te31ekng1EC+CY/DHveXzR2idBQHlKQ4vj w6DSePuUpzVBGh0S5hO5X4yyJeXYrcbp7z22jclrug2KK07BCYsgCVycZSkG1OskgbHX oPi2K3EkWB4i39WMP7PlxmrreZKiJy/7P4oFJoW2WpgMAleGo6EOjrRrfP94nQLh2+gj m/6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=O78xywV/WeUMZw6P+ZnHpCQ7tZ+vR8qII19ouyYA5rU=; b=rAY5VyYHB5FyGsZ8zb46zH/TUIPMKaouRGmpjwUZFRR6DJwjTLi5MMUAz8T+2B3LI5 ayLNUQ0NPKdkUEwSJHBwVFcFM//PPNqYqiqmprNMgUNJRqnl7Er0UyDzDO36QsVNQBS5 YrhRj2gBSafFjW8qFkXwmYRUgMZtO6w0lVy/9a+sG1BFChoxvxKk1uZqNhDdz9VtUKoe 4FeSCiORVxboVfsCmP/sChTbaoT75ZKbmpnipmtY4nB3/E9n5kdbEPDlRe+2/EL/v+im vsyJ8xT4fdLDT9VpjCaIuVujFvL3zdTrumCLt/AZXHgtMNg7uSy28j0/NKrxrtRF48xX ed1g== X-Gm-Message-State: AOAM533pwLylpeQ8n/v6ld5FTH9TM/XiBtROjpTtXGddMjQgoRsRbgwu PZMySNwizVu8FVKrahf0uf0iVw== X-Received: by 2002:a17:903:228e:b0:15e:9462:b058 with SMTP id b14-20020a170903228e00b0015e9462b058mr18359407plh.64.1652140508432; Mon, 09 May 2022 16:55:08 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id k70-20020a638449000000b003c6445e2aa8sm7212096pgd.4.2022.05.09.16.55.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 16:55:08 -0700 (PDT) Date: Mon, 9 May 2022 23:55:04 +0000 From: Sean Christopherson To: Wei Zhang 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 Subject: Re: [PATCH 1/2] KVM: x86: allow guest to send its _stext for kvm profiling Message-ID: References: <20220412195846.3692374-1-zhanwei@google.com> <20220412195846.3692374-2-zhanwei@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220412195846.3692374-2-zhanwei@google.com> 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, 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? > Signed-off-by: Wei Zhang > --- > arch/x86/kvm/x86.c | 15 +++++++++++++++ > include/linux/kvm_host.h | 4 ++++ > include/uapi/linux/kvm_para.h | 1 + > virt/kvm/Kconfig | 5 +++++ > 4 files changed, 25 insertions(+) > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 547ba00ef64f..abeacdd5d362 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -9246,6 +9246,12 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) > vcpu->arch.complete_userspace_io = complete_hypercall_exit; > return 0; > } > +#ifdef CONFIG_ACCURATE_KVM_PROFILING > + case KVM_HC_GUEST_STEXT: > + vcpu->kvm->guest_stext = a0; Rather than snapshot the guest offset, snapshot the delta. E.g. vcpu->kvm->arch.guest_stext_offset = (unsigned long)_stext - a0; Then the profiling flow can just be unsigned long rip; rip = kvm_rip_read(vcpu) + vcpu->kvm->arch.guest_text_offset; profile_hit(KVM_PROFILING, (void *)rip); > + ret = 0; > + break; > +#endif > default: > ret = -KVM_ENOSYS; > break; > @@ -10261,6 +10267,15 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) > */ > if (unlikely(prof_on == KVM_PROFILING)) { > unsigned long rip = kvm_rip_read(vcpu); > +#ifdef CONFIG_ACCURATE_KVM_PROFILING A Kconfig, and really any #define, is completely unnecessary. This is all x86 code, just throw the offest into struct kvm_arch.