18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci 38c2ecf20Sopenharmony_ci/* 48c2ecf20Sopenharmony_ci * This file provides wrappers with sanitizer instrumentation for atomic bit 58c2ecf20Sopenharmony_ci * operations. 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * To use this functionality, an arch's bitops.h file needs to define each of 88c2ecf20Sopenharmony_ci * the below bit operations with an arch_ prefix (e.g. arch_set_bit(), 98c2ecf20Sopenharmony_ci * arch___set_bit(), etc.). 108c2ecf20Sopenharmony_ci */ 118c2ecf20Sopenharmony_ci#ifndef _ASM_GENERIC_BITOPS_INSTRUMENTED_ATOMIC_H 128c2ecf20Sopenharmony_ci#define _ASM_GENERIC_BITOPS_INSTRUMENTED_ATOMIC_H 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#include <linux/instrumented.h> 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci/** 178c2ecf20Sopenharmony_ci * set_bit - Atomically set a bit in memory 188c2ecf20Sopenharmony_ci * @nr: the bit to set 198c2ecf20Sopenharmony_ci * @addr: the address to start counting from 208c2ecf20Sopenharmony_ci * 218c2ecf20Sopenharmony_ci * This is a relaxed atomic operation (no implied memory barriers). 228c2ecf20Sopenharmony_ci * 238c2ecf20Sopenharmony_ci * Note that @nr may be almost arbitrarily large; this function is not 248c2ecf20Sopenharmony_ci * restricted to acting on a single-word quantity. 258c2ecf20Sopenharmony_ci */ 268c2ecf20Sopenharmony_cistatic inline void set_bit(long nr, volatile unsigned long *addr) 278c2ecf20Sopenharmony_ci{ 288c2ecf20Sopenharmony_ci instrument_atomic_write(addr + BIT_WORD(nr), sizeof(long)); 298c2ecf20Sopenharmony_ci arch_set_bit(nr, addr); 308c2ecf20Sopenharmony_ci} 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci/** 338c2ecf20Sopenharmony_ci * clear_bit - Clears a bit in memory 348c2ecf20Sopenharmony_ci * @nr: Bit to clear 358c2ecf20Sopenharmony_ci * @addr: Address to start counting from 368c2ecf20Sopenharmony_ci * 378c2ecf20Sopenharmony_ci * This is a relaxed atomic operation (no implied memory barriers). 388c2ecf20Sopenharmony_ci */ 398c2ecf20Sopenharmony_cistatic inline void clear_bit(long nr, volatile unsigned long *addr) 408c2ecf20Sopenharmony_ci{ 418c2ecf20Sopenharmony_ci instrument_atomic_write(addr + BIT_WORD(nr), sizeof(long)); 428c2ecf20Sopenharmony_ci arch_clear_bit(nr, addr); 438c2ecf20Sopenharmony_ci} 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci/** 468c2ecf20Sopenharmony_ci * change_bit - Toggle a bit in memory 478c2ecf20Sopenharmony_ci * @nr: Bit to change 488c2ecf20Sopenharmony_ci * @addr: Address to start counting from 498c2ecf20Sopenharmony_ci * 508c2ecf20Sopenharmony_ci * This is a relaxed atomic operation (no implied memory barriers). 518c2ecf20Sopenharmony_ci * 528c2ecf20Sopenharmony_ci * Note that @nr may be almost arbitrarily large; this function is not 538c2ecf20Sopenharmony_ci * restricted to acting on a single-word quantity. 548c2ecf20Sopenharmony_ci */ 558c2ecf20Sopenharmony_cistatic inline void change_bit(long nr, volatile unsigned long *addr) 568c2ecf20Sopenharmony_ci{ 578c2ecf20Sopenharmony_ci instrument_atomic_write(addr + BIT_WORD(nr), sizeof(long)); 588c2ecf20Sopenharmony_ci arch_change_bit(nr, addr); 598c2ecf20Sopenharmony_ci} 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci/** 628c2ecf20Sopenharmony_ci * test_and_set_bit - Set a bit and return its old value 638c2ecf20Sopenharmony_ci * @nr: Bit to set 648c2ecf20Sopenharmony_ci * @addr: Address to count from 658c2ecf20Sopenharmony_ci * 668c2ecf20Sopenharmony_ci * This is an atomic fully-ordered operation (implied full memory barrier). 678c2ecf20Sopenharmony_ci */ 688c2ecf20Sopenharmony_cistatic inline bool test_and_set_bit(long nr, volatile unsigned long *addr) 698c2ecf20Sopenharmony_ci{ 708c2ecf20Sopenharmony_ci instrument_atomic_read_write(addr + BIT_WORD(nr), sizeof(long)); 718c2ecf20Sopenharmony_ci return arch_test_and_set_bit(nr, addr); 728c2ecf20Sopenharmony_ci} 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci/** 758c2ecf20Sopenharmony_ci * test_and_clear_bit - Clear a bit and return its old value 768c2ecf20Sopenharmony_ci * @nr: Bit to clear 778c2ecf20Sopenharmony_ci * @addr: Address to count from 788c2ecf20Sopenharmony_ci * 798c2ecf20Sopenharmony_ci * This is an atomic fully-ordered operation (implied full memory barrier). 808c2ecf20Sopenharmony_ci */ 818c2ecf20Sopenharmony_cistatic inline bool test_and_clear_bit(long nr, volatile unsigned long *addr) 828c2ecf20Sopenharmony_ci{ 838c2ecf20Sopenharmony_ci instrument_atomic_read_write(addr + BIT_WORD(nr), sizeof(long)); 848c2ecf20Sopenharmony_ci return arch_test_and_clear_bit(nr, addr); 858c2ecf20Sopenharmony_ci} 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci/** 888c2ecf20Sopenharmony_ci * test_and_change_bit - Change a bit and return its old value 898c2ecf20Sopenharmony_ci * @nr: Bit to change 908c2ecf20Sopenharmony_ci * @addr: Address to count from 918c2ecf20Sopenharmony_ci * 928c2ecf20Sopenharmony_ci * This is an atomic fully-ordered operation (implied full memory barrier). 938c2ecf20Sopenharmony_ci */ 948c2ecf20Sopenharmony_cistatic inline bool test_and_change_bit(long nr, volatile unsigned long *addr) 958c2ecf20Sopenharmony_ci{ 968c2ecf20Sopenharmony_ci instrument_atomic_read_write(addr + BIT_WORD(nr), sizeof(long)); 978c2ecf20Sopenharmony_ci return arch_test_and_change_bit(nr, addr); 988c2ecf20Sopenharmony_ci} 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci#endif /* _ASM_GENERIC_BITOPS_INSTRUMENTED_NON_ATOMIC_H */ 101