Path: blob/master/include/asm-generic/bitops/instrumented-atomic.h
26292 views
/* SPDX-License-Identifier: GPL-2.0 */12/*3* This file provides wrappers with sanitizer instrumentation for atomic bit4* operations.5*6* To use this functionality, an arch's bitops.h file needs to define each of7* the below bit operations with an arch_ prefix (e.g. arch_set_bit(),8* arch___set_bit(), etc.).9*/10#ifndef _ASM_GENERIC_BITOPS_INSTRUMENTED_ATOMIC_H11#define _ASM_GENERIC_BITOPS_INSTRUMENTED_ATOMIC_H1213#include <linux/instrumented.h>1415/**16* set_bit - Atomically set a bit in memory17* @nr: the bit to set18* @addr: the address to start counting from19*20* This is a relaxed atomic operation (no implied memory barriers).21*22* Note that @nr may be almost arbitrarily large; this function is not23* restricted to acting on a single-word quantity.24*/25static __always_inline void set_bit(long nr, volatile unsigned long *addr)26{27instrument_atomic_write(addr + BIT_WORD(nr), sizeof(long));28arch_set_bit(nr, addr);29}3031/**32* clear_bit - Clears a bit in memory33* @nr: Bit to clear34* @addr: Address to start counting from35*36* This is a relaxed atomic operation (no implied memory barriers).37*/38static __always_inline void clear_bit(long nr, volatile unsigned long *addr)39{40instrument_atomic_write(addr + BIT_WORD(nr), sizeof(long));41arch_clear_bit(nr, addr);42}4344/**45* change_bit - Toggle a bit in memory46* @nr: Bit to change47* @addr: Address to start counting from48*49* This is a relaxed atomic operation (no implied memory barriers).50*51* Note that @nr may be almost arbitrarily large; this function is not52* restricted to acting on a single-word quantity.53*/54static __always_inline void change_bit(long nr, volatile unsigned long *addr)55{56instrument_atomic_write(addr + BIT_WORD(nr), sizeof(long));57arch_change_bit(nr, addr);58}5960/**61* test_and_set_bit - Set a bit and return its old value62* @nr: Bit to set63* @addr: Address to count from64*65* This is an atomic fully-ordered operation (implied full memory barrier).66*/67static __always_inline bool test_and_set_bit(long nr, volatile unsigned long *addr)68{69kcsan_mb();70instrument_atomic_read_write(addr + BIT_WORD(nr), sizeof(long));71return arch_test_and_set_bit(nr, addr);72}7374/**75* test_and_clear_bit - Clear a bit and return its old value76* @nr: Bit to clear77* @addr: Address to count from78*79* This is an atomic fully-ordered operation (implied full memory barrier).80*/81static __always_inline bool test_and_clear_bit(long nr, volatile unsigned long *addr)82{83kcsan_mb();84instrument_atomic_read_write(addr + BIT_WORD(nr), sizeof(long));85return arch_test_and_clear_bit(nr, addr);86}8788/**89* test_and_change_bit - Change a bit and return its old value90* @nr: Bit to change91* @addr: Address to count from92*93* This is an atomic fully-ordered operation (implied full memory barrier).94*/95static __always_inline bool test_and_change_bit(long nr, volatile unsigned long *addr)96{97kcsan_mb();98instrument_atomic_read_write(addr + BIT_WORD(nr), sizeof(long));99return arch_test_and_change_bit(nr, addr);100}101102#endif /* _ASM_GENERIC_BITOPS_INSTRUMENTED_NON_ATOMIC_H */103104105