linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nick Desaulniers <ndesaulniers@google.com>
To: unlisted-recipients:; (no To-header on input)
Cc: zijun_hu@htc.com, akpm@linux-foundation.org,
	ghackmann@google.com, dianders@chromium.org, srhines@google.com,
	pirama@google.com, Nick Desaulniers <ndesaulniers@google.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will.deacon@arm.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Laura Abbott <labbott@redhat.com>,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	Oleksandr Andrushchenko <Oleksandr_Andrushchenko@epam.com>,
	Alexander Popov <alex.popov@linux.com>,
	Neeraj Upadhyay <neeraju@codeaurora.org>,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH] arm64: avoid overflow in VA_START and PAGE_OFFSET
Date: Thu,  3 Aug 2017 10:11:16 -0700	[thread overview]
Message-ID: <20170803171117.107992-1-ndesaulniers@google.com> (raw)
In-Reply-To: <20170803132035.gixd7m7oxtehpquu@yury-thinkpad>

The bitmask used to define these values produces overflow, as seen by
this compiler warning:

arch/arm64/kernel/head.S:47:8: warning:
      integer overflow in preprocessor expression
  #elif (PAGE_OFFSET & 0x1fffff) != 0
         ^~~~~~~~~~~
arch/arm64/include/asm/memory.h:52:46: note:
      expanded from macro 'PAGE_OFFSET'
  #define PAGE_OFFSET             (UL(0xffffffffffffffff) << (VA_BITS -
1))
                                      ~~~~~~~~~~~~~~~~~~  ^

It would be preferrable to use GENMASK_ULL() instead, but it's not set
up to be used from assembly (the UL() macro token pastes UL suffixes
when not included in assembly sources).

Suggested-by: Yury Norov <ynorov@caviumnetworks.com>
Suggested-by: Matthias Kaehlcke <mka@chromium.org>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
 arch/arm64/include/asm/memory.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h
index 32f82723338a..dde717a31dee 100644
--- a/arch/arm64/include/asm/memory.h
+++ b/arch/arm64/include/asm/memory.h
@@ -64,8 +64,9 @@
  * TASK_UNMAPPED_BASE - the lower boundary of the mmap VM area.
  */
 #define VA_BITS			(CONFIG_ARM64_VA_BITS)
-#define VA_START		(UL(0xffffffffffffffff) << VA_BITS)
-#define PAGE_OFFSET		(UL(0xffffffffffffffff) << (VA_BITS - 1))
+#define VA_START		((UL(0xffffffffffffffff) >> VA_BITS) << VA_BITS)
+#define PAGE_OFFSET		((UL(0xffffffffffffffff) >> (VA_BITS - 1)) \
+	<< (VA_BITS - 1))
 #define KIMAGE_VADDR		(MODULES_END)
 #define MODULES_END		(MODULES_VADDR + MODULES_VSIZE)
 #define MODULES_VADDR		(VA_START + KASAN_SHADOW_SIZE)
-- 
2.14.0.rc1.383.gd1ce394fe2-goog

  reply	other threads:[~2017-08-03 17:11 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-02 22:51 [PATCH 1/2] bitops: Avoid integer overflow warning in GENMASK_ULL Matthias Kaehlcke
2017-08-02 22:51 ` [PATCH 2/2] arm64: Define PAGE_OFFSET using GENMASK_ULL Matthias Kaehlcke
2017-08-02 23:13   ` Nick Desaulniers
2017-08-02 23:19     ` Nick Desaulniers
2017-08-02 23:44       ` Matthias Kaehlcke
2017-08-03 13:20   ` Yury Norov
2017-08-03 17:11     ` Nick Desaulniers [this message]
2017-08-03 17:20       ` [PATCH] arm64: avoid overflow in VA_START and PAGE_OFFSET Ard Biesheuvel
2017-08-03 17:53         ` Nick Desaulniers
2017-08-03 18:03           ` [PATCH v2] " Nick Desaulniers
2017-08-04  2:26   ` [PATCH 2/2] arm64: Define PAGE_OFFSET using GENMASK_ULL kbuild test robot
2017-08-03 13:24 ` [PATCH 1/2] bitops: Avoid integer overflow warning in GENMASK_ULL Yury Norov
2017-08-03 17:03   ` Matthias Kaehlcke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170803171117.107992-1-ndesaulniers@google.com \
    --to=ndesaulniers@google.com \
    --cc=Oleksandr_Andrushchenko@epam.com \
    --cc=akpm@linux-foundation.org \
    --cc=alex.popov@linux.com \
    --cc=ard.biesheuvel@linaro.org \
    --cc=catalin.marinas@arm.com \
    --cc=dianders@chromium.org \
    --cc=ghackmann@google.com \
    --cc=labbott@redhat.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=neeraju@codeaurora.org \
    --cc=pirama@google.com \
    --cc=srhines@google.com \
    --cc=will.deacon@arm.com \
    --cc=zijun_hu@htc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).