Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3778545pxv; Mon, 19 Jul 2021 08:32:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyur2tWXFuy7OuMQldIN83L1cO8R1Imd6u+U/gjZBZYxgsysWvzDBEsW4EvVzMbqABa5x2R X-Received: by 2002:a05:6402:4413:: with SMTP id y19mr31428497eda.142.1626708731591; Mon, 19 Jul 2021 08:32:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626708731; cv=none; d=google.com; s=arc-20160816; b=WKNMKCuvQifwwmCNMYgCEzih1Hw8nbeLlIfgpky0F9qoLyiKDinqryMj2oTM7Ufwvr bQeq2Z8/1Df9DstrKEXPVUUotcVkBu8n/fcCLpvUvacWWT5gbX0fMQMiTLpYwIAn4aXg DlG3XHF81ont/CdUUNYE1RGXow67u/eSu3QzQxQEh/4DBzzv4bCs/o6JmJOjS6Y5pAT1 cnUlCf3B0XsXKhnpmyu6DRZmLnPHipN0ndZF5t5kXxqS0UgVlMRhPdI2GTNeoaWhMB5j s9Jw3+x9zzPxd+q3kRafk8Wlwr+OB5C9cQJ5Hrn4HklhNGXIvs3Q+FpRIQYFsfuvlxGs KgwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=R13cdf2WiQnnXY5v59Z5BJIzZVHyoWFAN8gokrRWc2g=; b=MSHii1852/aLtlmKrHBxDv0EcC2bRLowB5XjziIywg78mnwGNmpGr2QwRXGWA+NGhq +Lv24iSzr2SaepZl+zeP0FIRW/SindJfO1TZm6TGYyfgXsu8ACoZQz1RpLZQw2y/MwfF MK4G3PIemDuENqvmMeI/DSqVrh3zX4sc2JNOfL4S7+uaBJEIcg4E0DOq3IoInWJ/UVI5 VasanHz3qVgQHq+UrVz5XSPijZ6LSch7+xfmf/xdvqGA7ncjQcq7THu8c4mfowKmNgLS vb1n8J8YgUj/BoQimyQcC8aoLCgG3JOg05eqdqGM0eHniByCqS7pZa8cY8NISwg1FlND Qz2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PzEPtGwB; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b3si20946894ejg.526.2021.07.19.08.31.49; Mon, 19 Jul 2021 08:32:11 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=PzEPtGwB; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238697AbhGSOtz (ORCPT + 99 others); Mon, 19 Jul 2021 10:49:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:47358 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244172AbhGSOcd (ORCPT ); Mon, 19 Jul 2021 10:32:33 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CF69A60FE4; Mon, 19 Jul 2021 15:12:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626707563; bh=R1Xihc1NNDZ0fneJ85QhbquZvOMvD+zfFNAFUL88etY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PzEPtGwBpX+ONO7L63bpnyrVAXNXfzOUt206ldtkj8kGVTbZBqT43Ks4bcO5D3HJF vzZaaA1H41/LiLzx+ecZB9wEbTIq7lcJPlf4awgdtQv6lNPO3wSoRDLJBUWrmNW56V GIq2y6cY/9yB2slRsFmmGVrPRkXy8l23IBPIpACE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sean Christopherson , Paolo Bonzini Subject: [PATCH 4.9 180/245] KVM: x86: Use guest MAXPHYADDR from CPUID.0x8000_0008 iff TDP is enabled Date: Mon, 19 Jul 2021 16:52:02 +0200 Message-Id: <20210719144946.221453777@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144940.288257948@linuxfoundation.org> References: <20210719144940.288257948@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson commit 4bf48e3c0aafd32b960d341c4925b48f416f14a5 upstream. Ignore the guest MAXPHYADDR reported by CPUID.0x8000_0008 if TDP, i.e. NPT, is disabled, and instead use the host's MAXPHYADDR. Per AMD'S APM: Maximum guest physical address size in bits. This number applies only to guests using nested paging. When this field is zero, refer to the PhysAddrSize field for the maximum guest physical address size. Fixes: 24c82e576b78 ("KVM: Sanitize cpuid") Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson Message-Id: <20210623230552.4027702-2-seanjc@google.com> Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/cpuid.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -633,8 +633,14 @@ static inline int __do_cpuid_ent(struct unsigned virt_as = max((entry->eax >> 8) & 0xff, 48U); unsigned phys_as = entry->eax & 0xff; - if (!g_phys_as) + /* + * Use bare metal's MAXPHADDR if the CPU doesn't report guest + * MAXPHYADDR separately, or if TDP (NPT) is disabled, as the + * guest version "applies only to guests using nested paging". + */ + if (!g_phys_as || !tdp_enabled) g_phys_as = phys_as; + entry->eax = g_phys_as | (virt_as << 8); entry->edx = 0; /*