From patchwork Tue Apr 3 23:28:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 10321857 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E47CB60532 for ; Tue, 3 Apr 2018 23:31:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE41A287CB for ; Tue, 3 Apr 2018 23:31:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D25E728CFD; Tue, 3 Apr 2018 23:31:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 49B76287CB for ; Tue, 3 Apr 2018 23:31:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754154AbeDCXaB (ORCPT ); Tue, 3 Apr 2018 19:30:01 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:33990 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753356AbeDCX36 (ORCPT ); Tue, 3 Apr 2018 19:29:58 -0400 Received: by mail-pl0-f65.google.com with SMTP id u11-v6so11315971plq.1; Tue, 03 Apr 2018 16:29:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kzwjQFHXGBAwH9JIjPEVo96qcoWD7XIcyrhuARmnHoY=; b=fO053eKEM/QQBwvjibGVouiwRAz1vdMntQof37v52tuQXpmgToce/IaNS2y21aROYK 4akUJiFPTosvRXy6TFbwFWCKNLZ0gYGimMS+F1A+pwa57qTTNVTznh3umMI58ptk0tkM 3red5Vg4nnd53iNZkimzKSrDX7hecL36TMPRwAiVLO8j3f4kDehQi5LcIz8AOpT45AWe OflBrx0swEJKeMGQp+RpoirK1GGZkWSGVA4YqkgC7mbg/GxxKjM/A/8cACuNUKpFwtR7 34z6KfZyWXR5FrRuXajgnDBh+E5wdMbYVSdk4rZlMkTQ1+Qnoku3v9J55e7IutSJrsup +OyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kzwjQFHXGBAwH9JIjPEVo96qcoWD7XIcyrhuARmnHoY=; b=gRsEqXP808VHznT/RdITgE5scMaNXZ9AnSbwQIjYoSmELUI4tiYK0q27A5xDSx3TO3 PqUI4VPX1oqshoEA/aDztySWIcsInLF85BZEbdRMdYNpDZUM4WobKJysX3/fD9ZfJIff PKtdgRJPpnfduF9dxnsq8eF3hk5NVjhiVKPaoIxiRiG1qChahXqn1jT/tj84a+QZwzoi DCKSAnnWWa5Xwh+hz0cw58AVXlC99oQaZ6Z+6lEReUTKjqQ2KoziyjqB/cFN6CE4rhaM 8EJDfeRI9Ir6eDXTkOzXHpnH7il/tiim/nUP0JV5ExTM2FmJGMsRZ/nI+rx40N1JmS++ rboA== X-Gm-Message-State: AElRT7HLq7ynlBod0kvEELnwekZi2rEJmK/opeL/C+/wAvKTa4p4EUTZ HW8m/OctPvIDLJQI6b7C+0vtVg== X-Google-Smtp-Source: AIpwx48JfD2Q9+Oi6Hm6nihOi34e2w1JLzCP0KYggHsuCZ6oAfxJ0no7rWDkKM70YP86oKRk4FGDdg== X-Received: by 2002:a17:902:9a44:: with SMTP id x4-v6mr16104689plv.312.1522798197308; Tue, 03 Apr 2018 16:29:57 -0700 (PDT) Received: from localhost.localdomain ([45.248.77.205]) by smtp.googlemail.com with ESMTPSA id y2sm373949pgv.38.2018.04.03.16.29.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 03 Apr 2018 16:29:56 -0700 (PDT) From: Wanpeng Li X-Google-Original-From: Wanpeng Li To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Andrew Cooper , Konrad Rzeszutek Wilk , Liran Alon Subject: [PATCH v5 1/2] KVM: X86: Introduce handle_ud() Date: Tue, 3 Apr 2018 16:28:48 -0700 Message-Id: <1522798129-14588-2-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522798129-14588-1-git-send-email-wanpengli@tencent.com> References: <1522798129-14588-1-git-send-email-wanpengli@tencent.com> MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Wanpeng Li Introduce handle_ud() to handle invalid opcode, this function will be used by later patches. Reviewed-by: Konrad Rzeszutek Wilk Reviewed-by: Liran Alon Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Andrew Cooper Cc: Konrad Rzeszutek Wilk Cc: Liran Alon Signed-off-by: Wanpeng Li Reviewed-by: David Hildenbrand --- arch/x86/kvm/svm.c | 9 +-------- arch/x86/kvm/vmx.c | 10 ++-------- arch/x86/kvm/x86.c | 13 +++++++++++++ arch/x86/kvm/x86.h | 2 ++ 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index f66fc2e..e0a3f56 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -2676,14 +2676,7 @@ static int bp_interception(struct vcpu_svm *svm) static int ud_interception(struct vcpu_svm *svm) { - int er; - - er = emulate_instruction(&svm->vcpu, EMULTYPE_TRAP_UD); - if (er == EMULATE_USER_EXIT) - return 0; - if (er != EMULATE_DONE) - kvm_queue_exception(&svm->vcpu, UD_VECTOR); - return 1; + return handle_ud(&svm->vcpu); } static int ac_interception(struct vcpu_svm *svm) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index b2f8a70..0f11243 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -6436,14 +6436,8 @@ static int handle_exception(struct kvm_vcpu *vcpu) if (is_nmi(intr_info)) return 1; /* already handled by vmx_vcpu_run() */ - if (is_invalid_opcode(intr_info)) { - er = emulate_instruction(vcpu, EMULTYPE_TRAP_UD); - if (er == EMULATE_USER_EXIT) - return 0; - if (er != EMULATE_DONE) - kvm_queue_exception(vcpu, UD_VECTOR); - return 1; - } + if (is_invalid_opcode(intr_info)) + return handle_ud(vcpu); error_code = 0; if (intr_info & INTR_INFO_DELIVER_CODE_MASK) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 7d9a444..1eb495e 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4840,6 +4840,19 @@ int kvm_write_guest_virt_system(struct x86_emulate_ctxt *ctxt, } EXPORT_SYMBOL_GPL(kvm_write_guest_virt_system); +int handle_ud(struct kvm_vcpu *vcpu) +{ + enum emulation_result er; + + er = emulate_instruction(vcpu, EMULTYPE_TRAP_UD); + if (er == EMULATE_USER_EXIT) + return 0; + if (er != EMULATE_DONE) + kvm_queue_exception(vcpu, UD_VECTOR); + return 1; +} +EXPORT_SYMBOL_GPL(handle_ud); + static int vcpu_is_mmio_gpa(struct kvm_vcpu *vcpu, unsigned long gva, gpa_t gpa, bool write) { diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h index 1e86174..7d35ce6 100644 --- a/arch/x86/kvm/x86.h +++ b/arch/x86/kvm/x86.h @@ -255,6 +255,8 @@ int kvm_write_guest_virt_system(struct x86_emulate_ctxt *ctxt, gva_t addr, void *val, unsigned int bytes, struct x86_exception *exception); +int handle_ud(struct kvm_vcpu *vcpu); + void kvm_vcpu_mtrr_init(struct kvm_vcpu *vcpu); u8 kvm_mtrr_get_guest_memory_type(struct kvm_vcpu *vcpu, gfn_t gfn); bool kvm_mtrr_valid(struct kvm_vcpu *vcpu, u32 msr, u64 data);