Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp816938rdb; Tue, 23 Jan 2024 16:40:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IFgYvGouXTXO8q2LrkSqtDXCguOGM0r+uFFvfygLXITfwzBhqq+TFbMqvF+AzYvP9Htku4O X-Received: by 2002:ac8:4e93:0:b0:42a:3a03:7ea0 with SMTP id 19-20020ac84e93000000b0042a3a037ea0mr1717379qtp.111.1706056833495; Tue, 23 Jan 2024 16:40:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706056833; cv=pass; d=google.com; s=arc-20160816; b=U/KCz4iV4FuubzCi+uy78anZ73OtYl9raCTinpfWMQPPGoFP/chQ33t+UpMztA/7+V QtKjYs+pvBGUhr8Ml/1SMLxaHmE6kaHTdkY31PInuxIllTheCZjx7wjxggBoM8EbH0v9 sJi1nJw9FpQfhpFnVIfXugCV5+/55IZWzKyXZMCxwSxSCMgUaO377K5DPx6ZgZp2g/v5 WBfFQMstLtDi2BgvO60sezPbNzJLszulrpbOlLs9Lj2jMCz+/THx81erGZ2fEHfjLEre 3YWL3Yoxj6aCq10LOTh0qF6LmNunr4yS+UrEtNw8NaapKJgIYGUakL365xSmzihAVSM4 d0iw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :reply-to:dkim-signature; bh=YABAD9MCJqjxVx7Kdqag9uuDZvgkIWsvnk7JYS6IBNE=; fh=BmxsMTAymmGF1UJR5MpB1hk/0oqfyaaP+WHwoCwyPO4=; b=sehqaTH+Yi4qZYu6nMTDmTORiqltxOtS8ECgqHA3g+DfRAGSqdkoZaIrFU9AcXM48n zjVZ3juUOmJOTBAwzAg3BYcT+JWkRkAbN7lNw7vCkZ3+kmlD1n9ffWWuoyCYcZKx58Rm p3CfpF2zApTnt1o87Cdqt4SgKRUkrtjozOj+TZFXVvwa5eeRkLNkoIPzSAb2gMS2hszO czhDZ3dD7nBJzB4ALjb/AbkAOCJbPhpN1fAVflaqCFqe85MA1/xulco2jO3U9ntpNf3b sBCS0CVIQn+KsB6blm9scfU1+Frc/X5Z4jzgbUc63qJXhApO+EfGs9q0J2w8VX3toTBW 9xjA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=GZ1lBDwj; arc=pass (i=1 spf=pass spfdomain=flex--mizhang.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-36228-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36228-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id j21-20020ac85c55000000b0042a54c61497si1683446qtj.698.2024.01.23.16.40.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 16:40:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-36228-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=GZ1lBDwj; arc=pass (i=1 spf=pass spfdomain=flex--mizhang.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-36228-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36228-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 79B671C217B0 for ; Wed, 24 Jan 2024 00:40:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 22B641FAA; Wed, 24 Jan 2024 00:39:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="GZ1lBDwj" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 D0B0F15AB for ; Wed, 24 Jan 2024 00:39:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706056751; cv=none; b=OZXCjeQMOeDLoe5kwwwGr8RjEwwxF+aGMFQQqDETJq8nwHPKImUEXElpJj0dhkOhYA/RCFHEvGxtDXn1eoENIn82DxrGPWkonFMWxXAjrxa4k2pRQdMd0qvW4MEFiTyXecnUbZO6w1J/ogaws2rSeyqxzT4Nv6UmkPXrAkA1Xt8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706056751; c=relaxed/simple; bh=tQzYCqIJlGScXwtS+O6x1VCReMd49PQ5WfpZOd7WlTQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=hHMtpUJxPJwwPKKG0dzbJp766tr3MDT8CLcf1p/WGWHhG79VZQgrxKovK8ll4ItjX34weiyDd0RBWVUEGja+RTjAhn6JPYUKyLu0vMbsXZeNzJPf3/oogVVz4eeLjyNpBv+6PXNIcER7J/01w4ii3cOAxCANdacjdmRu3B/AO+w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--mizhang.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=GZ1lBDwj; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--mizhang.bounces.google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc237543b74so6099669276.2 for ; Tue, 23 Jan 2024 16:39:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706056749; x=1706661549; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=YABAD9MCJqjxVx7Kdqag9uuDZvgkIWsvnk7JYS6IBNE=; b=GZ1lBDwj0nqnmPFAqKgkNIhLh0LNdR84u1TeMO1wMfWYlFf+pAbTasBI0Zee7z/Y6H Zy/9wgD/AeyXUWD12b0uh5qcZEuh0ArkuT+DiIHDU6niqpnJSL/ZzCYTy6rip2BMdfeh fkMlGVGq2ibwE5jk/ALtrjKEtCYMPa+Tbu7xZ/rE1NFwYdxzpNwpvM97iE6QSMev7wX0 BXca2IclZx0Sc1VI4C1K+xxQAhxmyL3Ia/QKEreA9HwN6Bq+m/tn93J0RH1jgR/dUgZl ksPDxmxrvpJFB93b9EqMNMaw0QpaAgwPc7HHrZIeZdvmI05bIRUwyQtcYSuBSD6roRl0 gd7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706056749; x=1706661549; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=YABAD9MCJqjxVx7Kdqag9uuDZvgkIWsvnk7JYS6IBNE=; b=lVoX0oSjA6DieWX7pw2LbaakBN9CfKJR6t+j2ELV3OVagbaio80UvDV5RqrjQH+lq4 AXcCt7gQMK1abz7yT6m+O/f9d5wIQ1XMefW6fdOpgqg6u02aYKBCTFsioduAYe8pXWNz belWrhwIpq5rhkPvvjaHZYNsYAlh9uK6mhTTzZV/pdbwQz9A48bs+ILdZISdSq07v219 qVzc/G1/1kmEmR7NsA0hyek6NmYmNyYNIzzAwRlUiPUzgWkeGCejgjpwtQ8rLzAFqDbg Jft2gfpP1eILobniwzTOEECh6wu1rMmuTitfSAoPoK+dmLJ2eiJENy/D5i+KuIyMAQUS 4zuQ== X-Gm-Message-State: AOJu0Yyt7i6udwhcWX8CiatFsfKu11UhF4jni0BgJizx6pNSxT8eH43L stm+pJpWMmEir/bgSe2/gMGovlNw4MKI409ce/HvgQR6PP3IPi8Chk9quzcLSEPLpvf562xSSP/ 6bQqmiA== X-Received: from mizhang-super.c.googlers.com ([35.247.89.60]) (user=mizhang job=sendgmr) by 2002:a05:6902:152:b0:dc2:3268:e9e7 with SMTP id p18-20020a056902015200b00dc23268e9e7mr1388ybh.10.1706056748886; Tue, 23 Jan 2024 16:39:08 -0800 (PST) Reply-To: Mingwei Zhang Date: Wed, 24 Jan 2024 00:38:56 +0000 In-Reply-To: <20240124003858.3954822-1-mizhang@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240124003858.3954822-1-mizhang@google.com> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240124003858.3954822-2-mizhang@google.com> Subject: [PATCH 1/2] KVM: x86/pmu: Reset perf_capabilities in vcpu to 0 if PDCM is disabled From: Mingwei Zhang To: Sean Christopherson , Paolo Bonzini Cc: "H. Peter Anvin" , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Aaron Lewis , Mingwei Zhang Content-Type: text/plain; charset="UTF-8" Reset vcpu->arch.perf_capabilities to 0 if PDCM is disabled in guest cpuid. Without this, there is an issue in live migration. In particular, to migrate a VM with no PDCM enabled, VMM on the source is able to retrieve a non-zero value by reading the MSR_IA32_PERF_CAPABILITIES. However, VMM on the target is unable to set the value. This creates confusions on the user side. Fundamentally, it is because vcpu->arch.perf_capabilities as the cached value of MSR_IA32_PERF_CAPABILITIES is incorrect, and there is nothing wrong on the kvm_get_msr_common() which just reads vcpu->arch.perf_capabilities. Fix the issue by adding the reset code in kvm_vcpu_after_set_cpuid(), i.e. early in VM setup time. Cc: Aaron Lewis Signed-off-by: Mingwei Zhang --- arch/x86/kvm/cpuid.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index adba49afb5fe..416bee03c42a 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -369,6 +369,9 @@ static void kvm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) vcpu->arch.maxphyaddr = cpuid_query_maxphyaddr(vcpu); vcpu->arch.reserved_gpa_bits = kvm_vcpu_reserved_gpa_bits_raw(vcpu); + /* Reset MSR_IA32_PERF_CAPABILITIES guest value to 0 if PDCM is off. */ + if (!guest_cpuid_has(vcpu, X86_FEATURE_PDCM)) + vcpu->arch.perf_capabilities = 0; kvm_pmu_refresh(vcpu); vcpu->arch.cr4_guest_rsvd_bits = __cr4_reserved_bits(guest_cpuid_has, vcpu); -- 2.43.0.429.g432eaa2c6b-goog