From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36CC8C001DD for ; Fri, 14 Jul 2023 01:52:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234097AbjGNBwy (ORCPT ); Thu, 13 Jul 2023 21:52:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231926AbjGNBww (ORCPT ); Thu, 13 Jul 2023 21:52:52 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7255C272E; Thu, 13 Jul 2023 18:52:50 -0700 (PDT) Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4R2DxQ4ZhTz18LhT; Fri, 14 Jul 2023 09:52:10 +0800 (CST) Received: from [10.174.177.243] (10.174.177.243) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 14 Jul 2023 09:52:45 +0800 Message-ID: <6f06f7d5-7d84-815e-699b-eef684e014b0@huawei.com> Date: Fri, 14 Jul 2023 09:52:45 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.10.1 Subject: Re: [PATCH rfc -next 01/10] mm: add a generic VMA lock-based page fault handler Content-Language: en-US To: Suren Baghdasaryan , Matthew Wilcox CC: , Andrew Morton , Russell King , Catalin Marinas , Will Deacon , Huacai Chen , WANG Xuerui , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexander Gordeev , Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Sven Schnelle , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , , , , , , , References: <20230713095339.189715-1-wangkefeng.wang@huawei.com> <20230713095339.189715-2-wangkefeng.wang@huawei.com> From: Kefeng Wang In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.177.243] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2023/7/14 4:12, Suren Baghdasaryan wrote: > On Thu, Jul 13, 2023 at 9:15 AM Matthew Wilcox 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 >>> >>>