Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp389389ybl; Fri, 23 Aug 2019 02:23:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqy9/wo1IHlhJKudHIa7JVeJeqoeb8lX/2W944zgANa/7SBJWWLZ2xcMdWVpiaBvWLxLEPiZ X-Received: by 2002:a63:7c0d:: with SMTP id x13mr3085509pgc.360.1566552229405; Fri, 23 Aug 2019 02:23:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566552229; cv=none; d=google.com; s=arc-20160816; b=OVOfauGjiC07P2aBe6jg8LGyOLpq9+5/bZXVEhCDXolqTRKJ50/ASnL9Kj8ihO0Skl BvJayA3g6aRyyXp1KKoFymh8mpaqLQgJOf6+Mk5GI98Z6vkkDGZp5IHaVb0T1952962W wrkwYsxG7bo5E7aBvquua3dR4OiYgTrsIRrTgmLsXP7htzpJmofgvZJsDCkokKs1dnHg SYivH/VNVataAR+3ug04CO0/QeXhYnxvK6v8Unu6N9MbDuHj3Loyo8fB3DSVJkLf5Djh U833RjOHrVzk42gGP1/xC3iTgrhrMnqaXG261ddtWV8PFwujbnlQdKfqFNtuf/ncJtkH FUbw== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=5c+Ub4/uFDWHR9dWoh9/TMMxpuFzdOmjrjJ1boaPzdE=; b=pt0g4/Il3wQvjxjucagIl4bKUSXXckQh8wgyrHmW0SQePfbZrtp4mkl+zbrPLYA2lw e8O3Bjz5I4MJiVY+DKtg9ZSeh2wfSH9jHx9Os8/5y7SnIxKm9wOGa4pD6JurcRjj3aFW 1Nc5Kr7Cv1EpZ56WiaLXrd0WnLkrJDgFNTRPCJFpUWO3TvfYXU40I7J5aQlyVoiZcEpe t2Z9HespRmlX3yQ69LAsWHi8bJ4DgL/Z5flmBl+rYl6enqQeMbBfr+5X11MljUhq4Ojk 990s3BeLWTF5tSbZQg1fFZGj/1PJPa9Gbvjad53aYpGpG7/lBXHuD0S8D7AriX/A4kpD DuBg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m4si1511307pgv.57.2019.08.23.02.23.33; Fri, 23 Aug 2019 02:23: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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733231AbfHWBHs (ORCPT + 99 others); Thu, 22 Aug 2019 21:07:48 -0400 Received: from mga01.intel.com ([192.55.52.88]:38007 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732741AbfHWBHO (ORCPT ); Thu, 22 Aug 2019 21:07:14 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Aug 2019 18:07:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,419,1559545200"; d="scan'208";a="186733507" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.41]) by FMSMGA003.fm.intel.com with ESMTP; 22 Aug 2019 18:07:12 -0700 From: Sean Christopherson To: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RESEND PATCH 08/13] KVM: x86: Move #UD injection for failed emulation into emulation code Date: Thu, 22 Aug 2019 18:07:04 -0700 Message-Id: <20190823010709.24879-9-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190823010709.24879-1-sean.j.christopherson@intel.com> References: <20190823010709.24879-1-sean.j.christopherson@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Immediately inject a #UD and return EMULATE done if emulation fails when handling an intercepted #UD. This helps pave the way for removing EMULATE_FAIL altogether. Signed-off-by: Sean Christopherson --- arch/x86/kvm/x86.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index a1f9e36b2d58..bff3320aa78e 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -5328,7 +5328,6 @@ EXPORT_SYMBOL_GPL(kvm_write_guest_virt_system); int handle_ud(struct kvm_vcpu *vcpu) { int emul_type = EMULTYPE_TRAP_UD; - enum emulation_result er; char sig[5]; /* ud2; .ascii "kvm" */ struct x86_exception e; @@ -5340,12 +5339,7 @@ int handle_ud(struct kvm_vcpu *vcpu) emul_type = EMULTYPE_TRAP_UD_FORCED; } - er = kvm_emulate_instruction(vcpu, emul_type); - if (er == EMULATE_USER_EXIT) - return 0; - if (er != EMULATE_DONE) - kvm_queue_exception(vcpu, UD_VECTOR); - return 1; + return kvm_emulate_instruction(vcpu, emul_type) != EMULATE_USER_EXIT; } EXPORT_SYMBOL_GPL(handle_ud); @@ -6533,8 +6527,10 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, ++vcpu->stat.insn_emulation; if (r != EMULATION_OK) { if ((emulation_type & EMULTYPE_TRAP_UD) || - (emulation_type & EMULTYPE_TRAP_UD_FORCED)) - return EMULATE_FAIL; + (emulation_type & EMULTYPE_TRAP_UD_FORCED)) { + kvm_queue_exception(vcpu, UD_VECTOR); + return EMULATE_DONE; + } if (reexecute_instruction(vcpu, cr2, write_fault_to_spt, emulation_type)) return EMULATE_DONE; -- 2.22.0