From: "Li Xinhai" <lixinhai.lxh@gmail.com>
To: "Mike Kravetz" <mike.kravetz@oracle.com>,
"Michal Hocko" <mhocko@kernel.org>
Cc: "linux-mm@kvack.org" <linux-mm@kvack.org>,
kirill.shutemov <kirill.shutemov@linux.intel.com>
Subject: Re: [PATCH v2] mm/page_vma_mapped.c: Detect mismatched pfn of hugetlbfs page in pfn_in_hpage()
Date: Fri, 10 Jan 2020 06:48:07 +0800 [thread overview]
Message-ID: <2020011006480540632892@gmail.com> (raw)
In-Reply-To: <568a2f44-ad16-f3b5-4691-4e6f6ff21bf1@oracle.com>
On 2020-01-10 at 01:09 Mike Kravetz wrote:
>On 1/9/20 7:00 AM, Michal Hocko wrote:
>> [Cc Mike who is hugetlb maintainer]
>>
>> On Thu 09-01-20 14:26:02, Li Xinhai wrote:
>>> check_pte is called for hugetlbfs page and comparing pfn in pfn_in_page,
>>> where pfn is compared in range [hpage_pfn, hpage_pfn+HPAGE_PMD_NR). For
>>> hugetlbfs page, pfn must equal to hpage_pfn, so catch it as bug if they
>>> are not equal.
>>
>> Why do we need this? Would that help to debug any past bug?
>
>I have the same question as Michal. Did you see an issue where such a check
>could help?
>
>There is nothing wrong with the proposed code. However, it would be good to
>know the reason for adding it. I started looking at all possible code paths
>where this could apply. However, it would be better if you pointed out the
>concern that caused you to create the patch.
>--
>Mike Kravetz
>
oops, I didn't write the code correctly. I should wrote it as
if (pfn >= hpage_pfn && pfn - hpage_pfn < hpage_nr_pages(hpage)) {
VM_BUG_ON_PAGE(PageHuge(hpage) && pfn != hpage_pfn, hpage);
return true;
}
return false;
hpage_nr_pages(hpage) give us HPAGE_PMD_NR for THP and hugetlbfs page,
but remapping PTE to a differrnt hugetlbfs page still allowed, so put the BUG code
into this condition is necessary. By this way, if it was not a exact match for PageHuge,
then it is a bug.
>>
>>> Signed-off-by: Li Xinhai <lixinhai.lxh@gmail.com>
>>> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
>>> ---
>>> mm/page_vma_mapped.c | 1 +
>>> 1 file changed, 1 insertion(+)
>>>
>>> diff --git a/mm/page_vma_mapped.c b/mm/page_vma_mapped.c
>>> index eff4b45..713aaed 100644
>>> --- a/mm/page_vma_mapped.c
>>> +++ b/mm/page_vma_mapped.c
>>> @@ -55,6 +55,7 @@ static bool map_pte(struct page_vma_mapped_walk *pvmw)
>>> static inline bool pfn_in_hpage(struct page *hpage, unsigned long pfn)
>>> {
>>> unsigned long hpage_pfn = page_to_pfn(hpage);
>>> + VM_BUG_ON_PAGE(PageHuge(hpage) && pfn != hpage_pfn, hpage);
>>>
>>> /* THP can be referenced by any subpage */
>>> return pfn >= hpage_pfn && pfn - hpage_pfn < hpage_nr_pages(hpage);
>>> --
>>> 1.8.3.1
next prev parent reply other threads:[~2020-01-09 22:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-09 14:26 Li Xinhai
2020-01-09 14:26 ` [PATCH] mm/page_vma_mapped.c: Exactly compare hugetlbfs page's pfn " Li Xinhai
2020-01-09 14:31 ` Li Xinhai
2020-01-09 15:00 ` [PATCH v2] mm/page_vma_mapped.c: Detect mismatched pfn of hugetlbfs page " Michal Hocko
2020-01-09 17:09 ` Mike Kravetz
2020-01-09 22:48 ` Li Xinhai [this message]
2020-01-09 23:00 ` Mike Kravetz
2020-01-10 2:52 ` Li Xinhai
2020-01-10 6:22 ` Michal Hocko
2020-01-10 7:11 ` Li Xinhai
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=2020011006480540632892@gmail.com \
--to=lixinhai.lxh@gmail.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=mike.kravetz@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