Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp4674875rwb; Mon, 21 Nov 2022 10:21:58 -0800 (PST) X-Google-Smtp-Source: AA0mqf5ucVfsN7Qku+fGN8RChqUgqpwwPXv2rMEurOGKQ4EQ3XHBXLD5wFi5AIhAsvUaeJ2+4dVN X-Received: by 2002:a17:906:cedc:b0:7ad:e8dd:837c with SMTP id si28-20020a170906cedc00b007ade8dd837cmr17598164ejb.264.1669054918700; Mon, 21 Nov 2022 10:21:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669054918; cv=none; d=google.com; s=arc-20160816; b=fqfEwIziADn/KUC35i8S1c63Dqt3gM14RP6PB7j1SlQD2cGyXxNpEVR74Id0NXI3vT lVMIXsHhw02qc4pQS+uz/zTVDTS4903L8oBkv7ADL8STh78VdYTKv0CjmpVQJgI45pw+ XNgD0zd4Z9XxqPyCPi631iLgu6wRGxiH/avBf03wlDWUZHef9tZyVtwFozUprk6wgPMl n3T8Z4JjZTRpH1BbjtB7fqgwPCmtIOh7b72O6CTEHOJkMzvGdUPSVo5jZoCgZXKNfyF5 PyL1eii9EkjNtcQzwXACBGLW3ArWsg6qE6N8z+tfUEXuVYeoF6iXMHOtf8Sw5ONEUWlX mxKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=z2svw9m4hShuPYQWl2tT3FssDOjrSODKLzg/rFvOD00=; b=PX88pKThLDZS39XZCBUHx0Dt6NniNmstYkyTBVTcyGghGFEXRTIkFtqOpuZ0+dmlz5 pQCjw1V3BJUMbB4XvALOwSNW0evYkndDXXfgb/pVyo8suUOIkM6uDfwJtDzWodYaIIJC lPEtG7sEaD3dwr9j7UNjv3NQBjqFF7RYcFjTUmGW04EIb64p1CXqV6GdO9o1cPNisFgF +9ElQtRaeqJHvtxnHJNzjVhNizIhgfNQ8EkrfNC/SErlVHmhFSmeaat77at+ucTUNvMk jYOni6X79/PZlNfgqDhkj+iglYDXC51/ANQKNNu3HPwxZO2VzL3Khbdx7qIIF9AySVFo UUqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=SIlkGVLL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z14-20020a05640240ce00b004599ae68f98si10412864edb.136.2022.11.21.10.21.24; Mon, 21 Nov 2022 10:21:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=SIlkGVLL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230484AbiKUSLi (ORCPT + 91 others); Mon, 21 Nov 2022 13:11:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229586AbiKUSLg (ORCPT ); Mon, 21 Nov 2022 13:11:36 -0500 Received: from mail-yb1-xb34.google.com (mail-yb1-xb34.google.com [IPv6:2607:f8b0:4864:20::b34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 869DAA3160 for ; Mon, 21 Nov 2022 10:11:35 -0800 (PST) Received: by mail-yb1-xb34.google.com with SMTP id 205so14518140ybe.7 for ; Mon, 21 Nov 2022 10:11:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=z2svw9m4hShuPYQWl2tT3FssDOjrSODKLzg/rFvOD00=; b=SIlkGVLLgwYG5rPEVqALwDpK5SHqK/y9LnUUK8sVNkLF7W6MirOINonE5mqsMMZQif g5SGQCRUK60Ighv3wVx2Kqdd2+0S3NyQvGxY6bqfeYPUW2BJH5WKhTLWYuZTpBiJ4jr0 lNdLVN7MSFkhOk6So8zvSzcbk8wFneJ/KR8D4VMWR3VWUge/E3YBKtWMWE5MmflHpyV3 aoCXeUdbOBxPu1+yON+q31shNMgTpakr2WN47D7nzc6lERREC08aW/g5R99banHTwu+Z Bs+2lv7CUsoIDxMKc4wnmDO0SWEG97ugzjjau8ws4Nyx+D2FsURDYQFgY+XY85ha2HEk kcvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=z2svw9m4hShuPYQWl2tT3FssDOjrSODKLzg/rFvOD00=; b=CHgnRFIewyNbNEGi0rlcxKf/UYZvtkkn99FP1kIArDgf25AjOlWWw+Fjxj19+zYydQ 2e547fyQHnDy5uRLudojPi1QSCdShGV1CfoxwtUmNKI44NAoyrqoAqFZaibehcOVqNc9 e7RnEbOzKmmEMnXCaeiHiSe51Un/qIpqWKuUnM6icDATQzHsxkcXe5heKlZXeRxdrMzL 9Lv++YB71Z+hHA0gxmnQ3AZNPEW3JMcvB3tDJnc3Qa+8+sgXKVCwUqUct0eJGdMgrTnJ zwLzjxOXhpcQdfDSY4xMp7kBgGaGHx/eGY5hFW4So/l8y/EqcRHaLaLOpoU9JRmvCdjX 4ezw== X-Gm-Message-State: ANoB5pmLJJxqdtc58zzRF+t0DsM+bNzswcU/rvWs5F+03wkvjHxYknls L0deSiDhhMgWvwmHwE9IqadvYWsr1ApUX60ORN6nTg== X-Received: by 2002:a05:6902:118e:b0:6e7:f54:b3d6 with SMTP id m14-20020a056902118e00b006e70f54b3d6mr2633115ybu.577.1669054294659; Mon, 21 Nov 2022 10:11:34 -0800 (PST) MIME-Version: 1.0 References: <20221021163703.3218176-1-jthoughton@google.com> <20221021163703.3218176-6-jthoughton@google.com> In-Reply-To: From: James Houghton Date: Mon, 21 Nov 2022 10:11:23 -0800 Message-ID: Subject: Re: [RFC PATCH v2 05/47] hugetlb: make hugetlb_vma_lock_alloc return its failure reason To: Peter Xu Cc: Mike Kravetz , Muchun Song , David Hildenbrand , David Rientjes , Axel Rasmussen , Mina Almasry , "Zach O'Keefe" , Manish Mishra , Naoya Horiguchi , "Dr . David Alan Gilbert" , "Matthew Wilcox (Oracle)" , Vlastimil Babka , Baolin Wang , Miaohe Lin , Yang Shi , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 16, 2022 at 9:08 AM Peter Xu wrote: > > No objection on the patch itself, but I am just wondering what guarantees > thread-safety for this function to not leak vm_private_data when two > threads try to allocate at the same time. > > I think it should be the write mmap lock. I saw that in your latest code > base there's: > > /* > * We must hold the mmap lock for writing so that callers can rely on > * hugetlb_hgm_enabled returning a consistent result while holding > * the mmap lock for reading. > */ > mmap_assert_write_locked(vma->vm_mm); > > /* HugeTLB HGM requires the VMA lock to synchronize collapsing. */ > ret = hugetlb_vma_data_alloc(vma); > if (ret) > return ret; > > So that's covered there. The rest places are hugetlb_vm_op_open() and > hugetlb_reserve_pages() and they all seem fine too: hugetlb_vm_op_open() is > during mmap(), the latter has vma==NULL so allocation will be skipped. > > I'm wondering whether it would make sense to move this assert to be inside > of hugetlb_vma_data_alloc() after the !vma check, or just add the same > assert too but for different reason. I think leaving the assert here and adding a new assert inside hugetlb_vma_data_alloc() makes sense. Thanks Peter. - James > > > > > vma_lock = kmalloc(sizeof(*vma_lock), GFP_KERNEL); > > if (!vma_lock) { > > @@ -7026,13 +7026,14 @@ static void hugetlb_vma_lock_alloc(struct vm_area_struct *vma) > > * allocation failure. > > */ > > pr_warn_once("HugeTLB: unable to allocate vma specific lock\n"); > > - return; > > + return -ENOMEM; > > } > > > > kref_init(&vma_lock->refs); > > init_rwsem(&vma_lock->rw_sema); > > vma_lock->vma = vma; > > vma->vm_private_data = vma_lock; > > + return 0; > > } > > > > /* > > @@ -7160,8 +7161,9 @@ static void hugetlb_vma_lock_free(struct vm_area_struct *vma) > > { > > } > > > > -static void hugetlb_vma_lock_alloc(struct vm_area_struct *vma) > > +static int hugetlb_vma_lock_alloc(struct vm_area_struct *vma) > > { > > + return 0; > > } > > > > pte_t *huge_pmd_share(struct mm_struct *mm, struct vm_area_struct *vma, > > -- > > 2.38.0.135.g90850a2211-goog > > > > > > -- > Peter Xu >