lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJZ5v0j6gMaHamrCvrF8s+SgC0QVtG+naXhA4Dwg0t1YJvh4Uw@mail.gmail.com>
Date: Mon, 15 Apr 2024 18:19:17 +0200
From: "Rafael J. Wysocki" <rafael@...nel.org>
To: Jonathan Cameron <jonathan.cameron@...wei.com>
Cc: "Rafael J. Wysocki" <rafael@...nel.org>, linux-pm@...r.kernel.org, loongarch@...ts.linux.dev, 
	linux-acpi@...r.kernel.org, linux-arch@...r.kernel.org, 
	linux-kernel@...r.kernel.org, linux-arm-kernel@...ts.infradead.org, 
	kvmarm@...ts.linux.dev, x86@...nel.org, Russell King <linux@...linux.org.uk>, 
	Miguel Luis <miguel.luis@...cle.com>, James Morse <james.morse@....com>, 
	Salil Mehta <salil.mehta@...wei.com>, Jean-Philippe Brucker <jean-philippe@...aro.org>, 
	Catalin Marinas <catalin.marinas@....com>, Will Deacon <will@...nel.org>, linuxarm@...wei.com, 
	justin.he@....com, jianyong.wu@....com
Subject: Re: [PATCH v5 02/18] ACPI: processor: Set the ACPI_COMPANION for the
 struct cpu instance

On Mon, Apr 15, 2024 at 6:16 PM Rafael J. Wysocki <rafael@...nel.org> wrote:
>
> On Mon, Apr 15, 2024 at 5:49 PM Jonathan Cameron
> <Jonathan.Cameron@...wei.com> wrote:
> >
> > On Fri, 12 Apr 2024 20:10:54 +0200
> > "Rafael J. Wysocki" <rafael@...nel.org> wrote:
> >
> > > On Fri, Apr 12, 2024 at 4:38 PM Jonathan Cameron
> > > <Jonathan.Cameron@...wei.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@...wei.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.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ