From patchwork Tue May 8 17:20: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: 10386609 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 8C598602C2 for ; Tue, 8 May 2018 17:21:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 79F42290B3 for ; Tue, 8 May 2018 17:21:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6D3E2290B9; Tue, 8 May 2018 17:21:28 +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 E2659290B3 for ; Tue, 8 May 2018 17:21:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C1AAA6B02C3; Tue, 8 May 2018 13:21:19 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B77266B02C4; Tue, 8 May 2018 13:21:19 -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 A172B6B02C5; Tue, 8 May 2018 13:21:19 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr0-f198.google.com (mail-wr0-f198.google.com [209.85.128.198]) by kanga.kvack.org (Postfix) with ESMTP id 3EEAA6B02C3 for ; Tue, 8 May 2018 13:21:19 -0400 (EDT) Received: by mail-wr0-f198.google.com with SMTP id w14-v6so21773974wrk.22 for ; Tue, 08 May 2018 10:21:19 -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:in-reply-to:references; bh=nG9MjoijhhOHYsuAcrJlXTo6xE/CO1spvQUB9l7KgZ8=; b=RupvdYNHNxAvmQ3M49mEd2Law1yPpjxtQ/MRHiRcJGOQjGIirwrXTchppppjgM3UZM 81QgzjiVOHyBDAC1bLBTug0sLSy8/BkMKZZn/g1Fb8aR4EzG3oaXQE9Z3JJYrRwt8Q9X Dd2z7U7ReFzd8/Jl7ZrWpVdnDLa6FRpUrI20HfZMRM3V0AiIedYYnnSeyes1L2R735sD wBypMvW5twSPgqQX4WhJqFIzAi5fHhWAj4EnGDmf2ND45jhVjskbR9PmNKWLct1TPQIm yyCN2pyV09ISDvyx5JhDZxajZ3PCEBvAkA3GRrwDg5QHGD9AHv2c8PZ/+SnaKzVWOuS4 /jWA== X-Gm-Message-State: ALQs6tA0IxvGkYoYUxQkBkauO85cfLIryGQF9dDYOIWy+bq2fLLg00KL D0THXzyDoonqcE7lTPTb5/I9pjGoA7IdOYOhLnXM0WGY6UaRnBX18y4079y7/fVPsUMc8eiD8rn nMhvK7tYnqRHz5OGOvXnEBgmhJiSQO1Bt7kz60KHuFNpRWuMHyC+5LpbE57I9HMr+IYbCwdG5Hh C398ZQ+2KjrtpZJja6RC+RJgZSN6Wsoyv5qbEaggIhevu7LGf/MuM8JLSPzI6fTvuCGEjCbO4vI OuB9c3mMi0jp+YSmxNwZ6KFWBUoYazucwsaB1qx1SFjHmnAPBUxuT4wO6E+8BQGG4AdXyCX6KXe 10yZRrhmHai9fo4yIoN5ds3yQBza0znIFrNTeaJkZVd4bc69aQU00EC+Qc3251jinH4uJ/+gvHl o X-Received: by 2002:adf:c4c4:: with SMTP id o4-v6mr33693123wrf.173.1525800078833; Tue, 08 May 2018 10:21:18 -0700 (PDT) X-Received: by 2002:adf:c4c4:: with SMTP id o4-v6mr33693058wrf.173.1525800078134; Tue, 08 May 2018 10:21:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525800078; cv=none; d=google.com; s=arc-20160816; b=Zl1yxTLHaLz9474V3ieP2glh2G6YaMVNfZ3Sn+/GHSdShn89K3opvmc3Q54jeQZUEP SS3cmO7HtUrFeDCsNucTmYxjBjifGPisv1wuDzjdSaahaPMU2UQgNGWPYs0Y/GVtg+XY 91aCplqQ0tymaKiRwg/6uPJVL6g83yOXNsQD5yqcjqLQ0HSGcseriXMh+T0yYUx8SQcH fXrEjmqYB/U5HxejT16IHkSflVb9WGQOaV4UHXr2V6XBECG6LWaQTfUw3ISYjcF8lLQ/ crE1g3Hjhk0ubjavqTgs07/HZCv0NpQqWV+w34CQcqA/y35PGs8hAi+uBn23UCt46EUL rzHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=nG9MjoijhhOHYsuAcrJlXTo6xE/CO1spvQUB9l7KgZ8=; b=tSVpqH8I496XzOSz83l2RfLTt4hqn8mspZycm93RNZO8mjfPvPTrq5XmEr/e1XtzJk yq62wOIPUIe5T0zs/tSt2KxsEIhSNZ2APpIM9ZXmKXYeWelb7rTiDzrWwTu12AtnzWwV BWXGn8iZLeUs2MP2nTS9A1tRKA9nxqxeeKfatdxusKtfcnSiTuL9mQWO66hjbaKFFsFY YzKymhjrTKOojedYRRm+ld4BrLoNkPBYlzRB8lEBq0Yx9eFtsqVGoZ7NPU+6KjMt6Wz6 fUE5T2HSOc0imwQKk57c5IdZnw4xce8Zq4FZiWPGuhTHCpWUDovgl1+BwIVZpkLV6dtv LKfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Owu32bhJ; 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 o18-v6sor12164780wrc.40.2018.05.08.10.21.17 for (Google Transport Security); Tue, 08 May 2018 10:21:18 -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=Owu32bhJ; 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 :in-reply-to:references; bh=nG9MjoijhhOHYsuAcrJlXTo6xE/CO1spvQUB9l7KgZ8=; b=Owu32bhJgnIn5MCOpsb3GpKW05BB2s3YIFKS1Ai1dH9FSr4esKgjvl2HypXHjhNbH1 noshxBHueeSf22hX0rcseeviceM0EgHHd8GG1k3m17jt9mzHoI/Y6x1xcTuJ0XFVO0nS gKy4qk0k4jKEP8c9JovR5aynARVnQChc126SYskoha4dEvVdviRBwrG9SHIqo+mv50Yh UVN0er0V2uH4gqKAEYQwHh99nN8CWT+hwwAI9c02OkpjWmpqlXH1s+L7oUyeBs3y++G/ PjB25R1VbeZwuG+j2f0ZeK/tbzKCxDy+oE+3lm/sivdagygduge/+t+90Es3sAhbzFaV QdIw== X-Google-Smtp-Source: AB8JxZrJU/QKo3xy/3TYI8JfPerBgokBVFF7GdMQY9+WQLmZh61xobD0PC1Cgwkk+tMTC3ql4z1KBQ== X-Received: by 2002:adf:8827:: with SMTP id d36-v6mr32685735wrd.41.1525800077019; Tue, 08 May 2018 10:21:17 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id m134sm14178311wmg.4.2018.05.08.10.21.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 May 2018 10:21:16 -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 v1 04/16] khwasan, arm64: adjust shadow size for CONFIG_KASAN_HW Date: Tue, 8 May 2018 19:20:50 +0200 Message-Id: <3dc2407877072a1f14154928a7ba542b4f5a9c05.1525798754.git.andreyknvl@google.com> X-Mailer: git-send-email 2.17.0.441.gb46fe60e1d-goog In-Reply-To: References: 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