From patchwork Tue Nov 6 17:30:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10670925 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4430F15E9 for ; Tue, 6 Nov 2018 17:31:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E0FE2ABB2 for ; Tue, 6 Nov 2018 17:31:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2BCAC2ABBA; Tue, 6 Nov 2018 17:31:07 +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=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B71D52ABB2 for ; Tue, 6 Nov 2018 17:31:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B9B436B0357; Tue, 6 Nov 2018 12:30:53 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B23086B0358; Tue, 6 Nov 2018 12:30:53 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9731D6B0359; Tue, 6 Nov 2018 12:30:53 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by kanga.kvack.org (Postfix) with ESMTP id 3B7286B0357 for ; Tue, 6 Nov 2018 12:30:53 -0500 (EST) Received: by mail-wr1-f71.google.com with SMTP id q1-v6so12316005wrr.9 for ; Tue, 06 Nov 2018 09:30:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=zR59Oh4f3YmUUjWQVuUWbISM47BcdXN0TxZaGQsGruw=; b=B8CW0VQu8JpTin0lzKPmzqpNJn0bu7WgyXHjq8diA6XvP858D+tbXyfB7lkcMrsKlu 3ZcQQA6W/OFK1HbliaTQ84Jr6Yp4dW7Zg7HcoSGe/mVzv092UZE7UfAOjXVb4uWuTa6o p+0IQzSDSAAWX3zqAG6HHiJK9S1q+vaYLw2OgBJC3V2IMFUC7DJZuZa2mMIgL8auAw1N DnerHX8qZcunvfE3W4PVDiJNVoaJ/Sirzm+9D8nBDNHsR0tbfV4d4JJrFMs3lat0Bzfq 6AvUYwfrElXXDtrFZE/NQrui/L0ee8moAoJvhWIu1aSRGxRUqz8FwPs1zVD8Koqkstyh YbpA== X-Gm-Message-State: AGRZ1gKsgC/gB1TWL1CECeJR32bkkaGP/X0UpjHQWIzn4lB+5EmSll3C x3uwj7TXwPVHofN2u7vi70dyFzP4aLkMW0bTTYWNCao+7U8IqmayCGyOdPUyq2pjxFbRuOT2eRY gGhRIfwpFDRcF3r7v7htNDXFUzKBVBpJqYk6092U1O9zsqY6Vcvn6NW0oPdg7L+cHuXbXbhz4Z4 6KJZFJgHlVKx4KnX4JPD5VwVAmy3Jg3oGG2QuruHSXp5TxI7l2e422g2dDMsvKUgjgCirU9oaT4 O+CXqRXzdVT70RLWgoo53NhWt+WbSybTwcU1r82I4/fkjpOkDzx0dJwenxGLnOO0x+Q3cKMsahg VH2NeB6dBWtr15VdF646/RQgD1+GpIJWdcQKUwc2HU3W4XkJ/PYMyRiv8u4KY2JQRenTPfC4+6F I X-Received: by 2002:a1c:5788:: with SMTP id l130-v6mr2702746wmb.60.1541525452695; Tue, 06 Nov 2018 09:30:52 -0800 (PST) X-Received: by 2002:a1c:5788:: with SMTP id l130-v6mr2702696wmb.60.1541525451641; Tue, 06 Nov 2018 09:30:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541525451; cv=none; d=google.com; s=arc-20160816; b=QWv5QnfRNL/RAri3h9snnq5TUQI0MQaSXleyL99iMYx0GeTV+C8FSmI3s6hv3xBY2q Gm49TgaMv686z00sVk4T2Qq9FuNcK9MWouNjHeyKn519l1Xnak5GRRJwr7tGDeUEZydo 2xNxvcmIskZUN2o/h14GXRsBcSFRUflnv1uO+6Z7f1ITMjPpTUg9c9fdVPMRaoDhDpHJ QQxBMGU1jGnEhxT6K7BFO7orCubQlwfu1y2BudxhAZg/lr/RKHI8W9cpJlpnplGsBgZB fmIfggWeoQxa4DgCQKM3QbX5qDdSAPQ2+8Hid4AWq+pO8UZ77jHyvLENw/HtOY0zzX89 SGZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=zR59Oh4f3YmUUjWQVuUWbISM47BcdXN0TxZaGQsGruw=; b=u8GcjclCDfjwWiF1A7sc5dDLRgp9Ycqo04p8r7KVeZNjYhsuhn11uf8Vc6F9Rz6OJm adlFje6h27VsZ8qZfz74cQ4qtXk28JHn+WW1BDwIguUXQwaxnyp/do8WFskCjZ701DDT YyxfJ+dzsErl2l4GZYgJ3itmQHctEHWSXQ5GxoxYeeg5F4UfwW1sAVFv6lcLGRNIfYlm 4kA/2SUwlatv9VKv8Z8iySDhuEffR3XpcqGgpI3O5zVt5ncsjmD3bsFrvmlwXH3N3ZER d/CGLt59qySPIFw2fQgqO4gPCmvCr5HG2DEUAkzKl3yw1OlDxFx/7atBtyH1cpN6OXf8 M9aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=KYgRkNeE; spf=pass (google.com: domain of andreyknvl@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=andreyknvl@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id z3-v6sor1504291wru.7.2018.11.06.09.30.51 for (Google Transport Security); Tue, 06 Nov 2018 09:30:51 -0800 (PST) Received-SPF: pass (google.com: domain of andreyknvl@google.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=KYgRkNeE; spf=pass (google.com: domain of andreyknvl@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=andreyknvl@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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=zR59Oh4f3YmUUjWQVuUWbISM47BcdXN0TxZaGQsGruw=; b=KYgRkNeECJs3IElsm0p/zMKWz/tzGt+6DJSzEuOn81O+jW9wjUl7WlsyE44DwW2UBJ IGjSnu8L6/Px81VwxB66DoNIWe9Fv13N1ZxhAB1MOHFuxbZpt5gBXpIC08ZcsnoU//06 p6ZwWNCogZ6ijzbJ2QLRUniM6z71avQSO6O3Dpg2UYO2qU8fsC6elqb+ah3SvDv1lQ0v D9t2T4M5r4m1nXUM/NX8cheOTr7DtYbhC9LBM/lc/47TWAtYevFH5WcZYmfAbmPPZwG6 CHwa7OZJXdLdFCnVq1AdWznvOE+WGHUxDfCZ5LT1J7r+8k29rGlpDeXzjJ8OYkGlKfR9 I2CA== X-Google-Smtp-Source: AJdET5eezPyu5zivf/GdDpGQTMhCVkl0xj8xUSgzntxDQd3ItQFM5kt+5hhSTXC4DgW6e/T6ozoIbw== X-Received: by 2002:adf:9589:: with SMTP id p9-v6mr24794256wrp.270.1541525451174; Tue, 06 Nov 2018 09:30:51 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id z17-v6sm16328416wrm.65.2018.11.06.09.30.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Nov 2018 09:30:50 -0800 (PST) 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 v10 06/22] kasan, arm64: adjust shadow size for tag-based mode Date: Tue, 6 Nov 2018 18:30:21 +0100 Message-Id: <86d1b17c755d8bfd6e44e6869a16f4a409e7bd06.1541525354.git.andreyknvl@google.com> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog In-Reply-To: References: MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov 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 6cb9fc7e9382..9887492381d9 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