From patchwork Fri May 25 14:40:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10427657 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 3DBFD602D6 for ; Fri, 25 May 2018 14:41:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2CD51297AC for ; Fri, 25 May 2018 14:41:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 21333297BB; Fri, 25 May 2018 14:41:03 +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=ham 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 923EE297BA for ; Fri, 25 May 2018 14:41:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DEB536B000C; Fri, 25 May 2018 10:40:49 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D72116B000D; Fri, 25 May 2018 10:40:49 -0400 (EDT) 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 C113B6B000E; Fri, 25 May 2018 10:40:49 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr0-f199.google.com (mail-wr0-f199.google.com [209.85.128.199]) by kanga.kvack.org (Postfix) with ESMTP id 5F8A46B000C for ; Fri, 25 May 2018 10:40:49 -0400 (EDT) Received: by mail-wr0-f199.google.com with SMTP id 44-v6so4401801wrt.9 for ; Fri, 25 May 2018 07:40:49 -0700 (PDT) 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; bh=oTtCGGLOzhv3V7VRTFXMq9cQig+QV1ud5Mv8svCaQV8=; b=b6F8Kg7iQ6YWiOHhBI8YN4KNqqJCqxdy13ewinkIb1mFWlZdPP9W64LD6Ze2IBv0VL tMNg7e9gZlq1oXdl7LWJeC6S6n6Myhe1ytZ8FBkjSZFLn3yG4LDXf4XQwVSDzAnQZ+DX jvoR0kVDsb0ix8FHZ6YQPPFTKlAWHoiP9uEhgqCcxZM4uSXi7n+QAslcyrBHS7brI+eq J7A1iTwrVKNr9NAEFVNRTgzwP/5Ap36PT78gLxab5hRuTMupigQls9RFuYSj+rxDCGsP k4I5N3ESeRAJhsDAeFU7HAN5RpT66Jaq+uH/dX5RMfVoEJ/sB2WID6wvhjgXZIwCfj7v 0VxQ== X-Gm-Message-State: ALKqPwflX3ezB3ip88skfyZHL84ff5DI4a3uG62UczA0MloWzQGHLaid 7vd4d64+h4GpPKURbcU4s8gPOQBwAgAQB/VIkoXHMSeY8umTFnlkEtZrMf9vTWNFvPgkfnATrSw 5b5NQcVlGPq6yN2DaRYVOweMZ2FgD2JUGY1qlewkJF0st4CmHuHJKQNyPJvlE5VzpsR1IdAZtbx Z4eL5zLDf1zur5wttOoWy0snJMKPLvpimc8sPtZLVmPunMuBY+gIlV7d8VtxMVpdLgIfLJnQKZD 6iVGdV5R3pgwi/WOE56ox9RR2kSt7jP37RHKd1tgiu5aC9VSigrMgzD7bGXz8yLwuQHddadz32o sWV6nHdUPcnOpiVZXltfTHKM4on5KEs8nQCNDEYrqmsM7MJTFZUBQ88jUN5Ui9ftnK/KglnCkRZ / X-Received: by 2002:adf:97c2:: with SMTP id t2-v6mr2701281wrb.28.1527259248951; Fri, 25 May 2018 07:40:48 -0700 (PDT) X-Received: by 2002:adf:97c2:: with SMTP id t2-v6mr2701236wrb.28.1527259248028; Fri, 25 May 2018 07:40:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527259248; cv=none; d=google.com; s=arc-20160816; b=exsPfNT9l7kr7sW3oiQVUiD5jhe7PQPWW1/hRG24qBZG6wnypg2g9f+ZbOVCmKJqBZ 3QVb12pHPDtQzFvoalkPeS/sSpuL6Y46r/d2FMKruCh+PA6yRNvy08Yo6r+k3WeCtvmf sZs8ZDReAl+tnGdUtkRTFiAMOY+Ph4/wL+/PoPlJMHprdu7asorkjnv04pdH5w12Atej RgLTDTsD24B1KSFeB2S2tvFuipdbhiltygZCxU9b49n6+IZNin7Y24PZicB7uqa1VS6j IO6MnCdXlcIg1m+QJj6Z14spAnfb4BbZtBrhlX1tul0LywPs9TLy3B0n1aLoI7/poLnh 2cvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=oTtCGGLOzhv3V7VRTFXMq9cQig+QV1ud5Mv8svCaQV8=; b=jadPdFiCkOwGqQT2UbqV2tOgfs1kLqgYIjAvr10s19T9U8DIQhyqJIu6mZtp1cDXQM MsTYGHv+H/Kb2xRXD4P4OhPJEuF2fXCJMNiGYXhO2C8Z0w00HdbJrixXkkJ9LQqxCmcB hQu50a1+O2MSAsKxSzeARlYlUYrTzNDuG9UPD4rcxpmQtYHdXgq+0Tj5wk4CPsgJJQHT szB9ZinlM/JNb5tCtfOEuF449ksWpDv/9GnARbCfeQJk04cXWUDKV84oMI6MlW8r61r5 22B8eWPLkeycJaDb5qVNIXj1MJ2dyJ6iY2/116ag0vwsgxpy0RzsXAcK3ksAX0xCmd92 4iHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ITcLfIdf; 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 m28-v6sor2209697wmi.51.2018.05.25.07.40.47 for (Google Transport Security); Fri, 25 May 2018 07:40:47 -0700 (PDT) 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=ITcLfIdf; 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; bh=oTtCGGLOzhv3V7VRTFXMq9cQig+QV1ud5Mv8svCaQV8=; b=ITcLfIdfiB4+ViuTgyxwUGAe13NGC3AvM392wIGMAepqOwQgS5O9EfDe2JKBzavM2O +6yEFy02YkGtxGoXjZ5Uq6B2Vu8RzpE+dJLz66Lz4PBhaIL/rolJ1Y6X7fnuUg8suwAx 39wZ/R1/tLsuB/RCHO3vm9QaOE2SSq7myAlaiJIkJ/DiqQiWiwk/wdTWMalTHJD34rDS jsyNXvuNxUBOkJQn/cFDNsoETBb9pqQljJ2aBcAwxqaz4O6uQmLTCopanNKl+aWs20kO tuet/XSmDh/POZArqAu7Pbhwrrmf642MujNgs6DJHuagUMeQkY6znzWs8gF6zrXXeO8G dLZA== X-Google-Smtp-Source: ADUXVKIC1ciGKk5ZOAO/+JEr3SLaimDhQC5FPOzZRNOsxlilolA5VvsWj29N1jx7OHTxzg8fVXnRQg== X-Received: by 2002:a1c:c2d5:: with SMTP id s204-v6mr1916812wmf.40.1527259246447; Fri, 25 May 2018 07:40:46 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id q2-v6sm25293885wrm.26.2018.05.25.07.40.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 May 2018 07:40:45 -0700 (PDT) From: Andrey Konovalov To: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Jonathan Corbet , Catalin Marinas , Will Deacon , Christopher Li , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Masahiro Yamada , Michal Marek , Andrey Konovalov , Mark Rutland , Nick Desaulniers , Yury Norov , Marc Zyngier , Kristina Martsenko , Suzuki K Poulose , Punit Agrawal , Dave Martin , Ard Biesheuvel , James Morse , Michael Weiser , Julien Thierry , Tyler Baicar , "Eric W . Biederman" , Thomas Gleixner , Ingo Molnar , Kees Cook , Sandipan Das , David Woodhouse , Paul Lawrence , Herbert Xu , Josh Poimboeuf , Geert Uytterhoeven , Tom Lendacky , Arnd Bergmann , Dan Williams , Michal Hocko , Jan Kara , Ross Zwisler , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , Matthew Wilcox , "Kirill A . Shutemov" , Souptick Joarder , Hugh Dickins , Davidlohr Bueso , Greg Kroah-Hartman , Philippe Ombredanne , Kate Stewart , Laura Abbott , Boris Brezillon , Vlastimil Babka , Pintu Agarwal , Doug Berger , Anshuman Khandual , Mike Rapoport , Mel Gorman , Pavel Tatashin , Tetsuo Handa , 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 , Kees Cook , Jann Horn , Mark Brand , Chintan Pandya Subject: [PATCH v2 04/16] khwasan, arm64: adjust shadow size for CONFIG_KASAN_HW Date: Fri, 25 May 2018 16:40:20 +0200 Message-Id: X-Mailer: git-send-email 2.17.0.921.gf22659ad46-goog In-Reply-To: References: 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 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 87f7d2f9f17c..99c9649c57b1 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -99,7 +99,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