All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yonghong Song <yhs@fb.com>
To: Jonathan Lemon <jonathan.lemon@gmail.com>,
	Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Networking <netdev@vger.kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>, bpf <bpf@vger.kernel.org>,
	Kernel Team <kernel-team@fb.com>
Subject: Re: [PATCH 1/1 v3 bpf-next] bpf: increment and use correct thread iterator
Date: Sun, 13 Dec 2020 23:00:09 -0800	[thread overview]
Message-ID: <7774ab85-ef6d-8928-0374-ae037f495cab@fb.com> (raw)
In-Reply-To: <20201211230134.qswet7pfrda23ooa@bsd-mbp.dhcp.thefacebook.com>



On 12/11/20 3:01 PM, Jonathan Lemon wrote:
> On Fri, Dec 11, 2020 at 12:23:34PM -0800, Andrii Nakryiko wrote:
>>> @@ -164,7 +164,7 @@ task_file_seq_get_next(struct bpf_iter_seq_task_file_info *info)
>>>                  curr_files = get_files_struct(curr_task);
>>>                  if (!curr_files) {
>>>                          put_task_struct(curr_task);
>>> -                       curr_tid = ++(info->tid);
>>> +                       curr_tid = curr_tid + 1;
>>
>> Yonghong might know definitively, but it seems like we need to update
>> info->tid here as well:
>>
>> info->tid = curr_tid;
>>
>> If the search eventually yields no task, then info->tid will stay at
>> some potentially much smaller value, and we'll keep re-searching tasks
>> from the same TID on each subsequent read (if user keeps reading the
>> file). So corner case, but good to have covered.
> 
> That applies earlier as well:
> 
>                  curr_task = task_seq_get_next(ns, &curr_tid, true);
>                  if (!curr_task) {
>                          info->task = NULL;
>                          info->files = NULL;
>                          return NULL;
>                  }
> 
> The logic seems to be "if task == NULL, then return NULL and stop".
> Is the seq_iterator allowed to continue/restart if seq_next returns NULL?

If seq_next() returns NULL, bpf_seq_read() will end and the control
will return to user space. There are two cases here:
    - there are something in the buffer and user will get non-zero-length
      return data and after this typically user will call read() syscall
      again. In such cases case, the search will be from last info->tid.
    - the buffer is empty and user will get a "0" return value for read()
      system. Typically, user will not call read() syscall any more.
      But if it does, the search will start from last info->tid.

Agree with Andrii, in general, this should not be a big problem.
But it is good to get this fixed too.

> --
> Jonathan
> 

  parent reply	other threads:[~2020-12-14  7:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-11 17:11 [PATCH 0/1 v3 bpf-next] bpf: increment and use correct thread iterator Jonathan Lemon
2020-12-11 17:11 ` [PATCH 1/1 " Jonathan Lemon
2020-12-11 20:23   ` Andrii Nakryiko
2020-12-11 23:01     ` Jonathan Lemon
2020-12-12  0:28       ` Andrii Nakryiko
2020-12-14  7:00       ` Yonghong Song [this message]
2020-12-18 16:53   ` Yonghong Song
2020-12-18 18:06     ` Jonathan Lemon
2020-12-18 18:21       ` Yonghong Song
2020-12-18 19:28       ` Andrii Nakryiko

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=7774ab85-ef6d-8928-0374-ae037f495cab@fb.com \
    --to=yhs@fb.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=jonathan.lemon@gmail.com \
    --cc=kernel-team@fb.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.