From patchwork Tue Jun 26 13:15:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10488975 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 21F68601A0 for ; Tue, 26 Jun 2018 13:18:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1196B26E98 for ; Tue, 26 Jun 2018 13:18:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 059552621D; Tue, 26 Jun 2018 13:18:27 +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 A3DB12621D for ; Tue, 26 Jun 2018 13:18:27 +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=tF6ZVlBx705IsaE4GJePomXgKAk6RhTRenp4mFYU0VU=; b=Gmguz9G7fUP/rvF/TMfvHP9P5m tInhPbf8OO2/UOgryKxlTIM4Q6lWt4iOEDEtX+NINWyeb7svjxqUyTaoCMrotmA25r42xgTEaCQmP dRyJVr9LNmjqYNsXRixHfExozFUJwbeYq3jcvqPSP2vre/QbhztH3b2T+s4L+Xzdet2e4i5rBZe78 sY4A+9qJuhQHr/CvLYK/wczzdXBYRQHNiBa9E3bFlnDlZp+vvvcfFu0Krs7ofQ5xkKLIryPIE62Sp pHzpIRI8xoh5cClIPPv7xRF9QaI1x25l4siVqGQg1M0FKhAMx4QxcPplZjek90OwCtgAuQehi4N1J Z+OX8gRQ==; 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 1fXnrN-0008VC-Jn; Tue, 26 Jun 2018 13:18:17 +0000 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fXnp1-00079j-DE for linux-arm-kernel@lists.infradead.org; Tue, 26 Jun 2018 13:16:13 +0000 Received: by mail-wr0-x242.google.com with SMTP id k6-v6so17223798wrp.4 for ; Tue, 26 Jun 2018 06:15:41 -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=YhNLQluC3zPdVMeBvR8Lp3d958WDaREzBrtKu3hGG6k=; b=RwV4diPI5VZPDDv5Zq8UsZ/Wk67TJvBxzP6g9IZUzZGKVf+VNmstYYfQWZsJZ/V0k5 kAGn6M69HRK9FZmOqol0Eujoa+GaZYCZXTCNBVvhD0E2dshKwkWAu1lPbilKNvNtAgRC 9sa+ZHs0eVFwO+Jc5oKtsJPREpBD2NVSdf1bsCDNzGPHXBvBig5iOm9PGRfd6gKMgupm +5g2h6ETCHP7/i9e/AUa3UezW+aAi2E4ZUz5XIr3RXUMzmWrdXUHKChNE1ij00G1qdSo BPejbwPfDWDB0ZVftjMIp3fLSmKWo7+XACY67IRLpaUtBvgzIIQ5rVx7RGuZe+qSw13u 0NcA== 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=YhNLQluC3zPdVMeBvR8Lp3d958WDaREzBrtKu3hGG6k=; b=GO3XYZctin0y3ZdUx2NbtSheXYMu29dc2wCWizhL7CYiPw1rPqnwsGw5dD+G4fRFH4 ge/ZSGnvMJ9dxjAgTDfZurkbjr5pzlNxHI9cPbT1b7qPY+2fJ24tGOvoUGd5o7Av+1Q1 4t42Q+U0duRlfhRqrNzTdAZnsCtgj2ocv51dp1kovzbHuLvtRQ+IhaW7ixYdFTzS7iBU JV/ngLWGXsyYrmCAQoGTprktS1zEsvp5lB96rAlA2sIm7kkeM4gix/DiH8R9GQ5XNPqM Oq6JfV9DYKpJYcK8r+ceneGO2h9zbvCaFKyrL0UCeFS0mwQangVYCsCvtFfvqvJSlhkY Cvpw== X-Gm-Message-State: APt69E2Ko9lrGRjFQ/bJXPumHJ913uRhFweHveo07yJ3p8xadInUaH9R rUp6+8k1kExEMOgh4Tks1FPipQ== X-Google-Smtp-Source: AAOMgpe73aw5AlVm35tCVu9KNcKwev8Ou8kNvcNlIjMYYsOqNt5bqVLG2IwOrZEwRCFZ4OVr7mUFFg== X-Received: by 2002:adf:88e3:: with SMTP id g32-v6mr1411208wrg.62.1530018939538; Tue, 26 Jun 2018 06:15:39 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([2a00:79e0:15:10:84be:a42a:826d:c530]) by smtp.gmail.com with ESMTPSA id w15-v6sm2162639wrn.25.2018.06.26.06.15.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 06:15:38 -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 v4 04/17] khwasan, arm64: adjust shadow size for CONFIG_KASAN_HW Date: Tue, 26 Jun 2018 15:15:14 +0200 Message-Id: <7bd08c76830e4cd23f90d1ed25721fca3c5f3205.1530018818.git.andreyknvl@google.com> X-Mailer: git-send-email 2.18.0.rc2.346.g013aa6912e-goog In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180626_061551_475439_EFCB294B X-CRM114-Status: GOOD ( 14.54 ) 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