From patchwork Tue Apr 28 10:06:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nadav Amit X-Patchwork-Id: 6287541 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B99ABBEEE5 for ; Tue, 28 Apr 2015 10:06:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DEF1F202DD for ; Tue, 28 Apr 2015 10:06:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8EDC120351 for ; Tue, 28 Apr 2015 10:06:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965373AbbD1KGT (ORCPT ); Tue, 28 Apr 2015 06:06:19 -0400 Received: from mailgw10.technion.ac.il ([132.68.225.10]:21783 "EHLO mailgw10.technion.ac.il" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965353AbbD1KGL (ORCPT ); Tue, 28 Apr 2015 06:06:11 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2BoAgAmWz9VjAEgRIRchDvHAAmHVgKBNjgUAQEBAQEBAREBAQEnT4QhAQEBAydSEFFXGYgrwViEbgEBCAIgkD0HFoQXBYtZkVeNGYcmgQOBJxyBVGyCRAEBAQ X-IPAS-Result: A2BoAgAmWz9VjAEgRIRchDvHAAmHVgKBNjgUAQEBAQEBAREBAQEnT4QhAQEBAydSEFFXGYgrwViEbgEBCAIgkD0HFoQXBYtZkVeNGYcmgQOBJxyBVGyCRAEBAQ X-IronPort-AV: E=Sophos;i="5.11,662,1422914400"; d="scan'208";a="20841366" Received: from csa.cs.technion.ac.il ([132.68.32.1]) by mailgw10.technion.ac.il with ESMTP; 28 Apr 2015 13:06:08 +0300 Received: from csn.cs.technion.ac.il (csn.cs.technion.ac.il [132.68.32.15]) by csa.cs.technion.ac.il (Postfix) with ESMTP id B8A3C14003E; Tue, 28 Apr 2015 13:06:05 +0300 (IDT) Received: from csl-tapuz20.cs.technion.ac.il (csl-tapuz20.cs.technion.ac.il [132.68.206.58]) by csn.cs.technion.ac.il (Postfix) with ESMTPSA id A000EA0412; Tue, 28 Apr 2015 13:06:05 +0300 (IDT) From: Nadav Amit To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, Nadav Amit Subject: [PATCH 1/2] KVM: x86: Fix update RCX/RDI/RSI on REP-string Date: Tue, 28 Apr 2015 13:06:00 +0300 Message-Id: <1430215561-6677-2-git-send-email-namit@cs.technion.ac.il> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1430215561-6677-1-git-send-email-namit@cs.technion.ac.il> References: <1430215561-6677-1-git-send-email-namit@cs.technion.ac.il> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When REP-string instruction is preceded with an address-size prefix, ECX/EDI/ESI are used as the operation counter and pointers. When they are updated, the high 32-bits of RCX/RDI/RSI are cleared, similarly to the way they are updated on every 32-bit register operation. Fix it. Signed-off-by: Nadav Amit --- arch/x86/kvm/emulate.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index c1bc650..296d58e 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -524,13 +524,9 @@ static void masked_increment(ulong *reg, ulong mask, int inc) static inline void register_address_increment(struct x86_emulate_ctxt *ctxt, int reg, int inc) { - ulong mask; + ulong *preg = reg_rmw(ctxt, reg); - if (ctxt->ad_bytes == sizeof(unsigned long)) - mask = ~0UL; - else - mask = ad_mask(ctxt); - masked_increment(reg_rmw(ctxt, reg), mask, inc); + assign_register(preg, *preg + inc, ctxt->ad_bytes); } static void rsp_increment(struct x86_emulate_ctxt *ctxt, int inc)