From patchwork Sat Feb 18 00:27:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Houghton X-Patchwork-Id: 58822 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp142641wrn; Fri, 17 Feb 2023 16:31:09 -0800 (PST) X-Google-Smtp-Source: AK7set8Mc0hyinTvfg4nT94IbFB1dIne2uopVSum9TUW4pmXCt4DAtJor4Ow7nuF4g93rwBsgSv6 X-Received: by 2002:a17:906:198f:b0:8b1:77bf:5b9f with SMTP id g15-20020a170906198f00b008b177bf5b9fmr5376367ejd.13.1676680269152; Fri, 17 Feb 2023 16:31:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676680269; cv=none; d=google.com; s=arc-20160816; b=S8o3nwFggIHSAQgu6kCD7xS21tENGXKl81PEzcjeo1iShSuLvPrHB7uiu8+dhkBYzq ilSLb5wJX2DwGkHBjVJAZm5Z2reRsFssN1gkO9ecHLbzh9io5QUi0eLXGi8dMtrD8g0S p2/yQPL4sg6r6ett418qH3wXGk/l4bGfRtLxN1oiiKdzX/3I7guXFgRtc8vMWoEEg6sP FM96g1Gb9r5Zbi0OaRTWzsJBS5RIMgEfbFJPhjMpzTiFesZbgO00pkTDTqOEFiNpg/Ln h3ibYW6bZpxaQOyCMx0ukexxATuF9xTvjKuVHuZ8VrMazQtfT9bZjFYNk5IEIpNNwirm riyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=0wSMKMWzwfQ8fLAFHXt0NmwJTi1H1o52qxxMn528B3Y=; b=udw1+A8E7mPF8ioJbXlyy+/8m4V1MAINoEcT/FN3i9cDskROVHQkYpJ2+VhqhkoDhW I11zQrdn07aYWVxYUQy3v2X5An0W31vzNTgiJZKffITA+Diw0FLTWotTxPP1rVy3ZZY6 oV/2p51vH4m+uH6Kaa3emKvZHy3I+X6TN2mwRbykcP34tJCjSyBphG2nabbkLgtLnUks 5lnkXwSdvWhP1lIIsDj/GSPE8rwmBLNFKlM9sGQ5BODBEhWo8/uBAIKHl7xa+yJJjy4x BL1LLnPcETVQA8xPIeL2L9NBvZ5h91srr8sW5xKhupm4BAC/okKemx2PhuKok0/fba0h Mamw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=axPHyxy1; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c22-20020a17090620d600b008b1801cac0dsi4184446ejc.417.2023.02.17.16.30.45; Fri, 17 Feb 2023 16:31:09 -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=@google.com header.s=20210112 header.b=axPHyxy1; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230061AbjBRA35 (ORCPT + 99 others); Fri, 17 Feb 2023 19:29:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229773AbjBRA3X (ORCPT ); Fri, 17 Feb 2023 19:29:23 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D8F66C00F for ; Fri, 17 Feb 2023 16:29:01 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id k72-20020a25244b000000b0083fa6f15c2fso1931074ybk.16 for ; Fri, 17 Feb 2023 16:29:01 -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=0wSMKMWzwfQ8fLAFHXt0NmwJTi1H1o52qxxMn528B3Y=; b=axPHyxy1GBdJ3j5NWk4sW5NYHawOKf9AoibB4HV5FfIZJydc97adJIODrPR+QPgxNK nr00e5FMgkdE8K907sG4ZDoHr5Lt8bsvRMbzhBZu9D/vDZvX+woxXErLOoWLQSU7lSB3 ColvlhjaPZZh6IxAnrEln+IITIxYCmy04Z2l1SbzE3B6POnZJUSMCAYWIRaT1Yw6pXLR Wq0cbmdstbtdCR3d2d+bJjVqqNZDwx8tE8yRYgFkpy+28U20Db+9VK0iOYSso+pD2sG8 OJeoIbKDbGGxUqdzljTj52m+1rUrxcY+G67jmbfYWqpHTo5y/BK5aqWA0UQIkWR55NRP GAqA== 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=0wSMKMWzwfQ8fLAFHXt0NmwJTi1H1o52qxxMn528B3Y=; b=M9PdICCwevoqsB+YVTZsRvQA61+M95wXb0iiBN3kIbODe4IrbG7LRQmgVpBlmVrqaS 3PDMXLyKm5+6I0IXX1hKLyLZdou2vq95clAAR4aCJGS/qRCvtcAjtqz40z7Y5lMaK9KV l0E9+fyxGoU4kbf198vOow1giRLatW4yVE/bHiPLqaRhoWLyrec8sTlUMOxnQyG7V4Yl OJNMLEeAKhvBq3QytuB34asEcjSPnnVWKLhZTdWfg7zb7hpD1jpUn15fOct9SWRFBABH WcWWYLlpe5zA91qiP5lJn4J+vmB984/78vdtDnOS9Fc/0Q9vkYn9A9algB6N+kmL6hzW Aa4g== X-Gm-Message-State: AO0yUKUGGrCD7M5JpPpo+d/M2EdLTg+ulxaUvXg1m2BkERda9pyfJIUJ Uu30ZxWxXHgh0wnMwBQ7wgQAQC5hRf6PGl5/ X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a05:690c:38d:b0:533:a15a:d33e with SMTP id bh13-20020a05690c038d00b00533a15ad33emr73114ywb.5.1676680140092; Fri, 17 Feb 2023 16:29:00 -0800 (PST) Date: Sat, 18 Feb 2023 00:27:50 +0000 In-Reply-To: <20230218002819.1486479-1-jthoughton@google.com> Mime-Version: 1.0 References: <20230218002819.1486479-1-jthoughton@google.com> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Message-ID: <20230218002819.1486479-18-jthoughton@google.com> Subject: [PATCH v2 17/46] hugetlbfs: do a full walk to check if vma maps a page From: James Houghton To: Mike Kravetz , Muchun Song , Peter Xu , Andrew Morton Cc: David Hildenbrand , David Rientjes , Axel Rasmussen , Mina Almasry , "Zach O'Keefe" , Manish Mishra , Naoya Horiguchi , "Dr . David Alan Gilbert" , "Matthew Wilcox (Oracle)" , Vlastimil Babka , Baolin Wang , Miaohe Lin , Yang Shi , Frank van der Linden , Jiaqi Yan , linux-mm@kvack.org, linux-kernel@vger.kernel.org, James Houghton X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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?1758126690060287624?= X-GMAIL-MSGID: =?utf-8?q?1758126690060287624?= Because it is safe to do so, do a full high-granularity page table walk to check if the page is mapped. Signed-off-by: James Houghton diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index cfd09f95551b..c0ee69f0418e 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;