From d56bde27915178e4630b524b83beefa00e8b3cca Mon Sep 17 00:00:00 2001 From: purplerain Date: Thu, 1 Aug 2024 19:31:36 +0000 Subject: [PATCH] sync with OpenBSD -current --- bin/cat/cat.1 | 6 +-- bin/chmod/chgrp.1 | 6 +-- bin/chmod/chmod.1 | 10 ++-- bin/chmod/chown.8 | 6 +-- .../OpenBSDKernel/ProcessOpenBSDKernel.cpp | 9 ++++ lib/libsndio/sndio.pc | 2 +- lib/libz/deflate.c | 14 +++++- lib/libz/deflate.h | 3 ++ lib/libz/trees.c | 2 + lib/libz/zconf.h | 1 + lib/libz/zlib.h | 12 +++++ sys/arch/arm64/stand/efiboot/efiboot.c | 4 +- sys/dev/pv/if_vio.c | 4 +- sys/dev/pv/vioblk.c | 6 +-- sys/dev/pv/viocon.c | 4 +- sys/dev/pv/viogpu.c | 19 +++---- sys/dev/pv/virtio.c | 50 ++++++++++++++++--- sys/kern/uipc_socket.c | 8 +-- sys/lib/libz/deflate.c | 14 +++++- sys/lib/libz/deflate.h | 3 ++ sys/lib/libz/trees.c | 2 + sys/lib/libz/zconf.h | 1 + sys/lib/libz/zlib.h | 12 +++++ sys/lib/libz/zutil.h | 2 +- usr.bin/sndiod/sock.c | 6 +-- usr.sbin/npppd/npppd/npppd.c | 6 +-- usr.sbin/radiusd/radiusd_ipcp.c | 4 +- 27 files changed, 162 insertions(+), 54 deletions(-) diff --git a/bin/cat/cat.1 b/bin/cat/cat.1 index e582167c5..47f37d109 100644 --- a/bin/cat/cat.1 +++ b/bin/cat/cat.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: cat.1,v 1.36 2016/07/10 00:15:39 tedu Exp $ +.\" $OpenBSD: cat.1,v 1.37 2024/08/01 14:08:07 jmc Exp $ .\" $NetBSD: cat.1,v 1.12 1995/09/27 05:38:55 cgd Exp $ .\" .\" Copyright (c) 1989, 1990, 1993 @@ -33,7 +33,7 @@ .\" .\" @(#)cat.1 8.3 (Berkeley) 5/2/95 .\" -.Dd $Mdocdate: July 10 2016 $ +.Dd $Mdocdate: August 1 2024 $ .Dt CAT 1 .Os .Sh NAME @@ -157,7 +157,7 @@ operand. The .Nm utility is compliant with the -.St -p1003.1-2008 +.St -p1003.1-2024 specification. .Pp The flags diff --git a/bin/chmod/chgrp.1 b/bin/chmod/chgrp.1 index 47363ad7f..7be0c70fb 100644 --- a/bin/chmod/chgrp.1 +++ b/bin/chmod/chgrp.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: chgrp.1,v 1.18 2019/09/02 21:18:41 deraadt Exp $ +.\" $OpenBSD: chgrp.1,v 1.19 2024/08/01 14:08:38 jmc Exp $ .\" .\" Copyright (c) 1983, 1990, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -32,7 +32,7 @@ .\" .\" from: @(#)chgrp.1 8.3 (Berkeley) 3/31/94 .\" -.Dd $Mdocdate: September 2 2019 $ +.Dd $Mdocdate: August 1 2024 $ .Dt CHGRP 1 .Os .Sh NAME @@ -136,5 +136,5 @@ group ID file The .Nm utility is compliant with the -.St -p1003.1-2008 +.St -p1003.1-2024 specification. diff --git a/bin/chmod/chmod.1 b/bin/chmod/chmod.1 index 64cdd1f1d..077b56794 100644 --- a/bin/chmod/chmod.1 +++ b/bin/chmod/chmod.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: chmod.1,v 1.43 2019/09/02 21:18:41 deraadt Exp $ +.\" $OpenBSD: chmod.1,v 1.44 2024/08/01 14:30:17 jmc Exp $ .\" $NetBSD: chmod.1,v 1.8 1995/03/21 09:02:07 cgd Exp $ .\" .\" Copyright (c) 1989, 1990, 1993, 1994 @@ -33,7 +33,7 @@ .\" .\" @(#)chmod.1 8.4 (Berkeley) 3/31/94 .\" -.Dd $Mdocdate: September 2 2019 $ +.Dd $Mdocdate: August 1 2024 $ .Dt CHMOD 1 .Os .Sh NAME @@ -363,17 +363,17 @@ Set the group bits equal to the user bits, but clear the group write bit: The .Nm utility is compliant with the -.St -p1003.1-2008 +.St -p1003.1-2024 specification. .Pp The flags -.Op Fl HLP +.Op Fl HhLP are extensions to that specification. .Pp The .Sq t perm symbol (sticky bit) is marked by -.St -p1003.1-2008 +.St -p1003.1-2024 as being an X/Open System Interfaces option. diff --git a/bin/chmod/chown.8 b/bin/chmod/chown.8 index 949892e61..6f3a245eb 100644 --- a/bin/chmod/chown.8 +++ b/bin/chmod/chown.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: chown.8,v 1.23 2019/09/06 19:25:08 schwarze Exp $ +.\" $OpenBSD: chown.8,v 1.24 2024/08/01 14:44:34 jmc Exp $ .\" .\" Copyright (c) 1990, 1991, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" from: @(#)chown.8 8.3 (Berkeley) 3/31/94 .\" -.Dd $Mdocdate: September 6 2019 $ +.Dd $Mdocdate: August 1 2024 $ .Dt CHOWN 8 .Os .Sh NAME @@ -147,7 +147,7 @@ Only the superuser is permitted to change the owner of a file. The .Nm utility is compliant with the -.St -p1003.1-2008 +.St -p1003.1-2024 specification. .Pp The ability to specify diff --git a/gnu/llvm/lldb/source/Plugins/Process/OpenBSDKernel/ProcessOpenBSDKernel.cpp b/gnu/llvm/lldb/source/Plugins/Process/OpenBSDKernel/ProcessOpenBSDKernel.cpp index 57724ca9e..e6b0a3626 100644 --- a/gnu/llvm/lldb/source/Plugins/Process/OpenBSDKernel/ProcessOpenBSDKernel.cpp +++ b/gnu/llvm/lldb/source/Plugins/Process/OpenBSDKernel/ProcessOpenBSDKernel.cpp @@ -19,6 +19,7 @@ #define _KERNEL #include #include +#include #undef _KERNEL #endif @@ -60,6 +61,14 @@ lldb::ProcessSP ProcessOpenBSDKernel::CreateInstance(lldb::TargetSP target_sp, ModuleSP executable = target_sp->GetExecutableModule(); if (crash_file && !can_connect && executable) { #if defined(__OpenBSD__) + char buf[4]; + FILE *fp = fopen(crash_file->GetPath().c_str(), "r"); + if (fp == NULL) + return nullptr; + size_t r = fread(buf, 1, sizeof(buf), fp); + fclose(fp); + if (r != sizeof(buf) || memcmp(buf, ELFMAG, sizeof(buf)) == 0) + return nullptr; kvm_t *kvm = kvm_open(executable->GetFileSpec().GetPath().c_str(), crash_file->GetPath().c_str(), nullptr, O_RDONLY, nullptr); diff --git a/lib/libsndio/sndio.pc b/lib/libsndio/sndio.pc index 71d76eee9..87526ce2d 100644 --- a/lib/libsndio/sndio.pc +++ b/lib/libsndio/sndio.pc @@ -5,7 +5,7 @@ includedir=${prefix}/include Name: sndio Description: sndio library -Version: 1.9.0 +Version: 1.10.0 Requires: Libs: -L${libdir} -lsndio Cflags: -I${includedir} diff --git a/lib/libz/deflate.c b/lib/libz/deflate.c index 7ab6c9942..fd817eb11 100644 --- a/lib/libz/deflate.c +++ b/lib/libz/deflate.c @@ -715,6 +715,14 @@ int ZEXPORT deflatePending(z_streamp strm, unsigned *pending, int *bits) { return Z_OK; } +/* ========================================================================= */ +int ZEXPORT deflateUsed(z_streamp strm, int *bits) { + if (deflateStateCheck(strm)) return Z_STREAM_ERROR; + if (bits != Z_NULL) + *bits = strm->state->bi_used; + return Z_OK; +} + /* ========================================================================= */ int ZEXPORT deflatePrime(z_streamp strm, int bits, int value) { deflate_state *s; @@ -1742,8 +1750,10 @@ local block_state deflate_stored(deflate_state *s, int flush) { s->high_water = s->strstart; /* If the last block was written to next_out, then done. */ - if (last) + if (last) { + s->bi_used = 8; return finish_done; + } /* If flushing and all input has been consumed, then done. */ if (flush != Z_NO_FLUSH && flush != Z_FINISH && @@ -1795,6 +1805,8 @@ local block_state deflate_stored(deflate_state *s, int flush) { } /* We've done all we can with the available input and output. */ + if (last) + s->bi_used = 8; return last ? finish_started : need_more; } diff --git a/lib/libz/deflate.h b/lib/libz/deflate.h index 8182a2604..ad230ef73 100644 --- a/lib/libz/deflate.h +++ b/lib/libz/deflate.h @@ -269,6 +269,9 @@ typedef struct internal_state { /* Number of valid bits in bi_buf. All bits above the last valid bit * are always zero. */ + int bi_used; + /* Last number of used bits when going to a byte boundary. + */ ulg high_water; /* High water mark offset in window for initialized bytes -- bytes above diff --git a/lib/libz/trees.c b/lib/libz/trees.c index cba0708b6..7ce629afb 100644 --- a/lib/libz/trees.c +++ b/lib/libz/trees.c @@ -182,6 +182,7 @@ local void bi_windup(deflate_state *s) { } else if (s->bi_valid > 0) { put_byte(s, (Byte)s->bi_buf); } + s->bi_used = ((s->bi_valid - 1) & 7) + 1; s->bi_buf = 0; s->bi_valid = 0; #ifdef ZLIB_DEBUG @@ -464,6 +465,7 @@ void ZLIB_INTERNAL _tr_init(deflate_state *s) { s->bi_buf = 0; s->bi_valid = 0; + s->bi_used = 0; #ifdef ZLIB_DEBUG s->compressed_len = 0L; s->bits_sent = 0L; diff --git a/lib/libz/zconf.h b/lib/libz/zconf.h index 99066348c..ed924d081 100644 --- a/lib/libz/zconf.h +++ b/lib/libz/zconf.h @@ -57,6 +57,7 @@ # define deflateSetDictionary z_deflateSetDictionary # define deflateSetHeader z_deflateSetHeader # define deflateTune z_deflateTune +# define deflateUsed z_deflateUsed # define deflate_copyright z_deflate_copyright # define get_crc_table z_get_crc_table # ifndef Z_SOLO diff --git a/lib/libz/zlib.h b/lib/libz/zlib.h index 5498b5420..ad33815f1 100644 --- a/lib/libz/zlib.h +++ b/lib/libz/zlib.h @@ -791,6 +791,18 @@ ZEXTERN int ZEXPORT deflatePending(z_streamp strm, stream state was inconsistent. */ +ZEXTERN int ZEXPORT deflateUsed(z_streamp strm, + int *bits); +/* + deflateUsed() returns in *bits the most recent number of deflate bits used + in the last byte when flushing to a byte boundary. The result is in 1..8, or + 0 if there has not yet been a flush. This helps determine the location of + the last bit of a deflate stream. + + deflateUsed returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. + */ + ZEXTERN int ZEXPORT deflatePrime(z_streamp strm, int bits, int value); diff --git a/sys/arch/arm64/stand/efiboot/efiboot.c b/sys/arch/arm64/stand/efiboot/efiboot.c index 044bf6e52..7d64c7f5d 100644 --- a/sys/arch/arm64/stand/efiboot/efiboot.c +++ b/sys/arch/arm64/stand/efiboot/efiboot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: efiboot.c,v 1.57 2024/07/10 18:46:42 patrick Exp $ */ +/* $OpenBSD: efiboot.c,v 1.58 2024/08/01 11:53:03 mglocker Exp $ */ /* * Copyright (c) 2015 YASUOKA Masahiko @@ -1123,6 +1123,8 @@ struct smbios_dtb { "qcom/sc8280xp-lenovo-thinkpad-x13s.dtb" }, { "LENOVO", "83ED", "qcom/x1e80100-lenovo-yoga-slim7x.dtb" }, + { "SAMSUNG", "Galaxy Book4 Edge", + "qcom/x1e80100-samsung-galaxy-book4-edge.dtb" }, }; void * diff --git a/sys/dev/pv/if_vio.c b/sys/dev/pv/if_vio.c index eee59d812..e6168ca38 100644 --- a/sys/dev/pv/if_vio.c +++ b/sys/dev/pv/if_vio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_vio.c,v 1.44 2024/07/26 07:55:23 sf Exp $ */ +/* $OpenBSD: if_vio.c,v 1.45 2024/08/01 11:13:19 sf Exp $ */ /* * Copyright (c) 2012 Stefan Fritsch, Alexander Fiveg. @@ -1303,7 +1303,7 @@ vio_txtick(void *arg) { struct virtqueue *vq = arg; int s = splnet(); - vio_tx_intr(vq); + virtio_check_vq(vq->vq_owner, vq); splx(s); } diff --git a/sys/dev/pv/vioblk.c b/sys/dev/pv/vioblk.c index 3be22b930..108309f4a 100644 --- a/sys/dev/pv/vioblk.c +++ b/sys/dev/pv/vioblk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vioblk.c,v 1.40 2024/07/26 07:55:23 sf Exp $ */ +/* $OpenBSD: vioblk.c,v 1.41 2024/08/01 11:13:19 sf Exp $ */ /* * Copyright (c) 2012 Stefan Fritsch. @@ -375,7 +375,7 @@ vioblk_reset(struct vioblk_softc *sc) virtio_reset(sc->sc_virtio); /* finish requests that have been completed */ - vioblk_vq_done(&sc->sc_vq[0]); + virtio_check_vq(sc->sc_virtio, &sc->sc_vq[0]); /* abort all remaining requests */ for (i = 0; i < sc->sc_nreqs; i++) { @@ -535,7 +535,7 @@ vioblk_scsi_cmd(struct scsi_xfer *xs) if (!ISSET(xs->flags, SCSI_POLL)) { /* check if some xfers are done: */ if (sc->sc_queued > 1) - vioblk_vq_done(vq); + virtio_check_vq(sc->sc_virtio, vq); splx(s); return; } diff --git a/sys/dev/pv/viocon.c b/sys/dev/pv/viocon.c index e81bc9520..409922285 100644 --- a/sys/dev/pv/viocon.c +++ b/sys/dev/pv/viocon.c @@ -1,4 +1,4 @@ -/* $OpenBSD: viocon.c,v 1.12 2024/06/26 01:40:49 jsg Exp $ */ +/* $OpenBSD: viocon.c,v 1.13 2024/08/01 11:13:19 sf Exp $ */ /* * Copyright (c) 2013-2015 Stefan Fritsch @@ -463,7 +463,7 @@ vioconhwiflow(struct tty *tp, int stop) virtio_stop_vq_intr(vp->vp_sc->sc_virtio, vp->vp_rx); } else { virtio_start_vq_intr(vp->vp_sc->sc_virtio, vp->vp_rx); - softintr_schedule(vp->vp_si); + virtio_check_vq(vp->vp_sc->sc_virtio, vp->vp_rx); } splx(s); return 1; diff --git a/sys/dev/pv/viogpu.c b/sys/dev/pv/viogpu.c index 81844e393..aa9f1596e 100644 --- a/sys/dev/pv/viogpu.c +++ b/sys/dev/pv/viogpu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: viogpu.c,v 1.6 2024/05/24 10:05:55 jsg Exp $ */ +/* $OpenBSD: viogpu.c,v 1.7 2024/08/01 11:13:19 sf Exp $ */ /* * Copyright (c) 2021-2023 joshua stein @@ -42,7 +42,7 @@ struct viogpu_softc; int viogpu_match(struct device *, void *, void *); void viogpu_attach(struct device *, struct device *, void *); int viogpu_send_cmd(struct viogpu_softc *, void *, size_t, void *, size_t); -int viogpu_vq_wait(struct virtqueue *vq); +int viogpu_vq_done(struct virtqueue *vq); void viogpu_rx_soft(void *arg); int viogpu_get_display_info(struct viogpu_softc *); @@ -178,7 +178,7 @@ viogpu_attach(struct device *parent, struct device *self, void *aux) printf(": alloc_vq failed\n"); return; } - sc->sc_vqs[VQCTRL].vq_done = viogpu_vq_wait; + sc->sc_vqs[VQCTRL].vq_done = viogpu_vq_done; if (virtio_alloc_vq(vsc, &sc->sc_vqs[VQCURS], VQCURS, NBPG, 1, "cursor")) { @@ -211,6 +211,8 @@ viogpu_attach(struct device *parent, struct device *self, void *aux) goto unmap; } + virtio_set_status(vsc, VIRTIO_CONFIG_DEVICE_STATUS_DRIVER_OK); + if (viogpu_get_display_info(sc) != 0) goto unmap; @@ -230,8 +232,6 @@ viogpu_attach(struct device *parent, struct device *self, void *aux) sc->sc_fb_dma_kva, sc->sc_fb_dma_size, NULL, BUS_DMA_NOWAIT) != 0) goto fb_unmap; - virtio_set_status(vsc, VIRTIO_CONFIG_DEVICE_STATUS_DRIVER_OK); - if (viogpu_create_2d(sc, 1, sc->sc_fb_width, sc->sc_fb_height) != 0) goto fb_unmap; @@ -325,14 +325,14 @@ viogpu_repaint(void *arg) } int -viogpu_vq_wait(struct virtqueue *vq) +viogpu_vq_done(struct virtqueue *vq) { struct virtio_softc *vsc = vq->vq_owner; struct viogpu_softc *sc = (struct viogpu_softc *)vsc->sc_child; int slot, len; - while (virtio_dequeue(vsc, vq, &slot, &len) != 0) - ; + if (virtio_dequeue(vsc, vq, &slot, &len) != 0) + return 0; bus_dmamap_sync(vsc->sc_dmat, sc->sc_dma_map, 0, sc->sc_dma_size, BUS_DMASYNC_POSTREAD); @@ -402,7 +402,8 @@ viogpu_send_cmd(struct viogpu_softc *sc, void *cmd, size_t cmd_size, void *ret, virtio_enqueue_p(vq, slot, sc->sc_dma_map, cmd_size, ret_size, 0); virtio_enqueue_commit(vsc, vq, slot, 1); - viogpu_vq_wait(vq); + while (virtio_check_vq(vsc, vq) == 0) + ; bus_dmamap_sync(vsc->sc_dmat, sc->sc_dma_map, 0, cmd_size, BUS_DMASYNC_POSTWRITE); diff --git a/sys/dev/pv/virtio.c b/sys/dev/pv/virtio.c index 7386d0ca1..4c834b67d 100644 --- a/sys/dev/pv/virtio.c +++ b/sys/dev/pv/virtio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: virtio.c,v 1.28 2024/07/26 07:55:23 sf Exp $ */ +/* $OpenBSD: virtio.c,v 1.29 2024/08/01 11:13:19 sf Exp $ */ /* $NetBSD: virtio.c,v 1.3 2011/11/02 23:05:52 njoly Exp $ */ /* @@ -185,6 +185,9 @@ virtio_reinit_end(struct virtio_softc *sc) /* * dmamap sync operations for a virtqueue. + * + * XXX These should be more fine grained. Syncing the whole ring if we + * XXX only need a few bytes is inefficient if we use bounce buffers. */ static inline void vq_sync_descs(struct virtio_softc *sc, struct virtqueue *vq, int ops) @@ -202,6 +205,15 @@ vq_sync_aring(struct virtio_softc *sc, struct virtqueue *vq, int ops) ops); } +static inline void +vq_sync_aring_used_event(struct virtio_softc *sc, struct virtqueue *vq, int ops) +{ + bus_dmamap_sync(sc->sc_dmat, vq->vq_dmamap, vq->vq_availoffset + + offsetof(struct vring_avail, ring) + vq->vq_num * sizeof(uint16_t), + sizeof(uint16_t), ops); +} + + static inline void vq_sync_uring(struct virtio_softc *sc, struct virtqueue *vq, int ops) { @@ -210,6 +222,16 @@ vq_sync_uring(struct virtio_softc *sc, struct virtqueue *vq, int ops) sizeof(struct vring_used_elem), ops); } +static inline void +vq_sync_uring_avail_event(struct virtio_softc *sc, struct virtqueue *vq, int ops) +{ + bus_dmamap_sync(sc->sc_dmat, vq->vq_dmamap, + vq->vq_usedoffset + offsetof(struct vring_used, ring) + + vq->vq_num * sizeof(struct vring_used_elem), sizeof(uint16_t), + ops); +} + + static inline void vq_sync_indirect(struct virtio_softc *sc, struct virtqueue *vq, int slot, int ops) @@ -672,11 +694,13 @@ virtio_enqueue_p(struct virtqueue *vq, int slot, bus_dmamap_t dmamap, static void publish_avail_idx(struct virtio_softc *sc, struct virtqueue *vq) { + /* first make sure the avail ring entries are visible to the device */ vq_sync_aring(sc, vq, BUS_DMASYNC_PREWRITE); virtio_membar_producer(); vq->vq_avail->idx = vq->vq_avail_idx; - vq_sync_aring(sc, vq, BUS_DMASYNC_POSTWRITE); + /* make the avail idx visible to the device */ + vq_sync_aring(sc, vq, BUS_DMASYNC_PREWRITE); vq->vq_queued = 1; } @@ -706,6 +730,7 @@ notify: publish_avail_idx(sc, vq); virtio_membar_sync(); + vq_sync_uring_avail_event(sc, vq, BUS_DMASYNC_POSTREAD); t = VQ_AVAIL_EVENT(vq) + 1; if ((uint16_t)(n - t) < (uint16_t)(n - o)) sc->sc_ops->kick(sc, vq->vq_index); @@ -713,6 +738,7 @@ notify: publish_avail_idx(sc, vq); virtio_membar_sync(); + vq_sync_uring(sc, vq, BUS_DMASYNC_POSTREAD); if (!(vq->vq_used->flags & VRING_USED_F_NO_NOTIFY)) sc->sc_ops->kick(sc, vq->vq_index); } @@ -781,8 +807,10 @@ virtio_enqueue_trim(struct virtqueue *vq, int slot, int nsegs) * Dequeue a request. */ /* - * dequeue: dequeue a request from uring; dmamap_sync for uring is - * already done in the interrupt handler. + * dequeue: dequeue a request from uring; bus_dmamap_sync for uring must + * already have been done, usually by virtio_check_vq() + * in the interrupt handler. This means that polling virtio_dequeue() + * repeatedly until it returns 0 does not work. */ int virtio_dequeue(struct virtio_softc *sc, struct virtqueue *vq, @@ -797,6 +825,7 @@ virtio_dequeue(struct virtio_softc *sc, struct virtqueue *vq, usedidx &= vq->vq_mask; virtio_membar_consumer(); + vq_sync_uring(sc, vq, BUS_DMASYNC_POSTREAD); slot = vq->vq_used->ring[usedidx].id; qe = &vq->vq_entries[slot]; @@ -852,7 +881,7 @@ virtio_postpone_intr(struct virtqueue *vq, uint16_t nslots) VQ_USED_EVENT(vq) = idx; virtio_membar_sync(); - vq_sync_aring(vq->vq_owner, vq, BUS_DMASYNC_PREWRITE); + vq_sync_aring_used_event(vq->vq_owner, vq, BUS_DMASYNC_PREWRITE); vq->vq_queued++; if (nslots < virtio_nused(vq)) @@ -905,6 +934,7 @@ virtio_stop_vq_intr(struct virtio_softc *sc, struct virtqueue *vq) * interrupt. */ VQ_USED_EVENT(vq) = vq->vq_used_idx + 0x8000; + vq_sync_aring_used_event(sc, vq, BUS_DMASYNC_PREWRITE); } else { vq->vq_avail->flags |= VRING_AVAIL_F_NO_INTERRUPT; } @@ -920,16 +950,19 @@ virtio_start_vq_intr(struct virtio_softc *sc, struct virtqueue *vq) * interrupts is done through setting the latest * consumed index in the used_event field */ - if (virtio_has_feature(sc, VIRTIO_F_RING_EVENT_IDX)) + if (virtio_has_feature(sc, VIRTIO_F_RING_EVENT_IDX)) { VQ_USED_EVENT(vq) = vq->vq_used_idx; - else + vq_sync_aring_used_event(sc, vq, BUS_DMASYNC_PREWRITE); + } else { vq->vq_avail->flags &= ~VRING_AVAIL_F_NO_INTERRUPT; + vq_sync_aring(sc, vq, BUS_DMASYNC_PREWRITE); + } virtio_membar_sync(); - vq_sync_aring(sc, vq, BUS_DMASYNC_PREWRITE); vq->vq_queued++; + vq_sync_uring(sc, vq, BUS_DMASYNC_POSTREAD); if (vq->vq_used_idx != vq->vq_used->idx) return 1; @@ -945,6 +978,7 @@ virtio_nused(struct virtqueue *vq) { uint16_t n; + vq_sync_uring(vq->vq_owner, vq, BUS_DMASYNC_POSTREAD); n = (uint16_t)(vq->vq_used->idx - vq->vq_used_idx); VIRTIO_ASSERT(n <= vq->vq_num); diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 21b31e74a..76bed8488 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_socket.c,v 1.340 2024/07/29 10:35:22 mvs Exp $ */ +/* $OpenBSD: uipc_socket.c,v 1.341 2024/08/01 17:19:01 bluhm Exp $ */ /* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */ /* @@ -361,7 +361,8 @@ sofree(struct socket *so, int keep_lock) #ifdef SOCKET_SPLICE if (so->so_sp) { /* Reuse splice idle, sounsplice() has been called before. */ - timeout_set_proc(&so->so_sp->ssp_idleto, soreaper, so); + timeout_set_flags(&so->so_sp->ssp_idleto, soreaper, so, + KCLOCK_NONE, TIMEOUT_PROC | TIMEOUT_MPSAFE); timeout_add(&so->so_sp->ssp_idleto, 0); } else #endif /* SOCKET_SPLICE */ @@ -1487,7 +1488,8 @@ sosplice(struct socket *so, int fd, off_t max, struct timeval *tv) so->so_idletv = *tv; else timerclear(&so->so_idletv); - timeout_set_proc(&so->so_idleto, soidle, so); + timeout_set_flags(&so->so_idleto, soidle, so, + KCLOCK_NONE, TIMEOUT_PROC | TIMEOUT_MPSAFE); task_set(&so->so_splicetask, sotask, so); /* diff --git a/sys/lib/libz/deflate.c b/sys/lib/libz/deflate.c index e653d530c..2a4fc280c 100644 --- a/sys/lib/libz/deflate.c +++ b/sys/lib/libz/deflate.c @@ -715,6 +715,14 @@ int ZEXPORT deflatePending(z_streamp strm, unsigned *pending, int *bits) { return Z_OK; } +/* ========================================================================= */ +int ZEXPORT deflateUsed(z_streamp strm, int *bits) { + if (deflateStateCheck(strm)) return Z_STREAM_ERROR; + if (bits != Z_NULL) + *bits = strm->state->bi_used; + return Z_OK; +} + /* ========================================================================= */ int ZEXPORT deflatePrime(z_streamp strm, int bits, int value) { deflate_state *s; @@ -1744,8 +1752,10 @@ local block_state deflate_stored(deflate_state *s, int flush) { s->high_water = s->strstart; /* If the last block was written to next_out, then done. */ - if (last) + if (last) { + s->bi_used = 8; return finish_done; + } /* If flushing and all input has been consumed, then done. */ if (flush != Z_NO_FLUSH && flush != Z_FINISH && @@ -1797,6 +1807,8 @@ local block_state deflate_stored(deflate_state *s, int flush) { } /* We've done all we can with the available input and output. */ + if (last) + s->bi_used = 8; return last ? finish_started : need_more; } diff --git a/sys/lib/libz/deflate.h b/sys/lib/libz/deflate.h index 8182a2604..ad230ef73 100644 --- a/sys/lib/libz/deflate.h +++ b/sys/lib/libz/deflate.h @@ -269,6 +269,9 @@ typedef struct internal_state { /* Number of valid bits in bi_buf. All bits above the last valid bit * are always zero. */ + int bi_used; + /* Last number of used bits when going to a byte boundary. + */ ulg high_water; /* High water mark offset in window for initialized bytes -- bytes above diff --git a/sys/lib/libz/trees.c b/sys/lib/libz/trees.c index cba0708b6..7ce629afb 100644 --- a/sys/lib/libz/trees.c +++ b/sys/lib/libz/trees.c @@ -182,6 +182,7 @@ local void bi_windup(deflate_state *s) { } else if (s->bi_valid > 0) { put_byte(s, (Byte)s->bi_buf); } + s->bi_used = ((s->bi_valid - 1) & 7) + 1; s->bi_buf = 0; s->bi_valid = 0; #ifdef ZLIB_DEBUG @@ -464,6 +465,7 @@ void ZLIB_INTERNAL _tr_init(deflate_state *s) { s->bi_buf = 0; s->bi_valid = 0; + s->bi_used = 0; #ifdef ZLIB_DEBUG s->compressed_len = 0L; s->bits_sent = 0L; diff --git a/sys/lib/libz/zconf.h b/sys/lib/libz/zconf.h index 1a3d41ebb..7221b8923 100644 --- a/sys/lib/libz/zconf.h +++ b/sys/lib/libz/zconf.h @@ -57,6 +57,7 @@ # define deflateSetDictionary z_deflateSetDictionary # define deflateSetHeader z_deflateSetHeader # define deflateTune z_deflateTune +# define deflateUsed z_deflateUsed # define deflate_copyright z_deflate_copyright # define get_crc_table z_get_crc_table # ifndef Z_SOLO diff --git a/sys/lib/libz/zlib.h b/sys/lib/libz/zlib.h index 5322a85f5..6c0e02d6c 100644 --- a/sys/lib/libz/zlib.h +++ b/sys/lib/libz/zlib.h @@ -791,6 +791,18 @@ ZEXTERN int ZEXPORT deflatePending(z_streamp strm, stream state was inconsistent. */ +ZEXTERN int ZEXPORT deflateUsed(z_streamp strm, + int *bits); +/* + deflateUsed() returns in *bits the most recent number of deflate bits used + in the last byte when flushing to a byte boundary. The result is in 1..8, or + 0 if there has not yet been a flush. This helps determine the location of + the last bit of a deflate stream. + + deflateUsed returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. + */ + ZEXTERN int ZEXPORT deflatePrime(z_streamp strm, int bits, int value); diff --git a/sys/lib/libz/zutil.h b/sys/lib/libz/zutil.h index 4995480cd..884d41785 100644 --- a/sys/lib/libz/zutil.h +++ b/sys/lib/libz/zutil.h @@ -41,7 +41,7 @@ typedef long ptrdiff_t; #endif #ifdef Z_SOLO - typedef long ptrdiff_t; /* guess -- will be caught if guess is wrong */ + typedef long ptrdiff_t; #endif #ifndef local diff --git a/usr.bin/sndiod/sock.c b/usr.bin/sndiod/sock.c index 86a78cb67..969ea9f0f 100644 --- a/usr.bin/sndiod/sock.c +++ b/usr.bin/sndiod/sock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sock.c,v 1.49 2024/05/24 15:16:09 ratchov Exp $ */ +/* $OpenBSD: sock.c,v 1.50 2024/08/01 14:36:27 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov * @@ -986,7 +986,7 @@ sock_execmsg(struct sock *f) struct slot *s = f->slot; struct amsg *m = &f->rmsg; unsigned char *data; - int size, ctl; + unsigned int size, ctl; int cmd; cmd = ntohl(m->cmd); @@ -1020,7 +1020,7 @@ sock_execmsg(struct sock *f) return 0; } size = ntohl(m->u.data.size); - if (size <= 0) { + if (size == 0) { #ifdef DEBUG if (log_level >= 1) { sock_log(f); diff --git a/usr.sbin/npppd/npppd/npppd.c b/usr.sbin/npppd/npppd/npppd.c index 556f6dcf8..cf1896eee 100644 --- a/usr.sbin/npppd/npppd/npppd.c +++ b/usr.sbin/npppd/npppd/npppd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: npppd.c,v 1.54 2024/07/11 14:05:59 yasuoka Exp $ */ +/* $OpenBSD: npppd.c,v 1.55 2024/08/01 00:05:16 yasuoka Exp $ */ /*- * Copyright (c) 2005-2008,2009 Internet Initiative Japan Inc. @@ -29,7 +29,7 @@ * Next pppd(nppd). This file provides a npppd daemon process and operations * for npppd instance. * @author Yasuoka Masahiko - * $Id: npppd.c,v 1.54 2024/07/11 14:05:59 yasuoka Exp $ + * $Id: npppd.c,v 1.55 2024/08/01 00:05:16 yasuoka Exp $ */ #include "version.h" #include /* ALIGNED_POINTER */ @@ -608,7 +608,7 @@ npppd_reset_routing_table(npppd *_this, int pool_only) if (is_first) in_route_add(&snp->snp_addr, &snp->snp_mask, &loop, - LOOPBACK_IFNAME, RTF_BLACKHOLE, 0); + LOOPBACK_IFNAME, RTF_REJECT, 0); break; case SNP_PPP: diff --git a/usr.sbin/radiusd/radiusd_ipcp.c b/usr.sbin/radiusd/radiusd_ipcp.c index c4b6ca7fe..407af6d6c 100644 --- a/usr.sbin/radiusd/radiusd_ipcp.c +++ b/usr.sbin/radiusd/radiusd_ipcp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: radiusd_ipcp.c,v 1.7 2024/07/22 10:00:16 yasuoka Exp $ */ +/* $OpenBSD: radiusd_ipcp.c,v 1.8 2024/08/01 00:58:14 yasuoka Exp $ */ /* * Copyright (c) 2024 Internet Initiative Japan Inc. @@ -794,7 +794,7 @@ ipcp_resdeco(void *ctx, u_int q_id, const u_char *req, size_t reqlen, if (!found) goto reject; } else { - n = arc4random() % self->npools; + n = arc4random_uniform(self->npools); i = 0; TAILQ_FOREACH(addr, &self->addrs, next) { if (addr->type == ADDRESS_TYPE_POOL) {