From: "Toke Høiland-Jørgensen" <toke@redhat.com>
To: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Cc: netdev@vger.kernel.org, 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>,
bpf@vger.kernel.org
Subject: Re: [PATCH net-next v3 2/5] bitops: add non-atomic bitops for pointers
Date: Wed, 23 Jun 2021 13:09:00 +0200 [thread overview]
Message-ID: <87bl7won1v.fsf@toke.dk> (raw)
In-Reply-To: <20210622231606.6ak5shta5bknt7lb@apollo>
Kumar Kartikeya Dwivedi <memxor@gmail.com> writes:
> On Wed, Jun 23, 2021 at 04:03:06AM IST, Toke Høiland-Jørgensen wrote:
>> Kumar Kartikeya Dwivedi <memxor@gmail.com> writes:
>>
>> > On Wed, Jun 23, 2021 at 03:22:51AM IST, Toke Høiland-Jørgensen wrote:
>> >> Kumar Kartikeya Dwivedi <memxor@gmail.com> writes:
>> >>
>> >> > 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.
>> >> >
>> >> > These wrap the non-atomic bitops __set_bit, __clear_bit, and test_bit
>> >> > but for pointer arguments. Pointer's address has to be passed in and it
>> >> > is treated as an unsigned long *, since width and representation of
>> >> > pointer and unsigned long match on targets Linux supports. They are
>> >> > prefixed with double underscore to indicate lack of atomicity.
>> >> >
>> >> > Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
>> >> > ---
>> >> > include/linux/bitops.h | 19 +++++++++++++++++++
>> >> > include/linux/typecheck.h | 10 ++++++++++
>> >> > 2 files changed, 29 insertions(+)
>> >> >
>> >> > diff --git a/include/linux/bitops.h b/include/linux/bitops.h
>> >> > index 26bf15e6cd35..a9e336b9fa4d 100644
>> >> > --- a/include/linux/bitops.h
>> >> > +++ b/include/linux/bitops.h
>> >> > @@ -4,6 +4,7 @@
>> >> >
>> >> > #include <asm/types.h>
>> >> > #include <linux/bits.h>
>> >> > +#include <linux/typecheck.h>
>> >> >
>> >> > #include <uapi/linux/kernel.h>
>> >> >
>> >> > @@ -253,6 +254,24 @@ static __always_inline void __assign_bit(long nr, volatile unsigned long *addr,
>> >> > __clear_bit(nr, addr);
>> >> > }
>> >> >
>> >> > +#define __ptr_set_bit(nr, addr) \
>> >> > + ({ \
>> >> > + typecheck_pointer(*(addr)); \
>> >> > + __set_bit(nr, (unsigned long *)(addr)); \
>> >> > + })
>> >> > +
>> >> > +#define __ptr_clear_bit(nr, addr) \
>> >> > + ({ \
>> >> > + typecheck_pointer(*(addr)); \
>> >> > + __clear_bit(nr, (unsigned long *)(addr)); \
>> >> > + })
>> >> > +
>> >> > +#define __ptr_test_bit(nr, addr) \
>> >> > + ({ \
>> >> > + typecheck_pointer(*(addr)); \
>> >> > + test_bit(nr, (unsigned long *)(addr)); \
>> >> > + })
>> >> > +
>> >>
>> >> Before these were functions that returned the modified values, now they
>> >> are macros that modify in-place. Why the change? :)
>> >>
>> >
>> > Given that we're exporting this to all kernel users now, it felt more
>> > appropriate to follow the existing convention/argument order for the
>> > functions/ops they are wrapping.
>>
>> I wasn't talking about the order of the arguments; swapping those is
>> fine. But before, you had:
>>
>> static void *__ptr_set_bit(void *ptr, int bit)
>>
>> with usage (function return is the modified value):
>> ret = ptr_ring_produce(rcpu->queue, __ptr_set_bit(skb, 0));
>>
>> now you have:
>> #define __ptr_set_bit(nr, addr)
>>
>> with usage (modifies argument in-place):
>> __ptr_set_bit(0, &skb);
>> ret = ptr_ring_produce(rcpu->queue, skb);
>>
>> why change from function to macro?
>>
>
> Earlier it just took the pointer value and returned one with the bit set. I
> changed it to work similar to __set_bit.
Hmm, okay, fair enough I suppose there's something to be said for
consistency, even though I personally prefer the function style. Let's
keep it as macros, then :)
-Toke
next prev parent reply other threads:[~2021-06-23 11:09 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-22 20:28 [PATCH net-next v3 0/5] Generic XDP improvements Kumar Kartikeya Dwivedi
2021-06-22 20:28 ` [PATCH net-next v3 1/5] net: core: split out code to run generic XDP prog Kumar Kartikeya Dwivedi
2021-06-22 20:28 ` [PATCH net-next v3 2/5] bitops: add non-atomic bitops for pointers Kumar Kartikeya Dwivedi
2021-06-22 21:52 ` Toke Høiland-Jørgensen
2021-06-22 22:10 ` Kumar Kartikeya Dwivedi
2021-06-22 22:33 ` Toke Høiland-Jørgensen
2021-06-22 23:16 ` Kumar Kartikeya Dwivedi
2021-06-23 11:09 ` Toke Høiland-Jørgensen [this message]
2021-06-24 13:08 ` David Laight
2021-06-22 20:28 ` [PATCH net-next v3 3/5] bpf: cpumap: implement generic cpumap Kumar Kartikeya Dwivedi
2021-06-22 20:28 ` [PATCH net-next v3 4/5] bpf: devmap: implement devmap prog execution for generic XDP Kumar Kartikeya Dwivedi
2021-06-22 20:28 ` [PATCH net-next v3 5/5] bpf: update XDP selftests to not fail with " Kumar Kartikeya Dwivedi
2021-06-23 11:17 ` Toke Høiland-Jørgensen
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=87bl7won1v.fsf@toke.dk \
--to=toke@redhat.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=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kuba@kernel.org \
--cc=memxor@gmail.com \
--cc=netdev@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).