Received: by 10.213.65.68 with SMTP id h4csp279794imn; Mon, 26 Mar 2018 21:42:12 -0700 (PDT) X-Google-Smtp-Source: AG47ELtk01xYPqk+Ono7RNJJCFEG4yZ3uAwxX5T26D6sx85I2nG30CXGnumHvOrfvyuBHmbqd3KZ X-Received: by 10.98.102.79 with SMTP id a76mr15594501pfc.162.1522125732061; Mon, 26 Mar 2018 21:42:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522125732; cv=none; d=google.com; s=arc-20160816; b=qg5tFM0P3bopT3F1S06zQhr8u4WWnfA8yhk23NfBGUCmtHexOBl0uUao54R1OsWrXx tU1daw8kZUDsvKUk/zC6ckPrSUHUgFr5V6rrGmVqzTUD9Jzls2/nxQj+lAh02/72BPcg 58nBxNmvkMA9O3ZZLo5WcODn/Bu585xqnEqPlu9OWLI+HKAGTKMKqFJwlKIPCcLkPDqq oWiDjQsgm8WsPZlgjMLecDp9IX8okV/9qrAd56BEkAVZU0EQlwTui8FLiUFAoOFKKQv+ DmJhmn9mcXxVNumgnCFNQLxP1Jt9mV9+IRKTi1tH8RFiQeitPxjqOIaHG5qQ1jNTul3+ FuQA== 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:user-agent :in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:dkim-signature:arc-authentication-results; bh=Kb66kram9OKRt7blJ1tGM9pgWHaHNNkdSRauAAWUMyM=; b=JQRllRMR0Zhrc69D7N7Sb7tda5g999whsiUjIkJ9jILywOxO2FKD1jONX7qfB9vfo5 oFPoypgiD6NHa2NBz3TFhDB52hMe+ljl2QXTtJJ8u88NH5Aig00UMgs3x6+rOQUQSrrT 7Brzfbn8ls2q9VB/pWRRux35PuAAJ4+KXpB12JQr+vI538XVhtGNhhrw3llt+tRrozSU XuhgwuZirQ0ZnvNaSu3/sywQ4pfHFJ/jBQksiinhvJv9xE5RcBRv8tgyb3wAd67HFKpx FnoRzMM5uaX47ieOd9HJxDHDo7hSelfo8ugHPuc0FQYgcUy3b1S6z58WemWsQ0W1qy9m 2mfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=aAeFgzFz; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c1-v6si418773plk.611.2018.03.26.21.41.58; Mon, 26 Mar 2018 21:42:12 -0700 (PDT) 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=@oracle.com header.s=corp-2017-10-26 header.b=aAeFgzFz; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751765AbeC0Ekh (ORCPT + 99 others); Tue, 27 Mar 2018 00:40:37 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:58936 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751202AbeC0Ekg (ORCPT ); Tue, 27 Mar 2018 00:40:36 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w2R4eNLC176788; Tue, 27 Mar 2018 04:40:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to : content-transfer-encoding; s=corp-2017-10-26; bh=Kb66kram9OKRt7blJ1tGM9pgWHaHNNkdSRauAAWUMyM=; b=aAeFgzFzBTrbWTEmC38ZdjlKJq54y3ehxWQ4o47senx3K2M31R1c39V6Ny+Ue7GYVE66 tXSH5kB84o8kO/VXdbHOg3A8YsFSFuICuDOnDV809sYwTdX/n5epAVgpro5cXH7UhWZR nZEPeuXNgzTKnU/RwlxRIdbSIt7FhCJnqTBQXExNERYgE2o0J4WTCKZ/udZ8paDKygKq 5k4/uqsdLCUC5fgLVlfBIL0JwIQvCVwJJJoZc0gkJVd3X6DQOC/rZuTn3NppcY/YwErY sIE5x2ez3N4B+5efkmDwJSZ/3ROM39Q3F+qCK15pQtL1VQobfEpzwSRDkvxfRNZMbiOm Zg== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2120.oracle.com with ESMTP id 2gyf4ur006-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 27 Mar 2018 04:40:23 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w2R4eMNn008294 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 27 Mar 2018 04:40:22 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w2R4eMQr005582; Tue, 27 Mar 2018 04:40:22 GMT Received: from char.us.oracle.com (/10.137.176.158) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 26 Mar 2018 21:40:21 -0700 Received: by char.us.oracle.com (Postfix, from userid 1000) id C2A226A0095; Tue, 27 Mar 2018 00:40:20 -0400 (EDT) Date: Tue, 27 Mar 2018 00:40:20 -0400 From: Konrad Rzeszutek Wilk To: Wanpeng Li Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , Andrew Cooper Subject: Re: [PATCH 2/2] KVM: VMX: Add Force Emulation Prefix for "emulate the next instruction" Message-ID: <20180327044020.GB16974@char.us.oracle.com> References: <1522116735-4861-1-git-send-email-wanpengli@tencent.com> <1522116735-4861-3-git-send-email-wanpengli@tencent.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1522116735-4861-3-git-send-email-wanpengli@tencent.com> User-Agent: Mutt/1.8.3 (2017-05-23) Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8844 signatures=668695 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1803270044 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 26, 2018 at 07:12:15PM -0700, Wanpeng Li wrote: > From: Wanpeng Li >=20 > This patch introduces a Force Emulation Prefix (ud2a; .ascii "kvm") for= =20 > "emulate the next instruction", the codes will be executed by emulator=20 > instead of processor, for testing purposes. Can you expand a bit ? Why do you want this in KVM in the first place? Should this be controlled by a boolean parameter?=20 >=20 > A testcase here: >=20 > #include > #include > =20 > #define HYPERVISOR_INFO 0x40000000 > =20 > #define CPUID(idx, eax, ebx, ecx, edx)\ > asm volatile (\ > "ud2a; .ascii \"kvm\"; 1: cpuid" \ > :"=3Db" (*ebx), "=3Da" (*eax),"=3Dc" (*ecx), "=3Dd" (*edx)\ > :"0"(idx) ); =20 > =20 > void main() =20 > { =20 > unsigned int eax,ebx,ecx,edx; =20 > char string[13]; =20 > =20 > CPUID(HYPERVISOR_INFO, &eax, &ebx, &ecx, &edx); =20 > *(unsigned int *)(string+0) =3D ebx; =20 > *(unsigned int *)(string+4) =3D ecx; =20 > *(unsigned int *)(string+8) =3D edx; =20 > =20 > string[12] =3D 0; =20 > if (strncmp(string, "KVMKVMKVM\0\0\0",12) =3D=3D 0) > printf("kvm guest\n"); =20 > else =20 > printf("bare hardware\n"); =20 > } >=20 > Suggested-by: Andrew Cooper > Cc: Paolo Bonzini > Cc: Radim Kr=C4=8Dm=C3=A1=C5=99 > Cc: Andrew Cooper > Signed-off-by: Wanpeng Li > --- > arch/x86/kvm/vmx.c | 18 +++++++++++++++++- > 1 file changed, 17 insertions(+), 1 deletion(-) >=20 > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > index 0f99833..90abed8 100644 > --- a/arch/x86/kvm/vmx.c > +++ b/arch/x86/kvm/vmx.c > @@ -108,6 +108,9 @@ module_param_named(enable_shadow_vmcs, enable_shado= w_vmcs, bool, S_IRUGO); > static bool __read_mostly nested =3D 0; > module_param(nested, bool, S_IRUGO); > =20 > +static bool __read_mostly fep =3D 0; > +module_param(fep, bool, S_IRUGO); > + > static u64 __read_mostly host_xss; > =20 > static bool __read_mostly enable_pml =3D 1; > @@ -6218,8 +6221,21 @@ static int handle_machine_check(struct kvm_vcpu = *vcpu) > static int handle_ud(struct kvm_vcpu *vcpu) > { > enum emulation_result er; > + int emulation_type =3D EMULTYPE_TRAP_UD; > + > + if (fep) { > + char sig[5]; /* ud2; .ascii "kvm" */ > + struct x86_exception e; Don't you want to do =3D { }; to memset it? > + > + kvm_read_guest_virt(&vcpu->arch.emulate_ctxt, > + kvm_get_linear_rip(vcpu), sig, sizeof(sig), &e); > + if (memcmp(sig, "\xf\xbkvm", sizeof(sig)) =3D=3D 0) { > + emulation_type =3D 0; > + kvm_rip_write(vcpu, kvm_rip_read(vcpu) + sizeof(sig)); > + } > + } > =20 > - er =3D emulate_instruction(vcpu, EMULTYPE_TRAP_UD); > + er =3D emulate_instruction(vcpu, emulation_type); > if (er =3D=3D EMULATE_USER_EXIT) > return 0; > if (er !=3D EMULATE_DONE) > --=20 > 2.7.4 >=20