[PATCH v2 0/7] AMD HSMP: metrics table improvements and Family 1Ah Model 50h-5Fh support

Muralidhara M K posted 7 patches 1 month, 2 weeks ago
arch/x86/include/uapi/asm/amd_hsmp.h | 235 ++++++++++++++++++++++++---
drivers/platform/x86/amd/hsmp/acpi.c |  14 +-
drivers/platform/x86/amd/hsmp/hsmp.c |  36 ++--
drivers/platform/x86/amd/hsmp/hsmp.h |   6 +-
drivers/platform/x86/amd/hsmp/plat.c |  13 +-
fs/sysfs/file.c                      |  45 +++++
fs/sysfs/group.c                     |   8 +-
include/linux/sysfs.h                |   1 +
8 files changed, 312 insertions(+), 46 deletions(-)
[PATCH v2 0/7] AMD HSMP: metrics table improvements and Family 1Ah Model 50h-5Fh support
Posted by Muralidhara M K 1 month, 2 weeks ago
This series adds HSMP protocol version 7 support for AMD Family 1Ah
Model 50h-5Fh processors and replaces offset-based chunked reading
with a single read method for variable-sized metrics data larger than
4 KB, and addresses locking to allow concurrent reads safely.

The zen6 metric table (~13 KB) exceeds the PAGE_SIZE (4096 bytes) read
cap imposed by kernfs_file_read_iter().  Commit 3124eb1679b2 ("sysfs:
remove bin_attribute.size") cleared i_size for sysfs binary files,
which made kernfs_file_read_iter() fall back to PAGE_SIZE as the
maximum single-read length.  This means userspace gets a silently
truncated snapshot when reading the metric table via sysfs.

To solve this, the series introduces SYSFS_HUGE_BIN_FILE, a new sysfs
mode flag that routes binary attribute reads through the seq_file path
(seq_read_iter) instead of kernfs_file_read_iter().  The seq_file
buffer grows dynamically (doubling from PAGE_SIZE) and has no built-in
size cap, so it can serve arbitrarily large binary attributes in a
single read.

Additionally, the series retrieves the actual metric table size from
the SMU at init time (via args[2] of HSMP_GET_METRIC_TABLE_DRAM_ADDR)
rather than relying on a compiled-in sizeof(), and adds per-socket
mutex serialization for metric table reads using the scoped guard(mutex)
API.

Link: https://lore.kernel.org/platform-driver-x86/81915669-87e0-f06d-7a91-eaec41ecc0e1@linux.intel.com/T/#m28341c51bcf27862ef6615414b1970d3db279fd7

Patch breakdown:

  1/7  HSMP messages    - Define HSMP protocol v7 message IDs and
                          response sizes in the UAPI header.
  2/7  UAPI structs     - Add hsmp_metric_table_zen6 UAPI structures
                          and widen acpi.c proto_ver checks to >= VER6.
  3/7  response_sz      - Unify response_sz validation to an upper-bound
                          check, allowing HSMP_GET_METRIC_TABLE_DRAM_ADDR
                          to return 3 dwords (including table size).
  4/7  SYSFS_HUGE_BIN_FILE - Add the sysfs infrastructure: new flag,
                          seq_show callback, and kernfs_ops for binary
                          files larger than PAGE_SIZE.
  5/7  Dynamic size     - Read actual table size from SMU args[2] at
                          init time; use bin_size callback to report it
                          to sysfs.
  6/7  Read locking     - Add per-socket guard(mutex) serialization for
                          metric table reads to prevent torn snapshots.
  7/7  Wire it up       - Set SYSFS_HUGE_BIN_FILE mode on metric table
                          bin_attributes in both acpi.c and plat.c.

Build-tested each patch individually with W=1, zero warnings.
Tested on AMD Family 1Ah Model 50h platform with HSMP protocol v7.

Muralidhara M K (6):
  platform/x86/amd/hsmp: Add metrics table support for Family 1Ah Model
    50h-5Fh
  platform/x86/amd/hsmp: Unify response_sz validation to an upper-bound
    check
  sysfs: Add SYSFS_HUGE_BIN_FILE flag for binary attributes larger than
    PAGE_SIZE
  platform/x86/amd/hsmp: Add dynamic table size for metric table
  platform/x86/amd/hsmp: Make metric table read locking use guard(mutex)
  platform/x86/amd/hsmp: Support SYSFS_HUGE_BIN_FILE for metric table
    reads

Suma Hegde (1):
  platform/x86/amd/hsmp: Add new HSMP messages for Family 1Ah, Model
    50h-5Fh

 arch/x86/include/uapi/asm/amd_hsmp.h | 235 ++++++++++++++++++++++++---
 drivers/platform/x86/amd/hsmp/acpi.c |  14 +-
 drivers/platform/x86/amd/hsmp/hsmp.c |  36 ++--
 drivers/platform/x86/amd/hsmp/hsmp.h |   6 +-
 drivers/platform/x86/amd/hsmp/plat.c |  13 +-
 fs/sysfs/file.c                      |  45 +++++
 fs/sysfs/group.c                     |   8 +-
 include/linux/sysfs.h                |   1 +
 8 files changed, 312 insertions(+), 46 deletions(-)

-- 
2.34.1
Re: [PATCH v2 0/7] AMD HSMP: metrics table improvements and Family 1Ah Model 50h-5Fh support
Posted by M K, Muralidhara 1 month ago
Hi ilpo,

I submitted this patch series and wanted to check if you had
a chance to review it. Please let me know if there's anything I can
do to help move this forward.


On 4/27/2026 9:21 PM, Muralidhara M K wrote:
> This series adds HSMP protocol version 7 support for AMD Family 1Ah
> Model 50h-5Fh processors and replaces offset-based chunked reading
> with a single read method for variable-sized metrics data larger than
> 4 KB, and addresses locking to allow concurrent reads safely.
> 
> The zen6 metric table (~13 KB) exceeds the PAGE_SIZE (4096 bytes) read
> cap imposed by kernfs_file_read_iter().  Commit 3124eb1679b2 ("sysfs:
> remove bin_attribute.size") cleared i_size for sysfs binary files,
> which made kernfs_file_read_iter() fall back to PAGE_SIZE as the
> maximum single-read length.  This means userspace gets a silently
> truncated snapshot when reading the metric table via sysfs.
> 
> To solve this, the series introduces SYSFS_HUGE_BIN_FILE, a new sysfs
> mode flag that routes binary attribute reads through the seq_file path
> (seq_read_iter) instead of kernfs_file_read_iter().  The seq_file
> buffer grows dynamically (doubling from PAGE_SIZE) and has no built-in
> size cap, so it can serve arbitrarily large binary attributes in a
> single read.
> 
> Additionally, the series retrieves the actual metric table size from
> the SMU at init time (via args[2] of HSMP_GET_METRIC_TABLE_DRAM_ADDR)
> rather than relying on a compiled-in sizeof(), and adds per-socket
> mutex serialization for metric table reads using the scoped guard(mutex)
> API.
> 
> Link: https://lore.kernel.org/platform-driver-x86/81915669-87e0-f06d-7a91-eaec41ecc0e1@linux.intel.com/T/#m28341c51bcf27862ef6615414b1970d3db279fd7
> 
> Patch breakdown:
> 
>    1/7  HSMP messages    - Define HSMP protocol v7 message IDs and
>                            response sizes in the UAPI header.
>    2/7  UAPI structs     - Add hsmp_metric_table_zen6 UAPI structures
>                            and widen acpi.c proto_ver checks to >= VER6.
>    3/7  response_sz      - Unify response_sz validation to an upper-bound
>                            check, allowing HSMP_GET_METRIC_TABLE_DRAM_ADDR
>                            to return 3 dwords (including table size).
>    4/7  SYSFS_HUGE_BIN_FILE - Add the sysfs infrastructure: new flag,
>                            seq_show callback, and kernfs_ops for binary
>                            files larger than PAGE_SIZE.
>    5/7  Dynamic size     - Read actual table size from SMU args[2] at
>                            init time; use bin_size callback to report it
>                            to sysfs.
>    6/7  Read locking     - Add per-socket guard(mutex) serialization for
>                            metric table reads to prevent torn snapshots.
>    7/7  Wire it up       - Set SYSFS_HUGE_BIN_FILE mode on metric table
>                            bin_attributes in both acpi.c and plat.c.
> 
> Build-tested each patch individually with W=1, zero warnings.
> Tested on AMD Family 1Ah Model 50h platform with HSMP protocol v7.
> 
> Muralidhara M K (6):
>    platform/x86/amd/hsmp: Add metrics table support for Family 1Ah Model
>      50h-5Fh
>    platform/x86/amd/hsmp: Unify response_sz validation to an upper-bound
>      check
>    sysfs: Add SYSFS_HUGE_BIN_FILE flag for binary attributes larger than
>      PAGE_SIZE
>    platform/x86/amd/hsmp: Add dynamic table size for metric table
>    platform/x86/amd/hsmp: Make metric table read locking use guard(mutex)
>    platform/x86/amd/hsmp: Support SYSFS_HUGE_BIN_FILE for metric table
>      reads
> 
> Suma Hegde (1):
>    platform/x86/amd/hsmp: Add new HSMP messages for Family 1Ah, Model
>      50h-5Fh
> 
>   arch/x86/include/uapi/asm/amd_hsmp.h | 235 ++++++++++++++++++++++++---
>   drivers/platform/x86/amd/hsmp/acpi.c |  14 +-
>   drivers/platform/x86/amd/hsmp/hsmp.c |  36 ++--
>   drivers/platform/x86/amd/hsmp/hsmp.h |   6 +-
>   drivers/platform/x86/amd/hsmp/plat.c |  13 +-
>   fs/sysfs/file.c                      |  45 +++++
>   fs/sysfs/group.c                     |   8 +-
>   include/linux/sysfs.h                |   1 +
>   8 files changed, 312 insertions(+), 46 deletions(-)
>