Received: by 10.223.164.221 with SMTP id h29csp2778083wrb; Thu, 2 Nov 2017 17:55:49 -0700 (PDT) X-Google-Smtp-Source: ABhQp+TmqW7aA9bDhBEYV62jHdv++tEc31ICVOdffK69I5WyZCZNy1uISgCQLFek+VVHaLfVRH3z X-Received: by 10.84.131.1 with SMTP id 1mr4985997pld.120.1509670549432; Thu, 02 Nov 2017 17:55:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509670549; cv=none; d=google.com; s=arc-20160816; b=HNC8sCf8/VnH9J0yd4p2XNGSsO+N67VrgK+UF2Z0bmfDhokqbolaa5ZKfzDIbS3grf g7+yfTm32SbsxWk5A6+1eY+E+9+HmmwB8StOJte1JDqLw1r5+VuMr7/xG4whf5Ld/u++ K3rIH6lzfvraN4O9u9Ovr4K0Ryj6Xb55NIb+oycZoeucP/H2WJQQpuYNo9u4JSo1+yNS rYBnCmyvsVn9tkTKncDmNJ/usONXTHuFKWVfVJeux8OQOE5qjS9C0TJGt0dxoGLqR1sL +XJio8bdJfzWylqcpjgTnJthWoPFqBVsiZgQXSP5TAU76vr2tEmxRk80dwiqB1n01RMw XxuA== 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=PHsZYymVmSlyXLSXLk7dtTiOHevBVaVUphDLahasq78=; b=VNfjg2stlZN0xz0muih0S1Nhn+7Wb/KYh2d4QNPCwnYk9koCJpSdSQWMzq//+JHwNy H14eOWNd85UCltm2dVpUgTQ7RrK24wODpm2Huc3IiKxjLDj69rn2Nbpw1jRoLbNUJ5xU lDk7NZ93gHBDow1BZGFz032L3BmuXJOOjK44S72irCMOho14+4GzPvPKCE+oixORqgML S4d4AmQZRu4jqgnYk/elJdZPuVWr/EExg2GUehLKVjy6ukoU4VKwBy2G5YgZLmRTxec5 7mvmQ69yZ184zGeTjjy0TpQ+b1G1Ja2+/SHgfZwgT7ILYmSJe+QwKXmwe4uwa7nqpnm/ 8yWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dOyW+obG; 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=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e2si4581967pgn.528.2017.11.02.17.55.36; Thu, 02 Nov 2017 17:55:49 -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=dOyW+obG; 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=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934717AbdKCAzC (ORCPT + 96 others); Thu, 2 Nov 2017 20:55:02 -0400 Received: from mail-oi0-f65.google.com ([209.85.218.65]:46878 "EHLO mail-oi0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932398AbdKCAzB (ORCPT ); Thu, 2 Nov 2017 20:55:01 -0400 Received: by mail-oi0-f65.google.com with SMTP id n82so1059940oig.3; Thu, 02 Nov 2017 17:55:01 -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=PHsZYymVmSlyXLSXLk7dtTiOHevBVaVUphDLahasq78=; b=dOyW+obG7xIiJYwpiExR7fZ6c7CJdymwDNlgqD1zIkupjpb1o3IWOfzOTUMvBJQedi vdwgROQ65XkXHR3Q1yre0Md6iZFdHTu/RpVoe68fEXorZhNFPDqmbFSwUk+q03CkvIKV Fpv4wmYQCdCJJNbfokbdTT6Bzcjx+CZPNBG6bPVntskklu7aXU6QDUlW98oDUb0vHWqa yNdBYwenBh6FRYBLcasKPrJiBoCzXb6+O3lnp/MIMclvslW+WSSckq9McYJj1bMN78l+ 7q4yfHgm/UvRmN5vuscEVvLjP1C58p9lbUgS37TO5BA2aSByC4Zig6lZA7Ctjn4zDm+2 Y+mQ== 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=PHsZYymVmSlyXLSXLk7dtTiOHevBVaVUphDLahasq78=; b=Ud0AxootHndDJejuaUVyTv+RE5Ecub09iRufKyUHJIwAcrv7T2Syl3rA9mJoxb1XDd VeRdbx6j56rOaR19XP0v+HZ86LzYeYvfXDo5TtEHYQ2TmADasz+i4LQpTiEsB/TGxTHg 0j3xEXTKFS/FyKLO91rqwPJ5kPrWDpYhbHV+41iD3Wl978Nk/uWLrTA4xGN9+P/kcU8p gp3NU0JEK5TPqHrduLSkvhD2LvwHL7c3cLyBYM7kTy/c0utxC6hpidQPQDNCybljhraF lOGYV1/dJPsSWupF4lcvdWTTWzoYr5EtO0xRb8Eqoe5ZsZCa/EGJs8nafT10uxpOhkyK QDIQ== X-Gm-Message-State: AMCzsaU2B2Ry2Ibbiz5m3uocpsec6uVkmbKUqDlNiZ7ZNN1nkgNpbw4t 8pGNOsw+IRTrWhNKRyTXIo+36NbL0tmdQzms0FA= X-Received: by 10.202.220.3 with SMTP id t3mr3306105oig.237.1509670500820; Thu, 02 Nov 2017 17:55:00 -0700 (PDT) MIME-Version: 1.0 Received: by 10.74.53.27 with HTTP; Thu, 2 Nov 2017 17:55:00 -0700 (PDT) In-Reply-To: References: <1509611499-9401-1-git-send-email-wanpeng.li@hotmail.com> From: Wanpeng Li Date: Fri, 3 Nov 2017 08:55:00 +0800 Message-ID: Subject: Re: [PATCH v3 1/3] KVM: X86: Fix operand size during instruction decoding To: Paolo Bonzini Cc: "linux-kernel@vger.kernel.org" , kvm , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Wanpeng Li , Nadav Amit , Pedro Fonseca 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 2017-11-03 1:45 GMT+08:00 Paolo Bonzini : > On 02/11/2017 09:31, Wanpeng Li wrote: >> From: Wanpeng Li >> >> Pedro reported: >> During tests that we conducted on KVM, we noticed that executing a "PU= SH %ES" >> instruction under KVM produces different results on both memory and th= e SP >> register depending on whether EPT support is enabled. With EPT the SP = is >> reduced by 4 bytes (and the written value is 0-padded) but without EPT= support >> it is only reduced by 2 bytes. The difference can be observed when the= CS.DB >> field is 1 (32-bit) but not when it's 0 (16-bit). >> >> The internal segment descriptor cache exist even in real/vm8096 mode. Th= e CS.D >> also should be respected instead of just default operand-size/66H prefix= during >> instruction decoding. This patch fixes it by also adjusting operand-size= according >> to CS.D. >> >> Reported-by: Pedro Fonseca >> Tested-by: Pedro Fonseca >> Cc: Paolo Bonzini >> Cc: Radim Kr=C4=8Dm=C3=A1=C5=99 >> Cc: Nadav Amit >> Cc: Pedro Fonseca >> Signed-off-by: Wanpeng Li >> --- >> v2 -> v3: >> * cleanup the codes >> v1 -> v2: >> * respect cs.d for real/vm8096, other modes have already >> been considered in init_emulate_ctxt(). >> >> arch/x86/kvm/emulate.c | 7 +++++++ >> 1 file changed, 7 insertions(+) >> >> diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c >> index 8079d14..6ebc4cb 100644 >> --- a/arch/x86/kvm/emulate.c >> +++ b/arch/x86/kvm/emulate.c >> @@ -5000,6 +5000,8 @@ int x86_decode_insn(struct x86_emulate_ctxt *ctxt,= void *insn, int insn_len) >> bool op_prefix =3D false; >> bool has_seg_override =3D false; >> struct opcode opcode; >> + u16 dummy; >> + struct desc_struct desc; >> >> ctxt->memop.type =3D OP_NONE; >> ctxt->memopp =3D NULL; >> @@ -5020,6 +5022,11 @@ int x86_decode_insn(struct x86_emulate_ctxt *ctxt= , void *insn, int insn_len) >> case X86EMUL_MODE_VM86: >> case X86EMUL_MODE_PROT16: >> def_op_bytes =3D def_ad_bytes =3D 2; >> + if (mode < X86EMUL_MODE_PROT16) { >> + ctxt->ops->get_segment(ctxt, &dummy, &desc, NULL, = VCPU_SREG_CS); >> + if (desc.d) >> + def_op_bytes =3D 4; > > def_ad_bytes must be changed to 4 as well. With that change, you should > probably separate X86EMUL_MODE_PROT16 altogether from the others. I just handle all the comments of the three patches in v5. :) Regards, Wanpeng Li From 1582977408417329435@xxx Thu Nov 02 17:48:17 +0000 2017 X-GM-THRID: 1582942588268709733 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread