Re: [PATCH net-next v6 2/5] bitops: add non-atomic bitops for pointers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jul 02, 2021 at 08:17:47PM IST, David Laight wrote:
> From: Kumar Kartikeya Dwivedi
> > Sent: 02 July 2021 12:18
> >
> > cpumap needs to set, clear, and test the lowest bit in skb pointer in
> > various places. To make these checks less noisy, add pointer friendly
> > bitop macros that also do some typechecking to sanitize the argument.
>
> Would this work?
> #define BIT_OP(val, op) ((typeof (val))((unsigned long)(val) op))
>
> Should let you do:
> 	ptr = BIT_OP(ptr, | 1);
> 	ptr = BIT_OP(ptr, & ~1);
> 	if (BIT_OPT(ptr, & 1))
> 		...
>
> See https://godbolt.org/z/E57aGK4js
>

This certainly works, but my preference for keeping it this way was reusing the
existing infrastructure (which also has KASAN/KCSAN instrumentation) and avoids
UB while shifting. Ofcourse for this particular case, anything works, but if
putting this in bitops, I thought we should keep it as simple wrappers over
__set_bit/__clear_bit/test_bit.

Also, I compared codegen for both, and it looks pretty much the same to me...

See https://godbolt.org/z/s9cjEnYKj

Let me know if I'm missing something.

> 	David
>
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)

--
Kartikeya



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux