From patchwork Fri Apr 3 13:03:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 46767 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2BEA8215B7 for ; Fri, 3 Apr 2015 13:04:04 +0000 (UTC) Received: by wgiv13 with SMTP id v13sf10980139wgi.3 for ; Fri, 03 Apr 2015 06:04:03 -0700 (PDT) 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:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=G4T5qn63Vrcw8n8reciUjYEPXTp1uBlrxTdHt4EpIYU=; b=b8eVH7gA9KC1IyWU/yxWE+eJmHgtsfl/goEi2/GuFlQoYOQ0bvw0X/bNT0YCV2PQua wljjvAYDM5uxwZX9Vkw2Aq1g/uC9nQm7bpVwFSgslr/sGok+C9Vb3WyF/rGdhhW3vds8 PspUL4X7Wyp3vYIP12aUzva0SVjBImGiVgNAGKQyWbVoNjl6I+6fu/ISnOcMi1Zjus/6 GxwfZgfsPO8D3z6e7ssntWxn9I2k+DvXiVn1s2OjdQTo0H8Jc9UYCTRdRELzq+dHl+Aj VDNMpa1H2QhuTLV+iPoQerVD9dL7zHHZ0pkUd/A6a9NUQbFBDsU2JvVUnMoW6Z5xFSNY FNyA== X-Gm-Message-State: ALoCoQnItoRVhcxDi3Agdz85amjrcALdokl/8IfwxJF1i1Bf3OI9mDUhbqYEJgZjFwh1un5lj6ix X-Received: by 10.194.236.196 with SMTP id uw4mr573752wjc.5.1428066243481; Fri, 03 Apr 2015 06:04:03 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.2.9 with SMTP id 9ls287704laq.16.gmail; Fri, 03 Apr 2015 06:04:03 -0700 (PDT) X-Received: by 10.152.28.233 with SMTP id e9mr2117852lah.3.1428066243351; Fri, 03 Apr 2015 06:04:03 -0700 (PDT) Received: from mail-lb0-f174.google.com (mail-lb0-f174.google.com. [209.85.217.174]) by mx.google.com with ESMTPS id qy3si6650435lbc.117.2015.04.03.06.04.03 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Apr 2015 06:04:03 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) client-ip=209.85.217.174; Received: by lbbug6 with SMTP id ug6so78767780lbb.3 for ; Fri, 03 Apr 2015 06:04:03 -0700 (PDT) X-Received: by 10.152.163.35 with SMTP id yf3mr2128671lab.86.1428066243202; Fri, 03 Apr 2015 06:04:03 -0700 (PDT) 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.57.201 with SMTP id k9csp1938791lbq; Fri, 3 Apr 2015 06:04:02 -0700 (PDT) X-Received: by 10.66.101.7 with SMTP id fc7mr4136768pab.26.1428066238367; Fri, 03 Apr 2015 06:03:58 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ki9si11954778pdb.160.2015.04.03.06.03.57; Fri, 03 Apr 2015 06:03:58 -0700 (PDT) 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 S1752595AbbDCND4 (ORCPT + 1 other); Fri, 3 Apr 2015 09:03:56 -0400 Received: from ip4-83-240-67-251.cust.nbox.cz ([83.240.67.251]:45367 "EHLO ip4-83-240-18-248.cust.nbox.cz" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752506AbbDCNDy (ORCPT ); Fri, 3 Apr 2015 09:03:54 -0400 Received: from ku by ip4-83-240-18-248.cust.nbox.cz with local (Exim 4.85) (envelope-from ) id 1Ye1GK-0001m0-ED; Fri, 03 Apr 2015 15:03:52 +0200 From: Jiri Slaby To: stable@vger.kernel.org Cc: Steven Capper , Russell King , Jiri Slaby Subject: [patch added to the 3.12 stable tree] ARM: 8108/1: mm: Introduce {pte, pmd}_isset and {pte, pmd}_isclear Date: Fri, 3 Apr 2015 15:03:43 +0200 Message-Id: <1428066232-6722-11-git-send-email-jslaby@suse.cz> X-Mailer: git-send-email 2.3.4 In-Reply-To: <1428066232-6722-1-git-send-email-jslaby@suse.cz> References: <1428066232-6722-1-git-send-email-jslaby@suse.cz> 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.174 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 This patch has been added to the 3.12 stable tree. If you have any objections, please let us know. =============== 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 Signed-off-by: Jiri Slaby --- 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 ceb4807ee8b2..738a2e346e1c 100644 --- a/arch/arm/include/asm/pgtable-3level.h +++ b/arch/arm/include/asm/pgtable-3level.h @@ -204,14 +204,18 @@ 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)) #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 1571d126e9dd..a348bfd34f66 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))