All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Julien Grall <julien@xen.org>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Anthony PERARD <anthony.perard@vates.tech>,
	Michal Orzel <michal.orzel@amd.com>
Subject: Re: [PATCH v2] core-parking: shrink core_parking_cpunum[]
Date: Tue, 10 Mar 2026 10:07:30 +0100	[thread overview]
Message-ID: <aa_fUpLqaPDal_-l@macbook.local> (raw)
In-Reply-To: <29922662-8b95-4a69-9401-11480df59cdf@suse.com>

You possibly want to adjust the subject, instead of shrink I would use
"dynamically allocate" or similar.

On Mon, Mar 09, 2026 at 04:35:34PM +0100, Jan Beulich wrote:
> This NR_CPUS-dimensioned array is likely unused on most installations.
> Therefore it is especially wasteful for it to consume more space than
> really needed. Allocate it dynamically ahead of registering the hooks.
> 
> Further the array having all fields set to -1 is actually useless. Nothing
> relies on it, and core_parking_remove() doesn't restore the sentinel for
> vacated slots. Drop the initializers altogether, rather than replacing
> them.
> 
> Also take the opportunity and update an adjacent variable's type, where
> a fixed-width type was pretty clearly inappropriate to use.
> 
> Finally drop the redundant initializer from core_parking_init().
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> ---
> I assume there is a reason this is acting (mostly) as a LIFO. Else a
> simple cpumask_t would suffice.
> 
> num_possible_cpus() would be the more correct thing to use as array
> dimension, yet we don't maintain cpu_possible_map on x86.
> ---
> v2: Use dynamic allocation.
> 
> --- a/xen/common/core_parking.c
> +++ b/xen/common/core_parking.c
> @@ -20,6 +20,7 @@
>  #include <xen/cpumask.h>
>  #include <xen/init.h>
>  #include <xen/param.h>
> +#include <xen/xvmalloc.h>
>  
>  #include <asm/smp.h>
>  
> @@ -27,8 +28,8 @@
>  #define CORE_PARKING_DECREMENT 2
>  
>  static DEFINE_SPINLOCK(accounting_lock);
> -static uint32_t cur_idle_nums;
> -static unsigned int core_parking_cpunum[NR_CPUS] = {[0 ... NR_CPUS-1] = -1};
> +static unsigned int cur_idle_nums;
> +static unsigned int *__ro_after_init core_parking_cpunum;

Don't you need some kind of check in core_parking_remove() to prevent a
NULL pointer dereference if core_parking_cpunum hasn't been allocated?

Callers of XEN_SYSCTL_cpu_hotplug can set fn = smt_up_down_helper, and
that would call core_parking_remove().  core_parking_helper() already
contains a check that prevents accessing core_parking_cpunum if no
policy has been registered.

Thanks, Roger.


  reply	other threads:[~2026-03-10  9:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-09 15:35 [PATCH v2] core-parking: shrink core_parking_cpunum[] Jan Beulich
2026-03-10  9:07 ` Roger Pau Monné [this message]
2026-03-10  9:20   ` Jan Beulich
2026-03-10  9:56     ` Roger Pau Monné
2026-03-11 14:10     ` Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aa_fUpLqaPDal_-l@macbook.local \
    --to=roger.pau@citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=anthony.perard@vates.tech \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=michal.orzel@amd.com \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.