Skip to contentSkip to conversation

Minor cleanups for UML

PATCH Superseded Benjamin Berg 1 participant 6 messages Sep 13, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Minor cleanups for UML

From: Benjamin Berg <[email protected]>

This removes a set of unused functions and also select HAVE_EFFICIENT_UNALIGNED_ACCESS on x86 to avoid UBSAN spewing warnings by default.

Benjamin Berg (5):
um: Remove unused os_process_pc
um: Remove unused os_process_parent
um: Remove unused os_stop_process
um: Remove unused os_getpgrp function
um: Set HAVE_EFFICIENT_UNALIGNED_ACCESS for x86

 arch/um/include/shared/os.h |  4 --
 arch/um/os-Linux/process.c  | 82 -------------------------------------
 arch/x86/um/Kconfig         |  1 +
 3 files changed, 1 insertion(+), 86 deletions(-)
Signature · 1 line
2.46.0
#1 lore raw

PATCH 1/5 um: Remove unused os_process_pc

From: Benjamin Berg <[email protected]>

The function is not used anywhere in the codebase.

---
 arch/um/include/shared/os.h |  1 -
 arch/um/os-Linux/process.c  | 33 ---------------------------------
 2 files changed, 34 deletions(-)
arch/um/include/shared/os.h +0 -1
index 9a039d6f1f74..c8c1a93c8d2c 100644
@@ -199,7 +199,6 @@ extern int create_mem_file(unsigned long long len);
 extern void report_enomem(void);
 
 /* process.c */
-extern unsigned long os_process_pc(int pid);
 extern int os_process_parent(int pid);
 extern void os_alarm_process(int pid);
 extern void os_stop_process(int pid);
arch/um/os-Linux/process.c +0 -33
index e52dd37ddadc..6b74a8d91e06 100644
@@ -18,44 +18,11 @@
 #include <longjmp.h>
 #include <os.h>
 
-#define ARBITRARY_ADDR -1
 #define FAILURE_PID    -1
 
 #define STAT_PATH_LEN sizeof("/proc/#######/stat\0")
 #define COMM_SCANF "%*[^)])"
 
-unsigned long os_process_pc(int pid)
-{
-	char proc_stat[STAT_PATH_LEN], buf[256];
-	unsigned long pc = ARBITRARY_ADDR;
-	int fd, err;
-
-	sprintf(proc_stat, "/proc/%d/stat", pid);
-	fd = open(proc_stat, O_RDONLY, 0);
-	if (fd < 0) {
-		printk(UM_KERN_ERR "os_process_pc - couldn't open '%s', "
-		       "errno = %d\n", proc_stat, errno);
-		goto out;
-	}
-	CATCH_EINTR(err = read(fd, buf, sizeof(buf)));
-	if (err < 0) {
-		printk(UM_KERN_ERR "os_process_pc - couldn't read '%s', "
-		       "err = %d\n", proc_stat, errno);
-		goto out_close;
-	}
-	os_close_file(fd);
-	pc = ARBITRARY_ADDR;
-	if (sscanf(buf, "%*d " COMM_SCANF " %*c %*d %*d %*d %*d %*d %*d %*d "
-		   "%*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d "
-		   "%*d %*d %*d %*d %*d %lu", &pc) != 1)
-		printk(UM_KERN_ERR "os_process_pc - couldn't find pc in '%s'\n",
-		       buf);
- out_close:
-	close(fd);
- out:
-	return pc;
-}
-
 int os_process_parent(int pid)
 {
 	char stat[STAT_PATH_LEN];
Signature · 1 line
2.46.0
#2 lore raw

PATCH 2/5 um: Remove unused os_process_parent

In reply to Benjamin Berg

From: Benjamin Berg <[email protected]>

The function is not used anywhere.

---
 arch/um/include/shared/os.h |  1 -
 arch/um/os-Linux/process.c  | 39 -------------------------------------
 2 files changed, 40 deletions(-)
arch/um/include/shared/os.h +0 -1
index c8c1a93c8d2c..4bdd4fb5dd80 100644
@@ -199,7 +199,6 @@ extern int create_mem_file(unsigned long long len);
 extern void report_enomem(void);
 
 /* process.c */
-extern int os_process_parent(int pid);
 extern void os_alarm_process(int pid);
 extern void os_stop_process(int pid);
 extern void os_kill_process(int pid, int reap_child);
arch/um/os-Linux/process.c +0 -39
index 6b74a8d91e06..b25c226c5491 100644
@@ -18,45 +18,6 @@
 #include <longjmp.h>
 #include <os.h>
 
-#define FAILURE_PID    -1
-
-#define STAT_PATH_LEN sizeof("/proc/#######/stat\0")
-#define COMM_SCANF "%*[^)])"
-
-int os_process_parent(int pid)
-{
-	char stat[STAT_PATH_LEN];
-	char data[256];
-	int parent = FAILURE_PID, n, fd;
-
-	if (pid == -1)
-		return parent;
-
-	snprintf(stat, sizeof(stat), "/proc/%d/stat", pid);
-	fd = open(stat, O_RDONLY, 0);
-	if (fd < 0) {
-		printk(UM_KERN_ERR "Couldn't open '%s', errno = %d\n", stat,
-		       errno);
-		return parent;
-	}
-
-	CATCH_EINTR(n = read(fd, data, sizeof(data)));
-	close(fd);
-
-	if (n < 0) {
-		printk(UM_KERN_ERR "Couldn't read '%s', errno = %d\n", stat,
-		       errno);
-		return parent;
-	}
-
-	parent = FAILURE_PID;
-	n = sscanf(data, "%*d " COMM_SCANF " %*c %d", &parent);
-	if (n != 1)
-		printk(UM_KERN_ERR "Failed to scan '%s'\n", data);
-
-	return parent;
-}
-
 void os_alarm_process(int pid)
 {
 	kill(pid, SIGALRM);
Signature · 1 line
2.46.0
#3 lore raw

PATCH 3/5 um: Remove unused os_stop_process

In reply to Benjamin Berg

From: Benjamin Berg <[email protected]>

The function is not used anywhere.

---
 arch/um/include/shared/os.h | 1 -
 arch/um/os-Linux/process.c  | 5 -----
 2 files changed, 6 deletions(-)
arch/um/include/shared/os.h +0 -1
index 4bdd4fb5dd80..a94093bfa5e4 100644
@@ -200,7 +200,6 @@ extern void report_enomem(void);
 
 /* process.c */
 extern void os_alarm_process(int pid);
-extern void os_stop_process(int pid);
 extern void os_kill_process(int pid, int reap_child);
 extern void os_kill_ptraced_process(int pid, int reap_child);
 
arch/um/os-Linux/process.c +0 -5
index b25c226c5491..d1f5e6002805 100644
@@ -23,11 +23,6 @@ void os_alarm_process(int pid)
 	kill(pid, SIGALRM);
 }
 
-void os_stop_process(int pid)
-{
-	kill(pid, SIGSTOP);
-}
-
 void os_kill_process(int pid, int reap_child)
 {
 	kill(pid, SIGKILL);
Signature · 1 line
2.46.0
#4 lore raw

PATCH 4/5 um: Remove unused os_getpgrp function

In reply to Benjamin Berg

From: Benjamin Berg <[email protected]>

The function is not used anywhere.

---
 arch/um/include/shared/os.h | 1 -
 arch/um/os-Linux/process.c  | 5 -----
 2 files changed, 6 deletions(-)
arch/um/include/shared/os.h +0 -1
index a94093bfa5e4..e54f64f55bb7 100644
@@ -204,7 +204,6 @@ extern void os_kill_process(int pid, int reap_child);
 extern void os_kill_ptraced_process(int pid, int reap_child);
 
 extern int os_getpid(void);
-extern int os_getpgrp(void);
 
 extern void init_new_thread_signals(void);
 
arch/um/os-Linux/process.c +0 -5
index d1f5e6002805..f20602e793d9 100644
@@ -53,11 +53,6 @@ int os_getpid(void)
 	return syscall(__NR_getpid);
 }
 
-int os_getpgrp(void)
-{
-	return getpgrp();
-}
-
 int os_map_memory(void *virt, int fd, unsigned long long off, unsigned long len,
 		  int r, int w, int x)
 {
Signature · 1 line
2.46.0
#5 lore raw

PATCH 5/5 um: Set HAVE_EFFICIENT_UNALIGNED_ACCESS for x86

In reply to Benjamin Berg

From: Benjamin Berg <[email protected]>

The x86 port of UM has efficient unaligned access. Set the option as it is appropriate and will e.g. cause UBSAN to not enable unaligned memory access checking by default.

---
 arch/x86/um/Kconfig | 1 +
 1 file changed, 1 insertion(+)
arch/x86/um/Kconfig +1 -0
index 186f13268401..dc56c608ce69 100644
@@ -10,6 +10,7 @@ config UML_X86
 	def_bool y
 	select ARCH_BINFMT_ELF_EXTRA_PHDRS if X86_32
 	select DCACHE_WORD_ACCESS
+	select HAVE_EFFICIENT_UNALIGNED_ACCESS
 
 config 64BIT
 	bool "64-bit kernel" if "$(SUBARCH)" = "x86"
Signature · 1 line
2.46.0