All of lore.kernel.org
 help / color / mirror / Atom feed
From: Felix Kuehling <felix.kuehling@amd.com>
To: Mario Limonciello <superm1@kernel.org>,
	mario.limonciello@amd.com, alexander.deucher@amd.com,
	christian.koenig@amd.com, Xinhui.Pan@amd.com, airlied@gmail.com,
	simona@ffwll.ch
Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] drm/amd: Refactor find_system_memory()
Date: Tue, 4 Feb 2025 18:19:03 -0500	[thread overview]
Message-ID: <65b47db9-883b-46c6-919a-e84c3ffde401@amd.com> (raw)
In-Reply-To: <20250204222140.3883013-1-superm1@kernel.org>


On 2025-02-04 17:21, Mario Limonciello wrote:
> From: Mario Limonciello <mario.limonciello@amd.com>
> 
> find_system_memory() pulls out two fields from an SMBIOS type 17
> device and sets them on KFD devices. This however is pulling from
> the middle of the field in the SMBIOS device and leads to an unaligned
> access.
> 
> Instead use a struct representation to access the members and pull
> out the two specific fields.

Isn't that still an unaligned access? I don't understand the purpose of this patch.

One more comment inline.

> 
> Link: https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.8.0.pdf p99
> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
> ---
>  drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 27 +++++++++++------------
>  drivers/gpu/drm/amd/amdkfd/kfd_topology.h | 17 ++++++++++++++
>  2 files changed, 30 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
> index ceb9fb475ef13..93d3924dfcba0 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
> @@ -968,24 +968,23 @@ static void kfd_update_system_properties(void)
>  	up_read(&topology_lock);
>  }
>  
> -static void find_system_memory(const struct dmi_header *dm,
> -	void *private)
> +static void find_system_memory(const struct dmi_header *dm, void *private)
>  {
> +	struct dmi_mem_device *memdev = (struct dmi_mem_device *)(dm);

I think it would be cleaner to use container_of to get a pointer to the structure containing the header.

Regards,
  Felix

>  	struct kfd_mem_properties *mem;
> -	u16 mem_width, mem_clock;
>  	struct kfd_topology_device *kdev =
>  		(struct kfd_topology_device *)private;
> -	const u8 *dmi_data = (const u8 *)(dm + 1);
> -
> -	if (dm->type == DMI_ENTRY_MEM_DEVICE && dm->length >= 0x15) {
> -		mem_width = (u16)(*(const u16 *)(dmi_data + 0x6));
> -		mem_clock = (u16)(*(const u16 *)(dmi_data + 0x11));
> -		list_for_each_entry(mem, &kdev->mem_props, list) {
> -			if (mem_width != 0xFFFF && mem_width != 0)
> -				mem->width = mem_width;
> -			if (mem_clock != 0)
> -				mem->mem_clk_max = mem_clock;
> -		}
> +
> +	if (memdev->header.type != DMI_ENTRY_MEM_DEVICE)
> +		return;
> +	if (memdev->header.length < sizeof(struct dmi_mem_device))
> +		return;
> +
> +	list_for_each_entry(mem, &kdev->mem_props, list) {
> +		if (memdev->total_width != 0xFFFF && memdev->total_width != 0)
> +			mem->width = memdev->total_width;
> +		if (memdev->speed != 0)
> +			mem->mem_clk_max = memdev->speed;
>  	}
>  }
>  
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_topology.h b/drivers/gpu/drm/amd/amdkfd/kfd_topology.h
> index 155b5c410af16..f06c9db7ddde9 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_topology.h
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_topology.h
> @@ -24,6 +24,7 @@
>  #ifndef __KFD_TOPOLOGY_H__
>  #define __KFD_TOPOLOGY_H__
>  
> +#include <linux/dmi.h>
>  #include <linux/types.h>
>  #include <linux/list.h>
>  #include <linux/kfd_sysfs.h>
> @@ -179,6 +180,22 @@ struct kfd_system_properties {
>  	struct attribute	attr_props;
>  };
>  
> +struct dmi_mem_device {
> +	struct dmi_header header;
> +	u16 physical_handle;
> +	u16 error_handle;
> +	u16 total_width;
> +	u16 data_width;
> +	u16 size;
> +	u8 form_factor;
> +	u8 device_set;
> +	u8 device_locator;
> +	u8 bank_locator;
> +	u8 memory_type;
> +	u16 type_detail;
> +	u16 speed;
> +} __packed;
> +
>  struct kfd_topology_device *kfd_create_topology_device(
>  		struct list_head *device_list);
>  void kfd_release_topology_device_list(struct list_head *device_list);


  reply	other threads:[~2025-02-04 23:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-04 22:21 [PATCH] drm/amd: Refactor find_system_memory() Mario Limonciello
2025-02-04 23:19 ` Felix Kuehling [this message]
2025-02-05 19:31   ` Mario Limonciello
2025-02-05 20:33     ` Felix Kuehling
2025-02-05 20:36       ` Mario Limonciello
2025-02-05 20:43         ` Felix Kuehling
2025-02-05 20:46           ` Mario Limonciello

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=65b47db9-883b-46c6-919a-e84c3ffde401@amd.com \
    --to=felix.kuehling@amd.com \
    --cc=Xinhui.Pan@amd.com \
    --cc=airlied@gmail.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=mario.limonciello@amd.com \
    --cc=simona@ffwll.ch \
    --cc=superm1@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 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.