Skip to contentSkip to conversation

incoming

PATCH In review Andrew Morton 17 participants 186 messages Sep 8, 2021 – Sep 24, 2021 Page 2 of 2

Subsystems (107)
lore
Share & tools
lore
author maintainer
#85 lore raw

PATCH 77/147 alpha: pci-sysfs: fix all kernel-doc warnings

In reply to Andrew Morton

From: Randy Dunlap <[email protected]>
Subject: alpha: pci-sysfs: fix all kernel-doc warnings

Fix all kernel-doc warnings in arch/alpha/kernel/pci-sysfs.c:

../arch/alpha/kernel/pci-sysfs.c:67: warning: No description found for return value of 'pci_mmap_resource' ../arch/alpha/kernel/pci-sysfs.c:115: warning: Function parameter or member 'pdev' not described in 'pci_remove_resource_files' ../arch/alpha/kernel/pci-sysfs.c:115: warning: Excess function parameter 'dev' description in 'pci_remove_resource_files' ../arch/alpha/kernel/pci-sysfs.c:230: warning: Function parameter or member 'pdev' not described in 'pci_create_resource_files' ../arch/alpha/kernel/pci-sysfs.c:230: warning: Excess function parameter 'dev' description in 'pci_create_resource_files' ../arch/alpha/kernel/pci-sysfs.c:232: warning: No description found for return value of 'pci_create_resource_files' ../arch/alpha/kernel/pci-sysfs.c:305: warning: Function parameter or member 'bus' not described in 'pci_adjust_legacy_attr' ../arch/alpha/kernel/pci-sysfs.c:305: warning: Excess function parameter 'b' description in 'pci_adjust_legacy_attr'

---

 arch/alpha/kernel/pci-sysfs.c |   12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
arch/alpha/kernel/pci-sysfs.c renamed from arch/alpha/kernel/pci-sysfs.c~alpha-pci-sysfs-fix-all-kernel-doc-warnings +8 -4
@@ -60,6 +60,8 @@ static int __pci_mmap_fits(struct pci_de
  * @sparse: address space type
  *
  * Use the bus mapping routines to map a PCI resource into userspace.
+ *
+ * Return: %0 on success, negative error code otherwise
  */
 static int pci_mmap_resource(struct kobject *kobj,
 			     struct bin_attribute *attr,
@@ -106,7 +108,7 @@ static int pci_mmap_resource_dense(struc
 
 /**
  * pci_remove_resource_files - cleanup resource files
- * @dev: dev to cleanup
+ * @pdev: pci_dev to cleanup
  *
  * If we created resource files for @dev, remove them from sysfs and
  * free their resources.
@@ -221,10 +223,12 @@ static int pci_create_attr(struct pci_de
 }
 
 /**
- * pci_create_resource_files - create resource files in sysfs for @dev
- * @dev: dev in question
+ * pci_create_resource_files - create resource files in sysfs for @pdev
+ * @pdev: pci_dev in question
  *
  * Walk the resources in @dev creating files for each resource available.
+ *
+ * Return: %0 on success, or negative error code
  */
 int pci_create_resource_files(struct pci_dev *pdev)
 {
@@ -296,7 +300,7 @@ int pci_mmap_legacy_page_range(struct pc
 
 /**
  * pci_adjust_legacy_attr - adjustment of legacy file attributes
- * @b: bus to create files under
+ * @bus: bus to create files under
  * @mmap_type: I/O port or memory
  *
  * Adjust file name and size for sparse mappings.

_

author maintainer
#86 lore raw

PATCH 78/147 percpu: remove export of pcpu_base_addr

In reply to Andrew Morton

From: Greg Kroah-Hartman <[email protected]>
Subject: percpu: remove export of pcpu_base_addr

This is not needed by any modules, so remove the export.

---

 mm/percpu.c |    1 -
 1 file changed, 1 deletion(-)
mm/percpu.c renamed from mm/percpu.c~percpu-remove-export-of-pcpu_base_addr +0 -1
@@ -146,7 +146,6 @@ static unsigned int pcpu_high_unit_cpu _
 
 /* the address of the first chunk which starts with the kernel static area */
 void *pcpu_base_addr __ro_after_init;
-EXPORT_SYMBOL_GPL(pcpu_base_addr);
 
 static const int *pcpu_unit_map __ro_after_init;		/* cpu -> unit */
 const unsigned long *pcpu_unit_offsets __ro_after_init;	/* cpu -> unit offset */

_

author maintainer
#87 lore raw

PATCH 79/147 fs/proc/kcore.c: add mmap interface

In reply to Andrew Morton

From: Feng Zhou <[email protected]>
Subject: fs/proc/kcore.c: add mmap interface

When we do the kernel monitor, use the DRGN
(https://github.com/osandov/drgn) access to kernel data structures, found that the system calls a lot. DRGN is implemented by reading /proc/kcore. After looking at the kcore code, it is found that kcore does not implement mmap, resulting in frequent context switching triggered by read. Therefore, we want to add mmap interface to optimize performance. Since vmalloc and module areas will change with allocation and release, consistency cannot be guaranteed, so mmap interface only maps KCORE_TEXT and KCORE_RAM.

The test results:
1. the default version of kcore
real 11.00
user 8.53
sys 3.59

% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
99.64 128.578319 12 11168701 pread64
...
------ ----------- ----------- --------- --------- ----------------
100.00 129.042853 11193748 966 total

2. added kcore for the mmap interface
real 6.44
user 7.32
sys 0.24

% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------

32.94    0.130120          24      5317       315 futex
11.66    0.046077          21      2231         1 lstat
 9.23    0.036449         177       206           mmap

...
------ ----------- ----------- --------- --------- ----------------
100.00 0.395077 25435 971 total

The test results show that the number of system calls and time consumption are significantly reduced.

---

 fs/proc/kcore.c |   73 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)
fs/proc/kcore.c renamed from fs/proc/kcore.c~fs-proc-kcorec-add-mmap-interface +73 -0
@@ -614,11 +614,84 @@ static int release_kcore(struct inode *i
 	return 0;
 }
 
+static vm_fault_t mmap_kcore_fault(struct vm_fault *vmf)
+{
+	return VM_FAULT_SIGBUS;
+}
+
+static const struct vm_operations_struct kcore_mmap_ops = {
+	.fault = mmap_kcore_fault,
+};
+
+static int mmap_kcore(struct file *file, struct vm_area_struct *vma)
+{
+	size_t size = vma->vm_end - vma->vm_start;
+	u64 start, end, pfn;
+	int nphdr;
+	size_t data_offset;
+	size_t phdrs_len, notes_len;
+	struct kcore_list *m = NULL;
+	int ret = 0;
+
+	down_read(&kclist_lock);
+
+	get_kcore_size(&nphdr, &phdrs_len, &notes_len, &data_offset);
+
+	data_offset &= PAGE_MASK;
+	start = (u64)vma->vm_pgoff << PAGE_SHIFT;
+	if (start < data_offset) {
+		ret = -EINVAL;
+		goto out;
+	}
+	start = kc_offset_to_vaddr(start - data_offset);
+	end   = start + size;
+
+	list_for_each_entry(m, &kclist_head, list) {
+		if (start >= m->addr && end <= m->addr + m->size)
+			break;
+	}
+
+	if (&m->list == &kclist_head) {
+		ret = -EINVAL;
+		goto out;
+	}
+
+	if (vma->vm_flags & (VM_WRITE | VM_EXEC)) {
+		ret = -EPERM;
+		goto out;
+	}
+
+	vma->vm_flags &= ~(VM_MAYWRITE | VM_MAYEXEC);
+	vma->vm_flags |= VM_MIXEDMAP;
+	vma->vm_ops = &kcore_mmap_ops;
+
+	if (kern_addr_valid(start)) {
+		if (m->type == KCORE_RAM)
+			pfn = __pa(start) >> PAGE_SHIFT;
+		else if (m->type == KCORE_TEXT)
+			pfn = __pa_symbol(start) >> PAGE_SHIFT;
+		else {
+			ret = -EFAULT;
+			goto out;
+		}
+
+		ret = remap_pfn_range(vma, vma->vm_start, pfn, size,
+				vma->vm_page_prot);
+	} else {
+		ret = -EFAULT;
+	}
+
+out:
+	up_read(&kclist_lock);
+	return ret;
+}
+
 static const struct proc_ops kcore_proc_ops = {
 	.proc_read	= read_kcore,
 	.proc_open	= open_kcore,
 	.proc_release	= release_kcore,
 	.proc_lseek	= default_llseek,
+	.proc_mmap	= mmap_kcore,
 };
 
 /* just remember that we have to update kcore */

_

#88 lore raw

Re: [patch 079/147] fs/proc/kcore.c: add mmap interface

Quoted 7 lines · Andrew Morton

After looking at the kcore code, it is found that kcore does not implement mmap, resulting in frequent context switching triggered by read. Therefore, we want to add mmap interface to optimize performance. Since vmalloc and module areas will change with allocation and release, consistency cannot be guaranteed, so mmap interface only maps KCORE_TEXT and KCORE_RAM.

Honestly, I still hate this patch.

The last time people wanted to speed up /dev/kcore accesses, it was all for black-hat reasons and speeding up kernel attacks.

And this code just makes me nervous even aside from that, because I do not understand what the heck it's doing.

fs/proc/kcore.c static int release_kcore(struct inode *i · line 672

Quoted 5 lines
fs/proc/kcore.c renamed from fs/proc/kcore.c~fs-proc-kcorec-add-mmap-interface +5 -0
+       if (kern_addr_valid(start)) {
+               if (m->type == KCORE_RAM)
+                       pfn = __pa(start) >> PAGE_SHIFT;
+               else if (m->type == KCORE_TEXT)
+                       pfn = __pa_symbol(start) >> PAGE_SHIFT;

Why is "__pa(start)" right in one situation, and "__pa_symbol(start)" in another.

So this just makes me go "this is all confusing, dangerous, and the use-case is dubious".

Mapping kernel memory is dangerous. The use-cases for it are dubious. The patch isn't obvious.

All of that screams "I'll skip this".

Linus

#89 lore raw

Re: [External] Re: [patch 079/147] fs/proc/kcore.c: add mmap interface

Quoted 16 lines · Linus Torvalds
Quoted 6 lines · Andrew Morton

After looking at the kcore code, it is found that kcore does not implement mmap, resulting in frequent context switching triggered by read. Therefore, we want to add mmap interface to optimize performance. Since vmalloc and module areas will change with allocation and release, consistency cannot be guaranteed, so mmap interface only maps KCORE_TEXT and KCORE_RAM.

Honestly, I still hate this patch.

The last time people wanted to speed up /dev/kcore accesses, it was all for black-hat reasons and speeding up kernel attacks.

And this code just makes me nervous even aside from that, because I do not understand what the heck it's doing.

Quoted 7 lines

fs/proc/kcore.c static int release_kcore(struct inode *i · line 672

Quoted 5 lines
fs/proc/kcore.c renamed from fs/proc/kcore.c~fs-proc-kcorec-add-mmap-interface +5 -0
+       if (kern_addr_valid(start)) {
+               if (m->type == KCORE_RAM)
+                       pfn = __pa(start) >> PAGE_SHIFT;
+               else if (m->type == KCORE_TEXT)
+                       pfn = __pa_symbol(start) >> PAGE_SHIFT;

Why is "__pa(start)" right in one situation, and "__pa_symbol(start)" in another.

Hi, Linus

The use here is refer to "read_kcore" in fs/proc/kcore.c.

list_for_each_entry(m, &kclist_head, list) {
...
if (m->type == KCORE_RAM || m->type == KCORE_REMAP) phdr->p_paddr = __pa(m->addr);
else if (m->type == KCORE_TEXT) phdr->p_paddr = __pa_symbol(m->addr);
...
}

Ensure consistency of usage.

Quoted 6 lines

So this just makes me go "this is all confusing, dangerous, and the use-case is dubious".

Mapping kernel memory is dangerous. The use-cases for it are dubious. The patch isn't obvious.

Kcore mmap kernel memory just has read permission.

+ if (vma->vm_flags & (VM_WRITE | VM_EXEC)) {
+ ret = -EPERM;
+ goto out;
+ }
+
+ vma->vm_flags &= ~(VM_MAYWRITE | VM_MAYEXEC);
+ vma->vm_flags |= VM_MIXEDMAP;
+ vma->vm_ops = &kcore_mmap_ops;

Compared to the read interface, kcore mmap has no increased risk, just reduce context switching.

Quoted 4 lines

All of that screams "I'll skip this".

Linus

#90 lore raw

Re: [External] Re: [patch 079/147] fs/proc/kcore.c: add mmap interface

Quoted 3 lines · Feng Zhou

Compared to the read interface, kcore mmap has no increased risk, just reduce context switching.

Yes, but the main worry is "do we really need to make this faster and easier"?

Because one of the possible main users is literally the black hat "I got root, now I want to do a rootkit".

And mmap is very very different from read().

Why? Because using mmap() you can now track changes in realtime (ie you poll waiting for some memory location to change, possibly even with hardware assist - like watchpoints or ring3 "monitor/mwait").

So mmap() of the kernel memory literally acts as a prime tool for looking at and exploiting races.

Which is why I'm _very_ leery of these kinds of interfaces.

Do they have possible good uses? Yes. But the bad uses seem to actually dominate. The good users don't seem _that_ critical, while the bad users would seem to absolutely love this interface.

See my argument?

This is basically a very dangerous interface. The fact that it is read-only doesn't change that at all.

Linus

#91 lore raw

Re: [External] Re: [patch 079/147] fs/proc/kcore.c: add mmap interface

Quoted 3 lines · Linus Torvalds

This is basically a very dangerous interface. The fact that it is read-only doesn't change that at all.

Just to clarify - we've done dangerous interfaces in the past. We probably have tons of them still that I haven't even thought about, and I think I can hear somebody sniggering from miles away about various bugs that cause much more obvious security holes that I didn't think of.

But the fact that we might have other holes that can be misused, doesn't mean we have to add new ones that seem to be almost designed for misuse.

Linus

#92 lore raw

Re: [External] Re: [patch 079/147] fs/proc/kcore.c: add mmap interface

Quoted 10 lines · Linus Torvalds
Quoted 2 lines · Linus Torvalds

This is basically a very dangerous interface. The fact that it is read-only doesn't change that at all.

Just to clarify - we've done dangerous interfaces in the past. We probably have tons of them still that I haven't even thought about, and I think I can hear somebody sniggering from miles away about various bugs that cause much more obvious security holes that I didn't think of.

Quoted 5 lines

But the fact that we might have other holes that can be misused, doesn't mean we have to add new ones that seem to be almost designed for misuse.

Linus

Ok, got it.

#93 lore raw

Re: [patch 079/147] fs/proc/kcore.c: add mmap interface

In reply to Andrew Morton
Quoted 104 lines · Andrew Morton

From: Feng Zhou <[email protected]>
Subject: fs/proc/kcore.c: add mmap interface

When we do the kernel monitor, use the DRGN
(https://github.com/osandov/drgn) access to kernel data structures, found that the system calls a lot. DRGN is implemented by reading /proc/kcore. After looking at the kcore code, it is found that kcore does not implement mmap, resulting in frequent context switching triggered by read. Therefore, we want to add mmap interface to optimize performance. Since vmalloc and module areas will change with allocation and release, consistency cannot be guaranteed, so mmap interface only maps KCORE_TEXT and KCORE_RAM.

The test results:
1. the default version of kcore
real 11.00
user 8.53
sys 3.59

% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
99.64 128.578319 12 11168701 pread64
...
------ ----------- ----------- --------- --------- ----------------
100.00 129.042853 11193748 966 total

2. added kcore for the mmap interface
real 6.44
user 7.32
sys 0.24

% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------

32.94    0.130120          24      5317       315 futex
11.66    0.046077          21      2231         1 lstat
  9.23    0.036449         177       206           mmap

...
------ ----------- ----------- --------- --------- ----------------
100.00 0.395077 25435 971 total

The test results show that the number of system calls and time consumption are significantly reduced.

---

  fs/proc/kcore.c |   73 ++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 73 insertions(+)
fs/proc/kcore.c renamed from fs/proc/kcore.c~fs-proc-kcorec-add-mmap-interface +41 -0
@@ -614,11 +614,84 @@ static int release_kcore(struct inode *i
  	return 0;
  }
 
+static vm_fault_t mmap_kcore_fault(struct vm_fault *vmf)
+{
+	return VM_FAULT_SIGBUS;
+}
+
+static const struct vm_operations_struct kcore_mmap_ops = {
+	.fault = mmap_kcore_fault,
+};
+
+static int mmap_kcore(struct file *file, struct vm_area_struct *vma)
+{
+	size_t size = vma->vm_end - vma->vm_start;
+	u64 start, end, pfn;
+	int nphdr;
+	size_t data_offset;
+	size_t phdrs_len, notes_len;
+	struct kcore_list *m = NULL;
+	int ret = 0;
+
+	down_read(&kclist_lock);
+
+	get_kcore_size(&nphdr, &phdrs_len, &notes_len, &data_offset);
+
+	data_offset &= PAGE_MASK;
+	start = (u64)vma->vm_pgoff << PAGE_SHIFT;
+	if (start < data_offset) {
+		ret = -EINVAL;
+		goto out;
+	}
+	start = kc_offset_to_vaddr(start - data_offset);
+	end   = start + size;
+
+	list_for_each_entry(m, &kclist_head, list) {
+		if (start >= m->addr && end <= m->addr + m->size)
+			break;
+	}
+
+	if (&m->list == &kclist_head) {
+		ret = -EINVAL;
+		goto out;
+	}

fs/proc/kcore.c static int release_kcore(struct inode *i · line 667

Quoted 10 lines
fs/proc/kcore.c renamed from fs/proc/kcore.c~fs-proc-kcorec-add-mmap-interface +10 -0
+
+	if (vma->vm_flags & (VM_WRITE | VM_EXEC)) {
+		ret = -EPERM;
+		goto out;
+	}
+
+	vma->vm_flags &= ~(VM_MAYWRITE | VM_MAYEXEC);
+	vma->vm_flags |= VM_MIXEDMAP;
+	vma->vm_ops = &kcore_mmap_ops;
+

This breaks all my efforts to sanitize /proc/kore access for virtio-mem.

Is there still a way to nack this?

Sorry I didn't spot this any sooner.

Signature · 3 lines
Thanks,

David / dhildenb
maintainer
#94 lore raw

Re: [patch 079/147] fs/proc/kcore.c: add mmap interface

Quoted 14 lines · David Hildenbrand

fs/proc/kcore.c static int release_kcore(struct inode *i · line 667

Quoted 10 lines · Andrew Morton
fs/proc/kcore.c renamed from fs/proc/kcore.c~fs-proc-kcorec-add-mmap-interface +10 -0
+
+	if (vma->vm_flags & (VM_WRITE | VM_EXEC)) {
+		ret = -EPERM;
+		goto out;
+	}
+
+	vma->vm_flags &= ~(VM_MAYWRITE | VM_MAYEXEC);
+	vma->vm_flags |= VM_MIXEDMAP;
+	vma->vm_ops = &kcore_mmap_ops;
+

This breaks all my efforts to sanitize /proc/kore access for virtio-mem.

Quoted 1 line

Is there still a way to nack this?

Already done:

https://lore.kernel.org/mm-commits/CAHk-=wgQ+8kmczLLKCY7yDsGHQBRcZESKd1dNaKbrjUgbWeb3A@mail.gmail.com

and down the same thread.

Quoted 7 lines

Sorry I didn't spot this any sooner.

Signature · 3 lines
Thanks,

David / dhildenb
Signature · 2 lines
Sincerely yours,
Mike.
#95 lore raw

Re: [patch 079/147] fs/proc/kcore.c: add mmap interface

Quoted 15 lines · Mike Rapoport
Quoted 14 lines · David Hildenbrand

fs/proc/kcore.c static int release_kcore(struct inode *i · line 667

Quoted 10 lines · Andrew Morton
fs/proc/kcore.c renamed from fs/proc/kcore.c~fs-proc-kcorec-add-mmap-interface +10 -0
+
+	if (vma->vm_flags & (VM_WRITE | VM_EXEC)) {
+		ret = -EPERM;
+		goto out;
+	}
+
+	vma->vm_flags &= ~(VM_MAYWRITE | VM_MAYEXEC);
+	vma->vm_flags |= VM_MIXEDMAP;
+	vma->vm_ops = &kcore_mmap_ops;
+

This breaks all my efforts to sanitize /proc/kore access for virtio-mem.

Quoted 8 lines
Quoted 1 line

Is there still a way to nack this?

Already done:

https://lore.kernel.org/mm-commits/CAHk-=wgQ+8kmczLLKCY7yDsGHQBRcZESKd1dNaKbrjUgbWeb3A@mail.gmail.com

and down the same thread.

Yeah, spotted Linus' reply just after I sent my reply.

... afterwards I thought about the implications fpr secretmem and ordinary memory hotunplug and was happy that we dodged this bullet. :)

Signature · 3 lines
Thanks,

David / dhildenb
author maintainer
#96 lore raw

PATCH 80/147 proc: stop using seq_get_buf in proc_task_name

In reply to Andrew Morton

From: Christoph Hellwig <[email protected]>
Subject: proc: stop using seq_get_buf in proc_task_name

Use seq_escape_str and seq_printf instead of poking holes into the seq_file abstraction.

---

 fs/proc/array.c |   18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
fs/proc/array.c renamed from fs/proc/array.c~proc-stop-using-seq_get_buf-in-proc_task_name +4 -14
@@ -98,27 +98,17 @@
 
 void proc_task_name(struct seq_file *m, struct task_struct *p, bool escape)
 {
-	char *buf;
-	size_t size;
 	char tcomm[64];
-	int ret;
 
 	if (p->flags & PF_WQ_WORKER)
 		wq_worker_comm(tcomm, sizeof(tcomm), p);
 	else
 		__get_task_comm(tcomm, sizeof(tcomm), p);
 
-	size = seq_get_buf(m, &buf);
-	if (escape) {
-		ret = string_escape_str(tcomm, buf, size,
-					ESCAPE_SPACE | ESCAPE_SPECIAL, "\n\\");
-		if (ret >= size)
-			ret = -1;
-	} else {
-		ret = strscpy(buf, tcomm, size);
-	}
-
-	seq_commit(m, ret);
+	if (escape)
+		seq_escape_str(m, tcomm, ESCAPE_SPACE | ESCAPE_SPECIAL, "\n\\");
+	else
+		seq_printf(m, "%.64s", tcomm);
 }
 
 /*

_

author maintainer
#97 lore raw

PATCH 81/147 connector: send event on write to /proc/[pid]/comm

In reply to Andrew Morton

From: Ohhoon Kwon <[email protected]>
Subject: connector: send event on write to /proc/[pid]/comm

While comm change event via prctl has been reported to proc connector by 'commit f786ecba4158 ("connector: add comm change event report to proc connector")', connector listeners were missing comm changes by explicit writes on /proc/[pid]/comm.

Let explicit writes on /proc/[pid]/comm report to proc connector.

---

 fs/proc/base.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/proc/base.c renamed from fs/proc/base.c~connector-send-event-on-write-to-proc-comm +4 -1
@@ -95,6 +95,7 @@
 #include <linux/posix-timers.h>
 #include <linux/time_namespace.h>
 #include <linux/resctrl.h>
+#include <linux/cn_proc.h>
 #include <trace/events/oom.h>
 #include "internal.h"
 #include "fd.h"
@@ -1674,8 +1675,10 @@ static ssize_t comm_write(struct file *f
 	if (!p)
 		return -ESRCH;
 
-	if (same_thread_group(current, p))
+	if (same_thread_group(current, p)) {
 		set_task_comm(p, buffer);
+		proc_comm_connector(p);
+	}
 	else
 		count = -EINVAL;
 

_

author maintainer
#98 lore raw

PATCH 82/147 arch: Kconfig: fix spelling mistake "seperate" -> "separate"

In reply to Andrew Morton

From: Colin Ian King <[email protected]>
Subject: arch: Kconfig: fix spelling mistake "seperate" -> "separate"

Threre is a spelling mistake in the Kconfig text. Fix it.

---

 arch/Kconfig |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/Kconfig renamed from arch/Kconfig~arch-kconfig-fix-spelling-mistake-seperate-separate +1 -1
@@ -886,7 +886,7 @@ config HAVE_SOFTIRQ_ON_OWN_STACK
 	bool
 	help
 	  Architecture provides a function to run __do_softirq() on a
-	  seperate stack.
+	  separate stack.
 
 config PGTABLE_LEVELS
 	int

_

author maintainer
#99 lore raw

PATCH 83/147 include/linux/once.h: fix trivia typo Not -> Note

In reply to Andrew Morton

From: Andy Shevchenko <[email protected]>
Subject: include/linux/once.h: fix trivia typo Not -> Note

Fix trivia typo Not -> Note in the comment to DO_ONCE().

---

 include/linux/once.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/once.h renamed from include/linux/once.h~once-fix-trivia-typo-not-note +1 -1
@@ -16,7 +16,7 @@ void __do_once_done(bool *done, struct s
  * out the condition into a nop. DO_ONCE() guarantees type safety of
  * arguments!
  *
- * Not that the following is not equivalent ...
+ * Note that the following is not equivalent ...
  *
  *   DO_ONCE(func, arg);
  *   DO_ONCE(func, arg);

_

author maintainer
#100 lore raw

PATCH 84/147 units: change from 'L' to 'UL'

In reply to Andrew Morton

From: Daniel Lezcano <[email protected]>
Subject: units: change from 'L' to 'UL'

Patch series "Add Hz macros", v3.

There are multiple definitions of the HZ_PER_MHZ or HZ_PER_KHZ in the different drivers. Instead of duplicating this definition again and again, add one in the units.h header to be reused in all the place the redefiniton occurs.

At the same time, change the type of the Watts, as they can not be negative.

This patch (of 10):

The users of the macros are safe to be assigned with an unsigned instead of signed as the variables using them are themselves unsigned.

Cc Andy Shevchenko <[email protected]>
Cc Jonathan Cameron <[email protected]>
Cc Christian Eggers <[email protected]>
Cc Lukasz Luba <[email protected]>
Cc MyungJoo Ham <[email protected]>
Cc Kyungmin Park <[email protected]>
Cc Lars-Peter Clausen <[email protected]>
Cc Peter Meerwald <[email protected]>
Cc Zhang Rui <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Miquel Raynal <[email protected]>
Cc Maxime Coquelin <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Daniel Lezcano <[email protected]>
Cc Chanwoo Choi <[email protected]>
Cc Jonathan Cameron <[email protected]>

---

 include/linux/units.h |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
include/linux/units.h renamed from include/linux/units.h~units-change-from-l-to-ul +3 -3
@@ -4,9 +4,9 @@
 
 #include <linux/math.h>
 
-#define MILLIWATT_PER_WATT	1000L
-#define MICROWATT_PER_MILLIWATT	1000L
-#define MICROWATT_PER_WATT	1000000L
+#define MILLIWATT_PER_WATT	1000UL
+#define MICROWATT_PER_MILLIWATT	1000UL
+#define MICROWATT_PER_WATT	1000000UL
 
 #define ABSOLUTE_ZERO_MILLICELSIUS -273150
 

_

author maintainer
#101 lore raw

PATCH 85/147 units: add the HZ macros

In reply to Andrew Morton

From: Daniel Lezcano <[email protected]>
Subject: units: add the HZ macros

The macros for the unit conversion for frequency are duplicated in different places.

Provide these macros in the 'units' header, so they can be reused.

Cc Chanwoo Choi <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Jonathan Cameron <[email protected]>
Cc Jonathan Cameron <[email protected]>
Cc Kyungmin Park <[email protected]>
Cc Lars-Peter Clausen <[email protected]>
Cc Lukasz Luba <[email protected]>
Cc Maxime Coquelin <[email protected]>
Cc Miquel Raynal <[email protected]>
Cc MyungJoo Ham <[email protected]>
Cc Peter Meerwald <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Zhang Rui <[email protected]>

---

 include/linux/units.h |    4 ++++
 1 file changed, 4 insertions(+)
include/linux/units.h renamed from include/linux/units.h~units-add-the-hz-macros +4 -0
@@ -4,6 +4,10 @@
 
 #include <linux/math.h>
 
+#define HZ_PER_KHZ		1000UL
+#define KHZ_PER_MHZ		1000UL
+#define HZ_PER_MHZ		1000000UL
+
 #define MILLIWATT_PER_WATT	1000UL
 #define MICROWATT_PER_MILLIWATT	1000UL
 #define MICROWATT_PER_WATT	1000000UL

_

author maintainer
#102 lore raw

PATCH 86/147 thermal/drivers/devfreq_cooling: use HZ macros

In reply to Andrew Morton

From: Daniel Lezcano <[email protected]>
Subject: thermal/drivers/devfreq_cooling: use HZ macros

HZ unit conversion macros are available in units.h, use them and remove the duplicate definition.

The new macro uses a unsigned long type which is already the type in the current code via the 'freq' variable.

Cc Chanwoo Choi <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Jonathan Cameron <[email protected]>
Cc Jonathan Cameron <[email protected]>
Cc Kyungmin Park <[email protected]>
Cc Lars-Peter Clausen <[email protected]>
Cc Lukasz Luba <[email protected]>
Cc Maxime Coquelin <[email protected]>
Cc Miquel Raynal <[email protected]>
Cc MyungJoo Ham <[email protected]>
Cc Peter Meerwald <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Zhang Rui <[email protected]>

---

 drivers/thermal/devfreq_cooling.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thermal/devfreq_cooling.c renamed from drivers/thermal/devfreq_cooling.c~thermal-drivers-devfreq_cooling-use-hz-macros +1 -1
@@ -18,10 +18,10 @@
 #include <linux/pm_opp.h>
 #include <linux/pm_qos.h>
 #include <linux/thermal.h>
+#include <linux/units.h>
 
 #include <trace/events/thermal.h>
 
-#define HZ_PER_KHZ		1000
 #define SCALE_ERROR_MITIGATION	100
 
 /**

_

author maintainer
#103 lore raw

PATCH 87/147 devfreq: use HZ macros

In reply to Andrew Morton

From: Daniel Lezcano <[email protected]>
Subject: devfreq: use HZ macros

HZ unit conversion macros are available in units.h, use them and remove the duplicate definition.

The new macro has an unsigned long type.

All the code is dealing with unsigned long and the code using the macro is doing a coercitive cast to unsigned long.

Cc Guenter Roeck <[email protected]>
Cc Jonathan Cameron <[email protected]>
Cc Jonathan Cameron <[email protected]>
Cc Kyungmin Park <[email protected]>
Cc Lars-Peter Clausen <[email protected]>
Cc Lukasz Luba <[email protected]>
Cc Maxime Coquelin <[email protected]>
Cc Miquel Raynal <[email protected]>
Cc MyungJoo Ham <[email protected]>
Cc Peter Meerwald <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Zhang Rui <[email protected]>

---

 drivers/devfreq/devfreq.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/devfreq/devfreq.c renamed from drivers/devfreq/devfreq.c~devfreq-use-hz-macros +1 -1
@@ -27,6 +27,7 @@
 #include <linux/hrtimer.h>
 #include <linux/of.h>
 #include <linux/pm_qos.h>
+#include <linux/units.h>
 #include "governor.h"
 
 #define CREATE_TRACE_POINTS
@@ -34,7 +35,6 @@
 
 #define IS_SUPPORTED_FLAG(f, name) ((f & DEVFREQ_GOV_FLAG_##name) ? true : false)
 #define IS_SUPPORTED_ATTR(f, name) ((f & DEVFREQ_GOV_ATTR_##name) ? true : false)
-#define HZ_PER_KHZ	1000
 
 static struct class *devfreq_class;
 static struct dentry *devfreq_debugfs;

_

author maintainer
#104 lore raw

PATCH 88/147 iio/drivers/as73211: use HZ macros

In reply to Andrew Morton

From: Daniel Lezcano <[email protected]>
Subject: iio/drivers/as73211: use HZ macros

HZ unit conversion macros are available in units.h, use them and remove the duplicate definition.

Cc Chanwoo Choi <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Jonathan Cameron <[email protected]>
Cc Kyungmin Park <[email protected]>
Cc Lars-Peter Clausen <[email protected]>
Cc Lukasz Luba <[email protected]>
Cc Maxime Coquelin <[email protected]>
Cc Miquel Raynal <[email protected]>
Cc MyungJoo Ham <[email protected]>
Cc Peter Meerwald <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Zhang Rui <[email protected]>

---

 drivers/iio/light/as73211.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/iio/light/as73211.c renamed from drivers/iio/light/as73211.c~iio-drivers-as73211-use-hz-macros +1 -2
@@ -24,8 +24,7 @@
 #include <linux/module.h>
 #include <linux/mutex.h>
 #include <linux/pm.h>
-
-#define HZ_PER_KHZ 1000
+#include <linux/units.h>
 
 #define AS73211_DRV_NAME "as73211"
 

_

author maintainer
#105 lore raw

PATCH 89/147 hwmon/drivers/mr75203: use HZ macros

In reply to Andrew Morton

From: Daniel Lezcano <[email protected]>
Subject: hwmon/drivers/mr75203: use HZ macros

HZ unit conversion macros are available in units.h, use them and remove the duplicate definition.

The new macro is an unsigned long. The code dealing with it is considering as an unsigned long also.

Cc Chanwoo Choi <[email protected]>
Cc Jonathan Cameron <[email protected]>
Cc Jonathan Cameron <[email protected]>
Cc Kyungmin Park <[email protected]>
Cc Lars-Peter Clausen <[email protected]>
Cc Lukasz Luba <[email protected]>
Cc Maxime Coquelin <[email protected]>
Cc Miquel Raynal <[email protected]>
Cc MyungJoo Ham <[email protected]>
Cc Peter Meerwald <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Zhang Rui <[email protected]>

---

 drivers/hwmon/mr75203.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/mr75203.c renamed from drivers/hwmon/mr75203.c~hwmon-drivers-mr75203-use-hz-macros +1 -1
@@ -17,6 +17,7 @@
 #include <linux/property.h>
 #include <linux/regmap.h>
 #include <linux/reset.h>
+#include <linux/units.h>
 
 /* PVT Common register */
 #define PVT_IP_CONFIG	0x04
@@ -37,7 +38,6 @@
 #define CLK_SYNTH_EN		BIT(24)
 #define CLK_SYS_CYCLES_MAX	514
 #define CLK_SYS_CYCLES_MIN	2
-#define HZ_PER_MHZ		1000000L
 
 #define SDIF_DISABLE	0x04
 

_

author maintainer
#106 lore raw

PATCH 90/147 iio/drivers/hid-sensor: use HZ macros

In reply to Andrew Morton

From: Daniel Lezcano <[email protected]>
Subject: iio/drivers/hid-sensor: use HZ macros

HZ unit conversion macros are available in units.h, use them and remove the duplicate definition.

Cc Chanwoo Choi <[email protected]>
Cc Christian Eggers <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Jonathan Cameron <[email protected]>
Cc Kyungmin Park <[email protected]>
Cc Lars-Peter Clausen <[email protected]>
Cc Lukasz Luba <[email protected]>
Cc Maxime Coquelin <[email protected]>
Cc Miquel Raynal <[email protected]>
Cc MyungJoo Ham <[email protected]>
Cc Peter Meerwald <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Zhang Rui <[email protected]>

---

 drivers/iio/common/hid-sensors/hid-sensor-attributes.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/iio/common/hid-sensors/hid-sensor-attributes.c renamed from drivers/iio/common/hid-sensors/hid-sensor-attributes.c~iio-drivers-hid-sensor-use-hz-macros +1 -2
@@ -6,12 +6,11 @@
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/time.h>
+#include <linux/units.h>
 
 #include <linux/hid-sensor-hub.h>
 #include <linux/iio/iio.h>
 
-#define HZ_PER_MHZ	1000000L
-
 static struct {
 	u32 usage_id;
 	int unit; /* 0 for default others from HID sensor spec */

_

author maintainer
#107 lore raw

PATCH 91/147 i2c/drivers/ov02q10: use HZ macros

In reply to Andrew Morton

From: Daniel Lezcano <[email protected]>
Subject: i2c/drivers/ov02q10: use HZ macros

HZ unit conversion macros are available in units.h, use them and remove the duplicate definition.

Cc Chanwoo Choi <[email protected]>
Cc Christian Eggers <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Jonathan Cameron <[email protected]>
Cc Jonathan Cameron <[email protected]>
Cc Kyungmin Park <[email protected]>
Cc Lars-Peter Clausen <[email protected]>
Cc Lukasz Luba <[email protected]>
Cc Maxime Coquelin <[email protected]>
Cc Miquel Raynal <[email protected]>
Cc MyungJoo Ham <[email protected]>
Cc Peter Meerwald <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Zhang Rui <[email protected]>

---

 drivers/media/i2c/ov02a10.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/ov02a10.c renamed from drivers/media/i2c/ov02a10.c~i2c-drivers-ov02q10-use-hz-macros +1 -1
@@ -9,6 +9,7 @@
 #include <linux/module.h>
 #include <linux/pm_runtime.h>
 #include <linux/regulator/consumer.h>
+#include <linux/units.h>
 #include <media/media-entity.h>
 #include <media/v4l2-async.h>
 #include <media/v4l2-ctrls.h>
@@ -64,7 +65,6 @@
 /* Test pattern control */
 #define OV02A10_REG_TEST_PATTERN			0xb6
 
-#define HZ_PER_MHZ					1000000L
 #define OV02A10_LINK_FREQ_390MHZ			(390 * HZ_PER_MHZ)
 #define OV02A10_ECLK_FREQ				(24 * HZ_PER_MHZ)
 

_

author maintainer
#108 lore raw

PATCH 92/147 mtd/drivers/nand: use HZ macros

In reply to Andrew Morton

From: Daniel Lezcano <[email protected]>
Subject: mtd/drivers/nand: use HZ macros

HZ unit conversion macros are available in units.h, use them and remove the duplicate definition.

Cc Chanwoo Choi <[email protected]>
Cc Christian Eggers <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Jonathan Cameron <[email protected]>
Cc Jonathan Cameron <[email protected]>
Cc Kyungmin Park <[email protected]>
Cc Lars-Peter Clausen <[email protected]>
Cc Lukasz Luba <[email protected]>
Cc Maxime Coquelin <[email protected]>
Cc MyungJoo Ham <[email protected]>
Cc Peter Meerwald <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Zhang Rui <[email protected]>

---

 drivers/mtd/nand/raw/intel-nand-controller.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/intel-nand-controller.c renamed from drivers/mtd/nand/raw/intel-nand-controller.c~mtd-drivers-nand-use-hz-macros +1 -1
@@ -20,6 +20,7 @@
 #include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/types.h>
+#include <linux/units.h>
 #include <asm/unaligned.h>
 
 #define EBU_CLC			0x000
@@ -102,7 +103,6 @@
 
 #define MAX_CS	2
 
-#define HZ_PER_MHZ	1000000L
 #define USEC_PER_SEC	1000000L
 
 struct ebu_nand_cs {

_

maintainer Acked-by on v1 92/147
#109 lore raw

Re: [patch 092/147] mtd/drivers/nand: use HZ macros

Hi Andrew,

[email protected] wrote on Tue, 07 Sep 2021 19:58:11 -0700:

Quoted 16 lines

From: Daniel Lezcano <[email protected]>
Subject: mtd/drivers/nand: use HZ macros

HZ unit conversion macros are available in units.h, use them and remove the duplicate definition.

Quoted 8 lines
Cc Lars-Peter Clausen <[email protected]>
Cc Lukasz Luba <[email protected]>
Cc Maxime Coquelin <[email protected]>
Cc MyungJoo Ham <[email protected]>
Cc Peter Meerwald <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Zhang Rui <[email protected]>

A better suffix would have been "mtd: rawnand: intel:". Maybe you can fix it when applying.

Quoted 23 lines

---

 drivers/mtd/nand/raw/intel-nand-controller.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/intel-nand-controller.c renamed from drivers/mtd/nand/raw/intel-nand-controller.c~mtd-drivers-nand-use-hz-macros +1 -1
@@ -20,6 +20,7 @@
 #include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/types.h>
+#include <linux/units.h>
 #include <asm/unaligned.h>
 
 #define EBU_CLC			0x000
@@ -102,7 +103,6 @@
 
 #define MAX_CS	2
 
-#define HZ_PER_MHZ	1000000L
 #define USEC_PER_SEC	1000000L
 
 struct ebu_nand_cs {
Quoted 1 line

_

Thanks,
Miquèl

author maintainer
#110 lore raw

PATCH 93/147 phy/drivers/stm32: use HZ macros

In reply to Andrew Morton

From: Daniel Lezcano <[email protected]>
Subject: phy/drivers/stm32: use HZ macros

HZ unit conversion macros are available in units.h, use them and remove the duplicate definition.

Cc Chanwoo Choi <[email protected]>
Cc Christian Eggers <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Jonathan Cameron <[email protected]>
Cc Jonathan Cameron <[email protected]>
Cc Kyungmin Park <[email protected]>
Cc Lars-Peter Clausen <[email protected]>
Cc Lukasz Luba <[email protected]>
Cc Maxime Coquelin <[email protected]>
Cc Miquel Raynal <[email protected]>
Cc MyungJoo Ham <[email protected]>
Cc Peter Meerwald <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Zhang Rui <[email protected]>

---

 drivers/phy/st/phy-stm32-usbphyc.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/phy/st/phy-stm32-usbphyc.c renamed from drivers/phy/st/phy-stm32-usbphyc.c~phy-drivers-stm32-use-hz-macros +1 -1
@@ -15,6 +15,7 @@
 #include <linux/of_platform.h>
 #include <linux/phy/phy.h>
 #include <linux/reset.h>
+#include <linux/units.h>
 
 #define STM32_USBPHYC_PLL	0x0
 #define STM32_USBPHYC_MISC	0x8
@@ -47,7 +48,6 @@
 #define PLL_FVCO_MHZ		2880
 #define PLL_INFF_MIN_RATE_HZ	19200000
 #define PLL_INFF_MAX_RATE_HZ	38400000
-#define HZ_PER_MHZ		1000000L
 
 struct pll_params {
 	u8 ndiv;

_

author maintainer
#111 lore raw

PATCH 94/147 kernel/acct.c: use dedicated helper to access rlimit values

In reply to Andrew Morton

From: Yang Yang <[email protected]>
Subject: kernel/acct.c: use dedicated helper to access rlimit values

Use rlimit() helper instead of manually writing whole chain from task to rlimit value. See patch "posix-cpu-timers: Use dedicated helper to access rlimit values".

---

 kernel/acct.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/acct.c renamed from kernel/acct.c~acct-use-dedicated-helper-to-access-rlimit-values +1 -1
@@ -478,7 +478,7 @@ static void do_acct_process(struct bsd_a
 	/*
 	 * Accounting records are not subject to resource limits.
 	 */
-	flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
+	flim = rlimit(RLIMIT_FSIZE);
 	current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
 	/* Perform file operations on behalf of whoever enabled accounting */
 	orig_cred = override_creds(file->f_cred);

_

author maintainer
#112 lore raw

PATCH 95/147 profiling: fix shift-out-of-bounds bugs

In reply to Andrew Morton

From: Pavel Skripkin <[email protected]>
Subject: profiling: fix shift-out-of-bounds bugs

Syzbot reported shift-out-of-bounds bug in profile_init().
The problem was in incorrect prof_shift. Since prof_shift value comes from userspace we need to clamp this value into [0, BITS_PER_LONG -1] boundaries.

Second possible shiht-out-of-bounds was found by Tetsuo:
sample_step local variable in read_profile() had "unsigned int" type, but prof_shift allows to make a BITS_PER_LONG shift. So, to prevent possible shiht-out-of-bounds sample_step type was changed to "unsigned long".

Also, "unsigned short int" will be sufficient for storing [0, BITS_PER_LONG] value, that's why there is no need for "unsigned long" prof_shift.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
Reported-and-tested-by [email protected]
Cc Thomas Gleixner <[email protected]>
Cc Steven Rostedt <[email protected]>

---

 kernel/profile.c |   21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
kernel/profile.c renamed from kernel/profile.c~profiling-fix-shift-out-of-bounds-bugs +11 -10
@@ -41,7 +41,8 @@ struct profile_hit {
 #define NR_PROFILE_GRP		(NR_PROFILE_HIT/PROFILE_GRPSZ)
 
 static atomic_t *prof_buffer;
-static unsigned long prof_len, prof_shift;
+static unsigned long prof_len;
+static unsigned short int prof_shift;
 
 int prof_on __read_mostly;
 EXPORT_SYMBOL_GPL(prof_on);
@@ -67,8 +68,8 @@ int profile_setup(char *str)
 		if (str[strlen(sleepstr)] == ',')
 			str += strlen(sleepstr) + 1;
 		if (get_option(&str, &par))
-			prof_shift = par;
-		pr_info("kernel sleep profiling enabled (shift: %ld)\n",
+			prof_shift = clamp(par, 0, BITS_PER_LONG - 1);
+		pr_info("kernel sleep profiling enabled (shift: %u)\n",
 			prof_shift);
 #else
 		pr_warn("kernel sleep profiling requires CONFIG_SCHEDSTATS\n");
@@ -78,21 +79,21 @@ int profile_setup(char *str)
 		if (str[strlen(schedstr)] == ',')
 			str += strlen(schedstr) + 1;
 		if (get_option(&str, &par))
-			prof_shift = par;
-		pr_info("kernel schedule profiling enabled (shift: %ld)\n",
+			prof_shift = clamp(par, 0, BITS_PER_LONG - 1);
+		pr_info("kernel schedule profiling enabled (shift: %u)\n",
 			prof_shift);
 	} else if (!strncmp(str, kvmstr, strlen(kvmstr))) {
 		prof_on = KVM_PROFILING;
 		if (str[strlen(kvmstr)] == ',')
 			str += strlen(kvmstr) + 1;
 		if (get_option(&str, &par))
-			prof_shift = par;
-		pr_info("kernel KVM profiling enabled (shift: %ld)\n",
+			prof_shift = clamp(par, 0, BITS_PER_LONG - 1);
+		pr_info("kernel KVM profiling enabled (shift: %u)\n",
 			prof_shift);
 	} else if (get_option(&str, &par)) {
-		prof_shift = par;
+		prof_shift = clamp(par, 0, BITS_PER_LONG - 1);
 		prof_on = CPU_PROFILING;
-		pr_info("kernel profiling enabled (shift: %ld)\n",
+		pr_info("kernel profiling enabled (shift: %u)\n",
 			prof_shift);
 	}
 	return 1;
@@ -468,7 +469,7 @@ read_profile(struct file *file, char __u
 	unsigned long p = *ppos;
 	ssize_t read;
 	char *pnt;
-	unsigned int sample_step = 1 << prof_shift;
+	unsigned long sample_step = 1UL << prof_shift;
 
 	profile_flip_buffers();
 	if (p >= (prof_len+1)*sizeof(unsigned int))

_

author maintainer
#113 lore raw

PATCH 96/147 MAINTAINERS: update ClangBuiltLinux mailing list

In reply to Andrew Morton

From: Nathan Chancellor <[email protected]>
Subject: MAINTAINERS: update ClangBuiltLinux mailing list

We are now at [email protected].

---

 MAINTAINERS |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
MAINTAINERS renamed from MAINTAINERS~maintainers-update-clangbuiltlinux-mailing-list +2 -2
@@ -4504,7 +4504,7 @@ F:	.clang-format
 CLANG/LLVM BUILD SUPPORT
 M:	Nathan Chancellor <[email protected]>
 M:	Nick Desaulniers <[email protected]>
-L:	[email protected]
+L:	[email protected]
 S:	Supported
 W:	https://clangbuiltlinux.github.io/
 B:	https://github.com/ClangBuiltLinux/linux/issues
@@ -4519,7 +4519,7 @@ M:	Sami Tolvanen <[email protected]
 M:	Kees Cook <[email protected]>
 R:	Nathan Chancellor <[email protected]>
 R:	Nick Desaulniers <[email protected]>
-L:	[email protected]
+L:	[email protected]
 S:	Supported
 B:	https://github.com/ClangBuiltLinux/linux/issues
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/clang/features

_

author maintainer
#114 lore raw

PATCH 97/147 Documentation/llvm: update mailing list

In reply to Andrew Morton

From: Nathan Chancellor <[email protected]>
Subject: Documentation/llvm: update mailing list

We are now at [email protected].

---

 Documentation/kbuild/llvm.rst |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Documentation/kbuild/llvm.rst renamed from Documentation/kbuild/llvm.rst~documentation-llvm-update-mailing-list +2 -1
@@ -111,7 +111,8 @@ Getting Help
 ------------
 
 - `Website <https://clangbuiltlinux.github.io/>`_
-- `Mailing List <https://groups.google.com/forum/#!forum/clang-built-linux>`_: <[email protected]>
+- `Mailing List <https://lore.kernel.org/llvm/>`_: <[email protected]>
+- `Old Mailing List Archives <https://groups.google.com/g/clang-built-linux>`_
 - `Issue Tracker <https://github.com/ClangBuiltLinux/linux/issues>`_
 - IRC: #clangbuiltlinux on chat.freenode.net
 - `Telegram <https://t.me/ClangBuiltLinux>`_: @ClangBuiltLinux

_

author maintainer
#115 lore raw

PATCH 98/147 Documentation/llvm: update IRC location

In reply to Andrew Morton

From: Nathan Chancellor <[email protected]>
Subject: Documentation/llvm: update IRC location

This should have been done with commit 91ed3ed0f798 ("MAINTAINERS: update ClangBuiltLinux IRC chat") but I did not realize it was in two separate spots.

---

 Documentation/kbuild/llvm.rst |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/kbuild/llvm.rst renamed from Documentation/kbuild/llvm.rst~documentation-llvm-update-irc-location +1 -1
@@ -114,7 +114,7 @@ Getting Help
 - `Mailing List <https://lore.kernel.org/llvm/>`_: <[email protected]>
 - `Old Mailing List Archives <https://groups.google.com/g/clang-built-linux>`_
 - `Issue Tracker <https://github.com/ClangBuiltLinux/linux/issues>`_
-- IRC: #clangbuiltlinux on chat.freenode.net
+- IRC: #clangbuiltlinux on irc.libera.chat
 - `Telegram <https://t.me/ClangBuiltLinux>`_: @ClangBuiltLinux
 - `Wiki <https://github.com/ClangBuiltLinux/linux/wiki>`_
 - `Beginner Bugs <https://github.com/ClangBuiltLinux/linux/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22>`_

_

author maintainer
#116 lore raw

PATCH 99/147 math: make RATIONAL tristate

In reply to Andrew Morton

From: Geert Uytterhoeven <[email protected]>
Subject: math: make RATIONAL tristate

Patch series "math: RATIONAL and RATIONAL_KUNIT_TEST improvements".

This series makes the RATIONAL symbol tristate, so it is not forced builtin if all users are modular, and makes the RATIONAL_KUNIT_TEST depend on RATIONAL, to avoid enabling RATIONAL if there are no real users.

This patch (of 2):

All but one symbols that select RATIONAL are tristate, but RATIONAL itself is bool. Change it to tristate, so the rational fractions support code can be modular if no builtin code relies on it.

---

 lib/math/Kconfig    |    2 +-
 lib/math/rational.c |    3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)
lib/math/Kconfig renamed from lib/math/Kconfig~math-make-rational-tristate +1 -1
@@ -14,4 +14,4 @@ config PRIME_NUMBERS
 	  If unsure, say N.
 
 config RATIONAL
-	bool
+	tristate
lib/math/rational.c renamed from lib/math/rational.c~math-make-rational-tristate +3 -0
@@ -13,6 +13,7 @@
 #include <linux/export.h>
 #include <linux/minmax.h>
 #include <linux/limits.h>
+#include <linux/module.h>
 
 /*
  * calculate best rational approximation for a given fraction
@@ -106,3 +107,5 @@ void rational_best_approximation(
 }
 
 EXPORT_SYMBOL(rational_best_approximation);
+
+MODULE_LICENSE("GPL v2");

_

author maintainer
#117 lore raw

PATCH 100/147 math: RATIONAL_KUNIT_TEST should depend on RATIONAL instead of selecting it

In reply to Andrew Morton

From: Geert Uytterhoeven <[email protected]>
Subject: math: RATIONAL_KUNIT_TEST should depend on RATIONAL instead of selecting it

RATIONAL_KUNIT_TEST selects RATIONAL, thus enabling an optional feature the user may not want to have enabled. Fix this by making the test depend on RATIONAL instead.

Fixes b6c75c4afceb8bc0 ("lib/math/rational: add Kunit test cases")
Cc Andy Shevchenko <[email protected]>
Cc Brendan Higgins <[email protected]>
Cc Colin Ian King <[email protected]>
Cc Trent Piepho <[email protected]>

---

 lib/Kconfig.debug |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
lib/Kconfig.debug renamed from lib/Kconfig.debug~math-rational_kunit_test-should-depend-on-rational-instead-of-selecting-it +1 -2
@@ -2460,8 +2460,7 @@ config SLUB_KUNIT_TEST
 
 config RATIONAL_KUNIT_TEST
 	tristate "KUnit test for rational.c" if !KUNIT_ALL_TESTS
-	depends on KUNIT
-	select RATIONAL
+	depends on KUNIT && RATIONAL
 	default KUNIT_ALL_TESTS
 	help
 	  This builds the rational math unit test.

_

author maintainer
#118 lore raw

PATCH 101/147 lib/string: optimized memcpy

In reply to Andrew Morton

From: Matteo Croce <[email protected]>
Subject: lib/string: optimized memcpy

Patch series "lib/string: optimized mem* functions", v2.

Rewrite the generic mem{cpy,move,set} so that memory is accessed with the widest size possible, but without doing unaligned accesses.

This was originally posted as C string functions for RISC-V[1], but as there was no specific RISC-V code, it was proposed for the generic lib/string.c implementation.

Tested on RISC-V and on x86_64 by undefining __HAVE_ARCH_MEM{CPY,SET,MOVE} and HAVE_EFFICIENT_UNALIGNED_ACCESS.

These are the performances of memcpy() and memset() of a RISC-V machine on a 32 mbyte buffer:

memcpy:
original aligned: 75 Mb/s
original unaligned: 75 Mb/s
new aligned: 114 Mb/s
new unaligned: 107 Mb/s

memset:
original aligned: 140 Mb/s
original unaligned: 140 Mb/s
new aligned: 241 Mb/s
new unaligned: 241 Mb/s

The size increase is negligible:

$ scripts/bloat-o-meter vmlinux.orig vmlinux
add/remove: 0/0 grow/shrink: 4/1 up/down: 427/-6 (421)
Function                                     old     new   delta
memcpy                                        29     351    +322
memset                                        29     117     +88
strlcat                                       68      78     +10
strlcpy                                       50      57      +7
memmove                                       56      50      -6
Total: Before=8556964, After=8557385, chg +0.00%

These functions will be used for RISC-V initially.

[1] https://lore.kernel.org/linux-riscv/[email protected]/

The only architecture which will use all the three function will be riscv, while memmove() will be used by arc, h8300, hexagon, ia64, openrisc and parisc.

Keep in mind that memmove() isn't anything special, it just calls memcpy() when possible (e.g. buffers not overlapping), and fallbacks to the byte by byte copy otherwise.

In future we can write two functions, one which copies forward and another one which copies backward, and call the right one depending on the buffers position. Then, we could alias memcpy() and memmove(), as proposed by
Linus: https://bugzilla.redhat.com/show_bug.cgi?id=638477#c132

This patch (of 3):

Rewrite the generic memcpy() to copy a word at time, without generating unaligned accesses.

The procedure is made of three steps: First copy data one byte at time until the destination buffer is aligned to a long boundary. Then copy the data one long at time shifting the current and the next long to compose a long at every cycle. Finally, copy the remainder one byte at time.

This is the improvement on RISC-V:

original aligned: 75 Mb/s
original unaligned: 75 Mb/s
new aligned: 114 Mb/s
new unaligned: 107 Mb/s

and this the binary size increase according to bloat-o-meter:

Function old new delta
memcpy 36 324 +288

---

 lib/string.c |   80 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 77 insertions(+), 3 deletions(-)
lib/string.c renamed from lib/string.c~lib-string-optimized-memcpy +77 -3
@@ -33,6 +33,23 @@
 #include <asm/word-at-a-time.h>
 #include <asm/page.h>
 
+#define BYTES_LONG	sizeof(long)
+#define WORD_MASK	(BYTES_LONG - 1)
+#define MIN_THRESHOLD	(BYTES_LONG * 2)
+
+/* convenience union to avoid cast between different pointer types */
+union types {
+	u8 *as_u8;
+	unsigned long *as_ulong;
+	uintptr_t as_uptr;
+};
+
+union const_types {
+	const u8 *as_u8;
+	const unsigned long *as_ulong;
+	uintptr_t as_uptr;
+};
+
 #ifndef __HAVE_ARCH_STRNCASECMP
 /**
  * strncasecmp - Case insensitive, length-limited string comparison
@@ -869,6 +886,13 @@ EXPORT_SYMBOL(memset64);
 #endif
 
 #ifndef __HAVE_ARCH_MEMCPY
+
+#ifdef __BIG_ENDIAN
+#define MERGE_UL(h, l, d) ((h) << ((d) * 8) | (l) >> ((BYTES_LONG - (d)) * 8))
+#else
+#define MERGE_UL(h, l, d) ((h) >> ((d) * 8) | (l) << ((BYTES_LONG - (d)) * 8))
+#endif
+
 /**
  * memcpy - Copy one area of memory to another
  * @dest: Where to copy to
@@ -880,14 +904,64 @@ EXPORT_SYMBOL(memset64);
  */
 void *memcpy(void *dest, const void *src, size_t count)
 {
-	char *tmp = dest;
-	const char *s = src;
+	union const_types s = { .as_u8 = src };
+	union types d = { .as_u8 = dest };
+	int distance = 0;
+
+	if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)) {
+		if (count < MIN_THRESHOLD)
+			goto copy_remainder;
+
+		/* Copy a byte at time until destination is aligned. */
+		for (; d.as_uptr & WORD_MASK; count--)
+			*d.as_u8++ = *s.as_u8++;
+
+		distance = s.as_uptr & WORD_MASK;
+	}
+
+	if (distance) {
+		unsigned long last, next;
 
+		/*
+		 * s is distance bytes ahead of d, and d just reached
+		 * the alignment boundary. Move s backward to word align it
+		 * and shift data to compensate for distance, in order to do
+		 * word-by-word copy.
+		 */
+		s.as_u8 -= distance;
+
+		next = s.as_ulong[0];
+		for (; count >= BYTES_LONG; count -= BYTES_LONG) {
+			last = next;
+			next = s.as_ulong[1];
+
+			d.as_ulong[0] = MERGE_UL(last, next, distance);
+
+			d.as_ulong++;
+			s.as_ulong++;
+		}
+
+		/* Restore s with the original offset. */
+		s.as_u8 += distance;
+	} else {
+		/*
+		 * If the source and dest lower bits are the same, do a simple
+		 * 32/64 bit wide copy.
+		 */
+		for (; count >= BYTES_LONG; count -= BYTES_LONG)
+			*d.as_ulong++ = *s.as_ulong++;
+	}
+
+copy_remainder:
 	while (count--)
-		*tmp++ = *s++;
+		*d.as_u8++ = *s.as_u8++;
+
 	return dest;
 }
 EXPORT_SYMBOL(memcpy);
+
+#undef MERGE_UL
+
 #endif
 
 #ifndef __HAVE_ARCH_MEMMOVE

_

#119 lore raw

Re: [patch 101/147] lib/string: optimized memcpy

I'm going to skip this one too.

Quoted 5 lines · Andrew Morton

From: Matteo Croce <[email protected]>
Subject: lib/string: optimized memcpy

Patch series "lib/string: optimized mem* functions", v2.

Honestly, if we change the fallback memcpy(), I think the change should be to remove it.

This is a core architecture thing, and every architecture does their own. And pretty much every architecture has their own optimizations for memcpy.

Yes, the byte-at-a-time default implementation is bad. But it's _intentionally_ bad. It's only meant for initial bringup. No architecture should actually end up using this in the long run, and if you see it in profiles it should make you go "Ahh" instead.

Linus

author maintainer
#120 lore raw

PATCH 102/147 lib/string: optimized memmove

In reply to Andrew Morton

From: Matteo Croce <[email protected]>
Subject: lib/string: optimized memmove

When the destination buffer is before the source one, or when the buffers doesn't overlap, it's safe to use memcpy() instead, which is optimized to use a bigger data size possible.

This "optimization" only covers a common case. In future, proper code which does the same thing as memcpy() does but backwards can be done.

Cc Christoph Hellwig <[email protected]>
Cc David Laight <[email protected]>
Cc Drew Fustini <[email protected]>
Cc Emil Renner Berthing <[email protected]>
Cc Guo Ren <[email protected]>
Cc Nick Desaulniers <[email protected]>
Cc Nick Kossifidis <[email protected]>
Cc Palmer Dabbelt <[email protected]>

---

 lib/string.c |   18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
lib/string.c renamed from lib/string.c~lib-string-optimized-memmove +6 -12
@@ -975,19 +975,13 @@ EXPORT_SYMBOL(memcpy);
  */
 void *memmove(void *dest, const void *src, size_t count)
 {
-	char *tmp;
-	const char *s;
+	if (dest < src || src + count <= dest)
+		return memcpy(dest, src, count);
+
+	if (dest > src) {
+		const char *s = src + count;
+		char *tmp = dest + count;
 
-	if (dest <= src) {
-		tmp = dest;
-		s = src;
-		while (count--)
-			*tmp++ = *s++;
-	} else {
-		tmp = dest;
-		tmp += count;
-		s = src;
-		s += count;
 		while (count--)
 			*--tmp = *--s;
 	}

_

#121 lore raw

Re: [patch 102/147] lib/string: optimized memmove

Quoted 4 lines · Andrew Morton

When the destination buffer is before the source one, or when the buffers doesn't overlap, it's safe to use memcpy() instead, which is optimized to use a bigger data size possible.

This one is actively buggy.

It depends on the possibly incorrect assumption that memcpy() always copies upwards.

That is admittedly commonly true, but it's not something we can depend on. Not even when the memcpy() implementation in the very same file ends up doing so - because architectures can and should replace that function with their own ones, and we have that __HAVE_ARCH_MEMCPY for exactly that case.

Like 101/147, all reasonable architectures end up having their own implementation anyway, but the immediate reason I'm dropping this patch is that it's literally incorrect.

Linus

#122 lore raw

RE: [patch 102/147] lib/string: optimized memmove

From: Linus Torvalds

Quoted 4 lines

Sent: 08 September 2021 19:30

Quoted 1 line · Andrew Morton
Quoted 8 lines
Quoted 3 lines

When the destination buffer is before the source one, or when the buffers doesn't overlap, it's safe to use memcpy() instead, which is optimized to use a bigger data size possible.

This one is actively buggy.

It depends on the possibly incorrect assumption that memcpy() always copies upwards.

Even if the memcpy() 'mostly' copies upwards it may copy the last 8 bytes first and then copy the rest of the buffer in 8 byte chunks.

OTOH the change to libc that made it do backwards is just stupid.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

author maintainer
#123 lore raw

PATCH 103/147 lib/string: optimized memset

In reply to Andrew Morton

From: Matteo Croce <[email protected]>
Subject: lib/string: optimized memset

The generic memset is defined as a byte at time write. This is always safe, but it's slower than a 4 byte or even 8 byte write.

Write a generic memset which fills the data one byte at time until the destination is aligned, then fills using the largest size allowed, and finally fills the remaining data one byte at time.

On a RISC-V machine the speed goes from 140 Mb/s to 241 Mb/s, and this the binary size increase according to bloat-o-meter:

Function old new delta
memset 32 148 +116

Cc Christoph Hellwig <[email protected]>
Cc David Laight <[email protected]>
Cc Drew Fustini <[email protected]>
Cc Emil Renner Berthing <[email protected]>
Cc Guo Ren <[email protected]>
Cc Nick Desaulniers <[email protected]>
Cc Nick Kossifidis <[email protected]>
Cc Palmer Dabbelt <[email protected]>

---

 lib/string.c |   32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)
lib/string.c renamed from lib/string.c~lib-string-optimized-memset +30 -2
@@ -810,10 +810,38 @@ EXPORT_SYMBOL(__sysfs_match_string);
  */
 void *memset(void *s, int c, size_t count)
 {
-	char *xs = s;
+	union types dest = { .as_u8 = s };
 
+	if (count >= MIN_THRESHOLD) {
+		unsigned long cu = (unsigned long)c;
+
+		/* Compose an ulong with 'c' repeated 4/8 times */
+#ifdef CONFIG_ARCH_HAS_FAST_MULTIPLIER
+		cu *= 0x0101010101010101UL;
+#else
+		cu |= cu << 8;
+		cu |= cu << 16;
+		/* Suppress warning on 32 bit machines */
+		cu |= (cu << 16) << 16;
+#endif
+		if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)) {
+			/*
+			 * Fill the buffer one byte at time until
+			 * the destination is word aligned.
+			 */
+			for (; count && dest.as_uptr & WORD_MASK; count--)
+				*dest.as_u8++ = c;
+		}
+
+		/* Copy using the largest size allowed */
+		for (; count >= BYTES_LONG; count -= BYTES_LONG)
+			*dest.as_ulong++ = cu;
+	}
+
+	/* copy the remainder */
 	while (count--)
-		*xs++ = c;
+		*dest.as_u8++ = c;
+
 	return s;
 }
 EXPORT_SYMBOL(memset);

_

#124 lore raw

Re: [patch 103/147] lib/string: optimized memset

I'm dropping this one just to be consistent, although for memset() it's possibly a bit more reasonable to fall back on some default.

But probably not. memcpy and memset really are *so* special that these generic versions should be considered to be "stupid placeholders for bringup, and nothing more".

Quoted 3 lines · Andrew Morton

On a RISC-V machine the speed goes from 140 Mb/s to 241 Mb/s, and this the binary size increase according to bloat-o-meter:

I also react to the benchmark numbers: RISC-V already has

  #define __HAVE_ARCH_MEMSET
  #define __HAVE_ARCH_MEMCPY
  #define __HAVE_ARCH_MEMMOVE

in its <asm/string.h> file, so these are just odd.

Did you benchmark these generic functions on their own, rather than the ones that actually get *used*?

Linus

#125 lore raw

Re: [patch 103/147] lib/string: optimized memset

Quoted 19 lines · On Wed, 8 Sep 2021 11:34:27 -0700 Linus Torvalds…

I'm dropping this one just to be consistent, although for memset() it's possibly a bit more reasonable to fall back on some default.

But probably not. memcpy and memset really are *so* special that these generic versions should be considered to be "stupid placeholders for bringup, and nothing more".

Quoted 3 lines · Andrew Morton

On a RISC-V machine the speed goes from 140 Mb/s to 241 Mb/s, and this the binary size increase according to bloat-o-meter:

I also react to the benchmark numbers: RISC-V already has

  #define __HAVE_ARCH_MEMSET
  #define __HAVE_ARCH_MEMCPY
  #define __HAVE_ARCH_MEMMOVE
Quoted 6 lines

in its <asm/string.h> file, so these are just odd.

Did you benchmark these generic functions on their own, rather than the ones that actually get *used*?

Linus

I benchmarked against the generic routines. The RISC-V specific are even slower than the generic ones, because generates lot of unaligned accesses.

That was the whole point of the series initially. These C routines should have replaced the risc-v specific assembly ones, but then it was proposed to use them as generic:

https://lore.kernel.org/linux-riscv/[email protected]/

Signature · 1 line
per aspera ad upstream
author maintainer
#126 lore raw

PATCH 104/147 lib/test: convert test_sort.c to use KUnit

In reply to Andrew Morton

From: Daniel Latypov <[email protected]>
Subject: lib/test: convert test_sort.c to use KUnit

This follows up commit ebd09577be6c ("lib/test: convert lib/test_list_sort.c to use KUnit").

Converting this test to KUnit makes the test a bit shorter, standardizes how it reports pass/fail, and adds an easier way to run the test [1].

Like ebd09577be6c, this leaves the file and Kconfig option name the same, but slightly changes their dependencies (needs CONFIG_KUNIT).

[1] Can be run via

$ ./tools/testing/kunit/kunit.py run --kunitconfig /dev/stdin <<EOF
CONFIG_KUNIT=y
CONFIG_TEST_SORT=y
EOF

[11:30:27] Starting KUnit Kernel ...
[11:30:30] ============================================================ [11:30:30] ======== [PASSED] lib_sort ========
[11:30:30] [PASSED] test_sort
[11:30:30] ============================================================ [11:30:30] Testing complete. 1 tests run. 0 failed. 0 crashed. 0 skipped. [11:30:30] Elapsed time: 37.032s total, 0.001s configuring, 34.090s building, 0.000s running

Note: this is the time it took after a make mrproper.

With an incremental rebuild, this looks more like:
[11:38:58] Elapsed time: 6.444s total, 0.001s configuring, 3.416s building, 0.000s running

Since the test has no dependencies, it can also be run (with some other tests) with just:

$ ./tools/testing/kunit/kunit.py run

---

 lib/Kconfig.debug |    5 +++--
 lib/test_sort.c   |   40 +++++++++++++++++++---------------------
 2 files changed, 22 insertions(+), 23 deletions(-)
lib/Kconfig.debug renamed from lib/Kconfig.debug~lib-test-convert-test_sortc-to-use-kunit +3 -2
@@ -2078,8 +2078,9 @@ config TEST_MIN_HEAP
 	  If unsure, say N.
 
 config TEST_SORT
-	tristate "Array-based sort test"
-	depends on DEBUG_KERNEL || m
+	tristate "Array-based sort test" if !KUNIT_ALL_TESTS
+	depends on KUNIT
+	default KUNIT_ALL_TESTS
 	help
 	  This option enables the self-test function of 'sort()' at boot,
 	  or at module load time.
lib/test_sort.c renamed from lib/test_sort.c~lib-test-convert-test_sortc-to-use-kunit +19 -21
@@ -1,4 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
+
+#include <kunit/test.h>
+
 #include <linux/sort.h>
 #include <linux/slab.h>
 #include <linux/module.h>
@@ -7,18 +10,17 @@
 
 #define TEST_LEN 1000
 
-static int __init cmpint(const void *a, const void *b)
+static int cmpint(const void *a, const void *b)
 {
 	return *(int *)a - *(int *)b;
 }
 
-static int __init test_sort_init(void)
+static void test_sort(struct kunit *test)
 {
-	int *a, i, r = 1, err = -ENOMEM;
+	int *a, i, r = 1;
 
-	a = kmalloc_array(TEST_LEN, sizeof(*a), GFP_KERNEL);
-	if (!a)
-		return err;
+	a = kunit_kmalloc_array(test, TEST_LEN, sizeof(*a), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, a);
 
 	for (i = 0; i < TEST_LEN; i++) {
 		r = (r * 725861) % 6599;
@@ -27,24 +29,20 @@ static int __init test_sort_init(void)
 
 	sort(a, TEST_LEN, sizeof(*a), cmpint, NULL);
 
-	err = -EINVAL;
 	for (i = 0; i < TEST_LEN-1; i++)
-		if (a[i] > a[i+1]) {
-			pr_err("test has failed\n");
-			goto exit;
-		}
-	err = 0;
-	pr_info("test passed\n");
-exit:
-	kfree(a);
-	return err;
+		KUNIT_ASSERT_LE(test, a[i], a[i + 1]);
 }
 
-static void __exit test_sort_exit(void)
-{
-}
+static struct kunit_case sort_test_cases[] = {
+	KUNIT_CASE(test_sort),
+	{}
+};
+
+static struct kunit_suite sort_test_suite = {
+	.name = "lib_sort",
+	.test_cases = sort_test_cases,
+};
 
-module_init(test_sort_init);
-module_exit(test_sort_exit);
+kunit_test_suites(&sort_test_suite);
 
 MODULE_LICENSE("GPL");

_

author maintainer
#127 lore raw

PATCH 105/147 lib/dump_stack: correct kernel-doc notation

In reply to Andrew Morton

From: Randy Dunlap <[email protected]>
Subject: lib/dump_stack: correct kernel-doc notation

Fix kernel-doc warnings in dump_stack.c:

lib/dump_stack.c:97: warning: Function parameter or member 'log_lvl' not described in 'dump_stack_lvl' lib/dump_stack.c:97: warning: expecting prototype for dump_stack(). Prototype was for dump_stack_lvl() instead

---

 lib/dump_stack.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/dump_stack.c renamed from lib/dump_stack.c~lib-dump_stack-correct-kernel-doc-notation +2 -1
@@ -89,7 +89,8 @@ static void __dump_stack(const char *log
 }
 
 /**
- * dump_stack - dump the current task information and its stack trace
+ * dump_stack_lvl - dump the current task information and its stack trace
+ * @log_lvl: log level
  *
  * Architectures can override this implementation by implementing its own.
  */

_

author maintainer
#128 lore raw

PATCH 106/147 lib/iov_iter.c: fix kernel-doc warnings

In reply to Andrew Morton

From: Randy Dunlap <[email protected]>
Subject: lib/iov_iter.c: fix kernel-doc warnings

Fix all kernel-doc warnings in lib/iov_iter.c:

lib/iov_iter.c:695: warning: Function parameter or member 'i' not described in '_copy_mc_to_iter' lib/iov_iter.c:695: warning: Excess function parameter 'iter' description in '_copy_mc_to_iter' lib/iov_iter.c:695: warning: No description found for return value of '_copy_mc_to_iter' lib/iov_iter.c:758: warning: Function parameter or member 'i' not described in '_copy_from_iter_flushcache' lib/iov_iter.c:758: warning: Excess function parameter 'iter' description in '_copy_from_iter_flushcache' lib/iov_iter.c:758: warning: No description found for return value of '_copy_from_iter_flushcache'

---

 lib/iov_iter.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
lib/iov_iter.c renamed from lib/iov_iter.c~lib-iov_iterc-fix-kernel-doc-warnings +6 -2
@@ -672,7 +672,7 @@ static size_t copy_mc_pipe_to_iter(const
  * _copy_mc_to_iter - copy to iter with source memory error exception handling
  * @addr: source kernel address
  * @bytes: total transfer length
- * @iter: destination iterator
+ * @i: destination iterator
  *
  * The pmem driver deploys this for the dax operation
  * (dax_copy_to_iter()) for dax reads (bypass page-cache and the
@@ -690,6 +690,8 @@ static size_t copy_mc_pipe_to_iter(const
  * * ITER_KVEC, ITER_PIPE, and ITER_BVEC can return short copies.
  *   Compare to copy_to_iter() where only ITER_IOVEC attempts might return
  *   a short copy.
+ *
+ * Return: number of bytes copied (may be %0)
  */
 size_t _copy_mc_to_iter(const void *addr, size_t bytes, struct iov_iter *i)
 {
@@ -744,7 +746,7 @@ EXPORT_SYMBOL(_copy_from_iter_nocache);
  * _copy_from_iter_flushcache - write destination through cpu cache
  * @addr: destination kernel address
  * @bytes: total transfer length
- * @iter: source iterator
+ * @i: source iterator
  *
  * The pmem driver arranges for filesystem-dax to use this facility via
  * dax_copy_from_iter() for ensuring that writes to persistent memory
@@ -753,6 +755,8 @@ EXPORT_SYMBOL(_copy_from_iter_nocache);
  * all iterator types. The _copy_from_iter_nocache() only attempts to
  * bypass the cache for the ITER_IOVEC case, and on some archs may use
  * instructions that strand dirty-data in the cache.
+ *
+ * Return: number of bytes copied (may be %0)
  */
 size_t _copy_from_iter_flushcache(void *addr, size_t bytes, struct iov_iter *i)
 {

_

author maintainer
#129 lore raw

PATCH 107/147 bitops: protect find_first_{,zero}_bit properly

In reply to Andrew Morton

From: Yury Norov <[email protected]>
Subject: bitops: protect find_first_{,zero}_bit properly

Patch series "Resend bitmap patches".

This patch (of 17):

find_first_bit() and find_first_zero_bit() are not protected with ifdefs as other functions in find.h. It causes build errors on some platforms if CONFIG_GENERIC_FIND_FIRST_BIT is enabled.

Fixes 2cc7b6a44ac2 ("lib: add fast path for find_first_*_bit() and find_last_bit()")
Cc Alexander Lobakin <[email protected]>
Cc Alexey Klimov <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Dennis Zhou <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Ulf Hansson <[email protected]>
Cc Will Deacon <[email protected]>

---

 include/asm-generic/bitops/find.h |    5 +++++
 1 file changed, 5 insertions(+)
include/asm-generic/bitops/find.h renamed from include/asm-generic/bitops/find.h~bitops-protect-find_first_zero_bit-properly +5 -0
@@ -97,6 +97,7 @@ unsigned long find_next_zero_bit(const u
 
 #ifdef CONFIG_GENERIC_FIND_FIRST_BIT
 
+#ifndef find_first_bit
 /**
  * find_first_bit - find the first set bit in a memory region
  * @addr: The address to start the search at
@@ -116,7 +117,9 @@ unsigned long find_first_bit(const unsig
 
 	return _find_first_bit(addr, size);
 }
+#endif
 
+#ifndef find_first_zero_bit
 /**
  * find_first_zero_bit - find the first cleared bit in a memory region
  * @addr: The address to start the search at
@@ -136,6 +139,8 @@ unsigned long find_first_zero_bit(const
 
 	return _find_first_zero_bit(addr, size);
 }
+#endif
+
 #else /* CONFIG_GENERIC_FIND_FIRST_BIT */
 
 #ifndef find_first_bit

_

author maintainer
#130 lore raw

PATCH 108/147 bitops: move find_bit_*_le functions from le.h to find.h

In reply to Andrew Morton

From: Yury Norov <[email protected]>
Subject: bitops: move find_bit_*_le functions from le.h to find.h

It's convenient to have all find_bit declarations in one place.

---

 include/asm-generic/bitops/find.h |  193 ----------------------------
 include/asm-generic/bitops/le.h   |   64 ---------
 2 files changed, 257 deletions(-)
include/asm-generic/bitops/find.h deleted +0 -193
@@ -1,193 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _ASM_GENERIC_BITOPS_FIND_H_
-#define _ASM_GENERIC_BITOPS_FIND_H_
-
-extern unsigned long _find_next_bit(const unsigned long *addr1,
-		const unsigned long *addr2, unsigned long nbits,
-		unsigned long start, unsigned long invert, unsigned long le);
-extern unsigned long _find_first_bit(const unsigned long *addr, unsigned long size);
-extern unsigned long _find_first_zero_bit(const unsigned long *addr, unsigned long size);
-extern unsigned long _find_last_bit(const unsigned long *addr, unsigned long size);
-
-#ifndef find_next_bit
-/**
- * find_next_bit - find the next set bit in a memory region
- * @addr: The address to base the search on
- * @offset: The bitnumber to start searching at
- * @size: The bitmap size in bits
- *
- * Returns the bit number for the next set bit
- * If no bits are set, returns @size.
- */
-static inline
-unsigned long find_next_bit(const unsigned long *addr, unsigned long size,
-			    unsigned long offset)
-{
-	if (small_const_nbits(size)) {
-		unsigned long val;
-
-		if (unlikely(offset >= size))
-			return size;
-
-		val = *addr & GENMASK(size - 1, offset);
-		return val ? __ffs(val) : size;
-	}
-
-	return _find_next_bit(addr, NULL, size, offset, 0UL, 0);
-}
-#endif
-
-#ifndef find_next_and_bit
-/**
- * find_next_and_bit - find the next set bit in both memory regions
- * @addr1: The first address to base the search on
- * @addr2: The second address to base the search on
- * @offset: The bitnumber to start searching at
- * @size: The bitmap size in bits
- *
- * Returns the bit number for the next set bit
- * If no bits are set, returns @size.
- */
-static inline
-unsigned long find_next_and_bit(const unsigned long *addr1,
-		const unsigned long *addr2, unsigned long size,
-		unsigned long offset)
-{
-	if (small_const_nbits(size)) {
-		unsigned long val;
-
-		if (unlikely(offset >= size))
-			return size;
-
-		val = *addr1 & *addr2 & GENMASK(size - 1, offset);
-		return val ? __ffs(val) : size;
-	}
-
-	return _find_next_bit(addr1, addr2, size, offset, 0UL, 0);
-}
-#endif
-
-#ifndef find_next_zero_bit
-/**
- * find_next_zero_bit - find the next cleared bit in a memory region
- * @addr: The address to base the search on
- * @offset: The bitnumber to start searching at
- * @size: The bitmap size in bits
- *
- * Returns the bit number of the next zero bit
- * If no bits are zero, returns @size.
- */
-static inline
-unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size,
-				 unsigned long offset)
-{
-	if (small_const_nbits(size)) {
-		unsigned long val;
-
-		if (unlikely(offset >= size))
-			return size;
-
-		val = *addr | ~GENMASK(size - 1, offset);
-		return val == ~0UL ? size : ffz(val);
-	}
-
-	return _find_next_bit(addr, NULL, size, offset, ~0UL, 0);
-}
-#endif
-
-#ifdef CONFIG_GENERIC_FIND_FIRST_BIT
-
-#ifndef find_first_bit
-/**
- * find_first_bit - find the first set bit in a memory region
- * @addr: The address to start the search at
- * @size: The maximum number of bits to search
- *
- * Returns the bit number of the first set bit.
- * If no bits are set, returns @size.
- */
-static inline
-unsigned long find_first_bit(const unsigned long *addr, unsigned long size)
-{
-	if (small_const_nbits(size)) {
-		unsigned long val = *addr & GENMASK(size - 1, 0);
-
-		return val ? __ffs(val) : size;
-	}
-
-	return _find_first_bit(addr, size);
-}
-#endif
-
-#ifndef find_first_zero_bit
-/**
- * find_first_zero_bit - find the first cleared bit in a memory region
- * @addr: The address to start the search at
- * @size: The maximum number of bits to search
- *
- * Returns the bit number of the first cleared bit.
- * If no bits are zero, returns @size.
- */
-static inline
-unsigned long find_first_zero_bit(const unsigned long *addr, unsigned long size)
-{
-	if (small_const_nbits(size)) {
-		unsigned long val = *addr | ~GENMASK(size - 1, 0);
-
-		return val == ~0UL ? size : ffz(val);
-	}
-
-	return _find_first_zero_bit(addr, size);
-}
-#endif
-
-#else /* CONFIG_GENERIC_FIND_FIRST_BIT */
-
-#ifndef find_first_bit
-#define find_first_bit(addr, size) find_next_bit((addr), (size), 0)
-#endif
-#ifndef find_first_zero_bit
-#define find_first_zero_bit(addr, size) find_next_zero_bit((addr), (size), 0)
-#endif
-
-#endif /* CONFIG_GENERIC_FIND_FIRST_BIT */
-
-#ifndef find_last_bit
-/**
- * find_last_bit - find the last set bit in a memory region
- * @addr: The address to start the search at
- * @size: The number of bits to search
- *
- * Returns the bit number of the last set bit, or size.
- */
-static inline
-unsigned long find_last_bit(const unsigned long *addr, unsigned long size)
-{
-	if (small_const_nbits(size)) {
-		unsigned long val = *addr & GENMASK(size - 1, 0);
-
-		return val ? __fls(val) : size;
-	}
-
-	return _find_last_bit(addr, size);
-}
-#endif
-
-/**
- * find_next_clump8 - find next 8-bit clump with set bits in a memory region
- * @clump: location to store copy of found clump
- * @addr: address to base the search on
- * @size: bitmap size in number of bits
- * @offset: bit offset at which to start searching
- *
- * Returns the bit offset for the next set clump; the found clump value is
- * copied to the location pointed by @clump. If no bits are set, returns @size.
- */
-extern unsigned long find_next_clump8(unsigned long *clump,
-				      const unsigned long *addr,
-				      unsigned long size, unsigned long offset);
-
-#define find_first_clump8(clump, bits, size) \
-	find_next_clump8((clump), (bits), (size), 0)
-
-#endif /*_ASM_GENERIC_BITOPS_FIND_H_ */
include/asm-generic/bitops/le.h renamed from include/asm-generic/bitops/le.h~bitops-move-find_bit__le-functions-from-leh-to-findh +0 -64

83 lines not on this page · raw message

_

#131 lore raw

Re: [patch 108/147] bitops: move find_bit_*_le functions from le.h to find.h

Quoted 5 lines · Andrew Morton

From: Yury Norov <[email protected]>
Subject: bitops: move find_bit_*_le functions from le.h to find.h

It's convenient to have all find_bit declarations in one place.

What what what?

The subject line says "move".

The body of the commit message doesn't imply anything else.

But the patch doesn't "move" anything at all:

Quoted 3 lines
 include/asm-generic/bitops/find.h |  193 ----------------------------
 include/asm-generic/bitops/le.h   |   64 ---------
 2 files changed, 257 deletions(-)

What's going on?

Dropped just because I refuse to have anything to do with patches that lie about what they are actually doing.

Linus

maintainer
#132 lore raw

Re: [patch 108/147] bitops: move find_bit_*_le functions from le.h to find.h

Quoted 15 lines · Linus Torvalds
Quoted 5 lines · Andrew Morton

From: Yury Norov <[email protected]>
Subject: bitops: move find_bit_*_le functions from le.h to find.h

It's convenient to have all find_bit declarations in one place.

What what what?

The subject line says "move".

The body of the commit message doesn't imply anything else.

But the patch doesn't "move" anything at all:

Quoted 8 lines
Quoted 3 lines
 include/asm-generic/bitops/find.h |  193 ----------------------------
 include/asm-generic/bitops/le.h   |   64 ---------
 2 files changed, 257 deletions(-)

What's going on?

Dropped just because I refuse to have anything to do with patches that lie about what they are actually doing.

This is how the patch looks in my tree:
https://github.com/norov/linux/commit/4a92b733138e3fd71cd8a021ad53cbce68d61cfc

And in my submission:
http://lkml.iu.edu/hypermail/linux/kernel/2108.1/07330.html

So it actually does what it says. The following patch in this series also differs from what I have in my tree. Something weird happened...

Andrew, Linus, are you OK if I resend the patchset?

Yury

#133 lore raw

Re: [patch 108/147] bitops: move find_bit_*_le functions from le.h to find.h

Quoted 2 lines · Yury Norov

Andrew, Linus, are you OK if I resend the patchset?

I've removed the whole series from my queue, so yes, resending is the right thing.

That said, by now it's starting to be the latter half of the second week of the merge window, and by the time it has gone through the queues, I'm not going to guarantee that I'll be in a mood to merge new stuff any more.

This has not been a particularly huge merge window in number of commits, but there's actually been an unusually large number of these kinds of odd things where I go "that's just not right".

So I've been a bit testy with people (sorry about that), and I'm getting to the point where I just am not feeling very generous to stuff that wasn't all prim and proper and ready by the merge window.

Linus

author maintainer
#134 lore raw

Re: [patch 108/147] bitops: move find_bit_*_le functions from le.h to find.h

In reply to Yury Norov
Quoted 25 lines · On Wed, 8 Sep 2021 12:38:27 -0700 Yury Norov <[email protected]> wrote:
Quoted 15 lines · Linus Torvalds
Quoted 5 lines · Andrew Morton

From: Yury Norov <[email protected]>
Subject: bitops: move find_bit_*_le functions from le.h to find.h

It's convenient to have all find_bit declarations in one place.

What what what?

The subject line says "move".

The body of the commit message doesn't imply anything else.

But the patch doesn't "move" anything at all:

Quoted 8 lines
Quoted 3 lines
 include/asm-generic/bitops/find.h |  193 ----------------------------
 include/asm-generic/bitops/le.h   |   64 ---------
 2 files changed, 257 deletions(-)

What's going on?

Dropped just because I refuse to have anything to do with patches that lie about what they are actually doing.

Quoted 8 lines

This is how the patch looks in my tree:
https://github.com/norov/linux/commit/4a92b733138e3fd71cd8a021ad53cbce68d61cfc

And in my submission:
http://lkml.iu.edu/hypermail/linux/kernel/2108.1/07330.html

So it actually does what it says. The following patch in this series also differs from what I have in my tree. Something weird happened...

There were some competing changes in next for a while so I guess there was damage.

Quoted 1 line

Andrew, Linus, are you OK if I resend the patchset?

Linus suggests other changes. I suggest you get this tree into -next as discussed and put the changes through another kernel cycle.

#135 lore raw

Re: [patch 108/147] bitops: move find_bit_*_le functions from le.h to find.h

Quoted 2 lines · Andrew Morton

Linus suggests other changes.

I _think_ my other objections were to patches in different groups (same 147-email series, but different sub-series).

But I didn't check how you had split things up, so they may end up being related.

I dropped all of the bit finding ones.

I'm in the middle of writing the merge message, I'll do my test builds, and then push out, so you can see exactly what I merged (and by implication, what I did not).

Linus

#136 lore raw

Re: [patch 108/147] bitops: move find_bit_*_le functions from le.h to find.h

Quoted 4 lines · Linus Torvalds

I'm in the middle of writing the merge message, I'll do my test builds, and then push out, so you can see exactly what I merged (and by implication, what I did not).

Ok, so no pr-tracker-bot for the manual patch merges, so here's the equivalent manual "it's merged and pushed out now" notification..

Linus

maintainer
#137 lore raw

Re: [patch 108/147] bitops: move find_bit_*_le functions from le.h to find.h

In reply to Andrew Morton
Quoted 36 lines · Andrew Morton
Quoted 25 lines · On Wed, 8 Sep 2021 12:38:27 -0700 Yury Norov <[email protected]> wrote:
Quoted 15 lines · Linus Torvalds
Quoted 5 lines · Andrew Morton

From: Yury Norov <[email protected]>
Subject: bitops: move find_bit_*_le functions from le.h to find.h

It's convenient to have all find_bit declarations in one place.

What what what?

The subject line says "move".

The body of the commit message doesn't imply anything else.

But the patch doesn't "move" anything at all:

Quoted 8 lines
Quoted 3 lines
 include/asm-generic/bitops/find.h |  193 ----------------------------
 include/asm-generic/bitops/le.h   |   64 ---------
 2 files changed, 257 deletions(-)

What's going on?

Dropped just because I refuse to have anything to do with patches that lie about what they are actually doing.

Quoted 8 lines

This is how the patch looks in my tree:
https://github.com/norov/linux/commit/4a92b733138e3fd71cd8a021ad53cbce68d61cfc

And in my submission:
http://lkml.iu.edu/hypermail/linux/kernel/2108.1/07330.html

So it actually does what it says. The following patch in this series also differs from what I have in my tree. Something weird happened...

Quoted 7 lines

There were some competing changes in next for a while so I guess there was damage.

Quoted 1 line

Andrew, Linus, are you OK if I resend the patchset?

Linus suggests other changes. I suggest you get this tree into -next as discussed and put the changes through another kernel cycle.

OK, I'll resend next week.

author maintainer
#138 lore raw

PATCH 109/147 include: move find.h from asm_generic to linux

In reply to Andrew Morton

From: Yury Norov <[email protected]>
Subject: include: move find.h from asm_generic to linux

find_bit API and bitmap API are closely related, but inclusion paths are different - include/asm-generic and include/linux, correspondingly. In the past it made a lot of troubles due to circular dependencies and/or undefined symbols. Fix this by moving find.h under include/linux.

---

 MAINTAINERS                        |    2 
 arch/alpha/include/asm/bitops.h    |    2 
 arch/arc/include/asm/bitops.h      |    1 
 arch/arm/include/asm/bitops.h      |    1 
 arch/arm64/include/asm/bitops.h    |    1 
 arch/csky/include/asm/bitops.h     |    1 
 arch/h8300/include/asm/bitops.h    |    1 
 arch/hexagon/include/asm/bitops.h  |    1 
 arch/ia64/include/asm/bitops.h     |    2 
 arch/m68k/include/asm/bitops.h     |    2 
 arch/mips/include/asm/bitops.h     |    1 
 arch/openrisc/include/asm/bitops.h |    1 
 arch/parisc/include/asm/bitops.h   |    2 
 arch/powerpc/include/asm/bitops.h  |    2 
 arch/riscv/include/asm/bitops.h    |    1 
 arch/s390/include/asm/bitops.h     |    1 
 arch/sh/include/asm/bitops.h       |    1 
 arch/sparc/include/asm/bitops_32.h |    1 
 arch/sparc/include/asm/bitops_64.h |    2 
 arch/x86/include/asm/bitops.h      |    2 
 arch/xtensa/include/asm/bitops.h   |    1 
 include/asm-generic/bitops.h       |    1 
 include/linux/bitmap.h             |    1 
 include/{asm-generic/bitops => linux}/find.h | 12 +++++++++---
 25 files changed, 270 insertions(+), 291 deletions(-)
arch/alpha/include/asm/bitops.h renamed from arch/alpha/include/asm/bitops.h~include-move-findh-from-asm_generic-to-linux +0 -2
@@ -430,8 +430,6 @@ static inline unsigned int __arch_hweigh
 
 #endif /* __KERNEL__ */
 
-#include <asm-generic/bitops/find.h>
-
 #ifdef __KERNEL__
 
 /*
arch/arc/include/asm/bitops.h renamed from arch/arc/include/asm/bitops.h~include-move-findh-from-asm_generic-to-linux +0 -1
@@ -369,7 +369,6 @@ static inline __attribute__ ((const)) un
 #include <asm-generic/bitops/sched.h>
 #include <asm-generic/bitops/lock.h>
 
-#include <asm-generic/bitops/find.h>
 #include <asm-generic/bitops/le.h>
 #include <asm-generic/bitops/ext2-atomic-setbit.h>
 
arch/arm64/include/asm/bitops.h renamed from arch/arm64/include/asm/bitops.h~include-move-findh-from-asm_generic-to-linux +0 -1
@@ -18,7 +18,6 @@
 
 #include <asm-generic/bitops/ffz.h>
 #include <asm-generic/bitops/fls64.h>
-#include <asm-generic/bitops/find.h>
 
 #include <asm-generic/bitops/sched.h>
 #include <asm-generic/bitops/hweight.h>
arch/arm/include/asm/bitops.h renamed from arch/arm/include/asm/bitops.h~include-move-findh-from-asm_generic-to-linux +0 -1
@@ -264,7 +264,6 @@ static inline int find_next_bit_le(const
 
 #endif
 
-#include <asm-generic/bitops/find.h>
 #include <asm-generic/bitops/le.h>
 
 /*
arch/csky/include/asm/bitops.h renamed from arch/csky/include/asm/bitops.h~include-move-findh-from-asm_generic-to-linux +0 -1
@@ -59,7 +59,6 @@ static __always_inline unsigned long __f
 
 #include <asm-generic/bitops/ffz.h>
 #include <asm-generic/bitops/fls64.h>
-#include <asm-generic/bitops/find.h>
 
 #ifndef _LINUX_BITOPS_H
 #error only <linux/bitops.h> can be included directly
arch/h8300/include/asm/bitops.h renamed from arch/h8300/include/asm/bitops.h~include-move-findh-from-asm_generic-to-linux +0 -1
@@ -168,7 +168,6 @@ static inline unsigned long __ffs(unsign
 	return result;
 }
 
-#include <asm-generic/bitops/find.h>
 #include <asm-generic/bitops/sched.h>
 #include <asm-generic/bitops/hweight.h>
 #include <asm-generic/bitops/lock.h>
arch/hexagon/include/asm/bitops.h renamed from arch/hexagon/include/asm/bitops.h~include-move-findh-from-asm_generic-to-linux +0 -1
@@ -271,7 +271,6 @@ static inline unsigned long __fls(unsign
 }
 
 #include <asm-generic/bitops/lock.h>
-#include <asm-generic/bitops/find.h>
 
 #include <asm-generic/bitops/fls64.h>
 #include <asm-generic/bitops/sched.h>
arch/ia64/include/asm/bitops.h renamed from arch/ia64/include/asm/bitops.h~include-move-findh-from-asm_generic-to-linux +0 -2
@@ -441,8 +441,6 @@ static __inline__ unsigned long __arch_h
 
 #endif /* __KERNEL__ */
 
-#include <asm-generic/bitops/find.h>
-
 #ifdef __KERNEL__
 
 #include <asm-generic/bitops/le.h>
arch/m68k/include/asm/bitops.h renamed from arch/m68k/include/asm/bitops.h~include-move-findh-from-asm_generic-to-linux +0 -2
@@ -529,6 +529,4 @@ static inline int __fls(int x)
 #include <asm-generic/bitops/le.h>
 #endif /* __KERNEL__ */
 
-#include <asm-generic/bitops/find.h>
-
 #endif /* _M68K_BITOPS_H */
arch/mips/include/asm/bitops.h renamed from arch/mips/include/asm/bitops.h~include-move-findh-from-asm_generic-to-linux +0 -1
@@ -446,7 +446,6 @@ static inline int ffs(int word)
 }
 
 #include <asm-generic/bitops/ffz.h>
-#include <asm-generic/bitops/find.h>
 
 #ifdef __KERNEL__
 
arch/openrisc/include/asm/bitops.h renamed from arch/openrisc/include/asm/bitops.h~include-move-findh-from-asm_generic-to-linux +0 -1
@@ -30,7 +30,6 @@
 #include <asm/bitops/fls.h>
 #include <asm/bitops/__fls.h>
 #include <asm-generic/bitops/fls64.h>
-#include <asm-generic/bitops/find.h>
 
 #ifndef _LINUX_BITOPS_H
 #error only <linux/bitops.h> can be included directly
arch/parisc/include/asm/bitops.h renamed from arch/parisc/include/asm/bitops.h~include-move-findh-from-asm_generic-to-linux +0 -2
@@ -208,8 +208,6 @@ static __inline__ int fls(unsigned int x
 
 #endif /* __KERNEL__ */
 
-#include <asm-generic/bitops/find.h>
-
 #ifdef __KERNEL__
 
 #include <asm-generic/bitops/le.h>
arch/powerpc/include/asm/bitops.h renamed from arch/powerpc/include/asm/bitops.h~include-move-findh-from-asm_generic-to-linux +0 -2
@@ -255,8 +255,6 @@ unsigned long __arch_hweight64(__u64 w);
 #include <asm-generic/bitops/hweight.h>
 #endif
 
-#include <asm-generic/bitops/find.h>
-
 /* wrappers that deal with KASAN instrumentation */
 #include <asm-generic/bitops/instrumented-atomic.h>
 #include <asm-generic/bitops/instrumented-lock.h>
arch/riscv/include/asm/bitops.h renamed from arch/riscv/include/asm/bitops.h~include-move-findh-from-asm_generic-to-linux +0 -1
@@ -20,7 +20,6 @@
 #include <asm-generic/bitops/fls.h>
 #include <asm-generic/bitops/__fls.h>
 #include <asm-generic/bitops/fls64.h>
-#include <asm-generic/bitops/find.h>
 #include <asm-generic/bitops/sched.h>
 #include <asm-generic/bitops/ffs.h>
 
arch/s390/include/asm/bitops.h renamed from arch/s390/include/asm/bitops.h~include-move-findh-from-asm_generic-to-linux +0 -1
@@ -387,7 +387,6 @@ static inline int fls(unsigned int word)
 #endif /* CONFIG_HAVE_MARCH_Z9_109_FEATURES */
 
 #include <asm-generic/bitops/ffz.h>
-#include <asm-generic/bitops/find.h>
 #include <asm-generic/bitops/hweight.h>
 #include <asm-generic/bitops/sched.h>
 #include <asm-generic/bitops/le.h>
arch/sh/include/asm/bitops.h renamed from arch/sh/include/asm/bitops.h~include-move-findh-from-asm_generic-to-linux +0 -1
@@ -68,6 +68,5 @@ static inline unsigned long __ffs(unsign
 #include <asm-generic/bitops/fls64.h>
 
 #include <asm-generic/bitops/le.h>
-#include <asm-generic/bitops/find.h>
 
 #endif /* __ASM_SH_BITOPS_H */
arch/sparc/include/asm/bitops_32.h renamed from arch/sparc/include/asm/bitops_32.h~include-move-findh-from-asm_generic-to-linux +0 -1
@@ -100,7 +100,6 @@ static inline void change_bit(unsigned l
 #include <asm-generic/bitops/fls64.h>
 #include <asm-generic/bitops/hweight.h>
 #include <asm-generic/bitops/lock.h>
-#include <asm-generic/bitops/find.h>
 #include <asm-generic/bitops/le.h>
 #include <asm-generic/bitops/ext2-atomic.h>
 
arch/sparc/include/asm/bitops_64.h renamed from arch/sparc/include/asm/bitops_64.h~include-move-findh-from-asm_generic-to-linux +0 -2
@@ -52,8 +52,6 @@ unsigned int __arch_hweight8(unsigned in
 #include <asm-generic/bitops/lock.h>
 #endif /* __KERNEL__ */
 
-#include <asm-generic/bitops/find.h>
-
 #ifdef __KERNEL__
 
 #include <asm-generic/bitops/le.h>
arch/x86/include/asm/bitops.h renamed from arch/x86/include/asm/bitops.h~include-move-findh-from-asm_generic-to-linux +0 -2
@@ -380,8 +380,6 @@ static __always_inline int fls64(__u64 x
 #include <asm-generic/bitops/fls64.h>
 #endif
 
-#include <asm-generic/bitops/find.h>
-
 #include <asm-generic/bitops/sched.h>
 
 #include <asm/arch_hweight.h>
arch/xtensa/include/asm/bitops.h renamed from arch/xtensa/include/asm/bitops.h~include-move-findh-from-asm_generic-to-linux +0 -1
@@ -205,7 +205,6 @@ BIT_OPS(change, "xor", )
 #undef BIT_OP
 #undef TEST_AND_BIT_OP
 
-#include <asm-generic/bitops/find.h>
 #include <asm-generic/bitops/le.h>
 
 #include <asm-generic/bitops/ext2-atomic-setbit.h>
include/asm-generic/bitops.h renamed from include/asm-generic/bitops.h~include-move-findh-from-asm_generic-to-linux +0 -1
@@ -20,7 +20,6 @@
 #include <asm-generic/bitops/fls.h>
 #include <asm-generic/bitops/__fls.h>
 #include <asm-generic/bitops/fls64.h>
-#include <asm-generic/bitops/find.h>
 
 #ifndef _LINUX_BITOPS_H
 #error only <linux/bitops.h> can be included directly
include/linux/bitmap.h renamed from include/linux/bitmap.h~include-move-findh-from-asm_generic-to-linux +1 -0
@@ -6,6 +6,7 @@
 
 #include <linux/align.h>
 #include <linux/bitops.h>
+#include <linux/find.h>
 #include <linux/limits.h>
 #include <linux/string.h>
 #include <linux/types.h>
MAINTAINERS renamed from MAINTAINERS~include-move-findh-from-asm_generic-to-linux +1 -1
@@ -3262,8 +3262,8 @@ M:	Yury Norov <[email protected]>
 R:	Andy Shevchenko <[email protected]>
 R:	Rasmus Villemoes <[email protected]>
 S:	Maintained
-F:	include/asm-generic/bitops/find.h
 F:	include/linux/bitmap.h
+F:	include/linux/find.h
 F:	lib/bitmap.c
 F:	lib/find_bit.c
 F:	lib/find_bit_benchmark.c

_

author maintainer
#139 lore raw

PATCH 110/147 arch: remove GENERIC_FIND_FIRST_BIT entirely

In reply to Andrew Morton

From: Yury Norov <[email protected]>
Subject: arch: remove GENERIC_FIND_FIRST_BIT entirely

In 5.12 cycle we enabled GENERIC_FIND_FIRST_BIT config option for ARM64 and MIPS. It increased performance and shrunk .text size; and so far I didn't receive any negative feedback on the change.

https://lore.kernel.org/linux-arch/[email protected]/

Now I think it's a good time to switch all architectures to use find_{first,last}_bit() unconditionally, and so remove corresponding config option.

The patch does't introduce functioal changes for arc, arm, arm64, mips, m68k, s390 and x86, for other architectures I expect improvement both in performance and .text size.

---

 arch/arc/Kconfig     |    1 -
 arch/arm64/Kconfig   |    1 -
 arch/mips/Kconfig    |    1 -
 arch/s390/Kconfig    |    1 -
 arch/x86/Kconfig     |    1 -
 arch/x86/um/Kconfig  |    1 -
 include/linux/find.h |   13 -------------
 lib/Kconfig          |    3 ---
 8 files changed, 22 deletions(-)
arch/arc/Kconfig renamed from arch/arc/Kconfig~arch-remove-generic_find_first_bit-entirely +0 -1
@@ -20,7 +20,6 @@ config ARC
 	select COMMON_CLK
 	select DMA_DIRECT_REMAP
 	select GENERIC_ATOMIC64 if !ISA_ARCV2 || !(ARC_HAS_LL64 && ARC_HAS_LLSC)
-	select GENERIC_FIND_FIRST_BIT
 	# for now, we don't need GENERIC_IRQ_PROBE, CONFIG_GENERIC_IRQ_CHIP
 	select GENERIC_IRQ_SHOW
 	select GENERIC_PCI_IOMAP
arch/arm64/Kconfig renamed from arch/arm64/Kconfig~arch-remove-generic_find_first_bit-entirely +0 -1
@@ -119,7 +119,6 @@ config ARM64
 	select GENERIC_CPU_AUTOPROBE
 	select GENERIC_CPU_VULNERABILITIES
 	select GENERIC_EARLY_IOREMAP
-	select GENERIC_FIND_FIRST_BIT
 	select GENERIC_IDLE_POLL_SETUP
 	select GENERIC_IRQ_IPI
 	select GENERIC_IRQ_PROBE
arch/mips/Kconfig renamed from arch/mips/Kconfig~arch-remove-generic_find_first_bit-entirely +0 -1
@@ -30,7 +30,6 @@ config MIPS
 	select GENERIC_ATOMIC64 if !64BIT
 	select GENERIC_CMOS_UPDATE
 	select GENERIC_CPU_AUTOPROBE
-	select GENERIC_FIND_FIRST_BIT
 	select GENERIC_GETTIMEOFDAY
 	select GENERIC_IOMAP
 	select GENERIC_IRQ_PROBE
arch/s390/Kconfig renamed from arch/s390/Kconfig~arch-remove-generic_find_first_bit-entirely +0 -1
@@ -126,7 +126,6 @@ config S390
 	select GENERIC_CPU_AUTOPROBE
 	select GENERIC_CPU_VULNERABILITIES
 	select GENERIC_ENTRY
-	select GENERIC_FIND_FIRST_BIT
 	select GENERIC_GETTIMEOFDAY
 	select GENERIC_PTDUMP
 	select GENERIC_SMP_IDLE_THREAD
arch/x86/Kconfig renamed from arch/x86/Kconfig~arch-remove-generic_find_first_bit-entirely +0 -1
@@ -133,7 +133,6 @@ config X86
 	select GENERIC_CPU_VULNERABILITIES
 	select GENERIC_EARLY_IOREMAP
 	select GENERIC_ENTRY
-	select GENERIC_FIND_FIRST_BIT
 	select GENERIC_IOMAP
 	select GENERIC_IRQ_EFFECTIVE_AFF_MASK	if SMP
 	select GENERIC_IRQ_MATRIX_ALLOCATOR	if X86_LOCAL_APIC
arch/x86/um/Kconfig renamed from arch/x86/um/Kconfig~arch-remove-generic_find_first_bit-entirely +0 -1
@@ -8,7 +8,6 @@ endmenu
 
 config UML_X86
 	def_bool y
-	select GENERIC_FIND_FIRST_BIT
 
 config 64BIT
 	bool "64-bit kernel" if "$(SUBARCH)" = "x86"
include/linux/find.h renamed from include/linux/find.h~arch-remove-generic_find_first_bit-entirely +0 -13
@@ -101,8 +101,6 @@ unsigned long find_next_zero_bit(const u
 }
 #endif
 
-#ifdef CONFIG_GENERIC_FIND_FIRST_BIT
-
 #ifndef find_first_bit
 /**
  * find_first_bit - find the first set bit in a memory region
@@ -147,17 +145,6 @@ unsigned long find_first_zero_bit(const
 }
 #endif
 
-#else /* CONFIG_GENERIC_FIND_FIRST_BIT */
-
-#ifndef find_first_bit
-#define find_first_bit(addr, size) find_next_bit((addr), (size), 0)
-#endif
-#ifndef find_first_zero_bit
-#define find_first_zero_bit(addr, size) find_next_zero_bit((addr), (size), 0)
-#endif
-
-#endif /* CONFIG_GENERIC_FIND_FIRST_BIT */
-
 #ifndef find_last_bit
 /**
  * find_last_bit - find the last set bit in a memory region
lib/Kconfig renamed from lib/Kconfig~arch-remove-generic_find_first_bit-entirely +0 -3
@@ -59,9 +59,6 @@ config GENERIC_STRNLEN_USER
 config GENERIC_NET_UTILS
 	bool
 
-config GENERIC_FIND_FIRST_BIT
-	bool
-
 source "lib/math/Kconfig"
 
 config NO_GENERIC_PCI_IOPORT_MAP

_

author maintainer
#140 lore raw

PATCH 111/147 lib: add find_first_and_bit()

In reply to Andrew Morton

From: Yury Norov <[email protected]>
Subject: lib: add find_first_and_bit()

Currently find_first_and_bit() is an alias to find_next_and_bit(). However, it is widely used in cpumask, so it worth to optimize it. This patch adds its own implementation for find_first_and_bit().

On x86_64 find_bit_benchmark says:

Before (#define find_first_and_bit(...) find_next_and_bit(..., 0):
Start testing find_bit() with random-filled bitmap

[  140.291468] find_first_and_bit:           46890919 ns,  32671 iterations
Start testing find_bit() with sparse bitmap
[  140.295028] find_first_and_bit:               7103 ns,      1 iterations

After:
Start testing find_bit() with random-filled bitmap

[  162.574907] find_first_and_bit:           25045813 ns,  32846 iterations
Start testing find_bit() with sparse bitmap
[  162.578458] find_first_and_bit:               4900 ns,      1 iterations

(Thanks to Alexey Klimov for thorough testing.)

---

 include/linux/find.h     |   27 +++++++++++++++++++++++++++
 lib/find_bit.c           |   21 +++++++++++++++++++++
 lib/find_bit_benchmark.c |   21 +++++++++++++++++++++
 3 files changed, 69 insertions(+)
include/linux/find.h renamed from include/linux/find.h~lib-add-find_first_and_bit +27 -0
@@ -12,6 +12,8 @@ extern unsigned long _find_next_bit(cons
 		const unsigned long *addr2, unsigned long nbits,
 		unsigned long start, unsigned long invert, unsigned long le);
 extern unsigned long _find_first_bit(const unsigned long *addr, unsigned long size);
+extern unsigned long _find_first_and_bit(const unsigned long *addr1,
+					 const unsigned long *addr2, unsigned long size);
 extern unsigned long _find_first_zero_bit(const unsigned long *addr, unsigned long size);
 extern unsigned long _find_last_bit(const unsigned long *addr, unsigned long size);
 
@@ -123,6 +125,31 @@ unsigned long find_first_bit(const unsig
 }
 #endif
 
+#ifndef find_first_and_bit
+/**
+ * find_first_and_bit - find the first set bit in both memory regions
+ * @addr1: The first address to base the search on
+ * @addr2: The second address to base the search on
+ * @size: The bitmap size in bits
+ *
+ * Returns the bit number for the next set bit
+ * If no bits are set, returns @size.
+ */
+static inline
+unsigned long find_first_and_bit(const unsigned long *addr1,
+				 const unsigned long *addr2,
+				 unsigned long size)
+{
+	if (small_const_nbits(size)) {
+		unsigned long val = *addr1 & *addr2 & GENMASK(size - 1, 0);
+
+		return val ? __ffs(val) : size;
+	}
+
+	return _find_first_and_bit(addr1, addr2, size);
+}
+#endif
+
 #ifndef find_first_zero_bit
 /**
  * find_first_zero_bit - find the first cleared bit in a memory region
lib/find_bit_benchmark.c renamed from lib/find_bit_benchmark.c~lib-add-find_first_and_bit +21 -0
@@ -49,6 +49,25 @@ static int __init test_find_first_bit(vo
 	return 0;
 }
 
+static int __init test_find_first_and_bit(void *bitmap, const void *bitmap2, unsigned long len)
+{
+	static DECLARE_BITMAP(cp, BITMAP_LEN) __initdata;
+	unsigned long i, cnt;
+	ktime_t time;
+
+	bitmap_copy(cp, bitmap, BITMAP_LEN);
+
+	time = ktime_get();
+	for (cnt = i = 0; i < len; cnt++) {
+		i = find_first_and_bit(cp, bitmap2, len);
+		__clear_bit(i, cp);
+	}
+	time = ktime_get() - time;
+	pr_err("find_first_and_bit: %18llu ns, %6ld iterations\n", time, cnt);
+
+	return 0;
+}
+
 static int __init test_find_next_bit(const void *bitmap, unsigned long len)
 {
 	unsigned long i, cnt;
@@ -129,6 +148,7 @@ static int __init find_bit_test(void)
 	 * traverse only part of bitmap to avoid soft lockup.
 	 */
 	test_find_first_bit(bitmap, BITMAP_LEN / 10);
+	test_find_first_and_bit(bitmap, bitmap2, BITMAP_LEN / 2);
 	test_find_next_and_bit(bitmap, bitmap2, BITMAP_LEN);
 
 	pr_err("\nStart testing find_bit() with sparse bitmap\n");
@@ -145,6 +165,7 @@ static int __init find_bit_test(void)
 	test_find_next_zero_bit(bitmap, BITMAP_LEN);
 	test_find_last_bit(bitmap, BITMAP_LEN);
 	test_find_first_bit(bitmap, BITMAP_LEN);
+	test_find_first_and_bit(bitmap, bitmap2, BITMAP_LEN);
 	test_find_next_and_bit(bitmap, bitmap2, BITMAP_LEN);
 
 	/*
lib/find_bit.c renamed from lib/find_bit.c~lib-add-find_first_and_bit +21 -0
@@ -89,6 +89,27 @@ unsigned long _find_first_bit(const unsi
 EXPORT_SYMBOL(_find_first_bit);
 #endif
 
+#ifndef find_first_and_bit
+/*
+ * Find the first set bit in two memory regions.
+ */
+unsigned long _find_first_and_bit(const unsigned long *addr1,
+				  const unsigned long *addr2,
+				  unsigned long size)
+{
+	unsigned long idx, val;
+
+	for (idx = 0; idx * BITS_PER_LONG < size; idx++) {
+		val = addr1[idx] & addr2[idx];
+		if (val)
+			return min(idx * BITS_PER_LONG + __ffs(val), size);
+	}
+
+	return size;
+}
+EXPORT_SYMBOL(_find_first_and_bit);
+#endif
+
 #ifndef find_first_zero_bit
 /*
  * Find the first cleared bit in a memory region.

_

author maintainer
#141 lore raw

PATCH 112/147 cpumask: use find_first_and_bit()

In reply to Andrew Morton

From: Yury Norov <[email protected]>
Subject: cpumask: use find_first_and_bit()

Now we have an efficient implementation for find_first_and_bit(), so switch cpumask to use it where appropriate.

---

 include/linux/cpumask.h |   30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)
include/linux/cpumask.h renamed from include/linux/cpumask.h~cpumask-use-find_first_and_bit +20 -10
@@ -123,6 +123,12 @@ static inline unsigned int cpumask_first
 	return 0;
 }
 
+static inline unsigned int cpumask_first_and(const struct cpumask *srcp1,
+					     const struct cpumask *srcp2)
+{
+	return 0;
+}
+
 static inline unsigned int cpumask_last(const struct cpumask *srcp)
 {
 	return 0;
@@ -167,7 +173,7 @@ static inline unsigned int cpumask_local
 
 static inline int cpumask_any_and_distribute(const struct cpumask *src1p,
 					     const struct cpumask *src2p) {
-	return cpumask_next_and(-1, src1p, src2p);
+	return cpumask_first_and(src1p, src2p);
 }
 
 static inline int cpumask_any_distribute(const struct cpumask *srcp)
@@ -196,6 +202,19 @@ static inline unsigned int cpumask_first
 }
 
 /**
+ * cpumask_first_and - return the first cpu from *srcp1 & *srcp2
+ * @src1p: the first input
+ * @src2p: the second input
+ *
+ * Returns >= nr_cpu_ids if no cpus set in both.  See also cpumask_next_and().
+ */
+static inline
+unsigned int cpumask_first_and(const struct cpumask *srcp1, const struct cpumask *srcp2)
+{
+	return find_first_and_bit(cpumask_bits(srcp1), cpumask_bits(srcp2), nr_cpumask_bits);
+}
+
+/**
  * cpumask_last - get the last CPU in a cpumask
  * @srcp:	- the cpumask pointer
  *
@@ -586,15 +605,6 @@ static inline void cpumask_copy(struct c
 #define cpumask_any(srcp) cpumask_first(srcp)
 
 /**
- * cpumask_first_and - return the first cpu from *srcp1 & *srcp2
- * @src1p: the first input
- * @src2p: the second input
- *
- * Returns >= nr_cpu_ids if no cpus set in both.  See also cpumask_next_and().
- */
-#define cpumask_first_and(src1p, src2p) cpumask_next_and(-1, (src1p), (src2p))
-
-/**
  * cpumask_any_and - pick a "random" cpu from *mask1 & *mask2
  * @mask1: the first input cpumask
  * @mask2: the second input cpumask

_

author maintainer
#142 lore raw

PATCH 113/147 all: replace find_next{,_zero}_bit with find_first{,_zero}_bit where appropriate

In reply to Andrew Morton

From: Yury Norov <[email protected]>
Subject: all: replace find_next{,_zero}_bit with find_first{,_zero}_bit where appropriate

find_first{,_zero}_bit is a more effective analogue of 'next' version if start == 0. This patch replaces 'next' with 'first' where things look trivial.

---

 arch/powerpc/platforms/pasemi/dma_lib.c |    4 ++--
 arch/s390/kvm/kvm-s390.c                |    2 +-
 drivers/block/rnbd/rnbd-clt.c           |    2 +-
 drivers/dma/ti/edma.c                   |    2 +-
 drivers/iio/adc/ad7124.c                |    2 +-
 drivers/infiniband/hw/irdma/hw.c        |   16 ++++++++--------
 drivers/media/cec/core/cec-core.c       |    2 +-
 drivers/media/mc/mc-devnode.c           |    2 +-
 drivers/pci/controller/dwc/pci-dra7xx.c |    2 +-
 drivers/scsi/lpfc/lpfc_sli.c            |   10 +++++-----
 drivers/soc/ti/k3-ringacc.c             |    4 ++--
 drivers/tty/n_tty.c                     |    2 +-
 drivers/virt/acrn/ioreq.c               |    3 +--
 fs/f2fs/segment.c                       |    8 ++++----
 fs/ocfs2/cluster/heartbeat.c            |    2 +-
 fs/ocfs2/dlm/dlmdomain.c                |    4 ++--
 fs/ocfs2/dlm/dlmmaster.c                |   18 +++++++++---------
 fs/ocfs2/dlm/dlmrecovery.c              |    2 +-
 fs/ocfs2/dlm/dlmthread.c                |    2 +-
 lib/genalloc.c                          |    2 +-
 net/ncsi/ncsi-manage.c                  |    4 ++--
 21 files changed, 47 insertions(+), 48 deletions(-)
arch/powerpc/platforms/pasemi/dma_lib.c renamed from arch/powerpc/platforms/pasemi/dma_lib.c~all-replace-find_next_zero_bit-with-find_first_zero_bit-where-appropriate +2 -2
@@ -375,7 +375,7 @@ int pasemi_dma_alloc_flag(void)
 	int bit;
 
 retry:
-	bit = find_next_bit(flags_free, MAX_FLAGS, 0);
+	bit = find_first_bit(flags_free, MAX_FLAGS);
 	if (bit >= MAX_FLAGS)
 		return -ENOSPC;
 	if (!test_and_clear_bit(bit, flags_free))
@@ -440,7 +440,7 @@ int pasemi_dma_alloc_fun(void)
 	int bit;
 
 retry:
-	bit = find_next_bit(fun_free, MAX_FLAGS, 0);
+	bit = find_first_bit(fun_free, MAX_FLAGS);
 	if (bit >= MAX_FLAGS)
 		return -ENOSPC;
 	if (!test_and_clear_bit(bit, fun_free))
arch/s390/kvm/kvm-s390.c renamed from arch/s390/kvm/kvm-s390.c~all-replace-find_next_zero_bit-with-find_first_zero_bit-where-appropriate +1 -1
@@ -2023,7 +2023,7 @@ static unsigned long kvm_s390_next_dirty
 	while ((slotidx > 0) && (ofs >= ms->npages)) {
 		slotidx--;
 		ms = slots->memslots + slotidx;
-		ofs = find_next_bit(kvm_second_dirty_bitmap(ms), ms->npages, 0);
+		ofs = find_first_bit(kvm_second_dirty_bitmap(ms), ms->npages);
 	}
 	return ms->base_gfn + ofs;
 }
drivers/block/rnbd/rnbd-clt.c renamed from drivers/block/rnbd/rnbd-clt.c~all-replace-find_next_zero_bit-with-find_first_zero_bit-where-appropriate +1 -1
@@ -196,7 +196,7 @@ rnbd_get_cpu_qlist(struct rnbd_clt_sessi
 		return per_cpu_ptr(sess->cpu_queues, bit);
 	} else if (cpu != 0) {
 		/* Search from 0 to cpu */
-		bit = find_next_bit(sess->cpu_queues_bm, cpu, 0);
+		bit = find_first_bit(sess->cpu_queues_bm, cpu);
 		if (bit < cpu)
 			return per_cpu_ptr(sess->cpu_queues, bit);
 	}
drivers/dma/ti/edma.c renamed from drivers/dma/ti/edma.c~all-replace-find_next_zero_bit-with-find_first_zero_bit-where-appropriate +1 -1
@@ -1681,7 +1681,7 @@ static irqreturn_t dma_ccerr_handler(int
 
 			dev_dbg(ecc->dev, "EMR%d 0x%08x\n", j, val);
 			emr = val;
-			for (i = find_next_bit(&emr, 32, 0); i < 32;
+			for (i = find_first_bit(&emr, 32); i < 32;
 			     i = find_next_bit(&emr, 32, i + 1)) {
 				int k = (j << 5) + i;
 
drivers/iio/adc/ad7124.c renamed from drivers/iio/adc/ad7124.c~all-replace-find_next_zero_bit-with-find_first_zero_bit-where-appropriate +1 -1
@@ -347,7 +347,7 @@ static int ad7124_find_free_config_slot(
 {
 	unsigned int free_cfg_slot;
 
-	free_cfg_slot = find_next_zero_bit(&st->cfg_slots_status, AD7124_MAX_CONFIGS, 0);
+	free_cfg_slot = find_first_zero_bit(&st->cfg_slots_status, AD7124_MAX_CONFIGS);
 	if (free_cfg_slot == AD7124_MAX_CONFIGS)
 		return -1;
 
drivers/infiniband/hw/irdma/hw.c renamed from drivers/infiniband/hw/irdma/hw.c~all-replace-find_next_zero_bit-with-find_first_zero_bit-where-appropriate +8 -8
@@ -1696,14 +1696,14 @@ clean_msixtbl:
  */
 static void irdma_get_used_rsrc(struct irdma_device *iwdev)
 {
-	iwdev->rf->used_pds = find_next_zero_bit(iwdev->rf->allocated_pds,
-						 iwdev->rf->max_pd, 0);
-	iwdev->rf->used_qps = find_next_zero_bit(iwdev->rf->allocated_qps,
-						 iwdev->rf->max_qp, 0);
-	iwdev->rf->used_cqs = find_next_zero_bit(iwdev->rf->allocated_cqs,
-						 iwdev->rf->max_cq, 0);
-	iwdev->rf->used_mrs = find_next_zero_bit(iwdev->rf->allocated_mrs,
-						 iwdev->rf->max_mr, 0);
+	iwdev->rf->used_pds = find_first_zero_bit(iwdev->rf->allocated_pds,
+						 iwdev->rf->max_pd);
+	iwdev->rf->used_qps = find_first_zero_bit(iwdev->rf->allocated_qps,
+						 iwdev->rf->max_qp);
+	iwdev->rf->used_cqs = find_first_zero_bit(iwdev->rf->allocated_cqs,
+						 iwdev->rf->max_cq);
+	iwdev->rf->used_mrs = find_first_zero_bit(iwdev->rf->allocated_mrs,
+						 iwdev->rf->max_mr);
 }
 
 void irdma_ctrl_deinit_hw(struct irdma_pci_f *rf)
drivers/media/cec/core/cec-core.c renamed from drivers/media/cec/core/cec-core.c~all-replace-find_next_zero_bit-with-find_first_zero_bit-where-appropriate +1 -1
@@ -106,7 +106,7 @@ static int __must_check cec_devnode_regi
 
 	/* Part 1: Find a free minor number */
 	mutex_lock(&cec_devnode_lock);
-	minor = find_next_zero_bit(cec_devnode_nums, CEC_NUM_DEVICES, 0);
+	minor = find_first_zero_bit(cec_devnode_nums, CEC_NUM_DEVICES);
 	if (minor == CEC_NUM_DEVICES) {
 		mutex_unlock(&cec_devnode_lock);
 		pr_err("could not get a free minor\n");
drivers/media/mc/mc-devnode.c renamed from drivers/media/mc/mc-devnode.c~all-replace-find_next_zero_bit-with-find_first_zero_bit-where-appropriate +1 -1
@@ -217,7 +217,7 @@ int __must_check media_devnode_register(
 
 	/* Part 1: Find a free minor number */
 	mutex_lock(&media_devnode_lock);
-	minor = find_next_zero_bit(media_devnode_nums, MEDIA_NUM_DEVICES, 0);
+	minor = find_first_zero_bit(media_devnode_nums, MEDIA_NUM_DEVICES);
 	if (minor == MEDIA_NUM_DEVICES) {
 		mutex_unlock(&media_devnode_lock);
 		pr_err("could not get a free minor\n");
drivers/pci/controller/dwc/pci-dra7xx.c renamed from drivers/pci/controller/dwc/pci-dra7xx.c~all-replace-find_next_zero_bit-with-find_first_zero_bit-where-appropriate +1 -1
@@ -211,7 +211,7 @@ static int dra7xx_pcie_handle_msi(struct
 	if (!val)
 		return 0;
 
-	pos = find_next_bit(&val, MAX_MSI_IRQS_PER_CTRL, 0);
+	pos = find_first_bit(&val, MAX_MSI_IRQS_PER_CTRL);
 	while (pos != MAX_MSI_IRQS_PER_CTRL) {
 		irq = irq_find_mapping(pp->irq_domain,
 				       (index * MAX_MSI_IRQS_PER_CTRL) + pos);
drivers/scsi/lpfc/lpfc_sli.c renamed from drivers/scsi/lpfc/lpfc_sli.c~all-replace-find_next_zero_bit-with-find_first_zero_bit-where-appropriate +5 -5
@@ -17250,8 +17250,8 @@ lpfc_sli4_alloc_xri(struct lpfc_hba *phb
 	 * the driver starts at 0 each time.
 	 */
 	spin_lock_irq(&phba->hbalock);
-	xri = find_next_zero_bit(phba->sli4_hba.xri_bmask,
-				 phba->sli4_hba.max_cfg_param.max_xri, 0);
+	xri = find_first_zero_bit(phba->sli4_hba.xri_bmask,
+				 phba->sli4_hba.max_cfg_param.max_xri);
 	if (xri >= phba->sli4_hba.max_cfg_param.max_xri) {
 		spin_unlock_irq(&phba->hbalock);
 		return NO_XRI;
@@ -18928,7 +18928,7 @@ lpfc_sli4_alloc_rpi(struct lpfc_hba *phb
 	max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
 	rpi_limit = phba->sli4_hba.next_rpi;
 
-	rpi = find_next_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit, 0);
+	rpi = find_first_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit);
 	if (rpi >= rpi_limit)
 		rpi = LPFC_RPI_ALLOC_ERROR;
 	else {
@@ -19571,8 +19571,8 @@ next_priority:
 		 * have been tested so that we can detect when we should
 		 * change the priority level.
 		 */
-		next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
-					       LPFC_SLI4_FCF_TBL_INDX_MAX, 0);
+		next_fcf_index = find_first_bit(phba->fcf.fcf_rr_bmask,
+					       LPFC_SLI4_FCF_TBL_INDX_MAX);
 	}
 
 
drivers/soc/ti/k3-ringacc.c renamed from drivers/soc/ti/k3-ringacc.c~all-replace-find_next_zero_bit-with-find_first_zero_bit-where-appropriate +2 -2
@@ -358,8 +358,8 @@ struct k3_ring *k3_ringacc_request_ring(
 		goto out;
 
 	if (flags & K3_RINGACC_RING_USE_PROXY) {
-		proxy_id = find_next_zero_bit(ringacc->proxy_inuse,
-					      ringacc->num_proxies, 0);
+		proxy_id = find_first_zero_bit(ringacc->proxy_inuse,
+					      ringacc->num_proxies);
 		if (proxy_id == ringacc->num_proxies)
 			goto error;
 	}
drivers/tty/n_tty.c renamed from drivers/tty/n_tty.c~all-replace-find_next_zero_bit-with-find_first_zero_bit-where-appropriate +1 -1
@@ -1975,7 +1975,7 @@ static bool canon_copy_from_read_buf(str
 	more = n - (size - tail);
 	if (eol == N_TTY_BUF_SIZE && more) {
 		/* scan wrapped without finding set bit */
-		eol = find_next_bit(ldata->read_flags, more, 0);
+		eol = find_first_bit(ldata->read_flags, more);
 		found = eol != more;
 	} else
 		found = eol != size;
drivers/virt/acrn/ioreq.c renamed from drivers/virt/acrn/ioreq.c~all-replace-find_next_zero_bit-with-find_first_zero_bit-where-appropriate +1 -2
@@ -246,8 +246,7 @@ void acrn_ioreq_request_clear(struct acr
 	spin_lock_bh(&vm->ioreq_clients_lock);
 	client = vm->default_client;
 	if (client) {
-		vcpu = find_next_bit(client->ioreqs_map,
-				     ACRN_IO_REQUEST_MAX, 0);
+		vcpu = find_first_bit(client->ioreqs_map, ACRN_IO_REQUEST_MAX);
 		while (vcpu < ACRN_IO_REQUEST_MAX) {
 			acrn_ioreq_complete_request(client, vcpu, NULL);
 			vcpu = find_next_bit(client->ioreqs_map,
fs/f2fs/segment.c renamed from fs/f2fs/segment.c~all-replace-find_next_zero_bit-with-find_first_zero_bit-where-appropriate +4 -4
@@ -2495,8 +2495,8 @@ find_other_zone:
 	secno = find_next_zero_bit(free_i->free_secmap, MAIN_SECS(sbi), hint);
 	if (secno >= MAIN_SECS(sbi)) {
 		if (dir == ALLOC_RIGHT) {
-			secno = find_next_zero_bit(free_i->free_secmap,
-							MAIN_SECS(sbi), 0);
+			secno = find_first_zero_bit(free_i->free_secmap,
+							MAIN_SECS(sbi));
 			f2fs_bug_on(sbi, secno >= MAIN_SECS(sbi));
 		} else {
 			go_left = 1;
@@ -2511,8 +2511,8 @@ find_other_zone:
 			left_start--;
 			continue;
 		}
-		left_start = find_next_zero_bit(free_i->free_secmap,
-							MAIN_SECS(sbi), 0);
+		left_start = find_first_zero_bit(free_i->free_secmap,
+							MAIN_SECS(sbi));
 		f2fs_bug_on(sbi, left_start >= MAIN_SECS(sbi));
 		break;
 	}
fs/ocfs2/cluster/heartbeat.c renamed from fs/ocfs2/cluster/heartbeat.c~all-replace-find_next_zero_bit-with-find_first_zero_bit-where-appropriate +1 -1
@@ -379,7 +379,7 @@ static void o2hb_nego_timeout(struct wor
 
 	o2hb_fill_node_map(live_node_bitmap, sizeof(live_node_bitmap));
 	/* lowest node as master node to make negotiate decision. */
-	master_node = find_next_bit(live_node_bitmap, O2NM_MAX_NODES, 0);
+	master_node = find_first_bit(live_node_bitmap, O2NM_MAX_NODES);
 
 	if (master_node == o2nm_this_node()) {
 		if (!test_bit(master_node, reg->hr_nego_node_bitmap)) {
fs/ocfs2/dlm/dlmdomain.c renamed from fs/ocfs2/dlm/dlmdomain.c~all-replace-find_next_zero_bit-with-find_first_zero_bit-where-appropriate +2 -2
@@ -1045,7 +1045,7 @@ static int dlm_send_regions(struct dlm_c
 	int status, ret = 0, i;
 	char *p;
 
-	if (find_next_bit(node_map, O2NM_MAX_NODES, 0) >= O2NM_MAX_NODES)
+	if (find_first_bit(node_map, O2NM_MAX_NODES) >= O2NM_MAX_NODES)
 		goto bail;
 
 	qr = kzalloc(sizeof(struct dlm_query_region), GFP_KERNEL);
@@ -1217,7 +1217,7 @@ static int dlm_send_nodeinfo(struct dlm_
 	struct o2nm_node *node;
 	int ret = 0, status, count, i;
 
-	if (find_next_bit(node_map, O2NM_MAX_NODES, 0) >= O2NM_MAX_NODES)
+	if (find_first_bit(node_map, O2NM_MAX_NODES) >= O2NM_MAX_NODES)
 		goto bail;
 
 	qn = kzalloc(sizeof(struct dlm_query_nodeinfo), GFP_KERNEL);
fs/ocfs2/dlm/dlmmaster.c renamed from fs/ocfs2/dlm/dlmmaster.c~all-replace-find_next_zero_bit-with-find_first_zero_bit-where-appropriate +9 -9
@@ -861,7 +861,7 @@ lookup:
 		 * to see if there are any nodes that still need to be
 		 * considered.  these will not appear in the mle nodemap
 		 * but they might own this lockres.  wait on them. */
-		bit = find_next_bit(dlm->recovery_map, O2NM_MAX_NODES, 0);
+		bit = find_first_bit(dlm->recovery_map, O2NM_MAX_NODES);
 		if (bit < O2NM_MAX_NODES) {
 			mlog(0, "%s: res %.*s, At least one node (%d) "
 			     "to recover before lock mastery can begin\n",
@@ -912,7 +912,7 @@ redo_request:
 		dlm_wait_for_recovery(dlm);
 
 		spin_lock(&dlm->spinlock);
-		bit = find_next_bit(dlm->recovery_map, O2NM_MAX_NODES, 0);
+		bit = find_first_bit(dlm->recovery_map, O2NM_MAX_NODES);
 		if (bit < O2NM_MAX_NODES) {
 			mlog(0, "%s: res %.*s, At least one node (%d) "
 			     "to recover before lock mastery can begin\n",
@@ -1079,7 +1079,7 @@ recheck:
 		sleep = 1;
 		/* have all nodes responded? */
 		if (voting_done && !*blocked) {
-			bit = find_next_bit(mle->maybe_map, O2NM_MAX_NODES, 0);
+			bit = find_first_bit(mle->maybe_map, O2NM_MAX_NODES);
 			if (dlm->node_num <= bit) {
 				/* my node number is lowest.
 			 	 * now tell other nodes that I am
@@ -1234,8 +1234,8 @@ static int dlm_restart_lock_mastery(stru
 		} else {
 			mlog(ML_ERROR, "node down! %d\n", node);
 			if (blocked) {
-				int lowest = find_next_bit(mle->maybe_map,
-						       O2NM_MAX_NODES, 0);
+				int lowest = find_first_bit(mle->maybe_map,
+						       O2NM_MAX_NODES);
 
 				/* act like it was never there */
 				clear_bit(node, mle->maybe_map);
@@ -1795,7 +1795,7 @@ int dlm_assert_master_handler(struct o2n
 		     "MLE for it! (%.*s)\n", assert->node_idx,
 		     namelen, name);
 	} else {
-		int bit = find_next_bit (mle->maybe_map, O2NM_MAX_NODES, 0);
+		int bit = find_first_bit(mle->maybe_map, O2NM_MAX_NODES);
 		if (bit >= O2NM_MAX_NODES) {
 			/* not necessarily an error, though less likely.
 			 * could be master just re-asserting. */
@@ -2521,7 +2521,7 @@ static int dlm_is_lockres_migratable(str
 	}
 
 	if (!nonlocal) {
-		node_ref = find_next_bit(res->refmap, O2NM_MAX_NODES, 0);
+		node_ref = find_first_bit(res->refmap, O2NM_MAX_NODES);
 		if (node_ref >= O2NM_MAX_NODES)
 			return 0;
 	}
@@ -3303,7 +3303,7 @@ static void dlm_clean_block_mle(struct d
 	BUG_ON(mle->type != DLM_MLE_BLOCK);
 
 	spin_lock(&mle->spinlock);
-	bit = find_next_bit(mle->maybe_map, O2NM_MAX_NODES, 0);
+	bit = find_first_bit(mle->maybe_map, O2NM_MAX_NODES);
 	if (bit != dead_node) {
 		mlog(0, "mle found, but dead node %u would not have been "
 		     "master\n", dead_node);
@@ -3542,7 +3542,7 @@ void dlm_force_free_mles(struct dlm_ctxt
 	spin_lock(&dlm->master_lock);
 
 	BUG_ON(dlm->dlm_state != DLM_CTXT_LEAVING);
-	BUG_ON((find_next_bit(dlm->domain_map, O2NM_MAX_NODES, 0) < O2NM_MAX_NODES));
+	BUG_ON((find_first_bit(dlm->domain_map, O2NM_MAX_NODES) < O2NM_MAX_NODES));
 
 	for (i = 0; i < DLM_HASH_BUCKETS; i++) {
 		bucket = dlm_master_hash(dlm, i);
fs/ocfs2/dlm/dlmrecovery.c renamed from fs/ocfs2/dlm/dlmrecovery.c~all-replace-find_next_zero_bit-with-find_first_zero_bit-where-appropriate +1 -1
@@ -451,7 +451,7 @@ static int dlm_do_recovery(struct dlm_ct
 	if (dlm->reco.dead_node == O2NM_INVALID_NODE_NUM) {
 		int bit;
 
-		bit = find_next_bit (dlm->recovery_map, O2NM_MAX_NODES, 0);
+		bit = find_first_bit(dlm->recovery_map, O2NM_MAX_NODES);
 		if (bit >= O2NM_MAX_NODES || bit < 0)
 			dlm_set_reco_dead_node(dlm, O2NM_INVALID_NODE_NUM);
 		else
fs/ocfs2/dlm/dlmthread.c renamed from fs/ocfs2/dlm/dlmthread.c~all-replace-find_next_zero_bit-with-find_first_zero_bit-where-appropriate +1 -1
@@ -92,7 +92,7 @@ int __dlm_lockres_unused(struct dlm_lock
 		return 0;
 
 	/* Another node has this resource with this node as the master */
-	bit = find_next_bit(res->refmap, O2NM_MAX_NODES, 0);
+	bit = find_first_bit(res->refmap, O2NM_MAX_NODES);
 	if (bit < O2NM_MAX_NODES)
 		return 0;
 
lib/genalloc.c renamed from lib/genalloc.c~all-replace-find_next_zero_bit-with-find_first_zero_bit-where-appropriate +1 -1
@@ -251,7 +251,7 @@ void gen_pool_destroy(struct gen_pool *p
 		list_del(&chunk->next_chunk);
 
 		end_bit = chunk_size(chunk) >> order;
-		bit = find_next_bit(chunk->bits, end_bit, 0);
+		bit = find_first_bit(chunk->bits, end_bit);
 		BUG_ON(bit < end_bit);
 
 		vfree(chunk);
net/ncsi/ncsi-manage.c renamed from net/ncsi/ncsi-manage.c~all-replace-find_next_zero_bit-with-find_first_zero_bit-where-appropriate +2 -2
@@ -608,7 +608,7 @@ static int clear_one_vid(struct ncsi_dev
 	bitmap = &ncf->bitmap;
 
 	spin_lock_irqsave(&nc->lock, flags);
-	index = find_next_bit(bitmap, ncf->n_vids, 0);
+	index = find_first_bit(bitmap, ncf->n_vids);
 	if (index >= ncf->n_vids) {
 		spin_unlock_irqrestore(&nc->lock, flags);
 		return -1;
@@ -667,7 +667,7 @@ static int set_one_vid(struct ncsi_dev_p
 		return -1;
 	}
 
-	index = find_next_zero_bit(bitmap, ncf->n_vids, 0);
+	index = find_first_zero_bit(bitmap, ncf->n_vids);
 	if (index < 0 || index >= ncf->n_vids) {
 		netdev_err(ndp->ndev.dev,
 			   "Channel %u already has all VLAN filters set\n",

_

author maintainer
#143 lore raw

PATCH 114/147 tools: sync tools/bitmap with mother linux

In reply to Andrew Morton

From: Yury Norov <[email protected]>
Subject: tools: sync tools/bitmap with mother linux

Remove tools/include/asm-generic/bitops/find.h and copy include/linux/bitmap.h to tools. find_*_le() functions are not copied because not needed in tools.

---

 MAINTAINERS                                   |  2 +-
 tools/include/asm-generic/bitops.h            |  1 -
 tools/include/linux/bitmap.h                  |  7 +-
 .../{asm-generic/bitops => linux}/find.h      | 81 +++++++++++++++++--
 tools/lib/find_bit.c                          | 20 +++++
 5 files changed, 100 insertions(+), 11 deletions(-)
 rename tools/include/{asm-generic/bitops => linux}/find.h (63%)
MAINTAINERS +1 -1
index 9b62293f7b72..b033083dbb42 100644
@@ -3277,8 +3277,8 @@ F:	lib/bitmap.c
 F:	lib/find_bit.c
 F:	lib/find_bit_benchmark.c
 F:	lib/test_bitmap.c
-F:	tools/include/asm-generic/bitops/find.h
 F:	tools/include/linux/bitmap.h
+F:	tools/include/linux/find.h
 F:	tools/lib/bitmap.c
 F:	tools/lib/find_bit.c
 
tools/include/asm-generic/bitops.h +0 -1
index 5d2ab38965cc..9ab313e93555 100644
@@ -18,7 +18,6 @@
 #include <asm-generic/bitops/fls.h>
 #include <asm-generic/bitops/__fls.h>
 #include <asm-generic/bitops/fls64.h>
-#include <asm-generic/bitops/find.h>
 
 #ifndef _TOOLS_LINUX_BITOPS_H_
 #error only <linux/bitops.h> can be included directly
tools/include/linux/bitmap.h +4 -3
index 9d959bc24859..13d90b574970 100644
@@ -1,9 +1,10 @@
 /* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _PERF_BITOPS_H
-#define _PERF_BITOPS_H
+#ifndef _TOOLS_LINUX_BITMAP_H
+#define _TOOLS_LINUX_BITMAP_H
 
 #include <string.h>
 #include <linux/bitops.h>
+#include <linux/find.h>
 #include <stdlib.h>
 #include <linux/kernel.h>
 
@@ -181,4 +182,4 @@ static inline int bitmap_intersects(const unsigned long *src1,
 		return __bitmap_intersects(src1, src2, nbits);
 }
 
-#endif /* _PERF_BITOPS_H */
+#endif /* _TOOLS_LINUX_BITMAP_H */
tools/include/linux/find.h renamed from tools/include/asm-generic/bitops/find.h +75 -6

108 lines not on this page · raw message

tools/lib/find_bit.c +20 -0
index 109aa7ffcf97..ba4b8d94e004 100644
@@ -96,6 +96,26 @@ unsigned long _find_first_bit(const unsigned long *addr, unsigned long size)
 }
 #endif
 
+#ifndef find_first_and_bit
+/*
+ * Find the first set bit in two memory regions.
+ */
+unsigned long _find_first_and_bit(const unsigned long *addr1,
+				  const unsigned long *addr2,
+				  unsigned long size)
+{
+	unsigned long idx, val;
+
+	for (idx = 0; idx * BITS_PER_LONG < size; idx++) {
+		val = addr1[idx] & addr2[idx];
+		if (val)
+			return min(idx * BITS_PER_LONG + __ffs(val), size);
+	}
+
+	return size;
+}
+#endif
+
 #ifndef find_first_zero_bit
 /*
  * Find the first cleared bit in a memory region.
Signature · 1 line
_
author maintainer
#144 lore raw

PATCH 115/147 cpumask: replace cpumask_next_* with cpumask_first_* where appropriate

In reply to Andrew Morton

From: Yury Norov <[email protected]>
Subject: cpumask: replace cpumask_next_* with cpumask_first_* where appropriate

cpumask_first() is a more effective analogue of 'next' version if n == -1 (which means start == 0). This patch replaces 'next' with 'first' where things look trivial.

There's no cpumask_first_zero() function, so create it.

---

 arch/powerpc/include/asm/cputhreads.h |    2 +-
 block/blk-mq.c                        |    2 +-
 drivers/net/virtio_net.c              |    2 +-
 drivers/soc/fsl/qbman/bman_portal.c   |    2 +-
 drivers/soc/fsl/qbman/qman_portal.c   |    2 +-
 include/linux/cpumask.h               |   16 ++++++++++++++++
 kernel/time/clocksource.c             |    4 ++--
 7 files changed, 23 insertions(+), 7 deletions(-)
arch/powerpc/include/asm/cputhreads.h renamed from arch/powerpc/include/asm/cputhreads.h~cpumask-replace-cpumask_next_-with-cpumask_first_-where-appropriate +1 -1
@@ -52,7 +52,7 @@ static inline cpumask_t cpu_thread_mask_
 	for (i = 0; i < NR_CPUS; i += threads_per_core) {
 		cpumask_shift_left(&tmp, &threads_core_mask, i);
 		if (cpumask_intersects(threads, &tmp)) {
-			cpu = cpumask_next_and(-1, &tmp, cpu_online_mask);
+			cpu = cpumask_first_and(&tmp, cpu_online_mask);
 			if (cpu < nr_cpu_ids)
 				cpumask_set_cpu(cpu, &res);
 		}
block/blk-mq.c renamed from block/blk-mq.c~cpumask-replace-cpumask_next_-with-cpumask_first_-where-appropriate +1 -1
@@ -2524,7 +2524,7 @@ static bool blk_mq_hctx_has_requests(str
 static inline bool blk_mq_last_cpu_in_hctx(unsigned int cpu,
 		struct blk_mq_hw_ctx *hctx)
 {
-	if (cpumask_next_and(-1, hctx->cpumask, cpu_online_mask) != cpu)
+	if (cpumask_first_and(hctx->cpumask, cpu_online_mask) != cpu)
 		return false;
 	if (cpumask_next_and(cpu, hctx->cpumask, cpu_online_mask) < nr_cpu_ids)
 		return false;
drivers/net/virtio_net.c renamed from drivers/net/virtio_net.c~cpumask-replace-cpumask_next_-with-cpumask_first_-where-appropriate +1 -1
@@ -2091,7 +2091,7 @@ static void virtnet_set_affinity(struct
 	stragglers = num_cpu >= vi->curr_queue_pairs ?
 			num_cpu % vi->curr_queue_pairs :
 			0;
-	cpu = cpumask_next(-1, cpu_online_mask);
+	cpu = cpumask_first(cpu_online_mask);
 
 	for (i = 0; i < vi->curr_queue_pairs; i++) {
 		group_size = stride + (i < stragglers ? 1 : 0);
drivers/soc/fsl/qbman/bman_portal.c renamed from drivers/soc/fsl/qbman/bman_portal.c~cpumask-replace-cpumask_next_-with-cpumask_first_-where-appropriate +1 -1
@@ -155,7 +155,7 @@ static int bman_portal_probe(struct plat
 	}
 
 	spin_lock(&bman_lock);
-	cpu = cpumask_next_zero(-1, &portal_cpus);
+	cpu = cpumask_first_zero(&portal_cpus);
 	if (cpu >= nr_cpu_ids) {
 		__bman_portals_probed = 1;
 		/* unassigned portal, skip init */
drivers/soc/fsl/qbman/qman_portal.c renamed from drivers/soc/fsl/qbman/qman_portal.c~cpumask-replace-cpumask_next_-with-cpumask_first_-where-appropriate +1 -1
@@ -248,7 +248,7 @@ static int qman_portal_probe(struct plat
 	pcfg->pools = qm_get_pools_sdqcr();
 
 	spin_lock(&qman_lock);
-	cpu = cpumask_next_zero(-1, &portal_cpus);
+	cpu = cpumask_first_zero(&portal_cpus);
 	if (cpu >= nr_cpu_ids) {
 		__qman_portals_probed = 1;
 		/* unassigned portal, skip init */
include/linux/cpumask.h renamed from include/linux/cpumask.h~cpumask-replace-cpumask_next_-with-cpumask_first_-where-appropriate +16 -0
@@ -123,6 +123,11 @@ static inline unsigned int cpumask_first
 	return 0;
 }
 
+static inline unsigned int cpumask_first_zero(const struct cpumask *srcp)
+{
+	return 0;
+}
+
 static inline unsigned int cpumask_first_and(const struct cpumask *srcp1,
 					     const struct cpumask *srcp2)
 {
@@ -202,6 +207,17 @@ static inline unsigned int cpumask_first
 }
 
 /**
+ * cpumask_first_zero - get the first unset cpu in a cpumask
+ * @srcp: the cpumask pointer
+ *
+ * Returns >= nr_cpu_ids if all cpus are set.
+ */
+static inline unsigned int cpumask_first_zero(const struct cpumask *srcp)
+{
+	return find_first_zero_bit(cpumask_bits(srcp), nr_cpumask_bits);
+}
+
+/**
  * cpumask_first_and - return the first cpu from *srcp1 & *srcp2
  * @src1p: the first input
  * @src2p: the second input
kernel/time/clocksource.c renamed from kernel/time/clocksource.c~cpumask-replace-cpumask_next_-with-cpumask_first_-where-appropriate +2 -2
@@ -257,7 +257,7 @@ static void clocksource_verify_choose_cp
 		return;
 
 	/* Make sure to select at least one CPU other than the current CPU. */
-	cpu = cpumask_next(-1, cpu_online_mask);
+	cpu = cpumask_first(cpu_online_mask);
 	if (cpu == smp_processor_id())
 		cpu = cpumask_next(cpu, cpu_online_mask);
 	if (WARN_ON_ONCE(cpu >= nr_cpu_ids))
@@ -279,7 +279,7 @@ static void clocksource_verify_choose_cp
 		cpu = prandom_u32() % nr_cpu_ids;
 		cpu = cpumask_next(cpu - 1, cpu_online_mask);
 		if (cpu >= nr_cpu_ids)
-			cpu = cpumask_next(-1, cpu_online_mask);
+			cpu = cpumask_first(cpu_online_mask);
 		if (!WARN_ON_ONCE(cpu >= nr_cpu_ids))
 			cpumask_set_cpu(cpu, &cpus_chosen);
 	}

_

author maintainer
#145 lore raw

PATCH 116/147 include/linux: move for_each_bit() macros from bitops.h to find.h

In reply to Andrew Morton

From: Yury Norov <[email protected]>
Subject: include/linux: move for_each_bit() macros from bitops.h to find.h

for_each_bit() macros depend on find_bit() machinery, and so the proper place for them is the find.h header.

---

 include/linux/bitops.h |   34 ----------------------------------
 include/linux/find.h   |   34 ++++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 34 deletions(-)
include/linux/bitops.h renamed from include/linux/bitops.h~include-linux-move-for_each_bit-macros-from-bitopsh-to-findh +0 -34
@@ -31,40 +31,6 @@ extern unsigned long __sw_hweight64(__u6
  */
 #include <asm/bitops.h>
 
-#define for_each_set_bit(bit, addr, size) \
-	for ((bit) = find_first_bit((addr), (size));		\
-	     (bit) < (size);					\
-	     (bit) = find_next_bit((addr), (size), (bit) + 1))
-
-/* same as for_each_set_bit() but use bit as value to start with */
-#define for_each_set_bit_from(bit, addr, size) \
-	for ((bit) = find_next_bit((addr), (size), (bit));	\
-	     (bit) < (size);					\
-	     (bit) = find_next_bit((addr), (size), (bit) + 1))
-
-#define for_each_clear_bit(bit, addr, size) \
-	for ((bit) = find_first_zero_bit((addr), (size));	\
-	     (bit) < (size);					\
-	     (bit) = find_next_zero_bit((addr), (size), (bit) + 1))
-
-/* same as for_each_clear_bit() but use bit as value to start with */
-#define for_each_clear_bit_from(bit, addr, size) \
-	for ((bit) = find_next_zero_bit((addr), (size), (bit));	\
-	     (bit) < (size);					\
-	     (bit) = find_next_zero_bit((addr), (size), (bit) + 1))
-
-/**
- * for_each_set_clump8 - iterate over bitmap for each 8-bit clump with set bits
- * @start: bit offset to start search and to store the current iteration offset
- * @clump: location to store copy of current 8-bit clump
- * @bits: bitmap address to base the search on
- * @size: bitmap size in number of bits
- */
-#define for_each_set_clump8(start, clump, bits, size) \
-	for ((start) = find_first_clump8(&(clump), (bits), (size)); \
-	     (start) < (size); \
-	     (start) = find_next_clump8(&(clump), (bits), (size), (start) + 8))
-
 static inline int get_bitmask_order(unsigned int count)
 {
 	int order;
include/linux/find.h renamed from include/linux/find.h~include-linux-move-for_each_bit-macros-from-bitopsh-to-findh +34 -0
@@ -279,4 +279,38 @@ unsigned long find_next_bit_le(const voi
 #error "Please fix <asm/byteorder.h>"
 #endif
 
+#define for_each_set_bit(bit, addr, size) \
+	for ((bit) = find_first_bit((addr), (size));		\
+	     (bit) < (size);					\
+	     (bit) = find_next_bit((addr), (size), (bit) + 1))
+
+/* same as for_each_set_bit() but use bit as value to start with */
+#define for_each_set_bit_from(bit, addr, size) \
+	for ((bit) = find_next_bit((addr), (size), (bit));	\
+	     (bit) < (size);					\
+	     (bit) = find_next_bit((addr), (size), (bit) + 1))
+
+#define for_each_clear_bit(bit, addr, size) \
+	for ((bit) = find_first_zero_bit((addr), (size));	\
+	     (bit) < (size);					\
+	     (bit) = find_next_zero_bit((addr), (size), (bit) + 1))
+
+/* same as for_each_clear_bit() but use bit as value to start with */
+#define for_each_clear_bit_from(bit, addr, size) \
+	for ((bit) = find_next_zero_bit((addr), (size), (bit));	\
+	     (bit) < (size);					\
+	     (bit) = find_next_zero_bit((addr), (size), (bit) + 1))
+
+/**
+ * for_each_set_clump8 - iterate over bitmap for each 8-bit clump with set bits
+ * @start: bit offset to start search and to store the current iteration offset
+ * @clump: location to store copy of current 8-bit clump
+ * @bits: bitmap address to base the search on
+ * @size: bitmap size in number of bits
+ */
+#define for_each_set_clump8(start, clump, bits, size) \
+	for ((start) = find_first_clump8(&(clump), (bits), (size)); \
+	     (start) < (size); \
+	     (start) = find_next_clump8(&(clump), (bits), (size), (start) + 8))
+
 #endif /*__LINUX_FIND_H_ */

_

author maintainer
#146 lore raw

PATCH 117/147 find: micro-optimize for_each_{set,clear}_bit()

In reply to Andrew Morton

From: Yury Norov <[email protected]>
Subject: find: micro-optimize for_each_{set,clear}_bit()

The macros iterate thru all set/clear bits in a bitmap. They search a first bit using find_first_bit(), and the rest bits using find_next_bit().

Since find_next_bit() is called shortly after find_first_bit(), we can save few lines of I-cache by not using find_first_bit().

---

 include/linux/find.h |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/find.h renamed from include/linux/find.h~find-micro-optimize-for_each_setclear_bit +2 -2
@@ -280,7 +280,7 @@ unsigned long find_next_bit_le(const voi
 #endif
 
 #define for_each_set_bit(bit, addr, size) \
-	for ((bit) = find_first_bit((addr), (size));		\
+	for ((bit) = find_next_bit((addr), (size), 0);		\
 	     (bit) < (size);					\
 	     (bit) = find_next_bit((addr), (size), (bit) + 1))
 
@@ -291,7 +291,7 @@ unsigned long find_next_bit_le(const voi
 	     (bit) = find_next_bit((addr), (size), (bit) + 1))
 
 #define for_each_clear_bit(bit, addr, size) \
-	for ((bit) = find_first_zero_bit((addr), (size));	\
+	for ((bit) = find_next_zero_bit((addr), (size), 0);	\
 	     (bit) < (size);					\
 	     (bit) = find_next_zero_bit((addr), (size), (bit) + 1))
 

_

author maintainer
#147 lore raw

PATCH 118/147 bitops: replace for_each_*_bit_from() with for_each_*_bit() where appropriate

In reply to Andrew Morton

From: Yury Norov <[email protected]>
Subject: bitops: replace for_each_*_bit_from() with for_each_*_bit() where appropriate

A couple of kernel functions call for_each_*_bit_from() with start bit equal to 0. Replace them with for_each_*_bit().

No functional changes, but might improve on readability.

---

 arch/x86/kernel/apic/vector.c         |    4 ++--
 drivers/gpu/drm/etnaviv/etnaviv_gpu.c |    4 ++--
 drivers/hwmon/ltc2992.c               |    3 +--
 3 files changed, 5 insertions(+), 6 deletions(-)
arch/x86/kernel/apic/vector.c renamed from arch/x86/kernel/apic/vector.c~replace-for_each__bit_from-with-for_each__bit-where-appropriate +2 -2
@@ -760,9 +760,9 @@ void __init lapic_update_legacy_vectors(
 
 void __init lapic_assign_system_vectors(void)
 {
-	unsigned int i, vector = 0;
+	unsigned int i, vector;
 
-	for_each_set_bit_from(vector, system_vectors, NR_VECTORS)
+	for_each_set_bit(vector, system_vectors, NR_VECTORS)
 		irq_matrix_assign_system(vector_matrix, vector, false);
 
 	if (nr_legacy_irqs() > 1)
drivers/gpu/drm/etnaviv/etnaviv_gpu.c renamed from drivers/gpu/drm/etnaviv/etnaviv_gpu.c~replace-for_each__bit_from-with-for_each__bit-where-appropriate +2 -2
@@ -1032,7 +1032,7 @@ pm_put:
 
 void etnaviv_gpu_recover_hang(struct etnaviv_gpu *gpu)
 {
-	unsigned int i = 0;
+	unsigned int i;
 
 	dev_err(gpu->dev, "recover hung GPU!\n");
 
@@ -1045,7 +1045,7 @@ void etnaviv_gpu_recover_hang(struct etn
 
 	/* complete all events, the GPU won't do it after the reset */
 	spin_lock(&gpu->event_spinlock);
-	for_each_set_bit_from(i, gpu->event_bitmap, ETNA_NR_EVENTS)
+	for_each_set_bit(i, gpu->event_bitmap, ETNA_NR_EVENTS)
 		complete(&gpu->event_free);
 	bitmap_zero(gpu->event_bitmap, ETNA_NR_EVENTS);
 	spin_unlock(&gpu->event_spinlock);
drivers/hwmon/ltc2992.c renamed from drivers/hwmon/ltc2992.c~replace-for_each__bit_from-with-for_each__bit-where-appropriate +1 -2
@@ -248,8 +248,7 @@ static int ltc2992_gpio_get_multiple(str
 
 	gpio_status = reg;
 
-	gpio_nr = 0;
-	for_each_set_bit_from(gpio_nr, mask, LTC2992_GPIO_NR) {
+	for_each_set_bit(gpio_nr, mask, LTC2992_GPIO_NR) {
 		if (test_bit(LTC2992_GPIO_BIT(gpio_nr), &gpio_status))
 			set_bit(gpio_nr, bits);
 	}

_

author maintainer
#148 lore raw

PATCH 119/147 tools: rename bitmap_alloc() to bitmap_zalloc()

In reply to Andrew Morton

From: Andy Shevchenko <[email protected]>
Subject: tools: rename bitmap_alloc() to bitmap_zalloc()

Rename bitmap_alloc() to bitmap_zalloc() in tools to follow the bitmap API in the kernel.

No functional changes intended.

---

 tools/include/linux/bitmap.h                            |    4 ++--
 tools/perf/bench/find-bit-bench.c                       |    2 +-
 tools/perf/builtin-c2c.c                                |    6 +++---
 tools/perf/builtin-record.c                             |    2 +-
 tools/perf/tests/bitmap.c                               |    2 +-
 tools/perf/tests/mem2node.c                             |    2 +-
 tools/perf/util/affinity.c                              |    4 ++--
 tools/perf/util/header.c                                |    4 ++--
 tools/perf/util/metricgroup.c                           |    2 +-
 tools/perf/util/mmap.c                                  |    4 ++--
 tools/testing/selftests/kvm/dirty_log_perf_test.c       |    2 +-
 tools/testing/selftests/kvm/dirty_log_test.c            |    4 ++--
 tools/testing/selftests/kvm/x86_64/vmx_dirty_log_test.c |    2 +-
 13 files changed, 20 insertions(+), 20 deletions(-)
tools/include/linux/bitmap.h renamed from tools/include/linux/bitmap.h~tools-rename-bitmap_alloc-to-bitmap_zalloc +2 -2
@@ -112,10 +112,10 @@ static inline int test_and_clear_bit(int
 }
 
 /**
- * bitmap_alloc - Allocate bitmap
+ * bitmap_zalloc - Allocate bitmap
  * @nbits: Number of bits
  */
-static inline unsigned long *bitmap_alloc(int nbits)
+static inline unsigned long *bitmap_zalloc(int nbits)
 {
 	return calloc(1, BITS_TO_LONGS(nbits) * sizeof(unsigned long));
 }
tools/perf/bench/find-bit-bench.c renamed from tools/perf/bench/find-bit-bench.c~tools-rename-bitmap_alloc-to-bitmap_zalloc +1 -1
@@ -54,7 +54,7 @@ static bool asm_test_bit(long nr, const
 
 static int do_for_each_set_bit(unsigned int num_bits)
 {
-	unsigned long *to_test = bitmap_alloc(num_bits);
+	unsigned long *to_test = bitmap_zalloc(num_bits);
 	struct timeval start, end, diff;
 	u64 runtime_us;
 	struct stats fb_time_stats, tb_time_stats;
tools/perf/builtin-c2c.c renamed from tools/perf/builtin-c2c.c~tools-rename-bitmap_alloc-to-bitmap_zalloc +3 -3
@@ -139,11 +139,11 @@ static void *c2c_he_zalloc(size_t size)
 	if (!c2c_he)
 		return NULL;
 
-	c2c_he->cpuset = bitmap_alloc(c2c.cpus_cnt);
+	c2c_he->cpuset = bitmap_zalloc(c2c.cpus_cnt);
 	if (!c2c_he->cpuset)
 		return NULL;
 
-	c2c_he->nodeset = bitmap_alloc(c2c.nodes_cnt);
+	c2c_he->nodeset = bitmap_zalloc(c2c.nodes_cnt);
 	if (!c2c_he->nodeset)
 		return NULL;
 
@@ -2047,7 +2047,7 @@ static int setup_nodes(struct perf_sessi
 		struct perf_cpu_map *map = n[node].map;
 		unsigned long *set;
 
-		set = bitmap_alloc(c2c.cpus_cnt);
+		set = bitmap_zalloc(c2c.cpus_cnt);
 		if (!set)
 			return -ENOMEM;
 
tools/perf/builtin-record.c renamed from tools/perf/builtin-record.c~tools-rename-bitmap_alloc-to-bitmap_zalloc +1 -1
@@ -2786,7 +2786,7 @@ int cmd_record(int argc, const char **ar
 
 	if (rec->opts.affinity != PERF_AFFINITY_SYS) {
 		rec->affinity_mask.nbits = cpu__max_cpu();
-		rec->affinity_mask.bits = bitmap_alloc(rec->affinity_mask.nbits);
+		rec->affinity_mask.bits = bitmap_zalloc(rec->affinity_mask.nbits);
 		if (!rec->affinity_mask.bits) {
 			pr_err("Failed to allocate thread mask for %zd cpus\n", rec->affinity_mask.nbits);
 			err = -ENOMEM;
tools/perf/tests/bitmap.c renamed from tools/perf/tests/bitmap.c~tools-rename-bitmap_alloc-to-bitmap_zalloc +1 -1
@@ -14,7 +14,7 @@ static unsigned long *get_bitmap(const c
 	unsigned long *bm = NULL;
 	int i;
 
-	bm = bitmap_alloc(nbits);
+	bm = bitmap_zalloc(nbits);
 
 	if (map && bm) {
 		for (i = 0; i < map->nr; i++)
tools/perf/tests/mem2node.c renamed from tools/perf/tests/mem2node.c~tools-rename-bitmap_alloc-to-bitmap_zalloc +1 -1
@@ -27,7 +27,7 @@ static unsigned long *get_bitmap(const c
 	unsigned long *bm = NULL;
 	int i;
 
-	bm = bitmap_alloc(nbits);
+	bm = bitmap_zalloc(nbits);
 
 	if (map && bm) {
 		for (i = 0; i < map->nr; i++) {
tools/perf/util/affinity.c renamed from tools/perf/util/affinity.c~tools-rename-bitmap_alloc-to-bitmap_zalloc +2 -2
@@ -25,11 +25,11 @@ int affinity__setup(struct affinity *a)
 {
 	int cpu_set_size = get_cpu_set_size();
 
-	a->orig_cpus = bitmap_alloc(cpu_set_size * 8);
+	a->orig_cpus = bitmap_zalloc(cpu_set_size * 8);
 	if (!a->orig_cpus)
 		return -1;
 	sched_getaffinity(0, cpu_set_size, (cpu_set_t *)a->orig_cpus);
-	a->sched_cpus = bitmap_alloc(cpu_set_size * 8);
+	a->sched_cpus = bitmap_zalloc(cpu_set_size * 8);
 	if (!a->sched_cpus) {
 		zfree(&a->orig_cpus);
 		return -1;
tools/perf/util/header.c renamed from tools/perf/util/header.c~tools-rename-bitmap_alloc-to-bitmap_zalloc +2 -2
@@ -278,7 +278,7 @@ static int do_read_bitmap(struct feat_fd
 	if (ret)
 		return ret;
 
-	set = bitmap_alloc(size);
+	set = bitmap_zalloc(size);
 	if (!set)
 		return -ENOMEM;
 
@@ -1294,7 +1294,7 @@ static int memory_node__read(struct memo
 
 	size++;
 
-	n->set = bitmap_alloc(size);
+	n->set = bitmap_zalloc(size);
 	if (!n->set) {
 		closedir(dir);
 		return -ENOMEM;
tools/perf/util/metricgroup.c renamed from tools/perf/util/metricgroup.c~tools-rename-bitmap_alloc-to-bitmap_zalloc +1 -1
@@ -313,7 +313,7 @@ static int metricgroup__setup_events(str
 	struct evsel *evsel, *tmp;
 	unsigned long *evlist_used;
 
-	evlist_used = bitmap_alloc(perf_evlist->core.nr_entries);
+	evlist_used = bitmap_zalloc(perf_evlist->core.nr_entries);
 	if (!evlist_used)
 		return -ENOMEM;
 
tools/perf/util/mmap.c renamed from tools/perf/util/mmap.c~tools-rename-bitmap_alloc-to-bitmap_zalloc +2 -2
@@ -106,7 +106,7 @@ static int perf_mmap__aio_bind(struct mm
 		data = map->aio.data[idx];
 		mmap_len = mmap__mmap_len(map);
 		node_index = cpu__get_node(cpu);
-		node_mask = bitmap_alloc(node_index + 1);
+		node_mask = bitmap_zalloc(node_index + 1);
 		if (!node_mask) {
 			pr_err("Failed to allocate node mask for mbind: error %m\n");
 			return -1;
@@ -258,7 +258,7 @@ static void build_node_mask(int node, st
 static int perf_mmap__setup_affinity_mask(struct mmap *map, struct mmap_params *mp)
 {
 	map->affinity_mask.nbits = cpu__max_cpu();
-	map->affinity_mask.bits = bitmap_alloc(map->affinity_mask.nbits);
+	map->affinity_mask.bits = bitmap_zalloc(map->affinity_mask.nbits);
 	if (!map->affinity_mask.bits)
 		return -1;
 
tools/testing/selftests/kvm/dirty_log_perf_test.c renamed from tools/testing/selftests/kvm/dirty_log_perf_test.c~tools-rename-bitmap_alloc-to-bitmap_zalloc +1 -1
@@ -121,7 +121,7 @@ static void run_test(enum vm_guest_mode
 	guest_num_pages = (nr_vcpus * guest_percpu_mem_size) >> vm_get_page_shift(vm);
 	guest_num_pages = vm_adjust_num_guest_pages(mode, guest_num_pages);
 	host_num_pages = vm_num_host_pages(mode, guest_num_pages);
-	bmap = bitmap_alloc(host_num_pages);
+	bmap = bitmap_zalloc(host_num_pages);
 
 	if (dirty_log_manual_caps) {
 		cap.cap = KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2;
tools/testing/selftests/kvm/dirty_log_test.c renamed from tools/testing/selftests/kvm/dirty_log_test.c~tools-rename-bitmap_alloc-to-bitmap_zalloc +2 -2
@@ -749,8 +749,8 @@ static void run_test(enum vm_guest_mode
 
 	pr_info("guest physical test memory offset: 0x%lx\n", guest_test_phys_mem);
 
-	bmap = bitmap_alloc(host_num_pages);
-	host_bmap_track = bitmap_alloc(host_num_pages);
+	bmap = bitmap_zalloc(host_num_pages);
+	host_bmap_track = bitmap_zalloc(host_num_pages);
 
 	/* Add an extra memory slot for testing dirty logging */
 	vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS,
tools/testing/selftests/kvm/x86_64/vmx_dirty_log_test.c renamed from tools/testing/selftests/kvm/x86_64/vmx_dirty_log_test.c~tools-rename-bitmap_alloc-to-bitmap_zalloc +1 -1
@@ -111,7 +111,7 @@ int main(int argc, char *argv[])
 	nested_map(vmx, vm, NESTED_TEST_MEM1, GUEST_TEST_MEM, 4096);
 	nested_map(vmx, vm, NESTED_TEST_MEM2, GUEST_TEST_MEM, 4096);
 
-	bmap = bitmap_alloc(TEST_MEM_PAGES);
+	bmap = bitmap_zalloc(TEST_MEM_PAGES);
 	host_test_mem = addr_gpa2hva(vm, GUEST_TEST_MEM);
 
 	while (!done) {

_

author maintainer
#149 lore raw

PATCH 120/147 mm/percpu: micro-optimize pcpu_is_populated()

In reply to Andrew Morton

From: Yury Norov <[email protected]>
Subject: mm/percpu: micro-optimize pcpu_is_populated()

bitmap_next_clear_region() calls find_next_zero_bit() and find_next_bit() sequentially to find a range of clear bits. In case of pcpu_is_populated() there's a chance to return earlier if bitmap has all bits set.

---

 mm/percpu.c |   15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
mm/percpu.c renamed from mm/percpu.c~mm-percpu-micro-optimize-pcpu_is_populated +8 -7
@@ -1070,17 +1070,18 @@ static void pcpu_block_update_hint_free(
 static bool pcpu_is_populated(struct pcpu_chunk *chunk, int bit_off, int bits,
 			      int *next_off)
 {
-	unsigned int page_start, page_end, rs, re;
+	unsigned int start, end;
 
-	page_start = PFN_DOWN(bit_off * PCPU_MIN_ALLOC_SIZE);
-	page_end = PFN_UP((bit_off + bits) * PCPU_MIN_ALLOC_SIZE);
+	start = PFN_DOWN(bit_off * PCPU_MIN_ALLOC_SIZE);
+	end = PFN_UP((bit_off + bits) * PCPU_MIN_ALLOC_SIZE);
 
-	rs = page_start;
-	bitmap_next_clear_region(chunk->populated, &rs, &re, page_end);
-	if (rs >= page_end)
+	start = find_next_zero_bit(chunk->populated, end, start);
+	if (start >= end)
 		return true;
 
-	*next_off = re * PAGE_SIZE / PCPU_MIN_ALLOC_SIZE;
+	end = find_next_bit(chunk->populated, end, start + 1);
+
+	*next_off = end * PAGE_SIZE / PCPU_MIN_ALLOC_SIZE;
 	return false;
 }
 

_

author maintainer
#150 lore raw

PATCH 121/147 bitmap: unify find_bit operations

In reply to Andrew Morton

From: Yury Norov <[email protected]>
Subject: bitmap: unify find_bit operations

bitmap_for_each_{set,clear}_region() are similar to for_each_bit() macros in include/linux/find.h, but interface and implementation of them are different.

This patch adds for_each_bitrange() macros and drops unused bitmap_*_region() API in sake of unification.

---

 drivers/mmc/host/renesas_sdhi_core.c |    2 
 include/linux/bitmap.h               |   33 --------------
 include/linux/find.h                 |   56 +++++++++++++++++++++++++
 mm/percpu.c                          |   20 +++-----
 4 files changed, 65 insertions(+), 46 deletions(-)
drivers/mmc/host/renesas_sdhi_core.c renamed from drivers/mmc/host/renesas_sdhi_core.c~bitmap-unify-find_bit-operations +1 -1
@@ -647,7 +647,7 @@ static int renesas_sdhi_select_tuning(st
 	 * is at least SH_MOBILE_SDHI_MIN_TAP_ROW probes long then use the
 	 * center index as the tap, otherwise bail out.
 	 */
-	bitmap_for_each_set_region(bitmap, rs, re, 0, taps_size) {
+	for_each_set_bitrange(rs, re, bitmap, taps_size) {
 		if (re - rs > tap_cnt) {
 			tap_end = re;
 			tap_start = rs;
include/linux/bitmap.h renamed from include/linux/bitmap.h~bitmap-unify-find_bit-operations +0 -33
@@ -55,12 +55,6 @@ struct device;
  *  bitmap_clear(dst, pos, nbits)               Clear specified bit area
  *  bitmap_find_next_zero_area(buf, len, pos, n, mask)  Find bit free area
  *  bitmap_find_next_zero_area_off(buf, len, pos, n, mask, mask_off)  as above
- *  bitmap_next_clear_region(map, &start, &end, nbits)  Find next clear region
- *  bitmap_next_set_region(map, &start, &end, nbits)  Find next set region
- *  bitmap_for_each_clear_region(map, rs, re, start, end)
- *  						Iterate over all clear regions
- *  bitmap_for_each_set_region(map, rs, re, start, end)
- *  						Iterate over all set regions
  *  bitmap_shift_right(dst, src, n, nbits)      *dst = *src >> n
  *  bitmap_shift_left(dst, src, n, nbits)       *dst = *src << n
  *  bitmap_cut(dst, src, first, n, nbits)       Cut n bits from first, copy rest
@@ -459,14 +453,6 @@ static inline void bitmap_replace(unsign
 		__bitmap_replace(dst, old, new, mask, nbits);
 }
 
-static inline void bitmap_next_clear_region(unsigned long *bitmap,
-					    unsigned int *rs, unsigned int *re,
-					    unsigned int end)
-{
-	*rs = find_next_zero_bit(bitmap, end, *rs);
-	*re = find_next_bit(bitmap, end, *rs + 1);
-}
-
 static inline void bitmap_next_set_region(unsigned long *bitmap,
 					  unsigned int *rs, unsigned int *re,
 					  unsigned int end)
@@ -475,25 +461,6 @@ static inline void bitmap_next_set_regio
 	*re = find_next_zero_bit(bitmap, end, *rs + 1);
 }
 
-/*
- * Bitmap region iterators.  Iterates over the bitmap between [@start, @end).
- * @rs and @re should be integer variables and will be set to start and end
- * index of the current clear or set region.
- */
-#define bitmap_for_each_clear_region(bitmap, rs, re, start, end)	     \
-	for ((rs) = (start),						     \
-	     bitmap_next_clear_region((bitmap), &(rs), &(re), (end));	     \
-	     (rs) < (re);						     \
-	     (rs) = (re) + 1,						     \
-	     bitmap_next_clear_region((bitmap), &(rs), &(re), (end)))
-
-#define bitmap_for_each_set_region(bitmap, rs, re, start, end)		     \
-	for ((rs) = (start),						     \
-	     bitmap_next_set_region((bitmap), &(rs), &(re), (end));	     \
-	     (rs) < (re);						     \
-	     (rs) = (re) + 1,						     \
-	     bitmap_next_set_region((bitmap), &(rs), &(re), (end)))
-
 /**
  * BITMAP_FROM_U64() - Represent u64 value in the format suitable for bitmap.
  * @n: u64 value
include/linux/find.h renamed from include/linux/find.h~bitmap-unify-find_bit-operations +56 -0

62 lines not on this page · raw message

mm/percpu.c renamed from mm/percpu.c~bitmap-unify-find_bit-operations +8 -12
@@ -779,7 +779,7 @@ static void pcpu_block_refresh_hint(stru
 {
 	struct pcpu_block_md *block = chunk->md_blocks + index;
 	unsigned long *alloc_map = pcpu_index_alloc_map(chunk, index);
-	unsigned int rs, re, start;	/* region start, region end */
+	unsigned int start, end;	/* region start, region end */
 
 	/* promote scan_hint to contig_hint */
 	if (block->scan_hint) {
@@ -795,9 +795,8 @@ static void pcpu_block_refresh_hint(stru
 	block->right_free = 0;
 
 	/* iterate over free areas and update the contig hints */
-	bitmap_for_each_clear_region(alloc_map, rs, re, start,
-				     PCPU_BITMAP_BLOCK_BITS)
-		pcpu_block_update(block, rs, re);
+	for_each_clear_bitrange_from(start, end, alloc_map, PCPU_BITMAP_BLOCK_BITS)
+		pcpu_block_update(block, start, end);
 }
 
 /**
@@ -1852,13 +1851,12 @@ area_found:
 
 	/* populate if not all pages are already there */
 	if (!is_atomic) {
-		unsigned int page_start, page_end, rs, re;
+		unsigned int page_end, rs, re;
 
-		page_start = PFN_DOWN(off);
+		rs = PFN_DOWN(off);
 		page_end = PFN_UP(off + size);
 
-		bitmap_for_each_clear_region(chunk->populated, rs, re,
-					     page_start, page_end) {
+		for_each_clear_bitrange_from(rs, re, chunk->populated, page_end) {
 			WARN_ON(chunk->immutable);
 
 			ret = pcpu_populate_chunk(chunk, rs, re, pcpu_gfp);
@@ -2014,8 +2012,7 @@ static void pcpu_balance_free(bool empty
 	list_for_each_entry_safe(chunk, next, &to_free, list) {
 		unsigned int rs, re;
 
-		bitmap_for_each_set_region(chunk->populated, rs, re, 0,
-					   chunk->nr_pages) {
+		for_each_set_bitrange(rs, re, chunk->populated, chunk->nr_pages) {
 			pcpu_depopulate_chunk(chunk, rs, re);
 			spin_lock_irq(&pcpu_lock);
 			pcpu_chunk_depopulated(chunk, rs, re);
@@ -2085,8 +2082,7 @@ retry_pop:
 			continue;
 
 		/* @chunk can't go away while pcpu_alloc_mutex is held */
-		bitmap_for_each_clear_region(chunk->populated, rs, re, 0,
-					     chunk->nr_pages) {
+		for_each_clear_bitrange(rs, re, chunk->populated, chunk->nr_pages) {
 			int nr = min_t(int, re - rs, nr_to_pop);
 
 			spin_unlock_irq(&pcpu_lock);

_

author maintainer
#151 lore raw

PATCH 122/147 lib: bitmap: add performance test for bitmap_print_to_pagebuf

In reply to Andrew Morton

From: Yury Norov <[email protected]>
Subject: lib: bitmap: add performance test for bitmap_print_to_pagebuf

Functional tests for bitmap_print_to_pagebuf() are provided in lib/test_printf.c. This patch adds performance test for a case of fully set bitmap.

---

 lib/test_bitmap.c |   37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
lib/test_bitmap.c renamed from lib/test_bitmap.c~lib-bitmap-add-performance-test-for-bitmap_print_to_pagebuf +37 -0
@@ -430,6 +430,42 @@ static void __init test_bitmap_parselist
 	}
 }
 
+static void __init test_bitmap_printlist(void)
+{
+	unsigned long *bmap = kmalloc(PAGE_SIZE, GFP_KERNEL);
+	char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
+	char expected[256];
+	int ret, slen;
+	ktime_t time;
+
+	if (!buf || !bmap)
+		goto out;
+
+	memset(bmap, -1, PAGE_SIZE);
+	slen = snprintf(expected, 256, "0-%ld", PAGE_SIZE * 8 - 1);
+	if (slen < 0)
+		goto out;
+
+	time = ktime_get();
+	ret = bitmap_print_to_pagebuf(true, buf, bmap, PAGE_SIZE * 8);
+	time = ktime_get() - time;
+
+	if (ret != slen + 1) {
+		pr_err("bitmap_print_to_pagebuf: result is %d, expected %d\n", ret, slen);
+		goto out;
+	}
+
+	if (strncmp(buf, expected, slen)) {
+		pr_err("bitmap_print_to_pagebuf: result is %s, expected %s\n", buf, expected);
+		goto out;
+	}
+
+	pr_err("bitmap_print_to_pagebuf: input is '%s', Time: %llu\n", buf, time);
+out:
+	kfree(buf);
+	kfree(bmap);
+}
+
 static const unsigned long parse_test[] __initconst = {
 	BITMAP_FROM_U64(0),
 	BITMAP_FROM_U64(1),
@@ -669,6 +705,7 @@ static void __init selftest(void)
 	test_bitmap_arr32();
 	test_bitmap_parse();
 	test_bitmap_parselist();
+	test_bitmap_printlist();
 	test_mem_optimisations();
 	test_for_each_set_clump8();
 	test_bitmap_cut();

_

author maintainer
#152 lore raw

PATCH 123/147 vsprintf: rework bitmap_list_string

In reply to Andrew Morton

From: Yury Norov <[email protected]>
Subject: vsprintf: rework bitmap_list_string

bitmap_list_string() is very ineffective when printing bitmaps with long ranges of set bits because it calls find_next_bit for each bit in the bitmap. We can do better by detecting ranges of set bits.

In my environment, before/after is 943008/31008 ns.

---

 lib/vsprintf.c |   24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)
lib/vsprintf.c renamed from lib/vsprintf.c~vsprintf-rework-bitmap_list_string +7 -17
@@ -1241,20 +1241,13 @@ char *bitmap_list_string(char *buf, char
 			 struct printf_spec spec, const char *fmt)
 {
 	int nr_bits = max_t(int, spec.field_width, 0);
-	/* current bit is 'cur', most recently seen range is [rbot, rtop] */
-	int cur, rbot, rtop;
 	bool first = true;
+	int rbot, rtop;
 
 	if (check_pointer(&buf, end, bitmap, spec))
 		return buf;
 
-	rbot = cur = find_first_bit(bitmap, nr_bits);
-	while (cur < nr_bits) {
-		rtop = cur;
-		cur = find_next_bit(bitmap, nr_bits, cur + 1);
-		if (cur < nr_bits && cur <= rtop + 1)
-			continue;
-
+	for_each_set_bitrange(rbot, rtop, bitmap, nr_bits) {
 		if (!first) {
 			if (buf < end)
 				*buf = ',';
@@ -1263,15 +1256,12 @@ char *bitmap_list_string(char *buf, char
 		first = false;
 
 		buf = number(buf, end, rbot, default_dec_spec);
-		if (rbot < rtop) {
-			if (buf < end)
-				*buf = '-';
-			buf++;
-
-			buf = number(buf, end, rtop, default_dec_spec);
-		}
+		if (rtop == rbot + 1)
+			continue;
 
-		rbot = cur;
+		if (buf < end)
+			*buf = '-';
+		buf = number(buf + 1, end, rtop - 1, default_dec_spec);
 	}
 	return buf;
 }

_

author maintainer
#153 lore raw

PATCH 124/147 checkpatch: support wide strings

In reply to Andrew Morton

From: Joe Perches <[email protected]>
Subject: checkpatch: support wide strings

Allow prefixing typical strings with L for wide strings and u for unicode strings.

---

 scripts/checkpatch.pl |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
scripts/checkpatch.pl renamed from scripts/checkpatch.pl~checkpatch-support-wide-strings +4 -3
@@ -501,7 +501,7 @@ our $Binary	= qr{(?i)0b[01]+$Int_type?};
 our $Hex	= qr{(?i)0x[0-9a-f]+$Int_type?};
 our $Int	= qr{[0-9]+$Int_type?};
 our $Octal	= qr{0[0-7]+$Int_type?};
-our $String	= qr{"[X\t]*"};
+our $String	= qr{(?:\b[Lu])?"[X\t]*"};
 our $Float_hex	= qr{(?i)0x[0-9a-f]+p-?[0-9]+[fl]?};
 our $Float_dec	= qr{(?i)(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?};
 our $Float_int	= qr{(?i)[0-9]+e-?[0-9]+[fl]?};
@@ -6132,7 +6132,8 @@ sub process {
 		}
 
 # concatenated string without spaces between elements
-		if ($line =~ /$String[A-Za-z0-9_]/ || $line =~ /[A-Za-z0-9_]$String/) {
+		if ($line =~ /$String[A-Z_]/ ||
+		    ($line =~ /([A-Za-z0-9_]+)$String/ && $1 !~ /^[Lu]$/)) {
 			if (CHK("CONCATENATED_STRING",
 				"Concatenated strings should use spaces between elements\n" . $herecurr) &&
 			    $fix) {
@@ -6145,7 +6146,7 @@ sub process {
 		}
 
 # uncoalesced string fragments
-		if ($line =~ /$String\s*"/) {
+		if ($line =~ /$String\s*[Lu]?"/) {
 			if (WARN("STRING_FRAGMENTS",
 				 "Consecutive strings are generally better as a single string\n" . $herecurr) &&
 			    $fix) {

_

author maintainer
#154 lore raw

PATCH 125/147 checkpatch: make email address check case insensitive

In reply to Andrew Morton

From: Mimi Zohar <[email protected]>
Subject: checkpatch: make email address check case insensitive

Instead of checkpatch requiring the patch author to exactly match the signed-off-by tag, commit 48ca2d8ac8a1 ("checkpatch: add new warnings to author signoff checks.") safely relaxed this requirement.

Although the local-part of an email address (local-part@domain), may be case sensitive, exploiting the case sensitivity of mailbox local-parts impedes interoperability and is discouraged. Mailbox domains follow normal DNS rules and are hence not case sensitive. (Refer to
https://datatracker.ietf.org/doc/html/rfc5321#section-2.4.)

Further relax the patch author and signed-off-by tag comparison by making the email address check case insensitive.

---

 scripts/checkpatch.pl |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/checkpatch.pl renamed from scripts/checkpatch.pl~checkpatch-make-email-address-check-case-insensitive +2 -2
@@ -2909,10 +2909,10 @@ sub process {
 					my ($email_name, $email_comment, $email_address, $comment1) = parse_email($ctx);
 					my ($author_name, $author_comment, $author_address, $comment2) = parse_email($author);
 
-					if ($email_address eq $author_address && $email_name eq $author_name) {
+					if (lc $email_address eq lc $author_address && $email_name eq $author_name) {
 						$author_sob = $ctx;
 						$authorsignoff = 2;
-					} elsif ($email_address eq $author_address) {
+					} elsif (lc $email_address eq lc $author_address) {
 						$author_sob = $ctx;
 						$authorsignoff = 3;
 					} elsif ($email_name eq $author_name) {

_

author maintainer
#155 lore raw

PATCH 126/147 checkpatch: improve GIT_COMMIT_ID test

In reply to Andrew Morton

From: Joe Perches <[email protected]>
Subject: checkpatch: improve GIT_COMMIT_ID test

The preferred git commit id reference has the form

	commit <SHA-1> ("Title line")

where SHA-1 is the commit hex hash with a minimum lenth of 12 and ("Title line") is the complete title line of the commit with a (" prefix and ") suffix.

The current tests fail when the "Title line" has one or more embedded double quotes.

Improve the test that finds the commit SHA-1 hex hash then ("Title line") by using $balanced_parens for a maximum of 3 consecutive lines.

---

 scripts/checkpatch.pl |   82 ++++++++++++++++++++++++----------------
 1 file changed, 51 insertions(+), 31 deletions(-)
scripts/checkpatch.pl renamed from scripts/checkpatch.pl~checkpatch-improve-git_commit_id-test +51 -31
@@ -1181,7 +1181,8 @@ sub git_commit_info {
 #		    git log --format='%H %s' -1 $line |
 #		    echo "commit $(cut -c 1-12,41-)"
 #		done
-	} elsif ($lines[0] =~ /^fatal: ambiguous argument '$commit': unknown revision or path not in the working tree\./) {
+	} elsif ($lines[0] =~ /^fatal: ambiguous argument '$commit': unknown revision or path not in the working tree\./ ||
+		 $lines[0] =~ /^fatal: bad object $commit/) {
 		$id = undef;
 	} else {
 		$id = substr($lines[0], 0, 12);
@@ -2587,6 +2588,8 @@ sub process {
 	my $reported_maintainer_file = 0;
 	my $non_utf8_charset = 0;
 
+	my $last_git_commit_id_linenr = -1;
+
 	my $last_blank_line = 0;
 	my $last_coalesced_string_linenr = -1;
 
@@ -3170,10 +3173,20 @@ sub process {
 		}
 
 # Check for git id commit length and improperly formed commit descriptions
-		if ($in_commit_log && !$commit_log_possible_stack_dump &&
+# A correctly formed commit description is:
+#    commit <SHA-1 hash length 12+ chars> ("Complete commit subject")
+# with the commit subject '("' prefix and '")' suffix
+# This is a fairly compilicated block as it tests for what appears to be
+# bare SHA-1 hash with  minimum length of 5.  It also avoids several types of
+# possible SHA-1 matches.
+# A commit match can span multiple lines so this block attempts to find a
+# complete typical commit on a maximum of 3 lines
+		if ($perl_version_ok &&
+		    $in_commit_log && !$commit_log_possible_stack_dump &&
 		    $line !~ /^\s*(?:Link|Patchwork|http|https|BugLink|base-commit):/i &&
 		    $line !~ /^This reverts commit [0-9a-f]{7,40}/ &&
-		    ($line =~ /\bcommit\s+[0-9a-f]{5,}\b/i ||
+		    (($line =~ /\bcommit\s+[0-9a-f]{5,}\b/i ||
+		      ($line =~ /\bcommit\s*$/i && defined($rawlines[$linenr]) && $rawlines[$linenr] =~ /^\s*[0-9a-f]{5,}\b/i)) ||
 		     ($line =~ /(?:\s|^)[0-9a-f]{12,40}(?:[\s"'\(\[]|$)/i &&
 		      $line !~ /[\<\[][0-9a-f]{12,40}[\>\]]/i &&
 		      $line !~ /\bfixes:\s*[0-9a-f]{12,40}/i))) {
@@ -3183,49 +3196,56 @@ sub process {
 			my $long = 0;
 			my $case = 1;
 			my $space = 1;
-			my $hasdesc = 0;
-			my $hasparens = 0;
 			my $id = '0123456789ab';
 			my $orig_desc = "commit description";
 			my $description = "";
+			my $herectx = $herecurr;
+			my $has_parens = 0;
+			my $has_quotes = 0;
+
+			my $input = $line;
+			if ($line =~ /(?:\bcommit\s+[0-9a-f]{5,}|\bcommit\s*$)/i) {
+				for (my $n = 0; $n < 2; $n++) {
+					if ($input =~ /\bcommit\s+[0-9a-f]{5,}\s*($balanced_parens)/i) {
+						$orig_desc = $1;
+						$has_parens = 1;
+						# Always strip leading/trailing parens then double quotes if existing
+						$orig_desc = substr($orig_desc, 1, -1);
+						if ($orig_desc =~ /^".*"$/) {
+							$orig_desc = substr($orig_desc, 1, -1);
+							$has_quotes = 1;
+						}
+						last;
+					}
+					last if ($#lines < $linenr + $n);
+					$input .= " " . trim($rawlines[$linenr + $n]);
+					$herectx .= "$rawlines[$linenr + $n]\n";
+				}
+				$herectx = $herecurr if (!$has_parens);
+			}
 
-			if ($line =~ /\b(c)ommit\s+([0-9a-f]{5,})\b/i) {
+			if ($input =~ /\b(c)ommit\s+([0-9a-f]{5,})\b/i) {
 				$init_char = $1;
 				$orig_commit = lc($2);
-			} elsif ($line =~ /\b([0-9a-f]{12,40})\b/i) {
+				$short = 0 if ($input =~ /\bcommit\s+[0-9a-f]{12,40}/i);
+				$long = 1 if ($input =~ /\bcommit\s+[0-9a-f]{41,}/i);
+				$space = 0 if ($input =~ /\bcommit [0-9a-f]/i);
+				$case = 0 if ($input =~ /\b[Cc]ommit\s+[0-9a-f]{5,40}[^A-F]/);
+			} elsif ($input =~ /\b([0-9a-f]{12,40})\b/i) {
 				$orig_commit = lc($1);
 			}
 
-			$short = 0 if ($line =~ /\bcommit\s+[0-9a-f]{12,40}/i);
-			$long = 1 if ($line =~ /\bcommit\s+[0-9a-f]{41,}/i);
-			$space = 0 if ($line =~ /\bcommit [0-9a-f]/i);
-			$case = 0 if ($line =~ /\b[Cc]ommit\s+[0-9a-f]{5,40}[^A-F]/);
-			if ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)"\)/i) {
-				$orig_desc = $1;
-				$hasparens = 1;
-			} elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s*$/i &&
-				 defined $rawlines[$linenr] &&
-				 $rawlines[$linenr] =~ /^\s*\("([^"]+)"\)/) {
-				$orig_desc = $1;
-				$hasparens = 1;
-			} elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("[^"]+$/i &&
-				 defined $rawlines[$linenr] &&
-				 $rawlines[$linenr] =~ /^\s*[^"]+"\)/) {
-				$line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)$/i;
-				$orig_desc = $1;
-				$rawlines[$linenr] =~ /^\s*([^"]+)"\)/;
-				$orig_desc .= " " . $1;
-				$hasparens = 1;
-			}
-
 			($id, $description) = git_commit_info($orig_commit,
 							      $id, $orig_desc);
 
 			if (defined($id) &&
-			   ($short || $long || $space || $case || ($orig_desc ne $description) || !$hasparens)) {
+			    ($short || $long || $space || $case || ($orig_desc ne $description) || !$has_quotes) &&
+			    $last_git_commit_id_linenr != $linenr - 1) {
 				ERROR("GIT_COMMIT_ID",
-				      "Please use git commit description style 'commit <12+ chars of sha1> (\"<title line>\")' - ie: '${init_char}ommit $id (\"$description\")'\n" . $herecurr);
+				      "Please use git commit description style 'commit <12+ chars of sha1> (\"<title line>\")' - ie: '${init_char}ommit $id (\"$description\")'\n" . $herectx);
 			}
+			#don't report the next line if this line ends in commit and the sha1 hash is the next line
+			$last_git_commit_id_linenr = $linenr if ($line =~ /\bcommit\s*$/i);
 		}
 
 # Check for added, moved or deleted files

_

author maintainer
#156 lore raw

PATCH 127/147 fs/epoll: use a per-cpu counter for user's watches count

In reply to Andrew Morton

From: Nicholas Piggin <[email protected]>
Subject: fs/epoll: use a per-cpu counter for user's watches count

This counter tracks the number of watches a user has, to compare against the 'max_user_watches' limit. This causes a scalability bottleneck on SPECjbb2015 on large systems as there is only one user. Changing to a per-cpu counter increases throughput of the benchmark by about 30% on a 16-socket, > 1000 thread system.

[[email protected]: fix build errors in kernel/user.c when CONFIG_EPOLL=n]
[[email protected]: move ifdefs into wrapper functions, slightly improve panic message]
[[email protected]: tweak user_epoll_alloc(), per Guenter]
Cc Alexander Viro <[email protected]>

---

 fs/eventpoll.c             |   18 ++++++++++--------
 include/linux/sched/user.h |    3 ++-
 kernel/user.c              |   25 +++++++++++++++++++++++++
 3 files changed, 37 insertions(+), 9 deletions(-)
fs/eventpoll.c renamed from fs/eventpoll.c~fs-epoll-use-a-per-cpu-counter-for-users-watches-count +10 -8
@@ -723,7 +723,7 @@ static int ep_remove(struct eventpoll *e
 	 */
 	call_rcu(&epi->rcu, epi_rcu_free);
 
-	atomic_long_dec(&ep->user->epoll_watches);
+	percpu_counter_dec(&ep->user->epoll_watches);
 
 	return 0;
 }
@@ -1439,7 +1439,6 @@ static int ep_insert(struct eventpoll *e
 {
 	int error, pwake = 0;
 	__poll_t revents;
-	long user_watches;
 	struct epitem *epi;
 	struct ep_pqueue epq;
 	struct eventpoll *tep = NULL;
@@ -1449,11 +1448,15 @@ static int ep_insert(struct eventpoll *e
 
 	lockdep_assert_irqs_enabled();
 
-	user_watches = atomic_long_read(&ep->user->epoll_watches);
-	if (unlikely(user_watches >= max_user_watches))
+	if (unlikely(percpu_counter_compare(&ep->user->epoll_watches,
+					    max_user_watches) >= 0))
 		return -ENOSPC;
-	if (!(epi = kmem_cache_zalloc(epi_cache, GFP_KERNEL)))
+	percpu_counter_inc(&ep->user->epoll_watches);
+
+	if (!(epi = kmem_cache_zalloc(epi_cache, GFP_KERNEL))) {
+		percpu_counter_dec(&ep->user->epoll_watches);
 		return -ENOMEM;
+	}
 
 	/* Item initialization follow here ... */
 	INIT_LIST_HEAD(&epi->rdllink);
@@ -1466,17 +1469,16 @@ static int ep_insert(struct eventpoll *e
 		mutex_lock_nested(&tep->mtx, 1);
 	/* Add the current item to the list of active epoll hook for this file */
 	if (unlikely(attach_epitem(tfile, epi) < 0)) {
-		kmem_cache_free(epi_cache, epi);
 		if (tep)
 			mutex_unlock(&tep->mtx);
+		kmem_cache_free(epi_cache, epi);
+		percpu_counter_dec(&ep->user->epoll_watches);
 		return -ENOMEM;
 	}
 
 	if (full_check && !tep)
 		list_file(tfile);
 
-	atomic_long_inc(&ep->user->epoll_watches);
-
 	/*
 	 * Add the current item to the RB tree. All RB tree operations are
 	 * protected by "mtx", and ep_insert() is called with "mtx" held.
include/linux/sched/user.h renamed from include/linux/sched/user.h~fs-epoll-use-a-per-cpu-counter-for-users-watches-count +2 -1
@@ -4,6 +4,7 @@
 
 #include <linux/uidgid.h>
 #include <linux/atomic.h>
+#include <linux/percpu_counter.h>
 #include <linux/refcount.h>
 #include <linux/ratelimit.h>
 
@@ -13,7 +14,7 @@
 struct user_struct {
 	refcount_t __count;	/* reference count */
 #ifdef CONFIG_EPOLL
-	atomic_long_t epoll_watches; /* The number of file descriptors currently watched */
+	struct percpu_counter epoll_watches; /* The number of file descriptors currently watched */
 #endif
 	unsigned long unix_inflight;	/* How many files in flight in unix sockets */
 	atomic_long_t pipe_bufs;  /* how many pages are allocated in pipe buffers */
kernel/user.c renamed from kernel/user.c~fs-epoll-use-a-per-cpu-counter-for-users-watches-count +25 -0
@@ -129,6 +129,22 @@ static struct user_struct *uid_hash_find
 	return NULL;
 }
 
+static int user_epoll_alloc(struct user_struct *up)
+{
+#ifdef CONFIG_EPOLL
+	return percpu_counter_init(&up->epoll_watches, 0, GFP_KERNEL);
+#else
+	return 0;
+#endif
+}
+
+static void user_epoll_free(struct user_struct *up)
+{
+#ifdef CONFIG_EPOLL
+	percpu_counter_destroy(&up->epoll_watches);
+#endif
+}
+
 /* IRQs are disabled and uidhash_lock is held upon function entry.
  * IRQ state (as stored in flags) is restored and uidhash_lock released
  * upon function exit.
@@ -138,6 +154,7 @@ static void free_user(struct user_struct
 {
 	uid_hash_remove(up);
 	spin_unlock_irqrestore(&uidhash_lock, flags);
+	user_epoll_free(up);
 	kmem_cache_free(uid_cachep, up);
 }
 
@@ -185,6 +202,10 @@ struct user_struct *alloc_uid(kuid_t uid
 
 		new->uid = uid;
 		refcount_set(&new->__count, 1);
+		if (user_epoll_alloc(new)) {
+			kmem_cache_free(uid_cachep, new);
+			return NULL;
+		}
 		ratelimit_state_init(&new->ratelimit, HZ, 100);
 		ratelimit_set_flags(&new->ratelimit, RATELIMIT_MSG_ON_RELEASE);
 
@@ -195,6 +216,7 @@ struct user_struct *alloc_uid(kuid_t uid
 		spin_lock_irq(&uidhash_lock);
 		up = uid_hash_find(uid, hashent);
 		if (up) {
+			user_epoll_free(new);
 			kmem_cache_free(uid_cachep, new);
 		} else {
 			uid_hash_insert(new, hashent);
@@ -216,6 +238,9 @@ static int __init uid_cache_init(void)
 	for(n = 0; n < UIDHASH_SZ; ++n)
 		INIT_HLIST_HEAD(uidhash_table + n);
 
+	if (user_epoll_alloc(&root_user))
+		panic("root_user epoll percpu counter alloc failed");
+
 	/* Insert the root user immediately (init already runs as root) */
 	spin_lock_irq(&uidhash_lock);
 	uid_hash_insert(&root_user, uidhashentry(GLOBAL_ROOT_UID));

_

author maintainer
#157 lore raw

PATCH 128/147 init: move usermodehelper_enable() to populate_rootfs()

In reply to Andrew Morton

From: Rasmus Villemoes <[email protected]>
Subject: init: move usermodehelper_enable() to populate_rootfs()

Currently, usermodehelper is enabled right before PID1 starts going through the initcalls. However, any call of a usermodehelper from a pure_, core_, postcore_, arch_, subsys_ or fs_ initcall is futile, as there is no filesystem contents yet.

Up until commit e7cb072eb988 ("init/initramfs.c: do unpacking asynchronously"), such calls, whether via some request_module(), a legacy uevent "/sbin/hotplug" notification or something else, would just fail silently with (presumably) -ENOENT from kernel_execve(). However, that commit introduced the wait_for_initramfs() synchronization hook which must be called from the usermodehelper exec path right before the kernel_execve, in order that request_module() et al done from *after* rootfs_initcall() time (i.e. device_ and late_ initcalls) would continue to find a populated initramfs as they used to.

Any call of wait_for_initramfs() done before the unpacking has been scheduled (i.e. before rootfs_initcall time) must just return immediately [and let the caller find an empty file system] in order not to deadlock the machine. I mistakenly thought, and my limited testing confirmed, that there were no such calls, so I added a pr_warn_once() in wait_for_initramfs(). It turns out that one can indeed hit request_module() as well as kobject_uevent_env() during those early init calls, leading to a user-visible warning in the kernel log emitted consistently for certain configurations.

We could just remove the pr_warn_once(), but I think it's better to postpone enabling the usermodehelper framework until there is at least some chance of finding the executable. That is also a little more efficient in that a lot of work done in umh.c will be elided. However, it does change the error seen by those early callers from -ENOENT to -EBUSY, so there is a risk of a regression if any caller care about the exact error value.

---

 init/initramfs.c   |    2 ++
 init/main.c        |    1 -
 init/noinitramfs.c |    2 ++
 3 files changed, 4 insertions(+), 1 deletion(-)
init/initramfs.c renamed from init/initramfs.c~init-move-usermodehelper_enable-to-populate_rootfs +2 -0
@@ -15,6 +15,7 @@
 #include <linux/mm.h>
 #include <linux/namei.h>
 #include <linux/init_syscalls.h>
+#include <linux/umh.h>
 
 static ssize_t __init xwrite(struct file *file, const char *p, size_t count,
 		loff_t *pos)
@@ -727,6 +728,7 @@ static int __init populate_rootfs(void)
 {
 	initramfs_cookie = async_schedule_domain(do_populate_rootfs, NULL,
 						 &initramfs_domain);
+	usermodehelper_enable();
 	if (!initramfs_async)
 		wait_for_initramfs();
 	return 0;
init/main.c renamed from init/main.c~init-move-usermodehelper_enable-to-populate_rootfs +0 -1
@@ -1392,7 +1392,6 @@ static void __init do_basic_setup(void)
 	driver_init();
 	init_irq_proc();
 	do_ctors();
-	usermodehelper_enable();
 	do_initcalls();
 }
 
init/noinitramfs.c renamed from init/noinitramfs.c~init-move-usermodehelper_enable-to-populate_rootfs +2 -0
@@ -10,6 +10,7 @@
 #include <linux/kdev_t.h>
 #include <linux/syscalls.h>
 #include <linux/init_syscalls.h>
+#include <linux/umh.h>
 
 /*
  * Create a simple rootfs that is similar to the default initramfs
@@ -18,6 +19,7 @@ static int __init default_rootfs(void)
 {
 	int err;
 
+	usermodehelper_enable();
 	err = init_mkdir("/dev", 0755);
 	if (err < 0)
 		goto out;

_

Reviewed-by on v1 128/147
#158 lore raw

Re: [patch 128/147] init: move usermodehelper_enable() to populate_rootfs()

Quoted 19 lines · Andrew Morton

From: Rasmus Villemoes <[email protected]>
Subject: init: move usermodehelper_enable() to populate_rootfs()

Currently, usermodehelper is enabled right before PID1 starts going through the initcalls. However, any call of a usermodehelper from a pure_, core_, postcore_, arch_, subsys_ or fs_ initcall is futile, as there is no filesystem contents yet.

Up until commit e7cb072eb988 ("init/initramfs.c: do unpacking asynchronously"), such calls, whether via some request_module(), a legacy uevent "/sbin/hotplug" notification or something else, would just fail silently with (presumably) -ENOENT from kernel_execve(). However, that commit introduced the wait_for_initramfs() synchronization hook which must be called from the usermodehelper exec path right before the kernel_execve, in order that request_module() et al done from *after* rootfs_initcall() time (i.e. device_ and late_ initcalls) would continue to find a populated initramfs as they used to.

Quoted 9 lines

Any call of wait_for_initramfs() done before the unpacking has been scheduled (i.e. before rootfs_initcall time) must just return immediately [and let the caller find an empty file system] in order not to deadlock the machine. I mistakenly thought, and my limited testing confirmed, that there were no such calls, so I added a pr_warn_once() in wait_for_initramfs(). It turns out that one can indeed hit request_module() as well as kobject_uevent_env() during those early init calls, leading to a user-visible warning in the kernel log emitted consistently for certain configurations.

Further proof that the semantics for init is still loose. Formalizing dependencies on init is something we should strive to. Eventualy with a DAG. The linker-tables work I had done years ago strived to get us there which allows us to get a simple explicit DAG through the linker. Unfortunately that patch set fell through because folks were more interested in questioning the alternative side benefits of linker-tables, but the use-case for helping with init is still valid.

If we *do* want to resurrect this folks should let me know.

Since the kobject_uevent_env() interest here is for /sbin/hotplug and that crap is deprecated, in practice the relevant calls we'd care about are the request_module() calls.

Quoted 4 lines

We could just remove the pr_warn_once(), but I think it's better to postpone enabling the usermodehelper framework until there is at least some chance of finding the executable. That is also a little more efficient in that a lot of work done in umh.c will be elided.

I *don't* think we were aware that such request_module() calls were happening before the fs was even ready and failing silently with -ENOENT. As such, although moving the usermodehelper_enable() to right after scheduling populating the rootfs is the right thing, we do loose on the opportunity to learn who were those odd callers before. We could not care... but this is also a missed opportunity in finding those. How important that is, is not clear to me as this was silently failing before...

If we wanted to keep a print for the above purpose though, we'd likely want the full stack trace to see who the hell made the call.

Quoted 4 lines

However,
it does change the error seen by those early callers from -ENOENT to -EBUSY, so there is a risk of a regression if any caller care about the exact error value.

I'd see this as a welcomed evolution as it tells us more: we're saying "it's coming, try again" or whatever.

A debug option to allow us to get a full warning trace in the -EBUSY case on early init would be nice to have.

Otherwise:

Luis

Quoted 62 lines

---

 init/initramfs.c   |    2 ++
 init/main.c        |    1 -
 init/noinitramfs.c |    2 ++
 3 files changed, 4 insertions(+), 1 deletion(-)
init/initramfs.c renamed from init/initramfs.c~init-move-usermodehelper_enable-to-populate_rootfs +2 -0
@@ -15,6 +15,7 @@
 #include <linux/mm.h>
 #include <linux/namei.h>
 #include <linux/init_syscalls.h>
+#include <linux/umh.h>
 
 static ssize_t __init xwrite(struct file *file, const char *p, size_t count,
 		loff_t *pos)
@@ -727,6 +728,7 @@ static int __init populate_rootfs(void)
 {
 	initramfs_cookie = async_schedule_domain(do_populate_rootfs, NULL,
 						 &initramfs_domain);
+	usermodehelper_enable();
 	if (!initramfs_async)
 		wait_for_initramfs();
 	return 0;
init/main.c renamed from init/main.c~init-move-usermodehelper_enable-to-populate_rootfs +0 -1
@@ -1392,7 +1392,6 @@ static void __init do_basic_setup(void)
 	driver_init();
 	init_irq_proc();
 	do_ctors();
-	usermodehelper_enable();
 	do_initcalls();
 }
 
init/noinitramfs.c renamed from init/noinitramfs.c~init-move-usermodehelper_enable-to-populate_rootfs +2 -0
@@ -10,6 +10,7 @@
 #include <linux/kdev_t.h>
 #include <linux/syscalls.h>
 #include <linux/init_syscalls.h>
+#include <linux/umh.h>
 
 /*
  * Create a simple rootfs that is similar to the default initramfs
@@ -18,6 +19,7 @@ static int __init default_rootfs(void)
 {
 	int err;
 
+	usermodehelper_enable();
 	err = init_mkdir("/dev", 0755);
 	if (err < 0)
 		goto out;

_

#159 lore raw

Re: [patch 128/147] init: move usermodehelper_enable() to populate_rootfs()

Quoted 20 lines · Luis Chamberlain
Quoted 10 lines · Andrew Morton

From: Rasmus Villemoes <[email protected]>
Any call of wait_for_initramfs() done before the unpacking has been scheduled (i.e. before rootfs_initcall time) must just return immediately [and let the caller find an empty file system] in order not to deadlock the machine. I mistakenly thought, and my limited testing confirmed, that there were no such calls, so I added a pr_warn_once() in wait_for_initramfs(). It turns out that one can indeed hit request_module() as well as kobject_uevent_env() during those early init calls, leading to a user-visible warning in the kernel log emitted consistently for certain configurations.

Further proof that the semantics for init is still loose. Formalizing dependencies on init is something we should strive to. Eventualy with a DAG. The linker-tables work I had done years ago strived to get us there which allows us to get a simple explicit DAG through the linker. Unfortunately that patch set fell through because folks were more interested in questioning the alternative side benefits of linker-tables, but the use-case for helping with init is still valid.

Quoted 1 line

If we *do* want to resurrect this folks should let me know.

Heh, a while back I actually had some completely unrelated thing where I'd want to make use of the linker tables infrastructure - I remembered reading about it on LWN, and was quite surprised when I learnt that that work had never made it in. I don't quite remember the use case (I think it was for some test module infrastructure). But if you do have time to resurrect those patches, I'd certainly be interested.

Quoted 3 lines

Since the kobject_uevent_env() interest here is for /sbin/hotplug and that crap is deprecated, in practice the relevant calls we'd care about are the request_module() calls.

Yes - the first report I got about that pr_warn_once was indeed fixed by the reporter simply disabling CONFIG_UEVENT_HELPER
(https://lore.kernel.org/lkml/[email protected]/).

Quoted 8 lines
Quoted 4 lines

We could just remove the pr_warn_once(), but I think it's better to postpone enabling the usermodehelper framework until there is at least some chance of finding the executable. That is also a little more efficient in that a lot of work done in umh.c will be elided.

I *don't* think we were aware that such request_module() calls were happening before the fs was even ready and failing silently with -ENOENT.

Probably not, no, otherwise somebody would have noticed.

As such, although moving the usermodehelper_enable()

Quoted 8 lines

to right after scheduling populating the rootfs is the right thing, we do loose on the opportunity to learn who were those odd callers before. We could not care... but this is also a missed opportunity in finding those. How important that is, is not clear to me as this was silently failing before...

If we wanted to keep a print for the above purpose though, we'd likely want the full stack trace to see who the hell made the call.

Well, yes, I have myself fallen into that trap not just once, but at least twice. The first time when I discovered this behaviour on one of the ppc targets I did this work for in the first place (before I came up with the CONFIG_MODPROBE_PATH patch). The second when I asked a reporter to replace the pr_warn_once by WARN_ONCE:

https://lore.kernel.org/lkml/[email protected]/

The problem is that request_module() just fires off some worker thread and then the original calling thread sits back and waits for that worker to return a result.

Quoted 7 lines
Quoted 4 lines

However,
it does change the error seen by those early callers from -ENOENT to -EBUSY, so there is a risk of a regression if any caller care about the exact error value.

I'd see this as a welcomed evolution as it tells us more: we're saying "it's coming, try again" or whatever.

Indeed, and I don't think it's the end of the world if somebody notices some change due to that, because we'd learn more about where those early request_module() calls come from.

Quoted 2 lines

A debug option to allow us to get a full warning trace in the -EBUSY case on early init would be nice to have.

As noted above, that's difficult. We'd need a way to know which other task is waiting for us, then print the trace of that guy.

I don't think anybody is gonna hear this tree falling, so let's not try to solve a problem before we know there is one.

Rasmus

#160 lore raw

Re: [patch 128/147] init: move usermodehelper_enable() to populate_rootfs()

I feel there is a general problem with the way infrastructure improvements are dealt with in the kernel – basically it feels like the submitter of new infrastructure is expected to convert existing users or "what we have now works." This is a classic way of building tech debt.

Maybe this might be a topic to discuss?

Quoted 95 lines · Rasmus Villemoes
Quoted 20 lines · Luis Chamberlain
Quoted 10 lines · Andrew Morton

From: Rasmus Villemoes <[email protected]>
Any call of wait_for_initramfs() done before the unpacking has been scheduled (i.e. before rootfs_initcall time) must just return immediately [and let the caller find an empty file system] in order not to deadlock the machine. I mistakenly thought, and my limited testing confirmed, that there were no such calls, so I added a pr_warn_once() in wait_for_initramfs(). It turns out that one can indeed hit request_module() as well as kobject_uevent_env() during those early init calls, leading to a user-visible warning in the kernel log emitted consistently for certain configurations.

Further proof that the semantics for init is still loose. Formalizing dependencies on init is something we should strive to. Eventualy with a DAG. The linker-tables work I had done years ago strived to get us there which allows us to get a simple explicit DAG through the linker. Unfortunately that patch set fell through because folks were more interested in questioning the alternative side benefits of linker-tables, but the use-case for helping with init is still valid.

Quoted 1 line

If we *do* want to resurrect this folks should let me know.

Heh, a while back I actually had some completely unrelated thing where I'd want to make use of the linker tables infrastructure - I remembered reading about it on LWN, and was quite surprised when I learnt that that work had never made it in. I don't quite remember the use case (I think it was for some test module infrastructure). But if you do have time to resurrect those patches, I'd certainly be interested.

Quoted 3 lines

Since the kobject_uevent_env() interest here is for /sbin/hotplug and that crap is deprecated, in practice the relevant calls we'd care about are the request_module() calls.

Yes - the first report I got about that pr_warn_once was indeed fixed by the reporter simply disabling CONFIG_UEVENT_HELPER
(https://lore.kernel.org/lkml/[email protected]/).

Quoted 8 lines
Quoted 4 lines

We could just remove the pr_warn_once(), but I think it's better to postpone enabling the usermodehelper framework until there is at least some chance of finding the executable. That is also a little more efficient in that a lot of work done in umh.c will be elided.

I *don't* think we were aware that such request_module() calls were happening before the fs was even ready and failing silently with -ENOENT.

Probably not, no, otherwise somebody would have noticed.

As such, although moving the usermodehelper_enable()

Quoted 8 lines

to right after scheduling populating the rootfs is the right thing, we do loose on the opportunity to learn who were those odd callers before. We could not care... but this is also a missed opportunity in finding those. How important that is, is not clear to me as this was silently failing before...

If we wanted to keep a print for the above purpose though, we'd likely want the full stack trace to see who the hell made the call.

Well, yes, I have myself fallen into that trap not just once, but at least twice. The first time when I discovered this behaviour on one of the ppc targets I did this work for in the first place (before I came up with the CONFIG_MODPROBE_PATH patch). The second when I asked a reporter to replace the pr_warn_once by WARN_ONCE:

https://lore.kernel.org/lkml/[email protected]/

The problem is that request_module() just fires off some worker thread and then the original calling thread sits back and waits for that worker to return a result.

Quoted 7 lines
Quoted 4 lines

However,
it does change the error seen by those early callers from -ENOENT to -EBUSY, so there is a risk of a regression if any caller care about the exact error value.

I'd see this as a welcomed evolution as it tells us more: we're saying "it's coming, try again" or whatever.

Indeed, and I don't think it's the end of the world if somebody notices some change due to that, because we'd learn more about where those early request_module() calls come from.

Quoted 2 lines

A debug option to allow us to get a full warning trace in the -EBUSY case on early init would be nice to have.

As noted above, that's difficult. We'd need a way to know which other task is waiting for us, then print the trace of that guy.

I don't think anybody is gonna hear this tree falling, so let's not try to solve a problem before we know there is one.

Rasmus

Signature · 1 line
Sent from my Android device with K-9 Mail. Please excuse my brevity.
#161 lore raw

Re: [patch 128/147] init: move usermodehelper_enable() to populate_rootfs()

In reply to Rasmus Villemoes
Quoted 21 lines · Rasmus Villemoes
Quoted 20 lines · Luis Chamberlain
Quoted 10 lines · Andrew Morton

From: Rasmus Villemoes <[email protected]>
Any call of wait_for_initramfs() done before the unpacking has been scheduled (i.e. before rootfs_initcall time) must just return immediately [and let the caller find an empty file system] in order not to deadlock the machine. I mistakenly thought, and my limited testing confirmed, that there were no such calls, so I added a pr_warn_once() in wait_for_initramfs(). It turns out that one can indeed hit request_module() as well as kobject_uevent_env() during those early init calls, leading to a user-visible warning in the kernel log emitted consistently for certain configurations.

Further proof that the semantics for init is still loose. Formalizing dependencies on init is something we should strive to. Eventualy with a DAG. The linker-tables work I had done years ago strived to get us there which allows us to get a simple explicit DAG through the linker. Unfortunately that patch set fell through because folks were more interested in questioning the alternative side benefits of linker-tables, but the use-case for helping with init is still valid.

Quoted 8 lines
Quoted 1 line

If we *do* want to resurrect this folks should let me know.

Heh, a while back I actually had some completely unrelated thing where I'd want to make use of the linker tables infrastructure - I remembered reading about it on LWN, and was quite surprised when I learnt that that work had never made it in. I don't quite remember the use case (I think it was for some test module infrastructure). But if you do have time to resurrect those patches, I'd certainly be interested.

OK I might.

Quoted 7 lines
Quoted 3 lines

Since the kobject_uevent_env() interest here is for /sbin/hotplug and that crap is deprecated, in practice the relevant calls we'd care about are the request_module() calls.

Yes - the first report I got about that pr_warn_once was indeed fixed by the reporter simply disabling CONFIG_UEVENT_HELPER
(https://lore.kernel.org/lkml/[email protected]/).

Ah I see.

Quoted 10 lines
Quoted 8 lines
Quoted 4 lines

We could just remove the pr_warn_once(), but I think it's better to postpone enabling the usermodehelper framework until there is at least some chance of finding the executable. That is also a little more efficient in that a lot of work done in umh.c will be elided.

I *don't* think we were aware that such request_module() calls were happening before the fs was even ready and failing silently with -ENOENT.

Probably not, no, otherwise somebody would have noticed.

OK your commit log was not clear on this, it seemed to suggest this as a possibility or that such a case existed. That also means the impact of your change is less.

Quoted 11 lines
Quoted 7 lines
Quoted 4 lines

However,
it does change the error seen by those early callers from -ENOENT to -EBUSY, so there is a risk of a regression if any caller care about the exact error value.

I'd see this as a welcomed evolution as it tells us more: we're saying "it's coming, try again" or whatever.

Indeed, and I don't think it's the end of the world if somebody notices some change due to that, because we'd learn more about where those early request_module() calls come from.

But since it would seem none have been reported yet, it is an even better situation.

Quoted 8 lines
Quoted 2 lines

A debug option to allow us to get a full warning trace in the -EBUSY case on early init would be nice to have.

As noted above, that's difficult. We'd need a way to know which other task is waiting for us, then print the trace of that guy.

I don't think anybody is gonna hear this tree falling, so let's not try to solve a problem before we know there is one.

That's fair. But let's also recall neither of us expected the above situation either. But I agree the possible collateral at this point seems to be small, if any.

Luis

author maintainer
#162 lore raw

PATCH 129/147 trap: cleanup trap_init()

In reply to Andrew Morton

From: Kefeng Wang <[email protected]>
Subject: trap: cleanup trap_init()

There are some empty trap_init() definitions in different ARCHs, Introduce a new weak trap_init() function to clean them up.

Acked-by Vineet Gupta [arc]
Cc Yoshinori Sato <[email protected]>
Cc Ley Foon Tan <[email protected]>
Cc Jonas Bonn <[email protected]>
Cc Stefan Kristiansson <[email protected]>
Cc Stafford Horne <[email protected]>
Cc James E.J. Bottomley <[email protected]>
Cc Helge Deller <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Paul Walmsley <[email protected]>
Cc Jeff Dike <[email protected]>
Cc Richard Weinberger <[email protected]>
Cc Anton Ivanov <[email protected]>

---

 arch/arc/kernel/traps.c      |    5 -----
 arch/arm/kernel/traps.c      |    5 -----
 arch/h8300/kernel/traps.c    |    4 ----
 arch/hexagon/kernel/traps.c  |    4 ----
 arch/nds32/kernel/traps.c    |    5 -----
 arch/nios2/kernel/traps.c    |    5 -----
 arch/openrisc/kernel/traps.c |    5 -----
 arch/parisc/kernel/traps.c   |    4 ----
 arch/powerpc/kernel/traps.c  |    5 -----
 arch/riscv/kernel/traps.c    |    5 -----
 arch/um/kernel/trap.c        |    4 ----
 init/main.c                  |    2 ++
 12 files changed, 2 insertions(+), 51 deletions(-)
arch/arc/kernel/traps.c renamed from arch/arc/kernel/traps.c~trap-cleanup-trap_init +0 -5
@@ -20,11 +20,6 @@
 #include <asm/unaligned.h>
 #include <asm/kprobes.h>
 
-void __init trap_init(void)
-{
-	return;
-}
-
 void die(const char *str, struct pt_regs *regs, unsigned long address)
 {
 	show_kernel_fault_diag(str, regs, address);
arch/arm/kernel/traps.c renamed from arch/arm/kernel/traps.c~trap-cleanup-trap_init +0 -5
@@ -781,11 +781,6 @@ void abort(void)
 	panic("Oops failed to kill thread");
 }
 
-void __init trap_init(void)
-{
-	return;
-}
-
 #ifdef CONFIG_KUSER_HELPERS
 static void __init kuser_init(void *vectors)
 {
arch/h8300/kernel/traps.c renamed from arch/h8300/kernel/traps.c~trap-cleanup-trap_init +0 -4
@@ -39,10 +39,6 @@ void __init base_trap_init(void)
 {
 }
 
-void __init trap_init(void)
-{
-}
-
 asmlinkage void set_esp0(unsigned long ssp)
 {
 	current->thread.esp0 = ssp;
arch/hexagon/kernel/traps.c renamed from arch/hexagon/kernel/traps.c~trap-cleanup-trap_init +0 -4
@@ -28,10 +28,6 @@
 #define TRAP_SYSCALL	1
 #define TRAP_DEBUG	0xdb
 
-void __init trap_init(void)
-{
-}
-
 #ifdef CONFIG_GENERIC_BUG
 /* Maybe should resemble arch/sh/kernel/traps.c ?? */
 int is_valid_bugaddr(unsigned long addr)
arch/nds32/kernel/traps.c renamed from arch/nds32/kernel/traps.c~trap-cleanup-trap_init +0 -5
@@ -183,11 +183,6 @@ void __pgd_error(const char *file, int l
 }
 
 extern char *exception_vector, *exception_vector_end;
-void __init trap_init(void)
-{
-	return;
-}
-
 void __init early_trap_init(void)
 {
 	unsigned long ivb = 0;
arch/nios2/kernel/traps.c renamed from arch/nios2/kernel/traps.c~trap-cleanup-trap_init +0 -5
@@ -105,11 +105,6 @@ void show_stack(struct task_struct *task
 	printk("%s\n", loglvl);
 }
 
-void __init trap_init(void)
-{
-	/* Nothing to do here */
-}
-
 /* Breakpoint handler */
 asmlinkage void breakpoint_c(struct pt_regs *fp)
 {
arch/openrisc/kernel/traps.c renamed from arch/openrisc/kernel/traps.c~trap-cleanup-trap_init +0 -5
@@ -231,11 +231,6 @@ void unhandled_exception(struct pt_regs
 	die("Oops", regs, 9);
 }
 
-void __init trap_init(void)
-{
-	/* Nothing needs to be done */
-}
-
 asmlinkage void do_trap(struct pt_regs *regs, unsigned long address)
 {
 	force_sig_fault(SIGTRAP, TRAP_BRKPT, (void __user *)regs->pc);
arch/parisc/kernel/traps.c renamed from arch/parisc/kernel/traps.c~trap-cleanup-trap_init +0 -4
@@ -859,7 +859,3 @@ void  __init early_trap_init(void)
 
 	initialize_ivt(&fault_vector_20);
 }
-
-void __init trap_init(void)
-{
-}
arch/powerpc/kernel/traps.c renamed from arch/powerpc/kernel/traps.c~trap-cleanup-trap_init +0 -5
@@ -2215,11 +2215,6 @@ DEFINE_INTERRUPT_HANDLER(kernel_bad_stac
 	die("Bad kernel stack pointer", regs, SIGABRT);
 }
 
-void __init trap_init(void)
-{
-}
-
-
 #ifdef CONFIG_PPC_EMULATED_STATS
 
 #define WARN_EMULATED_SETUP(type)	.type = { .name = #type }
arch/riscv/kernel/traps.c renamed from arch/riscv/kernel/traps.c~trap-cleanup-trap_init +0 -5
@@ -199,11 +199,6 @@ int is_valid_bugaddr(unsigned long pc)
 }
 #endif /* CONFIG_GENERIC_BUG */
 
-/* stvec & scratch is already set from head.S */
-void __init trap_init(void)
-{
-}
-
 #ifdef CONFIG_VMAP_STACK
 static DEFINE_PER_CPU(unsigned long [OVERFLOW_STACK_SIZE/sizeof(long)],
 		overflow_stack)__aligned(16);
arch/um/kernel/trap.c renamed from arch/um/kernel/trap.c~trap-cleanup-trap_init +0 -4
@@ -311,7 +311,3 @@ void winch(int sig, struct siginfo *unus
 {
 	do_IRQ(WINCH_IRQ, regs);
 }
-
-void trap_init(void)
-{
-}
init/main.c renamed from init/main.c~trap-cleanup-trap_init +2 -0
@@ -777,6 +777,8 @@ void __init __weak poking_init(void) { }
 
 void __init __weak pgtable_cache_init(void) { }
 
+void __init __weak trap_init(void) { }
+
 bool initcall_debug;
 core_param(initcall_debug, initcall_debug, bool, 0644);
 

_

author maintainer
#163 lore raw

PATCH 130/147 nilfs2: fix memory leak in nilfs_sysfs_create_device_group

In reply to Andrew Morton

From: Nanyong Sun <[email protected]>
Subject: nilfs2: fix memory leak in nilfs_sysfs_create_device_group

Patch series "nilfs2: fix incorrect usage of kobject".

This patchset from Nanyong Sun fixes memory leak issues and a NULL pointer dereference issue caused by incorrect usage of kboject in nilfs2 sysfs implementation.

This patch (of 6):

Reported by syzkaller:

BUG: memory leak

unreferenced object 0xffff888100ca8988 (size 8):
comm "syz-executor.1", pid 1930, jiffies 4294745569 (age 18.052s) hex dump (first 8 bytes):
6c 6f 6f 70 31 00 ff ff loop1...
backtrace:

[<000000009d9e0ac4>] slab_alloc_node mm/slub.c:2972 [inline]
[<000000009d9e0ac4>] slab_alloc mm/slub.c:2980 [inline]
[<000000009d9e0ac4>] __kmalloc_track_caller+0x164/0x330 mm/slub.c:4644
[<00000000b1825477>] kstrdup+0x36/0x70 mm/util.c:60
[<00000000fa081499>] kstrdup_const+0x35/0x60 mm/util.c:83
[<0000000024d13570>] kvasprintf_const+0xf1/0x180 lib/kasprintf.c:48
[<0000000024b69715>] kobject_set_name_vargs+0x56/0x150 lib/kobject.c:289
[<000000003fedac3d>] kobject_add_varg lib/kobject.c:384 [inline]
[<000000003fedac3d>] kobject_init_and_add+0xc9/0x150 lib/kobject.c:473
[<000000002795bd99>] nilfs_sysfs_create_device_group+0x150/0x7d0 fs/nilfs2/sysfs.c:986
[<00000000567fa12d>] init_nilfs+0xa21/0xea0 fs/nilfs2/the_nilfs.c:637
[<00000000082e7458>] nilfs_fill_super fs/nilfs2/super.c:1046 [inline]
[<00000000082e7458>] nilfs_mount+0x7b4/0xe80 fs/nilfs2/super.c:1316
[<00000000adc3fd88>] legacy_get_tree+0x105/0x210 fs/fs_context.c:592
[<00000000a98c45b8>] vfs_get_tree+0x8e/0x2d0 fs/super.c:1498
[<00000000e96282d3>] do_new_mount fs/namespace.c:2905 [inline]
[<00000000e96282d3>] path_mount+0xf9b/0x1990 fs/namespace.c:3235
[<000000003d2eb1b0>] do_mount+0xea/0x100 fs/namespace.c:3248
[<00000000e1ce771a>] __do_sys_mount fs/namespace.c:3456 [inline]
[<00000000e1ce771a>] __se_sys_mount fs/namespace.c:3433 [inline]
[<00000000e1ce771a>] __x64_sys_mount+0x14b/0x1f0 fs/namespace.c:3433
[<000000007c7f81e8>] do_syscall_x64 arch/x86/entry/common.c:50 [inline]
[<000000007c7f81e8>] do_syscall_64+0x3b/0x90 arch/x86/entry/common.c:80
[<00000000fd23ff06>] entry_SYSCALL_64_after_hwframe+0x44/0xae

If kobject_init_and_add return with error, then the cleanup of kobject is needed because memory may be allocated in kobject_init_and_add without freeing.

And the place of cleanup_dev_kobject should use kobject_put to free the memory associated with the kobject. As the section "Kobject removal" of "Documentation/core-api/kobject.rst" says, kobject_del() just makes the kobject "invisible", but it is not cleaned up. And no more cleanup will do after cleanup_dev_kobject, so kobject_put is needed here.

---

 fs/nilfs2/sysfs.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
fs/nilfs2/sysfs.c renamed from fs/nilfs2/sysfs.c~nilfs2-fix-memory-leak-in-nilfs_sysfs_create_device_group +2 -4
@@ -986,7 +986,7 @@ int nilfs_sysfs_create_device_group(stru
 	err = kobject_init_and_add(&nilfs->ns_dev_kobj, &nilfs_dev_ktype, NULL,
 				    "%s", sb->s_id);
 	if (err)
-		goto free_dev_subgroups;
+		goto cleanup_dev_kobject;
 
 	err = nilfs_sysfs_create_mounted_snapshots_group(nilfs);
 	if (err)
@@ -1023,9 +1023,7 @@ delete_mounted_snapshots_group:
 	nilfs_sysfs_delete_mounted_snapshots_group(nilfs);
 
 cleanup_dev_kobject:
-	kobject_del(&nilfs->ns_dev_kobj);
-
-free_dev_subgroups:
+	kobject_put(&nilfs->ns_dev_kobj);
 	kfree(nilfs->ns_dev_subgroups);
 
 failed_create_device_group:

_

author maintainer
#164 lore raw

PATCH 131/147 nilfs2: fix NULL pointer in nilfs_##name##_attr_release

In reply to Andrew Morton

From: Nanyong Sun <[email protected]>
Subject: nilfs2: fix NULL pointer in nilfs_##name##_attr_release

In nilfs_##name##_attr_release, kobj->parent should not be referenced because it is a NULL pointer. The release() method of kobject is always called in kobject_put(kobj), in the implementation of kobject_put(), the kobj->parent will be assigned as NULL before call the release() method. So just use kobj to get the subgroups, which is more efficient and can fix a NULL pointer reference problem.

---

 fs/nilfs2/sysfs.c |    8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
fs/nilfs2/sysfs.c renamed from fs/nilfs2/sysfs.c~nilfs2-fix-null-pointer-in-nilfs_name_attr_release +3 -5
@@ -51,11 +51,9 @@ static const struct sysfs_ops nilfs_##na
 #define NILFS_DEV_INT_GROUP_TYPE(name, parent_name) \
 static void nilfs_##name##_attr_release(struct kobject *kobj) \
 { \
-	struct nilfs_sysfs_##parent_name##_subgroups *subgroups; \
-	struct the_nilfs *nilfs = container_of(kobj->parent, \
-						struct the_nilfs, \
-						ns_##parent_name##_kobj); \
-	subgroups = nilfs->ns_##parent_name##_subgroups; \
+	struct nilfs_sysfs_##parent_name##_subgroups *subgroups = container_of(kobj, \
+						struct nilfs_sysfs_##parent_name##_subgroups, \
+						sg_##name##_kobj); \
 	complete(&subgroups->sg_##name##_kobj_unregister); \
 } \
 static struct kobj_type nilfs_##name##_ktype = { \

_

author maintainer
#165 lore raw

PATCH 132/147 nilfs2: fix memory leak in nilfs_sysfs_create_##name##_group

In reply to Andrew Morton

From: Nanyong Sun <[email protected]>
Subject: nilfs2: fix memory leak in nilfs_sysfs_create_##name##_group

If kobject_init_and_add return with error, kobject_put() is needed here to avoid memory leak, because kobject_init_and_add may return error without freeing the memory associated with the kobject it allocated.

---

 fs/nilfs2/sysfs.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/nilfs2/sysfs.c renamed from fs/nilfs2/sysfs.c~nilfs2-fix-memory-leak-in-nilfs_sysfs_create_name_group +2 -2
@@ -79,8 +79,8 @@ static int nilfs_sysfs_create_##name##_g
 	err = kobject_init_and_add(kobj, &nilfs_##name##_ktype, parent, \
 				    #name); \
 	if (err) \
-		return err; \
-	return 0; \
+		kobject_put(kobj); \
+	return err; \
 } \
 static void nilfs_sysfs_delete_##name##_group(struct the_nilfs *nilfs) \
 { \

_

author maintainer
#166 lore raw

PATCH 133/147 nilfs2: fix memory leak in nilfs_sysfs_delete_##name##_group

In reply to Andrew Morton

From: Nanyong Sun <[email protected]>
Subject: nilfs2: fix memory leak in nilfs_sysfs_delete_##name##_group

The kobject_put() should be used to cleanup the memory associated with the kobject instead of kobject_del. See the section "Kobject removal" of "Documentation/core-api/kobject.rst".

---

 fs/nilfs2/sysfs.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nilfs2/sysfs.c renamed from fs/nilfs2/sysfs.c~nilfs2-fix-memory-leak-in-nilfs_sysfs_delete_name_group +1 -1
@@ -84,7 +84,7 @@ static int nilfs_sysfs_create_##name##_g
 } \
 static void nilfs_sysfs_delete_##name##_group(struct the_nilfs *nilfs) \
 { \
-	kobject_del(&nilfs->ns_##parent_name##_subgroups->sg_##name##_kobj); \
+	kobject_put(&nilfs->ns_##parent_name##_subgroups->sg_##name##_kobj); \
 }
 
 /************************************************************************

_

author maintainer
#167 lore raw

PATCH 134/147 nilfs2: fix memory leak in nilfs_sysfs_create_snapshot_group

In reply to Andrew Morton

From: Nanyong Sun <[email protected]>
Subject: nilfs2: fix memory leak in nilfs_sysfs_create_snapshot_group

If kobject_init_and_add returns with error, kobject_put() is needed here to avoid memory leak, because kobject_init_and_add may return error without freeing the memory associated with the kobject it allocated.

---

 fs/nilfs2/sysfs.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/nilfs2/sysfs.c renamed from fs/nilfs2/sysfs.c~nilfs2-fix-memory-leak-in-nilfs_sysfs_create_snapshot_group +2 -2
@@ -195,9 +195,9 @@ int nilfs_sysfs_create_snapshot_group(st
 	}
 
 	if (err)
-		return err;
+		kobject_put(&root->snapshot_kobj);
 
-	return 0;
+	return err;
 }
 
 void nilfs_sysfs_delete_snapshot_group(struct nilfs_root *root)

_

author maintainer
#168 lore raw

PATCH 135/147 nilfs2: fix memory leak in nilfs_sysfs_delete_snapshot_group

In reply to Andrew Morton

From: Nanyong Sun <[email protected]>
Subject: nilfs2: fix memory leak in nilfs_sysfs_delete_snapshot_group

kobject_put() should be used to cleanup the memory associated with the kobject instead of kobject_del(). See the section "Kobject removal" of "Documentation/core-api/kobject.rst".

---

 fs/nilfs2/sysfs.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nilfs2/sysfs.c renamed from fs/nilfs2/sysfs.c~nilfs2-fix-memory-leak-in-nilfs_sysfs_delete_snapshot_group +1 -1
@@ -202,7 +202,7 @@ int nilfs_sysfs_create_snapshot_group(st
 
 void nilfs_sysfs_delete_snapshot_group(struct nilfs_root *root)
 {
-	kobject_del(&root->snapshot_kobj);
+	kobject_put(&root->snapshot_kobj);
 }
 
 /************************************************************************

_

author maintainer
#169 lore raw

PATCH 136/147 nilfs2: use refcount_dec_and_lock() to fix potential UAF

In reply to Andrew Morton

From: Zhen Lei <[email protected]>
Subject: nilfs2: use refcount_dec_and_lock() to fix potential UAF

When the refcount is decreased to 0, the resource reclamation branch is entered. Before CPU0 reaches the race point (1), CPU1 may obtain the spinlock and traverse the rbtree to find 'root', see nilfs_lookup_root(). Although CPU1 will call refcount_inc() to increase the refcount, it is obviously too late. CPU0 will release 'root' directly, CPU1 then accesses 'root' and triggers UAF.

Use refcount_dec_and_lock() to ensure that both the operations of decrease refcount to 0 and link deletion are lock protected eliminates this risk.

CPU0 CPU1
nilfs_put_root():

			    <-------- (1)

spin_lock(&nilfs->ns_cptree_lock);
rb_erase(&root->rb_node, &nilfs->ns_cptree);
spin_unlock(&nilfs->ns_cptree_lock);

kfree(root);
			    <-------- use-after-free

========================================================================
refcount_t: underflow; use-after-free.

WARNING: CPU: 2 PID: 9476 at lib/refcount.c:28 \
refcount_warn_saturate+0x1cf/0x210 lib/refcount.c:28
Modules linked in:
CPU: 2 PID: 9476 Comm: syz-executor.0 Not tainted 5.10.45-rc1+ #3
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), ...
RIP: 0010:refcount_warn_saturate+0x1cf/0x210 lib/refcount.c:28
... ...
Call Trace:
 __refcount_sub_and_test include/linux/refcount.h:283 [inline]
 __refcount_dec_and_test include/linux/refcount.h:315 [inline]
 refcount_dec_and_test include/linux/refcount.h:333 [inline]
 nilfs_put_root+0xc1/0xd0 fs/nilfs2/the_nilfs.c:795
 nilfs_segctor_destroy fs/nilfs2/segment.c:2749 [inline]
 nilfs_detach_log_writer+0x3fa/0x570 fs/nilfs2/segment.c:2812
 nilfs_put_super+0x2f/0xf0 fs/nilfs2/super.c:467
 generic_shutdown_super+0xcd/0x1f0 fs/super.c:464
 kill_block_super+0x4a/0x90 fs/super.c:1446
 deactivate_locked_super+0x6a/0xb0 fs/super.c:335
 deactivate_super+0x85/0x90 fs/super.c:366
 cleanup_mnt+0x277/0x2e0 fs/namespace.c:1118
 __cleanup_mnt+0x15/0x20 fs/namespace.c:1125
 task_work_run+0x8e/0x110 kernel/task_work.c:151
 tracehook_notify_resume include/linux/tracehook.h:188 [inline]
 exit_to_user_mode_loop kernel/entry/common.c:164 [inline]
 exit_to_user_mode_prepare+0x13c/0x170 kernel/entry/common.c:191
 syscall_exit_to_user_mode+0x16/0x30 kernel/entry/common.c:266
 do_syscall_64+0x45/0x80 arch/x86/entry/common.c:56
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

There is no reproduction program, and the above is only theoretical analysis.

---

 fs/nilfs2/the_nilfs.c |    9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
fs/nilfs2/the_nilfs.c renamed from fs/nilfs2/the_nilfs.c~nilfs2-use-refcount_dec_and_lock-to-fix-potential-uaf +4 -5
@@ -792,14 +792,13 @@ nilfs_find_or_create_root(struct the_nil
 
 void nilfs_put_root(struct nilfs_root *root)
 {
-	if (refcount_dec_and_test(&root->count)) {
-		struct the_nilfs *nilfs = root->nilfs;
+	struct the_nilfs *nilfs = root->nilfs;
 
-		nilfs_sysfs_delete_snapshot_group(root);
-
-		spin_lock(&nilfs->ns_cptree_lock);
+	if (refcount_dec_and_lock(&root->count, &nilfs->ns_cptree_lock)) {
 		rb_erase(&root->rb_node, &nilfs->ns_cptree);
 		spin_unlock(&nilfs->ns_cptree_lock);
+
+		nilfs_sysfs_delete_snapshot_group(root);
 		iput(root->ifile);
 
 		kfree(root);

_

#170 lore raw

Re: [patch 136/147] nilfs2: use refcount_dec_and_lock() to fix potential UAF

Hi!

Quoted 20 lines

From: Zhen Lei <[email protected]>
Subject: nilfs2: use refcount_dec_and_lock() to fix potential UAF

When the refcount is decreased to 0, the resource reclamation branch is entered. Before CPU0 reaches the race point (1), CPU1 may obtain the spinlock and traverse the rbtree to find 'root', see nilfs_lookup_root(). Although CPU1 will call refcount_inc() to increase the refcount, it is obviously too late. CPU0 will release 'root' directly, CPU1 then accesses 'root' and triggers UAF.

Use refcount_dec_and_lock() to ensure that both the operations of decrease refcount to 0 and link deletion are lock protected eliminates this risk.

CPU0 CPU1
nilfs_put_root():

			    <-------- (1)

spin_lock(&nilfs->ns_cptree_lock);
rb_erase(&root->rb_node, &nilfs->ns_cptree);
spin_unlock(&nilfs->ns_cptree_lock);

Quoted 5 lines
kfree(root);
			    <-------- use-after-free

There is no reproduction program, and the above is only theoretical analysis.

Ok, so we have a theoretical bug, and fix already on its way to stable. But ... is it correct?

Quoted 10 lines

+++ a/fs/nilfs2/the_nilfs.c

fs/nilfs2/the_nilfs.c renamed from fs/nilfs2/the_nilfs.c~nilfs2-use-refcount_dec_and_lock-to-fix-potential-uaf +1 -3
@@ -792,14 +792,13 @@ nilfs_find_or_create_root(struct the_nil
 
 void nilfs_put_root(struct nilfs_root *root)
 {
-	if (refcount_dec_and_test(&root->count)) {
-		struct the_nilfs *nilfs = root->nilfs;
+	struct the_nilfs *nilfs = root->nilfs;
 
-		nilfs_sysfs_delete_snapshot_group(root);

fs/nilfs2/the_nilfs.c nilfs_find_or_create_root(struct the_nil · line 804

Quoted 10 lines
fs/nilfs2/the_nilfs.c renamed from fs/nilfs2/the_nilfs.c~nilfs2-use-refcount_dec_and_lock-to-fix-potential-uaf +3 -2
-
-		spin_lock(&nilfs->ns_cptree_lock);
+	if (refcount_dec_and_lock(&root->count, &nilfs->ns_cptree_lock)) {
 		rb_erase(&root->rb_node, &nilfs->ns_cptree);
 		spin_unlock(&nilfs->ns_cptree_lock);
+
+		nilfs_sysfs_delete_snapshot_group(root);
 		iput(root->ifile);
 
 		kfree(root);

spin_lock() is deleted, but spin_unlock() is not affected. This means unbalanced locking, right?

Best regards,
Pavel
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

maintainer
#171 lore raw

Re: [patch 136/147] nilfs2: use refcount_dec_and_lock() to fix potential UAF

Hi,

Quoted 51 lines · Pavel Machek

Hi!

Quoted 20 lines

From: Zhen Lei <[email protected]>
Subject: nilfs2: use refcount_dec_and_lock() to fix potential UAF

When the refcount is decreased to 0, the resource reclamation branch is entered. Before CPU0 reaches the race point (1), CPU1 may obtain the spinlock and traverse the rbtree to find 'root', see nilfs_lookup_root(). Although CPU1 will call refcount_inc() to increase the refcount, it is obviously too late. CPU0 will release 'root' directly, CPU1 then accesses 'root' and triggers UAF.

Use refcount_dec_and_lock() to ensure that both the operations of decrease refcount to 0 and link deletion are lock protected eliminates this risk.

CPU0 CPU1
nilfs_put_root():

                          <-------- (1)

spin_lock(&nilfs->ns_cptree_lock);
rb_erase(&root->rb_node, &nilfs->ns_cptree);
spin_unlock(&nilfs->ns_cptree_lock);

Quoted 5 lines
kfree(root);
                          <-------- use-after-free

There is no reproduction program, and the above is only theoretical analysis.

Ok, so we have a theoretical bug, and fix already on its way to stable. But ... is it correct?

Quoted 19 lines

+++ a/fs/nilfs2/the_nilfs.c

fs/nilfs2/the_nilfs.c renamed from fs/nilfs2/the_nilfs.c~nilfs2-use-refcount_dec_and_lock-to-fix-potential-uaf +4 -5
@@ -792,14 +792,13 @@ nilfs_find_or_create_root(struct the_nil
 
 void nilfs_put_root(struct nilfs_root *root)
 {
-     if (refcount_dec_and_test(&root->count)) {
-             struct the_nilfs *nilfs = root->nilfs;
+     struct the_nilfs *nilfs = root->nilfs;
 
-             nilfs_sysfs_delete_snapshot_group(root);
-
-             spin_lock(&nilfs->ns_cptree_lock);
+     if (refcount_dec_and_lock(&root->count, &nilfs->ns_cptree_lock)) {
              rb_erase(&root->rb_node, &nilfs->ns_cptree);
              spin_unlock(&nilfs->ns_cptree_lock);
+
+             nilfs_sysfs_delete_snapshot_group(root);
              iput(root->ifile);
 
Quoted 4 lines

fs/nilfs2/the_nilfs.c nilfs_find_or_create_root(struct the_nil · line 804

Quoted 1 line
fs/nilfs2/the_nilfs.c renamed from fs/nilfs2/the_nilfs.c~nilfs2-use-refcount_dec_and_lock-to-fix-potential-uaf +0 -0
              kfree(root);

spin_lock() is deleted, but spin_unlock() is not affected. This means unbalanced locking, right?

It's okay. spin_lock() is integrated into refcount_dec_and_lock(), which was
originally refcount_dec_and_test().

Thanks,
Ryusuke Konishi

Quoted 7 lines

Best regards,
Pavel
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

maintainer
#172 lore raw

Re: [patch 136/147] nilfs2: use refcount_dec_and_lock() to fix potential UAF

In reply to Andrew Morton
Quoted 15 lines · Andrew Morton

From: Zhen Lei <[email protected]>
Subject: nilfs2: use refcount_dec_and_lock() to fix potential UAF

When the refcount is decreased to 0, the resource reclamation branch is entered. Before CPU0 reaches the race point (1), CPU1 may obtain the spinlock and traverse the rbtree to find 'root', see nilfs_lookup_root(). Although CPU1 will call refcount_inc() to increase the refcount, it is obviously too late. CPU0 will release 'root' directly, CPU1 then accesses 'root' and triggers UAF.

Use refcount_dec_and_lock() to ensure that both the operations of decrease refcount to 0 and link deletion are lock protected eliminates this risk.

CPU0 CPU1
nilfs_put_root():

Quoted 7 lines
			    <-------- (1)

spin_lock(&nilfs->ns_cptree_lock);
rb_erase(&root->rb_node, &nilfs->ns_cptree);
spin_unlock(&nilfs->ns_cptree_lock);

kfree(root);
			    <-------- use-after-free

I don't know where this happened, but the leading whitespace has been eaten at some point, making this description of the race completely unreadable as everything appears to be done by CPU 0.

maintainer
#173 lore raw

Re: [patch 136/147] nilfs2: use refcount_dec_and_lock() to fix potential UAF

Hi,

Quoted 22 lines · Matthew Wilcox
Quoted 20 lines · Andrew Morton

From: Zhen Lei <[email protected]>
Subject: nilfs2: use refcount_dec_and_lock() to fix potential UAF

When the refcount is decreased to 0, the resource reclamation branch is entered. Before CPU0 reaches the race point (1), CPU1 may obtain the spinlock and traverse the rbtree to find 'root', see nilfs_lookup_root(). Although CPU1 will call refcount_inc() to increase the refcount, it is obviously too late. CPU0 will release 'root' directly, CPU1 then accesses 'root' and triggers UAF.

Use refcount_dec_and_lock() to ensure that both the operations of decrease refcount to 0 and link deletion are lock protected eliminates this risk.

CPU0 CPU1
nilfs_put_root():

                          <-------- (1)

spin_lock(&nilfs->ns_cptree_lock);
rb_erase(&root->rb_node, &nilfs->ns_cptree);
spin_unlock(&nilfs->ns_cptree_lock);

Quoted 6 lines
Quoted 2 lines
kfree(root);
                          <-------- use-after-free

I don't know where this happened, but the leading whitespace has been eaten at some point, making this description of the race completely unreadable as everything appears to be done by CPU 0.

The diagram is the same as that in the original patch by author, and I approved it without any discomfort because these five operations (nilfs_put_root() ~ spin_lock(); rb_erase(); spin_unlock() ~ kfree() ) are all done by CPU0.

But, yeah, an example of a function call might have been written on the CPU1 side as well, for instance, a nilfs_lookup_root() call etc, to clarify the race issue the message explains..

Regards,
Ryusuke Konishi

author maintainer
#174 lore raw

PATCH 137/147 fs/coredump.c: log if a core dump is aborted due to changed file permissions

In reply to Andrew Morton

From: David Oberhollenzer <[email protected]>
Subject: fs/coredump.c: log if a core dump is aborted due to changed file permissions

For obvious security reasons, a core dump is aborted if the filesystem cannot preserve ownership or permissions of the dump file.

This affects filesystems like e.g. vfat, but also something like a 9pfs share in a Qemu test setup, running as a regular user, depending on the security model used. In those cases, the result is an empty core file and a confused user.

To hopefully safe other people a lot of time figuring out the cause, this patch adds a simple log message for those specific cases.

---

 fs/coredump.c |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
fs/coredump.c renamed from fs/coredump.c~log-if-a-core-dump-is-aborted-due-to-changed-file-permissions +9 -2
@@ -782,10 +782,17 @@ void do_coredump(const kernel_siginfo_t
 		 * filesystem.
 		 */
 		mnt_userns = file_mnt_user_ns(cprm.file);
-		if (!uid_eq(i_uid_into_mnt(mnt_userns, inode), current_fsuid()))
+		if (!uid_eq(i_uid_into_mnt(mnt_userns, inode),
+			    current_fsuid())) {
+			pr_info_ratelimited("Core dump to %s aborted: cannot preserve file owner\n",
+					    cn.corename);
 			goto close_fail;
-		if ((inode->i_mode & 0677) != 0600)
+		}
+		if ((inode->i_mode & 0677) != 0600) {
+			pr_info_ratelimited("Core dump to %s aborted: cannot preserve file permissions\n",
+					    cn.corename);
 			goto close_fail;
+		}
 		if (!(cprm.file->f_mode & FMODE_CAN_WRITE))
 			goto close_fail;
 		if (do_truncate(mnt_userns, cprm.file->f_path.dentry,

_

author maintainer
#175 lore raw

PATCH 138/147 coredump: fix memleak in dump_vma_snapshot()

In reply to Andrew Morton

From: QiuXi <[email protected]>
Subject: coredump: fix memleak in dump_vma_snapshot()

dump_vma_snapshot() allocs memory for *vma_meta, when dump_vma_snapshot() returns -EFAULT, the memory will be leaked, so we free it correctly.

Fixes a07279c9a8cd7 ("binfmt_elf, binfmt_elf_fdpic: use a VMA list snapshot")
Cc Al Viro <[email protected]>
Cc Jann Horn <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>

---

 fs/coredump.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/coredump.c renamed from fs/coredump.c~coredump-fix-memleak-in-dump_vma_snapshot +3 -1
@@ -1134,8 +1134,10 @@ int dump_vma_snapshot(struct coredump_pa
 
 	mmap_write_unlock(mm);
 
-	if (WARN_ON(i != *vma_count))
+	if (WARN_ON(i != *vma_count)) {
+		kvfree(*vma_meta);
 		return -EFAULT;
+	}
 
 	*vma_data_size_ptr = vma_data_size;
 	return 0;

_

author maintainer
#176 lore raw

PATCH 139/147 kernel/fork.c: unexport get_{mm,task}_exe_file

In reply to Andrew Morton

From: Christoph Hellwig <[email protected]>
Subject: kernel/fork.c: unexport get_{mm,task}_exe_file

Only used by core code and the tomoyo which can't be a module either.

---

 kernel/fork.c |    2 --
 1 file changed, 2 deletions(-)
kernel/fork.c renamed from kernel/fork.c~kernel-unexport-get_mmtask_exe_file +0 -2
@@ -1187,7 +1187,6 @@ struct file *get_mm_exe_file(struct mm_s
 	rcu_read_unlock();
 	return exe_file;
 }
-EXPORT_SYMBOL(get_mm_exe_file);
 
 /**
  * get_task_exe_file - acquire a reference to the task's executable file
@@ -1210,7 +1209,6 @@ struct file *get_task_exe_file(struct ta
 	task_unlock(task);
 	return exe_file;
 }
-EXPORT_SYMBOL(get_task_exe_file);
 
 /**
  * get_task_mm - acquire a reference to the task's mm

_

author maintainer
#177 lore raw

PATCH 140/147 pid: cleanup the stale comment mentioning pidmap_init().

In reply to Andrew Morton

From: Takahiro Itazuri <[email protected]>
Subject: pid: cleanup the stale comment mentioning pidmap_init().

pidmap_init() has already been replaced with pid_idr_init() in the commit 95846ecf9dac ("pid: replace pid bitmap implementation with IDR API"). Cleanup the stale comment which still mentions it.

---

 include/linux/threads.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/threads.h renamed from include/linux/threads.h~pid-cleanup-the-stale-comment-mentioning-pidmap_init +1 -1
@@ -38,7 +38,7 @@
  * Define a minimum number of pids per cpu.  Heuristically based
  * on original pid max of 32k for 32 cpus.  Also, increase the
  * minimum settable value for pid_max on the running system based
- * on similar defaults.  See kernel/pid.c:pidmap_init() for details.
+ * on similar defaults.  See kernel/pid.c:pid_idr_init() for details.
  */
 #define PIDS_PER_CPU_DEFAULT	1024
 #define PIDS_PER_CPU_MIN	8

_

author maintainer
#178 lore raw

PATCH 141/147 prctl: allow to setup brk for et_dyn executables

In reply to Andrew Morton

From: Cyrill Gorcunov <[email protected]>
Subject: prctl: allow to setup brk for et_dyn executables

Keno Fischer reported that when a binray loaded via ld-linux-x the prctl(PR_SET_MM_MAP) doesn't allow to setup brk value because it lays before mm:end_data.

For example a test program shows

 | # ~/t
 |
 | start_code      401000
 | end_code        401a15
 | start_stack     7ffce4577dd0
 | start_data	   403e10
 | end_data        40408c
 | start_brk	   b5b000
 | sbrk(0)         b5b000

and when executed via ld-linux

 | # /lib64/ld-linux-x86-64.so.2 ~/t
 |
 | start_code      7fc25b0a4000
 | end_code        7fc25b0c4524
 | start_stack     7fffcc6b2400
 | start_data	   7fc25b0ce4c0
 | end_data        7fc25b0cff98
 | start_brk	   55555710c000
 | sbrk(0)         55555710c000

This of course prevent criu from restoring such programs. Looking into how kernel operates with brk/start_brk inside brk() syscall I don't see any problem if we allow to setup brk/start_brk without checking for end_data. Even if someone pass some weird address here on a purpose then the worst possible result will be an unexpected unmapping of existing vma (own vma, since prctl works with the callers memory) but test for RLIMIT_DATA is still valid and a user won't be able to gain more memory in case of expanding VMAs via new values shipped with prctl call.

Fixes bbdc6076d2e5 ("binfmt_elf: move brk out of mmap when doing direct loader exec")
Cc Dmitry Safonov <[email protected]>
Cc Kirill Tkhai <[email protected]>
Cc Eric W. Biederman <[email protected]>
Cc Pavel Tikhomirov <[email protected]>
Cc Alexander Mikhalitsyn <[email protected]>

---

 kernel/sys.c |    7 -------
 1 file changed, 7 deletions(-)
kernel/sys.c renamed from kernel/sys.c~prctl-allow-to-setup-brk-for-et_dyn-executables +0 -7
@@ -1960,13 +1960,6 @@ static int validate_prctl_map_addr(struc
 	error = -EINVAL;
 
 	/*
-	 * @brk should be after @end_data in traditional maps.
-	 */
-	if (prctl_map->start_brk <= prctl_map->end_data ||
-	    prctl_map->brk <= prctl_map->end_data)
-		goto out;
-
-	/*
 	 * Neither we should allow to override limits if they set.
 	 */
 	if (check_data_rlimit(rlimit(RLIMIT_DATA), prctl_map->brk,

_

author maintainer
#179 lore raw

PATCH 142/147 configs: remove the obsolete CONFIG_INPUT_POLLDEV

In reply to Andrew Morton

From: Zenghui Yu <[email protected]>
Subject: configs: remove the obsolete CONFIG_INPUT_POLLDEV

This CONFIG option was removed in commit 278b13ce3a89 ("Input: remove input_polled_dev implementation") so there's no point to keep it in defconfigs any longer.

Get rid of the leftover for all arches.

---

 arch/arm/configs/dove_defconfig             |    1 -
 arch/arm/configs/pxa_defconfig              |    1 -
 arch/mips/configs/lemote2f_defconfig        |    1 -
 arch/mips/configs/pic32mzda_defconfig       |    1 -
 arch/mips/configs/rt305x_defconfig          |    1 -
 arch/mips/configs/xway_defconfig            |    1 -
 arch/parisc/configs/generic-32bit_defconfig |    1 -
 arch/x86/configs/i386_defconfig             |    1 -
 arch/x86/configs/x86_64_defconfig           |    1 -
 9 files changed, 9 deletions(-)
arch/arm/configs/dove_defconfig renamed from arch/arm/configs/dove_defconfig~configs-remove-the-obsolete-config_input_polldev +0 -1
@@ -56,7 +56,6 @@ CONFIG_ATA=y
 CONFIG_SATA_MV=y
 CONFIG_NETDEVICES=y
 CONFIG_MV643XX_ETH=y
-CONFIG_INPUT_POLLDEV=y
 # CONFIG_INPUT_MOUSEDEV is not set
 CONFIG_INPUT_EVDEV=y
 # CONFIG_KEYBOARD_ATKBD is not set
arch/arm/configs/pxa_defconfig renamed from arch/arm/configs/pxa_defconfig~configs-remove-the-obsolete-config_input_polldev +0 -1
@@ -284,7 +284,6 @@ CONFIG_RT2800USB=m
 CONFIG_MWIFIEX=m
 CONFIG_MWIFIEX_SDIO=m
 CONFIG_INPUT_FF_MEMLESS=m
-CONFIG_INPUT_POLLDEV=y
 CONFIG_INPUT_MATRIXKMAP=y
 CONFIG_INPUT_MOUSEDEV=m
 CONFIG_INPUT_MOUSEDEV_SCREEN_X=640
arch/mips/configs/lemote2f_defconfig renamed from arch/mips/configs/lemote2f_defconfig~configs-remove-the-obsolete-config_input_polldev +0 -1
@@ -116,7 +116,6 @@ CONFIG_8139TOO=y
 CONFIG_R8169=y
 CONFIG_USB_USBNET=m
 CONFIG_USB_NET_CDC_EEM=m
-CONFIG_INPUT_POLLDEV=m
 CONFIG_INPUT_EVDEV=y
 # CONFIG_MOUSE_PS2_ALPS is not set
 # CONFIG_MOUSE_PS2_LOGIPS2PP is not set
arch/mips/configs/pic32mzda_defconfig renamed from arch/mips/configs/pic32mzda_defconfig~configs-remove-the-obsolete-config_input_polldev +0 -1
@@ -34,7 +34,6 @@ CONFIG_SCSI_CONSTANTS=y
 CONFIG_SCSI_SCAN_ASYNC=y
 # CONFIG_SCSI_LOWLEVEL is not set
 CONFIG_INPUT_LEDS=m
-CONFIG_INPUT_POLLDEV=y
 CONFIG_INPUT_MOUSEDEV=m
 CONFIG_INPUT_EVDEV=y
 CONFIG_INPUT_EVBUG=m
arch/mips/configs/rt305x_defconfig renamed from arch/mips/configs/rt305x_defconfig~configs-remove-the-obsolete-config_input_polldev +0 -1
@@ -90,7 +90,6 @@ CONFIG_PPPOE=m
 CONFIG_PPP_ASYNC=m
 CONFIG_ISDN=y
 CONFIG_INPUT=m
-CONFIG_INPUT_POLLDEV=m
 # CONFIG_KEYBOARD_ATKBD is not set
 # CONFIG_INPUT_MOUSE is not set
 CONFIG_INPUT_MISC=y
arch/mips/configs/xway_defconfig renamed from arch/mips/configs/xway_defconfig~configs-remove-the-obsolete-config_input_polldev +0 -1
@@ -96,7 +96,6 @@ CONFIG_PPPOE=m
 CONFIG_PPP_ASYNC=m
 CONFIG_ISDN=y
 CONFIG_INPUT=m
-CONFIG_INPUT_POLLDEV=m
 # CONFIG_KEYBOARD_ATKBD is not set
 # CONFIG_INPUT_MOUSE is not set
 CONFIG_INPUT_MISC=y
arch/parisc/configs/generic-32bit_defconfig renamed from arch/parisc/configs/generic-32bit_defconfig~configs-remove-the-obsolete-config_input_polldev +0 -1
@@ -111,7 +111,6 @@ CONFIG_PPP_BSDCOMP=m
 CONFIG_PPP_DEFLATE=m
 CONFIG_PPPOE=m
 # CONFIG_WLAN is not set
-CONFIG_INPUT_POLLDEV=y
 CONFIG_KEYBOARD_HIL_OLD=m
 CONFIG_KEYBOARD_HIL=m
 CONFIG_MOUSE_SERIAL=y
arch/x86/configs/i386_defconfig renamed from arch/x86/configs/i386_defconfig~configs-remove-the-obsolete-config_input_polldev +0 -1
@@ -156,7 +156,6 @@ CONFIG_FORCEDETH=y
 CONFIG_8139TOO=y
 # CONFIG_8139TOO_PIO is not set
 CONFIG_R8169=y
-CONFIG_INPUT_POLLDEV=y
 CONFIG_INPUT_EVDEV=y
 CONFIG_INPUT_JOYSTICK=y
 CONFIG_INPUT_TABLET=y
arch/x86/configs/x86_64_defconfig renamed from arch/x86/configs/x86_64_defconfig~configs-remove-the-obsolete-config_input_polldev +0 -1
@@ -148,7 +148,6 @@ CONFIG_SKY2=y
 CONFIG_FORCEDETH=y
 CONFIG_8139TOO=y
 CONFIG_R8169=y
-CONFIG_INPUT_POLLDEV=y
 CONFIG_INPUT_EVDEV=y
 CONFIG_INPUT_JOYSTICK=y
 CONFIG_INPUT_TABLET=y

_

author maintainer
#180 lore raw

PATCH 143/147 Kconfig.debug: drop selecting non-existing HARDLOCKUP_DETECTOR_ARCH

In reply to Andrew Morton

From: Lukas Bulwahn <[email protected]>
Subject: Kconfig.debug: drop selecting non-existing HARDLOCKUP_DETECTOR_ARCH

Commit 05a4a9527931 ("kernel/watchdog: split up config options") adds a new config HARDLOCKUP_DETECTOR, which selects the non-existing config HARDLOCKUP_DETECTOR_ARCH.

Hence, ./scripts/checkkconfigsymbols.py warns:

HARDLOCKUP_DETECTOR_ARCH Referencing files: lib/Kconfig.debug

Simply drop selecting the non-existing HARDLOCKUP_DETECTOR_ARCH.

Fixes 05a4a9527931 ("kernel/watchdog: split up config options")
Cc Nicholas Piggin <[email protected]>
Cc Masahiro Yamada <[email protected]>
Cc Babu Moger <[email protected]>
Cc Don Zickus <[email protected]>
Cc Randy Dunlap <[email protected]>

---

 lib/Kconfig.debug |    1 -
 1 file changed, 1 deletion(-)
lib/Kconfig.debug renamed from lib/Kconfig.debug~kconfigdebug-drop-selecting-non-existing-hardlockup_detector_arch +0 -1
@@ -1062,7 +1062,6 @@ config HARDLOCKUP_DETECTOR
 	depends on HAVE_HARDLOCKUP_DETECTOR_PERF || HAVE_HARDLOCKUP_DETECTOR_ARCH
 	select LOCKUP_DETECTOR
 	select HARDLOCKUP_DETECTOR_PERF if HAVE_HARDLOCKUP_DETECTOR_PERF
-	select HARDLOCKUP_DETECTOR_ARCH if HAVE_HARDLOCKUP_DETECTOR_ARCH
 	help
 	  Say Y here to enable the kernel to act as a watchdog to detect
 	  hard lockups.

_

author maintainer
#181 lore raw

PATCH 144/147 selftests/memfd: remove unused variable

In reply to Andrew Morton

From: Greg Thelen <[email protected]>
Subject: selftests/memfd: remove unused variable

Commit 544029862cbb ("selftests/memfd: add tests for F_SEAL_FUTURE_WRITE seal") added an unused variable to mfd_assert_reopen_fd().

Delete the unused variable.

Fixes 544029862cbb ("selftests/memfd: add tests for F_SEAL_FUTURE_WRITE seal")
Cc Shuah Khan <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc "Joel Fernandes (Google)" <[email protected]>

---

 tools/testing/selftests/memfd/memfd_test.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/memfd/memfd_test.c renamed from tools/testing/selftests/memfd/memfd_test.c~selftests-memfd-remove-unused-variable +1 -1
@@ -56,7 +56,7 @@ static int mfd_assert_new(const char *na
 
 static int mfd_assert_reopen_fd(int fd_in)
 {
-	int r, fd;
+	int fd;
 	char path[100];
 
 	sprintf(path, "/proc/self/fd/%d", fd_in);

_

author maintainer
#182 lore raw

PATCH 145/147 ipc: replace costly bailout check in sysvipc_find_ipc()

In reply to Andrew Morton

From: Rafael Aquini <[email protected]>
Subject: ipc: replace costly bailout check in sysvipc_find_ipc()

sysvipc_find_ipc() was left with a costly way to check if the offset position fed to it is bigger than the total number of IPC IDs in use. So much so that the time it takes to iterate over /proc/sysvipc/* files grows exponentially for a custom benchmark that creates "N" SYSV shm segments and then times the read of /proc/sysvipc/shm (milliseconds):

    12 msecs to read   1024 segs from /proc/sysvipc/shm
    18 msecs to read   2048 segs from /proc/sysvipc/shm
    65 msecs to read   4096 segs from /proc/sysvipc/shm
   325 msecs to read   8192 segs from /proc/sysvipc/shm

1303 msecs to read 16384 segs from /proc/sysvipc/shm 5182 msecs to read 32768 segs from /proc/sysvipc/shm

The root problem lies with the loop that computes the total amount of ids in use to check if the "pos" feeded to sysvipc_find_ipc() grew bigger than "ids->in_use". That is a quite inneficient way to get to the maximum index in the id lookup table, specially when that value is already provided by struct ipc_ids.max_idx.

This patch follows up on the optimization introduced via commit 15df03c879836 ("sysvipc: make get_maxid O(1) again") and gets rid of the aforementioned costly loop replacing it by a simpler checkpoint based on ipc_get_maxidx() returned value, which allows for a smooth linear increase in time complexity for the same custom benchmark:

     2 msecs to read   1024 segs from /proc/sysvipc/shm
     2 msecs to read   2048 segs from /proc/sysvipc/shm
     4 msecs to read   4096 segs from /proc/sysvipc/shm
     9 msecs to read   8192 segs from /proc/sysvipc/shm

19 msecs to read 16384 segs from /proc/sysvipc/shm 39 msecs to read 32768 segs from /proc/sysvipc/shm

---

 ipc/util.c |   16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
ipc/util.c renamed from ipc/util.c~ipc-replace-costly-bailout-check-in-sysvipc_find_ipc +4 -12
@@ -788,21 +788,13 @@ struct pid_namespace *ipc_seq_pid_ns(str
 static struct kern_ipc_perm *sysvipc_find_ipc(struct ipc_ids *ids, loff_t pos,
 					      loff_t *new_pos)
 {
-	struct kern_ipc_perm *ipc;
-	int total, id;
+	struct kern_ipc_perm *ipc = NULL;
+	int max_idx = ipc_get_maxidx(ids);
 
-	total = 0;
-	for (id = 0; id < pos && total < ids->in_use; id++) {
-		ipc = idr_find(&ids->ipcs_idr, id);
-		if (ipc != NULL)
-			total++;
-	}
-
-	ipc = NULL;
-	if (total >= ids->in_use)
+	if (max_idx == -1 || pos > max_idx)
 		goto out;
 
-	for (; pos < ipc_mni; pos++) {
+	for (; pos <= max_idx; pos++) {
 		ipc = idr_find(&ids->ipcs_idr, pos);
 		if (ipc != NULL) {
 			rcu_read_lock();

_

author maintainer
#183 lore raw

PATCH 146/147 mm/workingset: correct kernel-doc notations

In reply to Andrew Morton

From: Randy Dunlap <[email protected]>
Subject: mm/workingset: correct kernel-doc notations

Use the documented kernel-doc format to prevent kernel-doc warnings.

mm/workingset.c:256: warning: No description found for return value of 'workingset_eviction' mm/workingset.c:285: warning: Function parameter or member 'folio' not described in 'workingset_refault' mm/workingset.c:285: warning: Excess function parameter 'page' description in 'workingset_refault'

---

 mm/workingset.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/workingset.c renamed from mm/workingset.c~mm-workingset-correct-kernel-doc-notations +1 -1
@@ -249,7 +249,7 @@ void workingset_age_nonresident(struct l
  * @target_memcg: the cgroup that is causing the reclaim
  * @page: the page being evicted
  *
- * Returns a shadow entry to be stored in @page->mapping->i_pages in place
+ * Return: a shadow entry to be stored in @page->mapping->i_pages in place
  * of the evicted @page so that a later refault can be detected.
  */
 void *workingset_eviction(struct page *page, struct mem_cgroup *target_memcg)

_

author maintainer
#184 lore raw

PATCH 147/147 scripts: check_extable: fix typo in user error message

In reply to Andrew Morton

From: Randy Dunlap <[email protected]>
Subject: scripts: check_extable: fix typo in user error message

Fix typo ("and" should be "an") in an error message.

---

 scripts/check_extable.sh |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/check_extable.sh renamed from scripts/check_extable.sh~scripts-check_extable-fix-typo-in-user-error-message +1 -1
@@ -4,7 +4,7 @@
 
 obj=$1
 
-file ${obj} | grep -q ELF || (echo "${obj} is not and ELF file." 1>&2 ; exit 0)
+file ${obj} | grep -q ELF || (echo "${obj} is not an ELF file." 1>&2 ; exit 0)
 
 # Bail out early if there isn't an __ex_table section in this object file.
 objdump -hj __ex_table ${obj} 2> /dev/null > /dev/null

_

#185 lore raw
In reply to Andrew Morton
Quoted 36 lines · Andrew Morton

Subsystem: mm/slub

Vlastimil Babka <[email protected]>:
Patch series "SLUB: reduce irq disabled scope and make it RT compatible", v6:
mm, slub: don't call flush_all() from slab_debug_trace_open()
mm, slub: allocate private object map for debugfs listings
mm, slub: allocate private object map for validate_slab_cache()
mm, slub: don't disable irq for debug_check_no_locks_freed()
mm, slub: remove redundant unfreeze_partials() from put_cpu_partial() mm, slub: extract get_partial() from new_slab_objects()
mm, slub: dissolve new_slab_objects() into ___slab_alloc()
mm, slub: return slab page from get_partial() and set c->page afterwards mm, slub: restructure new page checks in ___slab_alloc()
mm, slub: simplify kmem_cache_cpu and tid setup
mm, slub: move disabling/enabling irqs to ___slab_alloc()
mm, slub: do initial checks in ___slab_alloc() with irqs enabled
mm, slub: move disabling irqs closer to get_partial() in ___slab_alloc() mm, slub: restore irqs around calling new_slab()
mm, slub: validate slab from partial list or page allocator before making it cpu slab mm, slub: check new pages with restored irqs
mm, slub: stop disabling irqs around get_partial()
mm, slub: move reset of c->page and freelist out of deactivate_slab() mm, slub: make locking in deactivate_slab() irq-safe
mm, slub: call deactivate_slab() without disabling irqs
mm, slub: move irq control into unfreeze_partials()
mm, slub: discard slabs in unfreeze_partials() without irqs disabled mm, slub: detach whole partial list at once in unfreeze_partials()
mm, slub: separate detaching of partial list in unfreeze_partials() from unfreezing mm, slub: only disable irq with spin_lock in __unfreeze_partials()
mm, slub: don't disable irqs in slub_cpu_dead()
mm, slab: split out the cpu offline variant of flush_slab()

Sebastian Andrzej Siewior <[email protected]>:
mm: slub: move flush_cpu_slab() invocations __free_slab() invocations out of IRQ context
mm: slub: make object_map_lock a raw_spinlock_t

Quoted 5 lines

Vlastimil Babka <[email protected]>:
mm, slub: make slab_lock() disable irqs with PREEMPT_RT
mm, slub: protect put_cpu_partial() with disabled irqs instead of cmpxchg mm, slub: use migrate_disable() on PREEMPT_RT
mm, slub: convert kmem_cpu_slab protection to local_lock

For my own piece of mind, I've checked that this part (patches 1 to 33) are identical to the v6 posting [1] and git version [2] that Mel and Mike tested (replies to [1]).

[1] https://lore.kernel.org/all/[email protected]/
[2] git://git.kernel.org/pub/scm/linux/kernel/git/vbabka/linux.git
tags/mm-slub-5.15-rc1