From: sf Date: Sat, 2 Dec 2023 10:01:35 +0000 (+0000) Subject: virtio: Fix handling of feature bits >= 32 X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=c0ea3bd1e6801244e065cf90f8a4247feb3cf3d6;p=openbsd virtio: Fix handling of feature bits >= 32 Fix handling of feature bits >= 32. This does not yet affect any driver as no high feature bit besides VERSION_1 is used, and that one has special handling. Also, with VIRTIO_DEBUG, simply walk through all transport and device feature names, so that we don't need to adjust the if clause whenever the standard introduces new transport features. ok jan@ bluhm@ --- diff --git a/sys/dev/pv/virtio.c b/sys/dev/pv/virtio.c index e9be61c0bbe..53e27e27211 100644 --- a/sys/dev/pv/virtio.c +++ b/sys/dev/pv/virtio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: virtio.c,v 1.23 2023/07/07 10:23:39 patrick Exp $ */ +/* $OpenBSD: virtio.c,v 1.24 2023/12/02 10:01:35 sf Exp $ */ /* $NetBSD: virtio.c,v 1.3 2011/11/02 23:05:52 njoly Exp $ */ /* @@ -97,7 +97,7 @@ virtio_log_features(uint64_t host, uint64_t neg, const struct virtio_feature_name *namep; int i; char c; - uint32_t bit; + uint64_t bit; for (i = 0; i < 64; i++) { if (i == 30) { @@ -107,13 +107,17 @@ virtio_log_features(uint64_t host, uint64_t neg, */ continue; } - bit = 1 << i; + bit = 1ULL << i; if ((host&bit) == 0) continue; - namep = (i < 24 || i > 37) ? guest_feature_names : - transport_feature_names; + namep = guest_feature_names; while (namep->bit && namep->bit != bit) namep++; + if (namep->name == NULL) { + namep = transport_feature_names; + while (namep->bit && namep->bit != bit) + namep++; + } c = (neg&bit) ? '+' : '-'; if (namep->name) printf(" %c%s", c, namep->name); diff --git a/sys/dev/pv/virtiovar.h b/sys/dev/pv/virtiovar.h index 7f2aea701cd..d12cb2c59b8 100644 --- a/sys/dev/pv/virtiovar.h +++ b/sys/dev/pv/virtiovar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: virtiovar.h,v 1.15 2023/07/07 10:23:39 patrick Exp $ */ +/* $OpenBSD: virtiovar.h,v 1.16 2023/12/02 10:01:35 sf Exp $ */ /* $NetBSD: virtiovar.h,v 1.1 2011/10/30 12:12:21 hannken Exp $ */ /* @@ -138,7 +138,7 @@ struct virtqueue { }; struct virtio_feature_name { - uint32_t bit; + uint64_t bit; const char *name; }; @@ -203,7 +203,7 @@ struct virtio_softc { #define virtio_device_reset(sc) virtio_set_status((sc), 0) static inline int -virtio_has_feature(struct virtio_softc *sc, unsigned int fbit) +virtio_has_feature(struct virtio_softc *sc, uint64_t fbit) { if (sc->sc_active_features & fbit) return 1;