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: 13145383 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 810FEC6379F for ; Sat, 18 Feb 2023 00:29:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E949C28000D; Fri, 17 Feb 2023 19:29:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E42EE280002; Fri, 17 Feb 2023 19:29:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D342C28000D; Fri, 17 Feb 2023 19:29:02 -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 BA5E2280002 for ; Fri, 17 Feb 2023 19:29:02 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9B2EE4038F for ; Sat, 18 Feb 2023 00:29:02 +0000 (UTC) X-FDA: 80478527724.01.E3A9BC5 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf14.hostedemail.com (Postfix) with ESMTP id DDE9C100015 for ; Sat, 18 Feb 2023 00:29:00 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=axPHyxy1; spf=pass (imf14.hostedemail.com: domain of 3zBvwYwoKCOkUeSZfRSeZYRZZRWP.NZXWTYfi-XXVgLNV.ZcR@flex--jthoughton.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3zBvwYwoKCOkUeSZfRSeZYRZZRWP.NZXWTYfi-XXVgLNV.ZcR@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=1676680140; 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=0wSMKMWzwfQ8fLAFHXt0NmwJTi1H1o52qxxMn528B3Y=; b=XB6zjxdyZNJgbTjVDtcI3cIDs4nG8lMmjOrem5y3E//5XCXV7NLuldnAy5YTj6irz+0ewx 0Y50XBR3N4+bOxcfEPaa9q76T1mpg304yTns+Gh7Z3iDaLy/Qmni7MISuawCavQbIMce2S 5SEG94jxZCWn72Y2C8uz3VCkkTcXyZg= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=axPHyxy1; spf=pass (imf14.hostedemail.com: domain of 3zBvwYwoKCOkUeSZfRSeZYRZZRWP.NZXWTYfi-XXVgLNV.ZcR@flex--jthoughton.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3zBvwYwoKCOkUeSZfRSeZYRZZRWP.NZXWTYfi-XXVgLNV.ZcR@flex--jthoughton.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676680140; a=rsa-sha256; cv=none; b=MVxTjyiWPTBb6ZV5bAM/V7L26svs9PHRAwiRyMtUlHdRqcXf6SW94BLrdcM9WTaW2qZS6J BMZX821faSxP7cJsMr1zOYNm468by1X3nLdY4y6/ZY5PDn9/9Y6nP4WXKVcKbOCyl21h43 tbj1qteHY/Eo0jN6mmdNYKaBOq7AndY= Received: by mail-yb1-f201.google.com with SMTP id o137-20020a25418f000000b009419f64f6afso2164775yba.2 for ; Fri, 17 Feb 2023 16:29:00 -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=UsPJv8X73hHKaQrLH7cZ3iBJiJNZ+BJZjK9ecAUdYjxAPrWMvNZ5Gru87/GqbdH3XT og1CuZR8BGFOzvAfTWIi/Ffh8B6Kftv0sD9U1MuQLWwOox8gsM44UOngKW8EZX+fwqYn tCQDfQvnLb2Qd/+UgfHW8+TXuqwDyffpUhFxq3wrywGZ4RdmTO/T5UmfBwwyTn71XCEs qDOkie4lkG7UsURGQjfjzZIH7n0MknOsF6GtJXDbkVhmRJDuCHjyvtwmpsi9l8F9i8tT nMDofSz4O6OlvbuYQWwqf4nOl60nSmNU6/gEDT1UNkJar8AwSqW4z8/NnqU8yOsuxRcb 3Img== X-Gm-Message-State: AO0yUKUzqrYOD83uBW74a73DVjKakmuhlbxTJvthT9TerFk1vZhZEIMG /i4z05f4Pww0vlV3XegHfVUF1jDUJWHXBkyw X-Google-Smtp-Source: AK7set8P4IRNjQRV3GSaApBMgcJvUr/kZLWUTr2MSxmgTV4ZqD4cm7y5M6XYvFN0JDI5vO1MJ3hc9iawF3gnH6MW 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-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: DDE9C100015 X-Stat-Signature: b5jmwjncuypaxjbaccit6j5xhb9y6z8k X-HE-Tag: 1676680140-410913 X-HE-Meta: U2FsdGVkX19eQOS+zwP1LI3YZpRSVnWps7pHJ0FZgikf/CU9pOd8Ahje/aulPLjgRpIQrlohHhckdu7UrHxpqJGHZ4y1WrkaSRVufnYOljCnmcrBhsZPiF06/nHX3GHG5ZsZO6TVHOgeZ2Qv0NyOhZ92emPLxooqxmNgrVfQWkfBFKmYK/WBQfEJTjl+eDIGnPRRfo6nYgbeX/0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Ngty39/z6SYk07PZkPu5GSRfFqDyv3CcgR9gSkHZBgH+aa/n1eVwa62vbBTNuP0ug+02L8NdmgWYxRbBbTRieNQJtnW9nddDY+MCjI2IUEUBC+tpS+F4Er46FZFy/dxsK0RyxzL9UtGMdYw2ZWJ9wLW4sB0d9yQRHSNkZ37EW/HWqV2SNWEhv5LLVmXr00L9k6Y6EOXwS1fbHZ+mmZkkE0LIf9Vml71YG0Ra5diiQAG/mJnJkNOTeDBN2WNMA04b0Do7mYB+yOym2J/3Az0r+xcDYvsArARinLx6R7zjaYbrvLc4OquZx6 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: 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;