From: Andrew Jones Subject: Re: [kvm-unit-tests PATCH 05/14] page: add page alignment checker Date: Thu, 20 Oct 2016 14:23:14 +0200 Message-ID: <20161020122314.wp3cgpueprgz2mwf@kamzik.brq.redhat.com> References: <1476448852-30062-1-git-send-email-peterx@redhat.com> <1476448852-30062-6-git-send-email-peterx@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: kvm@vger.kernel.org, jan.kiszka@web.de, agordeev@redhat.com, rkrcmar@redhat.com, pbonzini@redhat.com To: Peter Xu Return-path: Received: from mx1.redhat.com ([209.132.183.28]:34740 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933777AbcJTMXT (ORCPT ); Thu, 20 Oct 2016 08:23:19 -0400 Content-Disposition: inline In-Reply-To: <1476448852-30062-6-git-send-email-peterx@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Fri, Oct 14, 2016 at 08:40:43PM +0800, Peter Xu wrote: > Signed-off-by: Peter Xu > --- > lib/asm-generic/page.h | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/lib/asm-generic/page.h b/lib/asm-generic/page.h > index 7b8a08b..cbdc8f6 100644 > --- a/lib/asm-generic/page.h > +++ b/lib/asm-generic/page.h > @@ -19,6 +19,11 @@ > > #define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE) > > +#define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0) > +#define PAGE_ALIGNED_4K(x) IS_ALIGNED((x), (0x1000)) > +#define PAGE_ALIGNED_2M(x) IS_ALIGNED((x), (0x200000)) > +#define PAGE_ALIGNED_1G(x) IS_ALIGNED((x), (0x40000000)) I like IS_ALIGNED, but not the others. The others are strangely named because it's half asking if an address is page aligned and half asking if it's aligned to a given boundary. Why not just ask the boundary, like ALIGNED_2M(x)? Anyway, my preference would be to replace them with SZ_4K, SZ_2M, SZ_1G definitions. Users would then do IS_ALIGNED(addr, SZ_2M) or whatever, which isn't much more typing. Thanks, drew