Skip to contentSkip to conversation

Add room for insn-enconding and symbol name

PATCH In review Sergio González Collado 3 participants 5 messages Apr 14, 2024 – May 14, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add room for insn-enconding and symbol name

The longest length of a symbol (KSYM_NAME_LEN) was increased to 512 in the reference [1]. This patch adds room for insn-encoding and a symbol name, as proposed in [2]

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

---
 arch/x86/tools/insn_decoder_test.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/tools/insn_decoder_test.c +2 -1
index 472540aeabc2..add51bfc2260 100644
@@ -10,6 +10,7 @@
 #include <assert.h>
 #include <unistd.h>
 #include <stdarg.h>
+#include <linux/kallsym.h>
 
 #define unlikely(cond) (cond)
 
@@ -106,7 +107,7 @@ static void parse_args(int argc, char **argv)
 	}
 }
 
-#define BUFSIZE 256
+#define BUFSIZE (256 + KSYM_NAME_LEN)
 
 int main(int argc, char **argv)
 {
Signature · 1 line
2.39.2
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Sergio González Collado

The longest length of a symbol (KSYM_NAME_LEN) was increased to 512 in the reference [1]. This patch adds room for insn-encoding and a symbol name, as proposed in [2]

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

Quoted 25 lines
---
  arch/x86/tools/insn_decoder_test.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/tools/insn_decoder_test.c +2 -1
index 472540aeabc2..add51bfc2260 100644
@@ -10,6 +10,7 @@
  #include <assert.h>
  #include <unistd.h>
  #include <stdarg.h>
+#include <linux/kallsym.h>
 
  #define unlikely(cond) (cond)
 
@@ -106,7 +107,7 @@ static void parse_args(int argc, char **argv)
  	}
  }
 
-#define BUFSIZE 256
+#define BUFSIZE (256 + KSYM_NAME_LEN)
 
  int main(int argc, char **argv)
  {
#2 lore raw

Hi,

Quoted 9 lines · Danilo Krummrich
Quoted 8 lines · Sergio González Collado

The longest length of a symbol (KSYM_NAME_LEN) was increased to 512 in the reference [1]. This patch adds room for insn-encoding and a symbol name, as proposed in [2]

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

What's the status on this one? Are there any concerns or can we land this?

- Danilo

Quoted 24 lines
Quoted 21 lines

---
  arch/x86/tools/insn_decoder_test.c | 3 ++-

  1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/tools/insn_decoder_test.c +2 -1
index 472540aeabc2..add51bfc2260 100644
@@ -10,6 +10,7 @@
   #include <assert.h>
   #include <unistd.h>
   #include <stdarg.h>
+#include <linux/kallsym.h>
   #define unlikely(cond) (cond)
@@ -106,7 +107,7 @@ static void parse_args(int argc, char **argv)
       }
   }
-#define BUFSIZE 256
+#define BUFSIZE (256 + KSYM_NAME_LEN)
   int main(int argc, char **argv)
   {
#4 lore raw
In reply to Sergio González Collado

Sergio!

On Sun, Apr 14 2024 at 20:09, Sergio González Collado wrote:

Please read through Documentation/process/maintainers-tip.rst. It explains details about how change logs and patch subjects should be written.

Quoted 3 lines

The longest length of a symbol (KSYM_NAME_LEN) was increased to 512 in the reference [1]. This patch adds room for insn-encoding and a symbol name, as proposed in [2]

This is really not a good explanation. The changelog wants to be self contained and explain the problem to be solved. Having to follow random archive links to get an explanation is just painful. The links can only serve as additional material.

Quoted 13 lines

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

---
 arch/x86/tools/insn_decoder_test.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/tools/insn_decoder_test.c +0 -0
index 472540aeabc2..add51bfc2260 100644

arch/x86/tools/insn_decoder_test.c line 13

Quoted 4 lines
arch/x86/tools/insn_decoder_test.c +1 -0
@@ -10,6 +10,7 @@
 #include <assert.h>
 #include <unistd.h>
 #include <stdarg.h>
+#include <linux/kallsym.h>

Please put a newline between the existing includes and the linux prefixed one.

arch/x86/tools/insn_decoder_test.c static void parse_args(int argc, char **argv) · line 110

Quoted 8 lines
arch/x86/tools/insn_decoder_test.c +1 -1
 #define unlikely(cond) (cond)
 
@@ -106,7 +107,7 @@ static void parse_args(int argc, char **argv)
 	}
 }
 
-#define BUFSIZE 256
+#define BUFSIZE (256 + KSYM_NAME_LEN)

What's the rationale here?

256 + KSYM_NAME_LEN is as arbitrary as defining the buffer size to 4096, i.e. it's a number pulled out of thin air.

If you really want to make this code resilent against future line length changes then the obvious thing to do is:

static char *update_buf(char *buf, ssize_t size)

{
	buf = realloc(buf, size);
        if (!buf) {
        	complain();
        	exit(9);
	}
}

main()

{
	char *buffer = NULL, *sym = NULL, *copy = NULL;
	ssize_t size = 256, oldsize = 0, len;

	for (len = getline(&buffer, &size, stdin); len > 0;
             len = getline(&buffer, &size, stdin) {
        	if (size != oldsize) {
              		update_buf(sym, size);
			update_buf(copy, size);
		}
                buffer[len - 1] = '\0';
                ...
        }
        if (errno)
        	complain(errno);

	free(buffer);
        free(sym);
        free(copy);
        ...

No?

Thanks,

tglx