Linux-PM Archive mirror
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rafael@kernel.org>
To: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
	linuxarm@huawei.com, linux-pm@vger.kernel.org,
	 loongarch@lists.linux.dev, linux-acpi@vger.kernel.org,
	 linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org,
	 linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
	x86@kernel.org,  Russell King <linux@armlinux.org.uk>,
	Miguel Luis <miguel.luis@oracle.com>,
	 James Morse <james.morse@arm.com>,
	Salil Mehta <salil.mehta@huawei.com>,
	 Jean-Philippe Brucker <jean-philippe@linaro.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	 Will Deacon <will@kernel.org>,
	justin.he@arm.com, jianyong.wu@arm.com
Subject: Re: [PATCH v5 02/18] ACPI: processor: Set the ACPI_COMPANION for the struct cpu instance
Date: Mon, 15 Apr 2024 19:41:43 +0200	[thread overview]
Message-ID: <CAJZ5v0huAAa5UpK4kqR-Uz4ALfY-wQ-gv7CC8C-kx9UDFvCgUw@mail.gmail.com> (raw)
In-Reply-To: <20240415183454.000072f6@Huawei.com>

On Mon, Apr 15, 2024 at 7:35 PM Jonathan Cameron
<Jonathan.Cameron@huawei.com> wrote:
>
> On Mon, 15 Apr 2024 17:50:57 +0100
> Jonathan Cameron <Jonathan.Cameron@Huawei.com> wrote:
>
> > On Mon, 15 Apr 2024 18:19:17 +0200
> > "Rafael J. Wysocki" <rafael@kernel.org> wrote:
> >
> > > On Mon, Apr 15, 2024 at 6:16 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
> > > >
> > > > On Mon, Apr 15, 2024 at 5:49 PM Jonathan Cameron
> > > > <Jonathan.Cameron@huawei.com> wrote:
> > > > >
> > > > > On Fri, 12 Apr 2024 20:10:54 +0200
> > > > > "Rafael J. Wysocki" <rafael@kernel.org> wrote:
> > > > >
> > > > > > On Fri, Apr 12, 2024 at 4:38 PM Jonathan Cameron
> > > > > > <Jonathan.Cameron@huawei.com> wrote:
> > > > > > >
> > > > > > > The arm64 specific arch_register_cpu() needs to access the _STA
> > > > > > > method of the DSDT object so make it available by assigning the
> > > > > > > appropriate handle to the struct cpu instance.
> > > > > > >
> > > > > > > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > > > > > > ---
> > > > > > >  drivers/acpi/acpi_processor.c | 3 +++
> > > > > > >  1 file changed, 3 insertions(+)
> > > > > > >
> > > > > > > diff --git a/drivers/acpi/acpi_processor.c b/drivers/acpi/acpi_processor.c
> > > > > > > index 7a0dd35d62c9..93e029403d05 100644
> > > > > > > --- a/drivers/acpi/acpi_processor.c
> > > > > > > +++ b/drivers/acpi/acpi_processor.c
> > > > > > > @@ -235,6 +235,7 @@ static int acpi_processor_get_info(struct acpi_device *device)
> > > > > > >         union acpi_object object = { 0 };
> > > > > > >         struct acpi_buffer buffer = { sizeof(union acpi_object), &object };
> > > > > > >         struct acpi_processor *pr = acpi_driver_data(device);
> > > > > > > +       struct cpu *c;
> > > > > > >         int device_declaration = 0;
> > > > > > >         acpi_status status = AE_OK;
> > > > > > >         static int cpu0_initialized;
> > > > > > > @@ -314,6 +315,8 @@ static int acpi_processor_get_info(struct acpi_device *device)
> > > > > > >                         cpufreq_add_device("acpi-cpufreq");
> > > > > > >         }
> > > > > > >
> > > > > > > +       c = &per_cpu(cpu_devices, pr->id);
> > > > > > > +       ACPI_COMPANION_SET(&c->dev, device);
> > > > > >
> > > > > > This is also set for per_cpu(cpu_sys_devices, pr->id) in
> > > > > > acpi_processor_add(), via acpi_bind_one().
> > > > >
> > > > > Hi Rafael,
> > > > >
> > > > > cpu_sys_devices gets filled with a pointer to this same structure.
> > > > > The contents gets set in register_cpu() so at this point
> > > > > it doesn't point anywhere.  As a side note register_cpu()
> > > > > memsets to zero the value I set it to in the code above which isn't
> > > > > great, particularly as I want to use this in post_eject for
> > > > > arm64.
> > > > >
> > > > > We could make a copy of the handle and put it back after
> > > > > the memset in register_cpu() but that is also ugly.
> > > > > It's the best I've come up with to make sure this is still set
> > > > > come remove time but is rather odd.
> > > > > >
> > > > > > Moreover, there is some pr->id validation in acpi_processor_add(), so
> > > > > > it seems premature to use it here this way.
> > > > > >
> > > > > > I think that ACPI_COMPANION_SET() should be called from here on
> > > > > > per_cpu(cpu_sys_devices, pr->id) after validating pr->id (so the
> > > > > > pr->id validation should all be done here) and then NULL can be passed
> > > > > > as acpi_dev to acpi_bind_one() in acpi_processor_add().  Then, there
> > > > > > will be one physical device corresponding to the processor ACPI device
> > > > > > and no confusion.
> > > > >
> > > > > I'm fairly sure this is pointing to the same device but agreed this
> > > > > is a tiny bit confusing. However we can't use cpu_sys_devices at this point
> > > > > so I'm not immediately seeing a cleaner solution :(
> > > >
> > > > Well, OK.
> > > >
> > > > Please at least consider doing the pr->id validation checks before
> > > > setting the ACPI companion for &per_cpu(cpu_devices, pr->id).
> > > >
> > > > Also, acpi_bind_one() needs to be called on the "physical" devices
> > > > passed to ACPI_COMPANION_SET() (with NULL as the second argument) for
> > > > the reference counting and physical device lookup to work.
> > > >
> > > > Please also note that acpi_primary_dev_companion() should return
> > > > per_cpu(cpu_sys_devices, pr->id) for the processor ACPI device, which
> > > > depends on the order of acpi_bind_one() calls involving the same ACPI
> > > > device.
> > >
> > > Of course, if the value set by ACPI_COMPANION_SET() is cleared
> > > subsequently, the above is not needed, but then using
> > > ACPI_COMPANION_SET() is questionable overall.
> >
> > Agreed + smoothing over that by stashing and putting it back doesn't
> > work because there is an additional call to acpi_bind_one() inbetween
> > here and the one you reference.
> >
> > The arch_register_cpu() calls end up calling register_cpu() /
> > device_register() / acpi_device_notify() / acpi_bind_one()
> >
> > With current code that fails (silently)

And that's why there is an explicit acpi_bind_one() invocation in
acpi_processor_add().

> > If I make sure the handle is set before register_cpu() then it
> > succeeds, but we end up with duplicate sysfs files etc because we
> > bind twice.

Right, I should have recalled that earlier.

> > I think the only way around this is larger reorganization of the
> > CPU hotplug code to pull the arch_register_cpu() call to where
> > the acpi_bind_one() call is.  However that changes a lot more than I'd like
> > (and I don't have it working yet).

I see.

> > Alternatively find somewhere else to stash the handle, or just add it as
> > a parameter to arch_register_cpu(). Right now this feels the easier
> > path to me. arch_register_cpu(int cpu, acpi_handle handle)
> >
> > Would that be a path you'd consider?
>
> Another option would be to do the per_cpu(processors, pr->id) = pr
> a few lines earlier than currently and access that directly from the
> arch_register_cpu() call.  Similarly remove that reference a bit later and
> use it in arch_unregister_cpu().
>
> This seems like the simplest solution, but I may be missing something.

This should work AFAICS, but I'd move the entire piece of code between
BUG_ON() and setting per_cpu(processors, pr->id) inclusive:

    BUG_ON(pr->id >= nr_cpu_ids);

    /*
     * Buggy BIOS check.
     * ACPI id of processors can be reported wrongly by the BIOS.
     * Don't trust it blindly
     */
    if (per_cpu(processor_device_array, pr->id) != NULL &&
        per_cpu(processor_device_array, pr->id) != device) {
        dev_warn(&device->dev,
            "BIOS reported wrong ACPI id %d for the processor\n",
            pr->id);
        /* Give up, but do not abort the namespace scan. */
        goto err;
    }
    /*
     * processor_device_array is not cleared on errors to allow buggy BIOS
     * checks.
     */
    per_cpu(processor_device_array, pr->id) = device;
    per_cpu(processors, pr->id) = pr;

into acpi_processor_get_info(), right after the point where pr->id is set.

  reply	other threads:[~2024-04-15 17:41 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-12 14:37 [PATCH v5 00/18] ACPI/arm64: add support for virtual cpu hotplug Jonathan Cameron
2024-04-12 14:37 ` [PATCH v5 01/18] cpu: Do not warn on arch_register_cpu() returning -EPROBE_DEFER Jonathan Cameron
2024-04-12 17:42   ` Rafael J. Wysocki
2024-04-22  3:53   ` Gavin Shan
2024-04-12 14:37 ` [PATCH v5 02/18] ACPI: processor: Set the ACPI_COMPANION for the struct cpu instance Jonathan Cameron
2024-04-12 18:10   ` Rafael J. Wysocki
2024-04-15 15:48     ` Jonathan Cameron
2024-04-15 16:16       ` Rafael J. Wysocki
2024-04-15 16:19         ` Rafael J. Wysocki
2024-04-15 16:50           ` Jonathan Cameron
2024-04-15 17:34             ` Jonathan Cameron
2024-04-15 17:41               ` Rafael J. Wysocki [this message]
2024-04-16 17:35                 ` Jonathan Cameron
2024-04-12 14:37 ` [PATCH v5 03/18] ACPI: processor: Register deferred CPUs from acpi_processor_get_info() Jonathan Cameron
2024-04-12 18:30   ` Rafael J. Wysocki
2024-04-12 20:16     ` Russell King (Oracle)
2024-04-12 20:54       ` Thomas Gleixner
2024-04-12 21:52         ` Russell King (Oracle)
2024-04-12 23:23           ` Thomas Gleixner
2024-04-15  8:45             ` Jonathan Cameron
2024-04-15  9:16               ` Jonathan Cameron
2024-04-15  9:31                 ` Jonathan Cameron
2024-04-15 11:57                 ` Jonathan Cameron
2024-04-15 11:37               ` Rafael J. Wysocki
2024-04-15 11:56                 ` Jonathan Cameron
2024-04-15 12:04                   ` Rafael J. Wysocki
2024-04-15 12:23                     ` Jonathan Cameron
2024-04-16 17:41                       ` Jonathan Cameron
2024-04-16 19:02                         ` Rafael J. Wysocki
2024-04-17 10:39                           ` Jonathan Cameron
2024-04-15 12:37                     ` Salil Mehta
2024-04-15 12:41                       ` Rafael J. Wysocki
2024-04-15 11:51         ` Salil Mehta
2024-04-15 12:51           ` Rafael J. Wysocki
2024-04-15 15:31             ` Salil Mehta
2024-04-15 16:38               ` Rafael J. Wysocki
2024-04-17 15:01                 ` Salil Mehta
2024-04-17 16:19                   ` Rafael J. Wysocki
2024-04-15 10:52     ` Jonathan Cameron
2024-04-15 11:11       ` Jonathan Cameron
2024-04-15 11:52       ` Rafael J. Wysocki
2024-04-15 11:07     ` Salil Mehta
2024-04-16 14:00   ` Jonathan Cameron
2024-04-12 14:37 ` [PATCH v5 04/18] ACPI: Rename acpi_processor_hotadd_init and remove pre-processor guards Jonathan Cameron
2024-04-12 14:37 ` [PATCH v5 05/18] ACPI: utils: Add an acpi_sta_enabled() helper and use it in acpi_processor_make_present() Jonathan Cameron
2024-04-12 14:37 ` [PATCH v5 06/18] ACPI: scan: Add parameter to allow defering some actions in acpi_scan_check_and_detach Jonathan Cameron
2024-04-12 14:37 ` [PATCH v5 07/18] ACPI: Add post_eject to struct acpi_scan_handler for cpu hotplug Jonathan Cameron
2024-04-12 14:37 ` [PATCH v5 08/18] ACPI: convert acpi_processor_post_eject() to use IS_ENABLED() Jonathan Cameron
2024-04-12 14:37 ` [PATCH v5 09/18] ACPI: Check _STA present bit before making CPUs not present Jonathan Cameron
2024-04-12 14:37 ` [PATCH v5 10/18] ACPI: Warn when the present bit changes but the feature is not enabled Jonathan Cameron
2024-04-12 14:37 ` [PATCH v5 11/18] arm64: acpi: Move get_cpu_for_acpi_id() to a header Jonathan Cameron
2024-04-12 14:37 ` [PATCH v5 12/18] irqchip/gic-v3: Don't return errors from gic_acpi_match_gicc() Jonathan Cameron
2024-04-12 14:37 ` [PATCH v5 13/18] irqchip/gic-v3: Add support for ACPI's disabled but 'online capable' CPUs Jonathan Cameron
2024-04-12 14:37 ` [PATCH v5 14/18] arm64: psci: Ignore DENIED CPUs Jonathan Cameron
2024-04-12 14:37 ` [PATCH v5 15/18] arm64: arch_register_cpu() variant to allow checking of ACPI _STA Jonathan Cameron
2024-04-12 14:37 ` [PATCH v5 16/18] ACPI: add support to (un)register CPUs based on the _STA enabled bit Jonathan Cameron
2024-04-12 14:37 ` [PATCH v5 17/18] arm64: document virtual CPU hotplug's expectations Jonathan Cameron
2024-04-12 14:37 ` [PATCH v5 18/18] cpumask: Add enabled cpumask for present CPUs that can be brought online Jonathan Cameron

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=CAJZ5v0huAAa5UpK4kqR-Uz4ALfY-wQ-gv7CC8C-kx9UDFvCgUw@mail.gmail.com \
    --to=rafael@kernel.org \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=catalin.marinas@arm.com \
    --cc=james.morse@arm.com \
    --cc=jean-philippe@linaro.org \
    --cc=jianyong.wu@arm.com \
    --cc=justin.he@arm.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=linuxarm@huawei.com \
    --cc=loongarch@lists.linux.dev \
    --cc=miguel.luis@oracle.com \
    --cc=salil.mehta@huawei.com \
    --cc=will@kernel.org \
    --cc=x86@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).