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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C11CC43217 for ; Wed, 16 Nov 2022 17:08:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8C7596B0072; Wed, 16 Nov 2022 12:08:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 877476B0073; Wed, 16 Nov 2022 12:08:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 718DF8E0001; Wed, 16 Nov 2022 12:08:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 63EA46B0072 for ; Wed, 16 Nov 2022 12:08:16 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id F0A171406CE for ; Wed, 16 Nov 2022 17:08:15 +0000 (UTC) X-FDA: 80139938550.19.8672A20 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf22.hostedemail.com (Postfix) with ESMTP id B01EBC0015 for ; Wed, 16 Nov 2022 17:08:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668618493; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=HqxuMjyuv4ZVgzjzmUzOoU3sDZ8+2sjayvk5TJWhlqI=; b=QReta4GYnQDwPFlhBeJyeaBzD8MbpBVUwRBTtrSRQN/nO9UKxyBRq/UhE+NOd9R6/ZJz/N pTEFc1pYdIpneW+kpxku7GNUDi+MD/9zNtFY+DOdfZC2ACo4sWkrc0b2f1m1Figa89gs/U d01xGlxZckU0r9L/uNf+iaUl8GnTrho= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-553-dXGl3BsUMnOBAx1uMwiewA-1; Wed, 16 Nov 2022 12:08:12 -0500 X-MC-Unique: dXGl3BsUMnOBAx1uMwiewA-1 Received: by mail-qk1-f198.google.com with SMTP id i17-20020a05620a249100b006fa2e10a2ecso17985078qkn.16 for ; Wed, 16 Nov 2022 09:08:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=HqxuMjyuv4ZVgzjzmUzOoU3sDZ8+2sjayvk5TJWhlqI=; b=TsmxkvD53ZipkXu9d/amClRBhX95sj2JKf5icgy9shjT5tb5l54abUJMt0rMtOtHek HMwyMXQKrmpMK+VFhrnJsen5IiK94Cke7IDparlNFmKxVaYCKXOiaMB2S6O8cavmhtcj WZaA8C1DZLknqxwGjMx+xpaNw9Kb7E1/GZNdInABC4Omm86g2hcubVDiXT8beKci6Pb+ r5IAnduttKCNLJtNydUrNfUKPj1AF6spDGEEDH0bLAsiP5iXPUX/lVCyVjaL9hr6kCp5 mWc17GKxgVwvxk2N0/7UAR+qlq9qSdKLCfq+eojMVxzx3SqrQrMwCb/S55mzHZls8eSL R6ZQ== X-Gm-Message-State: ANoB5pmnq7DC2a8BnPEtU5u80cmM9mhEqG8rEQe9SFzl9QmpTDwFiNXK gG6SdlWA3os2/qmtGFlgg4XBro0wH7JdON6AjuqCdqD+lZVRvi7HWjQ5K2AORn4H1G04j+rjGvX bARNOLfGo1zA= X-Received: by 2002:ac8:690:0:b0:39c:f63c:18b4 with SMTP id f16-20020ac80690000000b0039cf63c18b4mr22064078qth.17.1668618492095; Wed, 16 Nov 2022 09:08:12 -0800 (PST) X-Google-Smtp-Source: AA0mqf4rOP5n0Q/DNXZe7qm0eHphYe40gE/EYhfx2rdQvr+4Me7E9o/jzYLYg4jLPIycPd2brO0uLg== X-Received: by 2002:ac8:690:0:b0:39c:f63c:18b4 with SMTP id f16-20020ac80690000000b0039cf63c18b4mr22064050qth.17.1668618491817; Wed, 16 Nov 2022 09:08:11 -0800 (PST) Received: from x1n (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id s1-20020a05620a0bc100b006faaf6dc55asm10492098qki.22.2022.11.16.09.08.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Nov 2022 09:08:11 -0800 (PST) Date: Wed, 16 Nov 2022 12:08:09 -0500 From: Peter Xu To: James Houghton 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 Subject: Re: [RFC PATCH v2 05/47] hugetlb: make hugetlb_vma_lock_alloc return its failure reason Message-ID: References: <20221021163703.3218176-1-jthoughton@google.com> <20221021163703.3218176-6-jthoughton@google.com> MIME-Version: 1.0 In-Reply-To: <20221021163703.3218176-6-jthoughton@google.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668618495; a=rsa-sha256; cv=none; b=CX/fFsw4X1ab2N4e/oFdmXXdwUs7jHZERiJ4rSR0CEcGzeK53E7swarhd+3t9tmnM9+UVp tOrqpUq1jY//gcvSeXDMhMnSxILzOQJ2KBfieNCfHRftCpUGWcyunR48H+uKT9RZoBu3md iv88n35jzIC5t6uNO3s6juLDKyBsTig= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QReta4GY; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf22.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668618495; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=HqxuMjyuv4ZVgzjzmUzOoU3sDZ8+2sjayvk5TJWhlqI=; b=d4TiLFYU6LTrC3vdWCcEZjfNffx8wq41e+oCCD9YWwSslCoFNC6Omt6oVyg5Dt93EM8560 CevdKfVuWB4icbtAJBqwRx3a9p+zYdTUsCK+jT2Ljcg7Wzb2zAESuDUzY2mjPt2TkT8S7G bHHBtxiNpvbGAQjCoxT05UVQ6NmOp5M= X-Rspam-User: Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QReta4GY; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf22.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com X-Rspamd-Server: rspam02 X-Stat-Signature: 3morq13cst43hep3jq5a154j1gansy5u X-Rspamd-Queue-Id: B01EBC0015 X-HE-Tag: 1668618494-294126 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, Oct 21, 2022 at 04:36:21PM +0000, James Houghton wrote: > Currently hugetlb_vma_lock_alloc doesn't return anything, as there is no > need: if it fails, PMD sharing won't be enabled. However, HGM requires > that the VMA lock exists, so we need to verify that > hugetlb_vma_lock_alloc actually succeeded. If hugetlb_vma_lock_alloc > fails, then we can pass that up to the caller that is attempting to > enable HGM. > > Signed-off-by: James Houghton > --- > mm/hugetlb.c | 16 +++++++++------- > 1 file changed, 9 insertions(+), 7 deletions(-) > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index 52cec5b0789e..dc82256b89dd 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -92,7 +92,7 @@ struct mutex *hugetlb_fault_mutex_table ____cacheline_aligned_in_smp; > /* Forward declaration */ > static int hugetlb_acct_memory(struct hstate *h, long delta); > 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); > static void __hugetlb_vma_unlock_write_free(struct vm_area_struct *vma); > > static inline bool subpool_is_free(struct hugepage_subpool *spool) > @@ -7001,17 +7001,17 @@ 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) > { > struct hugetlb_vma_lock *vma_lock; > > /* Only establish in (flags) sharable vmas */ > if (!vma || !(vma->vm_flags & VM_MAYSHARE)) > - return; > + return -EINVAL; > > - /* Should never get here with non-NULL vm_private_data */ > + /* We've already allocated the lock. */ > if (vma->vm_private_data) > - return; > + return 0; 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. > > 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