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 DD5BDC32771 for ; Sat, 24 Sep 2022 13:12:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229483AbiIXNL7 (ORCPT ); Sat, 24 Sep 2022 09:11:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229669AbiIXNL4 (ORCPT ); Sat, 24 Sep 2022 09:11:56 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE5079F0CB for ; Sat, 24 Sep 2022 06:11:51 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MZTnN6kMRzHtft; Sat, 24 Sep 2022 21:07:04 +0800 (CST) Received: from [10.174.151.185] (10.174.151.185) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Sat, 24 Sep 2022 21:11:48 +0800 Subject: Re: [PATCH v2 6/9] hugetlb: add vma based lock for pmd sharing To: Mike Kravetz , , CC: Muchun Song , David Hildenbrand , Sven Schnelle , Michal Hocko , Peter Xu , Naoya Horiguchi , "Aneesh Kumar K . V" , Andrea Arcangeli , "Kirill A . Shutemov" , Davidlohr Bueso , Prakash Sangappa , James Houghton , Mina Almasry , Pasha Tatashin , Axel Rasmussen , Ray Fucillo , Andrew Morton References: <20220914221810.95771-1-mike.kravetz@oracle.com> <20220914221810.95771-7-mike.kravetz@oracle.com> From: Miaohe Lin Message-ID: <2b1b6d09-0188-23a3-6ac3-6e81446a10e4@huawei.com> Date: Sat, 24 Sep 2022 21:11:48 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <20220914221810.95771-7-mike.kravetz@oracle.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.151.185] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022/9/15 6:18, Mike Kravetz wrote: > Allocate a new hugetlb_vma_lock structure and hang off vm_private_data > for synchronization use by vmas that could be involved in pmd sharing. > This data structure contains a rw semaphore that is the primary tool > used for synchronization. > > This new structure is ref counted, so that it can exist when NOT attached > to a vma. This is only helpful in resolving lock ordering issues where > code may need to obtain the vma_lock while there are no guarantees the > vma may go away. By obtaining a ref on the structure, it can be > guaranteed that at least the rw semaphore will not go away. > > Only add infrastructure for the new lock here. Actual use will be added > in subsequent patches. > > Signed-off-by: Mike Kravetz LGTM with some nits below. Thanks for your work, Mike. Reviewed-by: Miaohe Lin > -/* Reset counters to 0 and clear all HPAGE_RESV_* flags */ > -void reset_vma_resv_huge_pages(struct vm_area_struct *vma) > +void hugetlb_dup_vma_private(struct vm_area_struct *vma) > { > VM_BUG_ON_VMA(!is_vm_hugetlb_page(vma), vma); > + /* > + * Clear vm_private_data > + * - For MAP_PRIVATE mappings, this is the reserve map which does > + * not apply to children. Faults generated by the children are > + * not guaranteed to succeed, even if read-only. > + * - For shared mappings this is a per-vma semaphore that may be > + * allocated in a subsequent call to hugetlb_vm_op_open. > + */ > + vma->vm_private_data = (void *)0; > if (!(vma->vm_flags & VM_MAYSHARE)) > - vma->vm_private_data = (void *)0; > + return; This if block can be deleted ? It doesn't do anything here. > } > > /* > +static void hugetlb_vma_lock_free(struct vm_area_struct *vma) > +{ > + /* > + * Only present in sharable vmas. See comment in > + * __unmap_hugepage_range_final about how VM_SHARED could > + * be set without VM_MAYSHARE. As a result, we need to > + * check if either is set in the free path. > + */ > + if (!vma || !(vma->vm_flags & (VM_MAYSHARE | VM_SHARED))) > + return; > + > + if (vma->vm_private_data) { > + struct hugetlb_vma_lock *vma_lock = vma->vm_private_data; > + > + /* > + * vma_lock structure may or not be released, but it may or not be released? Thanks, Miaohe Lin