Message ID | 20230105101844.1893104-17-jthoughton@google.com (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <owner-linux-mm@kvack.org> 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 64C6EC3DA7D for <linux-mm@archiver.kernel.org>; Thu, 5 Jan 2023 10:19:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F107A94000D; Thu, 5 Jan 2023 05:19:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EC2D5940008; Thu, 5 Jan 2023 05:19:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D396294000D; Thu, 5 Jan 2023 05:19:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id C18A1940008 for <linux-mm@kvack.org>; Thu, 5 Jan 2023 05:19:21 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 906981206CA for <linux-mm@kvack.org>; Thu, 5 Jan 2023 10:19:21 +0000 (UTC) X-FDA: 80320348122.14.65FBD7D Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf22.hostedemail.com (Postfix) with ESMTP id EE842C0007 for <linux-mm@kvack.org>; Thu, 5 Jan 2023 10:19:19 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=XMejQEid; spf=pass (imf22.hostedemail.com: domain of 3J6S2YwoKCG4VfTagSTfaZSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--jthoughton.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3J6S2YwoKCG4VfTagSTfaZSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--jthoughton.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1672913960; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=JBa/YNOWHc8BdkByQMj3j16NgHnHDUWMHmpwThmwYW8=; b=S9qdij6CR4WfikYLjuSGZhEr4ffiO2eb0DkUpFj2skjLFWx5KF8P0E4TGhzq87puicCNCx thM8gbEsJqZ9OCpk16VezRfjB4rcCYFZjCxju4DESF+e1WBZeNgdm0mk46sBZJP+KL64hd NvIM3s9vrhECoFrJCBzDCKNnaUL4Cu8= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=XMejQEid; spf=pass (imf22.hostedemail.com: domain of 3J6S2YwoKCG4VfTagSTfaZSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--jthoughton.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3J6S2YwoKCG4VfTagSTfaZSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--jthoughton.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1672913960; a=rsa-sha256; cv=none; b=ReCV4NxLCHMsjiojtswjmDngEARmsUha8g4mgqr4wLc+wM7h8yKUSqkuGNf3VQlRG9wROH 0gy9e+7HL8xP1LWlOdE7HgA7A+QujLpJvxP2ZJ0vHjDGKV6W0Hinpp//ioHyruCbIY8NJH EdXENJ/lWyAvLUB6Ck5Ml9jv1u0r+BE= Received: by mail-yb1-f202.google.com with SMTP id g9-20020a25bdc9000000b0073727a20239so36033645ybk.4 for <linux-mm@kvack.org>; Thu, 05 Jan 2023 02:19:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=JBa/YNOWHc8BdkByQMj3j16NgHnHDUWMHmpwThmwYW8=; b=XMejQEid82qJD40DqqAVmKO7KaK2I6fqGVaQFn3qa+xsUhE5GeK5QsvXmIgXrlYAYp ZglFLDAuM74Ul8HnkiBVKndyeFl7TfYD6lrTc+G+Y0y5590vBgUhLji2pkV/uo0dTtba JOhfbgAT9W5Ih3mvcLPzzoGXyJzqEfRKoNqybN3iBy+HEU29ORkAZ56QrvlR8wMgJBPv /fiJ3Qjur/kHePLpxQf6mexQ2zmKFEUxMYH6n8AvNHRLmu3tqS42gPfHnw2VZCW+sun6 KjrZlQt7j8nYKl5hgQmUrLHKrYGRJUYde6DMPUl9jm0rRYEyRoygWOPbOjS00/ls6W8J sVQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JBa/YNOWHc8BdkByQMj3j16NgHnHDUWMHmpwThmwYW8=; b=rIsMDpEQYkSM8VHUYybLIgekNergExXwLJWQL5qnApE5gWP5olt5We+D0NqpwdcLyf ty+bpSPGlcR+zV99ZwNPbl70DSygziTKZ//YCAT1ECZIggWG1NNK+ii0xBoY5eSdWZYz i7UPUGUeDNgcH5JB4JHk45nNnj+DLFvoyTzp96rYCIepSNwoOdp9H8gH8R5DFS4OgraT 8CNUjyrfykB6o6VXqtYwR2BG/++LRK4PZeaK+ueIPEBuGGJpArYK7EOnMjArVuL+IE0g ZIh9KDxyCiPEo4Yhx00HhsSQQ5B3v9iCkUZpN3yjgZdPAm0082NBbD/8OraqNzHAyZDE TeuA== X-Gm-Message-State: AFqh2kohWlGlRnWu/1kD4Nq3tE2JBYck9kujm7cE3KAKYQwn/rV9BGDt /UoCIq1E3Wpz0RP3XD/nug1JtUVr9pplPeVx X-Google-Smtp-Source: AMrXdXvV0r/wfkEbgjE+pvWMQzkSz+gLHIZu+cb6EHqmZiUJTMqvVQaEsHt/42vL01/hmp945pzEpgFSvftYQi7k X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a05:6902:b14:b0:6fc:c88a:1c6d with SMTP id ch20-20020a0569020b1400b006fcc88a1c6dmr5728371ybb.486.1672913959168; Thu, 05 Jan 2023 02:19:19 -0800 (PST) Date: Thu, 5 Jan 2023 10:18:14 +0000 In-Reply-To: <20230105101844.1893104-1-jthoughton@google.com> Mime-Version: 1.0 References: <20230105101844.1893104-1-jthoughton@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20230105101844.1893104-17-jthoughton@google.com> Subject: [PATCH 16/46] hugetlbfs: do a full walk to check if vma maps a page From: James Houghton <jthoughton@google.com> To: Mike Kravetz <mike.kravetz@oracle.com>, Muchun Song <songmuchun@bytedance.com>, Peter Xu <peterx@redhat.com> Cc: David Hildenbrand <david@redhat.com>, David Rientjes <rientjes@google.com>, Axel Rasmussen <axelrasmussen@google.com>, Mina Almasry <almasrymina@google.com>, "Zach O'Keefe" <zokeefe@google.com>, Manish Mishra <manish.mishra@nutanix.com>, Naoya Horiguchi <naoya.horiguchi@nec.com>, "Dr . David Alan Gilbert" <dgilbert@redhat.com>, "Matthew Wilcox (Oracle)" <willy@infradead.org>, Vlastimil Babka <vbabka@suse.cz>, Baolin Wang <baolin.wang@linux.alibaba.com>, Miaohe Lin <linmiaohe@huawei.com>, Yang Shi <shy828301@gmail.com>, Andrew Morton <akpm@linux-foundation.org>, linux-mm@kvack.org, linux-kernel@vger.kernel.org, James Houghton <jthoughton@google.com> Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: EE842C0007 X-Stat-Signature: erhesis88rxhr7ha1qzkbzixe86ussq8 X-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hNr71o418q64OF+H5vg9Qsr368i55BZ9y+LxiAkKOy6Gr8OoWPXVK0jiQvVuLBbUvD78ODyYlZzUtVZB07EkhGeBCZb9KSWBjsBKy2soT+1rqBki0bT1g0wnyKmUFHOdBYNHfvO+4b0lcsfuWxqgRZQGG2yS3gI8P1jD6gpC7Moiw8NGpVfFwRzJVy9J0vi8XqB7ibQ7HZt2r3QdDWKhyI+TTpfes/RIxA4wfahW2jnhfcwbhPhTJJhFtnlLok2/TFmUwO7hQD0dgB2q3n1+OWVEN1E0/llV/Ufwn5aK/L+l6Q0GIU/0rvP5Qm2YgHmAoZ0t3kpTTJ5ikZD64fH7U2qWTebr6Y3FptGLiFdsuguN3Qtg9oc= 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: <linux-mm.kvack.org> |
Series |
Based on latest mm-unstable (85b44c25cd1e).
|
expand
|
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 48f1a8ad2243..d34ce79da595 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -386,17 +386,24 @@ static void hugetlb_delete_from_page_cache(struct folio *folio) static bool hugetlb_vma_maps_page(struct vm_area_struct *vma, unsigned long addr, struct page *page) { - pte_t *ptep, pte; + pte_t pte; + struct hugetlb_pte hpte; - ptep = hugetlb_walk(vma, addr, huge_page_size(hstate_vma(vma))); - if (!ptep) + if (hugetlb_full_walk(&hpte, vma, addr)) return false; - pte = huge_ptep_get(ptep); + pte = huge_ptep_get(hpte.ptep); if (huge_pte_none(pte) || !pte_present(pte)) return false; - if (pte_page(pte) == page) + if (unlikely(!hugetlb_pte_present_leaf(&hpte, pte))) + /* + * We raced with someone splitting us, and the only case + * where this is impossible is when the pte was none. + */ + return false; + + if (compound_head(pte_page(pte)) == page) return true; return false;
Because it is safe to do so, we can do a full high-granularity page table walk to check if the page is mapped. If it were not safe to do so, we could bail out early in the case of a high-granularity mapped PTE, indicating that the page could have been mapped. Signed-off-by: James Houghton <jthoughton@google.com> --- fs/hugetlbfs/inode.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)