Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp417415pxu; Tue, 5 Jan 2021 15:04:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJzgkvPudsLO7+C57TE7SMk6KtCbZQg5LiHlHFN85lisJU7yM/9fOZfCkyJ3nSNIeCIxcQL8 X-Received: by 2002:a05:6402:510f:: with SMTP id m15mr513233edd.267.1609887876862; Tue, 05 Jan 2021 15:04:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609887876; cv=none; d=google.com; s=arc-20160816; b=wMO3QOcLvnHV9IOx1x5fqOHYIa8HsvQGgrKgE/VSPVWAGfBEBrrE3kKstl2Avy4JF7 vrutwMplSZr5npHY45fg5t9+5Iw/VG/z/P8PCxv2Ms8yvfqZlGUhV6heKmw+Gxt1sDoB 8ifiJG0wOlZ1R/vVRF9MBOy5wjmxEG+ZdE5n3KA1WScjw+zXAJ2Rx1jZGchBQ6u9mlKR 21mW0viAZTE7EzMgCpewFknf1kc93D2y9WEvvAh7qSIppkepnPSMNClxZSNFjFJBRUZ6 jy/88wfoxQV2yyK4MLFPRvUv9jW2wyYbdILhz/gYZceRXjnFKAJaCI2g0y/TTIYPpAhN n3Tg== 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=QbMPt8I3VcRDdWxFclid09bafyeFef46ToM33ENhg8c=; b=Q4ytWt93aoIWEGSndVptkR+wc0vQJDJiRRraM4rhTAVompFRA//xtACl6QudLHvk/J dvyazWa//X3qtevwNx1PNJcouS17V6H0+gBj4EVVS0r0frlQUiYQiMXY1Dc8y0Olx8vg K4D33RlaLrR4KglamrRugp0Si+1ldt8dH5+kEFAI9+iG4S9uTwbdzgknbwvQBUQOVGLg IW9i8uA5xF88ExrREs0Tg6dWrrLfS7udMOKH3L7OEdW9K7bnDFGR32+LWp6ST8q3p/HB Mp5tSCGDpk2BXPVFUd4Pj/ThI+sl86hQ7TE4lFB3mwuxytEynDoBh4ysihcyiLnqXq2E RM2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=fpeX5Okk; 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 f15si227592edc.147.2021.01.05.15.04.13; Tue, 05 Jan 2021 15:04:36 -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=fpeX5Okk; 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 S1731374AbhAEVRA (ORCPT + 99 others); Tue, 5 Jan 2021 16:17:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725828AbhAEVQ7 (ORCPT ); Tue, 5 Jan 2021 16:16:59 -0500 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 679D8C061796 for ; Tue, 5 Jan 2021 13:16:19 -0800 (PST) Received: by mail-pj1-x102b.google.com with SMTP id n3so1586143pjm.1 for ; Tue, 05 Jan 2021 13:16:19 -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:in-reply-to; bh=QbMPt8I3VcRDdWxFclid09bafyeFef46ToM33ENhg8c=; b=fpeX5OkkCMF1T8lCjn/AmjHrXc25G2Nzid/hZkoJCp3XOp+2OVdMIKyyBw/z2DlDiI a25BAr1DWsHBb/mI6kl2fcWxRwrvWi7EvKbWkjcluD2mY3fZIOUjCb397KCJDm+ctaKx mXB5BoRR4GrMhnsA5vvHOUltn0OEBX8PglQiuUqeMPKJ7zU/5GWUQO5Izb9u0lV5wkR5 Lrg5o3cu6or3N1DQ0B12I1LPrPMRS4IIsVwGG4YIiR6sjuE5j1/WesCf9a+cp9Xnu8qc szC8UOrvG9rVI7cmCA9wqg7TfDd2pSko//4lnULUjSCV1oOCWUenVU5t3EQDEiAluKZe aCzg== 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:in-reply-to; bh=QbMPt8I3VcRDdWxFclid09bafyeFef46ToM33ENhg8c=; b=pAUKVHgWQLNYLMhqvXYKBaV8Rersb/Z9Jn9siiDy9EXlb0qU8nuJYLIKP2hZr72qeU iiQHvx1MGxqkRFfxRETjmO2ii92LV2dahx3a9vl3XOWdF5k6GoYEkUc1165nwfv/AKSg gtUUJy/KZS43xEpZoIXiL6r3oECqpmkpATfZpuiPRjnNOdQswrNWo0RQKtKI7vS4YNk9 Cp+CU2IgbjxyKbavlAFV2KggKqx0S3D/MbCtL8da7I0x7gm49jdqZ0/pvudift897sEI WygFX6fJmOa3hWbHABmr6dVvl1Gl3QhWi2c1ugn03oKMXP0NmzD74tm1VovqkOpB9v7D ThxQ== X-Gm-Message-State: AOAM530dYVcfPtCvPLZTJBgOsLxBeN7EfYgoKSx21Ymtz05mylcFS2za O1El1SJVv6/3fxh9J1pSDqFtSw== X-Received: by 2002:a17:902:7292:b029:dc:ac9:25b5 with SMTP id d18-20020a1709027292b02900dc0ac925b5mr1147305pll.2.1609881378803; Tue, 05 Jan 2021 13:16:18 -0800 (PST) Received: from google.com ([2620:15c:f:10:1ea0:b8ff:fe73:50f5]) by smtp.gmail.com with ESMTPSA id b129sm113138pgc.52.2021.01.05.13.16.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Jan 2021 13:16:18 -0800 (PST) Date: Tue, 5 Jan 2021 13:16:11 -0800 From: Sean Christopherson To: Like Xu Cc: Peter Zijlstra , Paolo Bonzini , eranian@google.com, kvm@vger.kernel.org, Ingo Molnar , Thomas Gleixner , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Andi Kleen , Kan Liang , wei.w.wang@intel.com, luwei.kang@intel.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 07/17] KVM: x86/pmu: Add IA32_DS_AREA MSR emulation to manage guest DS buffer Message-ID: References: <20210104131542.495413-1-like.xu@linux.intel.com> <20210104131542.495413-8-like.xu@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210104131542.495413-8-like.xu@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 04, 2021, Like Xu wrote: > When CPUID.01H:EDX.DS[21] is set, the IA32_DS_AREA MSR exists and > points to the linear address of the first byte of the DS buffer > management area, which is used to manage the PEBS records. > > When guest PEBS is enabled and the value is different from the > host, KVM will add the IA32_DS_AREA MSR to the msr-switch list. > The guest's DS value can be loaded to the real HW before VM-entry, > and will be removed when guest PEBS is disabled. > > The WRMSR to IA32_DS_AREA MSR brings a #GP(0) if the source register > contains a non-canonical address. The switch of IA32_DS_AREA MSR would > also, setup a quiescent period to write the host PEBS records (if any) > to host DS area rather than guest DS area. > > When guest PEBS is enabled, the MSR_IA32_DS_AREA MSR will be > added to the perf_guest_switch_msr() and switched during the > VMX transitions just like CORE_PERF_GLOBAL_CTRL MSR. > > Originally-by: Andi Kleen > Co-developed-by: Kan Liang > Signed-off-by: Kan Liang > Signed-off-by: Like Xu > --- > arch/x86/events/intel/core.c | 13 +++++++++++++ > arch/x86/include/asm/kvm_host.h | 1 + > arch/x86/kvm/vmx/pmu_intel.c | 11 +++++++++++ > arch/x86/kvm/vmx/vmx.c | 6 ++++++ > 4 files changed, 31 insertions(+) > > diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c > index 6453b8a6834a..ccddda455bec 100644 > --- a/arch/x86/events/intel/core.c > +++ b/arch/x86/events/intel/core.c > @@ -3690,6 +3690,7 @@ static struct perf_guest_switch_msr *intel_guest_get_msrs(int *nr) > { > struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); > struct perf_guest_switch_msr *arr = cpuc->guest_switch_msrs; > + struct debug_store *ds = __this_cpu_read(cpu_hw_events.ds); > > arr[0].msr = MSR_CORE_PERF_GLOBAL_CTRL; > arr[0].host = x86_pmu.intel_ctrl & ~cpuc->intel_ctrl_guest_mask; > @@ -3735,6 +3736,18 @@ static struct perf_guest_switch_msr *intel_guest_get_msrs(int *nr) > *nr = 2; > } > > + if (arr[1].guest) { > + arr[2].msr = MSR_IA32_DS_AREA; > + arr[2].host = (unsigned long)ds; > + /* KVM will update MSR_IA32_DS_AREA with the trapped guest value. */ > + arr[2].guest = 0ull; > + *nr = 3; > + } else if (*nr == 2) { > + arr[2].msr = MSR_IA32_DS_AREA; > + arr[2].host = arr[2].guest = 0; > + *nr = 3; > + } Similar comments as the previous patch, please figure out a way to properly integrate this into the PEBS logic instead of querying arr/nr. > + > return arr; > }