Re: macppc bsd.mp pmap's hash lock

2021-05-10 Thread George Koehler
I made a mistake in my last diff by deleting the memory barriers.
Here is a diff that keeps membar_enter() and membar_exit().

With my last diff, my G5 froze after 15 hours of uptime, and again
after 10 hours of uptime.  I'm not sure whether the missing memory
barriers caused the freeze, but I will be running this diff and hoping
for fewer freezes.

On Sat, 8 May 2021 18:59:35 +0200 (CEST)
Mark Kettenis  wrote:

> Good find!  On powerpc64 I avoid the issue because I guarantee that
> the kernel mappings are never evicted from the hash.  But doing so on
> powerpc would require more serious development.  I'm not sure we
> really need a ticket lock for this, but since you already did the
> work, let's stick with it for now.

__ppc_lock (before and after this diff) doesn't give tickets like
__mp_lock does, but __ppc_lock and __mp_lock are both recursive locks.
I don't know an easy way to avoid the recursion, if some of the kernel
mappings might not be in the hash.  My __ppc_lock diff should be easy
if I don't make mistakes like wrong memory barriers.

--George

Index: arch/powerpc/include/mplock.h
===
RCS file: /cvs/src/sys/arch/powerpc/include/mplock.h,v
retrieving revision 1.4
diff -u -p -r1.4 mplock.h
--- arch/powerpc/include/mplock.h   15 Apr 2020 08:09:00 -  1.4
+++ arch/powerpc/include/mplock.h   10 May 2021 23:33:00 -
@@ -30,13 +30,13 @@
 #define __USE_MI_MPLOCK
 
 /*
+ * __ppc_lock exists because pte_spill_r() can't use __mp_lock.
  * Really simple spinlock implementation with recursive capabilities.
  * Correctness is paramount, no fancyness allowed.
  */
 
 struct __ppc_lock {
-   volatile struct cpu_info *mpl_cpu;
-   volatile long   mpl_count;
+   volatile unsigned int   mpl_bolt;
 };
 
 #ifndef _LOCORE
@@ -44,10 +44,6 @@ struct __ppc_lock {
 void __ppc_lock_init(struct __ppc_lock *);
 void __ppc_lock(struct __ppc_lock *);
 void __ppc_unlock(struct __ppc_lock *);
-int __ppc_release_all(struct __ppc_lock *);
-int __ppc_release_all_but_one(struct __ppc_lock *);
-void __ppc_acquire_count(struct __ppc_lock *, int);
-int __ppc_lock_held(struct __ppc_lock *, struct cpu_info *);
 
 #endif
 
Index: arch/powerpc/powerpc/lock_machdep.c
===
RCS file: /cvs/src/sys/arch/powerpc/powerpc/lock_machdep.c,v
retrieving revision 1.9
diff -u -p -r1.9 lock_machdep.c
--- arch/powerpc/powerpc/lock_machdep.c 15 Apr 2020 08:09:00 -  1.9
+++ arch/powerpc/powerpc/lock_machdep.c 10 May 2021 23:33:00 -
@@ -1,6 +1,7 @@
 /* $OpenBSD: lock_machdep.c,v 1.9 2020/04/15 08:09:00 mpi Exp $*/
 
 /*
+ * Copyright (c) 2021 George Koehler 
  * Copyright (c) 2007 Artur Grabowski 
  *
  * Permission to use, copy, modify, and distribute this software for any
@@ -22,15 +23,29 @@
 #include 
 
 #include 
-#include 
 
 #include 
 
+/*
+ * If __ppc_lock() crosses a page boundary in the kernel text, then it
+ * may cause a page fault (on G5 with ppc_nobat), and pte_spill_r()
+ * would recursively call __ppc_lock().  The lock must be in a valid
+ * state when the page fault happens.
+ *
+ * This lock has 2 fields, "cpuid" and "count", packed in a 32-bit
+ * "bolt", so we can use 32-bit atomic ops to ensure that our lock is
+ * always in a valid state.
+ */
+#define BOLT(cpuid, count) ((cpuid) << 24 | (count) & 0x00ff)
+#define BOLT_CPUID(bolt)   ((bolt) >> 24)
+#define BOLT_COUNT(bolt)   ((bolt) & 0x00ff)
+#define BOLT_LOCKED(bolt)  (BOLT_COUNT(bolt) != 0)
+#define BOLT_UNLOCKED(bolt)(BOLT_COUNT(bolt) == 0)
+
 void
 __ppc_lock_init(struct __ppc_lock *lock)
 {
-   lock->mpl_cpu = NULL;
-   lock->mpl_count = 0;
+   lock->mpl_bolt = 0;
 }
 
 #if defined(MP_LOCKDEBUG)
@@ -46,12 +61,12 @@ static __inline void
 __ppc_lock_spin(struct __ppc_lock *mpl)
 {
 #ifndef MP_LOCKDEBUG
-   while (mpl->mpl_count != 0)
+   while (BOLT_LOCKED(mpl->mpl_bolt))
CPU_BUSY_CYCLE();
 #else
int nticks = __mp_lock_spinout;
 
-   while (mpl->mpl_count != 0 && --nticks > 0)
+   while (BOLT_LOCKED(mpl->mpl_bolt) && --nticks > 0)
CPU_BUSY_CYCLE();
 
if (nticks == 0) {
@@ -64,33 +79,23 @@ __ppc_lock_spin(struct __ppc_lock *mpl)
 void
 __ppc_lock(struct __ppc_lock *mpl)
 {
-   /*
-* Please notice that mpl_count gets incremented twice for the
-* first lock. This is on purpose. The way we release the lock
-* in mp_unlock is to decrement the mpl_count and then check if
-* the lock should be released. Since mpl_count is what we're
-* spinning on, decrementing it in mpl_unlock to 0 means that
-* we can't clear mpl_cpu, because we're no longer holding the
-* lock. In theory mpl_cpu doesn't need to be cleared, but it's
-* safer to clear it and besides, setting mpl_count to 2 on the
-* first lock makes most of this code much simple

Re: systat(1) sticky help

2021-05-10 Thread Anindya Mukherjee
I have been using this patch from martijn@ and find it really useful. Is
it possible to merge this? Thanks!

Regards,
Anindya

On Tue, Mar 09, 2021 at 07:33:29PM +0100, Martijn van Duren wrote:
> I send out an earlier version of this diff to Anindya with some positive
> feedback. Instead of claiming another binding, why not make help, order
> and view a toggle? I see no reason why this information should disappear
> on the next input.
> 
> Seems to work fine in my testing.
> 
> OK?
> 
> martijn@
> 
> On Thu, 2021-03-04 at 22:47 -0800, Anindya Mukherjee wrote:
> > Hi,
> > 
> > I have reworked my proposed interface for sticky displays in systat
> > following earlier feedback. Thanks for that! It helped me rethink the
> > interface carefully.
> > 
> > In the current version, sticky mode has its own toggle: ^T. From a study
> > of the source and the man page it does not seem to be bound to anything
> > and, on my system at least, does not conflict with anything else. I
> > could add a dedicated command for it as well if that's useful. The
> > current version supports a sticky display for the view list, view mode
> > plus refresh interval, and available orderings.
> > 
> > I have tried the hotkeys for the various views as documented in the man
> > page (as well as some of the undocumented ones) and they seem to work. I
> > have also tried to make sure that the sticky displays don't interfere
> > with error messages. In future I would like to try to clean up the view
> > hotkeys, which conflict each other in some cases, and seem to be
> > undocumented. I found them useful; at least the ones that work. Please
> > have a look, thanks!
> > 
> > Regards,
> > Anindya
> 
> Index: engine.c
> ===
> RCS file: /cvs/src/usr.bin/systat/engine.c,v
> retrieving revision 1.27
> diff -u -p -r1.27 engine.c
> --- engine.c  6 Feb 2021 06:19:28 -   1.27
> +++ engine.c  9 Mar 2021 18:32:24 -
> @@ -91,6 +91,8 @@ char cmdbuf[MAX_LINE_BUF];
>  int cmd_len = -1;
>  struct command *curr_cmd = NULL;
>  char *curr_message = NULL;
> +enum message_mode message_mode = MESSAGE_NONE;
> +int message_cont = 1;
>  
>  void print_cmdline(void);
>  
> @@ -1145,14 +1147,26 @@ command_set(struct command *cmd, const c
>   return prev;
>  }
>  
> +void
> +message_toggle(enum message_mode mode)
> +{
> + message_mode = message_mode != mode ? mode : MESSAGE_NONE;
> + need_update = 1;
> + message_cont = 1;
> +}
> +
>  const char *
> -message_set(const char *msg) {
> - char *prev = curr_message;
> - if (msg)
> +message_set(const char *msg)
> +{
> + free(curr_message);
> +
> + if (msg) {
>   curr_message = strdup(msg);
> - else
> + message_cont = 0;
> + } else {
>   curr_message = NULL;
> - free(prev);
> + message_cont = 1;
> + }
>   return NULL;
>  }
>  
> @@ -1361,6 +1375,22 @@ engine_loop(int countmax)
>   if (!averageonly ||
>   (averageonly && count == countmax - 1))
>   disp_update();
> + if (message_cont) {
> + switch (message_mode) {
> + case MESSAGE_NONE:
> + message_set(NULL);
> + break;
> + case MESSAGE_HELP:
> + show_help();
> + break;
> + case MESSAGE_VIEW:
> + show_view();
> + break;
> + case MESSAGE_ORDER:
> + show_order();
> + break;
> + }
> + }
>   end_page();
>   need_update = 0;
>   if (countmax && ++count >= countmax)
> Index: engine.h
> ===
> RCS file: /cvs/src/usr.bin/systat/engine.h,v
> retrieving revision 1.12
> diff -u -p -r1.12 engine.h
> --- engine.h  12 Jan 2020 20:51:08 -  1.12
> +++ engine.h  9 Mar 2021 18:32:24 -
> @@ -95,6 +95,12 @@ struct command {
>   void ( *exec)(const char *);
>  };
>  
> +enum message_mode {
> + MESSAGE_NONE,
> + MESSAGE_HELP,
> + MESSAGE_VIEW,
> + MESSAGE_ORDER
> +};
>  
>  void tb_start(void);
>  
> @@ -133,6 +139,9 @@ void prev_view(void);
>  int foreach_order(void (*callback)(order_type *));
>  void set_order(const char *opt);
>  void next_order(void);
> +void show_help(void);
> +void show_view(void);
> +void show_order(void);
>  
>  void setup_term(int maxpr);
>  int check_termcap(void);
> @@ -141,6 +150,7 @@ void engine_initialize(void);
>  void engine_loop(int countmax);
>  
>  struct command *command_set(struct com

Re: patch: add support for RTLD_NODELETE

2021-05-10 Thread Brad Smith
Seeing your e-mail reminded me that I had asked Philip about adding
support for RTLD_NOLOAD / RTLD_NODELETE last year after seeing instances
of their usage in the tree here and there.


- Forwarded message from Philip Guenther  -

Date: Thu, 24 Sep 2020 23:19:27 -0700
From: Philip Guenther 
To: Brad Smith 
Subject: Re: dlopen & RTLD_NOLOAD / RTLD_NODELETE
User-Agent: Alpine 2.21 (BSO 202 2017-01-01)

On Sat, 19 Sep 2020, Brad Smith wrote:
> On 8/31/2020 12:24 AM, Philip Guenther wrote:
> > On Sun, 30 Aug 2020, Brad Smith wrote:
> > > Is there any chance that OpenBSD's dlopen() could have support for
> > > RTLD_NOLOAD / RTLD_NODELETE added? Specifically RTLD_NOLOAD as I've had
> > > a patch in MariaDB for ages to allow building on OpenBSD.
> > Sigh.  The hard part is writing the regress.
> 
> Is that a no?

The noload bits are completely untested.

Index: include/dlfcn.h
===
RCS file: /data/src/openbsd/src/include/dlfcn.h,v
retrieving revision 1.14
diff -u -p -r1.14 dlfcn.h
--- include/dlfcn.h 28 Nov 2017 17:19:47 -  1.14
+++ include/dlfcn.h 31 Aug 2020 00:55:55 -
@@ -42,6 +42,8 @@
 #define RTLD_GLOBAL0x100
 #define RTLD_LOCAL 0x000
 #define RTLD_TRACE 0x200
+#define RTLD_NODELETE  0x400
+#define RTLD_NOLOAD0x800
 
 /*
  * Special handle arguments for dlsym().
Index: libexec/ld.so/dlfcn.c
===
RCS file: /data/src/openbsd/src/libexec/ld.so/dlfcn.c,v
retrieving revision 1.106
diff -u -p -r1.106 dlfcn.c
--- libexec/ld.so/dlfcn.c   4 Oct 2019 17:42:16 -   1.106
+++ libexec/ld.so/dlfcn.c   1 Sep 2020 05:04:40 -
@@ -46,6 +46,15 @@ static int _dl_real_close(void *handle);
 static lock_cb *_dl_thread_fnc = NULL;
 static elf_object_t *obj_from_addr(const void *addr);
 
+#define OK_FLAGS   (0 \
+   | RTLD_TRACE\
+   | RTLD_LAZY \
+   | RTLD_NOW  \
+   | RTLD_GLOBAL   \
+   | RTLD_NODELETE \
+   | RTLD_NOLOAD   \
+   )
+
 void *
 dlopen(const char *libname, int flags)
 {
@@ -54,7 +63,7 @@ dlopen(const char *libname, int flags)
int failed = 0;
int obj_flags;
 
-   if (flags & ~(RTLD_TRACE|RTLD_LAZY|RTLD_NOW|RTLD_GLOBAL)) {
+   if (flags & ~OK_FLAGS) {
_dl_errno = DL_INVALID_MODE;
return NULL;
}
@@ -79,7 +88,10 @@ dlopen(const char *libname, int flags)
_dl_loading_object = NULL;
 
obj_flags = (flags & RTLD_NOW ? DF_1_NOW : 0)
-   | (flags & RTLD_GLOBAL ? DF_1_GLOBAL : 0);
+   | (flags & RTLD_GLOBAL ? DF_1_GLOBAL : 0)
+   | (flags & RTLD_NODELETE ? DF_1_NODELETE : 0)
+   | (flags & RTLD_NOLOAD ? DF_1_NOOPEN : 0)
+   ;
object = _dl_load_shlib(libname, _dl_objects, OBJTYPE_DLO, obj_flags);
if (object == 0) {
DL_DEB(("dlopen: failed to open %s\n", libname));
@@ -93,6 +105,10 @@ dlopen(const char *libname, int flags)
/* if opened but grpsym_vec has not been filled in */
if (object->grpsym_vec.len == 0)
_dl_cache_grpsym_list_setup(object);
+   if (flags & RTLD_NODELETE) {
+   object->obj_flags |= DF_1_NODELETE;
+   _dl_handle_nodelete(object);
+   }
goto loaded;
}
 
Index: libexec/ld.so/library.c
===
RCS file: /data/src/openbsd/src/libexec/ld.so/library.c,v
retrieving revision 1.85
diff -u -p -r1.85 library.c
--- libexec/ld.so/library.c 9 Dec 2019 22:15:15 -   1.85
+++ libexec/ld.so/library.c 31 Aug 2020 01:36:06 -
@@ -127,17 +127,14 @@ _dl_tryload_shlib(const char *libname, i
for (object = _dl_objects; object != NULL; object = object->next) {
if (object->dev == sb.st_dev &&
object->inode == sb.st_ino) {
-   object->obj_flags |= flags & DF_1_GLOBAL;
_dl_close(libfile);
-   if (_dl_loading_object == NULL)
-   _dl_loading_object = object;
-   if (object->load_object != _dl_objects &&
-   object->load_object != _dl_loading_object) {
-   _dl_link_grpref(object->load_object,
-   _dl_loading_object);
-   }
+   _dl_handle_already_loaded(object, flags);
return(object);
}
+   }
+   if (flags & DF_1_NOOPEN) {
+   _dl_close(libfile);
+   return NULL;
}
 
_dl_read(libfile, hbuf, sizeof(hbuf));
Index: libexec/ld.so/library_mquery.c
===
RCS file: /data/src/openbsd/src/libexec/ld.so/library_mquery.c,v
retrieving r

Diff for www:FAQ>PF: Packet Filtering

2021-05-10 Thread bsd
Hi,

Here a diff for www page: FAQ>PF: Packet Filtering

Just one typo.

Right?


Index: faq/pf/filter.html
===
RCS file: /cvs/www/faq/pf/filter.html,v
retrieving revision 1.97
diff -u -r1.97 filter.html
--- faq/pf/filter.html  5 May 2021 21:49:29 -   1.97
+++ faq/pf/filter.html  10 May 2021 17:58:11 -
@@ -695,7 +695,7 @@
 in transmitted packets in order to either hide the real address or
 to impersonate another node on the network.
 Once the address has been spoofed, a network attack can be launched without
-revealing the true source of the attack,
+revealing the true source of the attack.
 An attacker can also attempt to gain access to network services that are
 restricted to certain IP addresses.
 



Diff for www:FAQ>PF:Getting started

2021-05-10 Thread bsd
Hi,

Here a diff for www page: FAQ>PF:Getting started

Just some typos

Right?


Index: faq/pf/config.html
===
RCS file: /cvs/www/faq/pf/config.html,v
retrieving revision 1.66
diff -u -r1.66 config.html
--- faq/pf/config.html  5 May 2021 21:49:29 -   1.66
+++ faq/pf/config.html  10 May 2021 16:34:12 -
@@ -50,7 +50,7 @@
 Activation
 
 PF is enabled by default.
-If can be disabled at boot with the
+It can be disabled at boot with the
 https://man.openbsd.org/rcctl";>rcctl(8) tool:
 
 
@@ -107,8 +107,8 @@
 Some example commands are:
 
 
-# pfctl -f  /etc/pf.confLoad the pf.conf file
-# pfctl -nf /etc/pf.confParse the file, but don't load it
+# pfctl -f  /etc/pf.conf# Load the pf.conf file
+# pfctl -nf /etc/pf.conf# Parse the file, but don't 
load it
 # pfctl -sr # Show the current ruleset
 # pfctl -ss # Show the current state table
 # pfctl -si # Show filter stats and counters



Re: bgpd, non-blocking rtr connect

2021-05-10 Thread Sebastian Benoit
ok benno@

Claudio Jeker(cje...@diehard.n-r-g.com) on 2021.05.03 17:37:36 +0200:
> The RTR session was opened with a blocking connect() call. This is rather
> bad if the RTR peer does not exist since then bgpd will block until the
> connect timed out. This diff makes the connect() call non-blocking.
> With this connecting to non-existing RTR servers no longer blocks the main
> process.
> 
> -- 
> :wq Claudio
> 
> Index: bgpd.c
> ===
> RCS file: /cvs/src/usr.sbin/bgpd/bgpd.c,v
> retrieving revision 1.235
> diff -u -p -r1.235 bgpd.c
> --- bgpd.c3 May 2021 13:18:06 -   1.235
> +++ bgpd.c3 May 2021 15:33:20 -
> @@ -50,6 +50,7 @@ static void getsockpair(int [2]);
>  int  imsg_send_sockets(struct imsgbuf *, struct imsgbuf *,
>   struct imsgbuf *);
>  void bgpd_rtr_connect(struct rtr_config *);
> +void bgpd_rtr_connect_done(int, struct bgpd_config *);
>  
>  int   cflags;
>  volatile sig_atomic_t mrtdump;
> @@ -64,6 +65,16 @@ struct rib_namesribnames = SIMPLEQ_HEA
>  char *cname;
>  char *rcname;
>  
> +struct connect_elm {
> + TAILQ_ENTRY(connect_elm)entry;
> + u_int32_t   id;
> + int fd;
> +};
> +
> +TAILQ_HEAD( ,connect_elm)connect_queue = \
> + TAILQ_HEAD_INITIALIZER(connect_queue);
> +u_intconnect_cnt;
> +
>  void
>  sighdlr(int sig)
>  {
> @@ -97,7 +108,7 @@ usage(void)
>  #define PFD_PIPE_RTR 2
>  #define PFD_SOCK_ROUTE   3
>  #define PFD_SOCK_PFKEY   4
> -#define POLL_MAX 5
> +#define PFD_CONNECT_START5
>  #define MAX_TIMEOUT  3600
>  
>  int   cmd_opts;
> @@ -109,11 +120,13 @@ main(int argc, char *argv[])
>   enum bgpd_processproc = PROC_MAIN;
>   struct rde_rib  *rr;
>   struct peer *p;
> - struct pollfdpfd[POLL_MAX];
> + struct pollfd   *pfd = NULL;
> + struct connect_elm  *ce;
>   time_t   timeout;
>   pid_tse_pid = 0, rde_pid = 0, rtr_pid = 0, pid;
>   char*conffile;
>   char*saved_argv0;
> + u_intpfd_elms = 0, npfd, i;
>   int  debug = 0;
>   int  rfd, keyfd;
>   int  ch, status;
> @@ -289,7 +302,21 @@ BROKEN   if (pledge("stdio rpath wpath cpa
>   quit = 1;
>  
>   while (quit == 0) {
> - bzero(pfd, sizeof(pfd));
> + if (pfd_elms < PFD_CONNECT_START + connect_cnt) {
> + struct pollfd *newp;
> +
> + if ((newp = reallocarray(pfd,
> + PFD_CONNECT_START + connect_cnt,
> + sizeof(struct pollfd))) == NULL) {
> + log_warn("could not resize pfd from %u -> %u"
> + " entries", pfd_elms, PFD_CONNECT_START +
> + connect_cnt);
> + fatalx("exiting");
> + }
> + pfd = newp;
> + pfd_elms = PFD_CONNECT_START + connect_cnt;
> + }
> + bzero(pfd, sizeof(struct pollfd) * pfd_elms);
>  
>   timeout = mrt_timeout(conf->mrt);
>  
> @@ -303,9 +330,17 @@ BROKEN   if (pledge("stdio rpath wpath cpa
>   set_pollfd(&pfd[PFD_PIPE_RDE], ibuf_rde);
>   set_pollfd(&pfd[PFD_PIPE_RTR], ibuf_rtr);
>  
> + npfd = PFD_CONNECT_START;
> + TAILQ_FOREACH(ce, &connect_queue, entry) {
> + pfd[npfd].fd = ce->fd;
> + pfd[npfd++].events = POLLOUT;
> + if (npfd > pfd_elms)
> + fatalx("polli pfd overflow");
> + }
> +
>   if (timeout < 0 || timeout > MAX_TIMEOUT)
>   timeout = MAX_TIMEOUT;
> - if (poll(pfd, POLL_MAX, timeout * 1000) == -1)
> + if (poll(pfd, npfd, timeout * 1000) == -1)
>   if (errno != EINTR) {
>   log_warn("poll error");
>   quit = 1;
> @@ -357,6 +392,10 @@ BROKEN   if (pledge("stdio rpath wpath cpa
>   }
>   }
>  
> + for (i = PFD_CONNECT_START; i < npfd; i++)
> + if (pfd[i].revents != 0)
> + bgpd_rtr_connect_done(pfd[i].fd, conf);
> +
>   if (reconfig) {
>   u_int   error;
>  
> @@ -1261,32 +1300,97 @@ imsg_send_sockets(struct imsgbuf *se, st
>  void
>  bgpd_rtr_connect(struct rtr_config *r)
>  {
> + struct connect_elm *ce;
>   struct sockaddr *sa;
>   sock

Re: macppc: add ld.script for kernel, ofwboot

2021-05-10 Thread Mark Kettenis
> Date: Mon, 10 May 2021 14:22:33 -0400
> From: George Koehler 
> 
> On Fri, 7 May 2021 10:31:55 +0200 (CEST)
> Mark Kettenis  wrote:
> 
> > Makes sense to me.  It seems ldd always seems to require a little bit
> > more coercion to produce non-standard binaries.  We use linker scripts
> > for the various EFI bootloaders as well.
> > 
> > ok kettenis@
> 
> My diff had an extra "pwd" in arch/macppc/stand/ofwboot/Makefile;
> I deleted the "pwd" before committing it.
> 
> > > -${PROG}: ${OBJS} ${LIBSA} ${LIBZ}
> > > - ${LD} -nopie -znorelro -N -X -Ttext ${RELOC} -e ${ENTRY} -o ${PROG} \
> > > +${PROG}: ${OBJS} ${LIBSA} ${LIBZ} ld.script
> > > + pwd
> > > + ${LD} -nopie -znorelro -N -X -T ${.CURDIR}/ld.script -o ${PROG} \
> > >   ${OBJS} ${LIBS}
> 
> >From my experiments with lld 10, I believe that macppc is almost ready
> to switch from ld.bfd to ld.lld.  I know of 2 other problems:
> 
>   1.  ports/lang/gcc/8 needs USE_LLD = No, because lld 10 can't link
>   C++ code from gcc.  (I have not yet checked lld 11.)  lld had no
>   problem with Fortran ports built by gcc.
> 
>   2.  All instances of -Wl,-relax or -Wl,--relax in src or ports must
>   be deleted, because it is an unknown option to lld, but lld can
>   link large binaries without the option.

Maybe just coordinate with Theo and the ports folks and move ahead.



Re: macppc: add ld.script for kernel, ofwboot

2021-05-10 Thread George Koehler
On Fri, 7 May 2021 10:31:55 +0200 (CEST)
Mark Kettenis  wrote:

> Makes sense to me.  It seems ldd always seems to require a little bit
> more coercion to produce non-standard binaries.  We use linker scripts
> for the various EFI bootloaders as well.
> 
> ok kettenis@

My diff had an extra "pwd" in arch/macppc/stand/ofwboot/Makefile;
I deleted the "pwd" before committing it.

> > -${PROG}: ${OBJS} ${LIBSA} ${LIBZ}
> > -   ${LD} -nopie -znorelro -N -X -Ttext ${RELOC} -e ${ENTRY} -o ${PROG} \
> > +${PROG}: ${OBJS} ${LIBSA} ${LIBZ} ld.script
> > +   pwd
> > +   ${LD} -nopie -znorelro -N -X -T ${.CURDIR}/ld.script -o ${PROG} \
> > ${OBJS} ${LIBS}

>From my experiments with lld 10, I believe that macppc is almost ready
to switch from ld.bfd to ld.lld.  I know of 2 other problems:

  1.  ports/lang/gcc/8 needs USE_LLD = No, because lld 10 can't link
  C++ code from gcc.  (I have not yet checked lld 11.)  lld had no
  problem with Fortran ports built by gcc.

  2.  All instances of -Wl,-relax or -Wl,--relax in src or ports must
  be deleted, because it is an unknown option to lld, but lld can
  link large binaries without the option.

--George



Re: patch: add support for RTLD_NODELETE

2021-05-10 Thread Mark Kettenis
> Date: Mon, 10 May 2021 09:00:37 +0200
> From: Sebastien Marie 
> Content-Type: text/plain; charset=us-ascii
> Content-Disposition: inline
> 
> Hi,
> 
> The following diff adds support for RTLD_NODELETE in ld.so(1).
> 
> It helps Qt programs which is using RTLD_NODELETE per default for
> loading plugins.
> 
> Without this patch, qgis (for example) is crashing systematically on
> exit. With it, it is fine.
> 
> If RTLD_NODELETE isn't POSIX, it is widely deployed: at least linux,
> freebsd, dragonfly, netbsd, solaris, illumos, apple, and fuchsia have
> it.
> 
> I built a full release on i386 with it and built several packages
> (most of dependencies of gqis which is including qt5).
> 
> One drawback will be for ports: a build with the diff might change
> built code as RTLD_NODELETE will be present in headers. So it might
> deserves a libc bump to correctly update installed ports.
> 
> Comments or OK ?

The code is ok kettenis@

However, I have a comment on the man page change...

> diff 393e7b397988bb6abe46729de1794883d2b9d5cf /home/semarie/repos/openbsd/src
> blob - 431065f3eab32299ad39766592e72a1765c8e8dc
> file + include/dlfcn.h
> --- include/dlfcn.h
> +++ include/dlfcn.h
> @@ -42,6 +42,7 @@
>  #define RTLD_GLOBAL  0x100
>  #define RTLD_LOCAL   0x000
>  #define RTLD_TRACE   0x200
> +#define RTLD_NODELETE0x400
>  
>  /*
>   * Special handle arguments for dlsym().
> blob - b8d5512e32bf50351b432a539106b1695a51f10f
> file + libexec/ld.so/dlfcn.c
> --- libexec/ld.so/dlfcn.c
> +++ libexec/ld.so/dlfcn.c
> @@ -54,7 +54,7 @@ dlopen(const char *libname, int flags)
>   int failed = 0;
>   int obj_flags;
>  
> - if (flags & ~(RTLD_TRACE|RTLD_LAZY|RTLD_NOW|RTLD_GLOBAL)) {
> + if (flags & ~(RTLD_TRACE|RTLD_LAZY|RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE)) 
> {
>   _dl_errno = DL_INVALID_MODE;
>   return NULL;
>   }
> @@ -89,6 +89,9 @@ dlopen(const char *libname, int flags)
>  
>   _dl_link_dlopen(object);
>  
> + if (flags & RTLD_NODELETE)
> + object->obj_flags |= DF_1_NODELETE;
> + 
>   if (OBJECT_REF_CNT(object) > 1) {
>   /* if opened but grpsym_vec has not been filled in */
>   if (object->grpsym_vec.len == 0)
> blob - afdf60ff428680eabc76f667442934511a8576fb
> file + share/man/man3/dlfcn.3
> --- share/man/man3/dlfcn.3
> +++ share/man/man3/dlfcn.3
> @@ -124,6 +124,19 @@ each of the above values together.
>  If an object was opened with RTLD_LOCAL and later opened with RTLD_GLOBAL,
>  then it is promoted to RTLD_GLOBAL.
>  .Pp
> +Additionally, the following flag may be ORed into the mode argument:
> +.Pp
> +.Bl -tag -width "RTLD_NODELETE" -compact -offset indent
> +.It Sy RTLD_NODELETE
> +Prevents unload of the loaded object on
> +.Fn dlclose .
> +The same behaviour may be requested by
> +.Fl z
> +.Cm nodelete
> +option of the static linker
> +.Xr ld 1 .
> +.El
> +.Pp

Should -z nodelete be documented here?  It is related but doesn't do
the same thing.  RTLD_NODELETE lets the process that loads a module
make the decision, whereas -z nodelete puts a marker in the module
itself.

A similar relation exists between RTLD_NOW and -z now, but we don't
document that.

I'm leaning towards leaving out the sentence about -z nodelete.

Cheers,

Mark



Re: patch: add support for RTLD_NODELETE

2021-05-10 Thread Mark Kettenis
> From: Stuart Henderson 
> Date: Mon, 10 May 2021 09:16:01 +0100
> 
> We are due a _SYSTEM_VERSION bump for the clang update, it can ride 
> alongside that

We should probably still do a libc minor bump for this since this adds
an interface.

> 
> -- 
>   Sent from a phone, apologies for poor formatting.
> On 10 May 2021 08:01:18 Sebastien Marie  wrote:
> 
> > Hi,
> >
> > The following diff adds support for RTLD_NODELETE in ld.so(1).
> >
> > It helps Qt programs which is using RTLD_NODELETE per default for
> > loading plugins.
> >
> > Without this patch, qgis (for example) is crashing systematically on
> > exit. With it, it is fine.
> >
> > If RTLD_NODELETE isn't POSIX, it is widely deployed: at least linux,
> > freebsd, dragonfly, netbsd, solaris, illumos, apple, and fuchsia have
> > it.
> >
> > I built a full release on i386 with it and built several packages
> > (most of dependencies of gqis which is including qt5).
> >
> > One drawback will be for ports: a build with the diff might change
> > built code as RTLD_NODELETE will be present in headers. So it might
> > deserves a libc bump to correctly update installed ports.
> >
> > Comments or OK ?
> > --
> > Sebastien Marie
> >
> >
> > diff 393e7b397988bb6abe46729de1794883d2b9d5cf 
> > /home/semarie/repos/openbsd/src
> > blob - 431065f3eab32299ad39766592e72a1765c8e8dc
> > file + include/dlfcn.h
> > --- include/dlfcn.h
> > +++ include/dlfcn.h
> > @@ -42,6 +42,7 @@
> > #define RTLD_GLOBAL 0x100
> > #define RTLD_LOCAL  0x000
> > #define RTLD_TRACE  0x200
> > +#define RTLD_NODELETE  0x400
> >
> > /*
> >  * Special handle arguments for dlsym().
> > blob - b8d5512e32bf50351b432a539106b1695a51f10f
> > file + libexec/ld.so/dlfcn.c
> > --- libexec/ld.so/dlfcn.c
> > +++ libexec/ld.so/dlfcn.c
> > @@ -54,7 +54,7 @@ dlopen(const char *libname, int flags)
> > int failed = 0;
> > int obj_flags;
> >
> > -   if (flags & ~(RTLD_TRACE|RTLD_LAZY|RTLD_NOW|RTLD_GLOBAL)) {
> > +   if (flags & ~(RTLD_TRACE|RTLD_LAZY|RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE)) 
> > {
> > _dl_errno = DL_INVALID_MODE;
> > return NULL;
> > }
> > @@ -89,6 +89,9 @@ dlopen(const char *libname, int flags)
> >
> > _dl_link_dlopen(object);
> >
> > +   if (flags & RTLD_NODELETE)
> > +   object->obj_flags |= DF_1_NODELETE;
> > +   
> > if (OBJECT_REF_CNT(object) > 1) {
> > /* if opened but grpsym_vec has not been filled in */
> > if (object->grpsym_vec.len == 0)
> > blob - afdf60ff428680eabc76f667442934511a8576fb
> > file + share/man/man3/dlfcn.3
> > --- share/man/man3/dlfcn.3
> > +++ share/man/man3/dlfcn.3
> > @@ -124,6 +124,19 @@ each of the above values together.
> > If an object was opened with RTLD_LOCAL and later opened with RTLD_GLOBAL,
> > then it is promoted to RTLD_GLOBAL.
> > .Pp
> > +Additionally, the following flag may be ORed into the mode argument:
> > +.Pp
> > +.Bl -tag -width "RTLD_NODELETE" -compact -offset indent
> > +.It Sy RTLD_NODELETE
> > +Prevents unload of the loaded object on
> > +.Fn dlclose .
> > +The same behaviour may be requested by
> > +.Fl z
> > +.Cm nodelete
> > +option of the static linker
> > +.Xr ld 1 .
> > +.El
> > +.Pp
> > The main executable's symbols are normally invisible to
> > .Fn dlopen
> > symbol resolution.
> 
> 



Re: bgpd, non-blocking rtr connect

2021-05-10 Thread Claudio Jeker
On Mon, May 03, 2021 at 05:37:36PM +0200, Claudio Jeker wrote:
> The RTR session was opened with a blocking connect() call. This is rather
> bad if the RTR peer does not exist since then bgpd will block until the
> connect timed out. This diff makes the connect() call non-blocking.
> With this connecting to non-existing RTR servers no longer blocks the main
> process.

Ping. I think this is a fairly important fix to make RTR usable.
 
-- 
:wq Claudio

Index: bgpd.c
===
RCS file: /cvs/src/usr.sbin/bgpd/bgpd.c,v
retrieving revision 1.235
diff -u -p -r1.235 bgpd.c
--- bgpd.c  3 May 2021 13:18:06 -   1.235
+++ bgpd.c  3 May 2021 15:33:20 -
@@ -50,6 +50,7 @@ static void   getsockpair(int [2]);
 intimsg_send_sockets(struct imsgbuf *, struct imsgbuf *,
struct imsgbuf *);
 void   bgpd_rtr_connect(struct rtr_config *);
+void   bgpd_rtr_connect_done(int, struct bgpd_config *);
 
 int cflags;
 volatile sig_atomic_t   mrtdump;
@@ -64,6 +65,16 @@ struct rib_names  ribnames = SIMPLEQ_HEA
 char   *cname;
 char   *rcname;
 
+struct connect_elm {
+   TAILQ_ENTRY(connect_elm)entry;
+   u_int32_t   id;
+   int fd;
+};
+
+TAILQ_HEAD( ,connect_elm)  connect_queue = \
+   TAILQ_HEAD_INITIALIZER(connect_queue);
+u_int  connect_cnt;
+
 void
 sighdlr(int sig)
 {
@@ -97,7 +108,7 @@ usage(void)
 #define PFD_PIPE_RTR   2
 #define PFD_SOCK_ROUTE 3
 #define PFD_SOCK_PFKEY 4
-#define POLL_MAX   5
+#define PFD_CONNECT_START  5
 #define MAX_TIMEOUT3600
 
 int cmd_opts;
@@ -109,11 +120,13 @@ main(int argc, char *argv[])
enum bgpd_processproc = PROC_MAIN;
struct rde_rib  *rr;
struct peer *p;
-   struct pollfdpfd[POLL_MAX];
+   struct pollfd   *pfd = NULL;
+   struct connect_elm  *ce;
time_t   timeout;
pid_tse_pid = 0, rde_pid = 0, rtr_pid = 0, pid;
char*conffile;
char*saved_argv0;
+   u_intpfd_elms = 0, npfd, i;
int  debug = 0;
int  rfd, keyfd;
int  ch, status;
@@ -289,7 +302,21 @@ BROKEN if (pledge("stdio rpath wpath cpa
quit = 1;
 
while (quit == 0) {
-   bzero(pfd, sizeof(pfd));
+   if (pfd_elms < PFD_CONNECT_START + connect_cnt) {
+   struct pollfd *newp;
+
+   if ((newp = reallocarray(pfd,
+   PFD_CONNECT_START + connect_cnt,
+   sizeof(struct pollfd))) == NULL) {
+   log_warn("could not resize pfd from %u -> %u"
+   " entries", pfd_elms, PFD_CONNECT_START +
+   connect_cnt);
+   fatalx("exiting");
+   }
+   pfd = newp;
+   pfd_elms = PFD_CONNECT_START + connect_cnt;
+   }
+   bzero(pfd, sizeof(struct pollfd) * pfd_elms);
 
timeout = mrt_timeout(conf->mrt);
 
@@ -303,9 +330,17 @@ BROKEN if (pledge("stdio rpath wpath cpa
set_pollfd(&pfd[PFD_PIPE_RDE], ibuf_rde);
set_pollfd(&pfd[PFD_PIPE_RTR], ibuf_rtr);
 
+   npfd = PFD_CONNECT_START;
+   TAILQ_FOREACH(ce, &connect_queue, entry) {
+   pfd[npfd].fd = ce->fd;
+   pfd[npfd++].events = POLLOUT;
+   if (npfd > pfd_elms)
+   fatalx("polli pfd overflow");
+   }
+
if (timeout < 0 || timeout > MAX_TIMEOUT)
timeout = MAX_TIMEOUT;
-   if (poll(pfd, POLL_MAX, timeout * 1000) == -1)
+   if (poll(pfd, npfd, timeout * 1000) == -1)
if (errno != EINTR) {
log_warn("poll error");
quit = 1;
@@ -357,6 +392,10 @@ BROKEN if (pledge("stdio rpath wpath cpa
}
}
 
+   for (i = PFD_CONNECT_START; i < npfd; i++)
+   if (pfd[i].revents != 0)
+   bgpd_rtr_connect_done(pfd[i].fd, conf);
+
if (reconfig) {
u_int   error;
 
@@ -1261,32 +1300,97 @@ imsg_send_sockets(struct imsgbuf *se, st
 void
 bgpd_rtr_connect(struct rtr_config *r)
 {
+   struct connect_elm *ce;
struct sockaddr *sa;
socklen_t len;
-   int fd;
 
-   /* XXX should 

Re: patch: add support for RTLD_NODELETE

2021-05-10 Thread Stuart Henderson
We are due a _SYSTEM_VERSION bump for the clang update, it can ride 
alongside that


--
 Sent from a phone, apologies for poor formatting.
On 10 May 2021 08:01:18 Sebastien Marie  wrote:


Hi,

The following diff adds support for RTLD_NODELETE in ld.so(1).

It helps Qt programs which is using RTLD_NODELETE per default for
loading plugins.

Without this patch, qgis (for example) is crashing systematically on
exit. With it, it is fine.

If RTLD_NODELETE isn't POSIX, it is widely deployed: at least linux,
freebsd, dragonfly, netbsd, solaris, illumos, apple, and fuchsia have
it.

I built a full release on i386 with it and built several packages
(most of dependencies of gqis which is including qt5).

One drawback will be for ports: a build with the diff might change
built code as RTLD_NODELETE will be present in headers. So it might
deserves a libc bump to correctly update installed ports.

Comments or OK ?
--
Sebastien Marie


diff 393e7b397988bb6abe46729de1794883d2b9d5cf /home/semarie/repos/openbsd/src
blob - 431065f3eab32299ad39766592e72a1765c8e8dc
file + include/dlfcn.h
--- include/dlfcn.h
+++ include/dlfcn.h
@@ -42,6 +42,7 @@
#define RTLD_GLOBAL 0x100
#define RTLD_LOCAL  0x000
#define RTLD_TRACE  0x200
+#define RTLD_NODELETE  0x400

/*
 * Special handle arguments for dlsym().
blob - b8d5512e32bf50351b432a539106b1695a51f10f
file + libexec/ld.so/dlfcn.c
--- libexec/ld.so/dlfcn.c
+++ libexec/ld.so/dlfcn.c
@@ -54,7 +54,7 @@ dlopen(const char *libname, int flags)
int failed = 0;
int obj_flags;

-   if (flags & ~(RTLD_TRACE|RTLD_LAZY|RTLD_NOW|RTLD_GLOBAL)) {
+   if (flags & ~(RTLD_TRACE|RTLD_LAZY|RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE)) 
{
_dl_errno = DL_INVALID_MODE;
return NULL;
}
@@ -89,6 +89,9 @@ dlopen(const char *libname, int flags)

_dl_link_dlopen(object);

+   if (flags & RTLD_NODELETE)
+   object->obj_flags |= DF_1_NODELETE;
+   
if (OBJECT_REF_CNT(object) > 1) {
/* if opened but grpsym_vec has not been filled in */
if (object->grpsym_vec.len == 0)
blob - afdf60ff428680eabc76f667442934511a8576fb
file + share/man/man3/dlfcn.3
--- share/man/man3/dlfcn.3
+++ share/man/man3/dlfcn.3
@@ -124,6 +124,19 @@ each of the above values together.
If an object was opened with RTLD_LOCAL and later opened with RTLD_GLOBAL,
then it is promoted to RTLD_GLOBAL.
.Pp
+Additionally, the following flag may be ORed into the mode argument:
+.Pp
+.Bl -tag -width "RTLD_NODELETE" -compact -offset indent
+.It Sy RTLD_NODELETE
+Prevents unload of the loaded object on
+.Fn dlclose .
+The same behaviour may be requested by
+.Fl z
+.Cm nodelete
+option of the static linker
+.Xr ld 1 .
+.El
+.Pp
The main executable's symbols are normally invisible to
.Fn dlopen
symbol resolution.




patch: add support for RTLD_NODELETE

2021-05-10 Thread Sebastien Marie
Hi,

The following diff adds support for RTLD_NODELETE in ld.so(1).

It helps Qt programs which is using RTLD_NODELETE per default for
loading plugins.

Without this patch, qgis (for example) is crashing systematically on
exit. With it, it is fine.

If RTLD_NODELETE isn't POSIX, it is widely deployed: at least linux,
freebsd, dragonfly, netbsd, solaris, illumos, apple, and fuchsia have
it.

I built a full release on i386 with it and built several packages
(most of dependencies of gqis which is including qt5).

One drawback will be for ports: a build with the diff might change
built code as RTLD_NODELETE will be present in headers. So it might
deserves a libc bump to correctly update installed ports.

Comments or OK ?
-- 
Sebastien Marie


diff 393e7b397988bb6abe46729de1794883d2b9d5cf /home/semarie/repos/openbsd/src
blob - 431065f3eab32299ad39766592e72a1765c8e8dc
file + include/dlfcn.h
--- include/dlfcn.h
+++ include/dlfcn.h
@@ -42,6 +42,7 @@
 #define RTLD_GLOBAL0x100
 #define RTLD_LOCAL 0x000
 #define RTLD_TRACE 0x200
+#define RTLD_NODELETE  0x400
 
 /*
  * Special handle arguments for dlsym().
blob - b8d5512e32bf50351b432a539106b1695a51f10f
file + libexec/ld.so/dlfcn.c
--- libexec/ld.so/dlfcn.c
+++ libexec/ld.so/dlfcn.c
@@ -54,7 +54,7 @@ dlopen(const char *libname, int flags)
int failed = 0;
int obj_flags;
 
-   if (flags & ~(RTLD_TRACE|RTLD_LAZY|RTLD_NOW|RTLD_GLOBAL)) {
+   if (flags & ~(RTLD_TRACE|RTLD_LAZY|RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE)) 
{
_dl_errno = DL_INVALID_MODE;
return NULL;
}
@@ -89,6 +89,9 @@ dlopen(const char *libname, int flags)
 
_dl_link_dlopen(object);
 
+   if (flags & RTLD_NODELETE)
+   object->obj_flags |= DF_1_NODELETE;
+   
if (OBJECT_REF_CNT(object) > 1) {
/* if opened but grpsym_vec has not been filled in */
if (object->grpsym_vec.len == 0)
blob - afdf60ff428680eabc76f667442934511a8576fb
file + share/man/man3/dlfcn.3
--- share/man/man3/dlfcn.3
+++ share/man/man3/dlfcn.3
@@ -124,6 +124,19 @@ each of the above values together.
 If an object was opened with RTLD_LOCAL and later opened with RTLD_GLOBAL,
 then it is promoted to RTLD_GLOBAL.
 .Pp
+Additionally, the following flag may be ORed into the mode argument:
+.Pp
+.Bl -tag -width "RTLD_NODELETE" -compact -offset indent
+.It Sy RTLD_NODELETE
+Prevents unload of the loaded object on
+.Fn dlclose .
+The same behaviour may be requested by
+.Fl z
+.Cm nodelete
+option of the static linker
+.Xr ld 1 .
+.El
+.Pp
 The main executable's symbols are normally invisible to
 .Fn dlopen
 symbol resolution.