From patchwork Tue Nov 19 17:35:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Capper X-Patchwork-Id: 3203421 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.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A5816C045B for ; Tue, 19 Nov 2013 17:36:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8C2E02030E for ; Tue, 19 Nov 2013 17:36:29 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 874C12015E for ; Tue, 19 Nov 2013 17:36:24 +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 1VipDd-0005Tk-5I; Tue, 19 Nov 2013 17:36:09 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VipDV-0005bk-7x; Tue, 19 Nov 2013 17:36:01 +0000 Received: from mail-wi0-f173.google.com ([209.85.212.173]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VipDR-0005ao-QA for linux-arm-kernel@lists.infradead.org; Tue, 19 Nov 2013 17:35:58 +0000 Received: by mail-wi0-f173.google.com with SMTP id hm4so258930wib.0 for ; Tue, 19 Nov 2013 09:35:40 -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:in-reply-to :references; bh=NlHZBMQbZXPtdARnHMrP2dIFKBHIyzLjMCvi+qfLfwU=; b=Y/l6sJDB070LyhBbZIhgSatJq1Rp8SGPmu6Aic2SGtUpaCt3Jg7EmybrUGHxWXhQ2q HgDf6I349oOYgvIp4Tq0T6r0uLLttnzgZHBB7lKKW/snuvLGhkYXjUumg45T13OHQ8JO m+bC374E4k90hbHwsv8x+ZQJONXlkyrRlLu5QD2hS2TqxsfkJvgSR8X5AaXsYPKYIhfw UszGotbS4hf+gWWzjxHPobzp5H+cZq//8HmN20Dh6WPyhUukHbfbYeqG1tGqIJUTnGZf ob7FMuOYEKIBo7lZNcYA0jX3Lr3h23yh2X4icmb/S6xy/9V1sx5hPu5XDtV7iYf8Ku8T IS3Q== X-Gm-Message-State: ALoCoQlyv2yGtXsWcJTHajCDWX1wdJOcN6IOef9xnNW9liac2nkAmeecR6Ih9jpQZoJIpod7Ep8I X-Received: by 10.180.39.238 with SMTP id s14mr22290254wik.60.1384882540104; Tue, 19 Nov 2013 09:35:40 -0800 (PST) Received: from marmot.wormnet.eu (marmot.wormnet.eu. [188.246.204.87]) by mx.google.com with ESMTPSA id s2sm7529862wiy.7.2013.11.19.09.35.39 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Nov 2013 09:35:39 -0800 (PST) From: Steve Capper To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/3] ARM: mm: Rewire LPAE set_huge_pte_at Date: Tue, 19 Nov 2013 17:35:27 +0000 Message-Id: <1384882529-28104-2-git-send-email-steve.capper@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1384882529-28104-1-git-send-email-steve.capper@linaro.org> References: <1384882529-28104-1-git-send-email-steve.capper@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131119_123557_967222_562C75C5 X-CRM114-Status: GOOD ( 13.73 ) X-Spam-Score: -2.6 (--) Cc: Steve Capper , patches@linaro.org, catalin.marinas@arm.com, will.deacon@arm.com, linux@arm.linux.org.uk, christoffer.dall@linaro.org 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.7 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 LPAE, set_huge_pte_at calls set_pte_at which then calls set_pte_ext, which in turn is wired up to call cpu_v7_set_pte_ext, which is defined in proc-v7-3level.S. 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, cpu_v7_set_pte_ext will change the bit layout of the resultant pte, and will set the read only bit if the dirty bit is not also enabled. 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 succesfully. Signed-off-by: Steve Capper --- arch/arm/include/asm/hugetlb-3level.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/arm/include/asm/hugetlb-3level.h b/arch/arm/include/asm/hugetlb-3level.h index d4014fb..211e9a8 100644 --- a/arch/arm/include/asm/hugetlb-3level.h +++ b/arch/arm/include/asm/hugetlb-3level.h @@ -40,7 +40,12 @@ 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); + VM_BUG_ON(addr >= TASK_SIZE); + + if (pte_present_user(pte)) + __sync_icache_dcache(pte); + + *ptep = pte; } static inline void huge_ptep_clear_flush(struct vm_area_struct *vma,