Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp5125846imm; Tue, 26 Jun 2018 06:22:22 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK6218YO2UXHX64uXu4D6GBn80UZQAIgnjLrIWNBtilKUx+b86LZ5PLLUOgQks5X7nq5o4J X-Received: by 2002:a65:61cc:: with SMTP id j12-v6mr1338753pgv.299.1530019342792; Tue, 26 Jun 2018 06:22:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530019342; cv=none; d=google.com; s=arc-20160816; b=H8csZwsj+7lwiWkVO6Fr9uAtgm48voKd/A79ub0cVee6CyykX4uet8w9Bej3rYKTPK bqyDxjDH71789je6mzUO6kiW1TXDinsUnMthiljOQEC2bU1k1wa7u5mOlcm1MosZ8qtM nwQz5SiQqV2uYLiWgHutHcRfWa3xsU/FALa/lufLvf3ipyou+RJSuNF2FvK8uvOnc0R7 G1f/G0hsddNNRGF0rLNFEH9Sx3zucJAhIZiuaCgJev6Qou6CjyzP0oI75kGe9+wvqhWx fMX4AE4dFbGlME2C6Q8ZuAqBDcZQgpoaD33i1qFnonmTiU1/RFSOtKQDHZRakZgRCzRW w4LQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=YhNLQluC3zPdVMeBvR8Lp3d958WDaREzBrtKu3hGG6k=; b=03vcyAouXEqY79LQltaIgwR+M+f+UQqS0fAmXlz/wERh7GJ15j3M0rPLLGyXH3ffYZ j484mIjOtNSO9osgDW8fKJslGxR6Je/u1chumGmiPsA1dnMfx/qRD3uVuk3WzJ8Y4oGv PJnSsbJ7vHd1VDqxoOmIQtl48Bu+iSKQkKaqN4Yahb4X0Szt/fS6rN2MWDfqO540lXLu M+Eyq9j6i0u4fsGV1qAoXxMF5auxtRr94L3eE6musJcV0udnVwGFM/YduPLxeaBF5aI5 9HS7CaYRG8OqzMyGf6gqRkt4N7NVDUJx8pCWec50UmYUZG0/hIZvyM+I5CkkGF9Ptnz1 bhlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=RwV4diPI; 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 a10-v6si1330491pgt.552.2018.06.26.06.22.08; Tue, 26 Jun 2018 06:22:22 -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=RwV4diPI; 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 S935646AbeFZNUr (ORCPT + 99 others); Tue, 26 Jun 2018 09:20:47 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:37026 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964845AbeFZNPl (ORCPT ); Tue, 26 Jun 2018 09:15:41 -0400 Received: by mail-wr0-f196.google.com with SMTP id k6-v6so17223795wrp.4 for ; Tue, 26 Jun 2018 06:15:40 -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; bh=YhNLQluC3zPdVMeBvR8Lp3d958WDaREzBrtKu3hGG6k=; b=RwV4diPI5VZPDDv5Zq8UsZ/Wk67TJvBxzP6g9IZUzZGKVf+VNmstYYfQWZsJZ/V0k5 kAGn6M69HRK9FZmOqol0Eujoa+GaZYCZXTCNBVvhD0E2dshKwkWAu1lPbilKNvNtAgRC 9sa+ZHs0eVFwO+Jc5oKtsJPREpBD2NVSdf1bsCDNzGPHXBvBig5iOm9PGRfd6gKMgupm +5g2h6ETCHP7/i9e/AUa3UezW+aAi2E4ZUz5XIr3RXUMzmWrdXUHKChNE1ij00G1qdSo BPejbwPfDWDB0ZVftjMIp3fLSmKWo7+XACY67IRLpaUtBvgzIIQ5rVx7RGuZe+qSw13u 0NcA== 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; bh=YhNLQluC3zPdVMeBvR8Lp3d958WDaREzBrtKu3hGG6k=; b=DTl55fB1gOIv9MGo8OqZga2LrwgmdjBoQgdJ61SxpLBRdOcbjG7F2Re5ikpyW3uWa9 4FDBhiXnEvnHif/dDfLW1l4x65k8vmM4Zsd5n8tcsAECu7BdQe6xWkZhXZzkfpzLddgx TdlpBovXTtWDesqzU1HlGdB7Xkxk5U3kctEurLta4A7mQrY5+xP3CsYvkMUJ0Kzz6JfT GKclF3XO5yoKVpCYA0tsdQtYWeHiXcy23BiIE+Vi6GyWO3DO6oBKGC840OQDiU8JZ9e5 DyH+Nrq4Vu40+k4VNst/g1wgWtujP2Drs6MGwCepRVuGXsf7QpkRTEzDDbqkG4FB/otW hf+Q== X-Gm-Message-State: APt69E1waJ1zD63O9Z+Rldp62+b1LT9v7ne8Xzvo+n4vSDLVhkTgCmqC qn3Ny1+MYVpQuAs4AffZeIy5zQ== X-Received: by 2002:adf:88e3:: with SMTP id g32-v6mr1411208wrg.62.1530018939538; Tue, 26 Jun 2018 06:15:39 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id w15-v6sm2162639wrn.25.2018.06.26.06.15.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 06:15:38 -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 , Andrey Konovalov Subject: [PATCH v4 04/17] khwasan, arm64: adjust shadow size for CONFIG_KASAN_HW Date: Tue, 26 Jun 2018 15:15:14 +0200 Message-Id: <7bd08c76830e4cd23f90d1ed25721fca3c5f3205.1530018818.git.andreyknvl@google.com> X-Mailer: git-send-email 2.18.0.rc2.346.g013aa6912e-goog In-Reply-To: References: 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 45272266dafb..191a649f34e7 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -93,7 +93,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 49d99214f43c..6d084431b7f7 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.18.0.rc2.346.g013aa6912e-goog