Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp786242imm; Fri, 21 Sep 2018 08:16:29 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYc/WRpENoGuubgxme5UmN79+SfkB9uF/6hHH0wuiNAnmcgHZOrBXd+SC8mdxePN1JucEJs X-Received: by 2002:a63:d54e:: with SMTP id v14-v6mr42668720pgi.264.1537542989276; Fri, 21 Sep 2018 08:16:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537542989; cv=none; d=google.com; s=arc-20160816; b=m+lPJ1cBJqGL21Q804DSUD5mK5f9egfdwuqTOJh5VcY3ydZO5xU/yH4yLQ+Ps0pjve Gh7oVju1k79a9CRObN3hwxKJagmqNLllW7gr2PHJr88BFJ8z+k/jxpI8IyY1baQsjlJo mshQgyDhvBNYVgY+lIHddJ9hiuoR0/m7k/SDjR/pYQqBVN3I3jfnAo/Ybasv9EGcqdfs 32LmTu8vx6OkaRtLwI54RdudrjLQVitJ0tHNJfSvpbTsAbMSrpB3cxd8yHBhgWyEw5T5 wNLPoxZj8VwhNHjvGfzOISL9YwPw1Kvr5xC6Io5WfXZ0tmmGIpRiVJrAA+qxI7zR4mqc JDsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sTTlDohLEJvb592OsyAPVR+u8uN9dIVJB3pJotLdeOk=; b=Yt7uleh3kkt9Naiusn54ErsHwIkik3+GN4HmL9TrX3amsOctu2ljL5MuU11G+NjHx1 MtzyaNAXW2wUcEwqQKfAnJ+ENsXMdr6zQZB4SKJjx0GnsMiEqTlSHjbHnJdzxWtgCv8K 8hrxvvCOMa3JT/6hxBJCMIf/Y5Xx/Y/iXx9kmiZ7X7MJaWXubmzCP+OaU9M4gNQ+8wB+ saXyDRFRdp6JyNKajUWDrGLurad+Cb7Mb4wp+spOdUl/T8WJB1yw4gDeKhyGFthdKWns h8nE/VvG3otg8gyPIzAxmQtDuODkBzEjAK26rIRbOpX2bw4uFU5LegLu+Fob67uiy+9q oXFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=eFk3Aix9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y141-v6si29256195pfb.331.2018.09.21.08.16.03; Fri, 21 Sep 2018 08:16:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=eFk3Aix9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390890AbeIUVDR (ORCPT + 99 others); Fri, 21 Sep 2018 17:03:17 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:37311 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390607AbeIUVDQ (ORCPT ); Fri, 21 Sep 2018 17:03:16 -0400 Received: by mail-wm1-f67.google.com with SMTP id n11-v6so3676332wmc.2 for ; Fri, 21 Sep 2018 08:13:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sTTlDohLEJvb592OsyAPVR+u8uN9dIVJB3pJotLdeOk=; b=eFk3Aix99RmJaNZRwCRLFH/tDZNfk5/3JawlFf1a11HhqIDObEJMuPJ1S6LXnwafvv pDK0c73bjQBny01Z5FXE7/lMchlf2fzVj1CjiwcqDMTTgDOHopWD0Xsao4jr2F76rO9H sRTSfbicV3YQxXFxMGGkfCFrC7QW3EgUZvmN7yEkxsHMVhG9mzLQ22hOZVMlzaYFyiKq qqZ5w92kv5wzvOtcuL2bcpcyqlfncMFkBZuzP+z6GYR/0+6/C+PCRE7WLSWVJJymgBgc k5+LdjtnDdLQpZ9Mwb+AJaf3zvy/dB3bLa2M/Ru3XY8Je/6e0XKLgvNRH54XQJN7XAsO jXpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sTTlDohLEJvb592OsyAPVR+u8uN9dIVJB3pJotLdeOk=; b=ci640DxSdnVKCeGAFVTuVpQGsDeITrYT9EbChmMWHNSvYuVcAD6kLUhXqMH43uNg/m s2I93mGn3y1DjdmyVCJaGjgq5k7YhSWVg/SiABqLx0ClDvgUvu659BVusD55Rnz5EHiI 91E2C+zTvYOlnN5JHB5t5L2TC8X+2c5PTY4jPZ/BxNzf16I9amYtazmvvSrv+YoPhfOz fWf5S5pzhFu33tvbOJXrlFiS52eETeXudfoGAwh1uBh/N8p6+1Xraxlh8WHFDTrIFkIX YUEti8OD0N9SN+Dge/spahE/t97mBCFSCRzMBX/ZkgkhKSjdyDJfaI4HcrPt9acWq8qJ vGmA== X-Gm-Message-State: APzg51AEnplqBmIryj4Y3dEUaN79l4uHEhiYZWdXfGtqeZOQ+hC/UW2q yK4Q3BgBUF4fSBQG3LG9Jbvd1w== X-Received: by 2002:a1c:1eca:: with SMTP id e193-v6mr7134810wme.99.1537542835102; Fri, 21 Sep 2018 08:13:55 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id e7-v6sm27990271wru.46.2018.09.21.08.13.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Sep 2018 08:13:54 -0700 (PDT) From: Andrey Konovalov To: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Catalin Marinas , Will Deacon , Christoph Lameter , Andrew Morton , Mark Rutland , Nick Desaulniers , Marc Zyngier , Dave Martin , Ard Biesheuvel , "Eric W . Biederman" , Ingo Molnar , Paul Lawrence , Geert Uytterhoeven , Arnd Bergmann , "Kirill A . Shutemov" , Greg Kroah-Hartman , Kate Stewart , Mike Rapoport , kasan-dev@googlegroups.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sparse@vger.kernel.org, linux-mm@kvack.org, linux-kbuild@vger.kernel.org Cc: Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Jann Horn , Mark Brand , Chintan Pandya , Vishwath Mohan , Andrey Konovalov Subject: [PATCH v9 05/20] kasan, arm64: adjust shadow size for tag-based mode Date: Fri, 21 Sep 2018 17:13:27 +0200 Message-Id: <10cf432f0ffdb67fbd495acc61bdd9517af5b7b7.1537542735.git.andreyknvl@google.com> X-Mailer: git-send-email 2.19.0.444.g18242da7ef-goog In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Tag-based KASAN uses 1 shadow byte for 16 bytes of kernel memory, so it requires 1/16th of the kernel virtual address space for the shadow memory. This commit sets KASAN_SHADOW_SCALE_SHIFT to 4 when the tag-based KASAN mode is enabled. Signed-off-by: Andrey Konovalov --- arch/arm64/Makefile | 2 +- arch/arm64/include/asm/memory.h | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index 106039d25e2f..11f4750d8d41 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -94,7 +94,7 @@ endif # KASAN_SHADOW_OFFSET = VA_START + (1 << (VA_BITS - KASAN_SHADOW_SCALE_SHIFT)) # - (1 << (64 - KASAN_SHADOW_SCALE_SHIFT)) # in 32-bit arithmetic -KASAN_SHADOW_SCALE_SHIFT := 3 +KASAN_SHADOW_SCALE_SHIFT := $(if $(CONFIG_KASAN_SW_TAGS), 4, 3) KASAN_SHADOW_OFFSET := $(shell printf "0x%08x00000000\n" $$(( \ (0xffffffff & (-1 << ($(CONFIG_ARM64_VA_BITS) - 32))) \ + (1 << ($(CONFIG_ARM64_VA_BITS) - 32 - $(KASAN_SHADOW_SCALE_SHIFT))) \ diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index b96442960aea..0f1e024a951f 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -74,12 +74,17 @@ #define KERNEL_END _end /* - * KASAN requires 1/8th of the kernel virtual address space for the shadow - * region. KASAN can bloat the stack significantly, so double the (minimum) - * stack size when KASAN is in use. + * Generic and tag-based KASAN require 1/8th and 1/16th of the kernel virtual + * address space for the shadow region respectively. They can bloat the stack + * significantly, so double the (minimum) stack size when they are in use. */ -#ifdef CONFIG_KASAN +#ifdef CONFIG_KASAN_GENERIC #define KASAN_SHADOW_SCALE_SHIFT 3 +#endif +#ifdef CONFIG_KASAN_SW_TAGS +#define KASAN_SHADOW_SCALE_SHIFT 4 +#endif +#ifdef CONFIG_KASAN #define KASAN_SHADOW_SIZE (UL(1) << (VA_BITS - KASAN_SHADOW_SCALE_SHIFT)) #define KASAN_THREAD_SHIFT 1 #else -- 2.19.0.444.g18242da7ef-goog