Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp745572rwe; Thu, 25 Aug 2022 08:26:23 -0700 (PDT) X-Google-Smtp-Source: AA6agR4dYLCRjna1uqDJfmtvZbXPTPssfjlKgH9LsKjWuNJxpAnEBtr5sQrw2OyoQF/UeuTGVfpW X-Received: by 2002:a17:907:391:b0:73d:c7d5:bb51 with SMTP id ss17-20020a170907039100b0073dc7d5bb51mr2926536ejb.177.1661441182906; Thu, 25 Aug 2022 08:26:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661441182; cv=none; d=google.com; s=arc-20160816; b=EDZ5CRJ2wCRMlKEDbv6WihF+eFBQQq0nL0X/iEvxgB2CltUdG8IzfdScTvt0hpJ+pw +bfYVpkqL0s95h58Fw7tnW0uI+bYV4HojRDc5vTvX2ll0htqCxcENXzFO+vpVIWfPHjF xo+Jbo58MRAWfyFc8vP01rojmRfePlG3UBcSTHHt8OihsedGzWV/jyoczym+d/s8BVgz T6iJGiuz9+NLBWZf7/3qcXSfi8MCNz3lf0e9Sd/6hr69NHs2gZdUHOx8vYhaotBFwZhR NEAxqVSUCctZbF/JMfmy32NQwFtTSEs+jTShdkXUr9dW/IPp3MCn+vT4rv9fw6vFZTCJ F8gA== 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=AHkYLosTUlLzDn2E62SzaMtiFX4B6CYSNh1rEJtPsS4=; b=Sw1ai2cgBhIU+C2Fm+4005kifhMUDUPJLiTzMofyQJz3URKZWwemtYDLGT8PaB1nEO MuJs1vAEHvVU4QvVN4TbU33SUYQYR88bk7dhM39xKeHLPB4OujuiwgzROzgIXA5fNT9V u4Ki6D4p4hUDsdVrVbvF4qkyBgErhJa/BYmcJg7gBAfDAJ515UM/7JnMwhcFo/tQEV+T RT3JhtOllrZaPpQ8pXoKoDe0KcGBOi7lhFbmpduC776Cji2QSM9/VKto7iCJVJFfj1ty uNxROhZs8SjoGzRYnX2NkXxzwpCwavspxNDlM3txQZbXU1tBRXqA5zpJgzgX1rCs8BBx lIlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=XPykrXJn; 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 s2-20020a17090699c200b00718d0604af4si4060122ejn.604.2022.08.25.08.25.55; Thu, 25 Aug 2022 08:26:22 -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=XPykrXJn; 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 S239959AbiHYPXe (ORCPT + 99 others); Thu, 25 Aug 2022 11:23:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236230AbiHYPXc (ORCPT ); Thu, 25 Aug 2022 11:23:32 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DE2AB8F19 for ; Thu, 25 Aug 2022 08:23:31 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id w88-20020a17090a6be100b001fbb0f0b013so2116810pjj.5 for ; Thu, 25 Aug 2022 08:23:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc; bh=AHkYLosTUlLzDn2E62SzaMtiFX4B6CYSNh1rEJtPsS4=; b=XPykrXJnPtaVVrcd0/FJM5bJ9x9N5oHBNowUK8REQaSIxJQ5fgVKbic+daIEsTLBOU IKpjQwIrvsj2ME1uePBk8XBmSpeHN/Y2DAjzHA+GXh4eJsBGKETloAde1aQkHimPT58b pvkTlFbtDXHIWrRapcCaWLNnpo2MANPsafKsdX2vDNg9JyB+N/CNIBhTCExmOO4xajXP Ksc0vDokShK7dWI3bwEkRrkkriGPpqpMxrUePfPivUBdZqMNTqxAJsVpJXbi3qIDuwwR RNDAYnIPXqv8vjH3P8dK8RCHGhR0KYCCuM+W7aZ0RFngklXvwzrIJhcKzgYimQ1naZty 7cnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=AHkYLosTUlLzDn2E62SzaMtiFX4B6CYSNh1rEJtPsS4=; b=hevAVNVsyJ9wAWOMFyTx7btWbGchRvRzAYJL5j7gvlJhq1aLHfkZst8ohU58te7h2l FdHFJpGakFr4hKfBj2pOOUfi8BPQDywNW7aCQlcOwcgzgXVjEAqsB/ppaqBToUvHb3ND rP2giVKrG31Md4fKnebST5oEMGZdmIKGSGlkpaId4AlVPDKyKeD+y+ByOW2w8xV8cg5d LqZxxkziBx/+l3sJVMmgeXYCqHEoTaFDb/AyB+IrcDCCIV/cOECtDkX8qt7MjbS0T7By Qqjqxzdsdz7jhzsQavMpdLw7iEqn9R73w9IwPrFYZ0I5aAydFIk5JqVewdH/1+vviGc3 f39g== X-Gm-Message-State: ACgBeo1sCkk5QPZE+g8u2PdFMe7B9A01/Mp1G7R7kscYKFrnqQAGhM9H VqB4+9PCc0WiE/dvnRKWDUpfvw== X-Received: by 2002:a17:902:ce81:b0:172:9ac1:6ee with SMTP id f1-20020a170902ce8100b001729ac106eemr4104207plg.93.1661441010644; Thu, 25 Aug 2022 08:23:30 -0700 (PDT) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id u4-20020a17090a1f0400b001fa79c1de15sm3640192pja.24.2022.08.25.08.23.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Aug 2022 08:23:30 -0700 (PDT) Date: Thu, 25 Aug 2022 15:23:26 +0000 From: Sean Christopherson To: Xiaoyao Li Cc: Peter Zijlstra , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Paolo Bonzini , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: Re: [RFC PATCH 1/2] perf/x86/intel/pt: Introduce intel_pt_{stop,resume}() Message-ID: References: <20220825085625.867763-1-xiaoyao.li@intel.com> <20220825085625.867763-2-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220825085625.867763-2-xiaoyao.li@intel.com> X-Spam-Status: No, score=-14.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,FSL_HELO_FAKE,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=no 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 Thu, Aug 25, 2022, Xiaoyao Li wrote: > KVM supports PT_MODE_HOST_GUEST mode for Intel PT that host and guest > have separate Intel PT configurations and work independently. In that > mdoe, KVM needs to context switch all the Intel PT configurations > between host and guest on VM-entry and VM-exit. > > Before VM-entry, if Intel PT is enabled on host, KVM needs to disable it > first so as to context switch the PT configurations. After VM exit, KVM > needs to re-enable Intel PT for host. Currently, KVM achieves it by > manually toggle MSR_IA32_RTIT_CTL.TRACEEN bit to en/dis-able Intel PT. > > However, PT PMI can be delivered after MSR_IA32_RTIT_CTL.TRACEEN bit is > cleared. PT PMI handler changes PT MSRs and re-enable PT, that leads to > 1) VM-entry failure of guest 2) KVM stores stale value of PT MSRs. > > To solve the problems, expose two interfaces for KVM to stop and > resume the PT tracing. > > Signed-off-by: Xiaoyao Li > --- > arch/x86/events/intel/pt.c | 11 ++++++++++- > arch/x86/include/asm/intel_pt.h | 6 ++++-- > arch/x86/kernel/crash.c | 4 ++-- > 3 files changed, 16 insertions(+), 5 deletions(-) > > diff --git a/arch/x86/events/intel/pt.c b/arch/x86/events/intel/pt.c > index 82ef87e9a897..55fc02036ff1 100644 > --- a/arch/x86/events/intel/pt.c > +++ b/arch/x86/events/intel/pt.c > @@ -1730,13 +1730,22 @@ static int pt_event_init(struct perf_event *event) > return 0; > } > > -void cpu_emergency_stop_pt(void) > +void intel_pt_stop(void) > { > struct pt *pt = this_cpu_ptr(&pt_ctx); > > if (pt->handle.event) > pt_event_stop(pt->handle.event, PERF_EF_UPDATE); > } > +EXPORT_SYMBOL_GPL(intel_pt_stop); > + > +void intel_pt_resume(void) { Curly brace goes on its own line. > + struct pt *pt = this_cpu_ptr(&pt_ctx); > + > + if (pt->handle.event) > + pt_event_start(pt->handle.event, 0); > +} > +EXPORT_SYMBOL_GPL(intel_pt_resume); > > int is_intel_pt_event(struct perf_event *event) > {