Received: by 10.213.65.68 with SMTP id h4csp295827imn; Mon, 26 Mar 2018 22:10:52 -0700 (PDT) X-Google-Smtp-Source: AG47ELv8VUOdCgMbYUekoTPSs/ruStE1FHXhawQ08XfNnE21v0R8NO+4tBZ+najHX81SXXpXTKRS X-Received: by 10.99.116.22 with SMTP id p22mr15953579pgc.265.1522127452297; Mon, 26 Mar 2018 22:10:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522127452; cv=none; d=google.com; s=arc-20160816; b=izo8PwAZaGqMw/+e/MOjxv7YyXCLwSOgGl0MR6Fcd0XT6ZyWNm5aW430RonOMp3maA sGQrg7y3CRZOHwv4R3jmFY0Hd4WYz4cbKZkZttAD7OBirdwM7MJQOjwcrz1PmUyg6tdJ rvCn9Db8h3OzuEzO+TwreTLiA5wkyVT/ljNlSVxEPFnPR99a2XPOCrkGbkj6+eDF0QCE PPHHZ/Xekno9Qgbwjr5kiH7vEHB438cJKNZpcaY2Z73OvlH/wE7mJIgBmDLNau2Ab1qk 706df9FzoSHdPNEEHtWydzgNYmwGKbUO47/EfkoCuuVg6kO2adfXUW7WStQ3gvQBK923 pNuw== 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:cc:to:subject :message-id:date:from:references:in-reply-to:mime-version :dkim-signature:arc-authentication-results; bh=MoKEcR5iCrX93GxPRU9MVyfMpH9/sh6210zIpZ8nhUo=; b=mOjZa7OFeyw+8VHVjjVLU4ZO/0uNRydzYACCOG+cGB4+p9l2CzjIdOsUS0MCnjZyYd AA7E+0Mxr7+go+B3FCB73EUVyijWdJsxsMHLFCJaiPrg2j/XI4zpKh89FaU0/OcSeHjT HSUcARjglEzEJlt7H8H9NXtohqFlqx7/oJTcMcNl/bPgNfS56udnj4aDFy3MfYCBtD6a WzeG6pSsWT1qRJPAMC14vonQ925oWj4ek3SBAcP1F6RHpI+wbX6Xf5AwAfmGH840WWxv safitYMERLV1E+A3rrzJb8EqDJJbqoo4JpmsFwIqgUV2gZQ2o4EjUc4ZzdGkHPPm+1b2 aUPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=XRP44peL; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f91-v6si499138plb.178.2018.03.26.22.10.37; Mon, 26 Mar 2018 22:10:52 -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=@gmail.com header.s=20161025 header.b=XRP44peL; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751070AbeC0FJn (ORCPT + 99 others); Tue, 27 Mar 2018 01:09:43 -0400 Received: from mail-ot0-f195.google.com ([74.125.82.195]:37584 "EHLO mail-ot0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750836AbeC0FJl (ORCPT ); Tue, 27 Mar 2018 01:09:41 -0400 Received: by mail-ot0-f195.google.com with SMTP id y46-v6so3484552otd.4; Mon, 26 Mar 2018 22:09:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=MoKEcR5iCrX93GxPRU9MVyfMpH9/sh6210zIpZ8nhUo=; b=XRP44peLqYgg85CICAbh2JVRY9xKwTBZkNiVlmoPnzhK5RYOmGaC0Bb0ZliSWxTciZ 9LdAuSyS8ReIvB80fxI1OvrQhzuADh3DGzMbI170oMs7Wf9orIJ64S7RwSSyS73SkAWD 4JQh7BL7CnD32D5hp545LzxCUrIwO4JMnx7Uq/ynae+oa/Ra+gLy3PXzWHGBXQX1rVlo 2Mv/IhzXy3MXqEsGRKGNjMe0RKd7T91PujgqflhadLH1g4NUkiuNphCSb5Y1+wBLBQoa l/vE6Tmup17rKWY8JWWhZtss9pS6/OEYpwdXzuHzeYJvk6hNCOX9NMzu/FFCVDu7FsrC Hs/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=MoKEcR5iCrX93GxPRU9MVyfMpH9/sh6210zIpZ8nhUo=; b=s5qMaeUfa6l8jJxEnuG8avQOIMKJp8Ak0ykdBa0AVsqfCVV+4iPEktaNt2oxldC7Rq G8oC6NkbTRJQQoXm9sa6wR6V/u9dRhXR96pHwkMcnKQRUFVMjO/S69HHEXj/bYPMFLqt 2BRHRgB8Zyq8rDt3l+MyCUzLrXUM8Yo/a0hzGX9PdhkYn1kD+ye+hA+l5x3iSrBMoDRW Bq8TS/AjfVdYVoLtWCpPK70Q8LSQnqbtsiG6bbGzM8YYg2dxNzpR80QGGXDtE/7Z5s4i TlIHO3fjsJGHHmQBfvW7ONZFdlBkwb72exEdcRJtWkTp24L3OCGlzE06lnFneR7egrdZ hUqg== X-Gm-Message-State: AElRT7FwH9e5dtIZ2gzhaKClU2cMmTAhlHyvquzQVf6Q17BUKgEQwEp3 rxCbL4uhs7GZnhfYdOF3PKo/RSlyYPuK7kXDDmg= X-Received: by 2002:a9d:9a:: with SMTP id w26-v6mr22666013oti.250.1522127381128; Mon, 26 Mar 2018 22:09:41 -0700 (PDT) MIME-Version: 1.0 Received: by 10.74.165.65 with HTTP; Mon, 26 Mar 2018 22:09:40 -0700 (PDT) In-Reply-To: <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> <20180327044020.GB16974@char.us.oracle.com> From: Wanpeng Li Date: Tue, 27 Mar 2018 13:09:40 +0800 Message-ID: Subject: Re: [PATCH 2/2] KVM: VMX: Add Force Emulation Prefix for "emulate the next instruction" To: Konrad Rzeszutek Wilk Cc: LKML , kvm , Paolo Bonzini , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Andrew Cooper Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2018-03-27 12:40 GMT+08:00 Konrad Rzeszutek Wilk : > On Mon, Mar 26, 2018 at 07:12:15PM -0700, Wanpeng Li wrote: >> From: Wanpeng Li >> >> This patch introduces a Force Emulation Prefix (ud2a; .ascii "kvm") for >> "emulate the next instruction", the codes will be executed by emulator >> 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? >> >> A testcase here: >> >> #include >> #include >> >> #define HYPERVISOR_INFO 0x40000000 >> >> #define CPUID(idx, eax, ebx, ecx, edx)\ >> asm volatile (\ >> "ud2a; .ascii \"kvm\"; 1: cpuid" \ >> :"=3Db" (*ebx), "=3Da" (*eax),"=3Dc" (*ecx), "=3Dd" (*edx)\ >> :"0"(idx) ); >> >> void main() >> { >> unsigned int eax,ebx,ecx,edx; >> char string[13]; >> >> CPUID(HYPERVISOR_INFO, &eax, &ebx, &ecx, &edx); >> *(unsigned int *)(string+0) =3D ebx; >> *(unsigned int *)(string+4) =3D ecx; >> *(unsigned int *)(string+8) =3D edx; >> >> string[12] =3D 0; >> if (strncmp(string, "KVMKVMKVM\0\0\0",12) =3D=3D 0) >> printf("kvm guest\n"); >> else >> printf("bare hardware\n"); >> } >> >> 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(-) >> >> 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_shadow= _vmcs, bool, S_IRUGO); >> static bool __read_mostly nested =3D 0; >> module_param(nested, bool, S_IRUGO); >> >> +static bool __read_mostly fep =3D 0; >> +module_param(fep, bool, S_IRUGO); >> + >> static u64 __read_mostly host_xss; >> >> 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? sig buffer will be filled by insns which are fetched from guest memory, so I think not memset is fine. Regards, Wanpeng Li