From patchwork Wed Aug 20 11:24:42 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 4749311 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.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 981A4C033A for ; Wed, 20 Aug 2014 11:27:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BD3AC20170 for ; Wed, 20 Aug 2014 11:27:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DE30920176 for ; Wed, 20 Aug 2014 11:27:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752762AbaHTLYt (ORCPT ); Wed, 20 Aug 2014 07:24:49 -0400 Received: from mail-we0-f179.google.com ([74.125.82.179]:42538 "EHLO mail-we0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752031AbaHTLYs (ORCPT ); Wed, 20 Aug 2014 07:24:48 -0400 Received: by mail-we0-f179.google.com with SMTP id u57so7628841wes.24 for ; Wed, 20 Aug 2014 04:24:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id; bh=QjPMZOD88OernDrvtyHxqB+ITCVwjQPFf+Zn2VQbXQE=; b=LHnId/se8ZZqs65zH/SafAhwEFCOiM8ZelUNcg3r4p1Foyc6VyDUrrZ5JxzHgGGOe3 i+Ju8wVoV10l7mFVPiVmsDg7bWE5baR13o123TaZ9E5UHtp8oNyOvRkcdoERrCnSsCkT Njn4veGkkSbfa5yQoekFjxK26ClZmxr5JuBRm4RXoYGF5McMzQCkeUp/o6TDzAY/Xg34 zN3hH0OUTrQ43xJ7BgAn4or6y9FLXBSVk6MZkQTiGGWsNRgZT8OC7uGAe772LAW6W1Wu rIdlBIpTvGKYkYC342o2md5tvllGMyzHZTYyee/ih+Bh1D2hj6QElgo2db3gl6RUIdRo cEww== X-Received: by 10.180.210.231 with SMTP id mx7mr14021506wic.42.1408533887066; Wed, 20 Aug 2014 04:24:47 -0700 (PDT) Received: from playground.station (net-37-117-135-145.cust.vodafonedsl.it. [37.117.135.145]) by mx.google.com with ESMTPSA id lq15sm8368040wic.1.2014.08.20.04.24.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Aug 2014 04:24:46 -0700 (PDT) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: bdas@redhat.com Subject: [PATCH] KVM: emulate: warn on invalid or uninitialized exception numbers Date: Wed, 20 Aug 2014 13:24:42 +0200 Message-Id: <1408533882-18304-1-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,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 These were reported when running Jailhouse on AMD processors. Initialize ctxt->exception.vector with an invalid exception number, and warn if it remained invalid even though the emulator got an X86EMUL_PROPAGATE_FAULT return code. Signed-off-by: Paolo Bonzini --- arch/x86/kvm/emulate.c | 5 ++++- arch/x86/kvm/x86.c | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 4fbf4b598f92..e5bf13003cd2 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -527,6 +527,7 @@ static unsigned long seg_base(struct x86_emulate_ctxt *ctxt, int seg) static int emulate_exception(struct x86_emulate_ctxt *ctxt, int vec, u32 error, bool valid) { + WARN_ON(vec > 0x1f); ctxt->exception.vector = vec; ctxt->exception.error_code = error; ctxt->exception.error_code_valid = valid; @@ -4827,8 +4828,10 @@ writeback: ctxt->eip = ctxt->_eip; done: - if (rc == X86EMUL_PROPAGATE_FAULT) + if (rc == X86EMUL_PROPAGATE_FAULT) { + WARN_ON(ctxt->exception.vector > 0x1f); ctxt->have_exception = true; + } if (rc == X86EMUL_INTERCEPTED) return EMULATION_INTERCEPTED; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 737b4bdac41c..cd718c01cdf1 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -5248,6 +5248,7 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, ctxt->interruptibility = 0; ctxt->have_exception = false; + ctxt->exception.vector = -1; ctxt->perm_ok = false; ctxt->ud = emulation_type & EMULTYPE_TRAP_UD;