Skip to contentSkip to conversation

powerpc/book3s64/radix: make tlb_single_page_flush_ceiling a debugfs entry

PATCH Superseded Aneesh Kumar K.V 3 participants 5 messages Aug 10, 2021 – Aug 12, 2021 PowerPC

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/book3s64/radix: make tlb_single_page_flush_ceiling a debugfs entry

Similar to x86/s390 add a debugfs file to tune tlb_single_page_flush_ceiling.

---
 arch/powerpc/mm/book3s64/radix_tlb.c | 48 ++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
arch/powerpc/mm/book3s64/radix_tlb.c +48 -0
index aefc100d79a7..5cca0fe130e7 100644
@@ -17,6 +17,7 @@
 #include <asm/trace.h>
 #include <asm/cputhreads.h>
 #include <asm/plpar_wrappers.h>
+#include <asm/debugfs.h>
 
 #include "internal.h"
 
@@ -1524,3 +1525,50 @@ void do_h_rpt_invalidate_prt(unsigned long pid, unsigned long lpid,
 EXPORT_SYMBOL_GPL(do_h_rpt_invalidate_prt);
 
 #endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */
+
+static ssize_t tlbflush_read_file(struct file *file, char __user *user_buf,
+			     size_t count, loff_t *ppos)
+{
+	char buf[32];
+	unsigned int len;
+
+	len = sprintf(buf, "%ld\n", tlb_single_page_flush_ceiling);
+	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
+}
+
+static ssize_t tlbflush_write_file(struct file *file,
+		 const char __user *user_buf, size_t count, loff_t *ppos)
+{
+	char buf[32];
+	ssize_t len;
+	int ceiling;
+
+	len = min(count, sizeof(buf) - 1);
+	if (copy_from_user(buf, user_buf, len))
+		return -EFAULT;
+
+	buf[len] = '\0';
+	if (kstrtoint(buf, 0, &ceiling))
+		return -EINVAL;
+
+	if (ceiling < 0)
+		return -EINVAL;
+
+	tlb_single_page_flush_ceiling = ceiling;
+	return count;
+}
+
+static const struct file_operations fops_tlbflush = {
+	.read = tlbflush_read_file,
+	.write = tlbflush_write_file,
+	.llseek = default_llseek,
+};
+
+static int __init create_tlb_single_page_flush_ceiling(void)
+{
+	debugfs_create_file("tlb_single_page_flush_ceiling", S_IRUSR | S_IWUSR,
+			    powerpc_debugfs_root, NULL, &fops_tlbflush);
+	return 0;
+}
+late_initcall(create_tlb_single_page_flush_ceiling);
+
Signature · 1 line
2.31.1
#1 lore raw

Le 10/08/2021 à 06:53, Aneesh Kumar K.V a écrit :

Quoted 56 lines

Similar to x86/s390 add a debugfs file to tune tlb_single_page_flush_ceiling.

---
  arch/powerpc/mm/book3s64/radix_tlb.c | 48 ++++++++++++++++++++++++++++
  1 file changed, 48 insertions(+)
arch/powerpc/mm/book3s64/radix_tlb.c +34 -0
index aefc100d79a7..5cca0fe130e7 100644
@@ -17,6 +17,7 @@
  #include <asm/trace.h>
  #include <asm/cputhreads.h>
  #include <asm/plpar_wrappers.h>
+#include <asm/debugfs.h>
 
  #include "internal.h"
 
@@ -1524,3 +1525,50 @@ void do_h_rpt_invalidate_prt(unsigned long pid, unsigned long lpid,
  EXPORT_SYMBOL_GPL(do_h_rpt_invalidate_prt);
 
  #endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */
+
+static ssize_t tlbflush_read_file(struct file *file, char __user *user_buf,
+			     size_t count, loff_t *ppos)
+{
+	char buf[32];
+	unsigned int len;
+
+	len = sprintf(buf, "%ld\n", tlb_single_page_flush_ceiling);
+	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
+}
+
+static ssize_t tlbflush_write_file(struct file *file,
+		 const char __user *user_buf, size_t count, loff_t *ppos)
+{
+	char buf[32];
+	ssize_t len;
+	int ceiling;
+
+	len = min(count, sizeof(buf) - 1);
+	if (copy_from_user(buf, user_buf, len))
+		return -EFAULT;
+
+	buf[len] = '\0';
+	if (kstrtoint(buf, 0, &ceiling))
+		return -EINVAL;
+
+	if (ceiling < 0)
+		return -EINVAL;
+
+	tlb_single_page_flush_ceiling = ceiling;
+	return count;
+}
+

arch/powerpc/mm/book3s64/radix_tlb.c void do_h_rpt_invalidate_prt(unsigned long pid, unsigned long lpid, · line 1570

Quoted 10 lines
arch/powerpc/mm/book3s64/radix_tlb.c +10 -0
+static const struct file_operations fops_tlbflush = {
+	.read = tlbflush_read_file,
+	.write = tlbflush_write_file,
+	.llseek = default_llseek,
+};
+
+static int __init create_tlb_single_page_flush_ceiling(void)
+{
+	debugfs_create_file("tlb_single_page_flush_ceiling", S_IRUSR | S_IWUSR,
+			    powerpc_debugfs_root, NULL, &fops_tlbflush);

Could you just use debugfs_create_u32() instead of re-implementing simple read and write ?

Or at least use DEFINE_DEBUGFS_ATTRIBUTE() if you need something a bit more elaborated ?

Quoted 5 lines
arch/powerpc/mm/book3s64/radix_tlb.c +4 -0
+	return 0;
+}
+late_initcall(create_tlb_single_page_flush_ceiling);
+
#2 lore raw
Quoted 13 lines · Christophe Leroy

Le 10/08/2021 à 06:53, Aneesh Kumar K.V a écrit :

Quoted 12 lines

Similar to x86/s390 add a debugfs file to tune tlb_single_page_flush_ceiling.

---
  arch/powerpc/mm/book3s64/radix_tlb.c | 48 ++++++++++++++++++++++++++++
  1 file changed, 48 insertions(+)
arch/powerpc/mm/book3s64/radix_tlb.c +0 -0
index aefc100d79a7..5cca0fe130e7 100644
@@ -17,6 +17,7 @@

...

Quoted 7 lines

arch/powerpc/mm/book3s64/radix_tlb.c void do_h_rpt_invalidate_prt(unsigned long pid, unsigned long lpid, · line 1570

Quoted 5 lines
arch/powerpc/mm/book3s64/radix_tlb.c +5 -0
+
+static int __init create_tlb_single_page_flush_ceiling(void)
+{
+	debugfs_create_file("tlb_single_page_flush_ceiling", S_IRUSR | S_IWUSR,
+			    powerpc_debugfs_root, NULL, &fops_tlbflush);

Could you just use debugfs_create_u32() instead of re-implementing simple read and write ?

Yeah AFAICS that should work fine.

It could probably even be a u16?

cheers

#3 lore raw
Quoted 23 lines · Michael Ellerman
Quoted 13 lines · Christophe Leroy

Le 10/08/2021 à 06:53, Aneesh Kumar K.V a écrit :

Quoted 12 lines

Similar to x86/s390 add a debugfs file to tune tlb_single_page_flush_ceiling.

---
   arch/powerpc/mm/book3s64/radix_tlb.c | 48 ++++++++++++++++++++++++++++
   1 file changed, 48 insertions(+)
arch/powerpc/mm/book3s64/radix_tlb.c +0 -0
index aefc100d79a7..5cca0fe130e7 100644
@@ -17,6 +17,7 @@

...

Quoted 7 lines

arch/powerpc/mm/book3s64/radix_tlb.c void do_h_rpt_invalidate_prt(unsigned long pid, unsigned long lpid, · line 1570

Quoted 5 lines
arch/powerpc/mm/book3s64/radix_tlb.c +5 -0
+
+static int __init create_tlb_single_page_flush_ceiling(void)
+{
+	debugfs_create_file("tlb_single_page_flush_ceiling", S_IRUSR | S_IWUSR,
+			    powerpc_debugfs_root, NULL, &fops_tlbflush);

Could you just use debugfs_create_u32() instead of re-implementing simple read and write ?

Quoted 4 lines

Yeah AFAICS that should work fine.

It could probably even be a u16?

I was looking at switching all that to u64. Should i fallback to u16, considering a tlb_signle_page_flush_ceiling value larger that 2**16 doesn't make sense?

-aneesh

#4 lore raw
Quoted 24 lines · Aneesh Kumar K.V
Quoted 23 lines · Michael Ellerman
Quoted 13 lines · Christophe Leroy

Le 10/08/2021 à 06:53, Aneesh Kumar K.V a écrit :

Quoted 12 lines

Similar to x86/s390 add a debugfs file to tune tlb_single_page_flush_ceiling.

---
   arch/powerpc/mm/book3s64/radix_tlb.c | 48 ++++++++++++++++++++++++++++
   1 file changed, 48 insertions(+)
arch/powerpc/mm/book3s64/radix_tlb.c +0 -0
index aefc100d79a7..5cca0fe130e7 100644
@@ -17,6 +17,7 @@

...

Quoted 7 lines

arch/powerpc/mm/book3s64/radix_tlb.c void do_h_rpt_invalidate_prt(unsigned long pid, unsigned long lpid, · line 1570

Quoted 5 lines
arch/powerpc/mm/book3s64/radix_tlb.c +5 -0
+
+static int __init create_tlb_single_page_flush_ceiling(void)
+{
+	debugfs_create_file("tlb_single_page_flush_ceiling", S_IRUSR | S_IWUSR,
+			    powerpc_debugfs_root, NULL, &fops_tlbflush);

Could you just use debugfs_create_u32() instead of re-implementing simple read and write ?

Quoted 7 lines
Quoted 3 lines

Yeah AFAICS that should work fine.

It could probably even be a u16?

I was looking at switching all that to u64. Should i fallback to u16, considering a tlb_signle_page_flush_ceiling value larger that 2**16 doesn't make sense?

Hmm, if we make it u16 and someone writes a value >= 2^16 it just truncates the value to 0, which is a bit unfortunate.

So maybe just make it u32, that way if someone writes a stupidly large value it stays large.

cheers