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

Re: [Xen-devel] [PATCH v8 12/16] microcode: split out apply_microcode() from cpu_request_microcode()


  • To: Chao Gao <chao.gao@xxxxxxxxx>
  • From: Jan Beulich <JBeulich@xxxxxxxx>
  • Date: Fri, 2 Aug 2019 15:40:55 +0000
  • Accept-language: en-US
  • 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=OlLnlALvrrjJwn7GRt3aA5GiUVBhFUlddmc5wIf9HY8=; b=Qy+qBNjvqbw08A+etCYLxuMR5YvB0NpYpVkWrGbf87U+ZAKc3TFGx+bjzhdzm92d8szFMFZHIqeuSi2nGFa5g6N0nTqT61lG6JK1textDB3KVvhGujdBhVZlxT9rwRBapIYwhC7q8ZX5GvImubM4lYuBZD1nclI/ZoQQB1VDipVwQqgr7S8+4WTxEkQs+9U9fQQIyxl6dUBrIL4Fn4nJJq1q+l/jPchOSZLnAsnAhqMblsYuP8L4cSz9VXruY1C3kI8u6vYhbi7IYvUZ3x+un+G66c2vYZjb9zBMQIRFGR7zQ0RGOC7IEqIKpJH5AKGbQ/db+FgykdPYa2/6PdeSKw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C6FGWiaLJrAAppVw+jsyOgqdjdwkqvSjvx560zFTm2M/N6t/Rs1ccz27zCZaCoUf54TkZ0fgFPuGoV1KdZ3mJ593DFc4hjxwc0Ea6LeyhsLtdATnMajOhcKSShRFR2SQdBRop+Muj+VYliyej/NS7IrhfhWQD6xjzAntTIcNJIjNeK6qUQVuXyK8jxUdwcu6TT9C7Bm+X0DjugrwD7nHEmsat6nzUAGgbZMj7hfRF2zyV3HgSPTDymH0SVyn4HpHx7KvthWJsnqOs0pqNB9lRisdBlxHKG8wzAf0Cb3EV7AWmpaozWKPuduneDjA5aMXowU9IZkzSUL6mMQLA6kacQ==
  • Authentication-results: spf=none (sender IP is ) smtp.mailfrom=JBeulich@xxxxxxxx;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Ashok Raj <ashok.raj@xxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Delivery-date: Fri, 02 Aug 2019 15:42:21 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHVSFKxe9TG4/M45Uuu/98IT/ohCqboAK8A
  • Thread-topic: [PATCH v8 12/16] microcode: split out apply_microcode() from cpu_request_microcode()

On 01.08.2019 12:22, Chao Gao wrote:
> --- a/xen/arch/x86/microcode.c
> +++ b/xen/arch/x86/microcode.c
> @@ -189,12 +189,20 @@ static DEFINE_SPINLOCK(microcode_mutex);
>   
>   DEFINE_PER_CPU(struct cpu_signature, cpu_sig);
>   
> -struct microcode_info {
> -    unsigned int cpu;
> -    uint32_t buffer_size;
> -    int error;
> -    char buffer[1];
> -};
> +/*
> + * Return a patch that covers current CPU. If there are multiple patches,
> + * return the one with the highest revision number. Return error If no
> + * patch is found and an error occurs during the parsing process. Otherwise
> + * return NULL.
> + */
> +static struct microcode_patch *microcode_parse_blob(const char *buf,
> +                                                    uint32_t len)

Btw - you'd have less issues with line length if you omitted the
"microcode_" prefix from static functions.

> @@ -250,49 +251,88 @@ bool microcode_update_cache(struct microcode_patch 
> *patch)
>       return true;
>   }
>   
> -static int microcode_update_cpu(const void *buf, size_t size)
> +/*
> + * Load a microcode update to current CPU.
> + *
> + * If no patch is provided, the cached patch will be loaded. Microcode update
> + * during APs bringup and CPU resuming falls into this case.
> + */
> +static int microcode_update_cpu(const struct microcode_patch *patch)
>   {
> -    int err;
> -    unsigned int cpu = smp_processor_id();
> -    struct cpu_signature *sig = &per_cpu(cpu_sig, cpu);
> +    int err = microcode_ops->collect_cpu_info(&this_cpu(cpu_sig));
> +
> +    if ( unlikely(err) )
> +        return err;
>   
>       spin_lock(&microcode_mutex);
>   
> -    err = microcode_ops->collect_cpu_info(sig);
> -    if ( likely(!err) )
> -        err = microcode_ops->cpu_request_microcode(buf, size);
> +    if ( patch )
> +    {
> +        /*
> +         * If a patch is specified, it should has newer revision than
> +         * that of the patch cached.
> +         */
> +        if ( microcode_cache &&
> +             microcode_ops->compare_patch(patch, microcode_cache) != 
> NEW_UCODE )

While I see that you've taken care of the one case in Intel specific
code, this is again a case where I don't think you can validly call
this hook in the Intel case. Albeit maybe it is okay, provided that
the caller has already verified it against the CPU signature. Then
again I wonder why this check gets done here rather than in the
caller (next to that other check) anyway. Afaics this way you'd
also avoid re-checking on every CPU a CPU-independent property.

> -static long do_microcode_update(void *_info)
> +static long do_microcode_update(void *patch)
>   {
> -    struct microcode_info *info = _info;
> -    int error;
> -
> -    BUG_ON(info->cpu != smp_processor_id());
> +    unsigned int cpu;
>   
> -    error = microcode_update_cpu(info->buffer, info->buffer_size);
> -    if ( error )
> -        info->error = error;
> +    /* store the patch after a successful loading */

Nit: Comments should start with an uppercase letter.

Jan
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

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