From patchwork Thu Oct 1 12:06:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Capper X-Patchwork-Id: 7308441 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 89C3BBEEA4 for ; Thu, 1 Oct 2015 12:11:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9CA822065F for ; Thu, 1 Oct 2015 12:11:52 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 73CC020618 for ; Thu, 1 Oct 2015 12:11:51 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZhcgV-00078k-DR; Thu, 01 Oct 2015 12:10:03 +0000 Received: from mail-wi0-f179.google.com ([209.85.212.179]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZhcdK-0003Rz-CM for linux-arm-kernel@lists.infradead.org; Thu, 01 Oct 2015 12:06:47 +0000 Received: by wiclk2 with SMTP id lk2so25103021wic.1 for ; Thu, 01 Oct 2015 05:06:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=DKcKTYv9JNt6PrlP8uCN0XYz4J/TY4lB8oxu82goRk0=; b=KAtXPijV0yzTJTv6mzPkvdTlInNlx0/cMebbmIpXyryvTofOPCKG217k3TDmnHktBN 5xORJe/XBoqlvw5DUNdRKH0t/SpleruycRjYv4A4QeW3V0DYdMMXIoeGKkRS0I1NxPGy 1+tjtTcHoC13XbI+NtJ5BOMfKPxWFIh/DMXtqhX2l5fs4O6LeZQUastrueuCSce6Hheg PSODvu+67/0ku9LXPVBc1rszOXwUH7dMtZN8VI9QOqxA3krp1i3QBRzWjwEHVEjldAXY eWrkIfCnOumbthMPda9Kf353q45xmzFYBOJ0hol7vvpCfTRn8Cay11qXQQ4QJt1n7ej4 xqmA== X-Gm-Message-State: ALoCoQkNDiSQjHC5bqXeFdQyV9QnyPt6e9iTOi6gGKLfWaoYobL5wp1gkVKH7kqJKr5Ynh9PM5hx X-Received: by 10.194.5.135 with SMTP id s7mr11829523wjs.153.1443701184165; Thu, 01 Oct 2015 05:06:24 -0700 (PDT) Received: from marmot.wormnet.eu (marmot.wormnet.eu. [188.246.204.87]) by smtp.gmail.com with ESMTPSA id lb10sm5836309wjc.9.2015.10.01.05.06.22 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Oct 2015 05:06:23 -0700 (PDT) From: Steve Capper To: catalin.marinas@arm.com, Ganapatrao.Kulkarni@caviumnetworks.com Subject: [PATCH] arm64: Fix THP protection change logic Date: Thu, 1 Oct 2015 13:06:07 +0100 Message-Id: <1443701167-10816-1-git-send-email-steve.capper@linaro.org> X-Mailer: git-send-email 1.7.10.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151001_050646_603823_990F981D X-CRM114-Status: GOOD ( 17.28 ) X-Spam-Score: -2.6 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Feng Kan , Steve Capper , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 6910fa1 ("arm64: enable PTE type bit in the mask for pte_modify") fixes a problem whereby a large block of PROT_NONE mapped memory is incorrectly mapped as block descriptors when mprotect is called. Unfortunately, a subtle bug was introduced by this fix to the THP logic. If one mmaps a large block of memory, then faults it such that it is collapsed into THPs; resulting calls to mprotect on this area of memory will lead to incorrect table descriptors being written instead of block descriptors. This is because pmd_modify calls pte_modify which is now allowed to modify the type of the page table entry. This patch reverts commit 6910fa16dbe142f6a0fd0fd7c249f9883ff7fc8a, and fixes the problem it was trying to address by adjusting PAGE_NONE to represent a table entry. Thus no change in pte type is required when moving from PROT_NONE to a different protection. Fixes: 6910fa16dbe1 ("arm64: enable PTE type bit in the mask for pte_modify") Cc: Feng Kan Reported-by: Ganapatrao Kulkarni Signed-off-by: Steve Capper Reviewed-by: Catalin Marinas Tested-by: Ganapatrao Kulkarni --- This patch stops my THP mprotect tests from crashing my machine quite horrendously. Ganapatrao, could you please give this a test and let me know if it behaves with your NUMA stuff? Feng, does this revised fix work with the Trinity test you mentioned in 6910fa1 ("arm64: enable PTE type bit in the mask for pte_modify")? Cheers, diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index 56283f8..cf73194 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -80,7 +80,7 @@ extern void __pgd_error(const char *file, int line, unsigned long val); #define PAGE_S2 __pgprot(PROT_DEFAULT | PTE_S2_MEMATTR(MT_S2_NORMAL) | PTE_S2_RDONLY) #define PAGE_S2_DEVICE __pgprot(PROT_DEFAULT | PTE_S2_MEMATTR(MT_S2_DEVICE_nGnRE) | PTE_S2_RDONLY | PTE_UXN) -#define PAGE_NONE __pgprot(((_PAGE_DEFAULT) & ~PTE_TYPE_MASK) | PTE_PROT_NONE | PTE_PXN | PTE_UXN) +#define PAGE_NONE __pgprot(((_PAGE_DEFAULT) & ~PTE_VALID) | PTE_PROT_NONE | PTE_PXN | PTE_UXN) #define PAGE_SHARED __pgprot(_PAGE_DEFAULT | PTE_USER | PTE_NG | PTE_PXN | PTE_UXN | PTE_WRITE) #define PAGE_SHARED_EXEC __pgprot(_PAGE_DEFAULT | PTE_USER | PTE_NG | PTE_PXN | PTE_WRITE) #define PAGE_COPY __pgprot(_PAGE_DEFAULT | PTE_USER | PTE_NG | PTE_PXN | PTE_UXN) @@ -460,7 +460,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long addr) static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) { const pteval_t mask = PTE_USER | PTE_PXN | PTE_UXN | PTE_RDONLY | - PTE_PROT_NONE | PTE_WRITE | PTE_TYPE_MASK; + PTE_PROT_NONE | PTE_VALID | PTE_WRITE; pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask); return pte; }