[PATCH rfc -next 01/10] mm: add a generic VMA lock-based page fault handler
Kefeng Wang
wangkefeng.wang at huawei.com
Thu Jul 13 18:52:45 PDT 2023
On 2023/7/14 4:12, Suren Baghdasaryan wrote:
> On Thu, Jul 13, 2023 at 9:15 AM Matthew Wilcox <willy at infradead.org> wrote:
>>
>>> +int try_vma_locked_page_fault(struct vm_locked_fault *vmlf, vm_fault_t *ret)
>>> +{
>>> + struct vm_area_struct *vma;
>>> + vm_fault_t fault;
>>
>>
>> On Thu, Jul 13, 2023 at 05:53:29PM +0800, Kefeng Wang wrote:
>>> +#define VM_LOCKED_FAULT_INIT(_name, _mm, _address, _fault_flags, _vm_flags, _regs, _fault_code) \
>>> + _name.mm = _mm; \
>>> + _name.address = _address; \
>>> + _name.fault_flags = _fault_flags; \
>>> + _name.vm_flags = _vm_flags; \
>>> + _name.regs = _regs; \
>>> + _name.fault_code = _fault_code
>>
>> More consolidated code is a good idea; no question. But I don't think
>> this is the right way to do it.
I agree it is not good enough, but the arch's vma check acess has
different implementation, some use vm flags, some need fault code and
regs, and some use both :(
>>
>>> +int __weak arch_vma_check_access(struct vm_area_struct *vma,
>>> + struct vm_locked_fault *vmlf);
>>
>> This should be:
>>
>> #ifndef vma_check_access
>> bool vma_check_access(struct vm_area_struct *vma, )
>> {
>> return (vma->vm_flags & vm_flags) == 0;
>> }
>> #endif
>>
>> and then arches which want to do something different can just define
>> vma_check_access.
Ok, I could convert to use this way.
>>
>>> +int try_vma_locked_page_fault(struct vm_locked_fault *vmlf, vm_fault_t *ret)
>>> +{
>>> + struct vm_area_struct *vma;
>>> + vm_fault_t fault;
>>
>> Declaring the vmf in this function and then copying it back is just wrong.
>> We need to declare vm_fault_t earlier (in the arch fault handler) and
>> pass it in.
Actually I passed the vm_fault_t *ret(in the arch fault handler), we
could directly use *ret instead of a new local variable, and no copy.
>
> Did you mean to say "we need to declare vmf (struct vm_fault) earlier
> (in the arch fault handler) and pass it in." ?
>
>> I don't think that creating struct vm_locked_fault is the
>> right idea either.
As mentioned above for vma check access, we need many arguments for a
function, a new struct looks possible better, is there better solution
or any suggestion?
Thanks.
>>
>>> + if (!(vmlf->fault_flags & FAULT_FLAG_USER))
>>> + return -EINVAL;
>>> +
>>> + vma = lock_vma_under_rcu(vmlf->mm, vmlf->address);
>>> + if (!vma)
>>> + return -EINVAL;
>>> +
>>> + if (arch_vma_check_access(vma, vmlf)) {
>>> + vma_end_read(vma);
>>> + return -EINVAL;
>>> + }
>>> +
>>> + fault = handle_mm_fault(vma, vmlf->address,
>>> + vmlf->fault_flags | FAULT_FLAG_VMA_LOCK,
>>> + vmlf->regs);
>>> + *ret = fault;
>>> +
>>> + if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED)))
>>> + vma_end_read(vma);
>>> +
>>> + if ((fault & VM_FAULT_RETRY))
>>> + count_vm_vma_lock_event(VMA_LOCK_RETRY);
>>> + else
>>> + count_vm_vma_lock_event(VMA_LOCK_SUCCESS);
>>> +
>>> + return 0;
>>> +}
>>> +
>>> #endif /* CONFIG_PER_VMA_LOCK */
>>>
>>> #ifndef __PAGETABLE_P4D_FOLDED
>>> --
>>> 2.27.0
>>>
>>>
More information about the linux-arm-kernel
mailing list