* [PATCH V3 0/8] sysfs: drivers core: Add and use sysfs_emit and sysfs_emit_at @ 2020-09-16 20:40 Joe Perches 2020-09-16 20:40 ` [PATCH V3 6/8] mm: and drivers core: Convert hugetlb_report_node_meminfo to sysfs_emit Joe Perches 0 siblings, 1 reply; 8+ messages in thread From: Joe Perches @ 2020-09-16 20:40 UTC (permalink / raw) To: Greg Kroah-Hartman, Rafael J . Wysocki, linux-kernel, linux-pm, linux-mm Cc: Denis Efremov, Julia Lawall, Alex Dewar, linux-doc Output defects can exist in sysfs content using sprintf and snprintf. sprintf does not know the PAGE_SIZE maximum of the temporary buffer used for outputting sysfs content and it's possible to overrun the PAGE_SIZE buffer length. Add a generic sysfs_emit function that knows that the size of the temporary buffer and ensures that no overrun is done. Add a generic sysfs_emit_at function that can be used in multiple call situations that also ensures that no overrun is done. V2: Add drivers core conversions V3: Add a few more neatenings and conversions to drivers core Add mm hugetlb_report_node_meminfo conversion Joe Perches (8): sysfs: Add sysfs_emit and sysfs_emit_at to format sysfs output drivers core: Use sysfs_emit and sysfs_emit_at for show(device *...) functions drivers core: Remove strcat uses around sysfs_emit and neaten drivers core: Reindent a couple uses around sysfs_emit drivers core: Miscellaneous changes for sysfs_emit mm: and drivers core: Convert hugetlb_report_node_meminfo to sysfs_emit drivers core: Use sysfs_emit for shared_cpu_map_show and shared_cpu_list_show drivers core: node: Use a more typical macro definition style for ACCESS_ATTR Documentation/filesystems/sysfs.rst | 8 +- drivers/base/arch_topology.c | 2 +- drivers/base/bus.c | 2 +- drivers/base/cacheinfo.c | 49 ++-- drivers/base/class.c | 2 +- drivers/base/core.c | 59 +++-- drivers/base/cpu.c | 84 ++++--- drivers/base/dd.c | 3 +- drivers/base/devcoredump.c | 2 +- drivers/base/firmware_loader/fallback.c | 4 +- drivers/base/memory.c | 62 ++--- drivers/base/node.c | 306 ++++++++++++------------ drivers/base/platform.c | 17 +- drivers/base/power/sysfs.c | 160 ++++++++----- drivers/base/power/wakeup_stats.c | 17 +- drivers/base/soc.c | 64 +++-- drivers/base/topology.c | 10 +- fs/sysfs/file.c | 55 +++++ include/linux/hugetlb.h | 4 +- include/linux/sysfs.h | 15 ++ mm/hugetlb.c | 18 +- 21 files changed, 532 insertions(+), 411 deletions(-) -- 2.26.0 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH V3 6/8] mm: and drivers core: Convert hugetlb_report_node_meminfo to sysfs_emit 2020-09-16 20:40 [PATCH V3 0/8] sysfs: drivers core: Add and use sysfs_emit and sysfs_emit_at Joe Perches @ 2020-09-16 20:40 ` Joe Perches 2020-09-18 20:29 ` Mike Kravetz 2020-09-19 6:22 ` Greg Kroah-Hartman 0 siblings, 2 replies; 8+ messages in thread From: Joe Perches @ 2020-09-16 20:40 UTC (permalink / raw) To: Greg Kroah-Hartman, Rafael J . Wysocki, Mike Kravetz, Andrew Morton Cc: Denis Efremov, Julia Lawall, Alex Dewar, linux-kernel, linux-mm Convert the unbound sprintf in hugetlb_report_node_meminfo to use sysfs_emit_at so that no possible overrun of a PAGE_SIZE buf can occur. Signed-off-by: Joe Perches <joe@perches.com> --- drivers/base/node.c | 2 +- include/linux/hugetlb.h | 4 ++-- mm/hugetlb.c | 18 ++++++++++-------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/drivers/base/node.c b/drivers/base/node.c index b33526a9fcfc..dafe03e82e7c 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -473,7 +473,7 @@ static ssize_t node_read_meminfo(struct device *dev, HPAGE_PMD_NR) #endif ); - len += hugetlb_report_node_meminfo(nid, buf + len); + len += hugetlb_report_node_meminfo(buf, len, nid); return len; } diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index d5cc5f802dd4..ebca2ef02212 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -129,7 +129,7 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma, unsigned long start, unsigned long end, struct page *ref_page); void hugetlb_report_meminfo(struct seq_file *); -int hugetlb_report_node_meminfo(int, char *); +int hugetlb_report_node_meminfo(char *buf, int len, int nid); void hugetlb_show_meminfo(void); unsigned long hugetlb_total_pages(void); vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, @@ -245,7 +245,7 @@ static inline void hugetlb_report_meminfo(struct seq_file *m) { } -static inline int hugetlb_report_node_meminfo(int nid, char *buf) +static inline int hugetlb_report_node_meminfo(char *buf, int len, int nid) { return 0; } diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 61469fd3ad92..fe76f8fd5a73 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3571,18 +3571,20 @@ void hugetlb_report_meminfo(struct seq_file *m) seq_printf(m, "Hugetlb: %8lu kB\n", total / 1024); } -int hugetlb_report_node_meminfo(int nid, char *buf) +int hugetlb_report_node_meminfo(char *buf, int len, int nid) { struct hstate *h = &default_hstate; + if (!hugepages_supported()) return 0; - return sprintf(buf, - "Node %d HugePages_Total: %5u\n" - "Node %d HugePages_Free: %5u\n" - "Node %d HugePages_Surp: %5u\n", - nid, h->nr_huge_pages_node[nid], - nid, h->free_huge_pages_node[nid], - nid, h->surplus_huge_pages_node[nid]); + + return sysfs_emit_at(buf, len, + "Node %d HugePages_Total: %5u\n" + "Node %d HugePages_Free: %5u\n" + "Node %d HugePages_Surp: %5u\n", + nid, h->nr_huge_pages_node[nid], + nid, h->free_huge_pages_node[nid], + nid, h->surplus_huge_pages_node[nid]); } void hugetlb_show_meminfo(void) -- 2.26.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH V3 6/8] mm: and drivers core: Convert hugetlb_report_node_meminfo to sysfs_emit 2020-09-16 20:40 ` [PATCH V3 6/8] mm: and drivers core: Convert hugetlb_report_node_meminfo to sysfs_emit Joe Perches @ 2020-09-18 20:29 ` Mike Kravetz 2020-09-19 6:22 ` Greg Kroah-Hartman 1 sibling, 0 replies; 8+ messages in thread From: Mike Kravetz @ 2020-09-18 20:29 UTC (permalink / raw) To: Joe Perches, Greg Kroah-Hartman, Rafael J.Wysocki, Andrew Morton Cc: Denis Efremov, Julia Lawall, Alex Dewar, linux-kernel, linux-mm On 9/16/20 1:40 PM, Joe Perches wrote: > Convert the unbound sprintf in hugetlb_report_node_meminfo to use > sysfs_emit_at so that no possible overrun of a PAGE_SIZE buf can occur. > > Signed-off-by: Joe Perches <joe@perches.com> Acked-by: Mike Kravetz <mike.kravetz@oracle.com> -- Mike Kravetz ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH V3 6/8] mm: and drivers core: Convert hugetlb_report_node_meminfo to sysfs_emit 2020-09-16 20:40 ` [PATCH V3 6/8] mm: and drivers core: Convert hugetlb_report_node_meminfo to sysfs_emit Joe Perches 2020-09-18 20:29 ` Mike Kravetz @ 2020-09-19 6:22 ` Greg Kroah-Hartman 2020-09-19 16:51 ` Joe Perches ` (2 more replies) 1 sibling, 3 replies; 8+ messages in thread From: Greg Kroah-Hartman @ 2020-09-19 6:22 UTC (permalink / raw) To: Joe Perches Cc: Rafael J . Wysocki, Mike Kravetz, Andrew Morton, Denis Efremov, Julia Lawall, Alex Dewar, linux-kernel, linux-mm On Wed, Sep 16, 2020 at 01:40:43PM -0700, Joe Perches wrote: > Convert the unbound sprintf in hugetlb_report_node_meminfo to use > sysfs_emit_at so that no possible overrun of a PAGE_SIZE buf can occur. > > Signed-off-by: Joe Perches <joe@perches.com> > --- > drivers/base/node.c | 2 +- > include/linux/hugetlb.h | 4 ++-- > mm/hugetlb.c | 18 ++++++++++-------- > 3 files changed, 13 insertions(+), 11 deletions(-) > > diff --git a/drivers/base/node.c b/drivers/base/node.c > index b33526a9fcfc..dafe03e82e7c 100644 > --- a/drivers/base/node.c > +++ b/drivers/base/node.c > @@ -473,7 +473,7 @@ static ssize_t node_read_meminfo(struct device *dev, > HPAGE_PMD_NR) > #endif > ); > - len += hugetlb_report_node_meminfo(nid, buf + len); > + len += hugetlb_report_node_meminfo(buf, len, nid); > return len; > } > > diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h > index d5cc5f802dd4..ebca2ef02212 100644 > --- a/include/linux/hugetlb.h > +++ b/include/linux/hugetlb.h > @@ -129,7 +129,7 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma, > unsigned long start, unsigned long end, > struct page *ref_page); > void hugetlb_report_meminfo(struct seq_file *); > -int hugetlb_report_node_meminfo(int, char *); > +int hugetlb_report_node_meminfo(char *buf, int len, int nid); > void hugetlb_show_meminfo(void); > unsigned long hugetlb_total_pages(void); > vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, > @@ -245,7 +245,7 @@ static inline void hugetlb_report_meminfo(struct seq_file *m) > { > } > > -static inline int hugetlb_report_node_meminfo(int nid, char *buf) > +static inline int hugetlb_report_node_meminfo(char *buf, int len, int nid) > { > return 0; > } > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index 61469fd3ad92..fe76f8fd5a73 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -3571,18 +3571,20 @@ void hugetlb_report_meminfo(struct seq_file *m) > seq_printf(m, "Hugetlb: %8lu kB\n", total / 1024); > } > > -int hugetlb_report_node_meminfo(int nid, char *buf) > +int hugetlb_report_node_meminfo(char *buf, int len, int nid) > { > struct hstate *h = &default_hstate; > + > if (!hugepages_supported()) > return 0; > - return sprintf(buf, > - "Node %d HugePages_Total: %5u\n" > - "Node %d HugePages_Free: %5u\n" > - "Node %d HugePages_Surp: %5u\n", > - nid, h->nr_huge_pages_node[nid], > - nid, h->free_huge_pages_node[nid], > - nid, h->surplus_huge_pages_node[nid]); > + > + return sysfs_emit_at(buf, len, > + "Node %d HugePages_Total: %5u\n" > + "Node %d HugePages_Free: %5u\n" > + "Node %d HugePages_Surp: %5u\n", > + nid, h->nr_huge_pages_node[nid], > + nid, h->free_huge_pages_node[nid], > + nid, h->surplus_huge_pages_node[nid]); > } That is NOT one-value-per-file, which is required for sysfs files. This should be 3 different sysfs files. Ugh. But that's separate from this series, thanks for redoing this. I'll take a look at it on Monday... thanks, greg k-h ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH V3 6/8] mm: and drivers core: Convert hugetlb_report_node_meminfo to sysfs_emit 2020-09-19 6:22 ` Greg Kroah-Hartman @ 2020-09-19 16:51 ` Joe Perches 2020-09-25 18:32 ` Joe Perches 2020-09-29 0:53 ` Joe Perches 2 siblings, 0 replies; 8+ messages in thread From: Joe Perches @ 2020-09-19 16:51 UTC (permalink / raw) To: Greg Kroah-Hartman Cc: Rafael J . Wysocki, Mike Kravetz, Andrew Morton, Denis Efremov, Julia Lawall, Alex Dewar, linux-kernel, linux-mm On Sat, 2020-09-19 at 08:22 +0200, Greg Kroah-Hartman wrote: > I'll take a look at it on Monday... It's decidedly not urgent/critical. There are several logical defects all over the kernel for these unbounded sprintfs, but I don't know of an actual instance where the PAGE_SIZE buf is overfilled. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH V3 6/8] mm: and drivers core: Convert hugetlb_report_node_meminfo to sysfs_emit 2020-09-19 6:22 ` Greg Kroah-Hartman 2020-09-19 16:51 ` Joe Perches @ 2020-09-25 18:32 ` Joe Perches 2020-09-29 0:53 ` Joe Perches 2 siblings, 0 replies; 8+ messages in thread From: Joe Perches @ 2020-09-25 18:32 UTC (permalink / raw) To: Greg Kroah-Hartman Cc: Rafael J . Wysocki, Mike Kravetz, Andrew Morton, Denis Efremov, Julia Lawall, Alex Dewar, linux-kernel, linux-mm On Sat, 2020-09-19 at 08:22 +0200, Greg Kroah-Hartman wrote: > I'll take a look at it on Monday... Thoughts? ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH V3 6/8] mm: and drivers core: Convert hugetlb_report_node_meminfo to sysfs_emit 2020-09-19 6:22 ` Greg Kroah-Hartman 2020-09-19 16:51 ` Joe Perches 2020-09-25 18:32 ` Joe Perches @ 2020-09-29 0:53 ` Joe Perches 2020-09-29 4:17 ` Greg Kroah-Hartman 2 siblings, 1 reply; 8+ messages in thread From: Joe Perches @ 2020-09-29 0:53 UTC (permalink / raw) To: Greg Kroah-Hartman Cc: Rafael J . Wysocki, Mike Kravetz, Andrew Morton, Denis Efremov, Julia Lawall, Alex Dewar, linux-kernel, linux-mm On Sat, 2020-09-19 at 08:22 +0200, Greg Kroah-Hartman wrote: > On Wed, Sep 16, 2020 at 01:40:43PM -0700, Joe Perches wrote: > > Convert the unbound sprintf in hugetlb_report_node_meminfo to use > > sysfs_emit_at so that no possible overrun of a PAGE_SIZE buf can occur. [] > I'll take a look at it on Monday... (noting that you didn't say _which_ Monday...) Greg are you going to take this or should I ask someone else? The first sysfs_emit addition patch was first posted about a month ago without much change. I think it'd be useful to get it into -next before 5.9 is released. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH V3 6/8] mm: and drivers core: Convert hugetlb_report_node_meminfo to sysfs_emit 2020-09-29 0:53 ` Joe Perches @ 2020-09-29 4:17 ` Greg Kroah-Hartman 0 siblings, 0 replies; 8+ messages in thread From: Greg Kroah-Hartman @ 2020-09-29 4:17 UTC (permalink / raw) To: Joe Perches Cc: Rafael J . Wysocki, Mike Kravetz, Andrew Morton, Denis Efremov, Julia Lawall, Alex Dewar, linux-kernel, linux-mm On Mon, Sep 28, 2020 at 05:53:07PM -0700, Joe Perches wrote: > On Sat, 2020-09-19 at 08:22 +0200, Greg Kroah-Hartman wrote: > > On Wed, Sep 16, 2020 at 01:40:43PM -0700, Joe Perches wrote: > > > Convert the unbound sprintf in hugetlb_report_node_meminfo to use > > > sysfs_emit_at so that no possible overrun of a PAGE_SIZE buf can occur. > [] > > I'll take a look at it on Monday... > > (noting that you didn't say _which_ Monday...) True :) > Greg are you going to take this or should I ask someone else? > > The first sysfs_emit addition patch was first posted about a month > ago without much change. > > I think it'd be useful to get it into -next before 5.9 is released. I'll dig into this today... ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2020-09-29 4:17 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-09-16 20:40 [PATCH V3 0/8] sysfs: drivers core: Add and use sysfs_emit and sysfs_emit_at Joe Perches 2020-09-16 20:40 ` [PATCH V3 6/8] mm: and drivers core: Convert hugetlb_report_node_meminfo to sysfs_emit Joe Perches 2020-09-18 20:29 ` Mike Kravetz 2020-09-19 6:22 ` Greg Kroah-Hartman 2020-09-19 16:51 ` Joe Perches 2020-09-25 18:32 ` Joe Perches 2020-09-29 0:53 ` Joe Perches 2020-09-29 4:17 ` Greg Kroah-Hartman
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).