stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org,
	Sean Christopherson <sean.j.christopherson@intel.com>,
	Tom Lendacky <thomas.lendacky@amd.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: [PATCH 4.19 70/87] KVM: SVM: Override default MMIO mask if memory encryption is enabled
Date: Tue,  3 Mar 2020 18:44:01 +0100	[thread overview]
Message-ID: <20200303174356.572899901@linuxfoundation.org> (raw)
In-Reply-To: <20200303174349.075101355@linuxfoundation.org>

From: Tom Lendacky <thomas.lendacky@amd.com>

commit 52918ed5fcf05d97d257f4131e19479da18f5d16 upstream.

The KVM MMIO support uses bit 51 as the reserved bit to cause nested page
faults when a guest performs MMIO. The AMD memory encryption support uses
a CPUID function to define the encryption bit position. Given this, it is
possible that these bits can conflict.

Use svm_hardware_setup() to override the MMIO mask if memory encryption
support is enabled. Various checks are performed to ensure that the mask
is properly defined and rsvd_bits() is used to generate the new mask (as
was done prior to the change that necessitated this patch).

Fixes: 28a1f3ac1d0c ("kvm: x86: Set highest physical address bits in non-present/reserved SPTEs")
Suggested-by: Sean Christopherson <sean.j.christopherson@intel.com>
Reviewed-by: Sean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 arch/x86/kvm/svm.c |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -1298,6 +1298,47 @@ static void shrink_ple_window(struct kvm
 				    control->pause_filter_count, old);
 }
 
+/*
+ * The default MMIO mask is a single bit (excluding the present bit),
+ * which could conflict with the memory encryption bit. Check for
+ * memory encryption support and override the default MMIO mask if
+ * memory encryption is enabled.
+ */
+static __init void svm_adjust_mmio_mask(void)
+{
+	unsigned int enc_bit, mask_bit;
+	u64 msr, mask;
+
+	/* If there is no memory encryption support, use existing mask */
+	if (cpuid_eax(0x80000000) < 0x8000001f)
+		return;
+
+	/* If memory encryption is not enabled, use existing mask */
+	rdmsrl(MSR_K8_SYSCFG, msr);
+	if (!(msr & MSR_K8_SYSCFG_MEM_ENCRYPT))
+		return;
+
+	enc_bit = cpuid_ebx(0x8000001f) & 0x3f;
+	mask_bit = boot_cpu_data.x86_phys_bits;
+
+	/* Increment the mask bit if it is the same as the encryption bit */
+	if (enc_bit == mask_bit)
+		mask_bit++;
+
+	/*
+	 * If the mask bit location is below 52, then some bits above the
+	 * physical addressing limit will always be reserved, so use the
+	 * rsvd_bits() function to generate the mask. This mask, along with
+	 * the present bit, will be used to generate a page fault with
+	 * PFER.RSV = 1.
+	 *
+	 * If the mask bit location is 52 (or above), then clear the mask.
+	 */
+	mask = (mask_bit < 52) ? rsvd_bits(mask_bit, 51) | PT_PRESENT_MASK : 0;
+
+	kvm_mmu_set_mmio_spte_mask(mask, PT_WRITABLE_MASK | PT_USER_MASK);
+}
+
 static __init int svm_hardware_setup(void)
 {
 	int cpu;
@@ -1352,6 +1393,8 @@ static __init int svm_hardware_setup(voi
 		}
 	}
 
+	svm_adjust_mmio_mask();
+
 	for_each_possible_cpu(cpu) {
 		r = svm_cpu_init(cpu);
 		if (r)



  parent reply	other threads:[~2020-03-03 18:02 UTC|newest]

Thread overview: 102+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-03 17:42 [PATCH 4.19 00/87] 4.19.108-stable review Greg Kroah-Hartman
2020-03-03 17:42 ` [PATCH 4.19 01/87] irqchip/gic-v3-its: Fix misuse of GENMASK macro Greg Kroah-Hartman
2020-03-03 17:42 ` [PATCH 4.19 02/87] iwlwifi: pcie: fix rb_allocator workqueue allocation Greg Kroah-Hartman
2020-03-03 17:42 ` [PATCH 4.19 03/87] ipmi:ssif: Handle a possible NULL pointer reference Greg Kroah-Hartman
2020-03-03 17:42 ` [PATCH 4.19 04/87] drm/msm: Set dma maximum segment size for mdss Greg Kroah-Hartman
2020-03-04 15:13   ` Pavel Machek
2020-03-04 17:18     ` Greg Kroah-Hartman
2020-03-09 10:14       ` [PATCH] drm/msm: fix leaks if initialization fails Pavel Machek
2020-03-10 21:03         ` Doug Anderson
2020-03-03 17:42 ` [PATCH 4.19 05/87] sched/core: Dont skip remote tick for idle CPUs Greg Kroah-Hartman
2020-03-04 15:15   ` Pavel Machek
2020-03-04 17:17     ` Greg Kroah-Hartman
2020-03-03 17:42 ` [PATCH 4.19 06/87] dax: pass NOWAIT flag to iomap_apply Greg Kroah-Hartman
2020-03-03 17:42 ` [PATCH 4.19 07/87] mac80211: consider more elements in parsing CRC Greg Kroah-Hartman
2020-03-03 17:42 ` [PATCH 4.19 08/87] cfg80211: check wiphy driver existence for drvinfo report Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 09/87] s390/zcrypt: fix card and queue total counter wrap Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 10/87] qmi_wwan: re-add DW5821e pre-production variant Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 11/87] qmi_wwan: unconditionally reject 2 ep interfaces Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 12/87] arm/ftrace: Fix BE text poking Greg Kroah-Hartman
2020-03-05 13:49   ` Pavel Machek
2020-03-05 14:53     ` Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 13/87] ARM: dts: sti: fixup sound frame-inversion for stihxxx-b2120.dtsi Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 14/87] soc/tegra: fuse: Fix build with Tegra194 configuration Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 15/87] net: ena: fix potential crash when rxfh key is NULL Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 16/87] net: ena: fix uses of round_jiffies() Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 17/87] net: ena: add missing ethtool TX timestamping indication Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 18/87] net: ena: fix incorrect default RSS key Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 19/87] net: ena: rss: fix failure to get indirection table Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 20/87] net: ena: rss: store hash function as values and not bits Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 21/87] net: ena: fix incorrectly saving queue numbers when setting RSS indirection table Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 22/87] net: ena: ethtool: use correct value for crc32 hash Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 23/87] net: ena: ena-com.c: prevent NULL pointer dereference Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 24/87] cifs: Fix mode output in debugging statements Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 25/87] bcache: ignore pending signals when creating gc and allocator thread Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 26/87] cfg80211: add missing policy for NL80211_ATTR_STATUS_CODE Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 27/87] sysrq: Restore original console_loglevel when sysrq disabled Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 28/87] sysrq: Remove duplicated sysrq message Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 29/87] net: fib_rules: Correctly set table field when table number exceeds 8 bits Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 30/87] net: mscc: fix in frame extraction Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 31/87] net: phy: restore mdio regs in the iproc mdio driver Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 32/87] net: sched: correct flower port blocking Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 33/87] nfc: pn544: Fix occasional HW initialization failure Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 34/87] sctp: move the format error check out of __sctp_sf_do_9_1_abort Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 35/87] ipv6: Fix route replacement with dev-only route Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 36/87] ipv6: Fix nlmsg_flags when splitting a multipath route Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 37/87] qede: Fix race between rdma destroy workqueue and link change event Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 38/87] net/tls: Fix to avoid gettig invalid tls record Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 39/87] ext4: potential crash on allocation error in ext4_alloc_flex_bg_array() Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 40/87] audit: fix error handling in audit_data_to_entry() Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 41/87] ACPICA: Introduce ACPI_ACCESS_BYTE_WIDTH() macro Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 42/87] ACPI: watchdog: Fix gas->access_width usage Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 43/87] KVM: VMX: check descriptor table exits on instruction emulation Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 44/87] HID: ite: Only bind to keyboard USB interface on Acer SW5-012 keyboard dock Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 45/87] HID: core: fix off-by-one memset in hid_report_raw_event() Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 46/87] HID: core: increase HID report buffer size to 8KiB Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 47/87] macintosh: therm_windtunnel: fix regression when instantiating devices Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 48/87] tracing: Disable trace_printk() on post poned tests Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 49/87] Revert "PM / devfreq: Modify the device name as devfreq(X) for sysfs" Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 50/87] amdgpu/gmc_v9: save/restore sdpif regs during S3 Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 51/87] vhost: Check docket sk_family instead of call getname Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 52/87] HID: alps: Fix an error handling path in alps_input_configured() Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 53/87] HID: hiddev: Fix race in in hiddev_disconnect() Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 54/87] MIPS: VPE: Fix a double free and a memory leak in release_vpe() Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 55/87] i2c: altera: Fix potential integer overflow Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 56/87] i2c: jz4780: silence log flood on txabrt Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 57/87] drm/i915/gvt: Fix orphan vgpu dmabuf_objs lifetime Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 58/87] drm/i915/gvt: Separate display reset from ALL_ENGINES reset Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 59/87] hv_netvsc: Fix unwanted wakeup in netvsc_attach() Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 60/87] usb: charger: assign specific number for enum value Greg Kroah-Hartman
2020-03-04 17:27   ` Pavel Machek
2020-03-04 17:39     ` Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 61/87] s390/qeth: vnicc Fix EOPNOTSUPP precedence Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 62/87] net: netlink: cap max groups which will be considered in netlink_bind() Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 63/87] net: atlantic: fix use after free kasan warn Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 64/87] net: atlantic: fix potential error handling Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 65/87] net/smc: no peer ID in CLC decline for SMCD Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 66/87] net: ena: make ena rxfh support ETH_RSS_HASH_NO_CHANGE Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 67/87] namei: only return -ECHILD from follow_dotdot_rcu() Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 68/87] mwifiex: drop most magic numbers from mwifiex_process_tdls_action_frame() Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 69/87] mwifiex: delete unused mwifiex_get_intf_num() Greg Kroah-Hartman
2020-03-03 17:44 ` Greg Kroah-Hartman [this message]
2020-03-03 17:44 ` [PATCH 4.19 71/87] KVM: Check for a bad hva before dropping into the ghc slow path Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 72/87] sched/fair: Optimize update_blocked_averages() Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 73/87] sched/fair: Fix O(nr_cgroups) in the load balancing path Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 74/87] perf stat: Use perf_evsel__is_clocki() for clock events Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 75/87] perf stat: Fix shadow stats " Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 76/87] drivers: net: xgene: Fix the order of the arguments of alloc_etherdev_mqs() Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 77/87] kprobes: Set unoptimized flag after unoptimizing code Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 78/87] pwm: omap-dmtimer: put_device() after of_find_device_by_node() Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 79/87] perf hists browser: Restore ESC as "Zoom out" of DSO/thread/etc Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 80/87] KVM: x86: Remove spurious kvm_mmu_unload() from vcpu destruction path Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 81/87] KVM: x86: Remove spurious clearing of async #PF MSR Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 82/87] thermal: brcmstb_thermal: Do not use DT coefficients Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 83/87] netfilter: nft_tunnel: no need to call htons() when dumping ports Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 84/87] netfilter: nf_flowtable: fix documentation Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 85/87] padata: always acquire cpu_hotplug_lock before pinst->lock Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 86/87] mm/huge_memory.c: use head to check huge zero page Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 87/87] mm, thp: fix defrag setting if newline is not used Greg Kroah-Hartman
2020-03-03 22:10 ` [PATCH 4.19 00/87] 4.19.108-stable review Jon Hunter
2020-03-03 23:18 ` shuah
2020-03-04  7:09 ` Naresh Kamboju
2020-03-04 16:52 ` Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200303174356.572899901@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=sean.j.christopherson@intel.com \
    --cc=stable@vger.kernel.org \
    --cc=thomas.lendacky@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).