From: Song Liu <songliubraving@fb.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: lkml <linux-kernel@vger.kernel.org>,
Linux-MM <linux-mm@kvack.org>,
"Andrew Morton" <akpm@linux-foundation.org>,
"matthew.wilcox@oracle.com" <matthew.wilcox@oracle.com>,
"kirill.shutemov@linux.intel.com"
<kirill.shutemov@linux.intel.com>,
"peterz@infradead.org" <peterz@infradead.org>,
"rostedt@goodmis.org" <rostedt@goodmis.org>,
"Kernel Team" <Kernel-team@fb.com>,
"william.kucharski@oracle.com" <william.kucharski@oracle.com>
Subject: Re: [PATCH v8 2/4] uprobe: use original page when all uprobes are removed
Date: Thu, 25 Jul 2019 18:17:10 +0000 [thread overview]
Message-ID: <A0D24D6F-B649-4B4B-8C33-70B7DCB0D814@fb.com> (raw)
In-Reply-To: <20190725081414.GB4707@redhat.com>
> On Jul 25, 2019, at 1:14 AM, Oleg Nesterov <oleg@redhat.com> wrote:
>
> On 07/24, Song Liu wrote:
>>
>>
>>> On Jul 24, 2019, at 4:37 AM, Oleg Nesterov <oleg@redhat.com> wrote:
>>>
>>> On 07/24, Song Liu wrote:
>>>>
>>>> lock_page(old_page);
>>>> @@ -177,15 +180,24 @@ static int __replace_page(struct vm_area_struct *vma, unsigned long addr,
>>>> mmu_notifier_invalidate_range_start(&range);
>>>> err = -EAGAIN;
>>>> if (!page_vma_mapped_walk(&pvmw)) {
>>>> - mem_cgroup_cancel_charge(new_page, memcg, false);
>>>> + if (!orig)
>>>> + mem_cgroup_cancel_charge(new_page, memcg, false);
>>>> goto unlock;
>>>> }
>>>> VM_BUG_ON_PAGE(addr != pvmw.address, old_page);
>>>>
>>>> get_page(new_page);
>>>> - page_add_new_anon_rmap(new_page, vma, addr, false);
>>>> - mem_cgroup_commit_charge(new_page, memcg, false, false);
>>>> - lru_cache_add_active_or_unevictable(new_page, vma);
>>>> + if (orig) {
>>>> + lock_page(new_page); /* for page_add_file_rmap() */
>>>> + page_add_file_rmap(new_page, false);
>>>
>>>
>>> Shouldn't we re-check new_page->mapping after lock_page() ? Or we can't
>>> race with truncate?
>>
>> We can't race with truncate, because the file is open as binary and
>> protected with DENYWRITE (ETXTBSY).
>
> No. Yes, deny_write_access() protects mm->exe_file, but not the dynamic
> libraries or other files which can be mmaped.
I see. Let me see how we can cover this.
>
>>> and I am worried this code can try to lock the same page twice...
>>> Say, the probed application does MADV_DONTNEED and then writes "int3"
>>> into vma->vm_file at the same address to fool verify_opcode().
>>>
>>
>> Do you mean the case where old_page == new_page?
>
> Yes,
>
>> I think this won't
>> happen, because in uprobe_write_opcode() we only do orig_page for
>> !is_register case.
>
> See above.
>
> !is_register doesn't necessarily mean the original page was previously cow'ed.
> And even if it was cow'ed, MADV_DONTNEED can restore the original mapping.
I guess I know the case now. We can probably avoid this with an simp\x10le
check for old_page == new_page?
Thanks,
Song
next prev parent reply other threads:[~2019-07-25 18:17 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-24 8:35 [PATCH v8 0/4] THP aware uprobe Song Liu
2019-07-24 8:35 ` [PATCH v8 1/4] mm: move memcmp_pages() and pages_identical() Song Liu
2019-07-24 8:35 ` [PATCH v8 2/4] uprobe: use original page when all uprobes are removed Song Liu
2019-07-24 9:07 ` Oleg Nesterov
2019-07-24 9:17 ` Oleg Nesterov
2019-07-24 9:20 ` Song Liu
2019-07-24 11:37 ` Oleg Nesterov
2019-07-24 18:52 ` Song Liu
2019-07-25 8:14 ` Oleg Nesterov
2019-07-25 18:17 ` Song Liu [this message]
2019-07-26 6:07 ` Song Liu
2019-07-26 8:44 ` Oleg Nesterov
2019-07-26 21:19 ` Song Liu
2019-07-24 8:35 ` [PATCH v8 3/4] mm, thp: introduce FOLL_SPLIT_PMD Song Liu
2019-07-24 8:36 ` [PATCH v8 4/4] uprobe: use FOLL_SPLIT_PMD instead of FOLL_SPLIT Song Liu
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=A0D24D6F-B649-4B4B-8C33-70B7DCB0D814@fb.com \
--to=songliubraving@fb.com \
--cc=Kernel-team@fb.com \
--cc=akpm@linux-foundation.org \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=matthew.wilcox@oracle.com \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=william.kucharski@oracle.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;
as well as URLs for NNTP newsgroup(s).