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

Re: [PATCH] x86: Add Kconfig option to require NX bit support


  • To: Alejandro Vallejo <alejandro.vallejo@xxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Fri, 2 Jun 2023 10:31:08 +0200
  • 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=gMjj8e0o8WR1BdrHgAheGHQw7ORZQ5RCVQAhUgCAXDY=; b=ceFDSlL+krHIGOzC0as5Z37cWU9Np6j7kjBhsktGuqafn671P2OLS+Q89hwH4Dho/LdiNAjIKq7MrgrFm5vhqTLOTftzOIEVceoDq7SIEV9Sg2F2+HxP2o5xZrV9EIjkLSZPue2HHE0Y5CbqqjaPk/hg8NPMmJxangh+uBxRKCLfXTbukEWnrvQLzWeQ6Z8ib/+tzfenEAPyGnsTz9ZSUW2dXYIdHzjX7YwjJ1Bt3tvWfS0oS8l28tPoVJNaGydrtA3kahQO7cLob/H2yqgJkxhnzn/H6PPW2Y1JPIVzhyaadd8fP31iveEZqvV0HGtq3sKKIotnSN9k9t6GRiXM9g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IMDQL+eQsjJ13oWpu/rNEj9rvB8DkeG6xOn6Hyi8NLKoeU4e+2J7n9BQZgH+vmPRZK1k/Zr13AcysKQ01SobWzzpDYpy/NJqts1+ek5czhzzDFPra/GGGsoRyGgZxHWWkLXswIfsMkqlNMGYQDF4DxZaUyUfqFjLT+TfDfMq5Me1uuDdqRz5O9ssl8DqREbBZrtlvgyixuPJ5kfd9VKsctGF37Y8JgCDxNmRiiee7WYJd23Xy+V+K6XYMTFtKLdioXjAUSGok0z6Z7Qv3uurGvZFYnDg3RPXnwkhpX4t5+NuOI0dphTx5UZHLTeA4LyUpUEzfT6T81O64RW5+WRj3Q==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Fri, 02 Jun 2023 08:32:02 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 01.06.2023 19:43, Alejandro Vallejo wrote:
> This allows replacing many instances of runtime checks with folded
> constants. The patch asserts support for the NX bit in PTEs at boot time
> and if so short-circuits cpu_has_nx to 1. This has several knock-on effects
> that improve codegen:
>   * _PAGE_NX matches _PAGE_NX_BIT, optimising the macro to a constant.
>   * Many PAGE_HYPERVISOR_X are also folded into constants
>   * A few if ( cpu_has_nx ) statements are optimised out
> 
> We save 2.5KiB off the text section and remove the runtime dependency for
> applying NX, which hardens our security posture. The config option defaults
> to OFF for compatibility with previous behaviour.
> 
> Signed-off-by: Alejandro Vallejo <alejandro.vallejo@xxxxxxxxx>

At a guess this may want a Suggested-by: Andrew?

> --- a/xen/arch/x86/Kconfig
> +++ b/xen/arch/x86/Kconfig
> @@ -307,6 +307,16 @@ config MEM_SHARING
>       bool "Xen memory sharing support (UNSUPPORTED)" if UNSUPPORTED
>       depends on HVM
>  
> +config REQUIRE_NX_BIT

I don't think "_BIT" in the name is necessary or useful.

> +     def_bool n
> +     prompt "Require NX bit support"

Just

        bool "Require NX bit support"

please.

> +     ---help---

In new code just "help" please.

> @@ -151,6 +152,11 @@ not_multiboot:
>  .Lnot_aligned:
>          add     $sym_offs(.Lbag_alg_msg),%esi   # Error message
>          jmp     .Lget_vtb
> +#if IS_ENABLED(CONFIG_REQUIRE_NX_BIT)
> +no_nx_bit:

.Lno_nx_bit (no need for this to end up in the symbol table, just like
most other labels around here).

> @@ -647,11 +653,18 @@ trampoline_setup:
>          cpuid
>  1:      mov     %edx, CPUINFO_FEATURE_OFFSET(X86_FEATURE_LM) + 
> sym_esi(boot_cpu_data)
>  
> -        /* Check for NX. Adjust EFER setting if available. */
> +        /*
> +         * Check for NX:
> +         *   - If Xen was compiled requiring it simply assert it's
> +         *     supported. The trampoline already has the right constant.
> +         *   - Otherwise, update the trampoline EFER mask accordingly.
> +         */
>          bt      $cpufeat_bit(X86_FEATURE_NX), %edx
> -        jnc     1f
> +        jnc     no_nx_bit
> +#if !IS_ENABLED(CONFIG_REQUIRE_NX_BIT)
>          orb     $EFER_NXE >> 8, 1 + sym_esi(trampoline_efer)
> -1:
> +no_nx_bit:
> +#endif
>  
>          /* Check for availability of long mode. */
>          bt      $cpufeat_bit(X86_FEATURE_LM),%edx

I think it would be nice if this check came ahead of the NX one, as
LM availability is quite a bit more important (and hence imo lack
thereof wants diagnosing first). Especially as the re-ordering looks
to be entirely trivial.

> --- a/xen/arch/x86/efi/efi-boot.h
> +++ b/xen/arch/x86/efi/efi-boot.h
> @@ -751,6 +751,15 @@ static void __init efi_arch_cpu(void)
>      {
>          caps[FEATURESET_e1d] = cpuid_edx(0x80000001);
>  
> +        /*
> +         * This check purposefully doesn't use cpu_has_nx because
> +         * cpu_has_nx bypasses the boot_cpu_data read if Xen was compiled
> +         * with CONFIG_REQUIRE_NX_BIT
> +         */
> +        if ( IS_ENABLED(CONFIG_REQUIRE_NX_BIT) &&
> +             !boot_cpu_has(X86_FEATURE_NX) )
> +            blexit(L"This Xen build requires NX bit support");

Nit: Nearby uses of blexit() suggest there wants to be a full stop.

Jan



 


Rackspace

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