Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1626614pxj; Wed, 19 May 2021 10:05:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzz1bEI2XCP+/riaYLieh0oULUffb2ZgvAzw4nq73vN9FdmXLbtKNb0ojf1BKI7nsxrscAq X-Received: by 2002:a05:6402:5169:: with SMTP id d9mr14212ede.347.1621443929492; Wed, 19 May 2021 10:05:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621443929; cv=none; d=google.com; s=arc-20160816; b=EXvV5S5z0IpnCF4GQUKNcnwdVK03FGLEs3eXdc3C3a4r/F9vUVjIt6dbASVxKPSzIP iQ1GceSb/3fz2kLo+KKrGaPZ94j6sRiVsLM48dx7Ix0mOkRB+pkc17lULXa96D8AkuiG D6jGIFfQmG/5ocFcM6PHXeD04qZ8q8GARW5peCKNEph9EUhUY2GU1QXA+FUqatpz194o 1Sgtf5WS5HM2HbNE6fK2EEx2ShxcTwHyhynG/F2gQqonOY28QBVZqmlWTzs9chO8MTda e1VFMy+C+s+k2vlqtZm0iaMyEdlPlRC2Q1jJwHcZ8ShIU0Ejzonb/roVtjKpQFN50gMT vmwg== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=oLX06SvNo3MjZQD/51KQtJ1+KOvlvX5HnF5jVxIhJ2s=; b=K0EhTF1gInCc5bTXaL9ebjkGzM1XPX6ybQSF1nIpqMqohbTpR76NHEScY+GClDBsiH CchCI13ULdTH2ByNsC2dbkG2F3EbCt+4Px1pyFdG549zXglQZT5IZjL7q3RNx6qdmqwp gKhQ+zGOzJZbH27/pTXJfoqlw7fovPnkAgQvSQFy4x1wW7jcxJMmAkXpQEkTsBXS8xxO J7BygTPD4cUUXalB0ynWxSNkH3/+QThwnlVd/mxRirS7HuQ5Of3h1aNUdSnvp+TdGtiy +w2rpE4fqulHEA9nXEZ/yTDJ59oh45+0uWn+GurebEn6FG3UT8Dl20Vs5kSysapfNsTy J+hQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=EJKwgrdB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w9si759432edc.430.2021.05.19.10.05.05; Wed, 19 May 2021 10:05:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=EJKwgrdB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241704AbhERIk7 (ORCPT + 99 others); Tue, 18 May 2021 04:40:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347546AbhERIkq (ORCPT ); Tue, 18 May 2021 04:40:46 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BB43C061756; Tue, 18 May 2021 01:39:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=oLX06SvNo3MjZQD/51KQtJ1+KOvlvX5HnF5jVxIhJ2s=; b=EJKwgrdBNoAJQBcM1a+qXcU58X ufdldCqyZtZg7taAcR3bY73VKd/RcTNJFJINv+Hz7D658IyYipL1mFfdDuXfOE2R5ynjs9DRHYqPJ apDPlxzzKnYjUoVifboA42DEF9yaIPBXnQNEHgzgx5fUitm70X2GYSD6BIc/fEXHfPDfRsNg2DCnM ZnY7Wc8YErU/szLvDoGrjr1AcD3juaMUWujsd75m3/dFpJr6Zl3MnOUwwKmXwqhH3NTEtWr9INEv9 eyxNqT4Hm65/XF3QXVXvwWi150mH+gh4x1WS46aDjCAUHVDju7OsbmwNv29WxCYWJb91rzECGE4Ik N7BkBtIg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1livEZ-00DoCb-1W; Tue, 18 May 2021 08:37:53 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 99BC530022A; Tue, 18 May 2021 10:37:46 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 8366D2BE6E843; Tue, 18 May 2021 10:37:46 +0200 (CEST) Date: Tue, 18 May 2021 10:37:46 +0200 From: Peter Zijlstra To: "Xu, Like" Cc: Paolo Bonzini , Borislav Petkov , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , weijiang.yang@intel.com, Kan Liang , ak@linux.intel.com, wei.w.wang@intel.com, eranian@google.com, liuxiangdong5@huawei.com, linux-kernel@vger.kernel.org, x86@kernel.org, kvm@vger.kernel.org, Like Xu Subject: Re: [PATCH v6 02/16] perf/x86/intel: Handle guest PEBS overflow PMI for KVM guest Message-ID: References: <20210511024214.280733-1-like.xu@linux.intel.com> <20210511024214.280733-3-like.xu@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 18, 2021 at 03:38:52PM +0800, Xu, Like wrote: > > I'm thinking you have your conditions in the wrong order; would it not > > be much cheaper to first check: '!x86_pmu.pebs_active || !guest_pebs_idx' > > than to do that horrible indirect ->is_in_guest() call? > > > > After all, if the guest doesn't have PEBS enabled, who cares if we're > > currently in a guest or not. > > Yes, it makes sense. How about: > > @@ -2833,6 +2867,10 @@ static int handle_pmi_common(struct pt_regs *regs, > u64 status) > ??????????????? u64 pebs_enabled = cpuc->pebs_enabled; > > ??????????????? handled++; > +?????????????? if (x86_pmu.pebs_vmx && x86_pmu.pebs_active && > +?????????????????? (cpuc->pebs_enabled & ~cpuc->intel_ctrl_host_mask) && > +?????????????????? (static_call(x86_guest_state)() & PERF_GUEST_ACTIVE)) > +?????????????????????? x86_pmu_handle_guest_pebs(regs, &data); This is terruble, just call x86_pmu_handle_guest_pebs() unconditionally and put all the ugly inside it. > ??????????????? x86_pmu.drain_pebs(regs, &data); > ??????????????? status &= intel_ctrl | GLOBAL_STATUS_TRACE_TOPAPMI; > > > > > Also, something like the below perhaps (arm64 and xen need fixing up at > > the very least) could make all that perf_guest_cbs stuff suck less. > > How about the commit message for your below patch: > > From: "Peter Zijlstra (Intel)" > > x86/core: Use static_call to rewrite perf_guest_info_callbacks > > The two fields named "is_in_guest" and "is_user_mode" in > perf_guest_info_callbacks are replaced with a new multiplexed member > named "state", and the "get_guest_ip" field will be renamed to "get_ip". > > The application of DEFINE_STATIC_CALL_RET0 (arm64 and xen need fixing > up at the very least) could make all that perf_guest_cbs stuff suck less. > For KVM, these callbacks will be updated in the kvm_arch_init(). > > Signed-off-by: Peter Zijlstra (Intel) Well, you *do* need to fix up arm64 and xen, we can't very well break their builds can we now. > ---- > > I'm not sue if you have a strong reason to violate the check-patch rule: > > ERROR: Using weak declarations can have unintended link defects > #238: FILE: include/linux/perf_event.h:1242: > +extern void __weak arch_perf_update_guest_cbs(void); Copy/paste fail I think. I didn't really put much effort into the patch, only made sure defconfig+kvm_guest.config compiled.