From patchwork Tue Nov 11 11:31:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Pengyang X-Patchwork-Id: 40568 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 7912F241C9 for ; Tue, 11 Nov 2014 11:33:17 +0000 (UTC) Received: by mail-wg0-f70.google.com with SMTP id x13sf5175303wgg.9 for ; Tue, 11 Nov 2014 03:33:16 -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:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=dXOqodg/bcOvFI4gGY+xklMM9gxbbaxQOrQMORWVKVQ=; b=ERvyaJpw8cyZsObKsBJhZFQd4S9H2h6DY0QRcc2pYZG1nJ9qO2bGatmJ+d4ARdbELZ tFHeLek9BH9pdPhvwiJezkcOULrp2zQ4W6pDibslroNfmAka26q6ACDk8TWtmKFzptjv mptA18i5Y4vRgAb3/8hjFpS1THZe1f6Zt3P57RwOF9P5+G0ppWNfpyELva1lE4xrcnOC WsQW2D6BMRfVQjwRry9mou1jt+xr4nMt+U9UMJp20k0VRgK9ca3uPUZFco+9/YkNWibO ASAoo/oBPjNi4wPdhl9h4142FpRqSiCtajDEBMQ5y4yYOdAUbDyYVOqFZvMvotdVsNOL bLmA== X-Gm-Message-State: ALoCoQnYHG8fQ//TimvTLZ1W3LGSQaWaTHG/75rWxWgMOpJBUqzhDY9nDyNFM7j3hSe4E/jpjJ5x X-Received: by 10.181.13.80 with SMTP id ew16mr3409251wid.4.1415705596749; Tue, 11 Nov 2014 03:33:16 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.26.72 with SMTP id j8ls422766lag.105.gmail; Tue, 11 Nov 2014 03:33:16 -0800 (PST) X-Received: by 10.152.25.226 with SMTP id f2mr1357127lag.98.1415705596484; Tue, 11 Nov 2014 03:33:16 -0800 (PST) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com. [209.85.217.171]) by mx.google.com with ESMTPS id u2si31087854lal.70.2014.11.11.03.33.16 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 11 Nov 2014 03:33:16 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by mail-lb0-f171.google.com with SMTP id b6so7447128lbj.30 for ; Tue, 11 Nov 2014 03:33:16 -0800 (PST) X-Received: by 10.112.14.69 with SMTP id n5mr35640240lbc.34.1415705596412; Tue, 11 Nov 2014 03:33:16 -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.184.201 with SMTP id ew9csp239563lbc; Tue, 11 Nov 2014 03:33:15 -0800 (PST) X-Received: by 10.68.220.169 with SMTP id px9mr11082904pbc.146.1415705591192; Tue, 11 Nov 2014 03:33:11 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ms8si6258344pdb.144.2014.11.11.03.33.10 for ; Tue, 11 Nov 2014 03:33:11 -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 S1753220AbaKKLdI (ORCPT + 1 other); Tue, 11 Nov 2014 06:33:08 -0500 Received: from szxga01-in.huawei.com ([119.145.14.64]:2658 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753216AbaKKLdA (ORCPT ); Tue, 11 Nov 2014 06:33:00 -0500 Received: from 172.24.2.119 (EHLO szxeml406-hub.china.huawei.com) ([172.24.2.119]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CEG64710; Tue, 11 Nov 2014 19:32:57 +0800 (CST) Received: from linux-2wy1.site (10.107.197.185) by szxeml406-hub.china.huawei.com (10.82.67.93) with Microsoft SMTP Server id 14.3.158.1; Tue, 11 Nov 2014 19:32:47 +0800 From: Hou Pengyang To: , CC: Subject: [PATCH 11/12] ARM: 8108/1: mm: Introduce {pte, pmd}_isset and {pte, pmd}_isclear Date: Tue, 11 Nov 2014 11:31:38 +0000 Message-ID: <1415705499-197612-12-git-send-email-houpengyang@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1415705499-197612-1-git-send-email-houpengyang@huawei.com> References: <1415705499-197612-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.171 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.10: - adjust the context - ignore change to pmd, because 3.10 does not support HugePage.] Signed-off-by: Hou Pengyang Conflicts: arch/arm/include/asm/pgtable-3level.h arch/arm/include/asm/pgtable.h --- arch/arm/include/asm/pgtable.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h index 5aac06f..4043d7f 100644 --- a/arch/arm/include/asm/pgtable.h +++ b/arch/arm/include/asm/pgtable.h @@ -211,12 +211,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))