[PATCH rfc v2 01/10] mm: add a generic VMA lock-based page fault handler
Kefeng Wang
wangkefeng.wang at huawei.com
Fri Aug 25 17:56:28 PDT 2023
On 2023/8/24 15:12, Alexander Gordeev wrote:
> On Mon, Aug 21, 2023 at 08:30:47PM +0800, Kefeng Wang wrote:
>
> Hi Kefeng,
>
>> The ARCH_SUPPORTS_PER_VMA_LOCK are enabled by more and more architectures,
>> eg, x86, arm64, powerpc and s390, and riscv, those implementation are very
>> similar which results in some duplicated codes, let's add a generic VMA
>> lock-based page fault handler try_to_vma_locked_page_fault() to eliminate
>> them, and which also make us easy to support this on new architectures.
>>
>> Since different architectures use different way to check vma whether is
>> accessable or not, the struct pt_regs, page fault error code and vma flags
>> are added into struct vm_fault, then, the architecture's page fault code
>> could re-use struct vm_fault to record and check vma accessable by each
>> own implementation.
>>
>> Signed-off-by: Kefeng Wang <wangkefeng.wang at huawei.com>
>> ---
...
>> +
>> +vm_fault_t try_vma_locked_page_fault(struct vm_fault *vmf)
>> +{
>> + vm_fault_t fault = VM_FAULT_NONE;
>> + struct vm_area_struct *vma;
>> +
>> + if (!(vmf->flags & FAULT_FLAG_USER))
>> + return fault;
>> +
>> + vma = lock_vma_under_rcu(current->mm, vmf->real_address);
>> + if (!vma)
>> + return fault;
>> +
>> + if (arch_vma_access_error(vma, vmf)) {
>> + vma_end_read(vma);
>> + return fault;
>> + }
>> +
>> + fault = handle_mm_fault(vma, vmf->real_address,
>> + vmf->flags | FAULT_FLAG_VMA_LOCK, vmf->regs);
>> +
>> + if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED)))
>> + vma_end_read(vma);
>
> Could you please explain how vma_end_read() call could be conditional?
The check is added for swap and userfault, see
https://lkml.kernel.org/r/20230630211957.1341547-4-surenb@google.com
>
>> +
>> + if (fault & VM_FAULT_RETRY)
>> + count_vm_vma_lock_event(VMA_LOCK_RETRY);
>> + else
>> + count_vm_vma_lock_event(VMA_LOCK_SUCCESS);
>> +
>> + return fault;
>> +}
>> +
>> #endif /* CONFIG_PER_VMA_LOCK */
>>
>> #ifndef __PAGETABLE_P4D_FOLDED
More information about the linux-riscv
mailing list