From patchwork Thu Feb 18 18:03:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 8353211 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D7FF2C0554 for ; Thu, 18 Feb 2016 18:06:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DED5B203A1 for ; Thu, 18 Feb 2016 18:06:37 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 910DA20145 for ; Thu, 18 Feb 2016 18:06:36 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aWSve-00072m-9d; Thu, 18 Feb 2016 18:03:50 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aWSvc-00072F-Hc for xen-devel@lists.xen.org; Thu, 18 Feb 2016 18:03:48 +0000 Received: from [85.158.139.211] by server-9.bemta-5.messagelabs.com id F9/2B-03883-38706C65; Thu, 18 Feb 2016 18:03:47 +0000 X-Env-Sender: prvs=8491ce0b8=Andrew.Cooper3@citrix.com X-Msg-Ref: server-10.tower-206.messagelabs.com!1455818625!23376949!2 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 60221 invoked from network); 18 Feb 2016 18:03:47 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-10.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 18 Feb 2016 18:03:47 -0000 X-IronPort-AV: E=Sophos;i="5.22,466,1449532800"; d="scan'208";a="332690988" From: Andrew Cooper To: Xen-devel Date: Thu, 18 Feb 2016 18:03:39 +0000 Message-ID: <1455818622-30625-2-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1455818622-30625-1-git-send-email-andrew.cooper3@citrix.com> References: <1455818622-30625-1-git-send-email-andrew.cooper3@citrix.com> MIME-Version: 1.0 X-DLP: MIA2 Cc: Andrew Cooper , Tim Deegan , Ian Campbell , Jan Beulich Subject: [Xen-devel] [PATCH] xen: Introduce IS_ALIGNED() X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 And a few open-coded alignment checks which I encountered Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Tim Deegan CC: Ian Campbell --- xen/arch/x86/mm.c | 8 ++++---- xen/arch/x86/xen.lds.S | 2 +- xen/include/xen/config.h | 2 ++ xen/include/xen/tmem_xen.h | 3 +-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index ea3f9f2..d6aaed8 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -5957,8 +5957,8 @@ void destroy_xen_mappings(unsigned long s, unsigned long e) unsigned int i; unsigned long v = s; - ASSERT((s & ~PAGE_MASK) == 0); - ASSERT((e & ~PAGE_MASK) == 0); + ASSERT(IS_ALIGNED(s, PAGE_SIZE)); + ASSERT(IS_ALIGNED(e, PAGE_SIZE)); while ( v < e ) { @@ -6369,8 +6369,8 @@ static void __memguard_change_range(void *p, unsigned long l, int guard) unsigned int flags = __PAGE_HYPERVISOR_RW | MAP_SMALL_PAGES; /* Ensure we are dealing with a page-aligned whole number of pages. */ - ASSERT((_p&~PAGE_MASK) == 0); - ASSERT((_l&~PAGE_MASK) == 0); + ASSERT(IS_ALIGNED(_p, PAGE_SIZE)); + ASSERT(IS_ALIGNED(_l, PAGE_SIZE)); if ( guard ) flags &= ~_PAGE_PRESENT; diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S index 3b199ca..9fde1db 100644 --- a/xen/arch/x86/xen.lds.S +++ b/xen/arch/x86/xen.lds.S @@ -229,4 +229,4 @@ ASSERT(__image_base__ > XEN_VIRT_START || ASSERT(kexec_reloc_size - kexec_reloc <= PAGE_SIZE, "kexec_reloc is too large") #endif -ASSERT((cpu0_stack & (STACK_SIZE - 1)) == 0, "cpu0_stack misaligned") +ASSERT(IS_ALIGNED(cpu0_stack, STACK_SIZE), "cpu0_stack misaligned") diff --git a/xen/include/xen/config.h b/xen/include/xen/config.h index a992933..bd78176 100644 --- a/xen/include/xen/config.h +++ b/xen/include/xen/config.h @@ -74,6 +74,8 @@ #define MB(_mb) (_AC(_mb, ULL) << 20) #define GB(_gb) (_AC(_gb, ULL) << 30) +#define IS_ALIGNED(val, align) (((val) & ((align) - 1)) == 0) + #define __STR(...) #__VA_ARGS__ #define STR(...) __STR(__VA_ARGS__) diff --git a/xen/include/xen/tmem_xen.h b/xen/include/xen/tmem_xen.h index 0fdbf68..c770f3e 100644 --- a/xen/include/xen/tmem_xen.h +++ b/xen/include/xen/tmem_xen.h @@ -23,8 +23,7 @@ #endif typedef uint32_t pagesize_t; /* like size_t, must handle largest PAGE_SIZE */ -#define IS_PAGE_ALIGNED(addr) \ - ((void *)((((unsigned long)addr + (PAGE_SIZE - 1)) & PAGE_MASK)) == addr) +#define IS_PAGE_ALIGNED(addr) IS_ALIGNED((unsigned long)(addr), PAGE_SIZE) #define IS_VALID_PAGE(_pi) ( mfn_valid(page_to_mfn(_pi)) ) extern struct page_list_head tmem_page_list;