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

Re: [PATCH v2 01/10] xen: Implement xen/alternative-call.h for use in common code


  • To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 14 Jul 2021 17:35:36 +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-SenderADCheck; bh=pegp8Irz1OROPOni0AM8BAGfGr9mi2RFlugcUiMNSXg=; b=Lupcv6OIGS0xLctWfCLVe7IrG48bfgUVXwFc1NShTEutcRDoS8jjdsvrVYr/Xzrc+AmUvgU3KgqOxUafxCBCPo+3j0OYm62wdD/dzMAxxm0v1vV01kJYOW8ZuOs28RiT6apeuL0S1VqvgclVwgoDxi8I9c5Z9r/w6+3gnZOrdHiZTpToy5klLLDbcx+ms4AV+uniUYavKaqoGxb5vZ0c/MbEiKiyhAcaj9QCMynV8cPtFqAB/oRUaIFP4En8Ypc/Gv4CTMFORwDCJ1xTp8KIFGsKWzo7dct4XSHCgQNmjNKu/vDZHj+K5dONf3p9Z4LdsHQjHpKu503AsFeLMs+Fzg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kEEXzybuDolW7lVcYe89MxoAJgdNh5OO7XIrdM1qa5OAnXGu+snprY3G9TFoCCwYT4/1SKKV6Zn4RZGblB8bKd6SUKnyOq9Q5QOm6xpEEz0j+Yfgy435cir3ne8iP8YwzfrK+nxmf8/l7ol3hQO2KoXA+IcktMBbCuImplprZMxzCYBU+5IMGkljO3riPH+FAFBsuJt/2nJX1aS1Muud4+1aQEt4VjDKFeAwElhO0jIGXb0v01s3Fa7aJXgvCh+BV9Jk8a43MM+FOSDRobinDTzDlZFwBh6ZQJTTjrn9nJg8X2c5SU0aNt9bJPqgCjhLEL1RWxtaR159Kp3fFxFglg==
  • Authentication-results: apertussolutions.com; dkim=none (message not signed) header.d=none;apertussolutions.com; dmarc=none action=none header.from=suse.com;
  • Cc: Roger Pau Monné <roger.pau@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx, "Daniel P. Smith" <dpsmith@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Wed, 14 Jul 2021 15:35:58 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 12.07.2021 22:32, Daniel P. Smith wrote:
> --- a/xen/arch/x86/Kconfig
> +++ b/xen/arch/x86/Kconfig
> @@ -9,6 +9,7 @@ config X86
>       select ARCH_SUPPORTS_INT128
>       select CORE_PARKING
>       select HAS_ALTERNATIVE
> +     select ALTERNATIVE_CALL
>       select HAS_COMPAT
>       select HAS_CPUFREQ
>       select HAS_EHCI

Please respect the (at least largely) alphabetical ordering here and ...

> --- a/xen/common/Kconfig
> +++ b/xen/common/Kconfig
> @@ -25,6 +25,9 @@ config GRANT_TABLE
>  config HAS_ALTERNATIVE
>       bool
>  
> +config ALTERNATIVE_CALL
> +     bool
> +
>  config HAS_COMPAT
>       bool

... maybe also here.

> --- /dev/null
> +++ b/xen/include/xen/alternative-call.h
> @@ -0,0 +1,65 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#ifndef XEN_ALTERNATIVE_CALL
> +#define XEN_ALTERNATIVE_CALL
> +
> +/*
> + * Some subsystems in Xen may have multiple implementions, which can be
> + * resolved to a single implementation at boot time.  By default, this will
> + * result in the use of function pointers.
> + *
> + * Some architectures may have mechanisms for dynamically modifying .text.
> + * Using this mechnaism, function pointers can be converted to direct calls
> + * which are typically more efficient at runtime.
> + *
> + * For architectures to support:
> + *
> + * - Implement alternative_{,v}call() in asm/alternative.h.  Code generation
> + *   requirements are to emit a function pointer call at build time, and 
> stash
> + *   enough metadata to simplify the call at boot once the implementation has
> + *   been resolved.
> + * - Select ALTERNATIVE_CALL in Kconfig.
> + *
> + * To use:
> + *
> + * Consider the following simplified example.
> + *
> + *  1) struct foo_ops __alt_call_maybe_initdata ops;
> + *
> + *  2) struct foo_ops __alt_call_maybe_initconst foo_a_ops = { ... };
> + *     struct foo_ops __alt_call_maybe_initconst foo_b_ops = { ... };
> + *
> + *     void foo_init(void)
> + *     {
> + *         ...
> + *         if ( use_impl_a )
> + *             ops = *foo_a_ops;
> + *         else if ( use_impl_b )
> + *             ops = *foo_b_ops;
> + *         ...
> + *     }
> + *
> + *  3) alternative_call(ops.bar, ...);
> + *
> + * There needs to a single ops object (1) which will eventually contain the
> + * function pointers.  This should be populated in foo's init() function (2)
> + * by one of the available implementations.  To call functions, use
> + * alternative_{,v}call() referencing the main ops object (3).
> + */

May be worth adding a sentence about the section annotations, the
more that (as you did point out in an earlier reply) there are
pre-existing cases differing from the general goal here?

> +#ifdef CONFIG_ALTERNATIVE_CALL
> +
> +#include <asm/alternative.h>
> +
> +#define __alt_call_maybe_initdata  __initdata
> +#define __alt_call_maybe_initconst __initconst

As indicated elsewhere, I think this wants to be __initconstrel,
as the function pointers to place in the structures will
definitely involve relocations. Otoh, given your initial reply,
__alt_call_maybe_initdata may be all that's actually needed.

> +#else
> +
> +#define alternative_call(func, args...)  (func)(args)
> +#define alternative_vcall(func, args...) (func)(args)
> +
> +#define __alt_call_maybe_initdata
> +#define __alt_call_maybe_initconst
> +
> +#endif /* !CONFIG_ALTERNATIVE_CALL */
> +#endif /* XEN_ALTERNATIVE_CALL */

I'm surprised you have no "Local variables:" footer comment here.
Not that I need it for anything, but I thought you and others are
quite interested in it to be there.

Jan




 


Rackspace

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