From patchwork Mon Aug 10 02:27:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 11706907 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6A9A616B1 for ; Mon, 10 Aug 2020 02:30:00 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 40A7E20709 for ; Mon, 10 Aug 2020 02:30:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="fE7m/kl3"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WP278OOY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 40A7E20709 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=pGmuHg23is8GOyLe7qSLAjDNFmoW569BHKHkzmrEcAc=; b=fE7m/kl3NCWMSn1j5gPah9DUD OcyJao2khIak8p6z9sOaUsniXe2UHGmFQsejVtdHNGwQyJDNQ9UkKgWIs27CtOhs1E+vYTAfDDJ+n +feZvpG49ksxTGl9Ua8LpdSG5UYK7jL7hLtPONLGGI5Fnw3wogqZ4f1GUwNuRfrRMvLu1VWh6zpUb kyNzkHgImQTzFg80keZBFN/zG2YhPV104wVjM5c9qjSPsGxM0nwjK5Goo/DaL9yTFvxv2QVVVpFl2 7vBSa2g4xzonoSYKGzQvEAUvr32kYRE8pzl4UvvtckLtCu7X9vZeCJiYpcAfIMkzyUjSDGxLaKIKx sOZxt8hKA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1k4xXd-00050A-Qq; Mon, 10 Aug 2020 02:28:01 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1k4xXb-0004yl-83 for linux-arm-kernel@lists.infradead.org; Mon, 10 Aug 2020 02:28:00 +0000 Received: by mail-pl1-x644.google.com with SMTP id t11so4040349plr.5 for ; Sun, 09 Aug 2020 19:27:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mxm/C2mC0786WMQTE10aJFvTg/Tw0xwUgIx5I5X+hjE=; b=WP278OOYLrG+JIYsivHVGAzMTDa1eY0iFpr/M6I+aKWKr6bMnyODBgG4KETvzcgTXd ow7Jj2tsasJ8YFFWufeQv277XGisF25VPY5ZRhlBYYgpEWp1+50PYmlf923Gu/QUOITt etVT077ynKT7AWNGF/5mQcMdPJjA0gFZC+nLCGBjmku/JKs79bACOlt5k+qdWfrkM+Ui 7cIyNArYFYHVtz1M3cDImsXm9SmwTNdx2tC09A2Dter3y6Kuu2/oxvSq89h1uNaAGDuh zDBy5Pjw69YLMWfuhW7I/ekJKMRZ80wZ+GACMvHlcpOX7TEgC42KFlaiBl9YI8RZowwS DNKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mxm/C2mC0786WMQTE10aJFvTg/Tw0xwUgIx5I5X+hjE=; b=N0iuHbXyiHsKI7WafiKUKOJWlqR4K5rQHdGGzy39NuhjbizJ2CQSWEU5A5ufA6L8q0 b7fbZdwgh/yEolHLxoWS3+JIDKFWPKWqXo0LGoQsZ9QKRrmVZyWbDjQXeG+hzzk+crRH qSQmlmorf1N8qkM6EWCuuaoUJlDEgc+s11CZvpEoQerAYFkYzVX4yh4FHTgdWCSHH+t2 TOJ42EWpfQ2gC8em4Xk+Uhnkf+rcWWagJBh4BWuURDn/j8SSpjSukAgI4ANbnBxtl3Gg MOOmMIJtGF8m0GSBZm3xzkTUgwzzwBKcnfHBUVf8A41/t2cKwRJAt8M9sG/rdmEN7/gU hD6A== X-Gm-Message-State: AOAM5311nP7ptT3AWKpfg4knaInI613He4BREZ9qZ+6z6+nNtxj8hK/b V64PplJm0oeTvq4/OEWcULI= X-Google-Smtp-Source: ABdhPJzQrXlZ5GNgG6uz8L7myrJaEH5zZlbvoa/Z7fFHnyqY5iIPX6x3JpckcdyVbZxn3y4vyTxFlA== X-Received: by 2002:a17:902:7681:: with SMTP id m1mr9854542pll.62.1597026477066; Sun, 09 Aug 2020 19:27:57 -0700 (PDT) Received: from bobo.ibm.com (193-116-100-32.tpgi.com.au. [193.116.100.32]) by smtp.gmail.com with ESMTPSA id l17sm21863475pff.126.2020.08.09.19.27.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Aug 2020 19:27:56 -0700 (PDT) From: Nicholas Piggin To: linux-mm@kvack.org Subject: [PATCH v3 2/8] mm: apply_to_pte_range warn and fail if a large pte is encountered Date: Mon, 10 Aug 2020 12:27:26 +1000 Message-Id: <20200810022732.1150009-3-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200810022732.1150009-1-npiggin@gmail.com> References: <20200810022732.1150009-1-npiggin@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200809_222759_307159_F251339A X-CRM114-Status: GOOD ( 14.99 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:644 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [npiggin[at]gmail.com] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, Zefan Li , Catalin Marinas , x86@kernel.org, linuxppc-dev@lists.ozlabs.org, Nicholas Piggin , linux-kernel@vger.kernel.org, Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Thomas Gleixner , Will Deacon , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Signed-off-by: Nicholas Piggin --- mm/memory.c | 60 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index c39a13b09602..1d5f3093c249 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -2260,13 +2260,20 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud, } do { next = pmd_addr_end(addr, end); - if (create || !pmd_none_or_clear_bad(pmd)) { - err = apply_to_pte_range(mm, pmd, addr, next, fn, data, - create); - if (err) - break; + if (pmd_none(*pmd) && !create) + continue; + if (WARN_ON_ONCE(pmd_leaf(*pmd))) + return -EINVAL; + if (WARN_ON_ONCE(pmd_bad(*pmd))) { + if (!create) + continue; + pmd_clear_bad(pmd); } + err = apply_to_pte_range(mm, pmd, addr, next, fn, data, create); + if (err) + break; } while (pmd++, addr = next, addr != end); + return err; } @@ -2287,13 +2294,20 @@ static int apply_to_pud_range(struct mm_struct *mm, p4d_t *p4d, } do { next = pud_addr_end(addr, end); - if (create || !pud_none_or_clear_bad(pud)) { - err = apply_to_pmd_range(mm, pud, addr, next, fn, data, - create); - if (err) - break; + if (pud_none(*pud) && !create) + continue; + if (WARN_ON_ONCE(pud_leaf(*pud))) + return -EINVAL; + if (WARN_ON_ONCE(pud_bad(*pud))) { + if (!create) + continue; + pud_clear_bad(pud); } + err = apply_to_pmd_range(mm, pud, addr, next, fn, data, create); + if (err) + break; } while (pud++, addr = next, addr != end); + return err; } @@ -2314,13 +2328,20 @@ static int apply_to_p4d_range(struct mm_struct *mm, pgd_t *pgd, } do { next = p4d_addr_end(addr, end); - if (create || !p4d_none_or_clear_bad(p4d)) { - err = apply_to_pud_range(mm, p4d, addr, next, fn, data, - create); - if (err) - break; + if (p4d_none(*p4d) && !create) + continue; + if (WARN_ON_ONCE(p4d_leaf(*p4d))) + return -EINVAL; + if (WARN_ON_ONCE(p4d_bad(*p4d))) { + if (!create) + continue; + p4d_clear_bad(p4d); } + err = apply_to_pud_range(mm, p4d, addr, next, fn, data, create); + if (err) + break; } while (p4d++, addr = next, addr != end); + return err; } @@ -2339,8 +2360,15 @@ static int __apply_to_page_range(struct mm_struct *mm, unsigned long addr, pgd = pgd_offset(mm, addr); do { next = pgd_addr_end(addr, end); - if (!create && pgd_none_or_clear_bad(pgd)) + if (pgd_none(*pgd) && !create) continue; + if (WARN_ON_ONCE(pgd_leaf(*pgd))) + return -EINVAL; + if (WARN_ON_ONCE(pgd_bad(*pgd))) { + if (!create) + continue; + pgd_clear_bad(pgd); + } err = apply_to_p4d_range(mm, pgd, addr, next, fn, data, create); if (err) break;