Skip to content

Commit 7751491

Browse files
SiFiveHollandpalmer-dabbelt
authored andcommitted
riscv: Enable bitops instrumentation
Instead of implementing the bitops functions directly in assembly, provide the arch_-prefixed versions and use the wrappers from asm-generic to add instrumentation. This improves KASAN coverage and fixes the kasan_bitops_generic() unit test. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Alexandre Ghiti <[email protected]> Tested-by: Alexandre Ghiti <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 58ff537 commit 7751491

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

arch/riscv/include/asm/bitops.h

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -222,44 +222,44 @@ static __always_inline int variable_fls(unsigned int x)
222222
#define __NOT(x) (~(x))
223223

224224
/**
225-
* test_and_set_bit - Set a bit and return its old value
225+
* arch_test_and_set_bit - Set a bit and return its old value
226226
* @nr: Bit to set
227227
* @addr: Address to count from
228228
*
229229
* This operation may be reordered on other architectures than x86.
230230
*/
231-
static inline int test_and_set_bit(int nr, volatile unsigned long *addr)
231+
static inline int arch_test_and_set_bit(int nr, volatile unsigned long *addr)
232232
{
233233
return __test_and_op_bit(or, __NOP, nr, addr);
234234
}
235235

236236
/**
237-
* test_and_clear_bit - Clear a bit and return its old value
237+
* arch_test_and_clear_bit - Clear a bit and return its old value
238238
* @nr: Bit to clear
239239
* @addr: Address to count from
240240
*
241241
* This operation can be reordered on other architectures other than x86.
242242
*/
243-
static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
243+
static inline int arch_test_and_clear_bit(int nr, volatile unsigned long *addr)
244244
{
245245
return __test_and_op_bit(and, __NOT, nr, addr);
246246
}
247247

248248
/**
249-
* test_and_change_bit - Change a bit and return its old value
249+
* arch_test_and_change_bit - Change a bit and return its old value
250250
* @nr: Bit to change
251251
* @addr: Address to count from
252252
*
253253
* This operation is atomic and cannot be reordered.
254254
* It also implies a memory barrier.
255255
*/
256-
static inline int test_and_change_bit(int nr, volatile unsigned long *addr)
256+
static inline int arch_test_and_change_bit(int nr, volatile unsigned long *addr)
257257
{
258258
return __test_and_op_bit(xor, __NOP, nr, addr);
259259
}
260260

261261
/**
262-
* set_bit - Atomically set a bit in memory
262+
* arch_set_bit - Atomically set a bit in memory
263263
* @nr: the bit to set
264264
* @addr: the address to start counting from
265265
*
@@ -270,68 +270,68 @@ static inline int test_and_change_bit(int nr, volatile unsigned long *addr)
270270
* Note that @nr may be almost arbitrarily large; this function is not
271271
* restricted to acting on a single-word quantity.
272272
*/
273-
static inline void set_bit(int nr, volatile unsigned long *addr)
273+
static inline void arch_set_bit(int nr, volatile unsigned long *addr)
274274
{
275275
__op_bit(or, __NOP, nr, addr);
276276
}
277277

278278
/**
279-
* clear_bit - Clears a bit in memory
279+
* arch_clear_bit - Clears a bit in memory
280280
* @nr: Bit to clear
281281
* @addr: Address to start counting from
282282
*
283283
* Note: there are no guarantees that this function will not be reordered
284284
* on non x86 architectures, so if you are writing portable code,
285285
* make sure not to rely on its reordering guarantees.
286286
*/
287-
static inline void clear_bit(int nr, volatile unsigned long *addr)
287+
static inline void arch_clear_bit(int nr, volatile unsigned long *addr)
288288
{
289289
__op_bit(and, __NOT, nr, addr);
290290
}
291291

292292
/**
293-
* change_bit - Toggle a bit in memory
293+
* arch_change_bit - Toggle a bit in memory
294294
* @nr: Bit to change
295295
* @addr: Address to start counting from
296296
*
297297
* change_bit() may be reordered on other architectures than x86.
298298
* Note that @nr may be almost arbitrarily large; this function is not
299299
* restricted to acting on a single-word quantity.
300300
*/
301-
static inline void change_bit(int nr, volatile unsigned long *addr)
301+
static inline void arch_change_bit(int nr, volatile unsigned long *addr)
302302
{
303303
__op_bit(xor, __NOP, nr, addr);
304304
}
305305

306306
/**
307-
* test_and_set_bit_lock - Set a bit and return its old value, for lock
307+
* arch_test_and_set_bit_lock - Set a bit and return its old value, for lock
308308
* @nr: Bit to set
309309
* @addr: Address to count from
310310
*
311311
* This operation is atomic and provides acquire barrier semantics.
312312
* It can be used to implement bit locks.
313313
*/
314-
static inline int test_and_set_bit_lock(
314+
static inline int arch_test_and_set_bit_lock(
315315
unsigned long nr, volatile unsigned long *addr)
316316
{
317317
return __test_and_op_bit_ord(or, __NOP, nr, addr, .aq);
318318
}
319319

320320
/**
321-
* clear_bit_unlock - Clear a bit in memory, for unlock
321+
* arch_clear_bit_unlock - Clear a bit in memory, for unlock
322322
* @nr: the bit to set
323323
* @addr: the address to start counting from
324324
*
325325
* This operation is atomic and provides release barrier semantics.
326326
*/
327-
static inline void clear_bit_unlock(
327+
static inline void arch_clear_bit_unlock(
328328
unsigned long nr, volatile unsigned long *addr)
329329
{
330330
__op_bit_ord(and, __NOT, nr, addr, .rl);
331331
}
332332

333333
/**
334-
* __clear_bit_unlock - Clear a bit in memory, for unlock
334+
* arch___clear_bit_unlock - Clear a bit in memory, for unlock
335335
* @nr: the bit to set
336336
* @addr: the address to start counting from
337337
*
@@ -345,13 +345,13 @@ static inline void clear_bit_unlock(
345345
* non-atomic property here: it's a lot more instructions and we still have to
346346
* provide release semantics anyway.
347347
*/
348-
static inline void __clear_bit_unlock(
348+
static inline void arch___clear_bit_unlock(
349349
unsigned long nr, volatile unsigned long *addr)
350350
{
351-
clear_bit_unlock(nr, addr);
351+
arch_clear_bit_unlock(nr, addr);
352352
}
353353

354-
static inline bool xor_unlock_is_negative_byte(unsigned long mask,
354+
static inline bool arch_xor_unlock_is_negative_byte(unsigned long mask,
355355
volatile unsigned long *addr)
356356
{
357357
unsigned long res;
@@ -369,6 +369,9 @@ static inline bool xor_unlock_is_negative_byte(unsigned long mask,
369369
#undef __NOT
370370
#undef __AMO
371371

372+
#include <asm-generic/bitops/instrumented-atomic.h>
373+
#include <asm-generic/bitops/instrumented-lock.h>
374+
372375
#include <asm-generic/bitops/non-atomic.h>
373376
#include <asm-generic/bitops/le.h>
374377
#include <asm-generic/bitops/ext2-atomic.h>

0 commit comments

Comments
 (0)