From patchwork Mon Jun 26 16:28:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 9810125 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 4BACA603F3 for ; Mon, 26 Jun 2017 17:00:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4537F2857F for ; Mon, 26 Jun 2017 17:00:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3A1FA285A6; Mon, 26 Jun 2017 17:00:04 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A6F9128546 for ; Mon, 26 Jun 2017 17:00:03 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dPX9b-0008Ak-Gk; Mon, 26 Jun 2017 16:46:23 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dPX9a-0008Ac-K9 for xen-devel@lists.xenproject.org; Mon, 26 Jun 2017 16:46:22 +0000 Received: from [85.158.137.68] by server-16.bemta-3.messagelabs.com id 1D/D7-29088-D5A31595; Mon, 26 Jun 2017 16:46:21 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmplkeJIrShJLcpLzFFi42JxWrrBXjfWKjD S4M9uWYvvWyYzOTB6HP5whSWAMYo1My8pvyKBNePLuXvsBY22FVuXrWdtYLyr28XIySEh4C/x 5MAvNhCbTUBZ4mdnL5gtIqAn0XTgOSOIzSyQJ3F29SJWEFtYIEji5csVzCA2i4CqxNknc8Hqe QXMJZbe2sQKMVNeYlfbRTCbEyjesHo6mC0kYCaxq7ePDcJWkOiYfowJoldQ4uTMJywQuyQkDr 54wTyBkXcWktQsJKkFjEyrGDWKU4vKUot0jSz0kooy0zNKchMzc3QNDYz1clOLixPTU3MSk4r 1kvNzNzECg6eegYFxB2P7Cb9DjJIcTEqivBxPAiKF+JLyUyozEosz4otKc1KLDzHKcHAoSfCy WQZGCgkWpaanVqRl5gDDGCYtwcGjJMLbpQmU5i0uSMwtzkyHSJ1iVJQS52UG6RMASWSU5sG1w WLnEqOslDAvIwMDgxBPQWpRbmYJqvwrRnEORiVh3g6QKTyZeSVw018BLWYCWswyLwBkcUkiQk qqgTHlgtAP5YDlDrsuXrszZ69cbvZS+e0RJ7pWPcuKerE44F27ZxP3+dt/7lfEMh+QPfvMeq5 ojeW/+NybS3pFmyZxTYxWDrjC/t4z3bLgwgX2lVkxH77FqRumFv7ZrsK7XeFmnzhv/Aqfo5wn eCODjty+MlXfd35g6km7L9bK+q+vhW9Ys7t0lqkSS3FGoqEWc1FxIgAtxatgmAIAAA== X-Env-Sender: prvs=343741041=wei.liu2@citrix.com X-Msg-Ref: server-11.tower-31.messagelabs.com!1498495579!76567050!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 11537 invoked from network); 26 Jun 2017 16:46:21 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-11.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 26 Jun 2017 16:46:21 -0000 X-IronPort-AV: E=Sophos;i="5.39,396,1493683200"; d="scan'208";a="437867876" From: Wei Liu To: Xen-devel Date: Mon, 26 Jun 2017 17:28:41 +0100 Message-ID: <20170626162842.482-13-wei.liu2@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170626162842.482-1-wei.liu2@citrix.com> References: <20170626162842.482-1-wei.liu2@citrix.com> MIME-Version: 1.0 Cc: Andrew Cooper , Wei Liu , Jan Beulich Subject: [Xen-devel] [PATCH v5 12/13] x86/traps: move some PV specific functions to pv/traps.c X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Those functions must be moved at the same time. Also move softirq_trap because it is only used there. Fix some coding style issues while moving code. Signed-off-by: Wei Liu --- xen/arch/x86/pv/traps.c | 104 ++++++++++++++++++++++++++++++++++++++++++++ xen/arch/x86/traps.c | 88 ------------------------------------- xen/include/asm-x86/traps.h | 6 --- 3 files changed, 104 insertions(+), 94 deletions(-) diff --git a/xen/arch/x86/pv/traps.c b/xen/arch/x86/pv/traps.c index 7d2f9aa638..1fce7df0c0 100644 --- a/xen/arch/x86/pv/traps.c +++ b/xen/arch/x86/pv/traps.c @@ -19,9 +19,11 @@ * Copyright (c) 2017 Citrix Systems Ltd. */ +#include #include #include #include +#include #include #include @@ -148,6 +150,108 @@ void init_int80_direct_trap(struct vcpu *v) tb->flags = TBF_EXCEPTION | (TI_GET_IF(ti) ? TBF_INTERRUPT : 0); } +struct softirq_trap { + struct domain *domain; /* domain to inject trap */ + struct vcpu *vcpu; /* vcpu to inject trap */ + int processor; /* physical cpu to inject trap */ +}; + +static DEFINE_PER_CPU(struct softirq_trap, softirq_trap); + +static void nmi_mce_softirq(void) +{ + int cpu = smp_processor_id(); + struct softirq_trap *st = &per_cpu(softirq_trap, cpu); + + BUG_ON(st->vcpu == NULL); + + /* + * Set the tmp value unconditionally, so that the check in the iret + * hypercall works. + */ + cpumask_copy(st->vcpu->cpu_hard_affinity_tmp, + st->vcpu->cpu_hard_affinity); + + if ( (cpu != st->processor) || + (st->processor != st->vcpu->processor) ) + { + + /* + * We are on a different physical cpu. Make sure to wakeup the vcpu on + * the specified processor. + */ + vcpu_set_hard_affinity(st->vcpu, cpumask_of(st->processor)); + + /* Affinity is restored in the iret hypercall. */ + } + + /* + * Only used to defer wakeup of domain/vcpu to a safe (non-NMI/MCE) + * context. + */ + vcpu_kick(st->vcpu); + st->vcpu = NULL; +} + +void __init pv_trap_init(void) +{ + /* The 32-on-64 hypercall vector is only accessible from ring 1. */ + _set_gate(idt_table + HYPERCALL_VECTOR, + SYS_DESC_trap_gate, 1, entry_int82); + + /* Fast trap for int80 (faster than taking the #GP-fixup path). */ + _set_gate(idt_table + LEGACY_SYSCALL_VECTOR, SYS_DESC_trap_gate, 3, + &int80_direct_trap); + + open_softirq(NMI_MCE_SOFTIRQ, nmi_mce_softirq); +} + +int pv_raise_interrupt(struct vcpu *v, uint8_t trap_nr) +{ + struct softirq_trap *st = &per_cpu(softirq_trap, smp_processor_id()); + + switch ( trap_nr ) + { + case TRAP_nmi: + if ( cmpxchgptr(&st->vcpu, NULL, v) ) + return -EBUSY; + if ( !test_and_set_bool(v->nmi_pending) ) + { + st->domain = v->domain; + st->processor = v->processor; + + /* Not safe to wake up a vcpu here */ + raise_softirq(NMI_MCE_SOFTIRQ); + return 0; + } + st->vcpu = NULL; + break; + + case TRAP_machine_check: + if ( cmpxchgptr(&st->vcpu, NULL, v) ) + return -EBUSY; + + /* + * We are called by the machine check (exception or polling) handlers + * on the physical CPU that reported a machine check error. + */ + if ( !test_and_set_bool(v->mce_pending) ) + { + st->domain = v->domain; + st->processor = v->processor; + + /* not safe to wake up a vcpu here */ + raise_softirq(NMI_MCE_SOFTIRQ); + return 0; + } + st->vcpu = NULL; + break; + } + + /* Delivery failed */ + return -EIO; +} + /* * Local variables: * mode: C diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index f12a52032a..4d6f42d168 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -1540,39 +1540,6 @@ void do_general_protection(struct cpu_user_regs *regs) panic("GENERAL PROTECTION FAULT\n[error_code=%04x]", regs->error_code); } -static DEFINE_PER_CPU(struct softirq_trap, softirq_trap); - -static void nmi_mce_softirq(void) -{ - int cpu = smp_processor_id(); - struct softirq_trap *st = &per_cpu(softirq_trap, cpu); - - BUG_ON(st->vcpu == NULL); - - /* Set the tmp value unconditionally, so that - * the check in the iret hypercall works. */ - cpumask_copy(st->vcpu->cpu_hard_affinity_tmp, - st->vcpu->cpu_hard_affinity); - - if ((cpu != st->processor) - || (st->processor != st->vcpu->processor)) - { - /* We are on a different physical cpu. - * Make sure to wakeup the vcpu on the - * specified processor. - */ - vcpu_set_hard_affinity(st->vcpu, cpumask_of(st->processor)); - - /* Affinity is restored in the iret hypercall. */ - } - - /* Only used to defer wakeup of domain/vcpu to - * a safe (non-NMI/MCE) context. - */ - vcpu_kick(st->vcpu); - st->vcpu = NULL; -} - static void pci_serr_softirq(void) { printk("\n\nNMI - PCI system error (SERR)\n"); @@ -1934,19 +1901,6 @@ void __init init_idt_traps(void) this_cpu(compat_gdt_table) = boot_cpu_compat_gdt_table; } -void __init pv_trap_init(void) -{ - /* The 32-on-64 hypercall vector is only accessible from ring 1. */ - _set_gate(idt_table + HYPERCALL_VECTOR, - SYS_DESC_trap_gate, 1, entry_int82); - - /* Fast trap for int80 (faster than taking the #GP-fixup path). */ - _set_gate(idt_table + LEGACY_SYSCALL_VECTOR, SYS_DESC_trap_gate, 3, - &int80_direct_trap); - - open_softirq(NMI_MCE_SOFTIRQ, nmi_mce_softirq); -} - extern void (*const autogen_entrypoints[NR_VECTORS])(void); void __init trap_init(void) { @@ -1979,48 +1933,6 @@ void __init trap_init(void) open_softirq(PCI_SERR_SOFTIRQ, pci_serr_softirq); } -int pv_raise_interrupt(struct vcpu *v, uint8_t trap_nr) -{ - struct softirq_trap *st = &per_cpu(softirq_trap, smp_processor_id()); - - switch (trap_nr) { - case TRAP_nmi: - if ( cmpxchgptr(&st->vcpu, NULL, v) ) - return -EBUSY; - if ( !test_and_set_bool(v->nmi_pending) ) { - st->domain = v->domain; - st->processor = v->processor; - - /* not safe to wake up a vcpu here */ - raise_softirq(NMI_MCE_SOFTIRQ); - return 0; - } - st->vcpu = NULL; - break; - - case TRAP_machine_check: - if ( cmpxchgptr(&st->vcpu, NULL, v) ) - return -EBUSY; - - /* We are called by the machine check (exception or polling) handlers - * on the physical CPU that reported a machine check error. */ - - if ( !test_and_set_bool(v->mce_pending) ) { - st->domain = v->domain; - st->processor = v->processor; - - /* not safe to wake up a vcpu here */ - raise_softirq(NMI_MCE_SOFTIRQ); - return 0; - } - st->vcpu = NULL; - break; - } - - /* delivery failed */ - return -EIO; -} - void activate_debugregs(const struct vcpu *curr) { ASSERT(curr == current); diff --git a/xen/include/asm-x86/traps.h b/xen/include/asm-x86/traps.h index 1e3f9c7fad..8d903ec91b 100644 --- a/xen/include/asm-x86/traps.h +++ b/xen/include/asm-x86/traps.h @@ -19,12 +19,6 @@ #ifndef ASM_TRAP_H #define ASM_TRAP_H -struct softirq_trap { - struct domain *domain; /* domain to inject trap */ - struct vcpu *vcpu; /* vcpu to inject trap */ - int processor; /* physical cpu to inject trap */ -}; - struct cpu_user_regs; void async_exception_cleanup(struct vcpu *);