On Thu, Jan 07, 2021 at 11:51:02AM -0000, Miod Vallat wrote: > > >> Indeed. Wrappinge the mutex operations in msgbuf_putchar with if (!cold) > >> makes the kernel boot again. > > > > Here is a diff for that. > > After a bit more thinking, it might be worth introduce a > msgbuf_putchar_unlocked() routine for the inner part only, and have > initmsgbuf() use it, since: > - it has made sure the magic value test will suceed. > - this is the only use of msgbuf_putchar() on sparc64 until the proper > curcpu mappings are set up; all output from pmap_bootstrap() carefully > uses the prom routines (and do not end up in the message buffer).
Here is a diff. However, are there any other similar fallouts outside this initmsgbuf() situation? Index: kern/subr_log.c =================================================================== RCS file: src/sys/kern/subr_log.c,v retrieving revision 1.70 diff -u -p -r1.70 subr_log.c --- kern/subr_log.c 25 Dec 2020 12:59:52 -0000 1.70 +++ kern/subr_log.c 7 Jan 2021 13:21:45 -0000 @@ -109,6 +109,7 @@ const struct filterops logread_filtops = int dosendsyslog(struct proc *, const char *, size_t, int, enum uio_seg); void logtick(void *); size_t msgbuf_getlen(struct msgbuf *); +void msgbuf_putchar_locked(struct msgbuf *, const char); void initmsgbuf(caddr_t buf, size_t bufsize) @@ -137,9 +138,13 @@ initmsgbuf(caddr_t buf, size_t bufsize) mbp->msg_bufs = new_bufs; } - /* Always start new buffer data on a new line. */ + /* + * Always start new buffer data on a new line. + * Avoid using log_mtx because mutexes do not work during early boot + * on some architectures. + */ if (mbp->msg_bufx > 0 && mbp->msg_bufc[mbp->msg_bufx - 1] != '\n') - msgbuf_putchar(msgbufp, '\n'); + msgbuf_putchar_locked(mbp, '\n'); /* mark it as ready for use. */ msgbufmapped = 1; @@ -162,6 +167,13 @@ msgbuf_putchar(struct msgbuf *mbp, const return; mtx_enter(&log_mtx); + msgbuf_putchar_locked(mbp, c); + mtx_leave(&log_mtx); +} + +void +msgbuf_putchar_locked(struct msgbuf *mbp, const char c) +{ mbp->msg_bufc[mbp->msg_bufx++] = c; if (mbp->msg_bufx < 0 || mbp->msg_bufx >= mbp->msg_bufs) mbp->msg_bufx = 0; @@ -171,7 +183,6 @@ msgbuf_putchar(struct msgbuf *mbp, const mbp->msg_bufr = 0; mbp->msg_bufd++; } - mtx_leave(&log_mtx); } size_t