Re: [RFC][PATCH 6/8] mm: handle_speculative_fault()

From: Minchan Kim
Date: Mon Jan 04 2010 - 23:29:47 EST


Hi, Kame.

On Tue, Jan 5, 2010 at 9:25 AM, KAMEZAWA Hiroyuki
<kamezawa.hiroyu@xxxxxxxxxxxxxx> wrote:
> On Mon, 04 Jan 2010 19:24:35 +0100
> Peter Zijlstra <a.p.zijlstra@xxxxxxxxx> wrote:
>
>> Generic speculative fault handler, tries to service a pagefault
>> without holding mmap_sem.
>>
>> Signed-off-by: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
>
>
> I'm sorry if I miss something...how does this patch series avoid
> that vma is removed while __do_fault()->vma->vm_ops->fault() is called ?
> ("vma is removed" means all other things as freeing file struct etc..)

Isn't it protected by get_file and iget?
Am I miss something?

>
> Thanks,
> -Kame
>
>
>
>
>> ---
>> Âinclude/linux/mm.h | Â Â2 +
>> Âmm/memory.c    Â|  59 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
>> Â2 files changed, 60 insertions(+), 1 deletion(-)
>>
>> Index: linux-2.6/mm/memory.c
>> ===================================================================
>> --- linux-2.6.orig/mm/memory.c
>> +++ linux-2.6/mm/memory.c
>> @@ -1998,7 +1998,7 @@ again:
>> Â Â Â if (!*ptep)
>> Â Â Â Â Â Â Â goto out;
>>
>> - Â Â if (vma_is_dead(vma, seq))
>> + Â Â if (vma && vma_is_dead(vma, seq))
>> Â Â Â Â Â Â Â goto unlock;
>>
>> Â Â Â unpin_page_tables();
>> @@ -3112,6 +3112,63 @@ int handle_mm_fault(struct mm_struct *mm
>> Â Â Â return handle_pte_fault(mm, vma, address, entry, pmd, flags, 0);
>> Â}
>>
>> +int handle_speculative_fault(struct mm_struct *mm, unsigned long address,
>> + Â Â Â Â Â Â unsigned int flags)
>> +{
>> + Â Â pmd_t *pmd = NULL;
>> + Â Â pte_t *pte, entry;
>> + Â Â spinlock_t *ptl;
>> + Â Â struct vm_area_struct *vma;
>> + Â Â unsigned int seq;
>> + Â Â int ret = VM_FAULT_RETRY;
>> + Â Â int dead;
>> +
>> + Â Â __set_current_state(TASK_RUNNING);
>> + Â Â flags |= FAULT_FLAG_SPECULATIVE;
>> +
>> + Â Â count_vm_event(PGFAULT);
>> +
>> + Â Â rcu_read_lock();
>> + Â Â if (!pte_map_lock(mm, NULL, address, pmd, flags, 0, &pte, &ptl))
>> + Â Â Â Â Â Â goto out_unlock;
>> +
>> + Â Â vma = find_vma(mm, address);
>> +
>> + Â Â if (!vma)
>> + Â Â Â Â Â Â goto out_unmap;
>> +
>> + Â Â dead = RB_EMPTY_NODE(&vma->vm_rb);
>> + Â Â seq = vma->vm_sequence.sequence;
>> + Â Â /*
>> + Â Â Â* Matches both the wmb in write_seqcount_begin/end() and
>> + Â Â Â* the wmb in detach_vmas_to_be_unmapped()/__unlink_vma().
>> + Â Â Â*/
>> + Â Â smp_rmb();
>> + Â Â if (dead || seq & 1)
>> + Â Â Â Â Â Â goto out_unmap;
>> +
>> + Â Â if (!(vma->vm_end > address && vma->vm_start <= address))
>> + Â Â Â Â Â Â goto out_unmap;
>> +
>> + Â Â if (read_seqcount_retry(&vma->vm_sequence, seq))
>> + Â Â Â Â Â Â goto out_unmap;
>> +
>> + Â Â entry = *pte;
>> +
>> + Â Â pte_unmap_unlock(pte, ptl);
>> +
>> + Â Â ret = handle_pte_fault(mm, vma, address, entry, pmd, flags, seq);
>> +
>> +out_unlock:
>> + Â Â rcu_read_unlock();
>> + Â Â return ret;
>> +
>> +out_unmap:
>> + Â Â pte_unmap_unlock(pte, ptl);
>> + Â Â goto out_unlock;
>> +}
>> +
>> +
>> Â#ifndef __PAGETABLE_PUD_FOLDED
>> Â/*
>> Â * Allocate page upper directory.
>> Index: linux-2.6/include/linux/mm.h
>> ===================================================================
>> --- linux-2.6.orig/include/linux/mm.h
>> +++ linux-2.6/include/linux/mm.h
>> @@ -829,6 +829,8 @@ int invalidate_inode_page(struct page *p
>> Â#ifdef CONFIG_MMU
>> Âextern int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
>> Â Â Â Â Â Â Â Â Â Â Â unsigned long address, unsigned int flags);
>> +extern int handle_speculative_fault(struct mm_struct *mm,
>> + Â Â Â Â Â Â Â Â Â Â unsigned long address, unsigned int flags);
>> Â#else
>> Âstatic inline int handle_mm_fault(struct mm_struct *mm,
>> Â Â Â Â Â Â Â Â Â Â Â struct vm_area_struct *vma, unsigned long address,
>>
>> --
>>
>>
>
>



--
Kind regards,
Minchan Kim
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/