From: Miaohe Lin <linmiaohe@huawei.com>
To: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Ying Huang <ying.huang@intel.com>, <peterx@redhat.com>,
<apopple@nvidia.com>, <osalvador@suse.de>,
<mike.kravetz@oracle.com>, <songmuchun@bytedance.com>,
<hch@lst.de>, <dhowells@redhat.com>, <cl@linux.com>,
<linux-mm@kvack.org>, <linux-kernel@vger.kernel.org>,
<akpm@linux-foundation.org>, <naoya.horiguchi@nec.com>
Subject: Re: [PATCH v4 1/4] mm: reduce the rcu lock duration
Date: Wed, 1 Jun 2022 14:33:02 +0800 [thread overview]
Message-ID: <e10023d7-3d19-1edf-86af-4cb79071b78f@huawei.com> (raw)
In-Reply-To: <87bkvdfzvm.fsf@email.froward.int.ebiederm.org>
On 2022/6/1 0:09, Eric W. Biederman wrote:
> Miaohe Lin <linmiaohe@huawei.com> writes:
snip
>>
>> "
>> Commit 3268c63eded4 ("mm: fix move/migrate_pages() race on task struct")
>> extends the period of the rcu_read_lock until after the permissions checks
>> are done because it suspects the permissions checks are not safe unless
>> performed under both rcu_read_lock and task_lock to ensure the task<->mm
>> association does not change on us while we are working [1]. But extended
>> rcu read lock does not add much value. Because after permission checking
>> the permission may still be changed. There's no much difference. So it's
>> unnecessary to extend the period of the rcu_read_lock. Release the rcu
>> lock after task refcount is successfully grabbed to reduce the rcu holding
>> time.
>>
>> [1] https://lore.kernel.org/lkml/87sjhzun47.fsf@xmission.com/
>> "
>
> It doesn't make sense to me.
>
> I don't see any sleeping functions called from find_mm_struct or
> kernel_migrate_pages in the area kernel_migrate_pages in the area of the
> code protected by get_task_struct. So at a very basic level I see a
> justification for dirtying a cache line twice with get_task_struct and
> put_task_struct to reduce rcu_read_lock hold times.
>
> I would contend that a reasonable cleanup based up on the current state
> of the code would be to extend the rcu_read_lock over get_task_mm so
If so, security_task_movememory will be called inside rcu lock. It might
call sleeping functions, e.g. smack_log(). I think it's not a good idea.
> that a reference to task_struct does not need to be taken. That has
> the potential to reduce contention and reduce lock hold times.
>
>
> The code is missing a big fat comment with the assertion that it is ok
> if the permission checks are racy because the race is small, and the
> worst case thing that happens is the page is migrated to another
> numa node.
>
>
> Given that the get_mm_task takes task_lock the cost of dirtying the
> cache line is already being paid. Perhaps not extending task_lock hold
> times a little bit is justified, but I haven't seen that case made.
>
> This seems like code that is called little enough it would be better for
> it to be correct, and not need big fat comments explaining why it
> doesn't matter that they code is deliberately buggy.
>
Agree. A big fat comments will make code hard to follow.
>
> In short it does not make sense to me to justify a patch for performance
> reasons when it appears that extending the rcu_read_lock hold time and
> not touch the task reference count would stop dirtying a cache line and
> likely have more impact.
IMHO, incremented task refcount should make code works correctly. And extending
the rcu_read_lock over get_task_mm will break the things because sleeping functions
might be called while holding rcu lock.
Does the patch itself makes sense for you? Should I rephase the commit log further?
I'm afraid I didn't get your point correctly.
>
> Eric
Thanks!
> .
>
next prev parent reply other threads:[~2022-06-01 6:33 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-30 11:30 [PATCH v4 0/4] A few cleanup and fixup patches for migration Miaohe Lin
2022-05-30 11:30 ` [PATCH v4 1/4] mm: reduce the rcu lock duration Miaohe Lin
2022-05-31 6:06 ` Ying Huang
2022-05-31 9:01 ` Miaohe Lin
2022-05-31 16:09 ` Eric W. Biederman
2022-06-01 6:33 ` Miaohe Lin [this message]
2022-06-01 14:37 ` Eric W. Biederman
2022-06-02 9:22 ` Miaohe Lin
2022-06-03 16:28 ` Eric W. Biederman
2022-06-07 9:19 ` Miaohe Lin
2022-06-18 0:23 ` Andrew Morton
2022-06-18 2:49 ` Miaohe Lin
2022-05-31 12:50 ` David Hildenbrand
2022-05-31 12:58 ` Matthew Wilcox
2022-05-31 13:05 ` Matthew Wilcox
2022-06-01 3:21 ` Miaohe Lin
2022-05-30 11:30 ` [PATCH v4 2/4] mm/migration: remove unneeded lock page and PageMovable check Miaohe Lin
2022-05-31 12:50 ` David Hildenbrand
2022-05-30 11:30 ` [PATCH v4 3/4] mm/migration: return errno when isolate_huge_page failed Miaohe Lin
2022-05-30 11:30 ` [PATCH v4 4/4] mm/migration: fix potential pte_unmap on an not mapped pte Miaohe Lin
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=e10023d7-3d19-1edf-86af-4cb79071b78f@huawei.com \
--to=linmiaohe@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=cl@linux.com \
--cc=dhowells@redhat.com \
--cc=ebiederm@xmission.com \
--cc=hch@lst.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mike.kravetz@oracle.com \
--cc=naoya.horiguchi@nec.com \
--cc=osalvador@suse.de \
--cc=peterx@redhat.com \
--cc=songmuchun@bytedance.com \
--cc=ying.huang@intel.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).