The branch main has been updated by jrtc27: URL: https://cgit.FreeBSD.org/src/commit/?id=cb75bb51261b13a49636befdee1c4a76f2e9013e
commit cb75bb51261b13a49636befdee1c4a76f2e9013e Author: Jessica Clarke <jrt...@freebsd.org> AuthorDate: 2025-07-10 19:33:33 +0000 Commit: Jessica Clarke <jrt...@freebsd.org> CommitDate: 2025-07-10 19:33:33 +0000 vmbus: Avoid gratuitous ifdef and use more generic implementation instead Checking for __LP64__ is non-portable as it assumes that ILP32 and LP64 are the only two ABIs that exist, but CheriBSD supports an additional ABI where long is still 64-bit but pointers are 128-bit capabilities, and thus __LP64__ is not defined. We could change this to check the value of __SIZEOF_LONG__, since the code here only cares about that aspect of the ABI, however in this instance, the only real reason an ifdef is used at all is to be able to get log2(sizeof(u_long)), but if we instead multiply and divide rather than shift, and let the compiler optimise that to a shift, we can just use sizeof(u_long) instead. Note also that VMBUS_EVTFLAGS_MAX could always just have been defined as VMBUS_EVTFLAGS_SIZE / sizeof(u_long). Reviewed by: jhb Differential Revision: https://reviews.freebsd.org/D50630 --- sys/dev/hyperv/vmbus/vmbus_chan.c | 6 +++--- sys/dev/hyperv/vmbus/vmbus_reg.h | 10 ++-------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/sys/dev/hyperv/vmbus/vmbus_chan.c b/sys/dev/hyperv/vmbus/vmbus_chan.c index 189a3e66a039..7ea60a499c72 100644 --- a/sys/dev/hyperv/vmbus/vmbus_chan.c +++ b/sys/dev/hyperv/vmbus/vmbus_chan.c @@ -1555,7 +1555,7 @@ vmbus_event_flags_proc(struct vmbus_softc *sc, volatile u_long *event_flags, continue; flags = atomic_swap_long(&event_flags[f], 0); - chid_base = f << VMBUS_EVTFLAG_SHIFT; + chid_base = f * VMBUS_EVTFLAG_LEN; while ((chid_ofs = ffsl(flags)) != 0) { struct vmbus_channel *chan; @@ -1599,7 +1599,7 @@ vmbus_event_proc_compat(struct vmbus_softc *sc, int cpu) eventf = VMBUS_PCPU_GET(sc, event_flags, cpu) + VMBUS_SINT_MESSAGE; if (atomic_testandclear_long(&eventf->evt_flags[0], 0)) { vmbus_event_flags_proc(sc, sc->vmbus_rx_evtflags, - VMBUS_CHAN_MAX_COMPAT >> VMBUS_EVTFLAG_SHIFT); + VMBUS_CHAN_MAX_COMPAT / VMBUS_EVTFLAG_LEN); } } @@ -1903,7 +1903,7 @@ vmbus_chan_msgproc_choffer(struct vmbus_softc *sc, * Setup event flag. */ chan->ch_evtflag = - &sc->vmbus_tx_evtflags[chan->ch_id >> VMBUS_EVTFLAG_SHIFT]; + &sc->vmbus_tx_evtflags[chan->ch_id / VMBUS_EVTFLAG_LEN]; chan->ch_evtflag_mask = 1UL << (chan->ch_id & VMBUS_EVTFLAG_MASK); /* diff --git a/sys/dev/hyperv/vmbus/vmbus_reg.h b/sys/dev/hyperv/vmbus/vmbus_reg.h index 4aa729475b5d..76cdca0ebeb2 100644 --- a/sys/dev/hyperv/vmbus/vmbus_reg.h +++ b/sys/dev/hyperv/vmbus/vmbus_reg.h @@ -60,16 +60,10 @@ CTASSERT(sizeof(struct vmbus_message) == VMBUS_MSG_SIZE); * Hyper-V SynIC event flags */ -#ifdef __LP64__ -#define VMBUS_EVTFLAGS_MAX 32 -#define VMBUS_EVTFLAG_SHIFT 6 -#else -#define VMBUS_EVTFLAGS_MAX 64 -#define VMBUS_EVTFLAG_SHIFT 5 -#endif -#define VMBUS_EVTFLAG_LEN (1 << VMBUS_EVTFLAG_SHIFT) +#define VMBUS_EVTFLAG_LEN (sizeof(u_long) * 8) #define VMBUS_EVTFLAG_MASK (VMBUS_EVTFLAG_LEN - 1) #define VMBUS_EVTFLAGS_SIZE 256 +#define VMBUS_EVTFLAGS_MAX (VMBUS_EVTFLAGS_SIZE / sizeof(u_long)) struct vmbus_evtflags { u_long evt_flags[VMBUS_EVTFLAGS_MAX];