From patchwork Fri Nov 29 15:34:21 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Capper X-Patchwork-Id: 3258881 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C6CAE9F1F4 for ; Fri, 29 Nov 2013 15:35:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1C85E2053C for ; Fri, 29 Nov 2013 15:35:22 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BB6292051D for ; Fri, 29 Nov 2013 15:35:20 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VmQ67-0005yD-Su; Fri, 29 Nov 2013 15:35:16 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VmQ65-0004qO-Cu; Fri, 29 Nov 2013 15:35:13 +0000 Received: from mail-wg0-f48.google.com ([74.125.82.48]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VmQ62-0004ox-1K for linux-arm-kernel@lists.infradead.org; Fri, 29 Nov 2013 15:35:11 +0000 Received: by mail-wg0-f48.google.com with SMTP id z12so9514830wgg.27 for ; Fri, 29 Nov 2013 07:34:45 -0800 (PST) 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=F3UXz5np9hPD90kzKT3xdfaGNoVvkKgt0XdKgRQoDi0=; b=AW9xcMtfMAC2QV+2HLquIJclezFtaKT1jxwTGUrgzeoBCoqKkYGeDfhAXmDTiDObB1 zNk4v/vKMzYMf/LJT7iarpCB3X87tvuSdX2nqUWVdoGzJ1gTW/u5pwTKBFplNpf+oksB eUmOK6EeAD+rZXY17/7vT9J1eTbnoNo/hiO2QkoQJcqiCrJIt8NS7G7B41mUn/nq4d09 LCWLPIwy5ONLIK4Vyzah6gXhOxASSE2DAB7Ra2PfGSMOL71yH+QFPpNBO4aeh8fDG3Nq qsNK5BZgoUTIBSd6r2L6bwaSttwE18xWZeGGI6CJttEoPOAFT0L8uq0EoGvyhef3aVzl Twag== X-Gm-Message-State: ALoCoQmt0Ni2t6L8tt1908EF3tbsFtyszhiM73Lyd1kPYmL3S3r0qtJ1esBZFLTsW7vrpaMuj6A8 X-Received: by 10.180.36.105 with SMTP id p9mr7280436wij.58.1385739285319; Fri, 29 Nov 2013 07:34:45 -0800 (PST) Received: from marmot.wormnet.eu (marmot.wormnet.eu. [188.246.204.87]) by mx.google.com with ESMTPSA id c10sm92776796wie.11.2013.11.29.07.34.44 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Nov 2013 07:34:44 -0800 (PST) From: Steve Capper To: linux-arm-kernel@lists.infradead.org Subject: [PATCH] arm64: mm: Avoid set_pte_at with HugeTLB pages Date: Fri, 29 Nov 2013 15:34:21 +0000 Message-Id: <1385739261-26689-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-20131129_103510_228679_B0D3787D X-CRM114-Status: GOOD ( 13.81 ) X-Spam-Score: -2.6 (--) Cc: prasun.kapoor@cavium.com, linux@arm.linux.org.uk, patches@linaro.org, catalin.marinas@arm.com, will.deacon@arm.com, Steve Capper X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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, 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 For huge pages, given newprot a pgprot_t value for a shared writable VMA, and ptep a pointer to a pte belonging to this VMA; the following behaviour is assumed by core code: hugetlb_change_protection(vma, address, end, newprot); ... huge_pte_write(huge_ptep_get(ptep)); /* should be true! */ Unfortunately, set_huge_pte_at calls set_pte_at which includes a side-effect that renders ptes read only if the dirty bit is unset. If one were to allocate a read only shared huge page, then fault it in, and then mprotect it to be writeable. A subsequent write to that huge page will result in a spurious call to hugetlb_cow, which causes corruption. This call is optimised away prior to: 37a2140 mm, hugetlb: do not use a page in page cache for cow optimization If one runs the libhugetlbfs test suite on v3.12-rc1 upwards, then the mprotect test will cause the afformentioned corruption and before the set of tests completes, the system will be left in an unresponsive state. (calls to fork fail with -ENOMEM). This patch re-implements set_huge_pte_at to dereference the pte value explicitly. hugetlb_cow is no longer called spuriously, and the unit tests complete successfully. Signed-off-by: Steve Capper --- I operated under the deluded notion that set_pte_at on arm64 had no side effects when I originally sent out: http://lists.infradead.org/pipermail/linux-arm-kernel/2013-November/212475.html As this is patch is more or less self-contained for arm64, I am sending this out on its own rather than merging with the above series. Apologies for not catching this sooner. --- arch/arm64/include/asm/hugetlb.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/hugetlb.h b/arch/arm64/include/asm/hugetlb.h index 5b7ca8a..32b042f 100644 --- a/arch/arm64/include/asm/hugetlb.h +++ b/arch/arm64/include/asm/hugetlb.h @@ -33,7 +33,10 @@ static inline pte_t huge_ptep_get(pte_t *ptep) static inline void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte) { - set_pte_at(mm, addr, ptep, pte); + if (pte_exec(pte)) + __sync_icache_dcache(pte, addr); + + *ptep = pte; } static inline void huge_ptep_clear_flush(struct vm_area_struct *vma,