Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4296426pxb; Mon, 8 Feb 2021 12:45:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJwngxlEBiP+kKmrocjs28AmbccdwPoJH4hWhKshLYt+Z6u7BxXY1yA/9y8oV9lWftV3KiTz X-Received: by 2002:aa7:d58b:: with SMTP id r11mr18947210edq.241.1612817105374; Mon, 08 Feb 2021 12:45:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612817105; cv=none; d=google.com; s=arc-20160816; b=uUZITMPfiQu8BCUfQWqE8hMW29okcFZkOB70qncugK5k/RPejT0f26eOHuIgBREeS+ N5pvR8LOVZICAlVbPji7Anx7SK4rP5WJKln4XP9ixp1sMgaNOYOVfaRwqs0ciEG8C9ZX IEdiSXi7zBmtIYPbQcKijfSeB5Hs49QCbjxXnzAg5Gzsb4CzrpRkpzorL+MgRdoI/n0x 63j48P6OxTMKqYgcGMMROgZqabCTOGqEwLRHP0bFOVBzalboASErU//YetjFEVo77Hc+ vcg5tmhHLEzlT6hB6xl6EDuJ3Qzj82AsbkBjl5e/mKY4Fy44gbHwPOfKO8dR4D6RRAlQ 4YgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Nt08x/e1M06EURUD1LXp/c05E+0vYqfCV+k39JTMPjY=; b=c05YjiNg9Zl7f2u5l0CKfXKCK2vAllcOtMxV82J88Wt3EQeULohjScXIIn1q7LcXuC HkTJoQC/A46p+j2AkGdEoepOSUhKeZYDO0+0YMnUd/NGj2TH5QU8o0BunFWtVJrmMcBd m+rY8ZrsYqAzER5lZwpN2aI+28HZ8kzJs5LnBq3ZKTDsytDZMz3h+BTwks5hqwcdoaDJ NHh6uXywWtVU4FBklPx2rCV098n/lyIPgkz/3jwSoPy9UGyAGsWdB2c3v0RPr7KPBTdT XTW9XBsnPUBJh0/VwOqy9WQKIZ+VA5DSj8BEBxRpIgHf9oqskMM31Y7RnuX9LGIhkZ45 w8xA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n14si8222908ejr.267.2021.02.08.12.44.39; Mon, 08 Feb 2021 12:45:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234126AbhBHUnp (ORCPT + 99 others); Mon, 8 Feb 2021 15:43:45 -0500 Received: from relay7-d.mail.gandi.net ([217.70.183.200]:50045 "EHLO relay7-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233606AbhBHTc2 (ORCPT ); Mon, 8 Feb 2021 14:32:28 -0500 X-Originating-IP: 2.7.49.219 Received: from debian.home (lfbn-lyo-1-457-219.w2-7.abo.wanadoo.fr [2.7.49.219]) (Authenticated sender: alex@ghiti.fr) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 916D420002; Mon, 8 Feb 2021 19:31:24 +0000 (UTC) From: Alexandre Ghiti To: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Paul Walmsley , Palmer Dabbelt , Albert Ou , kasan-dev@googlegroups.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alexandre Ghiti Subject: [PATCH 1/4] riscv: Improve kasan definitions Date: Mon, 8 Feb 2021 14:30:14 -0500 Message-Id: <20210208193017.30904-2-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210208193017.30904-1-alex@ghiti.fr> References: <20210208193017.30904-1-alex@ghiti.fr> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is no functional change here, only improvement in code readability by adding comments to explain where the kasan constants come from and by replacing hardcoded numerical constant by the corresponding define. Note that the comments come from arm64. Signed-off-by: Alexandre Ghiti --- arch/riscv/include/asm/kasan.h | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/arch/riscv/include/asm/kasan.h b/arch/riscv/include/asm/kasan.h index b04028c6218c..a2b3d9cdbc86 100644 --- a/arch/riscv/include/asm/kasan.h +++ b/arch/riscv/include/asm/kasan.h @@ -8,12 +8,28 @@ #ifdef CONFIG_KASAN +/* + * The following comment was copied from arm64: + * KASAN_SHADOW_START: beginning of the kernel virtual addresses. + * KASAN_SHADOW_END: KASAN_SHADOW_START + 1/N of kernel virtual addresses, + * where N = (1 << KASAN_SHADOW_SCALE_SHIFT). + * + * KASAN_SHADOW_OFFSET: + * This value is used to map an address to the corresponding shadow + * address by the following formula: + * shadow_addr = (address >> KASAN_SHADOW_SCALE_SHIFT) + KASAN_SHADOW_OFFSET + * + * (1 << (64 - KASAN_SHADOW_SCALE_SHIFT)) shadow addresses that lie in range + * [KASAN_SHADOW_OFFSET, KASAN_SHADOW_END) cover all 64-bits of virtual + * addresses. So KASAN_SHADOW_OFFSET should satisfy the following equation: + * KASAN_SHADOW_OFFSET = KASAN_SHADOW_END - + * (1ULL << (64 - KASAN_SHADOW_SCALE_SHIFT)) + */ #define KASAN_SHADOW_SCALE_SHIFT 3 -#define KASAN_SHADOW_SIZE (UL(1) << (38 - KASAN_SHADOW_SCALE_SHIFT)) -#define KASAN_SHADOW_START KERN_VIRT_START /* 2^64 - 2^38 */ +#define KASAN_SHADOW_SIZE (UL(1) << ((CONFIG_VA_BITS - 1) - KASAN_SHADOW_SCALE_SHIFT)) +#define KASAN_SHADOW_START KERN_VIRT_START #define KASAN_SHADOW_END (KASAN_SHADOW_START + KASAN_SHADOW_SIZE) - #define KASAN_SHADOW_OFFSET (KASAN_SHADOW_END - (1ULL << \ (64 - KASAN_SHADOW_SCALE_SHIFT))) -- 2.20.1