Received: by 10.213.65.68 with SMTP id h4csp121784imn; Fri, 30 Mar 2018 02:09:27 -0700 (PDT) X-Google-Smtp-Source: AIpwx48/JAvbv0fhPRxn1ccVIeTqjJKg0fsYXLwRRkjraFbc27Fq+ddaUdIMrzUvUWoyHmRoNMMH X-Received: by 10.101.76.10 with SMTP id u10mr8067307pgq.445.1522400967365; Fri, 30 Mar 2018 02:09:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522400967; cv=none; d=google.com; s=arc-20160816; b=TjhJOXXMNiGvD0YxHbYPilufxYbijzbvvm/fEmXhR8Z9q8FMfocm91QWi3JWvVDOfN IXXpgqW5RP6Z6YfKnCRRJohso41Vp+t8czGS0tkPDeSUN84n17DEC9sbR5KNdu1dNKww 2+Y71z12JObYfJAB6jbV363illTx8eLyc8TbjafRCQExiE0zWEzjHdpDVCyXmdVgFrK6 9GacTGgWgVbIV589t4kr8+3CElLzEPzD/MgeKgtxMdB/+S26VC0VrC6q9vwLIrUCD6lm SS0wd6dmDDz1+5hTLw03n34T/X/OX92WQn89zpQtV2rWf5vgKDuWODzQAijmv4rzH/3Q Evtw== 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 :dkim-signature:arc-authentication-results; bh=CguQ2YPiBzUV+dxNkQhPCZiOD6SsKGCObfDpiQeyIyc=; b=gRKRPBP1VWxq59D1La7BNSGh660CoZ+wzJwQIKYqbqsSMGQpaj11086gqeWPaaAG7V aN0Xs7jm3kf/9SyZ04RKpMNBjPhzK9+qTZ8FhQaRHG9dgBL4jGnhgUv0NnERljrriQz/ DDTtAla+0VzOw/ZoCMjP1W155t2onAlYeXoDkQ/BCobObPoYT8C6+mdUgGdD88BmsZ9t bIIh/4dtR9zug6OpFOhwGUcRD6MRkvCm0MyFucFSkAB4k+FTmG7bC+DYKupEQLFrZ9HK CP5OArIMj/v3xqfZRMdbi5tlB5fm2DZX8V1Cx75nIniIr1RbstQBloTV3nWGdLjW+iu6 7SCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=H0bV/DU3; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w5si5312075pgt.823.2018.03.30.02.09.13; Fri, 30 Mar 2018 02:09:27 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=H0bV/DU3; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751280AbeC3JHo (ORCPT + 99 others); Fri, 30 Mar 2018 05:07:44 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:44239 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750764AbeC3JHk (ORCPT ); Fri, 30 Mar 2018 05:07:40 -0400 Received: by mail-pg0-f65.google.com with SMTP id v26so4764927pge.11; Fri, 30 Mar 2018 02:07:39 -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=CguQ2YPiBzUV+dxNkQhPCZiOD6SsKGCObfDpiQeyIyc=; b=H0bV/DU3ojV42LYcR97m/7lMYGodCHz59HHDwya6euX45cYs8yCqVcTfQftRfx4rZD AJbyCCM6gbo0Bn82A/w0Hwu4l8d2lRZidGO58FMlfHYCZBkVM51W9294psrK+6xgiaFM pxVCUBoGrqkn95oM3EmNIclMh6ThmZYbBfPcjmrcCghrgQO1QTwe4Lscl2tUuI3XPCiB 6W/GqAUs5L5s7e0P64TRtdNUtmKQsrj4DcAtyKGutGUPEAKQEL0WUfBS03S1ylTAHC+W gsG9QWTRYk2KFdrjZOp6Ss3G1fwrSAQxxokKjRCOxQtHKDSHrmYSVZBI1uXCD4/X9mU/ wLww== 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=CguQ2YPiBzUV+dxNkQhPCZiOD6SsKGCObfDpiQeyIyc=; b=MmIJVuTUefSfKEvwCHXCZBNcyEku4IoJFhz8KSHPs5md4nfFddyqmHlCzBDlZsgULW ZmO/zNSYwUsBD4WyrMuPs3r7GXWhpsc9KOOtc5Uz1ol94Z46A8L8g3F8p3k5z+cIQHW8 PwinbnmmI0me43Gn0SaXDnUoMgxZEcQT8jlQh5UoEXIGANy5Eg/Ycx7nd14KLfRNhIT8 Em7oKdEXEUOdZpPcsxv4g91ywsLLsP0gMlnvVpwQ8pKehOVcXMzcLwWik6eOuE8P/JHP J7qzQ0QDwX5xz5kktZMHd8cV/GIpu+dm/F93qm3M6lSaha5eM1aZ7GgZdK4eilKUBYVQ PwQg== X-Gm-Message-State: AElRT7EdfiY3HKGGmVmai7/OPdLlKtY+OG61N4U1VK93mZKypFtZHbVe xf/EqjXmq2rx9WGYMATOHFmA8Q== X-Received: by 10.101.87.138 with SMTP id b10mr7884137pgr.241.1522400858885; Fri, 30 Mar 2018 02:07:38 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.123]) by smtp.googlemail.com with ESMTPSA id w9sm10245345pfl.45.2018.03.30.02.07.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 30 Mar 2018 02:07:38 -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 v4 1/2] KVM: X86: Introduce handle_ud() Date: Fri, 30 Mar 2018 02:06:43 -0700 Message-Id: <1522400804-4578-2-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522400804-4578-1-git-send-email-wanpengli@tencent.com> References: <1522400804-4578-1-git-send-email-wanpengli@tencent.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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); -- 2.7.4