diff mbox series

[v6] driver core: platform: set numa_node before platform_device_add()

Message ID 20230918134527.252-1-guojinhui.liam@bytedance.com (mailing list archive)
State Changes Requested, archived
Headers show
Series [v6] driver core: platform: set numa_node before platform_device_add() | expand

Commit Message

Jinhui Guo Sept. 18, 2023, 1:45 p.m. UTC
Setting the devices' numa_node needs to be done in
platform_device_register_full(), because that's where the
platform device object is allocated.

Fixes: 4a60406d3592 ("driver core: platform: expose numa_node to users in sysfs")
Cc: stable@vger.kernel.org
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202309122309.mbxAnAIe-lkp@intel.com/
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Rafael J. Wysocki <rafael@kernel.org>
Signed-off-by: Jinhui Guo <guojinhui.liam@bytedance.com>
---
V5 -> V6:
  1. Update subject to correct function name platform_device_add().
  2. Provide a more clear and accurate description of the changes
     made in commit (suggested by Rafael J. Wysocki).
  3. Add reviewer name.

V4 -> V5:
  Add Cc: stable line and changes from the previous submited patches.

V3 -> V4:
  Refactor code to be an ACPI function call.

V2 -> V3:
  Fix Signed-off name.

V1 -> V2:
  Fix compile error without enabling CONFIG_ACPI.
---

 drivers/acpi/acpi_platform.c | 4 +---
 drivers/base/platform.c      | 1 +
 include/linux/acpi.h         | 5 +++++
 3 files changed, 7 insertions(+), 3 deletions(-)

Comments

Rafael J. Wysocki Sept. 18, 2023, 2:34 p.m. UTC | #1
On Mon, Sep 18, 2023 at 3:46 PM Jinhui Guo <guojinhui.liam@bytedance.com> wrote:
>
> Setting the devices' numa_node needs to be done in
> platform_device_register_full(), because that's where the
> platform device object is allocated.
>
> Fixes: 4a60406d3592 ("driver core: platform: expose numa_node to users in sysfs")
> Cc: stable@vger.kernel.org
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202309122309.mbxAnAIe-lkp@intel.com/
> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Reviewed-by: Rafael J. Wysocki <rafael@kernel.org>

No, I haven't given you this tag.

I don't think that Greg has given you the one above either.

Please don't add tage that you haven't received to your patches,
because they are not applicable with incorrect tags.

> Signed-off-by: Jinhui Guo <guojinhui.liam@bytedance.com>
> ---
> V5 -> V6:
>   1. Update subject to correct function name platform_device_add().
>   2. Provide a more clear and accurate description of the changes
>      made in commit (suggested by Rafael J. Wysocki).
>   3. Add reviewer name.
>
> V4 -> V5:
>   Add Cc: stable line and changes from the previous submited patches.
>
> V3 -> V4:
>   Refactor code to be an ACPI function call.
>
> V2 -> V3:
>   Fix Signed-off name.
>
> V1 -> V2:
>   Fix compile error without enabling CONFIG_ACPI.
> ---
>
>  drivers/acpi/acpi_platform.c | 4 +---
>  drivers/base/platform.c      | 1 +
>  include/linux/acpi.h         | 5 +++++
>  3 files changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/acpi/acpi_platform.c b/drivers/acpi/acpi_platform.c
> index 48d15dd785f6..adcbfbdc343f 100644
> --- a/drivers/acpi/acpi_platform.c
> +++ b/drivers/acpi/acpi_platform.c
> @@ -178,11 +178,9 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev,
>         if (IS_ERR(pdev))
>                 dev_err(&adev->dev, "platform device creation failed: %ld\n",
>                         PTR_ERR(pdev));
> -       else {
> -               set_dev_node(&pdev->dev, acpi_get_node(adev->handle));
> +       else
>                 dev_dbg(&adev->dev, "created platform device %s\n",
>                         dev_name(&pdev->dev));
> -       }
>
>         kfree(resources);
>
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index 76bfcba25003..35c891075d95 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -841,6 +841,7 @@ struct platform_device *platform_device_register_full(
>                         goto err;
>         }
>
> +       set_dev_node(&pdev->dev, ACPI_NODE_GET(ACPI_COMPANION(&pdev->dev)));
>         ret = platform_device_add(pdev);
>         if (ret) {
>  err:
> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
> index a73246c3c35e..6a349d53f19e 100644
> --- a/include/linux/acpi.h
> +++ b/include/linux/acpi.h
> @@ -477,6 +477,10 @@ static inline int acpi_get_node(acpi_handle handle)
>         return 0;
>  }
>  #endif
> +
> +#define ACPI_NODE_GET(adev) ((adev) && (adev)->handle ? \
> +       acpi_get_node((adev)->handle) : NUMA_NO_NODE)
> +
>  extern int pnpacpi_disabled;
>
>  #define PXM_INVAL      (-1)
> @@ -770,6 +774,7 @@ const char *acpi_get_subsystem_id(acpi_handle handle);
>  #define ACPI_COMPANION_SET(dev, adev)  do { } while (0)
>  #define ACPI_HANDLE(dev)               (NULL)
>  #define ACPI_HANDLE_FWNODE(fwnode)     (NULL)
> +#define ACPI_NODE_GET(adev)            NUMA_NO_NODE
>
>  #include <acpi/acpi_numa.h>
>
> --
> 2.20.1
>
Greg Kroah-Hartman Sept. 18, 2023, 3:17 p.m. UTC | #2
On Mon, Sep 18, 2023 at 09:45:27PM +0800, Jinhui Guo wrote:
> Setting the devices' numa_node needs to be done in
> platform_device_register_full(), because that's where the
> platform device object is allocated.
> 
> Fixes: 4a60406d3592 ("driver core: platform: expose numa_node to users in sysfs")
> Cc: stable@vger.kernel.org
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202309122309.mbxAnAIe-lkp@intel.com/
> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Where did I provide this tag?
Jinhui Guo Sept. 18, 2023, 3:25 p.m. UTC | #3
> On Mon, Sep 18, 2023 at 3:46 PM Jinhui Guo <guojinhui.liam@bytedance.com> wrote:
> >
> > Setting the devices' numa_node needs to be done in
> > platform_device_register_full(), because that's where the
> > platform device object is allocated.
> >
> > Fixes: 4a60406d3592 ("driver core: platform: expose numa_node to users in sysfs")
> > Cc: stable@vger.kernel.org
> > Reported-by: kernel test robot <lkp@intel.com>
> > Closes: https://lore.kernel.org/oe-kbuild-all/202309122309.mbxAnAIe-lkp@intel.com/
> > Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Reviewed-by: Rafael J. Wysocki <rafael@kernel.org>
> 
> No, I haven't given you this tag.
> 
> I don't think that Greg has given you the one above either.
> 
> Please don't add tage that you haven't received to your patches,
> because they are not applicable with incorrect tags.
>

I appologize to it. I just misunderstand what it means. I will drop it out soon.
 
> > Signed-off-by: Jinhui Guo <guojinhui.liam@bytedance.com>
> > ---
> > V5 -> V6:
> >   1. Update subject to correct function name platform_device_add().
> >   2. Provide a more clear and accurate description of the changes
> >      made in commit (suggested by Rafael J. Wysocki).
> >   3. Add reviewer name.
> >
> > V4 -> V5:
> >   Add Cc: stable line and changes from the previous submited patches.
> >
> > V3 -> V4:
> >   Refactor code to be an ACPI function call.
> >
> > V2 -> V3:
> >   Fix Signed-off name.
> >
> > V1 -> V2:
> >   Fix compile error without enabling CONFIG_ACPI.
> > ---
> >
> >  drivers/acpi/acpi_platform.c | 4 +---
> >  drivers/base/platform.c      | 1 +
> >  include/linux/acpi.h         | 5 +++++
> >  3 files changed, 7 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/acpi/acpi_platform.c b/drivers/acpi/acpi_platform.c
> > index 48d15dd785f6..adcbfbdc343f 100644
> > --- a/drivers/acpi/acpi_platform.c
> > +++ b/drivers/acpi/acpi_platform.c
> > @@ -178,11 +178,9 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev,
> >         if (IS_ERR(pdev))
> >                 dev_err(&adev->dev, "platform device creation failed: %ld\n",
> >                         PTR_ERR(pdev));
> > -       else {
> > -               set_dev_node(&pdev->dev, acpi_get_node(adev->handle));
> > +       else
> >                 dev_dbg(&adev->dev, "created platform device %s\n",
> >                         dev_name(&pdev->dev));
> > -       }
> >
> >         kfree(resources);
> >
> > diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> > index 76bfcba25003..35c891075d95 100644
> > --- a/drivers/base/platform.c
> > +++ b/drivers/base/platform.c
> > @@ -841,6 +841,7 @@ struct platform_device *platform_device_register_full(
> >                         goto err;
> >         }
> >
> > +       set_dev_node(&pdev->dev, ACPI_NODE_GET(ACPI_COMPANION(&pdev->dev)));
> >         ret = platform_device_add(pdev);
> >         if (ret) {
> >  err:
> > diff --git a/include/linux/acpi.h b/include/linux/acpi.h
> > index a73246c3c35e..6a349d53f19e 100644
> > --- a/include/linux/acpi.h
> > +++ b/include/linux/acpi.h
> > @@ -477,6 +477,10 @@ static inline int acpi_get_node(acpi_handle handle)
> >         return 0;
> >  }
> >  #endif
> > +
> > +#define ACPI_NODE_GET(adev) ((adev) && (adev)->handle ? \
> > +       acpi_get_node((adev)->handle) : NUMA_NO_NODE)
> > +
> >  extern int pnpacpi_disabled;
> >
> >  #define PXM_INVAL      (-1)
> > @@ -770,6 +774,7 @@ const char *acpi_get_subsystem_id(acpi_handle handle);
> >  #define ACPI_COMPANION_SET(dev, adev)  do { } while (0)
> >  #define ACPI_HANDLE(dev)               (NULL)
> >  #define ACPI_HANDLE_FWNODE(fwnode)     (NULL)
> > +#define ACPI_NODE_GET(adev)            NUMA_NO_NODE
> >
> >  #include <acpi/acpi_numa.h>
> >
> > --
> > 2.20.1
> >
Jinhui Guo Sept. 18, 2023, 3:29 p.m. UTC | #4
> On Mon, Sep 18, 2023 at 09:45:27PM +0800, Jinhui Guo wrote:
> > Setting the devices' numa_node needs to be done in
> > platform_device_register_full(), because that's where the
> > platform device object is allocated.
> > 
> > Fixes: 4a60406d3592 ("driver core: platform: expose numa_node to users in sysfs")
> > Cc: stable@vger.kernel.org
> > Reported-by: kernel test robot <lkp@intel.com>
> > Closes: https://lore.kernel.org/oe-kbuild-all/202309122309.mbxAnAIe-lkp@intel.com/
> > Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> 
> Where did I provide this tag?

I appologize to it. I just misunderstand what it means. I will drop it out soon.
Jinhui Guo Sept. 18, 2023, 3:44 p.m. UTC | #5
> On Mon, Sep 18, 2023 at 2:41 PM Jinhui Guo <guojinhui.liam@bytedance.com> wrote:
> >
> > On Mon, 18 Sep 2023 12:30:58 +0200, Rafael J. Wysocki wrote:
> > > On Thu, Sep 14, 2023 at 11:32 PM Jinhui Guo
> > > <guojinhui.liam@bytedance.com> wrote:
> > > >
> > > > platform_add_device()
> > >
> > > According to "git grep" this function is not present in 6.6-rc2.
> > >
> > > If you mean platform_device_add(), please update the patch subject and
> > > changelog accordingly.
> > >
> >
> > This is my mistake, the function name was written wrong.
> > I will fix it in the next patch.
> >
> > > > creates the numa_node attribute of sysfs according
> > > > to whether dev_to_node(dev) is equal to NUMA_NO_NODE. So set the numa node
> > > > of device before creating numa_node attribute of sysfs.
> > >
> > > It would be good to also say that this needs to be done in
> > > platform_device_register_full(), because that's where the platform
> > > device object is allocated.
> > >
> >
> > Thaks for your suggestion. I will modify my decription soon.
> >
> > > However, what about adding the NUMA node information to pdevinfo?  It
> > > would be more straightforward to handle it then AFAICS.
> > >
> >
> > I have tried three potential solutions to fix the bug:
> > 1. The first one is what the current patch do.
> >
> > 2. Add a new function interface only for acpi_create_platform_device() call.
> >    But the code will be a bit redundant.
> >
> > 3. Add an member "numa_node" in `struct platform_device_info`, just as what
> >    `struct device` done:
> >
> > ```
> > struct platform_device_info {
> >         ...;
> > #ifdef CONFIG_NUMA
> >         int             numa_node;
> > #endif
> > ```
> >
> > But not all the call to platform_device_register_full() would set numa_node,
> > and many of them use ` memset(&pdevinfo, 0, sizeof(pdevinfo));` to initialize
> > `struct platform_device_info`. It could initialize numa_node to zero and
> > result in wrong numa_node information in sysfs.
> 
> Well, platform_device_register_full() need not take that value as the
> numa node number directly.  It may, for example, take the number from
> pdevinfo, subtract 1 from it and use the result of that as the numa
> node number, if not negative.

It's a good idea. I will try to fix the bug in this way.

Thanks,

Jinhui Guo
diff mbox series

Patch

diff --git a/drivers/acpi/acpi_platform.c b/drivers/acpi/acpi_platform.c
index 48d15dd785f6..adcbfbdc343f 100644
--- a/drivers/acpi/acpi_platform.c
+++ b/drivers/acpi/acpi_platform.c
@@ -178,11 +178,9 @@  struct platform_device *acpi_create_platform_device(struct acpi_device *adev,
 	if (IS_ERR(pdev))
 		dev_err(&adev->dev, "platform device creation failed: %ld\n",
 			PTR_ERR(pdev));
-	else {
-		set_dev_node(&pdev->dev, acpi_get_node(adev->handle));
+	else
 		dev_dbg(&adev->dev, "created platform device %s\n",
 			dev_name(&pdev->dev));
-	}
 
 	kfree(resources);
 
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 76bfcba25003..35c891075d95 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -841,6 +841,7 @@  struct platform_device *platform_device_register_full(
 			goto err;
 	}
 
+	set_dev_node(&pdev->dev, ACPI_NODE_GET(ACPI_COMPANION(&pdev->dev)));
 	ret = platform_device_add(pdev);
 	if (ret) {
 err:
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index a73246c3c35e..6a349d53f19e 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -477,6 +477,10 @@  static inline int acpi_get_node(acpi_handle handle)
 	return 0;
 }
 #endif
+
+#define ACPI_NODE_GET(adev) ((adev) && (adev)->handle ? \
+	acpi_get_node((adev)->handle) : NUMA_NO_NODE)
+
 extern int pnpacpi_disabled;
 
 #define PXM_INVAL	(-1)
@@ -770,6 +774,7 @@  const char *acpi_get_subsystem_id(acpi_handle handle);
 #define ACPI_COMPANION_SET(dev, adev)	do { } while (0)
 #define ACPI_HANDLE(dev)		(NULL)
 #define ACPI_HANDLE_FWNODE(fwnode)	(NULL)
+#define ACPI_NODE_GET(adev)		NUMA_NO_NODE
 
 #include <acpi/acpi_numa.h>