From patchwork Mon Feb 24 15:33:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Capper X-Patchwork-Id: 3709901 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id BA28FBF13A for ; Mon, 24 Feb 2014 15:35:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D097F200F2 for ; Mon, 24 Feb 2014 15:35:35 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D3633200E7 for ; Mon, 24 Feb 2014 15:35:34 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WHxYG-0005He-Qg; Mon, 24 Feb 2014 15:34:41 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WHxY2-0000G5-I0; Mon, 24 Feb 2014 15:34:26 +0000 Received: from mail-wg0-f43.google.com ([74.125.82.43]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WHxXa-0000CB-Um for linux-arm-kernel@lists.infradead.org; Mon, 24 Feb 2014 15:33:59 +0000 Received: by mail-wg0-f43.google.com with SMTP id a1so4697859wgh.34 for ; Mon, 24 Feb 2014 07:33:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LfyyF8001lum459FlE4NxOX9RmOLsufiwop6Al09FiY=; b=TQWYcz5PWiVkj1MtN2vh7SM+afLmmMhaluLfN4YGOheD8V8tJam97N14l/ubWo/LZP R0ohiZmCTGTQqsbkkbI6AbEcuuHgD5z/HBCfF3RcUZ4u1ZHQ1xZs2u6pxv6zmjeQfDyb P+ij19QkKKMRV5RlBsw74BLnqwEghhmFPtUQpL+L9t+sfECSk264hJZVV8Uteht/YDlu nRt0hZmq9gUri8CJOprheblU+tFwDYumA0LJTCwn9yxV14M8Mttldx1HCx61WKPGCO3F RqcT6qtSULW2UBrZc3Lc323+R7qRMygO04OEvNI2j7JTirukMLk6VsMhG4RQE492GFfA qMeg== X-Gm-Message-State: ALoCoQkBIA/54XsDpzmCt5KbLHPXVe93+qN4bsCrRv1hKp2Yi0fzaRweBFeiYrinvGQ5T6QZPN+9 X-Received: by 10.180.83.137 with SMTP id q9mr14718841wiy.55.1393256015789; Mon, 24 Feb 2014 07:33:35 -0800 (PST) Received: from marmot.wormnet.eu (marmot.wormnet.eu. [188.246.204.87]) by mx.google.com with ESMTPSA id cm5sm25271736wid.5.2014.02.24.07.33.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Feb 2014 07:33:35 -0800 (PST) From: Steve Capper To: linux-arm-kernel@lists.infradead.org, linux@arm.linux.org.uk Subject: [RFC PATCH 2/2] arm64: Introduce pte_isset(pte,flag) Date: Mon, 24 Feb 2014 15:33:25 +0000 Message-Id: <1393256005-2206-3-git-send-email-steve.capper@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1393256005-2206-1-git-send-email-steve.capper@linaro.org> References: <1393256005-2206-1-git-send-email-steve.capper@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140224_103359_117343_C8BBA5A4 X-CRM114-Status: UNSURE ( 8.86 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.6 (--) Cc: catalin.marinas@arm.com, will.deacon@arm.com, 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+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 introduces a new macro pte_isset which performs the bitwise and, then performs a double logical invert to ensure predictable downcasting. Signed-off-by: Steve Capper --- arch/arm64/include/asm/pgtable.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index b524dcd..5130dd8 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -133,15 +133,16 @@ extern struct page *empty_zero_page; #define pte_unmap(pte) do { } while (0) #define pte_unmap_nested(pte) do { } while (0) +#define pte_isset(pte, val) (!!(pte_val(pte) & (val))) /* * 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_exec(pte) (!(pte_val(pte) & PTE_UXN)) +#define pte_present(pte) (pte_isset((pte), (PTE_VALID | PTE_PROT_NONE))) +#define pte_dirty(pte) (pte_isset((pte), PTE_DIRTY)) +#define pte_young(pte) (pte_isset((pte), PTE_AF)) +#define pte_special(pte) (pte_isset((pte), PTE_SPECIAL)) +#define pte_write(pte) (pte_isset((pte), PTE_WRITE)) +#define pte_exec(pte) (!(pte_isset((pte), PTE_UXN))) #define pte_valid_user(pte) \ ((pte_val(pte) & (PTE_VALID | PTE_USER)) == (PTE_VALID | PTE_USER))