From patchwork Fri Jun 24 17:36:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Houghton X-Patchwork-Id: 12894933 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 9D471C433EF for ; Fri, 24 Jun 2022 17:37:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 00FCC8E0246; Fri, 24 Jun 2022 13:37:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E8C888E0244; Fri, 24 Jun 2022 13:37:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C1BFC8E0246; Fri, 24 Jun 2022 13:37:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 9C76D8E0244 for ; Fri, 24 Jun 2022 13:37:21 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 6F12160B6F for ; Fri, 24 Jun 2022 17:37:21 +0000 (UTC) X-FDA: 79613835882.02.CC0E3F4 Received: from mail-ua1-f73.google.com (mail-ua1-f73.google.com [209.85.222.73]) by imf30.hostedemail.com (Postfix) with ESMTP id 134E58002C for ; Fri, 24 Jun 2022 17:37:20 +0000 (UTC) Received: by mail-ua1-f73.google.com with SMTP id b10-20020ab0238a000000b0037efa0a4ba0so1013217uan.11 for ; Fri, 24 Jun 2022 10:37:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=LYP6EWO0tHkDZ/Eb/N4ct/rtumW77ceMKYt6OWO28gw=; b=XFGCLL1FPCDch3s8zoHY1/aiVrNxiWrnh/6o6qV/K2RAwhUG1NoqoYSivh5BlEjSSN JSeDqdD7wmJqUHehWTyabP/SFxoPxLcdmJQciamvw0zZEkmrFOLEfH5MKvY7BMKKaRs5 OeQHOUrdz9iPL7xkNs8N8nJEHEVe58C79l9VExLO0snSG9Lzk432UZi5FNR67YMTpjNb nWD0bA1/rl29atfGjcsEE2x8Ah2JCvGLGQcQO7+KX8SrBMuFX9ufi1FM9t5s4yyq73GD HMYrizZfRIn1go+aVU8Gs1V6ny5gGjt1jqAVjKkGM9IiyAl9gtwolhjj4PEcCHbqvzlV R5nQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=LYP6EWO0tHkDZ/Eb/N4ct/rtumW77ceMKYt6OWO28gw=; b=HDcpaw7sGWCXM4ORuGAsY/YXBwDEQC4iXpTkxq0Dux6Uflfh5JkXIu3YOYc+kZb5rf SB98KZP1TPua+o1szL6VhENeiDoSzcOkwHCT+KGwQRuPt3NGw6gYXs4JKXWP8QjcsuYl ibv521NV8uNSxTJfnjhKJqtACg+I0yymlJi3shc59QiEnoowRSSEwyGFgDi+IuntHzsW 1tnLnWn3llyQILwhlVxAg6vKz2bnIjmU69qwTWWY8gjmBFYmNh8FA1eq75Aeokm1AaHl bA+C0b0RxFaQxbhZ746qaZu6wBq/yuHIBBhoA9Yhrdbo03KNos8txEETpubQD8SRMcSJ QH6A== X-Gm-Message-State: AJIora+o5Jun2LSDciKxsB5OIGz2jylwS44SuQ665deMrekh3xdX1/kj a0EckhfygidGssPj6xuhWqXQM8NJ4XM1jggG X-Google-Smtp-Source: AGRyM1ssMLMIRbwDkEduAqDq4DS/T59s9retjKTDy0iTSci5NwCImR9/ISla7A1bU/FQrm45/Cl8LL0Be0TLQc6l X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a05:6102:374d:b0:34c:1f02:aa59 with SMTP id u13-20020a056102374d00b0034c1f02aa59mr21351211vst.21.1656092240411; Fri, 24 Jun 2022 10:37:20 -0700 (PDT) Date: Fri, 24 Jun 2022 17:36:38 +0000 In-Reply-To: <20220624173656.2033256-1-jthoughton@google.com> Message-Id: <20220624173656.2033256-9-jthoughton@google.com> Mime-Version: 1.0 References: <20220624173656.2033256-1-jthoughton@google.com> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [RFC PATCH 08/26] hugetlb: add hugetlb_free_range to free PT structures From: James Houghton To: Mike Kravetz , Muchun Song , Peter Xu Cc: David Hildenbrand , David Rientjes , Axel Rasmussen , Mina Almasry , Jue Wang , Manish Mishra , "Dr . David Alan Gilbert" , linux-mm@kvack.org, linux-kernel@vger.kernel.org, James Houghton ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656092241; a=rsa-sha256; cv=none; b=Di5n7BI33Of2x62fKDQy5JmJpnGEUhiWE2n1GL2ude5mPUVluTyfgAR3mTN7kCgcMXbFxN ZJB9lGlAO2/kPJpdWiGc596ylEH/+gSioKN+nPZnLMASY4V2rQ0/JKctx0/lH+Ls0Yvyea ksFL0/BjRLa42U5XKLN8CWbpcDBX4rE= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=XFGCLL1F; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf30.hostedemail.com: domain of 3UPa1YgoKCDEWgUbhTUgbaTbbTYR.PbZYVahk-ZZXiNPX.beT@flex--jthoughton.bounces.google.com designates 209.85.222.73 as permitted sender) smtp.mailfrom=3UPa1YgoKCDEWgUbhTUgbaTbbTYR.PbZYVahk-ZZXiNPX.beT@flex--jthoughton.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656092241; 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=LYP6EWO0tHkDZ/Eb/N4ct/rtumW77ceMKYt6OWO28gw=; b=NpgaoNaSdB2rel75vhDUc+dXdnkgxzdy9TONXClFPan7SNO0ucTCkpPZlJrnUGu7YYcXoj 2pW/DEKHa9eL28qHo35CvYehse+tVskHRCrOzOY5Vx6lI+iQ541pSSodb7pN4vsdZsyLJk W0ZrHCnziBvgAZmEcjl3Ablmcv/WIDo= X-Stat-Signature: 1ejqgbhoaztf41ff9jyy5qhnsefr49ym X-Rspamd-Queue-Id: 134E58002C Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=XFGCLL1F; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf30.hostedemail.com: domain of 3UPa1YgoKCDEWgUbhTUgbaTbbTYR.PbZYVahk-ZZXiNPX.beT@flex--jthoughton.bounces.google.com designates 209.85.222.73 as permitted sender) smtp.mailfrom=3UPa1YgoKCDEWgUbhTUgbaTbbTYR.PbZYVahk-ZZXiNPX.beT@flex--jthoughton.bounces.google.com X-Rspamd-Server: rspam10 X-Rspam-User: X-HE-Tag: 1656092240-564722 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: This is a helper function for freeing the bits of the page table that map a particular HugeTLB PTE. Signed-off-by: James Houghton --- include/linux/hugetlb.h | 2 ++ mm/hugetlb.c | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 1d4ec9dfdebf..33ba48fac551 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -107,6 +107,8 @@ bool hugetlb_pte_none_mostly(const struct hugetlb_pte *hpte); pte_t hugetlb_ptep_get(const struct hugetlb_pte *hpte); void hugetlb_pte_clear(struct mm_struct *mm, const struct hugetlb_pte *hpte, unsigned long address); +void hugetlb_free_range(struct mmu_gather *tlb, const struct hugetlb_pte *hpte, + unsigned long start, unsigned long end); struct hugepage_subpool { spinlock_t lock; diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 1a1434e29740..a2d2ffa76173 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1120,6 +1120,23 @@ static bool vma_has_reserves(struct vm_area_struct *vma, long chg) return false; } +void hugetlb_free_range(struct mmu_gather *tlb, const struct hugetlb_pte *hpte, + unsigned long start, unsigned long end) +{ + unsigned long floor = start & hugetlb_pte_mask(hpte); + unsigned long ceiling = floor + hugetlb_pte_size(hpte); + + if (hugetlb_pte_size(hpte) >= PGDIR_SIZE) { + free_p4d_range(tlb, (pgd_t *)hpte->ptep, start, end, floor, ceiling); + } else if (hugetlb_pte_size(hpte) >= P4D_SIZE) { + free_pud_range(tlb, (p4d_t *)hpte->ptep, start, end, floor, ceiling); + } else if (hugetlb_pte_size(hpte) >= PUD_SIZE) { + free_pmd_range(tlb, (pud_t *)hpte->ptep, start, end, floor, ceiling); + } else if (hugetlb_pte_size(hpte) >= PMD_SIZE) { + free_pte_range(tlb, (pmd_t *)hpte->ptep, start); + } +} + bool hugetlb_pte_present_leaf(const struct hugetlb_pte *hpte) { pgd_t pgd;