git: 4c9e6ad3205a - main - xen: add atomic #defines to accomodate differing xen_ulong_t sizes

From: Roger Pau Monné <royger_at_FreeBSD.org>
Date: Fri, 15 Dec 2023 13:59:47 UTC
The branch main has been updated by royger:

URL: https://cgit.FreeBSD.org/src/commit/?id=4c9e6ad3205a770a029cedc3056790258791e6ba

commit 4c9e6ad3205a770a029cedc3056790258791e6ba
Author:     Elliott Mitchell <ehem+freebsd@m5p.com>
AuthorDate: 2023-12-02 21:54:48 +0000
Commit:     Roger Pau Monné <royger@FreeBSD.org>
CommitDate: 2023-12-15 13:59:26 +0000

    xen: add atomic #defines to accomodate differing xen_ulong_t sizes
    
    Alas, ARM declared xen_ulong_t to be 64-bits long, unlike i386 where
    it matches the word size.  As a result, compatibility wrappers are
    needed for Xen atomic operations.
    
    Reviewed by: royger
---
 sys/dev/xen/bus/xen_intr.c   |  6 +++---
 sys/x86/include/xen/xen-os.h | 10 ++++++++++
 sys/xen/evtchn/evtchnvar.h   |  6 +++---
 sys/xen/xen-os.h             | 12 ++++++------
 4 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/sys/dev/xen/bus/xen_intr.c b/sys/dev/xen/bus/xen_intr.c
index 3e44c05ceeb7..3fc8fb0fe83a 100644
--- a/sys/dev/xen/bus/xen_intr.c
+++ b/sys/dev/xen/bus/xen_intr.c
@@ -369,7 +369,7 @@ xen_intr_handle_upcall(void *unused __unused)
 	/* Clear master flag /before/ clearing selector flag. */
 	wmb();
 #endif
-	l1 = atomic_readandclear_long(&v->evtchn_pending_sel);
+	l1 = atomic_readandclear_xen_ulong(&v->evtchn_pending_sel);
 
 	l1i = pc->last_processed_l1i;
 	l2i = pc->last_processed_l2i;
@@ -475,7 +475,7 @@ xen_intr_init(void *dummy __unused)
 	}
 
 	for (i = 0; i < nitems(s->evtchn_mask); i++)
-		atomic_store_rel_long(&s->evtchn_mask[i], ~0);
+		atomic_store_rel_xen_ulong(&s->evtchn_mask[i], ~0);
 
 	xen_arch_intr_init();
 
@@ -582,7 +582,7 @@ xen_intr_resume(void)
 
 	/* Mask all event channels. */
 	for (i = 0; i < nitems(s->evtchn_mask); i++)
-		atomic_store_rel_long(&s->evtchn_mask[i], ~0);
+		atomic_store_rel_xen_ulong(&s->evtchn_mask[i], ~0);
 
 	/* Clear existing port mappings */
 	for (isrc_idx = 0; isrc_idx < NR_EVENT_CHANNELS; ++isrc_idx)
diff --git a/sys/x86/include/xen/xen-os.h b/sys/x86/include/xen/xen-os.h
index 6a3b82c0ba62..12942375be43 100644
--- a/sys/x86/include/xen/xen-os.h
+++ b/sys/x86/include/xen/xen-os.h
@@ -54,6 +54,16 @@ extern int xen_disable_pv_nics;
 
 extern uint32_t xen_cpuid_base;
 
+/* compatibility for accessing xen_ulong_t with atomics */
+#define	atomic_clear_xen_ulong		atomic_clear_long
+#define	atomic_set_xen_ulong		atomic_set_long
+#define	atomic_readandclear_xen_ulong	atomic_readandclear_long
+#define	atomic_testandset_xen_ulong	atomic_testandset_long
+#define	atomic_load_acq_xen_ulong	atomic_load_acq_long
+#define	atomic_store_rel_xen_ulong	atomic_store_rel_long
+#define	atomic_set_xen_ulong		atomic_set_long
+#define	atomic_clear_xen_ulong		atomic_clear_long
+
 static inline u_int
 XEN_CPUID_TO_VCPUID(u_int cpuid)
 {
diff --git a/sys/xen/evtchn/evtchnvar.h b/sys/xen/evtchn/evtchnvar.h
index 10eed8434ebe..455f7bcbd620 100644
--- a/sys/xen/evtchn/evtchnvar.h
+++ b/sys/xen/evtchn/evtchnvar.h
@@ -54,7 +54,7 @@ static inline int
 evtchn_test_and_set_mask(evtchn_port_t port)
 {
 
-	return (atomic_testandset_long(EVTCHN_PTR(mask, port),
+	return (atomic_testandset_xen_ulong(EVTCHN_PTR(mask, port),
 	    EVTCHN_BIT(port)));
 }
 
@@ -67,7 +67,7 @@ static inline void
 evtchn_clear_port(evtchn_port_t port)
 {
 
-	atomic_clear_long(EVTCHN_PTR(pending, port), EVTCHN_MASK(port));
+	atomic_clear_xen_ulong(EVTCHN_PTR(pending, port), EVTCHN_MASK(port));
 }
 
 /**
@@ -79,7 +79,7 @@ static inline void
 evtchn_mask_port(evtchn_port_t port)
 {
 
-	atomic_set_long(EVTCHN_PTR(mask, port), EVTCHN_MASK(port));
+	atomic_set_xen_ulong(EVTCHN_PTR(mask, port), EVTCHN_MASK(port));
 }
 
 /**
diff --git a/sys/xen/xen-os.h b/sys/xen/xen-os.h
index d009b1af11fa..d7e9b3ca8632 100644
--- a/sys/xen/xen-os.h
+++ b/sys/xen/xen-os.h
@@ -120,23 +120,23 @@ xen_initial_domain(void)
 #define NBPL (NBBY * sizeof(long))
 
 static inline bool
-xen_test_bit(int bit, volatile long *addr)
+xen_test_bit(int bit, volatile xen_ulong_t *addr)
 {
 	unsigned long mask = 1UL << (bit % NBPL);
 
-	return !!(atomic_load_acq_long(&addr[bit / NBPL]) & mask);
+	return !!(atomic_load_acq_xen_ulong(&addr[bit / NBPL]) & mask);
 }
 
 static inline void
-xen_set_bit(int bit, volatile long *addr)
+xen_set_bit(int bit, volatile xen_ulong_t *addr)
 {
-	atomic_set_long(&addr[bit / NBPL], 1UL << (bit % NBPL));
+	atomic_set_xen_ulong(&addr[bit / NBPL], 1UL << (bit % NBPL));
 }
 
 static inline void
-xen_clear_bit(int bit, volatile long *addr)
+xen_clear_bit(int bit, volatile xen_ulong_t *addr)
 {
-	atomic_clear_long(&addr[bit / NBPL], 1UL << (bit % NBPL));
+	atomic_clear_xen_ulong(&addr[bit / NBPL], 1UL << (bit % NBPL));
 }
 
 #undef NBPL