From patchwork Fri Dec 9 17:00:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13070021 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 92B9FC10F1E for ; Fri, 9 Dec 2022 17:01:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 064B98E000C; Fri, 9 Dec 2022 12:01:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F06508E0001; Fri, 9 Dec 2022 12:01:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE0738E000D; Fri, 9 Dec 2022 12:01:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id A409C8E0001 for ; Fri, 9 Dec 2022 12:01:36 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6F9D6120F1A for ; Fri, 9 Dec 2022 17:01:36 +0000 (UTC) X-FDA: 80223384192.21.5A5FD22 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf18.hostedemail.com (Postfix) with ESMTP id 136721C0024 for ; Fri, 9 Dec 2022 17:01:31 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=AkI7v8Y0; spf=pass (imf18.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1670605292; 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=QzeyNG+xisx8vPYcMzT01YLXY3V0nLFHTQTVfPkpFHw=; b=1FfuOKhZA3G0f5jUwtPeQdnAyHU2K3BujVZBb6c74TBYNkTC7Bz7Ddllt7yu3EKjqsxfjW lIVSMQIgnB4vla082/g4B7eNp36Wlo/Rc1wDavxWSi2+9xFlkvtP38ijNr3tq/5i5XRq8n HqkXtiAgeOPDWzB33MjmbOwv6TEsd9M= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=AkI7v8Y0; spf=pass (imf18.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1670605292; a=rsa-sha256; cv=none; b=dQrYpz2axRhCvdHjEAbuaS2UOX5piCKdqMSEhDzlJTQYyaif8HIPXtDlRwM8vVg/jSH7MC hWmRpCz68DYTYvWAH5//ZWKj8bjw9RL5mUcDnQImPw1a0Wd9sho9vHRhMtCiwNbq4xv2x7 b5wT0dqs5CG/o//31jOUhFHZDzzf/hg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670605291; 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=QzeyNG+xisx8vPYcMzT01YLXY3V0nLFHTQTVfPkpFHw=; b=AkI7v8Y0KNY57iPYbG3y4A/aw30ON0o+EB8z7hi42F22iwngHD7TDQxvfjrcXUfC2yscJn T6dqltbYpOuiGCVb3Y8X2P3miIR37sjczgRForvreW352t76E8VHCPAeZoDnX8LESJ7oTo OamwEJdHJT7+vEEg1ppfo8ILeVev6CI= Received: from mail-ua1-f72.google.com (mail-ua1-f72.google.com [209.85.222.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-8-dnRVlOP4PKq5D_mt_d4t5A-1; Fri, 09 Dec 2022 12:01:28 -0500 X-MC-Unique: dnRVlOP4PKq5D_mt_d4t5A-1 Received: by mail-ua1-f72.google.com with SMTP id b19-20020ab01413000000b00418fea11cc9so2087624uae.18 for ; Fri, 09 Dec 2022 09:01:28 -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=QzeyNG+xisx8vPYcMzT01YLXY3V0nLFHTQTVfPkpFHw=; b=UABQcE01+brUm5e/OQ0slHgV6BOgQTzxXHp/VmBoDByDGzAwWBm3YKHlDYai4I+ZTy J44f0puFcTdiwhX2tipX7AVfgyz97csLNTVJj+yLSOtaC05K3f1m6hv1n2BsaEQWGzyz +hrgZofv3P9X4h3DYk/saqhRa9eBrN1DjvAUMgDmghFeCWlhAshcmzPiUa5KqunP/XvW m80FhUe+VYI8CWmV2Nuj1ajNWMNFEDzfctEQvAdVZYFJSkvdGJh4wbJAKq41wXp5a3wt bshCpbSAk4x71UK3InftAyzh8K5rQRb9aKBT2FHTsww/48bO4VNIBSBbFyYKJ47JnP7k iNWA== X-Gm-Message-State: ANoB5pl17HvYokCtxI6GwWKzbsUr4jvq626Sj+gUqe3iaJ5Hhz8kvoVU pNju8+xYUDEwwe+rKkAwuVwq49esqbH18XIYIMHjzLNC3pmlwCLqGQBbD/mDe4BhzoJus03xEFK pZ9bL4/60xovtS2b13wrVYW0YcJG59RLGIfQWyGWMXLnrTQw719Bx6MqRt9vQ X-Received: by 2002:a1f:ee4e:0:b0:3bd:f324:5500 with SMTP id m75-20020a1fee4e000000b003bdf3245500mr3198348vkh.2.1670605283934; Fri, 09 Dec 2022 09:01:23 -0800 (PST) X-Google-Smtp-Source: AA0mqf5nmOoaLlqHDusb7JXaz8VNhkWlW4brwxUYuPvukkJNtkEIbapa5We/uBYiNWEM3SCaE8rMvQ== X-Received: by 2002:a1f:ee4e:0:b0:3bd:f324:5500 with SMTP id m75-20020a1fee4e000000b003bdf3245500mr3198279vkh.2.1670605283615; Fri, 09 Dec 2022 09:01:23 -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 q7-20020a05620a0d8700b006cf38fd659asm178907qkl.103.2022.12.09.09.01.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Dec 2022 09:01:22 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Andrew Morton , Miaohe Lin , David Hildenbrand , Nadav Amit , peterx@redhat.com, Andrea Arcangeli , Jann Horn , John Hubbard , Mike Kravetz , James Houghton , Rik van Riel , Muchun Song Subject: [PATCH v3 6/9] mm/hugetlb: Make hugetlb_follow_page_mask() safe to pmd unshare Date: Fri, 9 Dec 2022 12:00:57 -0500 Message-Id: <20221209170100.973970-7-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221209170100.973970-1-peterx@redhat.com> References: <20221209170100.973970-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-type: text/plain X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 136721C0024 X-Stat-Signature: 97wj71iba3noo1t7qoraqatzebpicxoc X-HE-Tag: 1670605291-607137 X-HE-Meta: U2FsdGVkX1+acCm6V0kOoLbxAtFuG4crQYne3uPdNrmgTH42NlScTTzY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hw9DbUtNVBmS03lzdiOe+xYTQq1crMbya7tqQ1Nh2AJoll0CBfIjhhV5UWV8GH0CS0VAK3ysG8/AlUJc6GRfh6J5iQuYHZKqBsvvAxIO4= 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. 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 247702eb9f88..e3af347470ac 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6227,9 +6227,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); @@ -6252,6 +6253,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; }