Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1317459rwb; Tue, 29 Nov 2022 11:49:51 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Db/ue75O6PZohBI+s3qA2IX7AEXcQbrwxBkxTjY1SyatKcguzv/QgN6wEtPI7EU8XGVQl X-Received: by 2002:a17:906:d782:b0:7bc:9d14:a2db with SMTP id pj2-20020a170906d78200b007bc9d14a2dbmr18872861ejb.770.1669751391136; Tue, 29 Nov 2022 11:49:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669751391; cv=none; d=google.com; s=arc-20160816; b=PRZ9l8AQmBPrL83PV+RBbYI4ouZKu8M0LSrOjf/0WYo+DtmyyFoAmwgV7Od4V1qepk FMcjQ+uLJnvZy/AMJRs6GO9tsO3vaRNG0Dkq57ZjEHgBeJzafY7R1R4EzlPh5cKvP05L YjL8rKfYDDEbYKc/qHXebE37jRuAMD5yjNZ+VC5RfDRqGlib6aadMRKe4LgdtScvjJMy GLpG/n347QnbeI18b9byOiOLBWNrazmcIihAlcbQs/DP371a7tyfCC8YzRNxpbLnui1Q mYvLPn1mfOSkf4Q/u24kyUQ03LfLl5PhPvujQwIu0YgepBk29ZElTkQAEbAZt8J4iGbQ wyDA== 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=4wYg4N/GqmDYcLEMWI8FN15PYOVGEp4Ds74Kweju+do=; b=wdronpBooFIm2WKxt231PPqWQwYGz+LD5E440xNS6uVQUwqOj1bkTyEI0eVk91BH/Q vuN9bKsY7W/lNoZY3NpZHaST6JxX8KSsV1rPej/qfulZDxWWUR9eHs9fC5Wtmhnn1JWE fUpma1g9ngBMY8OwSRdoX9rlU8a0K0EQ6g4N9GqTvWm1pOnejm2/e6S8W6bb3JMacJMP dKqfulcEytdD2SL4FQMKUqm/PMXoCB3/lx51J48nRoUIe8CYm3rAaKA280L95LtF35dC jwDDA1avoHTco6nAPAEkXuSftn44yt16WLY1DjDA0Bj8JX7tS2Y3ubHttB/mRLAKOKd1 SkCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="VL+TY/0M"; 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 t1-20020a50d701000000b0046744d9fff8si1288721edi.348.2022.11.29.11.49.30; Tue, 29 Nov 2022 11:49:51 -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="VL+TY/0M"; 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 S237107AbiK2Tiz (ORCPT + 85 others); Tue, 29 Nov 2022 14:38:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236981AbiK2Th1 (ORCPT ); Tue, 29 Nov 2022 14:37:27 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EF7050D76 for ; Tue, 29 Nov 2022 11:35:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669750543; 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=4wYg4N/GqmDYcLEMWI8FN15PYOVGEp4Ds74Kweju+do=; b=VL+TY/0MQDEO1WM70MooWGBlO02wzHzY2iLEhtaHgoKSvOnC8v70UuQ4g5Is9tS4JNPQms GEOtclbSalzJgO0yd1ac5Zvw1I2nfQrSLeQ1XWsSXHZhRk/HZ9VMNky5R6q1U+VNURX6dJ Q+cKD+JoCj2JDrVF3NMuhwiQ3w4ToyE= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-135-WlClVYzNNPCdJxpBjrExTw-1; Tue, 29 Nov 2022 14:35:40 -0500 X-MC-Unique: WlClVYzNNPCdJxpBjrExTw-1 Received: by mail-qt1-f200.google.com with SMTP id n12-20020ac85a0c000000b003a5849497f9so23431862qta.20 for ; Tue, 29 Nov 2022 11:35:40 -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=4wYg4N/GqmDYcLEMWI8FN15PYOVGEp4Ds74Kweju+do=; b=sOJXNsWpyq1/zwKn+hSfelw4dkfmTLAK6H6PtMKyDDcz/cnsmvJ+xOX+8eiQftk6ZJ YFs7Pnl5RrrFyD/6s4MfRKBRy+nXQxF/jUZj8zjVkLTOS+ZxnfDfa2nyIZN/0PNy0g9x NLSbxwhjuNbCcEAF6dgVjxwquMR+QVmi9cAFtdzaanGw/qbNSRd3udBj8RTKPZJ3DnLW xsGAV5MgiHg/Hx2zrT0BfG5c6ICwlcCWDdgo5fO1RS4vK7fi04bmqp1lFLscB10J7wZ4 hXJ/gS6hEM6lOfS1T/xuoI1JsT/FzjTyzZnJd7gPK2lJ8/OQi7FGGZjL6mGaYsnRb1gN M8Ow== X-Gm-Message-State: ANoB5pl2OkPa0TDmQq+prO9rd3syMMmW3GO8+HWGdrzXcVoLpdfKnKAW VegOEVpTx3JBuYs4dtjNaG//hloM+/jsjaZav2Va/9Y9WtDMm7Pj3a3CmC1vZr075U3eZcyOz8n aFYuB2r3HF0g+yevXk9SG9eOA X-Received: by 2002:a05:6214:207:b0:4c6:4ac0:12c1 with SMTP id i7-20020a056214020700b004c64ac012c1mr37457103qvt.111.1669750539639; Tue, 29 Nov 2022 11:35:39 -0800 (PST) X-Received: by 2002:a05:6214:207:b0:4c6:4ac0:12c1 with SMTP id i7-20020a056214020700b004c64ac012c1mr37457088qvt.111.1669750539374; Tue, 29 Nov 2022 11:35:39 -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 n1-20020a05620a294100b006fa16fe93bbsm11313013qkp.15.2022.11.29.11.35.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Nov 2022 11:35:38 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: James Houghton , Jann Horn , peterx@redhat.com, Andrew Morton , Andrea Arcangeli , Rik van Riel , Nadav Amit , Miaohe Lin , Muchun Song , Mike Kravetz , David Hildenbrand Subject: [PATCH 06/10] mm/hugetlb: Make hugetlb_follow_page_mask() safe to pmd unshare Date: Tue, 29 Nov 2022 14:35:22 -0500 Message-Id: <20221129193526.3588187-7-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221129193526.3588187-1-peterx@redhat.com> References: <20221129193526.3588187-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 Since hugetlb_follow_page_mask() walks the pgtable, it needs the vma lock to make sure the pgtable page will not be freed concurrently. Signed-off-by: Peter Xu --- mm/hugetlb.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 776e34ccf029..d6bb1d22f1c4 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6232,9 +6232,10 @@ struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, if (WARN_ON_ONCE(flags & FOLL_PIN)) return NULL; + hugetlb_vma_lock_read(vma); pte = huge_pte_offset(mm, haddr, huge_page_size(h)); if (!pte) - return NULL; + goto out_unlock; ptl = huge_pte_lock(h, mm, pte); entry = huge_ptep_get(pte); @@ -6257,6 +6258,8 @@ struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, } out: spin_unlock(ptl); +out_unlock: + hugetlb_vma_unlock_read(vma); return page; } -- 2.37.3