From: Kumar Kartikeya Dwivedi <memxor@gmail.com>
To: David Laight <David.Laight@aculab.com>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"Toke Høiland-Jørgensen" <toke@redhat.com>,
"Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Jesper Dangaard Brouer" <brouer@redhat.com>,
"David S. Miller" <davem@davemloft.net>,
"Jakub Kicinski" <kuba@kernel.org>,
"John Fastabend" <john.fastabend@gmail.com>,
"Martin KaFai Lau" <kafai@fb.com>,
"Eric Leblond" <eric@regit.org>,
"bpf@vger.kernel.org" <bpf@vger.kernel.org>
Subject: Re: [PATCH net-next v6 2/5] bitops: add non-atomic bitops for pointers
Date: Fri, 2 Jul 2021 21:41:09 +0530 [thread overview]
Message-ID: <20210702161109.q2cep7hmxyvfelh5@apollo> (raw)
In-Reply-To: <0660a065aad94979a560682cef5d573c@AcuMS.aculab.com>
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
next prev parent reply other threads:[~2021-07-02 16:13 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-02 11:18 [PATCH net-next v6 0/5] Generic XDP improvements Kumar Kartikeya Dwivedi
2021-07-02 11:18 ` [PATCH net-next v6 1/5] net: core: split out code to run generic XDP prog Kumar Kartikeya Dwivedi
2021-07-02 11:18 ` [PATCH net-next v6 2/5] bitops: add non-atomic bitops for pointers Kumar Kartikeya Dwivedi
2021-07-02 14:47 ` David Laight
2021-07-02 16:11 ` Kumar Kartikeya Dwivedi [this message]
2021-07-02 11:18 ` [PATCH net-next v6 3/5] bpf: cpumap: implement generic cpumap Kumar Kartikeya Dwivedi
2021-07-02 13:33 ` Jesper Dangaard Brouer
2021-07-02 11:18 ` [PATCH net-next v6 4/5] bpf: devmap: implement devmap prog execution for generic XDP Kumar Kartikeya Dwivedi
2021-07-02 11:18 ` [PATCH net-next v6 5/5] bpf: tidy xdp attach selftests Kumar Kartikeya Dwivedi
2021-07-08 3:10 ` [PATCH net-next v6 0/5] Generic XDP improvements Alexei Starovoitov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210702161109.q2cep7hmxyvfelh5@apollo \
--to=memxor@gmail.com \
--cc=David.Laight@aculab.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=brouer@redhat.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=eric@regit.org \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=toke@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox