Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp169859pxb; Fri, 15 Jan 2021 10:01:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJxgJkbOeCj3/yQyR+czec2qTH9Mn606+3IdhpzHaIuajoz8QxOS6fmtjBvcrXd2htsI9M77 X-Received: by 2002:a17:906:3a55:: with SMTP id a21mr9938828ejf.516.1610733689582; Fri, 15 Jan 2021 10:01:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610733689; cv=none; d=google.com; s=arc-20160816; b=jp44IWvNPwV5JDt9ki05VzKyQZfvjymiKM351nkL/bXkweLJbTEWPvZp+2XhsfdSt2 eSHcIcdHZNW388soDtu7ogb/i1GRe1hH7qpVOCleDoT9i8/kYhj70p+uTOYJEUkCQ7aM hPx77yMeT5ikuEjUSlaCVwS9luB7cHiVWTWAz1QD8BSB4BCPM4B36q14oRdZFJalQ5+P b3eNPjjA1WUljBfKfrdsTtmgPpIQjzHQGvByo4NCQiUcjVa3n+6k+fErZKQm7+Yk5iQy UbvnqFcAmOJ9YKHL4Bz3HX9DnAJHOx37fjoeKYmWRONFYqabDj2FaZvdi81ZYDeORfpx ON5A== 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=uEflp91SYEJEoNcnlfy5sa1fP5kmkuZCXVCSskOFlC0=; b=SEr9nHuZfshgc9TTqrHFKhLIIxyC9MQUzmvJE349oUZiY7dH6pcmSjErk0TOF9ThaI xvyo3GsbczULUQseK6zmITDFcQgHTiK3NM48zPXuV0/JznT1Q7qmYA4EfDRMlXomUn9x CowDQnRzzpWDWiW9r8EKyDXSsWyDIiDy6tlj4MckQfRhfF+/RwPm64arp+B399oygKLP jw3P5+NfM8qvR7Dz6LrBg0HWiRdsFRgFg664AD2KjYPV8sBrRqpVBt0Xlw/5Lk41398W 2S6KMkGquoxpHWC9hPFvQS1iXaJf/eZOLKlQD8zlX/oduNysY7v+B7xy9C1rXBmT8YzD xByQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ef0SziCC; 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 t21si5226111edi.2.2021.01.15.10.01.05; Fri, 15 Jan 2021 10:01:29 -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=ef0SziCC; 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 S1728293AbhAOR6a (ORCPT + 99 others); Fri, 15 Jan 2021 12:58:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726779AbhAOR63 (ORCPT ); Fri, 15 Jan 2021 12:58:29 -0500 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FAC0C061793 for ; Fri, 15 Jan 2021 09:57:49 -0800 (PST) Received: by mail-pj1-x102c.google.com with SMTP id g15so1328546pjd.2 for ; Fri, 15 Jan 2021 09:57:49 -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=uEflp91SYEJEoNcnlfy5sa1fP5kmkuZCXVCSskOFlC0=; b=ef0SziCCt1lkNSKK0R2jZx4Sw8hjm9L2wzdjpzq4IQaPH36hpLM5s0vnieW9z5ZpB9 da9hsXQ/zJ0+Fp/SUDT4O+0P2hwa5WfyUJz95cvFRn0X7CNpS0ru+U1zbSTNFaCyKYw+ 98AxW3+SW3nz/e9ES33250BC6DW22qwOxZ2ou8zEPkuMTH3hPysZT+q0vrsdysHw9nG0 4Sn/BUxxHz1siIU8eDu3mPCJ7/RQ+wzC0kcr9xUnrbMwHg/HcmacvZ324eV9+u1s3ctN mzYH9d56EYPctpqCa2ZmNJe7KimcbBfmKMrQ9rtT6WFM6U+rKMCXHJHgfzIbdu7IaFFh VlGw== 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=uEflp91SYEJEoNcnlfy5sa1fP5kmkuZCXVCSskOFlC0=; b=bl+2DRU8edg3HtVMFE6QVYJdpYDZjCDueP83oo71kRWKH9Q3iDJKfwgFGaVYQbIheo QdaRqhnU5XGXW2jpwNfF4ReqYYltC+6DxLRORZsM+cV/z2I6KvjjxjW6EL3mDbc7gMlO UOqbfRZKwRj1yiTn4e3x+n3rf/eXkE8pep7kbRD2eMpxeqMVYnh8RBXZ35U0iV4MBnRm lwmL/gbx6DA1HPS0cXodMQ+S5CoNuXruGCqH5XpFWt4D6Urtts+Vho+HbDFqqUJNhRPU F3vU3dDyEMR70pOdh7HNuLbkz5ToktWojwP9P8WafzxUNBP5lyvABURfHxjYdOnn6CVV cXGQ== X-Gm-Message-State: AOAM531d0EBm854yGmnnG69jdDwVrZd/p5KUMw6ItGH2ShytK2883BCl p77ySshoIJN0bbpZHtBaJzRSRg== X-Received: by 2002:a17:90a:9918:: with SMTP id b24mr11761239pjp.108.1610733468909; Fri, 15 Jan 2021 09:57:48 -0800 (PST) Received: from google.com ([2620:15c:f:10:1ea0:b8ff:fe73:50f5]) by smtp.gmail.com with ESMTPSA id f67sm8773844pfg.159.2021.01.15.09.57.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 09:57:48 -0800 (PST) Date: Fri, 15 Jan 2021 09:57:41 -0800 From: Sean Christopherson To: "Xu, Like" Cc: Andi Kleen , Kan Liang , Peter Zijlstra , Paolo Bonzini , eranian@google.com, kvm@vger.kernel.org, Ingo Molnar , Thomas Gleixner , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , wei.w.wang@intel.com, luwei.kang@intel.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 00/17] KVM: x86/pmu: Add support to enable Guest PEBS via DS Message-ID: References: <20210104131542.495413-1-like.xu@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 15, 2021, Xu, Like wrote: > Hi Sean, > > Thanks for your comments ! > > On 2021/1/15 3:10, Sean Christopherson wrote: > > On Mon, Jan 04, 2021, Like Xu wrote: > > > 2) Slow path (part 3, patch 0012-0017) > > > > > > This is when the host assigned physical PMC has a different index > > > from the virtual PMC (e.g. using physical PMC1 to emulate virtual PMC0) > > > In this case, KVM needs to rewrite the PEBS records to change the > > > applicable counter indexes to the virtual PMC indexes, which would > > > otherwise contain the physical counter index written by PEBS facility, > > > and switch the counter reset values to the offset corresponding to > > > the physical counter indexes in the DS data structure. > > > > > > Large PEBS needs to be disabled by KVM rewriting the > > > pebs_interrupt_threshold filed in DS to only one record in > > > the slow path. This is because a guest may implicitly drain PEBS buffer, > > > e.g., context switch. KVM doesn't get a chance to update the PEBS buffer. > > Are the PEBS record write, PEBS index update, and subsequent PMI atomic with > > respect to instruction execution? If not, doesn't this approach still leave a > > window where the guest could see the wrong counter? > > First, KVM would limit/rewrite guest DS pebs_interrupt_threshold to one > record before vm-entry, > (see patch [PATCH v3 14/17] KVM: vmx/pmu: Limit pebs_interrupt_threshold in > the guest DS area) > which means once a PEBS record is written into the guest pebs buffer, > a PEBS PMI will be generated immediately and thus vm-exit. I'm asking about ucode/hardare. Is the "guest pebs buffer write -> PEBS PMI" guaranteed to be atomic? In practice, under what scenarios will guest counters get cross-mapped? And, how does this support affect guest accuracy? I.e. how bad do things get for the guest if we simply disable guest counters if they can't have a 1:1 association with their physical counter?