[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <09DA43B9-0F6F-45C1-A60D-12E61493C71F@fb.com>
Date: Fri, 18 Dec 2020 17:23:25 +0000
From: Song Liu <songliubraving@...com>
To: Yonghong Song <yhs@...com>
CC: Alexei Starovoitov <alexei.starovoitov@...il.com>,
"bpf@...r.kernel.org" <bpf@...r.kernel.org>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>,
"ast@...nel.org" <ast@...nel.org>,
"daniel@...earbox.net" <daniel@...earbox.net>,
"andrii@...nel.org" <andrii@...nel.org>,
"john.fastabend@...il.com" <john.fastabend@...il.com>,
"kpsingh@...omium.org" <kpsingh@...omium.org>,
Kernel Team <Kernel-team@...com>
Subject: Re: [PATCH v2 bpf-next 1/4] bpf: introduce task_vma bpf_iter
> On Dec 18, 2020, at 8:38 AM, Yonghong Song <yhs@...com> wrote:
>
>
>
> On 12/17/20 9:23 PM, Alexei Starovoitov wrote:
>> On Thu, Dec 17, 2020 at 8:33 PM Song Liu <songliubraving@...com> wrote:
>>>>
>>>> ahh. I missed that. Makes sense.
>>>> vm_file needs to be accurate, but vm_area_struct should be accessed as ptr_to_btf_id.
>>>
>>> Passing pointer of vm_area_struct into BPF will be tricky. For example, shall we
>>> allow the user to access vma->vm_file? IIUC, with ptr_to_btf_id the verifier will
>>> allow access of vma->vm_file as a valid pointer to struct file. However, since the
>>> vma might be freed, vma->vm_file could point to random data.
>> I don't think so. The proposed patch will do get_file() on it.
>> There is actually no need to assign it into a different variable.
>> Accessing it via vma->vm_file is safe and cleaner.
>
> I did not check the code but do you have scenarios where vma is freed but old vma->vm_file is not freed due to reference counting, but
> freed vma area is reused so vma->vm_file could be garbage?
AFAIK, once we unlock mmap_sem, the vma could be freed and reused. I guess ptr_to_btf_id
or probe_read would not help with this?
Thanks,
Song
>
>>>>> [1] ff9f47f6f00c ("mm: proc: smaps_rollup: do not stall write attempts on mmap_lock")
>>>>
>>>> Thanks for this link. With "if (mmap_lock_is_contended())" check it should work indeed.
>>>
>>> To make sure we are on the same page: I am using slightly different mechanism in
>>> task_vma_iter, which doesn't require checking mmap_lock_is_contended(). In the
>>> smaps_rollup case, the code only unlock mmap_sem when the lock is contended. In
>>> task_iter, we always unlock mmap_sem between two iterations. This is because we
>>> don't want to hold mmap_sem while calling the BPF program, which may sleep (calling
>>> bpf_d_path).
>> That part is clear. I had to look into mmap_read_lock_killable() implementation
>> to realize that it's checking for lock_is_contended after acquiring
>> and releasing
>> if there is a contention. So it's the same behavior at the end.
Powered by blists - more mailing lists