From patchwork Wed Jun 20 17:39:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10478327 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C6C8E60383 for ; Wed, 20 Jun 2018 17:44:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B1E0D28DFB for ; Wed, 20 Jun 2018 17:44:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A5F2728E15; Wed, 20 Jun 2018 17:44:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2FE9C28DFB for ; Wed, 20 Jun 2018 17:44:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=WIY37XX+EjhSdlF+Ee27uQ0phlvvKhex+ncGyKQq7nc=; b=QDmfDyw7WQKpxQcwJ0LXd80ju9 XmCJXz6SW7I9rpudbAXIX4LsK/9Oa4cz/8qa1lHktfzTy11HclpRWqSvx1oqQQ9COh5a/NS/IMyTq Oj/8iCY5nlDOz9muw9VeP4GCQYgwPBKUP60rVBibeti6LTuwRjzLorhPpl/1/mAiVHGOTbJfJy6LQ h+umZBbOGiMi2BKzF8BQfFcMxbhLqUVO80dt680pXAsY+CcI0J9pnz2PEdGJI7aRa7nFo8R+J6IIO zvqKygHk7TF0YJzEfqtSHD2M2h2jFwy+hMIhGa0qk7KtSY2iLnUdK/6pJeBzl4c8tdZf4Rdk5ki2q 7F9SmsKA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fVh9G-0003vH-LB; Wed, 20 Jun 2018 17:44:02 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fVh5l-0001OI-E4 for linux-arm-kernel@lists.infradead.org; Wed, 20 Jun 2018 17:41:03 +0000 Received: by mail-wm0-x243.google.com with SMTP id v131-v6so1009532wma.1 for ; Wed, 20 Jun 2018 10:40:14 -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=tB4UWhMaNQffoQbAPM7NOHomrrfVksNGHY9yx1VD2yU=; b=RZAjwNiPmjyJp29bPlp8gxw3rG0h9l2DKYUD3bs9ne+Yn5OMNkHRuzb+/GUfGVDB04 N/6mPlVH2DM4bySGoit/dM64qclMS60gDhBjSlwUDXjayhHKXBoS6KlS60a70zt/TjGH 9hQp1Ayb5tv6Kbr9udS7AEcArs0BGAf0N6AJSC0YJIeXui2Fi4kWRDfUjrybQI2IyNMp d0B14jS2FrBnFozmKgI5zfIiD28jHGTx0RzxBuIB9/JzYsaJnHdt7lQBRv1UKc2D8I1z GCcdLc/YlmWoj62QWCzRyT00Hpkfc+YLQlpYqWevSPCLSc0if+oLpbRa7t4TnDk/xJHH Twpg== 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=tB4UWhMaNQffoQbAPM7NOHomrrfVksNGHY9yx1VD2yU=; b=iI/To8UAwSKnQ5R927aGYeB+XCAqLMHV85yzebpW0zr693lEpkgJlFastsRFY01a8i +/wWz8X6fE/WH7DVHtunYhJlKDp2+p5JhRv7C2QNIjtW2ibvKPx8g/6+Xg2Ozn+Crv0p faAfY49gOvTM9HxXLcu+OPBWiAnRZ+LpbwgfFUppgf6I9jRB/ooTNi/TS024XPPRssyq GYqdAhrT6Vr3e6Usu6BKsDAgY75KI4iiTzlW8VpG81Zkd2SjWBjt8p/4E31kJ82h5WzG 9y/Cwc3JCGPNfnrKLE86+DCq74VgG070j32Qw/Cob1PwuinGmyFFO52kTRAonyTt8jtb JFPg== X-Gm-Message-State: APt69E0AQwqmyefFVCZQTf4JTKlQCHuNMDHJFU0IgDbRn6aVzYAIfUeg 2sMZtrP4ZGdGDv46Y8LSvBkzXg== X-Google-Smtp-Source: ADUXVKKc2qUfzDyQAC8oFyJzKs2oHOk+fDpwj3O8IpWEMp1rs5cMpoOeRq48d6eJGtXDJlJDu6mymw== X-Received: by 2002:a1c:630b:: with SMTP id x11-v6mr2578729wmb.104.1529516413222; Wed, 20 Jun 2018 10:40:13 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id f18-v6sm4388598wro.1.2018.06.20.10.40.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Jun 2018 10:40:12 -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 Subject: [PATCH v3 04/17] khwasan, arm64: adjust shadow size for CONFIG_KASAN_HW Date: Wed, 20 Jun 2018 19:39:50 +0200 Message-Id: <44cfb47c7d8b485b03f17eb406037e3c01a52fa9.1529515183.git.andreyknvl@google.com> X-Mailer: git-send-email 2.18.0.rc1.244.gcf134e6275-goog In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180620_104025_484291_718A7F2B X-CRM114-Status: GOOD ( 14.68 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Chintan Pandya , Jacob Bramley , Jann Horn , Ruben Ayrapetyan , Andrey Konovalov , Lee Smith , Kostya Serebryany , Mark Brand , Ramana Radhakrishnan , Evgeniy Stepanov MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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