linux-um.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/7] um: Define PTRACE_OLDSETOPTIONS
@ 2015-10-26  9:48 Richard Weinberger
  2015-10-26  9:48 ` [uml-devel] [PATCH 2/7] um: Store syscall number after syscall_trace_enter() Richard Weinberger
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Richard Weinberger @ 2015-10-26  9:48 UTC (permalink / raw)
  To: user-mode-linux-devel; +Cc: linux-kernel, Richard Weinberger

...such that processes within UML can do a ptrace(PTRACE_OLDSETOPTIONS, ...)

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 arch/um/include/asm/ptrace-generic.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/um/include/asm/ptrace-generic.h b/arch/um/include/asm/ptrace-generic.h
index 2966adb..5ab2062 100644
--- a/arch/um/include/asm/ptrace-generic.h
+++ b/arch/um/include/asm/ptrace-generic.h
@@ -27,6 +27,8 @@ struct pt_regs {
 
 #define instruction_pointer(regs) PT_REGS_IP(regs)
 
+#define PTRACE_OLDSETOPTIONS 21
+
 struct task_struct;
 
 extern long subarch_ptrace(struct task_struct *child, long request,
-- 
1.8.4.5


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [uml-devel] [PATCH 2/7] um: Store syscall number after syscall_trace_enter()
  2015-10-26  9:48 [PATCH 1/7] um: Define PTRACE_OLDSETOPTIONS Richard Weinberger
@ 2015-10-26  9:48 ` Richard Weinberger
  2015-10-26  9:48 ` [uml-devel] [PATCH 3/7] um: Get rid of open coded NR_SYSCALLS Richard Weinberger
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Richard Weinberger @ 2015-10-26  9:48 UTC (permalink / raw)
  To: user-mode-linux-devel; +Cc: Richard Weinberger, linux-kernel

To support changing syscall numbers we have to store
it after syscall_trace_enter().

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 arch/um/include/shared/os.h     |  1 +
 arch/um/kernel/skas/syscall.c   | 13 +++----------
 arch/um/os-Linux/skas/process.c | 10 +++++++---
 3 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h
index ad3fa3a..f3cbaef 100644
--- a/arch/um/include/shared/os.h
+++ b/arch/um/include/shared/os.h
@@ -274,6 +274,7 @@ extern void initial_thread_cb_skas(void (*proc)(void *),
 				 void *arg);
 extern void halt_skas(void);
 extern void reboot_skas(void);
+extern int get_syscall(struct uml_pt_regs *regs);
 
 /* irq.c */
 extern int os_waiting_for_events(struct irq_fd *active_fds);
diff --git a/arch/um/kernel/skas/syscall.c b/arch/um/kernel/skas/syscall.c
index d9ec006..64a8fe5 100644
--- a/arch/um/kernel/skas/syscall.c
+++ b/arch/um/kernel/skas/syscall.c
@@ -8,6 +8,7 @@
 #include <kern_util.h>
 #include <sysdep/ptrace.h>
 #include <sysdep/syscalls.h>
+#include <os.h>
 
 extern int syscall_table_size;
 #define NR_SYSCALLS (syscall_table_size / sizeof(void *))
@@ -23,16 +24,8 @@ void handle_syscall(struct uml_pt_regs *r)
 		goto out;
 	}
 
-	/*
-	 * This should go in the declaration of syscall, but when I do that,
-	 * strace -f -c bash -c 'ls ; ls' breaks, sometimes not tracing
-	 * children at all, sometimes hanging when bash doesn't see the first
-	 * ls exit.
-	 * The assembly looks functionally the same to me.  This is
-	 *     gcc version 4.0.1 20050727 (Red Hat 4.0.1-5)
-	 * in case it's a compiler bug.
-	 */
-	syscall = UPT_SYSCALL_NR(r);
+	syscall = get_syscall(r);
+
 	if ((syscall >= NR_SYSCALLS) || (syscall < 0))
 		result = -ENOSYS;
 	else result = EXECUTE_SYSCALL(syscall, regs);
diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/process.c
index 3dddedb..d38f495 100644
--- a/arch/um/os-Linux/skas/process.c
+++ b/arch/um/os-Linux/skas/process.c
@@ -137,9 +137,6 @@ static void handle_trap(int pid, struct uml_pt_regs *regs,
 	if ((UPT_IP(regs) >= STUB_START) && (UPT_IP(regs) < STUB_END))
 		fatal_sigsegv();
 
-	/* Mark this as a syscall */
-	UPT_SYSCALL_NR(regs) = PT_SYSCALL_NR(regs->gp);
-
 	if (!local_using_sysemu)
 	{
 		err = ptrace(PTRACE_POKEUSER, pid, PT_SYSCALL_NR_OFFSET,
@@ -174,6 +171,13 @@ static void handle_trap(int pid, struct uml_pt_regs *regs,
 	handle_syscall(regs);
 }
 
+int get_syscall(struct uml_pt_regs *regs)
+{
+	UPT_SYSCALL_NR(regs) = PT_SYSCALL_NR(regs->gp);
+
+	return UPT_SYSCALL_NR(regs);
+}
+
 extern char __syscall_stub_start[];
 
 static int userspace_tramp(void *stack)
-- 
1.8.4.5


------------------------------------------------------------------------------
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [uml-devel] [PATCH 3/7] um: Get rid of open coded NR_SYSCALLS
  2015-10-26  9:48 [PATCH 1/7] um: Define PTRACE_OLDSETOPTIONS Richard Weinberger
  2015-10-26  9:48 ` [uml-devel] [PATCH 2/7] um: Store syscall number after syscall_trace_enter() Richard Weinberger
@ 2015-10-26  9:48 ` Richard Weinberger
  2015-10-26  9:48 ` [uml-devel] [PATCH 4/7] um: Remove dead code from x86_64 syscall stub Richard Weinberger
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Richard Weinberger @ 2015-10-26  9:48 UTC (permalink / raw)
  To: user-mode-linux-devel; +Cc: Richard Weinberger, linux-kernel

We can use __NR_syscall_max.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 arch/um/kernel/skas/syscall.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/arch/um/kernel/skas/syscall.c b/arch/um/kernel/skas/syscall.c
index 64a8fe5..1683b8e 100644
--- a/arch/um/kernel/skas/syscall.c
+++ b/arch/um/kernel/skas/syscall.c
@@ -10,9 +10,6 @@
 #include <sysdep/syscalls.h>
 #include <os.h>
 
-extern int syscall_table_size;
-#define NR_SYSCALLS (syscall_table_size / sizeof(void *))
-
 void handle_syscall(struct uml_pt_regs *r)
 {
 	struct pt_regs *regs = container_of(r, struct pt_regs, regs);
@@ -26,9 +23,10 @@ void handle_syscall(struct uml_pt_regs *r)
 
 	syscall = get_syscall(r);
 
-	if ((syscall >= NR_SYSCALLS) || (syscall < 0))
+	if ((syscall > __NR_syscall_max) || syscall < 0)
 		result = -ENOSYS;
-	else result = EXECUTE_SYSCALL(syscall, regs);
+	else
+		result = EXECUTE_SYSCALL(syscall, regs);
 
 out:
 	PT_REGS_SET_SYSCALL_RETURN(regs, result);
-- 
1.8.4.5


------------------------------------------------------------------------------
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [uml-devel] [PATCH 4/7] um: Remove dead code from x86_64 syscall stub
  2015-10-26  9:48 [PATCH 1/7] um: Define PTRACE_OLDSETOPTIONS Richard Weinberger
  2015-10-26  9:48 ` [uml-devel] [PATCH 2/7] um: Store syscall number after syscall_trace_enter() Richard Weinberger
  2015-10-26  9:48 ` [uml-devel] [PATCH 3/7] um: Get rid of open coded NR_SYSCALLS Richard Weinberger
@ 2015-10-26  9:48 ` Richard Weinberger
  2015-10-26  9:48 ` [uml-devel] [PATCH 5/7] " Richard Weinberger
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Richard Weinberger @ 2015-10-26  9:48 UTC (permalink / raw)
  To: user-mode-linux-devel; +Cc: Richard Weinberger, linux-kernel

syscall_stub is dead code as um is using only
batch_syscall_stub.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 arch/x86/um/stub_64.S | 13 -------------
 1 file changed, 13 deletions(-)

diff --git a/arch/x86/um/stub_64.S b/arch/x86/um/stub_64.S
index 7160b20..a212445 100644
--- a/arch/x86/um/stub_64.S
+++ b/arch/x86/um/stub_64.S
@@ -1,19 +1,6 @@
 #include <as-layout.h>
 
-	.globl syscall_stub
 .section .__syscall_stub, "ax"
-syscall_stub:
-	syscall
-	/* We don't have 64-bit constants, so this constructs the address
-	 * we need.
-	 */
-	movq	$(STUB_DATA >> 32), %rbx
-	salq	$32, %rbx
-	movq	$(STUB_DATA & 0xffffffff), %rcx
-	or	%rcx, %rbx
-	movq	%rax, (%rbx)
-	int3
-
 	.globl batch_syscall_stub
 batch_syscall_stub:
 	mov	$(STUB_DATA >> 32), %rbx
-- 
1.8.4.5


------------------------------------------------------------------------------
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [uml-devel] [PATCH 5/7] um: Remove dead code from x86_64 syscall stub
  2015-10-26  9:48 [PATCH 1/7] um: Define PTRACE_OLDSETOPTIONS Richard Weinberger
                   ` (2 preceding siblings ...)
  2015-10-26  9:48 ` [uml-devel] [PATCH 4/7] um: Remove dead code from x86_64 syscall stub Richard Weinberger
@ 2015-10-26  9:48 ` Richard Weinberger
  2015-10-26  9:48 ` [uml-devel] [PATCH 6/7] um: Simplify STUB_DATA loading Richard Weinberger
  2015-10-26  9:48 ` [uml-devel] [PATCH 7/7] um: Report host OOM more nicely Richard Weinberger
  5 siblings, 0 replies; 7+ messages in thread
From: Richard Weinberger @ 2015-10-26  9:48 UTC (permalink / raw)
  To: user-mode-linux-devel; +Cc: Richard Weinberger, linux-kernel

syscall_stub is dead code as um is using only
batch_syscall_stub.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 arch/x86/um/stub_32.S | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/x86/um/stub_32.S b/arch/x86/um/stub_32.S
index b972649..9881680 100644
--- a/arch/x86/um/stub_32.S
+++ b/arch/x86/um/stub_32.S
@@ -1,6 +1,5 @@
 #include <as-layout.h>
 
-	.globl syscall_stub
 .section .__syscall_stub, "ax"
 
 	.globl batch_syscall_stub
-- 
1.8.4.5


------------------------------------------------------------------------------
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [uml-devel] [PATCH 6/7] um: Simplify STUB_DATA loading
  2015-10-26  9:48 [PATCH 1/7] um: Define PTRACE_OLDSETOPTIONS Richard Weinberger
                   ` (3 preceding siblings ...)
  2015-10-26  9:48 ` [uml-devel] [PATCH 5/7] " Richard Weinberger
@ 2015-10-26  9:48 ` Richard Weinberger
  2015-10-26  9:48 ` [uml-devel] [PATCH 7/7] um: Report host OOM more nicely Richard Weinberger
  5 siblings, 0 replies; 7+ messages in thread
From: Richard Weinberger @ 2015-10-26  9:48 UTC (permalink / raw)
  To: user-mode-linux-devel; +Cc: Richard Weinberger, linux-kernel

As long STUB_DATA fits into 32bits we can use a plain mov.
If it will grow at some point in future we will switch to movabsq.
In any case the code is smaller and more easy to read
than the current one

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 arch/x86/um/stub_64.S | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/arch/x86/um/stub_64.S b/arch/x86/um/stub_64.S
index a212445..ba914b3 100644
--- a/arch/x86/um/stub_64.S
+++ b/arch/x86/um/stub_64.S
@@ -3,10 +3,7 @@
 .section .__syscall_stub, "ax"
 	.globl batch_syscall_stub
 batch_syscall_stub:
-	mov	$(STUB_DATA >> 32), %rbx
-	sal	$32, %rbx
-	mov	$(STUB_DATA & 0xffffffff), %rax
-	or	%rax, %rbx
+	mov	$(STUB_DATA), %rbx
 	/* load pointer to first operation */
 	mov	%rbx, %rsp
 	add	$0x10, %rsp
-- 
1.8.4.5


------------------------------------------------------------------------------
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [uml-devel] [PATCH 7/7] um: Report host OOM more nicely
  2015-10-26  9:48 [PATCH 1/7] um: Define PTRACE_OLDSETOPTIONS Richard Weinberger
                   ` (4 preceding siblings ...)
  2015-10-26  9:48 ` [uml-devel] [PATCH 6/7] um: Simplify STUB_DATA loading Richard Weinberger
@ 2015-10-26  9:48 ` Richard Weinberger
  5 siblings, 0 replies; 7+ messages in thread
From: Richard Weinberger @ 2015-10-26  9:48 UTC (permalink / raw)
  To: user-mode-linux-devel; +Cc: Richard Weinberger, linux-kernel

If UML runs on the host side out of memory, report this
condition more nicely.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 arch/um/kernel/tlb.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/arch/um/kernel/tlb.c b/arch/um/kernel/tlb.c
index 2077248..3777b82 100644
--- a/arch/um/kernel/tlb.c
+++ b/arch/um/kernel/tlb.c
@@ -50,6 +50,13 @@ struct host_vm_change {
 	   .index	= 0, \
 	   .force	= force })
 
+static void report_enomem(void)
+{
+	printk(KERN_ERR "UML ran out of memory on the host side! "
+			"This can happen due to a memory limitation or "
+			"vm.max_map_count has been reached.\n");
+}
+
 static int do_ops(struct host_vm_change *hvc, int end,
 		  int finished)
 {
@@ -81,6 +88,9 @@ static int do_ops(struct host_vm_change *hvc, int end,
 		}
 	}
 
+	if (ret == -ENOMEM)
+		report_enomem();
+
 	return ret;
 }
 
@@ -433,8 +443,12 @@ void flush_tlb_page(struct vm_area_struct *vma, unsigned long address)
 	else if (pte_newprot(*pte))
 		err = protect(mm_id, address, PAGE_SIZE, prot, 1, &flush);
 
-	if (err)
+	if (err) {
+		if (err == -ENOMEM)
+			report_enomem();
+
 		goto kill;
+	}
 
 	*pte = pte_mkuptodate(*pte);
 
-- 
1.8.4.5


------------------------------------------------------------------------------
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-10-26  9:48 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-26  9:48 [PATCH 1/7] um: Define PTRACE_OLDSETOPTIONS Richard Weinberger
2015-10-26  9:48 ` [uml-devel] [PATCH 2/7] um: Store syscall number after syscall_trace_enter() Richard Weinberger
2015-10-26  9:48 ` [uml-devel] [PATCH 3/7] um: Get rid of open coded NR_SYSCALLS Richard Weinberger
2015-10-26  9:48 ` [uml-devel] [PATCH 4/7] um: Remove dead code from x86_64 syscall stub Richard Weinberger
2015-10-26  9:48 ` [uml-devel] [PATCH 5/7] " Richard Weinberger
2015-10-26  9:48 ` [uml-devel] [PATCH 6/7] um: Simplify STUB_DATA loading Richard Weinberger
2015-10-26  9:48 ` [uml-devel] [PATCH 7/7] um: Report host OOM more nicely Richard Weinberger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).