lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <167863207565.5837.13979748605991037374.tip-bot2@tip-bot2>
Date:   Sun, 12 Mar 2023 14:41:15 -0000
From:   "tip-bot2 for Andrzej Hajda" <tip-bot2@...utronix.de>
To:     linux-tip-commits@...r.kernel.org
Cc:     Andrzej Hajda <andrzej.hajda@...el.com>,
        "Peter Zijlstra (Intel)" <peterz@...radead.org>,
        Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
        Andi Shyti <andi.shyti@...ux.intel.com>, x86@...nel.org,
        linux-kernel@...r.kernel.org
Subject: [tip: locking/core] linux/include: add non-atomic version of xchg

The following commit has been merged into the locking/core branch of tip:

Commit-ID:     6e58fca8f12015d783df9d155bbb969a09a29e64
Gitweb:        https://git.kernel.org/tip/6e58fca8f12015d783df9d155bbb969a09a29e64
Author:        Andrzej Hajda <andrzej.hajda@...el.com>
AuthorDate:    Wed, 18 Jan 2023 16:44:45 +01:00
Committer:     Peter Zijlstra <peterz@...radead.org>
CommitterDate: Sat, 11 Mar 2023 14:03:58 +01:00

linux/include: add non-atomic version of xchg

The pattern of setting variable with new value and returning old
one is very common in kernel. Usually atomicity of the operation
is not required, so xchg seems to be suboptimal and confusing in
such cases.

Signed-off-by: Andrzej Hajda <andrzej.hajda@...el.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@...radead.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Reviewed-by: Andi Shyti <andi.shyti@...ux.intel.com>
Link: https://lore.kernel.org/r/20230118154450.73842-2-andrzej.hajda@intel.com
---
 include/linux/non-atomic/xchg.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
 create mode 100644 include/linux/non-atomic/xchg.h

diff --git a/include/linux/non-atomic/xchg.h b/include/linux/non-atomic/xchg.h
new file mode 100644
index 0000000..f7fa5dd
--- /dev/null
+++ b/include/linux/non-atomic/xchg.h
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_NON_ATOMIC_XCHG_H
+#define _LINUX_NON_ATOMIC_XCHG_H
+
+/**
+ * __xchg - set variable pointed by @ptr to @val, return old value
+ * @ptr: pointer to affected variable
+ * @val: value to be written
+ *
+ * This is non-atomic variant of xchg.
+ */
+#define __xchg(ptr, val) ({		\
+	__auto_type __ptr = ptr;	\
+	__auto_type __t = *__ptr;	\
+	*__ptr = (val);			\
+	__t;				\
+})
+
+#endif

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ