Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1135176ybf; Thu, 27 Feb 2020 05:42:01 -0800 (PST) X-Google-Smtp-Source: APXvYqzBGVNoZSSxn2oMF4CMgQ9q53vKrIrjRATflc7jIYsIMT0JtJc77sPZMotNOt5tQaKixLyx X-Received: by 2002:a9d:7613:: with SMTP id k19mr3503060otl.144.1582810921226; Thu, 27 Feb 2020 05:42:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582810921; cv=none; d=google.com; s=arc-20160816; b=n797WeRWknwuK9oIcuvwXWrbvqRs0IwQiiSjlG92ZZg07xTtlytO5/RLgUn8JJbPJG kqxvWRjvmbv1QylVTFp2gmGp6UYopI+GjBkgpCJvyMZYZ0e1U7Tr0OzHoHUHsiyJiDir dud4shY1RbUPLT8XyQ2haWKNZIgfgGq2HRNMZchmFCNAbwynhXUZLwtiOePzBGEmfYy2 UnYmSJqAo24DCd7kWaNHjLEykMjlC4tXa9KIjc/M8JaFINsQpCr/oGQD4g61UBwrkSh+ mMd8mxZNqfEnmFDo0/i3eAhUkek+7MKCMOqNhCB3D47Mo6PJI4iRPCXuvxV35Jq61FE7 48/A== 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=oybHmrmfpazJW6LFQTYaNcnCt+QJrU64TGFP77FU2i0=; b=qhmW/Pq9KVeugbicyrWe+XEmg+Lt/y2jsV0KXtrx2vDOLDmL4z8LSuniMrpR72TbbV IsTZBQpL2PU/5viB8XUCui9xBe2nOEL6gKXY4qDsmK5gncMN6+cTQrwwn+A1Z1o8NyTX t8m2PO0gCZKHgkhTPmDkQwCvV1NkZMN9rAmivU1uu/2Zdtu4FxXhAElIMLJ8HL522lcF jUI13cHdaKuzbnJEk8LW3BrvYyVcBIFl1m/SQSRz5eNOSfQR3wIT6TiJgI3rubEvFRaj D6zL575AsroY3Et2zWworxNYce9zXoC+QqwPcKBv+k+4doGHmMygxqZWHmyTBFf4vG6l OSfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=181jZlBB; 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 m25si1598224otn.208.2020.02.27.05.41.48; Thu, 27 Feb 2020 05:42:01 -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=181jZlBB; 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 S1729287AbgB0Nkb (ORCPT + 99 others); Thu, 27 Feb 2020 08:40:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:34742 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729237AbgB0Nk3 (ORCPT ); Thu, 27 Feb 2020 08:40:29 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 3A11324656; Thu, 27 Feb 2020 13:40:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582810826; bh=JMBDWlIt6p0SZLCg1I64eKlJbM43wmlLwo0qS8j1FlM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=181jZlBBPuqa+IFAHmPlFlX1c9Mxdyl8Zx8D6wk30fc9Dpl7WGa+D283CFvz6z+og s+C//fD4uz8JlXNbY0nDNuB5ZV0a7hYBitUU1JyOEKrtvAPPdbvn8tJHCHujWFad5O hehb/XHcwksXReqO0xmILpU3rXFhuyegzlqpAVUs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wanpeng Li , Paolo Bonzini Subject: [PATCH 4.4 002/113] KVM: x86: emulate RDPID Date: Thu, 27 Feb 2020 14:35:18 +0100 Message-Id: <20200227132212.222051066@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200227132211.791484803@linuxfoundation.org> References: <20200227132211.791484803@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 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 Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- 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; }