From patchwork Fri Dec 16 15:52:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 33989 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp1044401wrn; Fri, 16 Dec 2022 07:54:34 -0800 (PST) X-Google-Smtp-Source: AA0mqf5yHLUzWsbchvynBsACcwe6b2K2JZQSTs7GVwQpyhjfrjdbGGMPcfvH2qz+kxBEEvqLjKfn X-Received: by 2002:a17:902:e8d6:b0:187:403c:7a3b with SMTP id v22-20020a170902e8d600b00187403c7a3bmr28584773plg.69.1671206073805; Fri, 16 Dec 2022 07:54:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671206073; cv=none; d=google.com; s=arc-20160816; b=Bk523aqS7lgN7ERv1lUkKk1GT31VJ+Hm0rihvm37mO4ELd3qMyA1dMhycLBrYrTbsD KTOXXv0Y+b5oC7r+8U5CE8t+J3hmNNqJM9pjqW7fESA6n9VzXeZya9+FlN6gV1s7WFBZ w0fWfo20f9aJNqIc4hvnuW0vZXDsZmFmML/Z877Kj9i0N5uUp20vMPcRq6XM2oGnDR+4 AMM1ehEabzeNQBQywJC2atDt0hnaWeMvi2+pyqUQstFn0DWMjN0EjaF/QU8PRDI8yY5M NNxvsMwtVIC3wLE53/mBb1mTbwWMh9DxLTEH9q5KSr7jjLSdAUf9lmnvrwJKVTiKisER jqFw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z14-20020a170903018e00b0017d9b373175si2959393plg.415.2022.12.16.07.54.21; Fri, 16 Dec 2022 07:54:33 -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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752386579967012551?= X-GMAIL-MSGID: =?utf-8?q?1752386579967012551?= 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; }