Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3796918pxv; Mon, 19 Jul 2021 08:59:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxd1ooQbOcPpIkboL0YodviEfjl09rZCHRZ8fl/VwX2qVpKmDYdhtCUt5/Npa2kuCj+U55K X-Received: by 2002:a6b:c40d:: with SMTP id y13mr19652593ioa.78.1626710361016; Mon, 19 Jul 2021 08:59:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626710361; cv=none; d=google.com; s=arc-20160816; b=bP4ddWlA8nnI25fw4NOf7zayK6ioaJPJaRoq2YPIPF2PvWngnBwVCEolDGkAtgFPr6 IgvcNGlEFbLnrRWGzSLYnjxtSqtAXUoBGSlW670as2c8/rXgnRHLDjj4xw2LY6mfgA1Z YqKoP+rt/thYPCec20G92cB6WJ+YIryCN061w1Tov+9EwSjpqdfP8TN7qZpkTUc/hHc2 Ibi9/g9YUZtshGTbBBzBOXUE5ciSyckGIl5tBnr685pYOPstaIhZm4sQti/hlCkeoOZq 8sSojBVmhZduQxXtqLqt9YbAY0hCR5Btxm0XhbG7Bcq7ZuLr+rDdfz85kX/sDi+fDRQT 0WSw== 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=ywFRNjnYvx8VBXlPDIv7o3oUrB8DDmgUUXfV1ivBQx8=; b=ixHfgEkFA2Zyv89Y/0I4KP43UF4aSFk912Sqv4Wl8+cBJZrxL5LnbFWSo/jsPPm3t+ T/2wlFG2fBLc15MLR8NLqpfsPRUGwRrycE5qZafOGZuR0+AK7UE/YPtrCwKahxtL9CBj OCXrWO55LR0oc16qkH2QHtKGGxA+rFeBG3aabeTWtE7fdJaibielmfRvnZgHxwvVYJEm duSQVSnca52xPsaswYqiRgoIFnsoPLxarqZSolL3EYA1SMnMZsO/LTgL8dFmENbL7Y5f QalMiBMDSDrRMNe90q//gg7VHuQVd/U9l4d8sA9QoEIYsqG7wOOWKhNp67cDJpDzamfH 49TA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=B84ytYHB; 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 r4si19072571ioh.93.2021.07.19.08.59.09; Mon, 19 Jul 2021 08:59:21 -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=B84ytYHB; 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 S1346804AbhGSPR3 (ORCPT + 99 others); Mon, 19 Jul 2021 11:17:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:40448 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245408AbhGSOr1 (ORCPT ); Mon, 19 Jul 2021 10:47:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 778A16135D; Mon, 19 Jul 2021 15:23:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626708225; bh=zJBtUAFuuksWae+2E56PDniugb1rGdBRRDPRRqC7C1E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B84ytYHBgjSzdJZuE4uUlqskKP72rjB2TZgv98AgjBXCEGb0LDNOMIrJcCeWEta3W tQva5ZuH9u7dRNWs1zIfrtniy1ypLAC+sv586EfLNJNDOgKvPm3SmC+1pGqVDcw+PB EDf1/SO3J12wd8ttJB4hBu5+9oZ9DRULvjiIBrIo= 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.14 230/315] KVM: x86: Use guest MAXPHYADDR from CPUID.0x8000_0008 iff TDP is enabled Date: Mon, 19 Jul 2021 16:51:59 +0200 Message-Id: <20210719144950.984768127@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144942.861561397@linuxfoundation.org> References: <20210719144942.861561397@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 @@ -649,8 +649,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; /*