git: 64e30cba3f04 - main - LinuxKPI: Add write_seqcount_invalidate() and seqprop_sequence()

From: Vladimir Kondratyev <wulf_at_FreeBSD.org>
Date: Sun, 24 Dec 2023 08:23:11 UTC
The branch main has been updated by wulf:

URL: https://cgit.FreeBSD.org/src/commit/?id=64e30cba3f0432fa684728b67850b6254d3713ea

commit 64e30cba3f0432fa684728b67850b6254d3713ea
Author:     Vladimir Kondratyev <wulf@FreeBSD.org>
AuthorDate: 2023-12-24 08:19:59 +0000
Commit:     Vladimir Kondratyev <wulf@FreeBSD.org>
CommitDate: 2023-12-24 08:19:59 +0000

    LinuxKPI: Add write_seqcount_invalidate() and seqprop_sequence()
    
    functions to linux/seqlock.h
    
    Sponsored by:   Serenity Cyber Security, LLC
    Reviewed by:    manu
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D42810
---
 sys/compat/linuxkpi/common/include/linux/seqlock.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/linux/seqlock.h b/sys/compat/linuxkpi/common/include/linux/seqlock.h
index a7b9dd12e493..48e42efc10fe 100644
--- a/sys/compat/linuxkpi/common/include/linux/seqlock.h
+++ b/sys/compat/linuxkpi/common/include/linux/seqlock.h
@@ -31,6 +31,7 @@
 
 #include <sys/param.h>
 #include <sys/systm.h>
+#include <sys/cdefs.h>
 #include <sys/lock.h>
 #include <sys/mutex.h>
 #include <sys/rwlock.h>
@@ -84,9 +85,24 @@ seqcount_mutex_init(struct seqcount_mutex *seqcount, void *mutex __unused)
 	struct seqcount_mutex:	seqc_write_end				\
     )(&(s)->seqc)
 
+static inline void
+lkpi_write_seqcount_invalidate(seqc_t *seqcp)
+{
+	atomic_thread_fence_rel();
+	*seqcp += SEQC_MOD * 2;
+}
+#define	write_seqcount_invalidate(s) lkpi_write_seqcount_invalidate(&(s)->seqc)
+
 #define	read_seqcount_begin(s)	seqc_read(&(s)->seqc)
 #define	raw_read_seqcount(s)	seqc_read_any(&(s)->seqc)
 
+static inline seqc_t
+lkpi_seqprop_sequence(const seqc_t *seqcp)
+{
+	return (atomic_load_int(__DECONST(seqc_t *, seqcp)));
+}
+#define	seqprop_sequence(s)	lkpi_seqprop_sequence(&(s)->seqc)
+
 /*
  * XXX: Are predicts from inline functions still not honored by clang?
  */