From patchwork Thu Jan 11 15:29:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 10158155 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 D6BC2602D8 for ; Thu, 11 Jan 2018 15:30:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BD2322881A for ; Thu, 11 Jan 2018 15:30:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B171E2882E; Thu, 11 Jan 2018 15:30: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=-4.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.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 31F702881A for ; Thu, 11 Jan 2018 15:30:03 +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=a4revUd59rC333pn3q58uF6ovWg7Hc95CvwLfODaJb0=; b=IFPNGS6pDa5XHEIPKE5vlkDIiJ qq2UtMxnuowQ7E+oWM6/Mp/T7aA02MlSLvxxdqcepMW2ZtneQwGBtvMLM2Rh6Xhqq+QNleyF+x2Pt u70Itxk8MezY48KNsP7Vx/41ltpJZ25icjERjZrqiHDhY6HWSX6/zCLLCQni83XGSW4hBV8fvMWSK iQjqECPkttYOpOvEUW26SN3Pv0Yyvm8fr4m1KRaHF+yXy01zmghyJ5ORBUyVAXdGhfQkR+DPmzbEI bEsJYcrKDT31F4Clg+fseZRsostQ3jwG05ntEdimx90NGUBbvlVQDdJJgc7jeLAgl3HHOCNXe4MAj fx1fjSjg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eZenn-0000tE-7f; Thu, 11 Jan 2018 15:29:59 +0000 Received: from mail-wr0-x244.google.com ([2a00:1450:400c:c0c::244]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eZenL-0000IY-31 for linux-arm-kernel@lists.infradead.org; Thu, 11 Jan 2018 15:29:33 +0000 Received: by mail-wr0-x244.google.com with SMTP id z48so2516575wrz.6 for ; Thu, 11 Jan 2018 07:29:20 -0800 (PST) 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=XHvsIIGs7WiTC3xvFP9O42JohHZFFRDOAp+U+p24ShQ=; b=uNY8mNr3Ra3vUukobzI8J7qx51McZ7Tu0Ftsm1854kG5qd4nnVN9vDfZVE/7gdufS/ 9PsJxur4nsXk8BOkP6wmEGa3WvSKRZlfg15xqRJk8ga+MQmrbCmLeT7hA2KoerW90RmS T6xjC2pwV4793945SW8IcMbPuIHR8RyvtmLZ0PxintBxPYd88HTvy1CwR7ZmELnyuvFo AsHVGnh/JJfiDY/xiBLamTz9PMPzraEG0hLZWhQFagsfJoTTngV0a+bwZdbAgUX3juNa INKKCkJrj0OPCoMatPzysUmoKuZqNOTfPkmcsUxUK21iXMfuz1D75Q9No6q0rVwalaB+ E3BA== 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:in-reply-to:references; bh=XHvsIIGs7WiTC3xvFP9O42JohHZFFRDOAp+U+p24ShQ=; b=QTybf/0ZAHyK8wPgii7pOMkDAF9bwii1dXuUbuXhoFhUzS+6tBE7yp2Xgja2ubJjCh 9blRQbyZiPbU9cOjJyQk9O0ffqAt7ABcN8K8GM0aR0+a4C19ugexCOYYaKnOZ0UIH+2o vY50kFcivYeoJ3jkBcy4c1r1rRnWiv82VcKJlycGHcRmLtRJidAbnthTr4j2jQ5dRLRv eZcS7P5M3lV2YOvzKKoQUMisb+8vD6Kzc9/rzLIYBoVYNVaZ7vHYsg7cUqZPp8MBu3Hg yyeWIj4yWW1bNJSeoZxftyJdZnno3lrPVDGggOnujcixwz8zeU1tGutmOLD5PMc2PwXL u57A== X-Gm-Message-State: AKGB3mIwmE838A5zJjMvDFmFa5qudg2LCb4/3N8VKBMd8NcCI1Hm+okL bToAHcEf7V9vSd8xD0HuWEWQIA== X-Google-Smtp-Source: ACJfBotA27ECSvGamM88KIctvkzYpmwI2Qlo5C/S5qB0ItH/aS1Goa4gQyZtq1OgT0vuksbbXksPWw== X-Received: by 10.223.167.66 with SMTP id e2mr21481864wrd.91.1515684558836; Thu, 11 Jan 2018 07:29:18 -0800 (PST) Received: from andreyknvl0.muc.corp.google.com ([100.105.28.69]) by smtp.gmail.com with ESMTPSA id 67sm1446517wmq.38.2018.01.11.07.29.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Jan 2018 07:29:18 -0800 (PST) Received: by andreyknvl0.muc.corp.google.com (Postfix, from userid 206546) id 535B118080E; Thu, 11 Jan 2018 16:29:17 +0100 (CET) From: Andrey Konovalov To: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Catalin Marinas , Will Deacon , Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] kasan: clean up KASAN_SHADOW_SCALE_SHIFT usage Date: Thu, 11 Jan 2018 16:29:09 +0100 Message-Id: X-Mailer: git-send-email 2.16.0.rc1.238.g530d649a79-goog In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180111_072931_222322_CAB61317 X-CRM114-Status: GOOD ( 13.83 ) 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: Kostya Serebryany , Andrey Konovalov 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 Right now the fact that KASAN uses a single shadow byte for 8 bytes of memory is scattered all over the code. This change defines KASAN_SHADOW_SCALE_SHIFT early in asm include files and makes use of this constant where necessary. Signed-off-by: Andrey Konovalov Acked-by: Will Deacon --- arch/arm64/include/asm/kasan.h | 3 ++- arch/arm64/include/asm/memory.h | 3 ++- arch/arm64/mm/kasan_init.c | 3 ++- arch/x86/include/asm/kasan.h | 8 ++++++-- include/linux/kasan.h | 2 -- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/arch/arm64/include/asm/kasan.h b/arch/arm64/include/asm/kasan.h index e266f80e45b7..811643fe7640 100644 --- a/arch/arm64/include/asm/kasan.h +++ b/arch/arm64/include/asm/kasan.h @@ -27,7 +27,8 @@ * should satisfy the following equation: * KASAN_SHADOW_OFFSET = KASAN_SHADOW_END - (1ULL << 61) */ -#define KASAN_SHADOW_OFFSET (KASAN_SHADOW_END - (1ULL << (64 - 3))) +#define KASAN_SHADOW_OFFSET (KASAN_SHADOW_END - (1ULL << \ + (64 - KASAN_SHADOW_SCALE_SHIFT))) void kasan_init(void); void kasan_copy_shadow(pgd_t *pgdir); diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index d4bae7d6e0d8..50fa96a49792 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -85,7 +85,8 @@ * stack size when KASAN is in use. */ #ifdef CONFIG_KASAN -#define KASAN_SHADOW_SIZE (UL(1) << (VA_BITS - 3)) +#define KASAN_SHADOW_SCALE_SHIFT 3 +#define KASAN_SHADOW_SIZE (UL(1) << (VA_BITS - KASAN_SHADOW_SCALE_SHIFT)) #define KASAN_THREAD_SHIFT 1 #else #define KASAN_SHADOW_SIZE (0) diff --git a/arch/arm64/mm/kasan_init.c b/arch/arm64/mm/kasan_init.c index acba49fb5aac..6e02e6fb4c7b 100644 --- a/arch/arm64/mm/kasan_init.c +++ b/arch/arm64/mm/kasan_init.c @@ -135,7 +135,8 @@ static void __init kasan_pgd_populate(unsigned long addr, unsigned long end, /* The early shadow maps everything to a single page of zeroes */ asmlinkage void __init kasan_early_init(void) { - BUILD_BUG_ON(KASAN_SHADOW_OFFSET != KASAN_SHADOW_END - (1UL << 61)); + BUILD_BUG_ON(KASAN_SHADOW_OFFSET != + KASAN_SHADOW_END - (1UL << (64 - KASAN_SHADOW_SCALE_SHIFT))); BUILD_BUG_ON(!IS_ALIGNED(KASAN_SHADOW_START, PGDIR_SIZE)); BUILD_BUG_ON(!IS_ALIGNED(KASAN_SHADOW_END, PGDIR_SIZE)); kasan_pgd_populate(KASAN_SHADOW_START, KASAN_SHADOW_END, NUMA_NO_NODE, diff --git a/arch/x86/include/asm/kasan.h b/arch/x86/include/asm/kasan.h index b577dd0916aa..737b7ea9bea3 100644 --- a/arch/x86/include/asm/kasan.h +++ b/arch/x86/include/asm/kasan.h @@ -4,6 +4,7 @@ #include #define KASAN_SHADOW_OFFSET _AC(CONFIG_KASAN_SHADOW_OFFSET, UL) +#define KASAN_SHADOW_SCALE_SHIFT 3 /* * Compiler uses shadow offset assuming that addresses start @@ -12,12 +13,15 @@ * 'kernel address space start' >> KASAN_SHADOW_SCALE_SHIFT */ #define KASAN_SHADOW_START (KASAN_SHADOW_OFFSET + \ - ((-1UL << __VIRTUAL_MASK_SHIFT) >> 3)) + ((-1UL << __VIRTUAL_MASK_SHIFT) >> \ + KASAN_SHADOW_SCALE_SHIFT)) /* * 47 bits for kernel address -> (47 - 3) bits for shadow * 56 bits for kernel address -> (56 - 3) bits for shadow */ -#define KASAN_SHADOW_END (KASAN_SHADOW_START + (1ULL << (__VIRTUAL_MASK_SHIFT - 3))) +#define KASAN_SHADOW_END (KASAN_SHADOW_START + \ + (1ULL << (__VIRTUAL_MASK_SHIFT - \ + KASAN_SHADOW_SCALE_SHIFT))) #ifndef __ASSEMBLY__ diff --git a/include/linux/kasan.h b/include/linux/kasan.h index e3eb834c9a35..e9eaa964473a 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -11,8 +11,6 @@ struct task_struct; #ifdef CONFIG_KASAN -#define KASAN_SHADOW_SCALE_SHIFT 3 - #include #include