Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5570055imm; Wed, 12 Sep 2018 07:56:37 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZAbt04EUzgPPnXhpLmZLGbyj7Bd9GzWsYdLGhDirzKys3B7wpCQp1B7Fj7vgKaFCJNWuNX X-Received: by 2002:a62:1391:: with SMTP id 17-v6mr2834980pft.34.1536764197490; Wed, 12 Sep 2018 07:56:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536764197; cv=none; d=google.com; s=arc-20160816; b=x3KmY1/6iobH0ht3Uv+15W3zfRIp2DAlhbh4fkzYSL1ujU19sX7YymyFQQ50IIXSAt NYzNPDKtle0sdpDMF5sJ/0nyktqbkA83V9WltXW5WDHe+ljC3DeGZ2HbcLTuyIeFqRTw UrEmAjG4HMAIAMEvdZUDaB8sZof/DKxXxy919EKEGTuuuqvZiIAf6HpWDSF5mrCY+SmC kSc/OmjF5LhfaR2USNDA3Zs7FJBM5piFj2wbGNs15NC/yL/B7w+OOFiqX1wRI9oR0wW2 jc683Q7XEoDETibZbDmXAgNFb8/uTuejlOQ+DkD5pqy+EWijhIs9QJ5b5jCJrc3yuudn 8q5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature; bh=k5V+92Mk2pae4B9LhuCcmaUy962Eq0PEXLKrQvbziRQ=; b=NdLJHhOKhzX4hv7+yWvJWzDpDEzwC3XVeiGEZ+xDQRducCjRL+/7p8a25XG4bVxBiQ wulTQG7NLg8ZCpF1kwQnCOzN7/uVQSvbXbwdxwxbdz3aO717NK91JjlFLpyf4XxqofQe Z9V9bRVFlT2L1GNT81U+hyporn28ATINUzm0IgIrndXl2/MG3Wd4i06ZL93OWnlhsGPs jhnh5y268m4ZDeJ76My3ZPEu4Az7MsTKKcjsg3kQXule6GNQsdx7XJpa5V08Kh10/UBa xKFSj9FKVidKbHK+u2xXssr+4uu5XNackVyxz5WPiw34A4yw4iFdP/3Hgo7kDrnJhNNI vTdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=fB9bKNXf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p126-v6si1249899pfb.77.2018.09.12.07.56.22; Wed, 12 Sep 2018 07:56:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=fB9bKNXf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728546AbeILT7U (ORCPT + 99 others); Wed, 12 Sep 2018 15:59:20 -0400 Received: from mail-it0-f65.google.com ([209.85.214.65]:38295 "EHLO mail-it0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728090AbeILT7U (ORCPT ); Wed, 12 Sep 2018 15:59:20 -0400 Received: by mail-it0-f65.google.com with SMTP id p129-v6so3413475ite.3 for ; Wed, 12 Sep 2018 07:54:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=k5V+92Mk2pae4B9LhuCcmaUy962Eq0PEXLKrQvbziRQ=; b=fB9bKNXfRlaE18KWq8t4mOT6pqGKfk5oLJqvYdLfqUcdq7lXCTlvLyxGlAmpNsp4pD PfbU25iwzQYrI5sIqKuvpkAIMIEOlPanPtUWSoz75y3JvqJovQLZogVF28q9Zj6i0yWU myjJW5kX+RBb//5ZSI9GAb2My0OKnmekyofBSugnqJpJT7HUlYl7c/5xu9stONwowv+u HzbB4nMxKQvhMI+ImS9mCQzKsvVgjD2/yJYknqSAcRxocJ+XCdtZjlgVc7shnlLWRbxy L3oEonKRvCmm5V6qihTvB22ZdCJwwurT7yWHzcn9yD8LSchv8nTDxMB2MH5oIVyssPgl 3pRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=k5V+92Mk2pae4B9LhuCcmaUy962Eq0PEXLKrQvbziRQ=; b=RxndXjEVDNNkcGX/JtWAh1PJKKG466ttkfUW/Ysm3XajLEfwPIWt4+S7lDrGKaxN2P l14z+0QWDtAv08KCWXTTql23Ji1mr1n1sYhNLpxj7umuEQ/B5q1dxS03NHBqZZ1Iyps7 OBALpSAaQQunutfq5rqrmxDj7Tqwowpm2uk6rkBcSr8AzpQgKGLc4n5KgunWjaa3aP9e YguaGh/gF1bOOoJuCo2uMF7d03O2c73R7818Z6LCJXKJoopkSe3PIAY0TlsyNpvnobku CdvT1aC37TTj6dMsWJC0zUjyoadJ2umIwVLzLY/Axj+NGC/EPc9fMR28vlIL0tJtKSf1 w+0g== X-Gm-Message-State: APzg51DzEfqEfD4898feJsBCM6v3HCEuTrpzDxB6JadebMcry+4BRB8O Niu30Y4NIxuTxUDvHBXZXiceGthXiy/mASwBIlgt7g== X-Received: by 2002:a02:c04e:: with SMTP id u14-v6mr2172320jam.110.1536764067365; Wed, 12 Sep 2018 07:54:27 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a02:5942:0:0:0:0:0 with HTTP; Wed, 12 Sep 2018 07:54:06 -0700 (PDT) In-Reply-To: References: From: Dmitry Vyukov Date: Wed, 12 Sep 2018 16:54:06 +0200 Message-ID: Subject: Re: [PATCH v6 04/18] khwasan, arm64: adjust shadow size for CONFIG_KASAN_HW To: Andrey Konovalov Cc: Andrey Ryabinin , Alexander Potapenko , 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 , linux-doc@vger.kernel.org, LKML , Linux ARM , linux-sparse@vger.kernel.org, Linux-MM , "open list:KERNEL BUILD + fi..." , Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Jann Horn , Mark Brand , Chintan Pandya , Vishwath Mohan Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 29, 2018 at 1:35 PM, Andrey Konovalov wrote: > 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 106039d25e2f..17047b8ab984 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_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 b96442960aea..f5e262ee76c1 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 I am somewhat confused by the terminology. "KASAN" is not actually "CONFIG_KASAN" below, it is actually "CONFIG_KASAN_GENERIC". While "KHWASAN" translates to "KASAN_HW" few lines later. I think we need some consistent terminology for comments and config names until it's too late. > + * 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 > -- > 2.19.0.rc0.228.g281dcd1b4d0-goog >