From patchwork Tue Feb 25 11:38:53 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Capper X-Patchwork-Id: 25285 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f200.google.com (mail-ob0-f200.google.com [209.85.214.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2CC1A20143 for ; Tue, 25 Feb 2014 11:53:13 +0000 (UTC) Received: by mail-ob0-f200.google.com with SMTP id wp4sf16436997obc.11 for ; Tue, 25 Feb 2014 03:53:12 -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:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=xUuiFZ1QiABZHlEp98LufIdAsRZav23xuli441nnaGo=; b=lg7vMSO/vjQKX0A7gZvNKX5Dt8ZwWv6Ub9NuQM3qUAUuP3F6ZkT4VIea1dsz1YwF1A QK3AIVT5KEXP4/YW/eLWrVsoq76JbhoSNO/1iw4MVswCv58fjdbUfRu7hoAqFtqTmGSC YcpfpCot5NNsYl4ntSABRDpKsRaPybO6m4mbj1jKfLBc/7s3dt5AbTQAiZREMFosZUBk FivZAy00oAt9BWuPdLTsaIVTsc1AP37T6+mnKjNggi1iG/+bliqMhwIG8eUyqCH0vTFe 8Ey3j9JWpeFAtWWygBD54nJs8n42jEoJmNvNZlwVE70aDOPBbu1dD9L/yzvBD+STW/sn txAw== X-Gm-Message-State: ALoCoQkWnYZCIwq20jsk7mfTIa+P4xtqfZrjYzjHM6eje0ahauRIwhSdLDxe5aw1WJRbV4jV1rFW X-Received: by 10.42.75.10 with SMTP id y10mr12284709icj.19.1393329192621; Tue, 25 Feb 2014 03:53:12 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.81.20 with SMTP id e20ls2441612qgd.58.gmail; Tue, 25 Feb 2014 03:53:12 -0800 (PST) X-Received: by 10.52.243.102 with SMTP id wx6mr641909vdc.12.1393329167203; Tue, 25 Feb 2014 03:52:47 -0800 (PST) Received: from mail-vc0-f180.google.com (mail-vc0-f180.google.com [209.85.220.180]) by mx.google.com with ESMTPS id eo4si6716999vdb.95.2014.02.25.03.52.47 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Feb 2014 03:52:47 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.180 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.180; Received: by mail-vc0-f180.google.com with SMTP id ks9so7100439vcb.39 for ; Tue, 25 Feb 2014 03:52:47 -0800 (PST) X-Received: by 10.52.118.242 with SMTP id kp18mr583868vdb.27.1393329167104; Tue, 25 Feb 2014 03:52:47 -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.220.174.196 with SMTP id u4csp133003vcz; Tue, 25 Feb 2014 03:52:46 -0800 (PST) X-Received: by 10.180.164.73 with SMTP id yo9mr2402684wib.29.1393328503734; Tue, 25 Feb 2014 03:41:43 -0800 (PST) Received: from casper.infradead.org (casper.infradead.org. [2001:770:15f::2]) by mx.google.com with ESMTPS id f20si17594094wjz.75.2014.02.25.03.41.43 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Feb 2014 03:41:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:770:15f::2 as permitted sender) client-ip=2001:770:15f::2; Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WIGMj-00048Z-77; Tue, 25 Feb 2014 11:40:01 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WIGMZ-0006qo-Cn; Tue, 25 Feb 2014 11:39:51 +0000 Received: from mail-we0-f176.google.com ([74.125.82.176]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WIGMB-0006na-RN for linux-arm-kernel@lists.infradead.org; Tue, 25 Feb 2014 11:39:29 +0000 Received: by mail-we0-f176.google.com with SMTP id p61so252663wes.7 for ; Tue, 25 Feb 2014 03:39:06 -0800 (PST) X-Received: by 10.194.190.10 with SMTP id gm10mr2039895wjc.55.1393328344826; Tue, 25 Feb 2014 03:39:04 -0800 (PST) Received: from marmot.wormnet.eu (marmot.wormnet.eu. [188.246.204.87]) by mx.google.com with ESMTPSA id pm2sm33866921wic.0.2014.02.25.03.39.03 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Feb 2014 03:39:04 -0800 (PST) From: Steve Capper To: linux-arm-kernel@lists.infradead.org, linux@arm.linux.org.uk Subject: [PATCH V2 2/3] arm64: mm: Add double logical invert to pte accessors Date: Tue, 25 Feb 2014 11:38:53 +0000 Message-Id: <1393328334-27285-3-git-send-email-steve.capper@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1393328334-27285-1-git-send-email-steve.capper@linaro.org> References: <1393328334-27285-1-git-send-email-steve.capper@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140225_063928_031208_00BAE48C X-CRM114-Status: UNSURE ( 9.35 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.82.176 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: lauraa@codeaurora.org, catalin.marinas@arm.com, will.deacon@arm.com, keescook@chromium.org, Steve Capper 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+patch=linaro.org@lists.infradead.org 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.220.180 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 Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Page table entries on ARM64 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 adds a double logical invert to all the pte_ accessors to ensure predictable downcasting. Signed-off-by: Steve Capper --- Changes in V2: drop the pte_isset macro, just add the !! --- arch/arm64/include/asm/pgtable.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index b524dcd..aa3917c 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -136,11 +136,11 @@ extern struct page *empty_zero_page; /* * The following only work if pte_present(). Undefined behaviour otherwise. */ -#define pte_present(pte) (pte_val(pte) & (PTE_VALID | PTE_PROT_NONE)) -#define pte_dirty(pte) (pte_val(pte) & PTE_DIRTY) -#define pte_young(pte) (pte_val(pte) & PTE_AF) -#define pte_special(pte) (pte_val(pte) & PTE_SPECIAL) -#define pte_write(pte) (pte_val(pte) & PTE_WRITE) +#define pte_present(pte) (!!(pte_val(pte) & (PTE_VALID | PTE_PROT_NONE))) +#define pte_dirty(pte) (!!(pte_val(pte) & PTE_DIRTY)) +#define pte_young(pte) (!!(pte_val(pte) & PTE_AF)) +#define pte_special(pte) (!!(pte_val(pte) & PTE_SPECIAL)) +#define pte_write(pte) (!!(pte_val(pte) & PTE_WRITE)) #define pte_exec(pte) (!(pte_val(pte) & PTE_UXN)) #define pte_valid_user(pte) \