* [PATCH bpf-next] bpf: remove useless variable
@ 2018-12-13 21:44 Andrea Claudi
2018-12-14 11:24 ` Stefano Brivio
2018-12-14 17:03 ` Martin Lau
0 siblings, 2 replies; 5+ messages in thread
From: Andrea Claudi @ 2018-12-13 21:44 UTC (permalink / raw)
To: netdev; +Cc: ast, daniel, sbrivio
bytes is initialized to end - start at the beginning of this function,
and is never changed. Remove it making the code a bit more readable.
Suggested-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
---
net/core/filter.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/net/core/filter.c b/net/core/filter.c
index aa274679965d..f31a0de14216 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -2170,8 +2170,8 @@ static const struct bpf_func_proto bpf_msg_cork_bytes_proto = {
BPF_CALL_4(bpf_msg_pull_data, struct sk_msg *, msg, u32, start,
u32, end, u64, flags)
{
- u32 len = 0, offset = 0, copy = 0, poffset = 0, bytes = end - start;
u32 first_sge, last_sge, i, shift, bytes_sg_total;
+ u32 len = 0, offset = 0, copy = 0, poffset = 0;
struct scatterlist *sge;
u8 *raw, *to, *from;
struct page *page;
@@ -2196,7 +2196,7 @@ BPF_CALL_4(bpf_msg_pull_data, struct sk_msg *, msg, u32, start,
/* The start may point into the sg element so we need to also
* account for the headroom.
*/
- bytes_sg_total = start - offset + bytes;
+ bytes_sg_total = end - offset;
if (!msg->sg.copy[i] && bytes_sg_total <= len)
goto out;
@@ -2279,7 +2279,7 @@ BPF_CALL_4(bpf_msg_pull_data, struct sk_msg *, msg, u32, start,
msg->sg.end - shift;
out:
msg->data = sg_virt(&msg->sg.data[first_sge]) + start - offset;
- msg->data_end = msg->data + bytes;
+ msg->data_end = msg->data + end - start;
return 0;
}
--
2.19.2
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH bpf-next] bpf: remove useless variable
2018-12-13 21:44 [PATCH bpf-next] bpf: remove useless variable Andrea Claudi
@ 2018-12-14 11:24 ` Stefano Brivio
2018-12-14 17:03 ` Martin Lau
1 sibling, 0 replies; 5+ messages in thread
From: Stefano Brivio @ 2018-12-14 11:24 UTC (permalink / raw)
To: Andrea Claudi; +Cc: netdev, ast, daniel
On Thu, 13 Dec 2018 22:44:57 +0100
Andrea Claudi <aclaudi@redhat.com> wrote:
> bytes is initialized to end - start at the beginning of this function,
> and is never changed. Remove it making the code a bit more readable.
>
> Suggested-by: Stefano Brivio <sbrivio@redhat.com>
> Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
Reviewed-by: Stefano Brivio <sbrivio@redhat.com>
--
Stefano
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next] bpf: remove useless variable
2018-12-13 21:44 [PATCH bpf-next] bpf: remove useless variable Andrea Claudi
2018-12-14 11:24 ` Stefano Brivio
@ 2018-12-14 17:03 ` Martin Lau
2018-12-14 17:14 ` Stefano Brivio
2018-12-15 1:13 ` Daniel Borkmann
1 sibling, 2 replies; 5+ messages in thread
From: Martin Lau @ 2018-12-14 17:03 UTC (permalink / raw)
To: Andrea Claudi
Cc: netdev@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
sbrivio@redhat.com, John Fastabend
On Thu, Dec 13, 2018 at 10:44:57PM +0100, Andrea Claudi wrote:
> bytes is initialized to end - start at the beginning of this function,
> and is never changed. Remove it making the code a bit more readable.
>
> Suggested-by: Stefano Brivio <sbrivio@redhat.com>
> Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
The change looks correct.
I found the original code more intuitive to read though.
Daniel/John, thoughts?
> ---
> net/core/filter.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/net/core/filter.c b/net/core/filter.c
> index aa274679965d..f31a0de14216 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -2170,8 +2170,8 @@ static const struct bpf_func_proto bpf_msg_cork_bytes_proto = {
> BPF_CALL_4(bpf_msg_pull_data, struct sk_msg *, msg, u32, start,
> u32, end, u64, flags)
> {
> - u32 len = 0, offset = 0, copy = 0, poffset = 0, bytes = end - start;
> u32 first_sge, last_sge, i, shift, bytes_sg_total;
> + u32 len = 0, offset = 0, copy = 0, poffset = 0;
> struct scatterlist *sge;
> u8 *raw, *to, *from;
> struct page *page;
> @@ -2196,7 +2196,7 @@ BPF_CALL_4(bpf_msg_pull_data, struct sk_msg *, msg, u32, start,
> /* The start may point into the sg element so we need to also
> * account for the headroom.
> */
> - bytes_sg_total = start - offset + bytes;
> + bytes_sg_total = end - offset;
> if (!msg->sg.copy[i] && bytes_sg_total <= len)
> goto out;
>
> @@ -2279,7 +2279,7 @@ BPF_CALL_4(bpf_msg_pull_data, struct sk_msg *, msg, u32, start,
> msg->sg.end - shift;
> out:
> msg->data = sg_virt(&msg->sg.data[first_sge]) + start - offset;
> - msg->data_end = msg->data + bytes;
> + msg->data_end = msg->data + end - start;
> return 0;
> }
>
> --
> 2.19.2
>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH bpf-next] bpf: remove useless variable
2018-12-14 17:03 ` Martin Lau
@ 2018-12-14 17:14 ` Stefano Brivio
2018-12-15 1:13 ` Daniel Borkmann
1 sibling, 0 replies; 5+ messages in thread
From: Stefano Brivio @ 2018-12-14 17:14 UTC (permalink / raw)
To: Martin Lau
Cc: Andrea Claudi, netdev@vger.kernel.org, ast@kernel.org,
daniel@iogearbox.net, John Fastabend
On Fri, 14 Dec 2018 17:03:02 +0000
Martin Lau <kafai@fb.com> wrote:
> On Thu, Dec 13, 2018 at 10:44:57PM +0100, Andrea Claudi wrote:
> > bytes is initialized to end - start at the beginning of this function,
> > and is never changed. Remove it making the code a bit more readable.
> >
> > Suggested-by: Stefano Brivio <sbrivio@redhat.com>
> > Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
> The change looks correct.
> I found the original code more intuitive to read though.
> Daniel/John, thoughts?
In detail: the idea behind my suggestion was that:
bytes_sg_total = start - offset + bytes;
sounds like: start from 'start', move back by 'offset' (where am I
now?), add 'bytes' (what is 'bytes'? Oh, it's end - start...). Whereas:
bytes_sg_total = end - offset;
looked easier to follow: total bytes are the distance between 'end' and
'offset'.
--
Stefano
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next] bpf: remove useless variable
2018-12-14 17:03 ` Martin Lau
2018-12-14 17:14 ` Stefano Brivio
@ 2018-12-15 1:13 ` Daniel Borkmann
1 sibling, 0 replies; 5+ messages in thread
From: Daniel Borkmann @ 2018-12-15 1:13 UTC (permalink / raw)
To: Martin Lau, Andrea Claudi
Cc: netdev@vger.kernel.org, ast@kernel.org, sbrivio@redhat.com,
John Fastabend
On 12/14/2018 06:03 PM, Martin Lau wrote:
> On Thu, Dec 13, 2018 at 10:44:57PM +0100, Andrea Claudi wrote:
>> bytes is initialized to end - start at the beginning of this function,
>> and is never changed. Remove it making the code a bit more readable.
>>
>> Suggested-by: Stefano Brivio <sbrivio@redhat.com>
>> Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
> The change looks correct.
> I found the original code more intuitive to read though.
> Daniel/John, thoughts?
Change is correct, but I kind of agree with Martin that it seems to
make it slightly less intuitive to follow the logic. Probably just
personal preference. I think the change is mainly about the first
part since 'msg->data + bytes' is perhaps slightly more obvious than
'msg->data + end - start', so that second chunk was kind of a necessity
due to getting rid of bytes var. The first part is on finding the
right scatterlist ring entry based on the user provided data /start/.
And the /offset/ is the accumulation of the sg entries in the skmsg
we needed to walk to get to this point. So the /start - offset/ is
the headroom of the last skmsg entry. This and /bytes/ is needed for
checking whether it's single or multi skmsg element. 'end - offset'
feels a bit less intuitive to follow here given the previous logic.
Thanks,
Daniel
>> ---
>> net/core/filter.c | 6 +++---
>> 1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/net/core/filter.c b/net/core/filter.c
>> index aa274679965d..f31a0de14216 100644
>> --- a/net/core/filter.c
>> +++ b/net/core/filter.c
>> @@ -2170,8 +2170,8 @@ static const struct bpf_func_proto bpf_msg_cork_bytes_proto = {
>> BPF_CALL_4(bpf_msg_pull_data, struct sk_msg *, msg, u32, start,
>> u32, end, u64, flags)
>> {
>> - u32 len = 0, offset = 0, copy = 0, poffset = 0, bytes = end - start;
>> u32 first_sge, last_sge, i, shift, bytes_sg_total;
>> + u32 len = 0, offset = 0, copy = 0, poffset = 0;
>> struct scatterlist *sge;
>> u8 *raw, *to, *from;
>> struct page *page;
>> @@ -2196,7 +2196,7 @@ BPF_CALL_4(bpf_msg_pull_data, struct sk_msg *, msg, u32, start,
>> /* The start may point into the sg element so we need to also
>> * account for the headroom.
>> */
>> - bytes_sg_total = start - offset + bytes;
>> + bytes_sg_total = end - offset;
>> if (!msg->sg.copy[i] && bytes_sg_total <= len)
>> goto out;
>>
>> @@ -2279,7 +2279,7 @@ BPF_CALL_4(bpf_msg_pull_data, struct sk_msg *, msg, u32, start,
>> msg->sg.end - shift;
>> out:
>> msg->data = sg_virt(&msg->sg.data[first_sge]) + start - offset;
>> - msg->data_end = msg->data + bytes;
>> + msg->data_end = msg->data + end - start;
>> return 0;
>> }
>>
>> --
>> 2.19.2
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-12-15 1:13 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-12-13 21:44 [PATCH bpf-next] bpf: remove useless variable Andrea Claudi
2018-12-14 11:24 ` Stefano Brivio
2018-12-14 17:03 ` Martin Lau
2018-12-14 17:14 ` Stefano Brivio
2018-12-15 1:13 ` Daniel Borkmann
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).