Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1407437rwb; Wed, 7 Dec 2022 12:41:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf7arlrZYISFMZopBKfmzIdhnnTpIrvSdhgHQv/WqR1M4m0Ae9e6t94RoM7FWQ9DoBmGMP3p X-Received: by 2002:a62:198d:0:b0:572:5a7f:9f4a with SMTP id 135-20020a62198d000000b005725a7f9f4amr75075219pfz.33.1670445660735; Wed, 07 Dec 2022 12:41:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670445660; cv=none; d=google.com; s=arc-20160816; b=UFsgRHTmY6tKBoWLGZm8qeT3gsZeOnIzKp+0KdUfw0wI88mo83WcpRtxnwo06dkf1d agDm15U41Y63PKrRkAqpDZe+bufuMrhGNm9tchkK2m5x32QjIqtessw4KcNTZ+y5hibv 6FOvHR9lbVGL0DoeWUf+7XbRHUPJ2xUJX1BSNjJW9urRoxbWY3cNwFy5Tk1f6aUSVj9w RtxlcX/bnyOYR8XH15OU96yp+vc7kmaFS+BaG5cbnJ+lOPb2f2XISebjbZQ1rmzf4GuF s9vDtJVX2NPoG/VkhyPr/tuBL0H1BgZGJMm8VlRkm3LFFgqEtDPneAvSpKGx7rsa/+MA pbnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=IJ6TW2E1hLLncShjpLbEpjeIsJ0SxMbIuMnmoV2Wa4Y=; b=S7dMMNI4zJxLGyRuz0/Ni5/cdvHZ6HC4KWPDbtK7scCP+c6ReAmuev/HHEzqQXdV0z czIb1gbmXX3Y4HYKCEudAzBTKKVDRUqLRNd+vfQ3JJuSujaCR/W4Obf4uRPnpwGtlKZx QpzAEHDrpoerpiFjte6ccmtEOJJLJOH5+6hO4YnLLbHSlvjqc9PoxMjh1cAnLwcYeU9o nx+vCae5exM3mkqAUdS9IOiKgYCEM782rB08H4nTKRpNk2BULVZLifYUp6qjh6pDtstC Pq5fX0A8VMuMuV+KW2E9iQi4HAttogS8hMchWBLvj6kH4qgYzWqC2yaARkwlrTMFZaxN AHhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=iC7vgpMD; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s11-20020a170902ea0b00b0018938988ea9si23495070plg.520.2022.12.07.12.40.50; Wed, 07 Dec 2022 12:41:00 -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=@redhat.com header.s=mimecast20190719 header.b=iC7vgpMD; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229893AbiLGUdt (ORCPT + 75 others); Wed, 7 Dec 2022 15:33:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229877AbiLGUdX (ORCPT ); Wed, 7 Dec 2022 15:33:23 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2C907E40B for ; Wed, 7 Dec 2022 12:32:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670445122; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IJ6TW2E1hLLncShjpLbEpjeIsJ0SxMbIuMnmoV2Wa4Y=; b=iC7vgpMD1kprpPJTbKrRyUt3svh17KKgXEa/L3QmSGYlHFLn5DPIs5YYg3IDRDvsC9643J Bp5b5a3GiA4/E/fI7Ir1alKClmjdETTQVhkdcpKsMc3JYNPb8fjbG+JO3RFVoeFcjT2TO6 Drg9L25wi3K1gZNMP1QY2DsK57xU/4w= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-526-TThzOUmoOVa49-e_Ar_Mew-1; Wed, 07 Dec 2022 15:32:01 -0500 X-MC-Unique: TThzOUmoOVa49-e_Ar_Mew-1 Received: by mail-qv1-f72.google.com with SMTP id 71-20020a0c804d000000b004b2fb260447so37549156qva.10 for ; Wed, 07 Dec 2022 12:32:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IJ6TW2E1hLLncShjpLbEpjeIsJ0SxMbIuMnmoV2Wa4Y=; b=xZg0+5I8pd3k9ZKQY/Ut8S4jSnK+Op4a9wLCqSv4U1qLqE64G+HrSc85Lv7iah8W4E gwibX+dcUtcbxgFbGr4xMI1EzAZ4AnIxmS6/xrbuRv3iXRc6UC3n33GZNH6La4fp3Hfo WPxaS+K/9wpNpFvrCsTeti5NspNIAFOCSnnB3GHx1cB/lhfJGsTylyGMsxdavZZuqUlK Ynrh0k1qhcq8VDaRUIqM2o3JjD6LwfifVXHy3k3YDBYV0rSnB/fOOushvAchzGQd8GAA a9TCr7Ip3SuiymPl80T9bRLNBwQ/jcNZl/bebRGeCfPt8gjWcRqP3aMnSL9ssHliv1f6 PYDg== X-Gm-Message-State: ANoB5pm0Tn0Zwob6Y5Ai1538JLZlWdIO+sIwahFlX8G9k2ols7AetQ2G d4Oe1GQxVuyvda4epCxEZne9OOYRJnJ7J0wUJULFfzutcDJ47OPZfm48D0iike754TAWAmdxsXX REPG4Y5aR9eHn4XMT2haEqaRn X-Received: by 2002:ad4:4709:0:b0:4c7:629e:7a70 with SMTP id qb9-20020ad44709000000b004c7629e7a70mr1636771qvb.44.1670445120725; Wed, 07 Dec 2022 12:32:00 -0800 (PST) X-Received: by 2002:ad4:4709:0:b0:4c7:629e:7a70 with SMTP id qb9-20020ad44709000000b004c7629e7a70mr1636758qvb.44.1670445120489; Wed, 07 Dec 2022 12:32:00 -0800 (PST) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id bm8-20020a05620a198800b006fa8299b4d5sm18007118qkb.100.2022.12.07.12.31.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 12:32:00 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Jann Horn , Andrea Arcangeli , peterx@redhat.com, James Houghton , Rik van Riel , Miaohe Lin , Nadav Amit , John Hubbard , Mike Kravetz , David Hildenbrand , Andrew Morton , Muchun Song Subject: [PATCH v2 10/10] mm/hugetlb: Document why page_vma_mapped_walk() is safe to walk Date: Wed, 7 Dec 2022 15:31:58 -0500 Message-Id: <20221207203158.651092-1-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221207203034.650899-1-peterx@redhat.com> References: <20221207203034.650899-1-peterx@redhat.com> MIME-Version: 1.0 Content-type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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 Taking vma lock here is not needed for now because all potential hugetlb walkers here should have i_mmap_rwsem held. Document the fact. Reviewed-by: Mike Kravetz Signed-off-by: Peter Xu --- mm/page_vma_mapped.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mm/page_vma_mapped.c b/mm/page_vma_mapped.c index e97b2e23bd28..2e59a0419d22 100644 --- a/mm/page_vma_mapped.c +++ b/mm/page_vma_mapped.c @@ -168,8 +168,14 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw) /* The only possible mapping was handled on last iteration */ if (pvmw->pte) return not_found(pvmw); - - /* when pud is not present, pte will be NULL */ + /* + * NOTE: we don't need explicit lock here to walk the + * hugetlb pgtable because either (1) potential callers of + * hugetlb pvmw currently holds i_mmap_rwsem, or (2) the + * caller will not walk a hugetlb vma (e.g. ksm or uprobe). + * When one day this rule breaks, one will get a warning + * in hugetlb_walk(), and then we'll figure out what to do. + */ pvmw->pte = hugetlb_walk(vma, pvmw->address, size); if (!pvmw->pte) return false; -- 2.37.3