Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3832858pxv; Mon, 19 Jul 2021 09:48:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtCw+PmmI2AKwUgxDeUufHpIp00Lzwlt3EFHmuBGfAjT3HhVRLp4Bl7jRCPU4r2DZSCOh1 X-Received: by 2002:a17:907:9604:: with SMTP id gb4mr27851817ejc.142.1626713334455; Mon, 19 Jul 2021 09:48:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626713334; cv=none; d=google.com; s=arc-20160816; b=C5rklsH+pEgbmcQu9BRJ8pAZGbQVRc0JLwq965HHNHKDjCMV2uI10vTFjZU/V5d1kM diB2NGVnwaTuDOf/AyAY1mrgCjV5WcnBKX8XbvZfC9oJDOPRZOywOwh4jw1gOAuuA7Uz qnnd5FrLQ90d9FbOo7otT0P93s5Gkqs84eNgzjSK9YW25uBGZVWGTTQ6fcxJBVHcUzyU uBrgsR2sxnl2qyvRoSIgUD2CucsWikyJj8gQA4YLLk9iZr561rD84Xq7F2mG2H41D/Yw jekekhLTfL4OGpG+YB+YPhzkvNQtPLe75qachCyf95EFLSRGP34IdkMx3xg3AM4C7IMM cYGg== 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=Qp+AscY1uRUrz9W8tJs95NZiUSzm1B/GQcDhKMtaQu8=; b=eEcognGMelwoUSIt8saPLwiQ8Ddcb3MwwoAG4hM9VD8eQwd33uPgy8rZChPlQeSuEg IPhh5P+7r8B5/mYOxH3A6b91pGjk74cnCZEHb0Awm9QniRpS4FE98vm5bnxJY+LsaPcE KgZVHXsWICagyO8GMJDop2dNzqP62lGC9u6jt0W0WMS3x7FMWY6W5nGa0yM5e76+bXu1 O9JXhXLRPi5CoULyF/JZnRh36HOhA76t71xxHCOVUjoc6OZStU+DQm27NBff4CQDPub5 sTCuTAWUp4muZJPtx7IASIX7D6TmtBzrV7ODh2duB6zhKFP6uqbopcKIvLjSyIjJjwCi va5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vdV1+Nbv; 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 hh4si22770644ejb.79.2021.07.19.09.48.32; Mon, 19 Jul 2021 09:48:54 -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=vdV1+Nbv; 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 S1346018AbhGSQEV (ORCPT + 99 others); Mon, 19 Jul 2021 12:04:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:38958 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245360AbhGSPFo (ORCPT ); Mon, 19 Jul 2021 11:05:44 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 32B7A60551; Mon, 19 Jul 2021 15:46:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626709583; bh=kLTIpvOZ32+6MYMPkGf1nFmXSYOM+osAesHAb6P/h/c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vdV1+NbvXwRicnCNMBxPllxABRji9ZAfPIH3vy8a9rmwPgCRaJTmzTzNLy6DTlU8U MPpEiZIh4JGwes7wHIzGypEr6yCkwsUqw5cfjPZs/20RYC51xtSAFPDxyswSPXAoaT 8iodKS4cnRbx0foJL4gkqKtr8MDEiv8+5lXMofgc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sean Christopherson , Paolo Bonzini Subject: [PATCH 5.4 002/149] KVM: x86: Use guest MAXPHYADDR from CPUID.0x8000_0008 iff TDP is enabled Date: Mon, 19 Jul 2021 16:51:50 +0200 Message-Id: <20210719144901.943271232@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144901.370365147@linuxfoundation.org> References: <20210719144901.370365147@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 @@ -745,8 +745,14 @@ static inline int __do_cpuid_func(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; entry->ebx &= kvm_cpuid_8000_0008_ebx_x86_features;