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 000C3C0015E for ; Sat, 15 Jul 2023 01:54:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229796AbjGOBys (ORCPT ); Fri, 14 Jul 2023 21:54:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229728AbjGOByq (ORCPT ); Fri, 14 Jul 2023 21:54:46 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAD373AA1; Fri, 14 Jul 2023 18:54:42 -0700 (PDT) Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4R2rx46ZcYzhYcy; Sat, 15 Jul 2023 09:54:00 +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; Sat, 15 Jul 2023 09:54:38 +0800 Message-ID: <153b94dc-d003-fe81-eef4-332ece878af0@huawei.com> Date: Sat, 15 Jul 2023 09:54:38 +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 From: Kefeng Wang 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> <6f06f7d5-7d84-815e-699b-eef684e014b0@huawei.com> In-Reply-To: <6f06f7d5-7d84-815e-699b-eef684e014b0@huawei.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.177.243] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) 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 9:52, Kefeng Wang wrote: > > > 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." ? After recheck the code, I think Matthew' idea is 'declare vmf (struct vm_fault) earlier' like Suren said, not vm_fault_t, right? will try this, thanks. >> >>>   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. >