Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2969731rwb; Fri, 16 Dec 2022 08:34:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf5BIC0WPIdXt+wBhYOh9sogJP6xudZY5qo1lyTJrJ5g423QLu2nq5KTR/qlFjtDp0N+TEC/ X-Received: by 2002:a05:6402:2949:b0:460:ce2e:30ba with SMTP id ed9-20020a056402294900b00460ce2e30bamr27297577edb.10.1671208475721; Fri, 16 Dec 2022 08:34:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671208475; cv=none; d=google.com; s=arc-20160816; b=zNlJmaYGknYANXKcsi0AUPEcf59TEn+OP1ZdyvFpvTncDk5MF/1yJBHZDQdP9hzYax wGZnvN5IxRKOGETMfhKf2QzYPFK2fDSLtj9pkSqmSF2DV2AdiIdOWORinllQ54akKPgM 6EO8LWZIsr03PlnRgq0/LYzNamaKInzeFbE6N6WJV+vkc41C6hBZ48k+1Q2fi7rzZLkO OlGSM3BoqKlvNfINAgRMToZ9YSLPFL4v01Khg7uA0Yz34g+j0vAxlrPPK8cjDhwq6b2Q zHgi6T9uAzQ3e/H/gHkUkj8RiTNgeAlUzN66fTYA6nSlxD7tJsLsWM66oWpLJJYlCt3p Txlg== 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=7a/XOpLMoccJVDSJCL0inQbFYq9WEos4O0UHGEG2GQ8=; b=oyqH9kAmUTt5wCal3mPugACB6jBmN5Tl+ZNdnbVz6obKp0EvUWXacThjErdcCbzJbT H7lN5XaBQCADHngcH1rS3H3FPEAqBoPabSZY9wQe+Yior+v+ZsaBcFrOmTO0Tx8FPege DNbR6e+zyjBWquUGFS0fx4Tf7cV+J/J1KPED+OFZ0g1iTC4uCx24nrenM89NtecFVls0 J5zUpmAiqCLSA4CSAI8BnoXT6AbUivnIgcAWNdcMtHf76lcOqRNT04hJ0JF9EsynbRt5 yN0pfcHehY9Yw9lQJKHd5P+IU/e/aNVDgNl9hftNaQJT62I04IEBTv4lO+5VoQk9oZWn I+Rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gcukfW1j; 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 bo4-20020a0564020b2400b004672d4e4ff2si2555027edb.171.2022.12.16.08.34.19; Fri, 16 Dec 2022 08:34:35 -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=gcukfW1j; 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 S231547AbiLPPx5 (ORCPT + 68 others); Fri, 16 Dec 2022 10:53:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231472AbiLPPxe (ORCPT ); Fri, 16 Dec 2022 10:53:34 -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 6EEBB2D1FB for ; Fri, 16 Dec 2022 07:52:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671205946; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7a/XOpLMoccJVDSJCL0inQbFYq9WEos4O0UHGEG2GQ8=; b=gcukfW1jx9ghc3Rxufk88BiLnwzhHzCfgP2XJE/8mW0eMRhZLDZODrPPF4u2QkIlwgJuN4 Pm3YueXz49zCuOj3nAatDVBY5YC9AGzJDKkf/vXStR6JynnOIkG1HKZVmAi6QasnPdQUh+ pqs+WLfz/BN2Q7yUqZJfR0npU3z7+uc= 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-593-ShNxBb3rM6WTLcfA3stdXg-1; Fri, 16 Dec 2022 10:52:25 -0500 X-MC-Unique: ShNxBb3rM6WTLcfA3stdXg-1 Received: by mail-qk1-f198.google.com with SMTP id h8-20020a05620a284800b006b5c98f09fbso2068038qkp.21 for ; Fri, 16 Dec 2022 07:52:25 -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=7a/XOpLMoccJVDSJCL0inQbFYq9WEos4O0UHGEG2GQ8=; b=fPcB4WN+0S5MZj8Eoq1pix7GLfdTZPDu8ViVxFrtG4HG4hlFwGzpyBV3N1vCuniuDO aX8dCM3KMnM77mBchZ0mCQgNQvGJ1CBXOIkeVwqH4JU08j/qtmk0a1v7/+ESKCQyxNIv 3alMtc0Rxhu858K5adkAI3BXVL0zI3ZsgMVyf4tBwkmP7OdWL0RKHHZxDhYuLlP+7amK quwCaDRmente9ZdJj3ssyV80HzQrMN/UCLfe9fPIDQduoLk0x+DxSVtQoL4VMNrzZ2Du i7uyihR/MHBO1Uf6o7T3q/Qb/8RlhwmXviYrudXGwl9ROB5hHzLoUnwtI6r8pttd7BBV GruQ== X-Gm-Message-State: ANoB5pnswnm1/J8u/TUrlyM35BAWl7C9mb3X/I1V0oFDWVULax0voNcP d4yYHlPZU9sTMrwb59CuSME5xdGdixuHp2lLrFppoP3laULI9MTvO4P3R78XHMqIlTAlOjJraAt UEwXGBNzkXKz2ZC0JcomN5V/WU76oqKnwevSzAt6ToOu3OEs92lc8uLqAn6ayt01xYhla0PzwFA == X-Received: by 2002:ac8:5755:0:b0:3a6:9162:245e with SMTP id 21-20020ac85755000000b003a69162245emr61455526qtx.36.1671205943533; Fri, 16 Dec 2022 07:52:23 -0800 (PST) X-Received: by 2002:ac8:5755:0:b0:3a6:9162:245e with SMTP id 21-20020ac85755000000b003a69162245emr61455484qtx.36.1671205943290; Fri, 16 Dec 2022 07:52:23 -0800 (PST) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-45-70-31-26-132.dsl.bell.ca. [70.31.26.132]) by smtp.gmail.com with ESMTPSA id d136-20020ae9ef8e000000b006fef157c8aesm1673001qkg.36.2022.12.16.07.52.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Dec 2022 07:52:22 -0800 (PST) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: David Hildenbrand , John Hubbard , Muchun Song , Mike Kravetz , Nadav Amit , Andrea Arcangeli , Rik van Riel , peterx@redhat.com, Miaohe Lin , Jann Horn , James Houghton , Andrew Morton Subject: [PATCH v4 6/9] mm/hugetlb: Make hugetlb_follow_page_mask() safe to pmd unshare Date: Fri, 16 Dec 2022 10:52:19 -0500 Message-Id: <20221216155219.2043714-1-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221216155100.2043537-1-peterx@redhat.com> References: <20221216155100.2043537-1-peterx@redhat.com> MIME-Version: 1.0 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. Acked-by: David Hildenbrand Reviewed-by: Mike Kravetz Reviewed-by: John Hubbard 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 64512a151567..0bf0abea388d 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6375,9 +6375,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); @@ -6400,6 +6401,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