Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp159457pxb; Fri, 15 Jan 2021 09:45:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJwqMf++zgeWzi5lXZjNYrP71dGgXkYMQPNQ39l7OkhmSNE9hyRQU7taJml3q81I0VcYfVTi X-Received: by 2002:a17:906:653:: with SMTP id t19mr9666978ejb.44.1610732710559; Fri, 15 Jan 2021 09:45:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610732710; cv=none; d=google.com; s=arc-20160816; b=Kgy661D1zm2K8N/y2+v9I4cnr/LigQiP7X4GiTh4v/fTqjq3y8IRoRQDcR5/zuVwKi 7yGs8qB8/nAWMN42YITrcSGSLeju2WNBfOht8QujKkt5JyUebZOsU9OWeYDxk4KDuhpx vQeDIHCiLZbhZFlhZZ1eO/UuiFdX6D4yvVHItK42ToQ1GxVdSOljrf8yuDpAV625AkU5 N3vrN+MTYMKz/v0w/Z/TJhjx/CgJUJZFYbUB6+E6lkk1Z0/xz0uMv6zN/SrqbqrWEuhp Vpk28a7qHvZpBRAW1vibtAFpLNtNtNhFok/ocrrnNGqnY+buLcIPTpaetuxh3J4/jKR+ bSEA== 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=HHcrPMunMXLd4pGO1neHtBLweNEDPBq5DPbqA2qARP4=; b=gJ7WPNkIDAbGrby8ppUldHRpgrAyN2eTCt92fasebI6rLuSgFu0k6wgf2yBHMlPXTy d1WPMjabtcpiRNNtIFJ8p7trpIaiQB+VOk9cy3EJMjFF7PEfWq8XgCbqCIYyn7Ha4xuN 1+sj+IlLuFsxqqwVHV0kjJyk34vAnURfZah4Ol+TSvcBRm19HBFMIoCBgi6PPZENtnfg dl7UgsLpoaXdHaaSZ6aLk1MNRhF6PjBEb9ud3xkxc+XC5AZqEpmRa1m6DKL6WJV3zlQA qMqDto1F/zOX5V6O58hKKhoqfmdzePErCmwex77TAqXaAIVN2UxUr2P6HbbC9XMmzObB S1NA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=X2Ksib9k; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l7si3520180eds.458.2021.01.15.09.44.46; Fri, 15 Jan 2021 09:45:10 -0800 (PST) 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=@google.com header.s=20161025 header.b=X2Ksib9k; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732931AbhAORnI (ORCPT + 99 others); Fri, 15 Jan 2021 12:43:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732438AbhAORnH (ORCPT ); Fri, 15 Jan 2021 12:43:07 -0500 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2127EC0613C1 for ; Fri, 15 Jan 2021 09:42:27 -0800 (PST) Received: by mail-pl1-x62e.google.com with SMTP id x12so5053841plr.10 for ; Fri, 15 Jan 2021 09:42:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=HHcrPMunMXLd4pGO1neHtBLweNEDPBq5DPbqA2qARP4=; b=X2Ksib9kXtDryNhSQ2hrFIt7jHXSUocyXuM3sn5o25k/6kIj16YW909qGlRcjBPsBH pm24WVQNJFcJqWbFSJ76NZPhJsP+LaVdZRdlSX+WHjgREmn+jUtg9qzukGXWDH9TqroB 3tKkzH6EAA9nEMoxrKuB1RAo14QAVswlSM+ZHr7Mg89D36XwFMzBq/p3743nFi7UL20n ZH8dwyflEjKUXu1aSDsF1KQMbkeOTpZmR4hC8p2yhQwmtni5fEj7YVJX28pvfrjdrmTq YuFGxV6NP3ir2Q+wdfLnmvMHMBk1B2FofM031HEGQ+H07vPkWrwqPuum1FjYGJj1bYZ4 oqqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=HHcrPMunMXLd4pGO1neHtBLweNEDPBq5DPbqA2qARP4=; b=KUq5jTULzTuQOx1WyF8UYEeu/Zai8J6nUhQZh4YOdsUPCo3cTdqOvgKC8qSmIWBToz 0YJh0+Y2AHHAGlMaY9mQsS3c1Lca9uxkEr19wlRo7YqTMR+kgmGhfmdYctcps9+oLAlc AYqT18uhONP24Sgp/qcHfdBakGrvvhdNtQLjsPLIC3xF/Atk4J9s5QQUJeHvWzJYwQgY VgG9UOtzWPBWSSCxa4npHp2aEvPbbs7xnsH4/5+lh64qskY/bqAWapwpoiejSl7OBkX0 0zehR6skYG0GXicK6dO7Q2Qe8ybZajsacIXRQG4sqH5d0QvWLAM4yfqPy222pTUbCF93 snsQ== X-Gm-Message-State: AOAM532kTlpHtDig0jA93K89lC7iHFaK37WsTySmw0VhclNWlMx7OdQf G3q6MGEAo9OXi0Ej0IMEMZJlbg== X-Received: by 2002:a17:90a:708b:: with SMTP id g11mr11390902pjk.23.1610732546469; Fri, 15 Jan 2021 09:42:26 -0800 (PST) Received: from google.com ([2620:15c:f:10:1ea0:b8ff:fe73:50f5]) by smtp.gmail.com with ESMTPSA id r79sm8341027pfc.166.2021.01.15.09.42.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 09:42:25 -0800 (PST) Date: Fri, 15 Jan 2021 09:42:19 -0800 From: Sean Christopherson To: "Xu, Like" Cc: Like Xu , Peter Zijlstra , Kan Liang , Paolo Bonzini , eranian@google.com, kvm@vger.kernel.org, Ingo Molnar , Thomas Gleixner , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Andi Kleen , wei.w.wang@intel.com, luwei.kang@intel.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 04/17] perf: x86/ds: Handle guest PEBS overflow PMI and inject it to guest Message-ID: References: <20210104131542.495413-1-like.xu@linux.intel.com> <20210104131542.495413-5-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 Fri, Jan 15, 2021, Xu, Like wrote: > On 2021/1/15 2:55, Sean Christopherson wrote: > > On Mon, Jan 04, 2021, Like Xu wrote: > > > + * Note: KVM disables the co-existence of guest PEBS and host PEBS. > > By "KVM", do you mean KVM's loading of the MSRs provided by intel_guest_get_msrs()? > > Because the PMU should really be the entity that controls guest vs. host. KVM > > should just be a dumb pipe that handles the mechanics of how values are context > > switch. > > The intel_guest_get_msrs() and atomic_switch_perf_msrs() > will work together to disable the co-existence of guest PEBS and host PEBS: > > https://lore.kernel.org/kvm/961e6135-ff6d-86d1-3b7b-a1846ad0e4c4@intel.com/ > > + > > static void atomic_switch_perf_msrs(struct vcpu_vmx *vmx) > ... > ??? if (nr_msrs > 2 && (msrs[1].guest & msrs[0].guest)) { > ??? ??? msrs[2].guest = pmu->ds_area; > ??? ??? if (nr_msrs > 3) > ??? ??? ??? msrs[3].guest = pmu->pebs_data_cfg; > ??? } > > ?? for (i = 0; i < nr_msrs; i++) > ... Yeah, that's exactly what I'm complaining about. Splitting the logic for determining the guest values is unnecessarily confusing, and as evidenced by the PEBS_ENABLE bug, potentially fragile. Perf should have full knowledge and control of what values are loaded for the guest. And, the above indexing magic is nigh impossible to follow and _super_ fragile. If we change .guest_get_msrs() to take a struct kvm_pmu pointer, then it can generate the full set of guest values by grabbing ds_area and pebs_data_cfg. Alternatively, .guest_get_msrs() could take the desired guest MSR values directly (ds_area and pebs_data_cfg), but kvm_pmu is vendor agnostic, so I don't see any reason to not just pass the pointer.