From patchwork Tue Nov 29 19:35:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13059090 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 9C2C0C4167B for ; Tue, 29 Nov 2022 19:35:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 38C828E0003; Tue, 29 Nov 2022 14:35:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 363906B007E; Tue, 29 Nov 2022 14:35:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 07C736B0081; Tue, 29 Nov 2022 14:35:43 -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 E1DDB6B007E for ; Tue, 29 Nov 2022 14:35:43 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id B160140BA9 for ; Tue, 29 Nov 2022 19:35:43 +0000 (UTC) X-FDA: 80187484566.03.E827BBE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf14.hostedemail.com (Postfix) with ESMTP id 5E02810000D for ; Tue, 29 Nov 2022 19:35:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669750542; 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=QcCROOXUwDOBPnXzg8qdciMd6/cbeY4lGWg8c0ISdqw5xaBxb0JJVEaHG0i+SZKyONuCRA NH0fwFPKRWzFSxC5LE8O80MPaR3O93jb5byBK01q06kb1fgsPpe977O2EXQKcxyU+ws+YP ttK6o4wiW+SPI7gmv2TWox4zOYuDfGU= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-150-0011wSP_OXCdz56AUxDhLA-1; Tue, 29 Nov 2022 14:35:40 -0500 X-MC-Unique: 0011wSP_OXCdz56AUxDhLA-1 Received: by mail-qk1-f200.google.com with SMTP id w4-20020a05620a444400b006fa24b2f394so31142693qkp.15 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=W652PuXpHwEI3nkxy3yynMB0DYdXtI8Oy76iEWP7SgYT2KlX/rKOTNiSOXjXZAviW3 Z4MNnejmVwQ4U7f5wcuBXxX+L10Xx3NAltVf2pkENwIvG9YARVjuWPIukhWlFcGjjFHq q7WFkXCU0ioOlVt8TuovqcXBjg+gQnXZSgCkCxwP7IevGsBYJ6LQZilQdgitUhaY8h3g /EEIvR/n5llrNtNKgHwHJmB8wEquPomtdwrsKR2xlrOdwClOEDzh7GI8VKW0kULdyd+D XmhfZidyHoGPktrv3n0G1x2WgA3es4uPn+dtJf3Z+LTCTLHBsHJ6V+plwt1wWohxklg8 u9EA== X-Gm-Message-State: ANoB5plXoZePjqkHiDeIRRx4aLwqrWnfHfBG2WV+n9tiX7Qgmv8vCxvo MUVOwOSEuu2bYHI9crNJw2oHHm52z5k/z/oEnuKftNd571i7ECGMM/TqqI0RvEvyDr5mVv7zgoK SqGmik8FGj+NWrnODL76FwbshXncUKhyhqCbIrwwAkdqJzSDdz8CnpEff3N50 X-Received: by 2002:a05:6214:207:b0:4c6:4ac0:12c1 with SMTP id i7-20020a056214020700b004c64ac012c1mr37457121qvt.111.1669750539690; Tue, 29 Nov 2022 11:35:39 -0800 (PST) X-Google-Smtp-Source: AA0mqf4u/49M+6rzccmqGiecb+5YeMty5DWCqGQppJOYyST0NA7r4AdqewGNpJUPOi2AgkzWJM2jYA== 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 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-type: text/plain ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669750543; a=rsa-sha256; cv=none; b=kKAn/gaHXvbI3OySq1BlFowesQ1jw68CuIS8N85OCI4bUxDeisTlwGXChuTviIGJ85CMZv Cjx+ICSQruyVu+aUQPJH5JCnJKlMVYatFEoYRt7yod1IzG2gbeMApwp4yH+4rB9O7JDxhM M5wt7RfnWF9PKt3ybGPBOJ1oyvZF9io= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QcCROOXU; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf14.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.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=1669750543; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=4wYg4N/GqmDYcLEMWI8FN15PYOVGEp4Ds74Kweju+do=; b=KL0eof9uI/6eG8mw3brxEnKnBAINuVzE8U/mPWJ9PoAFzb0XfeYLlI8zNR4GGzRluiiV8p Iom5ro7XJ4B6uRFSRFdxpum+AVBiSYiobrIUiX6h1rbwnnDlMrTzsd4TGdc+3ndj6wYkz6 8q1IwGM+1iz8o7LEjYn0DpZYcZP1AWQ= X-Rspamd-Queue-Id: 5E02810000D Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QcCROOXU; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf14.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com X-Rspamd-Server: rspam12 X-Rspam-User: X-Stat-Signature: jt3ky1n8418p9zicbk45az39hc96kipt X-HE-Tag: 1669750543-735882 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: 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 Acked-by: David Hildenbrand Reviewed-by: Mike Kravetz --- 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; }