Index | Thread | Search

From:
Jonathan Gray <jsg@jsg.id.au>
Subject:
de-macro uvm SWAP_KEY_*
To:
tech@openbsd.org
Date:
Thu, 7 Nov 2024 17:25:13 +1100

Download raw body.

Thread
Index: sys/uvm/uvm_swap_encrypt.h
===================================================================
RCS file: /cvs/src/sys/uvm/uvm_swap_encrypt.h,v
diff -u -p -r1.13 uvm_swap_encrypt.h
--- sys/uvm/uvm_swap_encrypt.h	7 Nov 2024 06:04:11 -0000	1.13
+++ sys/uvm/uvm_swap_encrypt.h	7 Nov 2024 06:14:38 -0000
@@ -60,22 +60,24 @@ void swap_decrypt(struct swap_key *,cadd
 void swap_key_cleanup(struct swap_key *);
 void swap_key_prepare(struct swap_key *, int);
 
-#define SWAP_KEY_GET(s,x)	do {					\
-					if ((x)->refcount == 0) {	\
-						swap_key_create(x);	\
-					}				\
-					(x)->refcount++;		\
-				} while(0);
-
-#define SWAP_KEY_PUT(s,x)	do {					\
-					(x)->refcount--;		\
-					if ((x)->refcount == 0) {	\
-						swap_key_delete(x);	\
-					}				\
-				} while(0);
-
 void swap_key_create(struct swap_key *);
 void swap_key_delete(struct swap_key *);
+
+static inline void
+swap_key_get(struct swap_key *key)
+{
+	if (key->refcount == 0)
+		swap_key_create(key);
+	key->refcount++;
+}
+
+static inline void
+swap_key_put(struct swap_key *key)
+{
+	key->refcount--;
+	if (key->refcount == 0)
+		swap_key_delete(key);
+}
 
 extern int uvm_doswapencrypt;		/* swapencrypt enabled/disabled */
 extern int swap_encrypt_initialized;
Index: sys/uvm/uvm_swap.c
===================================================================
RCS file: /cvs/src/sys/uvm/uvm_swap.c,v
diff -u -p -r1.172 uvm_swap.c
--- sys/uvm/uvm_swap.c	30 Oct 2024 06:16:27 -0000	1.172
+++ sys/uvm/uvm_swap.c	7 Nov 2024 06:14:38 -0000
@@ -1624,7 +1624,7 @@ uvm_swap_free(int startslot, int nslots)
 
 					key = SWD_KEY(sdp, startslot + i);
 					if (key->refcount != 0)
-						SWAP_KEY_PUT(sdp, key);
+						swap_key_put(key);
 				}
 
 			/* Mark range as not decrypt */
@@ -1813,7 +1813,7 @@ uvm_swap_io(struct vm_page **pps, int st
 
 			if (encrypt) {
 				key = SWD_KEY(sdp, startslot + i);
-				SWAP_KEY_GET(sdp, key);	/* add reference */
+				swap_key_get(key);	/* add reference */
 
 				swap_encrypt(key, src, dst, block, PAGE_SIZE);
 				block += btodb(PAGE_SIZE);