From patchwork Sat Jul 30 09:02:29 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takuya Yoshikawa X-Patchwork-Id: 1022302 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p6U92atu016958 for ; Sat, 30 Jul 2011 09:02:36 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751297Ab1G3JCe (ORCPT ); Sat, 30 Jul 2011 05:02:34 -0400 Received: from mail-pz0-f42.google.com ([209.85.210.42]:38107 "EHLO mail-pz0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750816Ab1G3JCd (ORCPT ); Sat, 30 Jul 2011 05:02:33 -0400 Received: by pzk37 with SMTP id 37so7770243pzk.1 for ; Sat, 30 Jul 2011 02:02:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:in-reply-to:references:x-mailer :mime-version:content-type:content-transfer-encoding; bh=1lT09MfQ3CJn09u0fI8fIhF5a6S/YuqPJrJnnks0L+Y=; b=lMhChzSewk2obkKehRFXJNy4Uk5oCC7xSmXfSrLoaKtYFWRXcsvEB76zlOK6KU3zU9 /jdak+tHy9EM+0XaiZCTdPW6c7xpIQCgC5tQYZfriVRnjbPnwV9kFCOGyE0btbaeoQwE 3aniZAAxjFcp9fEVpdDSkfn4wzUSh1OCpVF+4= Received: by 10.68.29.200 with SMTP id m8mr4043561pbh.278.1312016553391; Sat, 30 Jul 2011 02:02:33 -0700 (PDT) Received: from amd (x096101.dynamic.ppp.asahi-net.or.jp [122.249.96.101]) by mx.google.com with ESMTPS id u6sm3033420pbh.80.2011.07.30.02.02.31 (version=SSLv3 cipher=OTHER); Sat, 30 Jul 2011 02:02:32 -0700 (PDT) Date: Sat, 30 Jul 2011 18:02:29 +0900 From: Takuya Yoshikawa To: avi@redhat.com, mtosatti@redhat.com Cc: kvm@vger.kernel.org, yoshikawa.takuya@oss.ntt.co.jp Subject: [PATCH 3/4] KVM: x86 emulator: Let compiler know insn_fetch() rarely fails Message-Id: <20110730180229.68752719.takuya.yoshikawa@gmail.com> In-Reply-To: <20110730175836.a119d816.takuya.yoshikawa@gmail.com> References: <20110730175836.a119d816.takuya.yoshikawa@gmail.com> X-Mailer: Sylpheed 3.1.0 (GTK+ 2.24.4; x86_64-pc-linux-gnu) Mime-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Sat, 30 Jul 2011 09:02:36 +0000 (UTC) From: Takuya Yoshikawa Fetching the instruction which was to be executed by the guest cannot fail normally. So compiler should always predict that it will succeed. Signed-off-by: Takuya Yoshikawa --- arch/x86/kvm/emulate.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 54f26d9..ae8d23c 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -672,11 +672,11 @@ static int do_insn_fetch_byte(struct x86_emulate_ctxt *ctxt, u8 *dest) size = min(15UL - cur_size, PAGE_SIZE - offset_in_page(ctxt->_eip)); rc = __linearize(ctxt, addr, size, false, true, &linear); - if (rc != X86EMUL_CONTINUE) + if (unlikely(rc != X86EMUL_CONTINUE)) return rc; rc = ctxt->ops->fetch(ctxt, linear, fc->data + cur_size, size, &ctxt->exception); - if (rc != X86EMUL_CONTINUE) + if (unlikely(rc != X86EMUL_CONTINUE)) return rc; fc->end += size; } @@ -691,7 +691,7 @@ static int do_insn_fetch(struct x86_emulate_ctxt *ctxt, int rc; /* x86 instructions are limited to 15 bytes. */ - if (ctxt->_eip + size - ctxt->eip > 15) + if (unlikely(ctxt->_eip + size - ctxt->eip > 15)) return X86EMUL_UNHANDLEABLE; while (size--) { rc = do_insn_fetch_byte(ctxt, dest++);