From patchwork Tue Nov 27 16:55:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10700909 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 DE8A81869 for ; Tue, 27 Nov 2018 16:56:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC9422C4AB for ; Tue, 27 Nov 2018 16:56:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C97EC2C4B7; Tue, 27 Nov 2018 16:56:17 +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 59E812C431 for ; Tue, 27 Nov 2018 16:56:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0F3C26B493E; Tue, 27 Nov 2018 11:56:02 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 02E716B4941; Tue, 27 Nov 2018 11:56:01 -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 DEE066B4942; Tue, 27 Nov 2018 11:56:01 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by kanga.kvack.org (Postfix) with ESMTP id 7CD746B493E for ; Tue, 27 Nov 2018 11:56:01 -0500 (EST) Received: by mail-wm1-f70.google.com with SMTP id y85so18175495wmc.7 for ; Tue, 27 Nov 2018 08:56:01 -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=xTUWDQtoCoS0aCkqKcHlSfKscpiq6EmalPX21Pfc5fY=; b=Gf0ViYonmJJVGVBByDxRobVLGEAwCt9g6H/KdT+7UxenZAXR3ayd0y4NIoKH5lsINM Q53RDFII6prG2oc063kX293EN1F0dX4yUGzCf+Pxa7nOYxuo77JglLv3LlJ65JB8ZjK8 KIu/hfDIyY0HCdNUhEhmCOj5J4Sfuqlp2KfS2L+8+aMna6rjuJF33vp9YtF2Lt75cG4W X1cUOirPm9nqexEHrFBjJuPtJDPMUhp3C+WmGxXJV3pLkhqAvKMFWLV//OUtpEvWdmD/ Boq5Sdwmo/h3UZZm4TBINhHWUt2BHzHGKVMdN+WAezxEVNn+WP1M/w7GOeM9PqLOFi8P yzBg== X-Gm-Message-State: AGRZ1gJa11ojb8slwFftlmkSPwvo1Ui1sjSqWdZgWWek2k3Agr8KMvHX UjRkeToUXeVyYXvyspl6vAYQRy+nnqUXNHc0WUIDc63nA7wX0fLKCG0iNVUe1O+rCYoTwLuhWD6 e+gVLeZQy2dD967cw+AwPozF2I94ma98uiAbUkOtViULaod+Z762wNuAww5OU80Z5p/FAGtCV8R HVtJHVpPDrTTXCOth+nOtgd2W8Uvyptp/r/sK+VeZwSNvKbeKEAwZCi4VdCPwbEoZoowX2xD7AX ysQsUntpLvzFODndOVoWlH1qlVjNcFWuhoSeb53mDj0gKh1As8ob/fUWCyPGy2E/CsXIF3dYw1b TNMLQK5zvi0Fe0PwCbl6Q8VgXdx/4aaEkTzUozJNGdZ9HYR6bn+se9a5NKL75H6+46k1j2fjhjX e X-Received: by 2002:a1c:1c86:: with SMTP id c128mr27395340wmc.107.1543337760969; Tue, 27 Nov 2018 08:56:00 -0800 (PST) X-Received: by 2002:a1c:1c86:: with SMTP id c128mr27395291wmc.107.1543337759988; Tue, 27 Nov 2018 08:55:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543337759; cv=none; d=google.com; s=arc-20160816; b=llFr+Ovi+2tZo27ChS0QtqIAEn0u4ki+K7f8Rq8VpFg5aW6IMyyj/nVxq2AX4XtTT/ JiUQNnZ7ytxJpc3lqNZ0yKO3A0Y4+1ZmYL6a5D3WH+OkALXZ7a8fqstpPHWJG3cv+Hd8 v3RMCdweVWNk3pgg3MJQFzrL1QTMMWahnoxh8DUPN7MZcc+aQLfBXmOVuHHPTR2x3q7K HycwFE6+P23C1gP0V3XYpM0S1rPYbJOp/K+MPrhkIO6pvhUBCuoqPQRC/MbJ/2M9KFyF OJQDuxImb4iEsn9USk0Ja7sp+vAyOUKwlwaiAJkcDsT/QvoIZlrGnZxD4TYqa16jv3gT 3vhg== 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=xTUWDQtoCoS0aCkqKcHlSfKscpiq6EmalPX21Pfc5fY=; b=unRW26htBnjnGVfsG8eP4zE5LCyI/uaIkUAS1uUR1FzgTqfZEvAdyxi/TLKK0RcMaL pj+RVcEWAN4AO/UO87ZEd/1Z7APDxVfvwFuTTj2IjXRpV3seyh7XOR0FYmacWEFfvQOt tPq87j5Apbs7af2poS2H4QqrAOt2nwCyvGIZFAnvnjG6+zNV0wqhdFZ1yS05p1CO0OZU +Lf4Ga926pklofPnC4xMnZVNQZG0Ut1kynW4BIxHb0KEyWYKUCe6mvpk0M5v8Mh/Ro+E kxpqmPHCQExtpeukH04CayUtf4eXt7Adtdj19YMF+nijDCBSlJurNKKG262afXmR+I2l /dHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=dwUU3Biv; 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 l127sor3247071wmb.7.2018.11.27.08.55.59 for (Google Transport Security); Tue, 27 Nov 2018 08:55:59 -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=dwUU3Biv; 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=xTUWDQtoCoS0aCkqKcHlSfKscpiq6EmalPX21Pfc5fY=; b=dwUU3BivFrGTU0l5vocuel01QRAE+v2OGhkebJVpy0mfJmO48WW8JjO/aQRDNIxlzp 7Q7mQuPIYO6ENLlB1vL2wNEuEIHZp+ISZDSJKEFWk4t6VwdTO034MsDUqOMVSpnvYHaG EJcyDLbTK9jrS7IEcf09GuU+VgeRwknC0Tlm4O/P5QswfFrC1hiDKmoKuUuLwhOvaaB1 eOqzl7HmKc1Hk+kdVzfJIn3rAmpOXnEkoLkjR1OyF9bg+r+lmbARfTC79ZfPy4UEbmPK TLasPIfGNrBaUGy9nXGM879QdxieJEgd31QTd/Q6LhFdvEscYdJa6SZolCyN4ZLBGe0E +eCQ== X-Google-Smtp-Source: AFSGD/WWRQkAxqiKVcqGdnvTy6zSnKmrDpYhgJDtIRt2URzdNRxagoHNN/L5SvG9mNp5eIbIhcSMqw== X-Received: by 2002:a1c:9692:: with SMTP id y140mr12993788wmd.67.1543337759395; Tue, 27 Nov 2018 08:55:59 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:3180:41f8:3010:ff61]) by smtp.gmail.com with ESMTPSA id k73sm6383099wmd.36.2018.11.27.08.55.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Nov 2018 08:55:58 -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 v12 06/25] kasan, arm64: adjust shadow size for tag-based mode Date: Tue, 27 Nov 2018 17:55:24 +0100 Message-Id: <95fa472a03a8ff268e24b8730ebd108922824e74.1543337629.git.andreyknvl@google.com> X-Mailer: git-send-email 2.20.0.rc0.387.gc7a69e6b6c-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 | 11 ++++++++++- arch/arm64/include/asm/memory.h | 7 +++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index 6cb9fc7e9382..99e7d08c6083 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -91,10 +91,19 @@ else TEXT_OFFSET := 0x00080000 endif +ifeq ($(CONFIG_KASAN_SW_TAGS), y) +KASAN_SHADOW_SCALE_SHIFT := 4 +else +KASAN_SHADOW_SCALE_SHIFT := 3 +endif + +KBUILD_CFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT) +KBUILD_CPPFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT) +KBUILD_AFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT) + # 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_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..05fbc7ffcd31 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -74,12 +74,11 @@ #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 -#define KASAN_SHADOW_SCALE_SHIFT 3 #define KASAN_SHADOW_SIZE (UL(1) << (VA_BITS - KASAN_SHADOW_SCALE_SHIFT)) #define KASAN_THREAD_SHIFT 1 #else