Re: [PATCH v5 1/2] kernfs: sysfs: support custom llseek method for sysfs entries

From: Greg Kroah-Hartman
Date: Wed Aug 23 2023 - 10:38:08 EST


On Wed, Aug 23, 2023 at 05:58:33PM +0500, Valentine Sinitsyn wrote:
> As of now, seeking in sysfs files is handled by generic_file_llseek().
> There are situations where one may want to customize seeking logic:
>
> - Many sysfs entries are fixed files while generic_file_llseek() accepts
> past-the-end positions. Not only being useless by itself, this
> also means a bug in userspace code will trigger not at lseek(), but at
> some later point making debugging harder.
> - generic_file_llseek() relies on f_mapping->host to get the file size
> which might not be correct for all sysfs entries.
> See commit 636b21b50152 ("PCI: Revoke mappings like devmem") as an example.
>
> Implement llseek method to override this behavior at sysfs attribute
> level. The method is optional, and if it is absent,
> generic_file_llseek() is called to preserve backwards compatibility.
>
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Valentine Sinitsyn <valesini@xxxxxxxxxxxxxx>
> ---
> v5:
> - Fix builds without PCI mmap support (e.g. Alpha)
> v4:
> - Fix builds which #define HAVE_PCI_LEGACY (e.g. PowerPC)
> v3:
> - Grammar fixes
> - Add base-patch: and prerequisite-patch-id: to make kernel test
> robot happy
> v2:
> - Add infrastructure to customize llseek per sysfs entry type
> - Override llseek for PCI sysfs entries with fixed_file_llseek()
> fs/kernfs/file.c | 14 +++++++++++++-
> fs/sysfs/file.c | 13 +++++++++++++
> include/linux/kernfs.h | 1 +
> include/linux/sysfs.h | 2 ++
> 4 files changed, 29 insertions(+), 1 deletion(-)
>

Due to the high rate of errors and respins of this, I'm going to wait
until after 5.7-rc1 is out before adding it to my tree so that things
can calm down a bit...

thanks,

greg k-h