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: 21898 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f72.google.com (mail-qa0-f72.google.com [209.85.216.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8941623FC4 for ; Fri, 29 Nov 2013 15:34:47 +0000 (UTC) Received: by mail-qa0-f72.google.com with SMTP id f11sf4542179qae.11 for ; Fri, 29 Nov 2013 07:34:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=F3UXz5np9hPD90kzKT3xdfaGNoVvkKgt0XdKgRQoDi0=; b=JCwE8q64PFXw0xkZkisGOE5a0ox6vfIPi/hQTdl0mPOZY998cJOVMwqC0ruAR49oG8 Hsq6F5+WrBuUVuDjl8rIMesCw4js+HxmQ0Y1l/Afo9WCD26E7UCTMyX/VYUJECB+sMIl 3Mgyavv1x2IpglINolrycjQefdV9wa872nzmCK5Oxi8uSsd7d1zz3h3vZYEd02N+Syy5 gKwsUYDaddFmj4SE1U1m8Ja1oVX645GdcO61kUCzt9VuiZ9hTD9uh6JJk5ZqWD27lMMr In8AIKx4JgzcS5K9KQzHs3RrqZRr3e88TWeCZgpTtE0lr4e9+o3rIsWYd/AVPjC8ohUI 0Gbg== X-Gm-Message-State: ALoCoQkvfxAsreFw44pPGqd6B3PWtQSQ3vrr+MfAFxl8UD5Lct/gy3D01US5FpSWuB+xyqW9cE3a X-Received: by 10.236.51.9 with SMTP id a9mr23285853yhc.41.1385739286946; Fri, 29 Nov 2013 07:34:46 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.17.163 with SMTP id p3ls1135657qed.41.gmail; Fri, 29 Nov 2013 07:34:46 -0800 (PST) X-Received: by 10.52.32.37 with SMTP id f5mr35167646vdi.17.1385739286850; Fri, 29 Nov 2013 07:34:46 -0800 (PST) Received: from mail-vb0-f47.google.com (mail-vb0-f47.google.com [209.85.212.47]) by mx.google.com with ESMTPS id g10si24988277vcm.85.2013.11.29.07.34.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 29 Nov 2013 07:34:46 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.47 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.47; Received: by mail-vb0-f47.google.com with SMTP id x11so6695133vbb.20 for ; Fri, 29 Nov 2013 07:34:46 -0800 (PST) X-Received: by 10.52.227.165 with SMTP id sb5mr137344vdc.85.1385739286725; Fri, 29 Nov 2013 07:34:46 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp100682vcz; Fri, 29 Nov 2013 07:34:46 -0800 (PST) X-Received: by 10.194.20.230 with SMTP id q6mr21198682wje.49.1385739285822; Fri, 29 Nov 2013 07:34:45 -0800 (PST) Received: from mail-we0-f177.google.com (mail-we0-f177.google.com [74.125.82.177]) by mx.google.com with ESMTPS id ey8si4167172wib.53.2013.11.29.07.34.45 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 29 Nov 2013 07:34:45 -0800 (PST) Received-SPF: neutral (google.com: 74.125.82.177 is neither permitted nor denied by best guess record for domain of steve.capper@linaro.org) client-ip=74.125.82.177; Received: by mail-we0-f177.google.com with SMTP id p61so9365285wes.22 for ; Fri, 29 Nov 2013 07:34:45 -0800 (PST) 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 Cc: linux@arm.linux.org.uk, will.deacon@arm.com, catalin.marinas@arm.com, patches@linaro.org, prasun.kapoor@cavium.com, Steve Capper 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-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: steve.capper@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.47 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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,