Received: by 10.213.65.68 with SMTP id h4csp109607imn; Tue, 27 Mar 2018 17:52:09 -0700 (PDT) X-Google-Smtp-Source: AIpwx49VV/WA7d/NGKLZLX+M6ul49qCkSgCv0KC52Z7X3b7ZdRVSj5OQdUqHsmCrWmMEu9VkPlRP X-Received: by 2002:a17:902:9a86:: with SMTP id w6-v6mr1462548plp.175.1522198329456; Tue, 27 Mar 2018 17:52:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522198329; cv=none; d=google.com; s=arc-20160816; b=kId111cG52xGlk9FkW2FimuFPBw4Z5PBe8UTcOwkvLou62v8F3atCLvY7wL3n/FRZm IIzVGpD3oCTVK8611qsxzAQsrNOFqBhchDRG66L+n/9Cy+lemVPMR/aIgJhPYRP0Pvpf BWsBS8clQvR5KyWG04F1K8bA6EOLGAntqZDmbhiH0F3lPQ8HCFl2USEh+XLOAR8Qm8lH QbKAJiSFUnB7Di55BuJ5CWgIvWIaW7e8MO1gAzlEXl+nxpbrlHWHrxYRgUa5fnaRWsWp qsdtEM67WRhmH75IWarOBWOGCjU/se9+pkrTzK99INAhN7Ea8IVDUZpm5Dj101Gwj+c1 i0XA== 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=r93wtMQab6vL41d7lW+vDAJmKzuwRsw5Jxpd669pGkI=; b=r1FKW794Sj4W5fujXJYJNlFehPgKy9RSuoA/qzqb2GYlagNyUaIY04UiRizsQIaMk0 lXuiURri7IquMWWSXZgXiwxNeEKSFJufyIb1tlr+/UqhNhoCMLohcR7PKKdBufpdxAIH rkUvuT9MLl2PCe7glX5PuvmttsCIJ3eRgkj62Mdx0J/OlwbG97CSXavQfFwf5da2SmjH Cr+BQexKxp7pKWuj+sgzkgOUOLGXQjqKbv8ZKYJVir1A7rnfFVcTLEPoe5Grju/U8PuE UgFTNgYIYJOqrPWMdzndtImjGBQh25QLqj6j7bt7euU4Kf69NyeMKoPYskq2x9EO38lH IIQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=iEtbnrH6; 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 u6-v6si2325548plm.239.2018.03.27.17.51.55; Tue, 27 Mar 2018 17:52:09 -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=iEtbnrH6; 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 S1752679AbeC1Atz (ORCPT + 99 others); Tue, 27 Mar 2018 20:49:55 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:40307 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752008AbeC1Att (ORCPT ); Tue, 27 Mar 2018 20:49:49 -0400 Received: by mail-pl0-f65.google.com with SMTP id x4-v6so522277pln.7; Tue, 27 Mar 2018 17:49:48 -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=r93wtMQab6vL41d7lW+vDAJmKzuwRsw5Jxpd669pGkI=; b=iEtbnrH6E73qQ/14f4YAcjoJ2f8AHCx44ej8NbRR5tDsEsdcSynhUMt1fZHfjVk1Kv ol8msj3f8riH3TtAuB5pmLX7+L88lUfbkAdYW8prdiJjJRE0d+LBJ+tRYqoNDdsQMLuH qUbrM2EY3vdcV9XgQ/rALf8PM5Iius7NFXgXfNk5WZrdzY4J1LaT35ADX1eEXD3kxTNA e0bSnTHu0o3VMoNtb/4dZAWHlkSQ20a72hlQaZYzlqAbYIzUu0Yd/vJhbS080nmaS3GU F/ik/RGbth3jpv1WeQizrBUfbsiFpv86YdIkJ+WUa+1oEwyCR0XZ7guiyJoTyMShOVJZ Dy5g== 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=r93wtMQab6vL41d7lW+vDAJmKzuwRsw5Jxpd669pGkI=; b=ZZi72Id0XWhsj1t9baWbOC1CmPUSGVSCExpIzScU/L60iWukmoK92SE+ShjDqa/JgP h+IHzqpMka2Kh+wrzQ/xWW6eoHNfORj3dkXNrz24ShKZfPkCEmNsuMODOO0kPJePdjI2 OD848Un2P9+j9fQmYpLMbB5dZD4sgivTMjvUMRDjCDLhyXW8GY8+ZQ+ybGUd82WROWzK CEj+6xMXQpWXbH6eJ7+UP0ove8jsV7rtkP7zQcSnaZlLYrvxlF/x8EQjaEu9669PHqM7 kUgMML3Eg1gp7u6zpGiMfh5nFLxlMpfSNVG36xgNCLSKYj+EAnkBIbZOyoLyp/7Zj2/L TtBg== X-Gm-Message-State: AElRT7Hg4m0t1APut7a+P2M0eGuF9qe3U6wHf+5KXthMEXQrV07tvK25 Q7MntQAyKTt67l4LWLtvPaJzlg== X-Received: by 2002:a17:902:5acf:: with SMTP id g15-v6mr1474731plm.138.1522198188344; Tue, 27 Mar 2018 17:49:48 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.123]) by smtp.googlemail.com with ESMTPSA id j65sm4367083pge.58.2018.03.27.17.49.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Mar 2018 17:49:47 -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 v3 1/2] KVM: X86: Introduce handle_ud() Date: Tue, 27 Mar 2018 17:48:53 -0700 Message-Id: <1522198134-2709-2-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522198134-2709-1-git-send-email-wanpengli@tencent.com> References: <1522198134-2709-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 cb46e98..65eb3b9 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -2581,14 +2581,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 9bc05f5..63b46db 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -6233,14 +6233,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 1583bdc..e3a60ab 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 b620cfa..b2f6191 100644 --- a/arch/x86/kvm/x86.h +++ b/arch/x86/kvm/x86.h @@ -219,6 +219,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