From 2402b673480c9fff670dbec7cc0aa08be61501bc Mon Sep 17 00:00:00 2001 From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Fri, 9 Jan 2015 10:11:26 +0100 Subject: add patch series --- ...oid-acquiring-global-lock-in-message-disp.patch | 80 ------------------ ...-libports-silence-pointless-error-message.patch | 30 +++++++ debian/patches/0002-auth-simplify-expression.patch | 35 ++++++++ debian/patches/0002-startup-faster-reboots.patch | 25 ------ ...-implicit-assumption-about-the-bootstrap-.patch | 61 ++++++++++++++ ...-proc-call-startup_essential_task-earlier.patch | 95 ++++++++++++++++++++++ ...oid-acquiring-global-lock-in-message-disp.patch | 80 ++++++++++++++++++ .../merge-me-0002-startup-faster-reboots.patch | 25 ++++++ debian/patches/series | 8 +- 9 files changed, 332 insertions(+), 107 deletions(-) delete mode 100644 debian/patches/0001-libports-avoid-acquiring-global-lock-in-message-disp.patch create mode 100644 debian/patches/0001-libports-silence-pointless-error-message.patch create mode 100644 debian/patches/0002-auth-simplify-expression.patch delete mode 100644 debian/patches/0002-startup-faster-reboots.patch create mode 100644 debian/patches/0003-auth-remove-implicit-assumption-about-the-bootstrap-.patch create mode 100644 debian/patches/0004-proc-call-startup_essential_task-earlier.patch create mode 100644 debian/patches/merge-me-0001-libports-avoid-acquiring-global-lock-in-message-disp.patch create mode 100644 debian/patches/merge-me-0002-startup-faster-reboots.patch (limited to 'debian') diff --git a/debian/patches/0001-libports-avoid-acquiring-global-lock-in-message-disp.patch b/debian/patches/0001-libports-avoid-acquiring-global-lock-in-message-disp.patch deleted file mode 100644 index 17af18da..00000000 --- a/debian/patches/0001-libports-avoid-acquiring-global-lock-in-message-disp.patch +++ /dev/null @@ -1,80 +0,0 @@ -From 9e94fffba8ffbc9af4a6ceb75a78d2dab2da5682 Mon Sep 17 00:00:00 2001 -From: Justus Winter <4winter@informatik.uni-hamburg.de> -Date: Mon, 15 Dec 2014 11:53:26 +0100 -Subject: [PATCH hurd 1/2] libports: avoid acquiring global lock in message - dispatch - -* libports/interrupt-operation.c (ports_S_interrupt_operation): Update -`cancel_threshold' using atomic operations. -* libports/manage-multithread.c (internal_demuxer): Avoid taking the lock. -* libports/ports.h (struct port_info): Mention that one needs atomic -operations to access `cancel_threshold'. ---- - libports/interrupt-operation.c | 14 ++++++++++---- - libports/manage-multithread.c | 8 +++++--- - libports/ports.h | 2 +- - 3 files changed, 16 insertions(+), 8 deletions(-) - -diff --git a/libports/interrupt-operation.c b/libports/interrupt-operation.c -index 943bd4f..5d4b0b7 100644 ---- a/libports/interrupt-operation.c -+++ b/libports/interrupt-operation.c -@@ -27,12 +27,18 @@ kern_return_t - ports_S_interrupt_operation (struct port_info *pi, - mach_port_seqno_t seqno) - { -+ mach_port_seqno_t old; -+ - if (!pi) - return EOPNOTSUPP; -- pthread_mutex_lock (&_ports_lock); -- if (pi->cancel_threshold < seqno) -- pi->cancel_threshold = seqno; -- pthread_mutex_unlock (&_ports_lock); -+ -+ retry: -+ old = __atomic_load_n (&pi->cancel_threshold, __ATOMIC_SEQ_CST); -+ if (old < seqno -+ && ! __atomic_compare_exchange_n (&pi->cancel_threshold, &old, seqno, -+ 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) -+ goto retry; -+ - ports_interrupt_rpcs (pi); - return 0; - } -diff --git a/libports/manage-multithread.c b/libports/manage-multithread.c -index 2067cba..7d2e126 100644 ---- a/libports/manage-multithread.c -+++ b/libports/manage-multithread.c -@@ -173,10 +173,12 @@ ports_manage_port_operations_multithread (struct port_bucket *bucket, - } - else - { -- pthread_mutex_lock (&_ports_lock); -- if (inp->msgh_seqno < pi->cancel_threshold) -+ mach_port_seqno_t cancel_threshold = -+ __atomic_load_n (&pi->cancel_threshold, __ATOMIC_SEQ_CST); -+ -+ if (inp->msgh_seqno < cancel_threshold) - hurd_thread_cancel (link.thread); -- pthread_mutex_unlock (&_ports_lock); -+ - status = demuxer (inp, outheadp); - ports_end_rpc (pi, &link); - } -diff --git a/libports/ports.h b/libports/ports.h -index a625b47..f02edb4 100644 ---- a/libports/ports.h -+++ b/libports/ports.h -@@ -48,7 +48,7 @@ struct port_info - struct port_class *class; - refcounts_t refcounts; - mach_port_mscount_t mscount; -- mach_msg_seqno_t cancel_threshold; -+ mach_msg_seqno_t cancel_threshold; /* needs atomic operations */ - int flags; - mach_port_t port_right; - struct rpc_info *current_rpcs; --- -2.1.3 - diff --git a/debian/patches/0001-libports-silence-pointless-error-message.patch b/debian/patches/0001-libports-silence-pointless-error-message.patch new file mode 100644 index 00000000..9cc66761 --- /dev/null +++ b/debian/patches/0001-libports-silence-pointless-error-message.patch @@ -0,0 +1,30 @@ +From ba9d293d8fe40f6e634cf800c42ece97727ccd0f Mon Sep 17 00:00:00 2001 +From: Justus Winter <4winter@informatik.uni-hamburg.de> +Date: Sat, 3 Jan 2015 16:21:24 +0100 +Subject: [PATCH hurd 1/4] libports: silence pointless error message + +* libports/manage-multithread.c (adjust_priority): Silence pointless +error message. +--- + libports/manage-multithread.c | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/libports/manage-multithread.c b/libports/manage-multithread.c +index 2067cba..ad22991 100644 +--- a/libports/manage-multithread.c ++++ b/libports/manage-multithread.c +@@ -50,6 +50,11 @@ adjust_priority (unsigned int totalthreads) + thread_switch (MACH_PORT_NULL, SWITCH_OPTION_DEPRESS, t); + + err = get_privileged_ports (&host_priv, NULL); ++ if (err == MACH_SEND_INVALID_DEST) ++ /* This is returned if we neither have the privileged host control ++ port cached nor have a proc server to talk to. Give up. */ ++ return; ++ + if (err) + goto error_host_priv; + +-- +2.1.4 + diff --git a/debian/patches/0002-auth-simplify-expression.patch b/debian/patches/0002-auth-simplify-expression.patch new file mode 100644 index 00000000..5fc19cfa --- /dev/null +++ b/debian/patches/0002-auth-simplify-expression.patch @@ -0,0 +1,35 @@ +From 197894abb7e3493019c50e807eac54b7b2396e9f Mon Sep 17 00:00:00 2001 +From: Justus Winter <4winter@informatik.uni-hamburg.de> +Date: Fri, 2 Jan 2015 21:53:08 +0100 +Subject: [PATCH hurd 2/4] auth: simplify expression + +* auth/auth.c (S_auth_{user,server}_authenticate): Simplify expression. +--- + auth/auth.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/auth/auth.c b/auth/auth.c +index c36bcb2..a7a188a 100644 +--- a/auth/auth.c ++++ b/auth/auth.c +@@ -299,7 +299,7 @@ S_auth_user_authenticate (struct authhandle *userauth, + if (! userauth) + return EOPNOTSUPP; + +- if (rendezvous == MACH_PORT_NULL || rendezvous == MACH_PORT_DEAD) ++ if (! MACH_PORT_VALID (rendezvous)) + return EINVAL; + + u.user = userauth; +@@ -380,7 +380,7 @@ S_auth_server_authenticate (struct authhandle *serverauth, + if (! serverauth) + return EOPNOTSUPP; + +- if (rendezvous == MACH_PORT_NULL || rendezvous == MACH_PORT_DEAD) ++ if (! MACH_PORT_VALID (rendezvous)) + return EINVAL; + + pthread_mutex_lock (&pending_lock); +-- +2.1.4 + diff --git a/debian/patches/0002-startup-faster-reboots.patch b/debian/patches/0002-startup-faster-reboots.patch deleted file mode 100644 index 1291b446..00000000 --- a/debian/patches/0002-startup-faster-reboots.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 6214a1df308f46738a832b04489200127e59a927 Mon Sep 17 00:00:00 2001 -From: Justus Winter <4winter@informatik.uni-hamburg.de> -Date: Wed, 17 Dec 2014 11:43:09 +0100 -Subject: [PATCH hurd 2/2] startup: faster reboots - ---- - startup/startup.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/startup/startup.c b/startup/startup.c -index 601c894..ebd0e12 100644 ---- a/startup/startup.c -+++ b/startup/startup.c -@@ -176,7 +176,7 @@ reboot_mach (int flags) - printf ("%s: %sing Mach (flags %#x)...\n", - program_invocation_short_name, BOOT (flags), flags); - fflush (stdout); -- sleep (5); -+ sleep (1); - while ((err = host_reboot (host_priv, flags))) - error (0, err, "reboot"); - for (;;); --- -2.1.3 - diff --git a/debian/patches/0003-auth-remove-implicit-assumption-about-the-bootstrap-.patch b/debian/patches/0003-auth-remove-implicit-assumption-about-the-bootstrap-.patch new file mode 100644 index 00000000..1c7780cd --- /dev/null +++ b/debian/patches/0003-auth-remove-implicit-assumption-about-the-bootstrap-.patch @@ -0,0 +1,61 @@ +From fc44d0e5258fe3120e40f1ea629ddb84ba4cc971 Mon Sep 17 00:00:00 2001 +From: Justus Winter <4winter@informatik.uni-hamburg.de> +Date: Wed, 7 Jan 2015 16:00:06 +0100 +Subject: [PATCH hurd 3/4] auth: remove implicit assumption about the bootstrap + process + +The current code assumes, that it can speak the startup protocol over +its bootstrap port. + +* auth/auth.c (main): Generalize by trying to use `/servers/startup' +before falling back to the bootstrap port. +--- + auth/auth.c | 15 ++++++++++++++- + 1 file changed, 14 insertions(+), 1 deletion(-) + +diff --git a/auth/auth.c b/auth/auth.c +index a7a188a..d5ef587 100644 +--- a/auth/auth.c ++++ b/auth/auth.c +@@ -25,6 +25,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -482,6 +483,7 @@ main (int argc, char **argv) + { + error_t err; + mach_port_t boot; ++ mach_port_t startup; + process_t proc; + mach_port_t hostpriv, masterdev; + struct authhandle *firstauth; +@@ -518,10 +520,21 @@ main (int argc, char **argv) + _hurd_port_set (&_hurd_ports[INIT_PORT_PROC], proc); + _hurd_proc_init (argv, NULL, 0); + ++ startup = file_name_lookup (_SERVERS_STARTUP, 0, 0); ++ if (! MACH_PORT_VALID (startup)) ++ { ++ error (0, errno, "%s", _SERVERS_STARTUP); ++ /* Fall back to using the bootstrap port as before. */ ++ startup = boot; ++ } ++ + /* Init knows intimately that we will be ready for messages + as soon as this returns. */ +- startup_essential_task (boot, mach_task_self (), MACH_PORT_NULL, "auth", ++ startup_essential_task (startup, mach_task_self (), MACH_PORT_NULL, "auth", + hostpriv); ++ ++ if (startup != boot) ++ mach_port_deallocate (mach_task_self (), startup); + mach_port_deallocate (mach_task_self (), boot); + mach_port_deallocate (mach_task_self (), hostpriv); + +-- +2.1.4 + diff --git a/debian/patches/0004-proc-call-startup_essential_task-earlier.patch b/debian/patches/0004-proc-call-startup_essential_task-earlier.patch new file mode 100644 index 00000000..667922db --- /dev/null +++ b/debian/patches/0004-proc-call-startup_essential_task-earlier.patch @@ -0,0 +1,95 @@ +From ff81cb4c7044a803b3338135dad97b14233eed7d Mon Sep 17 00:00:00 2001 +From: Justus Winter <4winter@informatik.uni-hamburg.de> +Date: Wed, 7 Jan 2015 16:05:48 +0100 +Subject: [PATCH hurd 4/4] proc: call `startup_essential_task' earlier + +* proc/main.c (main): Try to lookup `/servers/startup' and send the +message here, or... +* proc/msg.c (S_proc_setmsgport): ... fall back to the old way here. +* proc/proc.h (startup_fallback): New variable. +--- + proc/main.c | 19 +++++++++++++++++++ + proc/msg.c | 2 +- + proc/proc.h | 2 ++ + 3 files changed, 22 insertions(+), 1 deletion(-) + +diff --git a/proc/main.c b/proc/main.c +index b4288fb..2a3d279 100644 +--- a/proc/main.c ++++ b/proc/main.c +@@ -22,6 +22,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ + #include + #include + #include ++#include + #include + #include + #include +@@ -62,6 +63,7 @@ message_demuxer (mach_msg_header_t *inp, + } + + pthread_mutex_t global_lock = PTHREAD_MUTEX_INITIALIZER; ++int startup_fallback; + + error_t + increase_priority (void) +@@ -99,6 +101,7 @@ main (int argc, char **argv, char **envp) + error_t err; + void *genport; + process_t startup_port; ++ mach_port_t startup; + struct argp argp = { 0, 0, 0, "Hurd process server" }; + + argp_parse (&argp, argc, argv, 0, 0, 0); +@@ -173,6 +176,22 @@ main (int argc, char **argv, char **envp) + mach_port_deallocate (mach_task_self (), cons); + } + ++ startup = file_name_lookup (_SERVERS_STARTUP, 0, 0); ++ if (MACH_PORT_VALID (startup)) ++ { ++ err = startup_essential_task (startup, mach_task_self (), ++ MACH_PORT_NULL, "proc", _hurd_host_priv); ++ assert_perror (err); ++ err = mach_port_deallocate (mach_task_self (), startup); ++ assert_perror (err); ++ } ++ else ++ { ++ error (0, errno, "%s", _SERVERS_STARTUP); ++ /* Fall back to abusing the message port lookup. */ ++ startup_fallback = 1; ++ } ++ + while (1) + ports_manage_port_operations_multithread (proc_bucket, + message_demuxer, +diff --git a/proc/msg.c b/proc/msg.c +index 796cae3..c7bab99 100644 +--- a/proc/msg.c ++++ b/proc/msg.c +@@ -63,7 +63,7 @@ S_proc_setmsgport (struct proc *p, + prociterate (check_message_return, p); + p->p_checkmsghangs = 0; + +- if (p == startup_proc) ++ if (p == startup_proc && startup_fallback) + { + /* Init is single threaded, so we can't delay our reply for + the essential task RPC; spawn a thread to do it. */ +diff --git a/proc/proc.h b/proc/proc.h +index a056d18..4be1de4 100644 +--- a/proc/proc.h ++++ b/proc/proc.h +@@ -151,6 +151,8 @@ mach_port_t generic_port; /* messages not related to a specific proc */ + + pthread_mutex_t global_lock; + ++extern int startup_fallback; /* (ab)use /hurd/startup's message port */ ++ + /* Forward declarations */ + void complete_wait (struct proc *, int); + int check_uid (struct proc *, uid_t); +-- +2.1.4 + diff --git a/debian/patches/merge-me-0001-libports-avoid-acquiring-global-lock-in-message-disp.patch b/debian/patches/merge-me-0001-libports-avoid-acquiring-global-lock-in-message-disp.patch new file mode 100644 index 00000000..17af18da --- /dev/null +++ b/debian/patches/merge-me-0001-libports-avoid-acquiring-global-lock-in-message-disp.patch @@ -0,0 +1,80 @@ +From 9e94fffba8ffbc9af4a6ceb75a78d2dab2da5682 Mon Sep 17 00:00:00 2001 +From: Justus Winter <4winter@informatik.uni-hamburg.de> +Date: Mon, 15 Dec 2014 11:53:26 +0100 +Subject: [PATCH hurd 1/2] libports: avoid acquiring global lock in message + dispatch + +* libports/interrupt-operation.c (ports_S_interrupt_operation): Update +`cancel_threshold' using atomic operations. +* libports/manage-multithread.c (internal_demuxer): Avoid taking the lock. +* libports/ports.h (struct port_info): Mention that one needs atomic +operations to access `cancel_threshold'. +--- + libports/interrupt-operation.c | 14 ++++++++++---- + libports/manage-multithread.c | 8 +++++--- + libports/ports.h | 2 +- + 3 files changed, 16 insertions(+), 8 deletions(-) + +diff --git a/libports/interrupt-operation.c b/libports/interrupt-operation.c +index 943bd4f..5d4b0b7 100644 +--- a/libports/interrupt-operation.c ++++ b/libports/interrupt-operation.c +@@ -27,12 +27,18 @@ kern_return_t + ports_S_interrupt_operation (struct port_info *pi, + mach_port_seqno_t seqno) + { ++ mach_port_seqno_t old; ++ + if (!pi) + return EOPNOTSUPP; +- pthread_mutex_lock (&_ports_lock); +- if (pi->cancel_threshold < seqno) +- pi->cancel_threshold = seqno; +- pthread_mutex_unlock (&_ports_lock); ++ ++ retry: ++ old = __atomic_load_n (&pi->cancel_threshold, __ATOMIC_SEQ_CST); ++ if (old < seqno ++ && ! __atomic_compare_exchange_n (&pi->cancel_threshold, &old, seqno, ++ 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) ++ goto retry; ++ + ports_interrupt_rpcs (pi); + return 0; + } +diff --git a/libports/manage-multithread.c b/libports/manage-multithread.c +index 2067cba..7d2e126 100644 +--- a/libports/manage-multithread.c ++++ b/libports/manage-multithread.c +@@ -173,10 +173,12 @@ ports_manage_port_operations_multithread (struct port_bucket *bucket, + } + else + { +- pthread_mutex_lock (&_ports_lock); +- if (inp->msgh_seqno < pi->cancel_threshold) ++ mach_port_seqno_t cancel_threshold = ++ __atomic_load_n (&pi->cancel_threshold, __ATOMIC_SEQ_CST); ++ ++ if (inp->msgh_seqno < cancel_threshold) + hurd_thread_cancel (link.thread); +- pthread_mutex_unlock (&_ports_lock); ++ + status = demuxer (inp, outheadp); + ports_end_rpc (pi, &link); + } +diff --git a/libports/ports.h b/libports/ports.h +index a625b47..f02edb4 100644 +--- a/libports/ports.h ++++ b/libports/ports.h +@@ -48,7 +48,7 @@ struct port_info + struct port_class *class; + refcounts_t refcounts; + mach_port_mscount_t mscount; +- mach_msg_seqno_t cancel_threshold; ++ mach_msg_seqno_t cancel_threshold; /* needs atomic operations */ + int flags; + mach_port_t port_right; + struct rpc_info *current_rpcs; +-- +2.1.3 + diff --git a/debian/patches/merge-me-0002-startup-faster-reboots.patch b/debian/patches/merge-me-0002-startup-faster-reboots.patch new file mode 100644 index 00000000..1291b446 --- /dev/null +++ b/debian/patches/merge-me-0002-startup-faster-reboots.patch @@ -0,0 +1,25 @@ +From 6214a1df308f46738a832b04489200127e59a927 Mon Sep 17 00:00:00 2001 +From: Justus Winter <4winter@informatik.uni-hamburg.de> +Date: Wed, 17 Dec 2014 11:43:09 +0100 +Subject: [PATCH hurd 2/2] startup: faster reboots + +--- + startup/startup.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/startup/startup.c b/startup/startup.c +index 601c894..ebd0e12 100644 +--- a/startup/startup.c ++++ b/startup/startup.c +@@ -176,7 +176,7 @@ reboot_mach (int flags) + printf ("%s: %sing Mach (flags %#x)...\n", + program_invocation_short_name, BOOT (flags), flags); + fflush (stdout); +- sleep (5); ++ sleep (1); + while ((err = host_reboot (host_priv, flags))) + error (0, err, "reboot"); + for (;;); +-- +2.1.3 + diff --git a/debian/patches/series b/debian/patches/series index 0dc4c152..b2dfa224 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -45,5 +45,9 @@ startup-avoid-broken-puts.patch pfinet_dhcp.patch libports-payloads.patch proc-task-notify-0005-proc-fix-build.patch -0001-libports-avoid-acquiring-global-lock-in-message-disp.patch -0002-startup-faster-reboots.patch +merge-me-0001-libports-avoid-acquiring-global-lock-in-message-disp.patch +merge-me-0002-startup-faster-reboots.patch +0001-libports-silence-pointless-error-message.patch +0002-auth-simplify-expression.patch +0003-auth-remove-implicit-assumption-about-the-bootstrap-.patch +0004-proc-call-startup_essential_task-earlier.patch -- cgit v1.2.3