Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp467403imm; Wed, 29 Aug 2018 04:39:14 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYk258s2KhGuX2XI/tdxFYWyzhZHkPwqdV/VXvPs15R7N7xA4YTpyvxYpkfP8utX7ptEJx/ X-Received: by 2002:a17:902:22:: with SMTP id 31-v6mr5592027pla.190.1535542754522; Wed, 29 Aug 2018 04:39:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535542754; cv=none; d=google.com; s=arc-20160816; b=qs7HaaKmEAGaN3PyMLfPjfpnXQJEj7Lp+0f0WZ3uitaZJBRmAhidP92S4U1kQLlmox DL+H0anYifU5z/LVbwLnl9I8XmltEnMhkdioBGUrnioQWrpJrcxtd+adZQZCP8B+zRlj JU2nKmhfJHdSVwS1K5gNUuuy4E9TAEBcrVdldffC6xKUXU4BwmmvDqPNeHC5kWyIkv7Z N1ApnzrvK8OmV8bhUJT1Pn4eWnHlDIu2+rwQ3OPNJfgsZZSEudHyGcKJ44/Bcu1OOHI+ VGGyftfNfsTlfYGWUMMFptjPFAFoUaVgxRylji2U+E3fRRzO+V1EPo3qOiKyQSnZQphY uFMw== 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:arc-authentication-results; bh=Oho6JdHma26yH9i0K5sb+l4Yb9Bpt1LjR+gOl5dkBUo=; b=aYjzWoG9bE8fgze7Sim6o2xSrgMfXAO1kDobe6BUh6B2s06T/k+JLX0qT2CrHjjmKN gF0tj2fZk/KJofI+Km/fMKaHxc9B/CaCQw5iS/FsAOjw0TLDtK2rtFIx4uq+PQqTjfRK swQsLwZPtCtpEgazDesaGdRcCpG1mYn5fMBszafbLKx1XlGtACiGGmng7J4pwdtIy7k4 nEwg1xaL4uBnyWHnEOHMETJH3GL1texMKbL6L59ir4fMTh8DXcEdMGZ4/e88dR2kotCa DRQtQ8+FYquH2kxyq33PQg032CxJXT+AuLu98j3JrXX/K7Lp60vMykWc5DusCRt56q5l wqTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=SaDmWZ9f; 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 s21-v6si3235058pgm.651.2018.08.29.04.38.59; Wed, 29 Aug 2018 04:39:14 -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=SaDmWZ9f; 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 S1728713AbeH2Pds (ORCPT + 99 others); Wed, 29 Aug 2018 11:33:48 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:53123 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728436AbeH2PcE (ORCPT ); Wed, 29 Aug 2018 11:32:04 -0400 Received: by mail-wm0-f68.google.com with SMTP id y139-v6so4892351wmc.2 for ; Wed, 29 Aug 2018 04:35:35 -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=Oho6JdHma26yH9i0K5sb+l4Yb9Bpt1LjR+gOl5dkBUo=; b=SaDmWZ9fK2PewT8oJonwMmFfr8WhrgkwKC1k18mnNmJmAsCXOB3epwtFKQCa9bJOAi mEj8+WOJp2nZjwSiGScw6Xf5tBPmT1MpzndcX+Y+Ct0cNtljF9Ux6NW+JhEZSOSdgrxU yvYeNx0zRXThLLrsda7sUxBeiipmmCaRpWw3EfQPRM0nzAAWxcYpVEaZsynW76N+kdWG uuyyKkgeP3GLgqci7gdynMTo3MsxqG1n2vZYlR2lP32Vi0+iyNDuLjgbLH4od9gAkPMz p3j/Y1rMM2RUu+jDYRBgy/F6h8F3cZXPVHFrtsUqaArAhctqLIcRmQaMiHZ5DTmF+235 K9Dg== 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=Oho6JdHma26yH9i0K5sb+l4Yb9Bpt1LjR+gOl5dkBUo=; b=BzUmbrgfvQGlN+J5MnCVPKjROtpz2siILqA7LRaLefAtaN6TOkNBL7qo1XwfG1QIBb tMIaTujel6Gp0Nk5JiqiYXTo9i+NveXtQuBDQ6gTehdcLRyxW9YFdjyiM/+65A6zjOYp aB5vNiGdVThCQlguK1jMYbtKmW/eM7c/9pmPtDbMgf4Eo/R/RbGjwnPbob6e/+1XzQ2n uCtBwak7RvxxPm7VxkHHe26Ut4QEixJiSZONU+s88UHe8k8F2JqADLcttWZ1spdtPHYU 0S7Px7/W73YrLfk9iSmhUoezCBA1/5VVMsDZKwmi/sjISJDx2hQ0gEdu8sgf7fR7earR LMXA== X-Gm-Message-State: APzg51BYtsIkA9HiknwOLmyQiEbDuhxGdGku0LawftTgMtEopdbWQdXB ZYfSquBooqV4nkzRSmNgPKBF+A== X-Received: by 2002:a1c:7fc6:: with SMTP id a189-v6mr4102021wmd.42.1535542534055; Wed, 29 Aug 2018 04:35:34 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id s10-v6sm7800454wmd.22.2018.08.29.04.35.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Aug 2018 04:35:33 -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 v6 04/18] khwasan, arm64: adjust shadow size for CONFIG_KASAN_HW Date: Wed, 29 Aug 2018 13:35:08 +0200 Message-Id: X-Mailer: git-send-email 2.19.0.rc0.228.g281dcd1b4d0-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 KWHASAN 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 KHWASAN 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..17047b8ab984 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_HW), 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..f5e262ee76c1 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. + * KASAN and KHWASAN 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_HW +#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.rc0.228.g281dcd1b4d0-goog