Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1728055rdh; Tue, 26 Sep 2023 01:24:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGwnYsZ1/Z1y+sWNr3JbojzXTM/W9P2gqRxwIpbrBaasKALEwWLdqU4atbMS04yxm564yxQ X-Received: by 2002:a17:902:f543:b0:1c6:2f59:8c4d with SMTP id h3-20020a170902f54300b001c62f598c4dmr920907plf.28.1695716697630; Tue, 26 Sep 2023 01:24:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695716697; cv=none; d=google.com; s=arc-20160816; b=YuEMAAvguTDO3ic7jHl1i+rqch9dXhaytMKy5TnNv8gS+105FlCzH7xHdUbwf6YX0x LDtnPWlNlpAYRxk568Y9YyFvWsBgWPYDXQNx95sftjKx1EszUusHbrzxeD+XrIutZWpf G218YI+KtPKamiALensxdrNkT7YJSzaS/c5KQG4gl5wFqC+dIpIMdabHogVah5aNwlbD DSLjPDiyeyDEf+gdna4/QXqRUBMaYegJ9zEjN+Ml28Cnx4viXwDN4s/actbdJo5cpspW NVk+E1Vlo6XWPizroJj9kcbAGG8C9SqYSTTseVkExlpxgYb4L/v3YO2AXNL0ryYNEBZ/ PfWA== 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=eJxrMaSceLhoHUwbSBQFNIWRaTVumnsiZsfe8eDrUVE=; fh=AOFZf1zBVrp5GOgsL4XoirnhDgTWDqQxY8pysrJ7UgQ=; b=vfppKGVvR7445tm0R1eM/OTFixa4qd9aBF2ENVU1q93I7PizcDEPKr3iG/kutlxbKu 1/IA9+PNJhVeWTRWVXvgY1CXVT1Zjb3oREQrBdlfFCSj+QRAb0eXEeWNY2+ksgUKnQwk 6WYMPJhDkprTRvKs9vUewu//3xCu36mmiS98cKe80hFgoGrG0N2kXkRRIdeW/L3UuRMO bcsAUl2M5rNOxPAVNzNFrzarsl+CnFHn54xmxDVQOlwJFdb1STWGjThObpumVMe4kRW8 KJd/3LsKZeLqaVtSa+iN39KnCMW6u6ONj2gR7GmHabb3sN5NhliNBYk/k1TUoQCWPepq x2XQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=mCtQHIkx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id lc13-20020a170902fa8d00b001be025f8407si11831919plb.37.2023.09.26.01.24.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 01:24:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=mCtQHIkx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 8B0B980ACB62; Mon, 25 Sep 2023 16:32:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233532AbjIYXcJ (ORCPT + 99 others); Mon, 25 Sep 2023 19:32:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230125AbjIYXcI (ORCPT ); Mon, 25 Sep 2023 19:32:08 -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 5508C101 for ; Mon, 25 Sep 2023 16:32:01 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d8191a1d5acso11454107276.1 for ; Mon, 25 Sep 2023 16:32:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695684720; x=1696289520; 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=eJxrMaSceLhoHUwbSBQFNIWRaTVumnsiZsfe8eDrUVE=; b=mCtQHIkxCWdPRJCpfXNxlDtHqd5VzC4UAbNobaAoCz+dNJLfU6+PkKf9wdOGEgZzkn A5cpxXemND6MbXna7ivH4ur2DoIXkIZKQJhjshrNGuZ/PLcCYJMO2dhqyxWycKTtsaoM gGcc/x7pEzLpMa5koTkdp4KGDnKlnXOHRXhpRAbeW80Qkb5tYxeRVdy6IXX0EtVSQLkK bYkuAaR4s+pIK3Sa7X/CIbGelyNIQE31Yrms8YTF7lh3/MC5XMJ6/WjZDVxPcjqPGCJ3 fJRYiM1T9RPirFMGdP/JIRXeVXXJ8xc2pbLMQPr4PbvkLbdyjTcG6/3moJHKdQeJ4uNP W+pQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695684720; x=1696289520; 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=eJxrMaSceLhoHUwbSBQFNIWRaTVumnsiZsfe8eDrUVE=; b=WTvrCAtiQGvb1EIu5hJXamRgy40PHS/2J3jmRIpxw1zSK214HxGaJPyMv+PwEJ9E2c VKw/I8ByVW6JsoNunVHxG8YQCWmGkrDH5zRAGth1QDxIN05JsEuVrAtz/yxpgcezDAji uIhfHSWt4QppiIalNzvwkhKpKF024bwZjRy9QrUl2zF0l7zO+1QTDsIyVMxF2lXLXy6x 3zRcdO2eVTKW8JXBKxZM3Ve1s+vmbxc/4FbCfKHSI+We6QM2b/J20OC7Vl4GHsCnEdds 33EMg8D8ZPnraBLaYv3Nz1DRahsqtsM1VjuWG3fR6te0FLUQJdcoTcfMCNMxbhEumck4 t4IA== X-Gm-Message-State: AOJu0Yyq3y4lN5zr9drGjdW8EAMFVx+uuWyzwXoJlBfICMbswWbvMJxj rYrdOU/vCIp/bkNDkNZXM7tG3sN5/qc= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:50ce:0:b0:d74:93a1:70a2 with SMTP id e197-20020a2550ce000000b00d7493a170a2mr83729ybb.5.1695684720550; Mon, 25 Sep 2023 16:32:00 -0700 (PDT) Date: Mon, 25 Sep 2023 16:31:58 -0700 In-Reply-To: <6ee140c9-ccd5-9569-db17-a542a7e28d5c@gmail.com> Mime-Version: 1.0 References: <20230407085646.24809-1-likexu@tencent.com> <6ee140c9-ccd5-9569-db17-a542a7e28d5c@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=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 25 Sep 2023 16:32:15 -0700 (PDT) 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. 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.