Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3698643ybv; Mon, 10 Feb 2020 04:56:31 -0800 (PST) X-Google-Smtp-Source: APXvYqy47ajWnPsQDx32KKmZkB/+JPrE9vItZpYhtCzgh2SfdjWwESyDtxGaYy/3s3GtWhpPBa+/ X-Received: by 2002:a9d:6e05:: with SMTP id e5mr980895otr.46.1581339390958; Mon, 10 Feb 2020 04:56:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581339390; cv=none; d=google.com; s=arc-20160816; b=jylzZTLHUZUreW/C7TOXSyViyMjYKzuOvWEATxN5GHBjdG9HBVVVvb5W/JG7S9pMms RthL55w+Qfci+Bi7Bg58PpIDQc7IH9Jkz+ZKliF1mlZ882haGBSAx7qrXCIh9YfHn/4T 7SuUFWTMJPvjXnSVZIr7UvBgUtRGx22/yGebCjHMKRKeYv4upGTm8iZ6sjmb6bz9m2Tr u8n/hRNV8M3JOZHQLUANDK72rYhuTBiwwf11/sU5hdVtd4u8bX+MktrDpa6gqLOq+nJs vl/MhRKotVNaP+j214sl2tzrvdKMFcklOtHWbOmwyyBqG2naC87YBquwRdIArPhzoyTN 4RRQ== 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=g9oODHUT5HRl5CZZjGrBjDG6is0kWJB3gWvc77Yq+bs=; b=TihxqzjkToRi35nXHkVQDk5LNCdepJQTuDak6Q/HR+4KMtRNMtr+E3wfhkhcsgQZTX FSWkVzga+knF/p0V3237f5tyGTzEMYvyyEoDj5CjmTa4zID5C5N9rMmKoRgB9S55TpMS ulRLPstanNc+7jI3M6GeWJQOS0sKYjZfnEf3W/kfgivoNqeah++4TSgBxErOCzf/FtTT iZ5BTzowgLqAF0cKMwubtHOa+ANiweLfHpP0eIPEGYr08pe9aa2lO5nbnIQJaV9N3EaP H4vNvvunmF+v5v/FpJLeZdolxi7A5eKQsaLcOcSwoj60fuueYrskX1eFEYGjoYN3wX+b Mfsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lG8NgWcX; 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 x72si138084oia.194.2020.02.10.04.56.19; Mon, 10 Feb 2020 04:56:30 -0800 (PST) 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=lG8NgWcX; 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 S1729408AbgBJM4P (ORCPT + 99 others); Mon, 10 Feb 2020 07:56:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:44344 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728574AbgBJMlm (ORCPT ); Mon, 10 Feb 2020 07:41:42 -0500 Received: from localhost (unknown [209.37.97.194]) (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 252A420733; Mon, 10 Feb 2020 12:41:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581338501; bh=39WzRQPwvW5XrxKbELBSz19WS+NFf8umOaaiF2Is8OY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lG8NgWcXaVBJb4mqg/bQIIvUVvMLeoG3aQmQ6RW/RTJYk89FmJUaCZJypVfA9soEW wK+uPUId1KLoMnVOXQH8UHTikRWdVainB2ysbJnJSczItTLDivRP2kHHoH6CEokkEo aMAzJd3QLNV/cSZugQgzt4lwiHFC9rlsGehca/yY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tom Lendacky , Paolo Bonzini Subject: [PATCH 5.5 245/367] KVM: x86: use CPUID to locate host page table reserved bits Date: Mon, 10 Feb 2020 04:32:38 -0800 Message-Id: <20200210122446.800976612@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200210122423.695146547@linuxfoundation.org> References: <20200210122423.695146547@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: Paolo Bonzini commit 7adacf5eb2d2048045d9fd8fdab861fd9e7e2e96 upstream. The comment in kvm_get_shadow_phys_bits refers to MKTME, but the same is actually true of SME and SEV. Just use CPUID[0x8000_0008].EAX[7:0] unconditionally if available, it is simplest and works even if memory is not encrypted. Cc: stable@vger.kernel.org Reported-by: Tom Lendacky Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/mmu/mmu.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -538,16 +538,20 @@ EXPORT_SYMBOL_GPL(kvm_mmu_set_mask_ptes) static u8 kvm_get_shadow_phys_bits(void) { /* - * boot_cpu_data.x86_phys_bits is reduced when MKTME is detected - * in CPU detection code, but MKTME treats those reduced bits as - * 'keyID' thus they are not reserved bits. Therefore for MKTME - * we should still return physical address bits reported by CPUID. + * boot_cpu_data.x86_phys_bits is reduced when MKTME or SME are detected + * in CPU detection code, but the processor treats those reduced bits as + * 'keyID' thus they are not reserved bits. Therefore KVM needs to look at + * the physical address bits reported by CPUID. */ - if (!boot_cpu_has(X86_FEATURE_TME) || - WARN_ON_ONCE(boot_cpu_data.extended_cpuid_level < 0x80000008)) - return boot_cpu_data.x86_phys_bits; + if (likely(boot_cpu_data.extended_cpuid_level >= 0x80000008)) + return cpuid_eax(0x80000008) & 0xff; - return cpuid_eax(0x80000008) & 0xff; + /* + * Quite weird to have VMX or SVM but not MAXPHYADDR; probably a VM with + * custom CPUID. Proceed with whatever the kernel found since these features + * aren't virtualizable (SME/SEV also require CPUIDs higher than 0x80000008). + */ + return boot_cpu_data.x86_phys_bits; } static void kvm_mmu_reset_all_pte_masks(void)