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, Wanpeng Li <wanpeng.li@hotmail.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: [PATCH 4.4 002/113] KVM: x86: emulate RDPID
Date: Thu, 27 Feb 2020 14:35:18 +0100	[thread overview]
Message-ID: <20200227132212.222051066@linuxfoundation.org> (raw)
In-Reply-To: <20200227132211.791484803@linuxfoundation.org>

From: Paolo Bonzini <pbonzini@redhat.com>

commit fb6d4d340e0532032c808a9933eaaa7b8de435ab upstream.

This is encoded as F3 0F C7 /7 with a register argument.  The register
argument is the second array in the group9 GroupDual, while F3 is the
fourth element of a Prefix.

Reviewed-by: Wanpeng Li <wanpeng.li@hotmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 arch/x86/kvm/cpuid.c   |    7 ++++++-
 arch/x86/kvm/emulate.c |   22 +++++++++++++++++++++-
 arch/x86/kvm/vmx.c     |   15 +++++++++++++++
 3 files changed, 42 insertions(+), 2 deletions(-)

--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -267,13 +267,18 @@ static int __do_cpuid_ent_emulated(struc
 {
 	switch (func) {
 	case 0:
-		entry->eax = 1;		/* only one leaf currently */
+		entry->eax = 7;
 		++*nent;
 		break;
 	case 1:
 		entry->ecx = F(MOVBE);
 		++*nent;
 		break;
+	case 7:
+		entry->flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX;
+		if (index == 0)
+			entry->ecx = F(RDPID);
+		++*nent;
 	default:
 		break;
 	}
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -3519,6 +3519,16 @@ static int em_cwd(struct x86_emulate_ctx
 	return X86EMUL_CONTINUE;
 }
 
+static int em_rdpid(struct x86_emulate_ctxt *ctxt)
+{
+	u64 tsc_aux = 0;
+
+	if (ctxt->ops->get_msr(ctxt, MSR_TSC_AUX, &tsc_aux))
+		return emulate_gp(ctxt, 0);
+	ctxt->dst.val = tsc_aux;
+	return X86EMUL_CONTINUE;
+}
+
 static int em_rdtsc(struct x86_emulate_ctxt *ctxt)
 {
 	u64 tsc = 0;
@@ -4379,10 +4389,20 @@ static const struct opcode group8[] = {
 	F(DstMem | SrcImmByte | Lock | PageTable,	em_btc),
 };
 
+/*
+ * The "memory" destination is actually always a register, since we come
+ * from the register case of group9.
+ */
+static const struct gprefix pfx_0f_c7_7 = {
+	N, N, N, II(DstMem | ModRM | Op3264 | EmulateOnUD, em_rdpid, rdtscp),
+};
+
+
 static const struct group_dual group9 = { {
 	N, I(DstMem64 | Lock | PageTable, em_cmpxchg8b), N, N, N, N, N, N,
 }, {
-	N, N, N, N, N, N, N, N,
+	N, N, N, N, N, N, N,
+	GP(0, &pfx_0f_c7_7),
 } };
 
 static const struct opcode group11[] = {
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -10744,6 +10744,21 @@ static int vmx_check_intercept(struct kv
 			       struct x86_instruction_info *info,
 			       enum x86_intercept_stage stage)
 {
+	struct vmcs12 *vmcs12 = get_vmcs12(vcpu);
+	struct x86_emulate_ctxt *ctxt = &vcpu->arch.emulate_ctxt;
+
+	/*
+	 * RDPID causes #UD if disabled through secondary execution controls.
+	 * Because it is marked as EmulateOnUD, we need to intercept it here.
+	 */
+	if (info->intercept == x86_intercept_rdtscp &&
+	    !nested_cpu_has2(vmcs12, SECONDARY_EXEC_RDTSCP)) {
+		ctxt->exception.vector = UD_VECTOR;
+		ctxt->exception.error_code_valid = false;
+		return X86EMUL_PROPAGATE_FAULT;
+	}
+
+	/* TODO: check more intercepts... */
 	return X86EMUL_CONTINUE;
 }
 



  parent reply	other threads:[~2020-02-27 13:40 UTC|newest]

Thread overview: 120+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-27 13:35 [PATCH 4.4 000/113] 4.4.215-stable review Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 001/113] x86/vdso: Use RDPID in preference to LSL when available Greg Kroah-Hartman
2020-02-27 13:35 ` Greg Kroah-Hartman [this message]
2020-02-27 13:35 ` [PATCH 4.4 003/113] ALSA: hda: Use scnprintf() for printing texts for sysfs/procfs Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 004/113] ecryptfs: fix a memory leak bug in parse_tag_1_packet() Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 005/113] ecryptfs: fix a memory leak bug in ecryptfs_init_messaging() Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 006/113] ALSA: usb-audio: Apply sample rate quirk for Audioengine D1 Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 007/113] ubifs: Fix deadlock in concurrent bulk-read and writepage Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 008/113] ext4: fix checksum errors with indexed dirs Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 009/113] Btrfs: fix race between using extent maps and merging them Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 010/113] btrfs: log message when rw remount is attempted with unclean tree-log Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 011/113] padata: Remove broken queue flushing Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 012/113] s390/time: Fix clk type in get_tod_clock Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 013/113] hwmon: (pmbus/ltc2978) Fix PMBus polling of MFR_COMMON definitions Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 014/113] jbd2: move the clearing of b_modified flag to the journal_unmap_buffer() Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 015/113] jbd2: do not clear the BH_Mapped flag when forgetting a metadata buffer Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 016/113] btrfs: print message when tree-log replay starts Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 017/113] scsi: qla2xxx: fix a potential NULL pointer dereference Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 018/113] Revert "KVM: VMX: Add non-canonical check on writes to RTIT address MSRs" Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 019/113] drm/gma500: Fixup fbdev stolen size usage evaluation Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 020/113] brcmfmac: Fix use after free in brcmf_sdio_readframes() Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 021/113] gianfar: Fix TX timestamping with a stacked DSA driver Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 022/113] pinctrl: sh-pfc: sh7264: Fix CAN function GPIOs Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 023/113] media: i2c: mt9v032: fix enum mbus codes and frame sizes Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 024/113] media: sti: bdisp: fix a possible sleep-in-atomic-context bug in bdisp_device_run() Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 025/113] efi/x86: Map the entire EFI vendor string before copying it Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 026/113] MIPS: Loongson: Fix potential NULL dereference in loongson3_platform_init() Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 027/113] uio: fix a sleep-in-atomic-context bug in uio_dmem_genirq_irqcontrol() Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 028/113] usb: gadget: udc: fix possible sleep-in-atomic-context bugs in gr_probe() Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 029/113] nfs: NFS_SWAP should depend on SWAP Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 030/113] jbd2: clear JBD2_ABORT flag before journal_reset to update log tail info when load journal Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 031/113] tracing: Fix very unlikely race of registering two stat tracers Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 032/113] ext4, jbd2: ensure panic when aborting with zero errno Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 033/113] kconfig: fix broken dependency in randconfig-generated .config Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 034/113] clk: qcom: rcg2: Dont crash if our parent cant be found; return an error Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 035/113] drm/amdgpu: remove 4 set but not used variable in amdgpu_atombios_get_connector_info_from_object_table Greg Kroah-Hartman
2020-03-11  9:07   ` nobuhiro1.iwamatsu
2020-03-16 10:53     ` Greg KH
2020-02-27 13:35 ` [PATCH 4.4 036/113] regulator: rk808: Lower log level on optional GPIOs being not available Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 037/113] NFC: port100: Convert cpu_to_le16(le16_to_cpu(E1) + E2) to use le16_add_cpu() Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 038/113] reiserfs: Fix spurious unlock in reiserfs_fill_super() error handling Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 039/113] ALSA: usx2y: Adjust indentation in snd_usX2Y_hwdep_dsp_status Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 040/113] b43legacy: Fix -Wcast-function-type Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 041/113] ipw2x00: " Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 042/113] iwlegacy: " Greg Kroah-Hartman
2020-02-27 13:35 ` [PATCH 4.4 043/113] rtlwifi: rtl_pci: " Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 044/113] orinoco: avoid assertion in case of NULL pointer Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 045/113] ACPICA: Disassembler: create buffer fields in ACPI_PARSE_LOAD_PASS1 Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 046/113] scsi: aic7xxx: Adjust indentation in ahc_find_syncrate Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 047/113] ARM: dts: r8a7779: Add device node for ARM global timer Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 048/113] x86/vdso: Provide missing include file Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 049/113] pinctrl: sh-pfc: sh7269: Fix CAN function GPIOs Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 050/113] ALSA: sh: Fix compile warning wrt const Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 051/113] tools lib api fs: Fix gcc9 stringop-truncation compilation error Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 052/113] usbip: Fix unsafe unaligned pointer usage Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 053/113] soc/tegra: fuse: Correct straps address for older Tegra124 device trees Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 054/113] rcu: Use WRITE_ONCE() for assignments to ->pprev for hlist_nulls Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 055/113] Input: edt-ft5x06 - work around first register access error Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 056/113] wan: ixp4xx_hss: fix compile-testing on 64-bit Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 057/113] ASoC: atmel: fix build error with CONFIG_SND_ATMEL_SOC_DMA=m Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 058/113] PCI: Dont disable bridge BARs when assigning bus resources Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 059/113] driver core: Print device when resources present in really_probe() Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 060/113] drm/nouveau: Fix copy-paste error in nouveau_fence_wait_uevent_handler Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 061/113] drm/vmwgfx: prevent memory leak in vmw_cmdbuf_res_add Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 062/113] iommu/arm-smmu-v3: Use WRITE_ONCE() when changing validity of an STE Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 063/113] scsi: iscsi: Dont destroy session if there are outstanding connections Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 064/113] cmd64x: potential buffer overflow in cmd64x_program_timings() Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 065/113] ide: serverworks: potential overflow in svwks_set_pio_mode() Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 066/113] remoteproc: Initialize rproc_class before use Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 067/113] s390/ftrace: generate traced function stack frame Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 068/113] ALSA: hda - Add docking station support for Lenovo Thinkpad T420s Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 069/113] jbd2: switch to use jbd2_journal_abort() when failed to submit the commit record Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 070/113] ARM: 8951/1: Fix Kexec compilation issue Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 071/113] hostap: Adjust indentation in prism2_hostapd_add_sta Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 072/113] iwlegacy: ensure loop counter addr does not wrap and cause an infinite loop Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 073/113] drm/nouveau/disp/nv50-: prevent oops when no channel method map provided Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 074/113] trigger_next should increase position index Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 075/113] radeon: insert 10ms sleep in dce5_crtc_load_lut Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 076/113] ocfs2: fix a NULL pointer dereference when call ocfs2_update_inode_fsync_trans() Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 077/113] lib/scatterlist.c: adjust indentation in __sg_alloc_table Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 078/113] reiserfs: prevent NULL pointer dereference in reiserfs_insert_item() Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 079/113] bcache: explicity type cast in bset_bkey_last() Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 080/113] irqchip/gic-v3-its: Reference to its_invall_cmd descriptor when building INVALL Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 081/113] microblaze: Prevent the overflow of the start Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 082/113] brd: check and limit max_part par Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 083/113] selinux: ensure we cleanup the internal AVC counters on error in avc_update() Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 084/113] enic: prevent waking up stopped tx queues over watchdog reset Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 085/113] floppy: check FDC index for errors before assigning it Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 086/113] staging: android: ashmem: Disallow ashmem memory from being remapped Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 087/113] staging: vt6656: fix sign of rx_dbm to bb_pre_ed_rssi Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 088/113] usb: uas: fix a plug & unplug racing Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 089/113] USB: Fix novation SourceControl XL after suspend Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 090/113] USB: hub: Dont record a connect-change event during reset-resume Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 091/113] staging: rtl8188eu: Fix potential security hole Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 092/113] staging: rtl8188eu: Fix potential overuse of kernel memory Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 093/113] x86/mce/amd: Fix kobject lifetime Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 094/113] tty: serial: imx: setup the correct sg entry for tx dma Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 095/113] Revert "ipc,sem: remove uneeded sem_undo_list lock usage in exit_sem()" Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 096/113] xhci: apply XHCI_PME_STUCK_QUIRK to Intel Comet Lake platforms Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 097/113] VT_RESIZEX: get rid of field-by-field copyin Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 098/113] vt: vt_ioctl: fix race in VT_RESIZEX Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 099/113] KVM: nVMX: Dont emulate instructions in guest mode Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 100/113] netfilter: xt_bpf: add overflow checks Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 101/113] ext4: fix a data race in EXT4_I(inode)->i_disksize Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 102/113] ext4: add cond_resched() to __ext4_find_entry() Greg Kroah-Hartman
2020-02-27 13:36 ` [PATCH 4.4 103/113] KVM: nVMX: Refactor IO bitmap checks into helper function Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.4 104/113] KVM: nVMX: Check IO instruction VM-exit conditions Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.4 105/113] KVM: apic: avoid calculating pending eoi from an uninitialized val Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.4 106/113] Btrfs: fix btrfs_wait_ordered_range() so that it waits for all ordered extents Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.4 107/113] scsi: Revert "RDMA/isert: Fix a recently introduced regression related to logout" Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.4 108/113] scsi: Revert "target: iscsi: Wait for all commands to finish before freeing a session" Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.4 109/113] ecryptfs: replace BUG_ON with error handling code Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.4 110/113] ALSA: rawmidi: Avoid bit fields for state flags Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.4 111/113] ALSA: seq: Avoid concurrent access to queue flags Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.4 112/113] ALSA: seq: Fix concurrent access to queue current tick/time Greg Kroah-Hartman
2020-02-27 13:37 ` [PATCH 4.4 113/113] xen: Enable interrupts when calling _cond_resched() Greg Kroah-Hartman
2020-02-27 15:52 ` [PATCH 4.4 000/113] 4.4.215-stable review Chris Paterson
2020-02-27 18:50 ` Jon Hunter
2020-02-27 19:37 ` Guenter Roeck
2020-02-28 11:11 ` Naresh Kamboju

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=20200227132212.222051066@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=wanpeng.li@hotmail.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).