Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2178841rdh; Tue, 26 Sep 2023 15:21:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE1lQ0EmXvmMhsLTbHSZTrh14YpSKlD3hUL+/LMwbDrI9oPvHU5sBoTM9Sc6QMD86NoqD9N X-Received: by 2002:a17:903:1cc:b0:1bb:994c:bc43 with SMTP id e12-20020a17090301cc00b001bb994cbc43mr89464plh.18.1695766870282; Tue, 26 Sep 2023 15:21:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695766870; cv=none; d=google.com; s=arc-20160816; b=JfgkgPreB8V46rBbGCvZY2TdBNBeFNxfVtwkqvbhPTi1e7GebfeuELu8/KiFhQ2Xxc GJaAu08Odh8ZNAbkL7VBPAL4Qh/dsLZV0C56OmBeqm64h+sSvmBlEpuSDdfpg7rWuCwp uesStPRBxvwL5C4bfxP7qudAJXbPrQfCZfONz5deo1Ug4dIO1ltpuuXtJyGdpMyS/KJv pXmt7PGZOMuET2bxQLVUQSuwNn39BwrRD11NSIBs0aNiryFewuu1j4KtyBQoff45FE56 JQtrzFDcb3RbTmJJBYHNIHJ7gJKtNLsKDXcD6vrKpweljV4D9jvlNMEsUxjrbv0b8KdW CDwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=dUqxLY2nTBwa9TznKkTTvHje90znBvp6KBryn5bkyvU=; fh=AOFZf1zBVrp5GOgsL4XoirnhDgTWDqQxY8pysrJ7UgQ=; b=jOWLc+NXZ0krmO9Cr9Qzy+H5gB3fbR1cEzXE8IRyqUoN3FKKDBPFnsceTnsDWxkn6N 7de/IXyRatOchXrbmvZxph5+LjK5gFjst0sZo2HryEbWmJ3UjI4atMkz25PimujBL0wX zhfI1nCl/sUQ7ear9R7x5FYKt+mt90s/T3zFzjFDUsuOXb5hfd2qyVs16kRTB3sUlZ4W 2kyYGPYIG64c8muI6sFSvOKvXJp/fm3jPZgz8WIax6LAZvmtdjeTmy1ehm9Z+jjL731f kluOQDv/e0eIQHf0OeU8E6bsaIeHAETvZ5bPbDeWtmHXqaRiLUCV/TGoUDG3pwiehXul 3iWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=zrnFlS6O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id h20-20020a170902f7d400b001c56edc4b7asi13553342plw.278.2023.09.26.15.21.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 15:21:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=zrnFlS6O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id C72ED828EC29; Tue, 26 Sep 2023 08:44:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229513AbjIZPon (ORCPT + 99 others); Tue, 26 Sep 2023 11:44:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233792AbjIZPom (ORCPT ); Tue, 26 Sep 2023 11:44:42 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2124910A for ; Tue, 26 Sep 2023 08:44:34 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d81c39acfd9so13753749276.0 for ; Tue, 26 Sep 2023 08:44:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695743073; x=1696347873; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=dUqxLY2nTBwa9TznKkTTvHje90znBvp6KBryn5bkyvU=; b=zrnFlS6O3Q/Uf1lgaA7OEby+ESk7FU/X4I2aqgg6RW384xfQNSiF/q0b4VFU9axZfu WYcyY8OO3ee2HZ9VDCq1JUHrl3iUqXZvUOBVm6McNzCIK4/jjtrQJRLFgY/BkL80ejZw YFVCqzf+72WbpSQDg6pnjSyxbkM3aiyD3TxLZWQZzf7h75jk5Cc8SVCxZpLtmP4nWlxE ssFzE8OuD9lIzFHqwvX9YAmtd4UnJsgfkuMy3ns+S7egO19Tl4jCdINCWfVzgbEz++KM 50szg3qBkspaXBrGUbgttOTToHfYps2x4su4lDAaxOxBIsAy7nitpaJ/xWGO4ua6IGCP z56g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695743073; x=1696347873; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dUqxLY2nTBwa9TznKkTTvHje90znBvp6KBryn5bkyvU=; b=wylOW3rn8jCjbFz3kRorRMVm444Boi46YVdnHG3BixPb/Yu8P90vay8yiSzLQogwEj 4ttiNARcdjpar7VIMaaNLelCMWsCCAA/scWNIkySa7w5h2LKE5qcEPm9AcuAyyS5zHL0 Cdq+yuthjVnWF1jZg86ZdBT4h1NX+EPos1OfpSj0Rd2lDpNKkIddsncAoE1kixCVwmpB /fDfPsFtr3YtDGixSmxZfY7T/xsrCryqgG+dhbaoCn3Q/aLIt3p+yZcaUb2kToO+yEuv A4BjsvsGrQ9HW7osiJFH2Lt6EE6dGrJQODoDeILnmx0EFqHqj+KoD+iJI9jfrvlyF+qV uWFA== X-Gm-Message-State: AOJu0Yxl4FYWi2f/WD5783V+1ePLVjFgi6eGJXduN0ezz1gXMZ+cZ3cS A895Aj8/yXFmBcJ1WE3C6iRhSpBV2No= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:8c02:0:b0:d81:43c7:61ed with SMTP id k2-20020a258c02000000b00d8143c761edmr104033ybl.5.1695743073295; Tue, 26 Sep 2023 08:44:33 -0700 (PDT) Date: Tue, 26 Sep 2023 08:44:31 -0700 In-Reply-To: <90dd2e2e-71ae-d8c4-5d3b-9628e7710337@gmail.com> Mime-Version: 1.0 References: <20230407085646.24809-1-likexu@tencent.com> <6ee140c9-ccd5-9569-db17-a542a7e28d5c@gmail.com> <90dd2e2e-71ae-d8c4-5d3b-9628e7710337@gmail.com> Message-ID: Subject: Re: [PATCH V2] KVM: x86/pmu: Disable vPMU if EVENTSEL_GUESTONLY bit doesn't exist From: Sean Christopherson To: Like Xu Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Ravi Bangoria , Manali Shukla Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 26 Sep 2023 08:44:48 -0700 (PDT) On Tue, Sep 26, 2023, Like Xu wrote: > On 26/9/2023 7:31 am, Sean Christopherson wrote: > > On Thu, Sep 14, 2023, Like Xu wrote: > > > On 7/4/2023 11:37 pm, Sean Christopherson wrote: > > > > On Fri, Apr 07, 2023, Like Xu wrote: > > > /* > > > * The guest vPMU counter emulation depends on the EVENTSEL_GUESTONLY bit. > > > * If this bit is present on the host, the host needs to support at least > > > the PERFCTR_CORE. > > > */ > > > > ... > > > > > > /* > > > > * KVM requires guest-only event support in order to isolate guest PMCs > > > > * from host PMCs. SVM doesn't provide a way to atomically load MSRs > > > > * on VMRUN, and manually adjusting counts before/after VMRUN is not > > > > * accurate enough to properly virtualize a PMU. > > > > */ > > > > > > > > But now I'm really confused, because if I'm reading the code correctly, perf > > > > invokes amd_core_hw_config() for legacy PMUs, i.e. even if PERFCTR_CORE isn't > > > > supported. And the APM documents the host/guest bits only for "Core Performance > > > > Event-Select Registers". > > > > > > > > So either (a) GUESTONLY isn't supported on legacy CPUs and perf is relying on AMD > > > > CPUs ignoring reserved bits or (b) GUESTONLY _is_ supported on legacy PMUs and > > > > pmu_has_guestonly_mode() is checking the wrong MSR when running on older CPUs. > > > > > > > > And if (a) is true, then how on earth does KVM support vPMU when running on a > > > > legacy PMU? Is vPMU on AMD just wildly broken? Am I missing something? > > > > > > > > > > (a) It's true and AMD guest vPMU have only been implemented accurately with > > > the help of this GUESTONLY bit. > > > > > > There are two other scenarios worth discussing here: one is support L2 vPMU > > > on the PERFCTR_CORE+ host and this proposal is disabling it; and the other > > > case is to support AMD legacy vPMU on the PERFCTR_CORE+ host. > > > > Oooh, so the really problematic case is when PERFCTR_CORE+ is supported but > > GUESTONLY is not, in which case KVM+perf *think* they can use GUESTONLY (and > > HOSTONLY). > > > > That's a straight up KVM (as L0) bug, no? I don't see anything in the APM that > > suggests those bits are optional, i.e. KVM is blatantly violating AMD's architecture > > by ignoring those bits. > > For L2 guest, it often doesn't see all the cpu features corresponding to the > cpu model because KVM and VMM filter some of the capabilities. We can't say > that the absence of these features violates spec, can we ? Yes, KVM hides features via architectural means. This is enumerating a feature, PERFCTR_CORE, and not providing all its functionalality. The two things are distinctly different. > I treat it as a KVM flaw or a lack of emulation capability. A.k.a. a bug. > > I would rather fix KVM (as L0). It doesn't seem _that_ hard to support, e.g. > > modify reprogram_counter() to disable the counter if it's supposed to be silent > > for the current mode, and reprogram all counters if EFER.SVME is toggled, and on > > all nested transitions. > > I thought about that too, setting up EFER.SVME and VMRUN is still a little > bit far away, and more micro-testing is needed to correct the behavior > of the emulation here, considering KVM also has to support emulated ins. > > It's safe to say that there are no real user scenarios using vPMU in a nested > guest, so I'm more inclined to disable it provisionally (for the sake of more > stable tree users), enabling this feature is honestly at the end of my to-do list. I don't see a way to do that without violating AMD's architecture while still exposing the PMU to L1.