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: 11706891 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 4C33A618 for ; Mon, 10 Aug 2020 02:28:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0E15620709 for ; Mon, 10 Aug 2020 02:28:00 +0000 (UTC) Authentication-Results: mail.kernel.org; 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 0E15620709 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 43FA98D0002; Sun, 9 Aug 2020 22:27:59 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3EF886B0006; Sun, 9 Aug 2020 22:27:59 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2DED88D0002; Sun, 9 Aug 2020 22:27:59 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0140.hostedemail.com [216.40.44.140]) by kanga.kvack.org (Postfix) with ESMTP id 1A8DA6B0005 for ; Sun, 9 Aug 2020 22:27:59 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id D7A56362B for ; Mon, 10 Aug 2020 02:27:58 +0000 (UTC) X-FDA: 77133073836.14.nut74_33097bb26fd6 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id B14F818229818 for ; Mon, 10 Aug 2020 02:27:58 +0000 (UTC) X-Spam-Summary: 1,0,0,a9a3bbeff89958b8,d41d8cd98f00b204,npiggin@gmail.com,,RULES_HIT:41:69:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1359:1515:1535:1542:1711:1730:1747:1777:1792:2393:2559:2562:2898:3138:3139:3140:3141:3142:3354:3876:3877:4117:4321:5007:6114:6119:6261:6642:6653:6742:7514:9413:10004:11026:11473:11658:11914:12043:12291:12296:12297:12438:12517:12519:12555:12683:12895:12986:13255:13894:14096:14110:14181:14394:14687:14721:21080:21444:21451:21611:21627:21666:21990:30054:30070,0,RBL:209.85.216.66:@gmail.com:.lbl8.mailshell.net-62.50.0.100 66.100.201.100;04yrkhw9hd8y5oae83zfnxeurwkcqoc8ha73weafrcdj8f1an8pmb7rddtuhwaf.mtrcedn96h53dqjjmd51asrhr4b6bke8qzhcsgttjw738robuwdfjzmmw19tdmr.o-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: nut74_33097bb26fd6 X-Filterd-Recvd-Size: 6142 Received: from mail-pj1-f66.google.com (mail-pj1-f66.google.com [209.85.216.66]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Mon, 10 Aug 2020 02:27:58 +0000 (UTC) Received: by mail-pj1-f66.google.com with SMTP id d4so4160097pjx.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=tEkzr407mDvFm86iMpJoGNCvL7OGpYKuWyDovoydjAvfDrsYblHWB/UdwrgBnlwLgr L7wan7oaSGqvMWkJGMVOStFGe2PQ376e7wMZ8hz2h4KdrhJ2Ea5WZ6n7ufQOkJHdPcYk 7szNRExP0N1ULvyGVID2PRzY6gvbpkwMRf89+XulDzuUv0/DIoYU8+ioJacaBEZ0U+Vo MGOw7mjOTWzclCYiWqsOwjboN1azqbtm50f/soUI3U3AOTzFozVvT4uuAfEqpTyqHDxr pUTFoBxElTn3pD24JuT4xrNvopEL44Ff7mnWBqMpjs3BtkizPwFW6NaMV8X3RAmTl3bl 06qA== X-Gm-Message-State: AOAM533ct89kioaxrdQtCaRSj4JOQqIDYPxVNH0jMluyGOTGYJ0CqFFk HGugo1zJVXVGeJ0jwkEcbD/HoR+k 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 Cc: Nicholas Piggin , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Zefan Li 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-Rspamd-Queue-Id: B14F818229818 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 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: 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;