The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: K Prateek Nayak <kprateek.nayak@amd.com>
To: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"Muralidhara M K" <muralidhara.mk@amd.com>,
	"Danilo Krummrich" <dakr@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	<platform-driver-x86@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	<driver-core@lists.linux.dev>
Subject: Re: [PATCH v2 4/7] sysfs: Add SYSFS_HUGE_BIN_FILE flag for binary attributes larger than PAGE_SIZE
Date: Wed, 13 May 2026 09:29:19 +0530	[thread overview]
Message-ID: <f1d24d38-0d26-4aa1-abdd-b663fb7d8feb@amd.com> (raw)
In-Reply-To: <c288b106-b8fb-bd4c-fd47-062cd03cd337@linux.intel.com>

Hello Ilpo,

On 5/12/2026 5:14 PM, Ilpo Järvinen wrote:
>> Historically, sysfs read buffers were allocated with get_zeroed_page(),
>> limiting reads to PAGE_SIZE.  Commit 13c589d5b0ac ("sysfs: use seq_file
>> when reading regular files") transitioned regular (text) attribute reads
>> to seq_file, which can dynamically grow buffers beyond PAGE_SIZE.
> 
> 
>> However, the PAGE_SIZE limit was intentionally preserved for
>> compatibility. When binary attribute handling was later unified into
>> the same codebase, the non-seq_file read path (kernfs_file_read_iter)
>> retained this PAGE_SIZE cap for binary files as well.
> 
> I tried to investigate these claims but with the lack of references,
> I didn't get very far. At least the thread where 13c589d5b0ac came from 
> didn't seem to clearly say the things claimed here (assuming I managed 
> to find all its emails from the archives).

For most part I looked at the code that existed at the time of
13c589d5b0ac and now.

Prior to that commit fill_read_buffer() was the read function which used
get_zeroed_page() for buffering. This is also the reason we have these
defensive bits in the current sysfs_kf_seq_show():

    if (count >= (ssize_t)PAGE_SIZE) {
        ...
        /* Try to struggle along */
        count = PAGE_SIZE - 1;
    }

Also see commit 815d2d50da41 ("driver core: debug for bad
dev_attr_show() return value.") which added that printk() for debugging
the violator of PAGE_SIZE constraints back in the days.

Once sysfs had a seq_file path, the seq_file side handled buffering and
it would do so by calling ->read() in a loop while increasing the
seq_iter buffer size by a scale of 2 each time the content wouldn't fit
in the given buffer.

This is also the reason we have a:

    count = seq_get_buf(sf, &buf);
    if (count < PAGE_SIZE) {
        seq_commit(sf, -1);
        return 0;
    }

which ensures we have a buffer worth PAGE_SIZE before calling the read
function, else, we spoof a overflow and let seq_file bits give us a
bigger buffer when we try to read.

* All snippets are from sysfs_kf_seq_show() in fs/sysfs/file.c

> 
>> Drivers that expose binary attributes larger than PAGE_SIZE — such as
>> the AMD HSMP metric table (~13 KB) — cannot deliver the full content
>> in a single read() call through the existing path.
>>
>> Introduce a new opt-in flag SYSFS_HUGE_BIN_FILE (040000)
> 
>> that drivers can OR into their bin_attribute mode.
> 
> Simplify to:
> 
> for bin_attribute mode.
> 
> ?

Ack!

> 
>> When set, sysfs selects a new
>> kernfs_ops (sysfs_bin_kfops_huge_file_ro) whose .seq_show callback
>> pipes the bin_attribute ->read() result through seq_file, allowing
>> reads of arbitrary size in one shot.  Existing binary attributes
>> without the flag continue using the legacy capped path.
> 
> I suggest you avoid using "legacy" as a term for anything that is in use 
> in any way or still exists. I've seen people to jump on that particular 
> word enough times, it can sidetrack discussions.

Sorry about that! We'll just refer to it as the default / current
behavior henceforth.

Thanks a ton for taking a look at the series! Much appreciated.

-- 
Thanks and Regards,
Prateek


  reply	other threads:[~2026-05-13  3:59 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260427155129.545327-1-muralidhara.mk@amd.com>
     [not found] ` <20260427155129.545327-3-muralidhara.mk@amd.com>
2026-05-08  5:12   ` [PATCH v2 2/7] platform/x86/amd/hsmp: Add metrics table support for Family 1Ah Model 50h-5Fh Suma Hegde
2026-05-11 17:38   ` Ilpo Järvinen
2026-05-12  6:24     ` M K, Muralidhara
     [not found] ` <20260427155129.545327-4-muralidhara.mk@amd.com>
2026-05-08  5:13   ` [PATCH v2 3/7] platform/x86/amd/hsmp: Unify response_sz validation to an upper-bound check Suma Hegde
2026-05-11 11:20 ` [PATCH v2 0/7] AMD HSMP: metrics table improvements and Family 1Ah Model 50h-5Fh support M K, Muralidhara
     [not found] ` <20260427155129.545327-7-muralidhara.mk@amd.com>
2026-05-11 17:27   ` [PATCH v2 6/7] platform/x86/amd/hsmp: Make metric table read locking use guard(mutex) Ilpo Järvinen
2026-05-12  6:26     ` M K, Muralidhara
     [not found] ` <20260427155129.545327-2-muralidhara.mk@amd.com>
2026-05-11 17:35   ` [PATCH v2 1/7] platform/x86/amd/hsmp: Add new HSMP messages for Family 1Ah, Model 50h-5Fh Ilpo Järvinen
2026-05-12  6:21     ` M K, Muralidhara
     [not found] ` <20260427155129.545327-5-muralidhara.mk@amd.com>
2026-05-12  6:28   ` [PATCH v2 4/7] sysfs: Add SYSFS_HUGE_BIN_FILE flag for binary attributes larger than PAGE_SIZE M K, Muralidhara
2026-05-12 11:44   ` Ilpo Järvinen
2026-05-13  3:59     ` K Prateek Nayak [this message]
2026-05-12 12:01   ` Greg KH
2026-05-13  4:13     ` K Prateek Nayak
2026-05-13  6:24       ` Greg KH
2026-05-13  6:36         ` K Prateek Nayak
2026-05-13  7:18           ` Greg KH

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=f1d24d38-0d26-4aa1-abdd-b663fb7d8feb@amd.com \
    --to=kprateek.nayak@amd.com \
    --cc=dakr@kernel.org \
    --cc=driver-core@lists.linux.dev \
    --cc=gregkh@linuxfoundation.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=muralidhara.mk@amd.com \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=rafael@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