From patchwork Tue Feb 10 02:30:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Pengyang X-Patchwork-Id: 44512 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f71.google.com (mail-ee0-f71.google.com [74.125.83.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 33EE021512 for ; Tue, 10 Feb 2015 02:33:07 +0000 (UTC) Received: by mail-ee0-f71.google.com with SMTP id d17sf1448765eek.2 for ; Mon, 09 Feb 2015 18:33:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-type:sender:precedence :list-id:x-original-sender:x-original-authentication-results :mailing-list:list-post:list-help:list-archive:list-unsubscribe; bh=u4g78vRqt+bayVpnKrn0DjdpwvX6yvr8ocAJ5bdSfpc=; b=YAcl9uwsyylXRRxYk68/Xkqt4g9kvHPNnMsfiMbFF7dx5PVP8OYTUs04UhqtGQiSNg eUTcDTcQzAQ+tS5Qik/bktY3MwgUvQgHnYnbcRdYu4QfAp8DerXotaUtAGAiQ9xifNHX sOApiPFBh+mDUiks+aIkVb45zOwUCrykTg/2DeIiKhZjLn9enjrcmZ8AqEKSALIbPRSV J37cZ0Ryrq8nKLY2k8kCGtoYeXb53YtrpxdtQuw0Ip1c6+s9vU23eZtyvyQexiDKELRg Fi2nDjrYw/BvMHzNmPqKTpUeLoMZsLbuwOnCeopEeqnjXsT9hTuo3tuMI5Y8runJls43 DWnA== X-Gm-Message-State: ALoCoQntSwcv4Pawp97CWMCDfXbjuWJp8LYPcmT3C6QBV+zjx9GzZaYjjirU214ISBquDMygvHLX X-Received: by 10.152.10.65 with SMTP id g1mr2395172lab.5.1423535586368; Mon, 09 Feb 2015 18:33:06 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.7.106 with SMTP id db10ls283985lad.54.gmail; Mon, 09 Feb 2015 18:33:06 -0800 (PST) X-Received: by 10.152.21.97 with SMTP id u1mr9917280lae.53.1423535586182; Mon, 09 Feb 2015 18:33:06 -0800 (PST) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com. [209.85.217.169]) by mx.google.com with ESMTPS id xv2si9309554lab.133.2015.02.09.18.33.06 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Feb 2015 18:33:06 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) client-ip=209.85.217.169; Received: by mail-lb0-f169.google.com with SMTP id f15so33544047lbj.0 for ; Mon, 09 Feb 2015 18:33:06 -0800 (PST) X-Received: by 10.152.37.138 with SMTP id y10mr20803586laj.88.1423535586080; Mon, 09 Feb 2015 18:33:06 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp330506lbj; Mon, 9 Feb 2015 18:33:05 -0800 (PST) X-Received: by 10.66.66.230 with SMTP id i6mr1187861pat.108.1423535583430; Mon, 09 Feb 2015 18:33:03 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id oh4si24774690pbc.168.2015.02.09.18.33.02; Mon, 09 Feb 2015 18:33:03 -0800 (PST) Received-SPF: none (google.com: stable-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750734AbbBJCdA (ORCPT + 1 other); Mon, 9 Feb 2015 21:33:00 -0500 Received: from szxga01-in.huawei.com ([119.145.14.64]:53970 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750757AbbBJCc7 (ORCPT ); Mon, 9 Feb 2015 21:32:59 -0500 Received: from 172.24.2.119 (EHLO SZXEML429-HUB.china.huawei.com) ([172.24.2.119]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CJI18420; Tue, 10 Feb 2015 10:32:58 +0800 (CST) Received: from linux-2wy1.site (10.107.197.185) by SZXEML429-HUB.china.huawei.com (10.82.67.184) with Microsoft SMTP Server id 14.3.158.1; Tue, 10 Feb 2015 10:32:49 +0800 From: Hou Pengyang To: , CC: , Subject: [PATCH 1/2] ARM: 8108/1: mm: Introduce {pte, pmd}_isset and {pte, pmd}_isclear Date: Tue, 10 Feb 2015 02:30:32 +0000 Message-ID: <1423535433-213902-2-git-send-email-houpengyang@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1423535433-213902-1-git-send-email-houpengyang@huawei.com> References: <1423535433-213902-1-git-send-email-houpengyang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.107.197.185] X-CFilter-Loop: Reflected Sender: stable-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: stable@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: patch@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Steven Capper commit f2950706871c4b6e8c0f0d7c3f62d35930b8de63 upstream. Long descriptors on ARM are 64 bits, and some pte functions such as pte_dirty return a bitwise-and of a flag with the pte value. If the flag to be tested resides in the upper 32 bits of the pte, then we run into the danger of the result being dropped if downcast. For example: gather_stats(page, md, pte_dirty(*pte), 1); where pte_dirty(*pte) is downcast to an int. This patch introduces a new macro pte_isset which performs the bitwise and, then performs a double logical invert (where needed) to ensure predictable downcasting. The logical inverse pte_isclear is also introduced. Equivalent pmd functions for Transparent HugePages have also been added. Signed-off-by: Steve Capper Reviewed-by: Will Deacon Signed-off-by: Russell King [hpy: Backported to 3.14 - adjust the context ] Signed-off-by: Hou Pengyang --- arch/arm/include/asm/pgtable-3level.h | 12 ++++++++---- arch/arm/include/asm/pgtable.h | 14 +++++++++----- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h index 85c60ad..34f371c 100644 --- a/arch/arm/include/asm/pgtable-3level.h +++ b/arch/arm/include/asm/pgtable-3level.h @@ -207,17 +207,21 @@ static inline pmd_t *pmd_offset(pud_t *pud, unsigned long addr) #define pte_huge(pte) (pte_val(pte) && !(pte_val(pte) & PTE_TABLE_BIT)) #define pte_mkhuge(pte) (__pte(pte_val(pte) & ~PTE_TABLE_BIT)) -#define pmd_young(pmd) (pmd_val(pmd) & PMD_SECT_AF) +#define pmd_isset(pmd, val) ((u32)(val) == (val) ? pmd_val(pmd) & (val) \ + : !!(pmd_val(pmd) & (val))) +#define pmd_isclear(pmd, val) (!(pmd_val(pmd) & (val))) + +#define pmd_young(pmd) (pmd_isset((pmd), PMD_SECT_AF)) #define __HAVE_ARCH_PMD_WRITE -#define pmd_write(pmd) (!(pmd_val(pmd) & PMD_SECT_RDONLY)) +#define pmd_write(pmd) (pmd_isclear((pmd), PMD_SECT_RDONLY)) #define pmd_hugewillfault(pmd) (!pmd_young(pmd) || !pmd_write(pmd)) #define pmd_thp_or_huge(pmd) (pmd_huge(pmd) || pmd_trans_huge(pmd)) #ifdef CONFIG_TRANSPARENT_HUGEPAGE -#define pmd_trans_huge(pmd) (pmd_val(pmd) && !(pmd_val(pmd) & PMD_TABLE_BIT)) -#define pmd_trans_splitting(pmd) (pmd_val(pmd) & PMD_SECT_SPLITTING) +#define pmd_trans_huge(pmd) (pmd_val(pmd) && !pmd_table(pmd)) +#define pmd_trans_splitting(pmd) (pmd_isset((pmd), PMD_SECT_SPLITTING)) #endif #define PMD_BIT_FUNC(fn,op) \ diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h index 7d59b52..89dba13 100644 --- a/arch/arm/include/asm/pgtable.h +++ b/arch/arm/include/asm/pgtable.h @@ -214,12 +214,16 @@ static inline pte_t *pmd_page_vaddr(pmd_t pmd) #define pte_clear(mm,addr,ptep) set_pte_ext(ptep, __pte(0), 0) +#define pte_isset(pte, val) ((u32)(val) == (val) ? pte_val(pte) & (val) \ + : !!(pte_val(pte) & (val))) +#define pte_isclear(pte, val) (!(pte_val(pte) & (val))) + #define pte_none(pte) (!pte_val(pte)) -#define pte_present(pte) (pte_val(pte) & L_PTE_PRESENT) -#define pte_write(pte) (!(pte_val(pte) & L_PTE_RDONLY)) -#define pte_dirty(pte) (pte_val(pte) & L_PTE_DIRTY) -#define pte_young(pte) (pte_val(pte) & L_PTE_YOUNG) -#define pte_exec(pte) (!(pte_val(pte) & L_PTE_XN)) +#define pte_present(pte) (pte_isset((pte), L_PTE_PRESENT)) +#define pte_write(pte) (pte_isclear((pte), L_PTE_RDONLY)) +#define pte_dirty(pte) (pte_isset((pte), L_PTE_DIRTY)) +#define pte_young(pte) (pte_isset((pte), L_PTE_YOUNG)) +#define pte_exec(pte) (pte_isclear((pte), L_PTE_XN)) #define pte_special(pte) (0) #define pte_present_user(pte) (pte_present(pte) && (pte_val(pte) & L_PTE_USER))