linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
To: linux-kernel@vger.kernel.org
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
	linux-fsdevel@vger.kernel.org, maple-tree@lists.infradead.org
Subject: [PATCH v2 1/5] tools: Add kernel stubs needed for rosebush
Date: Tue, 25 Jun 2024 22:17:56 +0100	[thread overview]
Message-ID: <20240625211803.2750563-2-willy@infradead.org> (raw)
In-Reply-To: <20240625211803.2750563-1-willy@infradead.org>

Various parts of the kernel API didn't need to exist before, so add
them:

 - spin_trylock()
 - DECLARE_FLEX_ARRAY
 - vmalloc
 - __vmalloc_node
 - kvmalloc
 - kvfree_rcu_mightsleep

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 tools/include/linux/compiler.h           |  4 ++++
 tools/include/linux/compiler_types.h     |  2 ++
 tools/include/linux/spinlock.h           |  2 ++
 tools/include/linux/stddef.h             |  3 +++
 tools/testing/radix-tree/linux/kernel.h  |  2 ++
 tools/testing/radix-tree/linux/vmalloc.h | 14 ++++++++++++++
 6 files changed, 27 insertions(+)
 create mode 100644 tools/include/linux/stddef.h
 create mode 100644 tools/testing/radix-tree/linux/vmalloc.h

diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
index 8a63a9913495..936b5153b0fe 100644
--- a/tools/include/linux/compiler.h
+++ b/tools/include/linux/compiler.h
@@ -62,6 +62,10 @@
 #define __nocf_check __attribute__((nocf_check))
 #endif
 
+#ifndef __refdata
+#define __refdata
+#endif
+
 /* Are two types/vars the same type (ignoring qualifiers)? */
 #ifndef __same_type
 # define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
diff --git a/tools/include/linux/compiler_types.h b/tools/include/linux/compiler_types.h
index d09f9dc172a4..18bd8767cebc 100644
--- a/tools/include/linux/compiler_types.h
+++ b/tools/include/linux/compiler_types.h
@@ -17,6 +17,7 @@
 /* context/locking */
 # define __must_hold(x)	__attribute__((context(x,1,1)))
 # define __acquires(x)	__attribute__((context(x,0,1)))
+# define __cond_acquires(x) __attribute__((context(x,0,-1)))
 # define __releases(x)	__attribute__((context(x,1,0)))
 # define __acquire(x)	__context__(x,1)
 # define __release(x)	__context__(x,-1)
@@ -27,6 +28,7 @@
 # define __acquires(x)
 # define __releases(x)
 # define __acquire(x)	(void)0
+# define __cond_acquires(x)
 # define __release(x)	(void)0
 # define __cond_lock(x,c) (c)
 #endif /* __CHECKER__ */
diff --git a/tools/include/linux/spinlock.h b/tools/include/linux/spinlock.h
index a6cdf25b6b9d..871a6a305b9d 100644
--- a/tools/include/linux/spinlock.h
+++ b/tools/include/linux/spinlock.h
@@ -20,6 +20,8 @@
 #define spin_lock_irqsave(x, f)		(void)f, pthread_mutex_lock(x)
 #define spin_unlock_irqrestore(x, f)	(void)f, pthread_mutex_unlock(x)
 
+#define spin_trylock(x)			(pthread_mutex_trylock(x) == 0)
+
 #define arch_spinlock_t pthread_mutex_t
 #define __ARCH_SPIN_LOCK_UNLOCKED PTHREAD_MUTEX_INITIALIZER
 
diff --git a/tools/include/linux/stddef.h b/tools/include/linux/stddef.h
new file mode 100644
index 000000000000..337f520eba1d
--- /dev/null
+++ b/tools/include/linux/stddef.h
@@ -0,0 +1,3 @@
+#include <uapi/linux/stddef.h>
+
+#define DECLARE_FLEX_ARRAY(TYPE, NAME) __DECLARE_FLEX_ARRAY(TYPE, NAME)
diff --git a/tools/testing/radix-tree/linux/kernel.h b/tools/testing/radix-tree/linux/kernel.h
index c0a2bb785b92..72a95fd9708c 100644
--- a/tools/testing/radix-tree/linux/kernel.h
+++ b/tools/testing/radix-tree/linux/kernel.h
@@ -26,4 +26,6 @@
 #define __must_hold(x)
 
 #define EXPORT_PER_CPU_SYMBOL_GPL(x)
+
+#define PAGE_SIZE	4096
 #endif /* _KERNEL_H */
diff --git a/tools/testing/radix-tree/linux/vmalloc.h b/tools/testing/radix-tree/linux/vmalloc.h
new file mode 100644
index 000000000000..2857c37472bb
--- /dev/null
+++ b/tools/testing/radix-tree/linux/vmalloc.h
@@ -0,0 +1,14 @@
+#include <malloc.h>
+
+#define vmalloc(x)		malloc(x)
+#define __vmalloc_node(size, align, gfp, node, caller)	memalign(size, align)
+#define vfree(x)		free(x)
+
+#define kvmalloc(x, gfp)	memalign(x, x)
+#define kvfree(x)		free(x)
+
+/* A correct but slow implementation */
+#define kvfree_rcu_mightsleep(x)	{				\
+	synchronize_rcu();						\
+	free(x);							\
+}
-- 
2.43.0


  reply	other threads:[~2024-06-25 21:18 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-25 21:17 [PATCH v2 0/5] Rosebush, a new hash table Matthew Wilcox (Oracle)
2024-06-25 21:17 ` Matthew Wilcox (Oracle) [this message]
2024-06-25 21:17 ` [PATCH v2 2/5] rosebush: Add new data structure Matthew Wilcox (Oracle)
2024-06-25 23:36   ` Dr. David Alan Gilbert
2024-06-26 13:16     ` Matthew Wilcox
2024-06-26 13:07   ` Matthew Wilcox
2024-06-29 19:45   ` Markus Elfring
2024-07-01  1:32     ` Matthew Wilcox
2024-07-01  5:21       ` [v2 " Markus Elfring
2024-07-01 14:18         ` Paul E. McKenney
2024-07-02  1:04   ` [PATCH v2 " Bagas Sanjaya
2024-06-25 21:17 ` [PATCH v2 3/5] rosebush: Add test suite Matthew Wilcox (Oracle)
2024-06-28 15:18   ` Pankaj Raghav (Samsung)
2024-06-29  5:13   ` Jeff Johnson
2024-06-25 21:17 ` [PATCH v2 4/5] tools: Add support for running rosebush tests in userspace Matthew Wilcox (Oracle)
2024-06-29  5:15   ` Jeff Johnson
2024-06-25 21:18 ` [PATCH v2 5/5] dcache: Convert to use rosebush Matthew Wilcox (Oracle)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240625211803.2750563-2-willy@infradead.org \
    --to=willy@infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maple-tree@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).