[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 2/3] x86/entry: Rework the exception entrypoints


  • To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 21 Feb 2023 12:46:50 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=0eXlZA1QoDOm9OHGtcFI8UbVABcXIw6qHaZQ04e+qj8=; b=j03TJpcJkGtjngs6+6m9VLx5McA4d2PXLDRN5crcuZtAPp3VkSFDxJTqI7bN7py3hLrk29Plx2tQq1G2KyozPVhC1pBqrnScHukstgiMFgpKN+Lj+q7Yog60rr3/0dc6laRhIwsJeOSOUs9iVNaQD8nengDKRZyx8/ADuau20GeL9yb6m1GbmKMJ7gyWCQSHQBNUkg7fBbh8b2iI93JaPgY5cyvkF8xr1xmHFu6+f9+r2YdCQtmOop9MUMglmoNNqBznP+w9wpMV+qLsrymZB1X6dNSF6h21kKWpZfjx5QdIMauNCjKX9AucL99+pY6XyHHxC+wobKe1WSW7ndd2Cw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HevpR9SYzQGTzN7lHC0BHvxnoAGi7Z73y9Urf0f1fhyi4poQk6fcvbtNFMkXiLGJ8Fig2tOzfajQZoGX2RUWRwish2HVRY/L5wiylnzUufwKU5xeRxrnolJ7e7ysRIamfW8Um9f7Mrj1xK834xzewePf4iGJCo2tfvywd630jGJvfZ7yLBJE3O9aYwyX59LdUR1l+fQy7x9Xy5WNoUNqZgJYwgHZ0FjdJHRsJSV1/gxsRB2V+hY2FlHDzGUoQU5o6r503NNLQxstYYzI+neOKYwLwhg9OcO3pbXu2Es/xkU1xhvFee89jTlaTWb08ELS9m4D9rn8mlRMC7yMl7XOJg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Roger Pau Monné <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>, Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>, Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Tue, 21 Feb 2023 11:46:55 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 20.02.2023 12:59, Andrew Cooper wrote:
> This fixes two issues preventing livepatching.  First, that #PF and NMI fall
> through into other functions,

I thought this was deliberate, aiming at avoiding the unconditional branch
for the most commonly taken path each. I'm not really opposed to the change,
but I think it wants saying a little more as to how little (or big) of an
effect this has (or at least is expected to have).

> and second to add ELF metadata.
> 
> Use a macro to generate the entrypoints programatically, rather than
> opencoding them all.  Switch to using the architectural short names.
> 
> Remove the DECLARE_TRAP_HANDLER{,_CONST}() infrastructure.  Only NMI/#MC are
> referenced externally (and NMI will cease to be soon, as part of adding FRED
> support).  Move the entrypoint declarations into the respective traps.c where
> they're used, rather than keeping them visible across ~all of Xen.

What about Misra? Won't they be unhappy about global functions with no
declaration in any header?

> Drop the long-stale comment at the top of init_idt_traps().  It's mostly
> discussing a 32bit Xen.

The use of interrupt gates isn't 32-bit only, and justifying why trap gates
aren't used looks to me like quite reasonable a purpose of that comment.

> --- a/xen/arch/x86/x86_64/entry.S
> +++ b/xen/arch/x86/x86_64/entry.S
> @@ -142,6 +142,50 @@ process_trap:
>  
>          .section .text.entry, "ax", @progbits
>  
> +.macro IDT_ENTRY vec label handler

As said in reply to another recent patch: Could we agree on separating
macro parameters by commas? I also wonder whether they shouldn't all have
":req" tagged onto them, as none of them is optional.

> +ENTRY(\label)
> +        ENDBR64
> +     .if ((1 << \vec) & X86_EXC_HAVE_EC) == 0

Nit: Hard tab slipped in here.

> +            push $0
> +        .endif
> +        movl  $\vec, 4(%rsp)
> +        jmp   \handler
> +
> +        .type \label, @function
> +        .size \label, . - \label
> +.endm
> +
> +.macro ENTRY vec label
> +        IDT_ENTRY \vec \label handle_exception
> +.endm
> +.macro ENTRY_IST vec label
> +        IDT_ENTRY \vec \label handle_ist_exception
> +.endm
> +
> +
> +ENTRY     X86_EXC_DE  entry_DE  /* 00 Divide Error */
> +ENTRY_IST X86_EXC_DB  entry_DB  /* 01 Debug Exception */
> +ENTRY_IST X86_EXC_NMI entry_NMI /* 02 Non-Maskable Interrupt */
> +ENTRY     X86_EXC_BP  entry_BP  /* 03 Breakpoint (int3) */
> +ENTRY     X86_EXC_OF  entry_OF  /* 04 Overflow (into) */
> +ENTRY     X86_EXC_BR  entry_BR  /* 05 Bound Range */
> +ENTRY     X86_EXC_UD  entry_UD  /* 06 Undefined Opcode */
> +ENTRY     X86_EXC_NM  entry_NM  /* 07 No Maths (Device Not Present) */
> +/*   _IST X86_EXC_DF  entry_DF     08 Double Fault - Handled specially */
> +/*        X86_EXC_CSO entry_CSO    09 Coprocessor Segment Override - Autogen 
> */
> +ENTRY     X86_EXC_TS  entry_TS  /* 10 Invalid TSS */
> +ENTRY     X86_EXC_NP  entry_NP  /* 11 Segment Not Present */
> +ENTRY     X86_EXC_SS  entry_SS  /* 12 Stack Segment Fault */
> +ENTRY     X86_EXC_GP  entry_GP  /* 13 General Protection Fault */
> +ENTRY     X86_EXC_PF  entry_PF  /* 14 Page Fault */
> +/*        X86_EXC_SPV entry_SPV    15 PIC Spurious Interrupt Vector - 
> Autogen */
> +ENTRY     X86_EXC_MF  entry_MF  /* 16 Maths Fault (x87 FPU) */
> +ENTRY     X86_EXC_AC  entry_AC  /* 17 Alignment Check */
> +ENTRY_IST X86_EXC_MC  entry_MC  /* 18 Machine Check */
> +ENTRY     X86_EXC_XM  entry_XM  /* 19 SIMD Maths Fault */
> +/*        X86_EXC_VE  entry_VE     20 Virtualisation Exception - Not 
> implemented */
> +ENTRY     X86_EXC_CP  entry_CP  /* 21 Control-flow Protection */

I expect you won't like the request, but still: There's a lot of redundancy
here. The first two arguments could all be folded, having the macro attach
the X86_EXC_ and entry_ prefixes. Or wait - only quite, as long as X86_EXC_*
are C macros rather than assembler equates.

Jan



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.