From: Ben Hutchings <ben@decadent.org.uk>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: akpm@linux-foundation.org, "Paolo Bonzini" <pbonzini@redhat.com>,
"Petr Matousek" <pmatouse@redhat.com>,
"Andy Lutomirski" <luto@amacapital.net>,
"Linus Torvalds" <torvalds@linux-foundation.org>,
stable@vger.kernel.org, "Gleb Natapov" <gleb@kernel.org>
Subject: [PATCH 3.2 097/102] x86,kvm,vmx: Preserve CR4 across VM entry
Date: Sat, 01 Nov 2014 22:28:03 +0000 [thread overview]
Message-ID: <lsq.1414880883.43488917@decadent.org.uk> (raw)
In-Reply-To: <lsq.1414880882.522510247@decadent.org.uk>
3.2.64-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: Andy Lutomirski <luto@amacapital.net>
commit d974baa398f34393db76be45f7d4d04fbdbb4a0a upstream.
CR4 isn't constant; at least the TSD and PCE bits can vary.
TBH, treating CR0 and CR3 as constant scares me a bit, too, but it looks
like it's correct.
This adds a branch and a read from cr4 to each vm entry. Because it is
extremely likely that consecutive entries into the same vcpu will have
the same host cr4 value, this fixes up the vmcs instead of restoring cr4
after the fact. A subsequent patch will add a kernel-wide cr4 shadow,
reducing the overhead in the common case to just two memory reads and a
branch.
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Cc: stable@vger.kernel.org
Cc: Petr Matousek <pmatouse@redhat.com>
Cc: Gleb Natapov <gleb@kernel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
[bwh: Backported to 3.2:
- Adjust context
- Add struct vcpu_vmx *vmx parameter to vmx_set_constant_host_state(), done
upstream in commit a547c6db4d2f ("KVM: VMX: Enable acknowledge interupt
on vmexit")]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
arch/x86/kvm/vmx.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -390,6 +390,7 @@ struct vcpu_vmx {
u16 fs_sel, gs_sel, ldt_sel;
int gs_ldt_reload_needed;
int fs_reload_needed;
+ unsigned long vmcs_host_cr4; /* May not match real cr4 */
} host_state;
struct {
int vm86_active;
@@ -3631,16 +3632,21 @@ static void vmx_disable_intercept_for_ms
* Note that host-state that does change is set elsewhere. E.g., host-state
* that is set differently for each CPU is set in vmx_vcpu_load(), not here.
*/
-static void vmx_set_constant_host_state(void)
+static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
{
u32 low32, high32;
unsigned long tmpl;
struct desc_ptr dt;
+ unsigned long cr4;
vmcs_writel(HOST_CR0, read_cr0() | X86_CR0_TS); /* 22.2.3 */
- vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
+ /* Save the most likely value for this task's CR4 in the VMCS. */
+ cr4 = read_cr4();
+ vmcs_writel(HOST_CR4, cr4); /* 22.2.3, 22.2.5 */
+ vmx->host_state.vmcs_host_cr4 = cr4;
+
vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
vmcs_write16(HOST_DS_SELECTOR, __KERNEL_DS); /* 22.2.4 */
vmcs_write16(HOST_ES_SELECTOR, __KERNEL_DS); /* 22.2.4 */
@@ -3762,7 +3768,7 @@ static int vmx_vcpu_setup(struct vcpu_vm
vmcs_write16(HOST_FS_SELECTOR, 0); /* 22.2.4 */
vmcs_write16(HOST_GS_SELECTOR, 0); /* 22.2.4 */
- vmx_set_constant_host_state();
+ vmx_set_constant_host_state(vmx);
#ifdef CONFIG_X86_64
rdmsrl(MSR_FS_BASE, a);
vmcs_writel(HOST_FS_BASE, a); /* 22.2.4 */
@@ -6172,6 +6178,7 @@ static void atomic_switch_perf_msrs(stru
static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
{
struct vcpu_vmx *vmx = to_vmx(vcpu);
+ unsigned long cr4;
if (is_guest_mode(vcpu) && !vmx->nested.nested_run_pending) {
struct vmcs12 *vmcs12 = get_vmcs12(vcpu);
@@ -6202,6 +6209,12 @@ static void __noclone vmx_vcpu_run(struc
if (test_bit(VCPU_REGS_RIP, (unsigned long *)&vcpu->arch.regs_dirty))
vmcs_writel(GUEST_RIP, vcpu->arch.regs[VCPU_REGS_RIP]);
+ cr4 = read_cr4();
+ if (unlikely(cr4 != vmx->host_state.vmcs_host_cr4)) {
+ vmcs_writel(HOST_CR4, cr4);
+ vmx->host_state.vmcs_host_cr4 = cr4;
+ }
+
/* When single-stepping over STI and MOV SS, we must clear the
* corresponding interruptibility bits in the guest state. Otherwise
* vmentry fails as it then expects bit 14 (BS) in pending debug
@@ -6666,7 +6679,7 @@ static void prepare_vmcs02(struct kvm_vc
* Other fields are different per CPU, and will be set later when
* vmx_vcpu_load() is called, and when vmx_save_host_state() is called.
*/
- vmx_set_constant_host_state();
+ vmx_set_constant_host_state(vmx);
/*
* HOST_RSP is normally set correctly in vmx_vcpu_run() just before
next prev parent reply other threads:[~2014-11-01 22:53 UTC|newest]
Thread overview: 120+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-01 22:28 [PATCH 3.2 000/102] 3.2.64-rc1 review Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 040/102] usb: hub: take hub->hdev reference when processing from eventlist Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 018/102] drm/vmwgfx: Fix a potential infinite spin waiting for fifo idle Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 091/102] KVM: x86: Emulator fixes for eip canonical checks on near branches Ben Hutchings
2014-11-02 8:44 ` Nadav Amit
2014-11-03 13:51 ` Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 025/102] usb: dwc3: core: use pm_runtime_put_sync() on remove Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 093/102] KVM: x86: Handle errors when RIP is set during far jumps Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 039/102] Input: serport - add compat handling for SPIOCSTYPE ioctl Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 043/102] Input: i8042 - add Fujitsu U574 to no_timeout dmi table Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 034/102] Input: synaptics - add support for ForcePads Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 013/102] ata_piix: Add Device IDs for Intel 9 Series PCH Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 014/102] Revert "iwlwifi: dvm: don't enable CTS to self" Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 030/102] Input: elantech - fix detection of touchpad on ASUS s301l Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 080/102] ipv4: avoid parallel route cache gc executions Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 068/102] parisc: Only use -mfast-indirect-calls option for 32-bit kernel builds Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 008/102] MIPS: ZBOOT: add missing <linux/string.h> include Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 074/102] shmem: fix nlink for rename overwrite directory Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 086/102] KVM: x86: Improve thread safety in pit Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 083/102] ext4: fix BUG_ON in mb_free_blocks() Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 071/102] MIPS: mcount: Adjust stack pointer for static trace in MIPS32 Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 085/102] KVM: x86: Check non-canonical addresses upon WRMSR Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 062/102] can: flexcan: correctly initialize mailboxes Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 100/102] nfsd: Fix ACL null pointer deref Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 004/102] percpu: free percpu allocation info for uniprocessor system Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 002/102] percpu: fix pcpu_alloc_pages() failure path Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 033/102] perf: Fix a race condition in perf_remove_from_context() Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 081/102] ipv4: disable bh while doing route gc Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 053/102] iscsi-target: Fix memory corruption in iscsit_logout_post_handler_diffcid Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 066/102] ALSA: pcm: fix fifo_size frame calculation Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 045/102] futex: Unlock hb->lock in futex_wait_requeue_pi() error path Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 088/102] kvm: vmx: handle invvpid vm exit gracefully Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 076/102] perf: fix perf bug in fork() Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 016/102] USB: sierra: avoid CDC class functions on "68A3" devices Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 094/102] net: sctp: fix skb_over_panic when receiving malformed ASCONF chunks Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 077/102] init/Kconfig: Hide printk log config if CONFIG_PRINTK=n Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 090/102] KVM: x86: Fix wrong masking on relative jump/call Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 096/102] net: sctp: fix remote memory pressure from excessive queueing Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 084/102] ipv6: reuse ip6_frag_id from ip6_ufo_append_data Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 078/102] MIPS: Fix forgotten preempt_enable() when CPU has inclusive pcaches Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 005/102] cgroup: reject cgroup names with '\n' Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 037/102] libceph: add process_one_ticket() helper Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 001/102] regulatory: add NUL to alpha2 Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 044/102] Input: i8042 - add nomux quirk for Avatar AVIU-145A6 Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 015/102] USB: ftdi_sio: add support for NOVITUS Bono E thermal printer Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 007/102] rtlwifi: rtl8192cu: Add new ID Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 054/102] iscsi-target: avoid NULL pointer in iscsi_copy_param_list failure Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 003/102] percpu: perform tlb flush after pcpu_map_pages() failure Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 061/102] can: flexcan: mark TX mailbox as TX_INACTIVE Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 065/102] can: at91_can: add missing prepare and unprepare of the clock Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 028/102] drm/radeon: add connector quirk for fujitsu board Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 082/102] ipv6: reallocate addrconf router for ipv6 address when lo device up Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 038/102] libceph: do not hard code max auth ticket len Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 027/102] ahci: add pcid for Marvel 0x9182 controller Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 012/102] ahci: Add Device IDs for Intel 9 Series PCH Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 073/102] ocfs2/dlm: do not get resource spinlock if lockres is new Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 026/102] usb: dwc3: core: fix order of PM runtime calls Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 056/102] [SCSI] libiscsi: fix potential buffer overrun in __iscsi_conn_send_pdu Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 049/102] alarmtimer: Lock k_itimer during timer callback Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 046/102] jiffies: Fix timeval conversion to jiffies Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 051/102] vfs: Fold follow_mount_rcu() into follow_dotdot_rcu() Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 042/102] xhci: Fix null pointer dereference if xhci initialization fails Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 024/102] ACPI / cpuidle: fix deadlock between cpuidle_lock and cpu_hotplug.lock Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 041/102] storage: Add single-LUN quirk for Jaz USB Adapter Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 029/102] usb: host: xhci: fix compliance mode workaround Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 019/102] xfs: don't dirty buffers beyond EOF Ben Hutchings
2014-11-04 7:09 ` Dave Chinner
2014-11-05 19:58 ` Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 095/102] net: sctp: fix panic on duplicate ASCONF chunks Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 099/102] ext2: Fix fs corruption in ext2_get_xip_mem() Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 063/102] can: flexcan: implement workaround for errata ERR005829 Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 035/102] libceph: rename ceph_msg::front_max to front_alloc_len Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 098/102] dm crypt: fix access beyond the end of allocated space Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 067/102] Fix nasty 32-bit overflow bug in buffer i/o code Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 087/102] nEPT: Nested INVEPT Ben Hutchings
2014-11-02 9:03 ` Paolo Bonzini
2014-11-03 13:44 ` Ben Hutchings
2014-11-03 15:29 ` Paolo Bonzini
2014-11-05 20:21 ` Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 075/102] mm: migrate: Close race between migration completion and mprotect Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 006/102] KVM: s390: Fix user triggerable bug in dead code Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 089/102] KVM: x86 emulator: Use opcode::execute for CALL Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 064/102] can: flexcan: put TX mailbox into TX_INACTIVE mode after tx-complete Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 079/102] ipv4: move route garbage collector to work queue Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 072/102] nilfs2: fix data loss with mmap() Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 021/102] xen/manage: Always freeze/thaw processes when suspend/resuming Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 055/102] NFSv4: Fix another bug in the close/open_downgrade code Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 059/102] USB: storage: Add quirks for Entrega/Xircom USB to SCSI converters Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 101/102] ipvs: avoid netns exit crash on ip_vs_conn_drop_conntrack Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 020/102] ALSA: hda - Fix COEF setups for ALC1150 codec Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 057/102] USB: storage: Add quirk for Adaptec USBConnect 2000 USB-to-SCSI Adapter Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 102/102] ring-buffer: Fix infinite spin in reading buffer Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 010/102] regmap: Fix handling of volatile registers for format_write() chips Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 092/102] KVM: x86: use new CS.RPL as CPL during task switch Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 017/102] USB: sierra: add 1199:68AA device ID Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 023/102] block: Fix dev_t minor allocation lifetime Ben Hutchings
2014-11-01 23:18 ` Jens Axboe
2014-11-01 23:48 ` Ben Hutchings
2014-11-03 1:24 ` Jens Axboe
2014-11-01 22:28 ` [PATCH 3.2 070/102] ARM: 8165/1: alignment: don't break misaligned NEON load/store Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 009/102] regmap: if format_write is used, declare all registers as "unreadable" Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 011/102] drm/i915: Remove bogus __init annotation from DMI callbacks Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 022/102] aio: add missing smp_rmb() in read_events_ring Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 050/102] don't bugger nd->seq on set_root_rcu() from follow_dotdot_rcu() Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 069/102] sched: Fix unreleased llc_shared_mask bit during CPU hotplug Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 048/102] alarmtimer: Do not signal SIGEV_NONE timers Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 032/102] uwb: init beacon cache entry before registering uwb device Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 052/102] be careful with nd->inode in path_init() and follow_dotdot_rcu() Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 058/102] USB: storage: Add quirk for Ariston Technologies iConnect USB to SCSI adapter Ben Hutchings
2014-11-01 22:28 ` Ben Hutchings [this message]
2014-11-01 22:28 ` [PATCH 3.2 031/102] USB: ftdi_sio: Add support for GE Healthcare Nemo Tracker device Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 060/102] nl80211: clear skb cb before passing to netlink Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 047/102] alarmtimer: Return relative times in timer_gettime Ben Hutchings
2014-11-01 22:28 ` [PATCH 3.2 036/102] libceph: gracefully handle large reply messages from the mon Ben Hutchings
2014-11-01 23:12 ` [PATCH 3.2 000/102] 3.2.64-rc1 review Ben Hutchings
2014-11-01 23:46 ` Ben Hutchings
2014-11-01 23:29 ` Guenter Roeck
2014-11-01 23:43 ` Ben Hutchings
2014-11-03 10:32 ` Guillaume Nault
2014-11-03 13:54 ` Ben Hutchings
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=lsq.1414880883.43488917@decadent.org.uk \
--to=ben@decadent.org.uk \
--cc=akpm@linux-foundation.org \
--cc=gleb@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=pbonzini@redhat.com \
--cc=pmatouse@redhat.com \
--cc=stable@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/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