Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp2250328ybd; Mon, 24 Jun 2019 03:18:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqyNSFTA5iXJ9sKMOkg4MuVdGf/PkJDKzO6kxsnqp3UOLIIk0EJdLzL8DIINOGLjGqHqhqpE X-Received: by 2002:a63:3383:: with SMTP id z125mr18374735pgz.8.1561371501512; Mon, 24 Jun 2019 03:18:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561371501; cv=none; d=google.com; s=arc-20160816; b=rl8QWVAC1vwRFyabAV1cGQ67Ya9SiwQDRs22OlMq6x9nO619w0DQg8kMoKMXXx6n/v 9LuMr2RJJlCaAE4yST2yuZSB3IfVkIFI+CwgtMK3QT6jCm26LFpyquBg0Es3pBkehOl6 7q2fZvW1qTMdo65AZ2CMkOpKpA89rF4LGfx1GzDuiZUHc6QiCxRncImc0grY9Gs0L/C6 UBjrlHR15ahlclW9kPBaBq5tc4iM3jvEDzLuITKIS5zwBd/io0Y5GHSJtRQ5nuIY2w86 ms2uvLeKksj1rwGTOw79G9Pwp29gfXchmRtiBNccD1lqK54mtHjwUXe5q30hvf/NbLYY /kqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Z/vYY44ySFF9gi07SdWopVde0IvlbrUOi3II07hRVcI=; b=zsLZ/tyA9xwnDtgMvmbCr+y4IgVKpPI1hJ6H1e/qWaX70dV2zkWbN8lQgVsq7tnDVQ MaBuKrjDkArtoGhP5ZgCwSlIYmkQzFQZJHi0W5R8itGZs2uW8VjaB2y5wO9F8Gw9Yj77 Dfqni9OprnSgIaUTzQDbbH/Ki5kJy4z7a3PEzpK0RGTd22colKIjeZYWXEjcNsMOn4Lr QoFzCcj6ecrZvINierxeRP/QZFBbSGyGw156yUt45T5ZP4Y3/qSxoCPXat+NWSgjCQXz Vy+CjnznifavDlImrE9rdrz7wcb6nWunwu1skUueKyR7YYWAcI8M+LvDcTNUO18AB6A2 ZwYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xawQ68yE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h8si9536433plr.291.2019.06.24.03.18.05; Mon, 24 Jun 2019 03:18:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xawQ68yE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730975AbfFXKR1 (ORCPT + 99 others); Mon, 24 Jun 2019 06:17:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:55058 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730957AbfFXKRY (ORCPT ); Mon, 24 Jun 2019 06:17:24 -0400 Received: from localhost (f4.8f.5177.ip4.static.sl-reverse.com [119.81.143.244]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4BAA1205C9; Mon, 24 Jun 2019 10:17:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561371443; bh=joX4oBxgWRfbTYhg0szXbGlMdRkBFd2o4j+rCTRn/x0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xawQ68yENsmVl3rZNFD96qhvJV6X9rsrDEQFxn2ZaNKullWoQC/635w7HMAm6rSzX TyCkaJr2uKC7piN0MttcMXEIeJbNgtn6DXg+c6Q2ZcEsDm9ayr7KkhLlssNV8X+Fy4 2kkQC1Op3dyBfCSfggmHn5J4Nkm3OOeSQL386eTc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiri Palecek , Sean Christopherson , Paolo Bonzini Subject: [PATCH 5.1 104/121] KVM: x86/mmu: Allocate PAE root array when using SVMs 32-bit NPT Date: Mon, 24 Jun 2019 17:57:16 +0800 Message-Id: <20190624092326.022031366@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190624092320.652599624@linuxfoundation.org> References: <20190624092320.652599624@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson commit b6b80c78af838bef17501416d5d383fedab0010a upstream. SVM's Nested Page Tables (NPT) reuses x86 paging for the host-controlled page walk. For 32-bit KVM, this means PAE paging is used even when TDP is enabled, i.e. the PAE root array needs to be allocated. Fixes: ee6268ba3a68 ("KVM: x86: Skip pae_root shadow allocation if tdp enabled") Cc: stable@vger.kernel.org Reported-by: Jiri Palecek Signed-off-by: Sean Christopherson Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/mmu.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -5591,14 +5591,18 @@ static int alloc_mmu_pages(struct kvm_vc struct page *page; int i; - if (tdp_enabled) - return 0; - /* - * When emulating 32-bit mode, cr3 is only 32 bits even on x86_64. - * Therefore we need to allocate shadow page tables in the first - * 4GB of memory, which happens to fit the DMA32 zone. + * When using PAE paging, the four PDPTEs are treated as 'root' pages, + * while the PDP table is a per-vCPU construct that's allocated at MMU + * creation. When emulating 32-bit mode, cr3 is only 32 bits even on + * x86_64. Therefore we need to allocate the PDP table in the first + * 4GB of memory, which happens to fit the DMA32 zone. Except for + * SVM's 32-bit NPT support, TDP paging doesn't use PAE paging and can + * skip allocating the PDP table. */ + if (tdp_enabled && kvm_x86_ops->get_tdp_level(vcpu) > PT32E_ROOT_LEVEL) + return 0; + page = alloc_page(GFP_KERNEL_ACCOUNT | __GFP_DMA32); if (!page) return -ENOMEM;