Re: [PATCH v12 5/6] khugepaged: enable collapse pmd for pte-mapped THP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




> On Aug 9, 2019, at 8:24 AM, Oleg Nesterov <oleg@xxxxxxxxxx> wrote:
> 
> On 08/08, Song Liu wrote:
>> 
>>> On Aug 8, 2019, at 9:33 AM, Oleg Nesterov <oleg@xxxxxxxxxx> wrote:
>>> 
>>>> +	for (i = 0, addr = haddr; i < HPAGE_PMD_NR; i++, addr += PAGE_SIZE) {
>>>> +		pte_t *pte = pte_offset_map(pmd, addr);
>>>> +		struct page *page;
>>>> +
>>>> +		if (pte_none(*pte))
>>>> +			continue;
>>>> +
>>>> +		page = vm_normal_page(vma, addr, *pte);
> 
> just noticed... shouldn't you also check pte_present() before
> vm_normal_page() ?

Good catch! Let me fix this. 

> 
>>>> +		if (!page || !PageCompound(page))
>>>> +			return;
>>>> +
>>>> +		if (!hpage) {
>>>> +			hpage = compound_head(page);
>>> 
>>> OK,
>>> 
>>>> +			if (hpage->mapping != vma->vm_file->f_mapping)
>>>> +				return;
>>> 
>>> is it really possible? May be WARN_ON(hpage->mapping != vm_file->f_mapping)
>>> makes more sense ?
>> 
>> I haven't found code paths lead to this,
> 
> Neither me, that is why I asked. I think this should not be possible,
> but again this is not my area.
> 
>> but this is technically possible.
>> This pmd could contain subpages from different THPs.
> 
> Then please explain how this can happen ?
> 
>> The __replace_page()
>> function in uprobes.c creates similar pmd.
> 
> No it doesn't,
> 
>> Current uprobe code won't really create this problem, because
>> !PageCompound() check above is sufficient. But it won't be difficult to
>> modify uprobe code to break this.
> 
> I bet it will be a) difficult and b) the very idea to do this would be wrong.
> 
>> For this code to be accurate and safe,
>> I think both this check and the one below are necessary.
> 
> I didn't suggest to remove these checks.
> 
>> Also, this code
>> is not on any critical path, so the overhead should be negligible.
> 
> I do not care about overhead. But I do care about a poor reader like me
> who will try to understand this code.
> 
> If you too do not understand how a THP page can have a different mapping
> then use VM_WARN or at least add a comment to explain that this is not
> supposed to happen!

Fair enough. I will add WARN and more comments. 

Thanks,
Song





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux