Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp152273lqg; Fri, 1 Mar 2024 00:37:40 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWEmGNZZzYww3TgiFCjNRgQjFnniHtztahcCZilzhklNFfrXqYaHlFFLRtgNBMAfdwcwSYNbVdtzmbppcSbnYT5gntGUA+Ey4AhZFZD4g== X-Google-Smtp-Source: AGHT+IHaiVrtq44DK/KqgThtE4yg5q8Jtezsp3OaLg0wZYNyKGk6CW/43RbTw7O46kIX3zFT+QKU X-Received: by 2002:a17:902:d485:b0:1dc:518e:45b7 with SMTP id c5-20020a170902d48500b001dc518e45b7mr1104107plg.49.1709282260639; Fri, 01 Mar 2024 00:37:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709282260; cv=pass; d=google.com; s=arc-20160816; b=qt/mQRRex1dpCQFWmK76lq7n+RQkupkQeoXSYXGqklOw89VzGjeR1SZqjFcquhMjWr DGUikl8IhlaeYvP3ixZYKQkjgrg+n6PAwwYzSsljyTRVJ7OFZNs+x5hbb5Ih/ZCCe0cN SHsvNZNreT+nECbiWkErpqtvJjscIzwmewval+oELrhSWESo70Hy+hz9EZzi+gFzDe96 fNZBgZ4u5YmuP4io8D/qyvXlMt4D2sgXdT3Vkaxt9IeoqmOhvJIPo4PzWk5+Owb36VQR 5QFkh3HyZuEx8Qcqp4sv4yJcx4zKoy3JZAFbMArqb2tEEW9fguMGPgpDeCVW9n4bCiMA C5HQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=1KP1OIsCMvJGez96bNApKJ4GpsDICD3OZeSUcfZwjEc=; fh=/9l1/hq3YCcMquTV/s+kr2ZwbI+nzGzOu/Ty/falbNk=; b=FLAz+yaPXLZdWIwm/S3T/64s93FwvFkvDx47MhUAtedQjOkSy0/SaozrURKQqKxbG7 ljOh8R6v1TThVEc/nsHSSXkZyN0uw9ZBDi3tX8ViAkgUuJikaYx+RXUEfG/kOgce2c8Q QIZQdaWz9eZ5SXNGHGTbgF1XzhQRPL5XjEcYnHBOixOn94mWe01cNo49KwOvCzJPqpMo 6CFZ66WFp40paU27TydvKYV+DYa8wwc7CwBhmZn8JVVDPDDd8FUyf2VXsYA1hJCMk47y 6wFzDKpn8Bapvx4roDaOtIrDNhUHWru4bSA7LmUaND4Eqe8O8yAi9Tvqx4snj0H/4rZE 8KzQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=dBClkucG; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-88087-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88087-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id j15-20020a170902da8f00b001dbf3786659si3107841plx.222.2024.03.01.00.37.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 00:37:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88087-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=dBClkucG; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-88087-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88087-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 4E609282CCE for ; Fri, 1 Mar 2024 08:37:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5F2FF69E0A; Fri, 1 Mar 2024 08:37:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dBClkucG" Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BA5569D0F; Fri, 1 Mar 2024 08:37:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709282248; cv=none; b=iUTF0wjxLMN9HRIPoEY4BkAEt5vx24nzMNTq9l2VfojSgVaeu7Y56ve5kXaCfrcKqcqx3iPvFqIcEIgNr2u8P+eMklWWUcO2G2aUbc1Vn20pq0v5bxBu/6+0W1MKQwvMS/ON5DdiICB0K+631qpGDmNpbbcmkN3PaRjc43CZpZc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709282248; c=relaxed/simple; bh=O/xcTjzqimRfgoome/Wsnc5JDospAjX/DhL+CZ4+z7E=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ak9+8ZhOSeSyitxu9vAfFnLdwc8jTEn27sC0mLsZ7yLbFKDZsd2b0f+sOWagQwh+PH5tz//D9CkbAq5XJadbmcxJl0L8gGkVPQs33p5zwH/XqbKdL7wNWDts8xynOP4JOKm8wXxRlx62hXuCD8odoK/nuh490BxjJWpIwcbRTtQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dBClkucG; arc=none smtp.client-ip=209.85.216.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-299ea1f1989so1356014a91.0; Fri, 01 Mar 2024 00:37:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709282246; x=1709887046; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=1KP1OIsCMvJGez96bNApKJ4GpsDICD3OZeSUcfZwjEc=; b=dBClkucGCNQG6VpUvd8UWVJPW500FjQnkWKP3U7h2qsmwr+Ke/uF98gNHQ2ko/rlsF vY9BwX3ZUBzFHDXrArfA2jXzVCTgC7+TN0jcE06j6nh5d21q40XsnuPKXNZSVbK5bijM MD65zuPubBoI0V5GmyZprrjFoWVgxaYGrmPngxxdv0OU+z6br3GTT6MC8eSvZ00i8q7Y aWf1sVdGQHMZiTUubN9HPTTPnDkIl/emlQaUY3dYzGDM5cxqo9dAaOdRPqvefBheYpEt hpo3LcpqRx6No9YcV56/eUq9OHC0FpFK5kI2lYeL0qe3s2hcisf/VfZh4RON0IuCx9Kq BsRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709282246; x=1709887046; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1KP1OIsCMvJGez96bNApKJ4GpsDICD3OZeSUcfZwjEc=; b=kWr5Oa+OpQMOeTfNQXKqzDKITSLifq/S7Hb11sKJv275KR+YHWNmTCA8Z6Z9seRYmf 2Kg1sVxKDoIulgONvVZq8V2ZSlc4J7gtAXLy0kr8cUFzdDdfApSl32wTEEvfHn0dfNd3 u6Uibo6wEDRIWBblFF/Oox04NLVhi7zDVnhU/8Nj8Fyh9PiJPD3J53MEQhkDmnIjdU/o N/16rx7GZtWqSJE87OhoTCZQQA7mC3slss8TlIUnhZk+qbZLE5BBuDyH0aABUGMZ/pa+ tl62bpZ7f9j7/KZFF7hKNE4XRNfnwjOMdVezJRWy6rqXvlbsBOzKrutg800YJT4iSE/U zH2Q== X-Forwarded-Encrypted: i=1; AJvYcCXNbfiJzI14onxQ4WOtol0sWTOCzOzVLhOM+lrMycFPcilmcL+dPU3m+j5DVw8VAZ0CEDEU0hqJtcoqFSjPpp9aO/6hzANAbR/Qf6jnEmOI3fbpli8CQ7rYu/jXP1niSj31 X-Gm-Message-State: AOJu0Yz1QCdGwf9ch/yrb9oms38kqn9FYwCcsZxOyS2Bu1tNkFj9irgd epxgZNXn7Lz7TElC95/ZfI9LISIStpFocVeuGPpLSpgPjWrXP0/O X-Received: by 2002:a17:90a:a8f:b0:299:7b37:9221 with SMTP id 15-20020a17090a0a8f00b002997b379221mr924936pjw.12.1709282246357; Fri, 01 Mar 2024 00:37:26 -0800 (PST) Received: from [192.168.255.10] ([43.132.141.20]) by smtp.gmail.com with ESMTPSA id c13-20020a17090ae10d00b0029a8a599584sm2712200pjz.13.2024.03.01.00.37.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 01 Mar 2024 00:37:25 -0800 (PST) Message-ID: <06061a28-88c0-404b-98a6-83cc6cc8c796@gmail.com> Date: Fri, 1 Mar 2024 16:37:20 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] KVM: x86/svm/pmu: Set PerfMonV2 global control bits correctly Content-Language: en-US To: Sandipan Das Cc: seanjc@google.com, pbonzini@redhat.com, dapeng1.mi@linux.intel.com, mizhang@google.com, jmattson@google.com, ravi.bangoria@amd.com, nikunj.dadhania@amd.com, santosh.shukla@amd.com, manali.shukla@amd.com, babu.moger@amd.com, kvm list , "linux-kernel@vger.kernel.org" References: <20240301075007.644152-1-sandipan.das@amd.com> From: Like Xu In-Reply-To: <20240301075007.644152-1-sandipan.das@amd.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 1/3/2024 3:50 pm, Sandipan Das wrote: > With PerfMonV2, a performance monitoring counter will start operating > only when both the PERF_CTLx enable bit as well as the corresponding > PerfCntrGlobalCtl enable bit are set. > > When the PerfMonV2 CPUID feature bit (leaf 0x80000022 EAX bit 0) is set > for a guest but the guest kernel does not support PerfMonV2 (such as > kernels older than v5.19), the guest counters do not count since the > PerfCntrGlobalCtl MSR is initialized to zero and the guest kernel never > writes to it. If the vcpu has the PerfMonV2 feature, it should not work the way legacy PMU does. Users need to use the new driver to operate the new hardware, don't they ? One practical approach is that the hypervisor should not set the PerfMonV2 bit for this unpatched 'v5.19' guest. > > This is not observed on bare-metal as the default value of the > PerfCntrGlobalCtl MSR after a reset is 0x3f (assuming there are six > counters) and the counters can still be operated by using the enable > bit in the PERF_CTLx MSRs. Replicate the same behaviour in guests for > compatibility with older kernels. > > Before: > > $ perf stat -e cycles:u true > > Performance counter stats for 'true': > > 0 cycles:u > > 0.001074773 seconds time elapsed > > 0.001169000 seconds user > 0.000000000 seconds sys > > After: > > $ perf stat -e cycles:u true > > Performance counter stats for 'true': > > 227,850 cycles:u > > 0.037770758 seconds time elapsed > > 0.000000000 seconds user > 0.037886000 seconds sys > > Reported-by: Babu Moger > Fixes: 4a2771895ca6 ("KVM: x86/svm/pmu: Add AMD PerfMonV2 support") > Signed-off-by: Sandipan Das > --- > arch/x86/kvm/svm/pmu.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/arch/x86/kvm/svm/pmu.c b/arch/x86/kvm/svm/pmu.c > index b6a7ad4d6914..14709c564d6a 100644 > --- a/arch/x86/kvm/svm/pmu.c > +++ b/arch/x86/kvm/svm/pmu.c > @@ -205,6 +205,7 @@ static void amd_pmu_refresh(struct kvm_vcpu *vcpu) > if (pmu->version > 1) { > pmu->global_ctrl_mask = ~((1ull << pmu->nr_arch_gp_counters) - 1); > pmu->global_status_mask = pmu->global_ctrl_mask; > + pmu->global_ctrl = ~pmu->global_ctrl_mask; > } > > pmu->counter_bitmask[KVM_PMC_GP] = ((u64)1 << 48) - 1;