diff mbox series

[v3,19/39] kasan: rename SHADOW layout macros to META

Message ID cac8b9713e5d3ac1ab767a9cc42c61b04c46bdfc.1600987622.git.andreyknvl@google.com (mailing list archive)
State New, archived
Headers show
Series kasan: add hardware tag-based mode for arm64 | expand

Commit Message

Andrey Konovalov Sept. 24, 2020, 10:50 p.m. UTC
This is a preparatory commit for the upcoming addition of a new hardware
tag-based (MTE-based) KASAN mode.

Hardware tag-based KASAN won't be using shadow memory, but will reuse
these macros. Rename "SHADOW" to implementation-neutral "META".

No functional changes.

Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
Signed-off-by: Vincenzo Frascino <vincenzo.frascino@arm.com>
---
Change-Id: Id2d836bf43b401bce1221cc06e745185f17b1cc
---
 mm/kasan/report.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

Comments

Marco Elver Oct. 1, 2020, 5:48 p.m. UTC | #1
On Fri, Sep 25, 2020 at 12:50AM +0200, Andrey Konovalov wrote:
> This is a preparatory commit for the upcoming addition of a new hardware
> tag-based (MTE-based) KASAN mode.
> 
> Hardware tag-based KASAN won't be using shadow memory, but will reuse
> these macros. Rename "SHADOW" to implementation-neutral "META".
> 
> No functional changes.
> 
> Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
> Signed-off-by: Vincenzo Frascino <vincenzo.frascino@arm.com>

Reviewed-by: Marco Elver <elver@google.com>

> ---
> Change-Id: Id2d836bf43b401bce1221cc06e745185f17b1cc
> ---
>  mm/kasan/report.c | 30 +++++++++++++++---------------
>  1 file changed, 15 insertions(+), 15 deletions(-)
> 
> diff --git a/mm/kasan/report.c b/mm/kasan/report.c
> index 67aa30b45805..13b27675a696 100644
> --- a/mm/kasan/report.c
> +++ b/mm/kasan/report.c
> @@ -31,11 +31,11 @@
>  #include "kasan.h"
>  #include "../slab.h"
>  
> -/* Shadow layout customization. */
> -#define SHADOW_BYTES_PER_BLOCK 1
> -#define SHADOW_BLOCKS_PER_ROW 16
> -#define SHADOW_BYTES_PER_ROW (SHADOW_BLOCKS_PER_ROW * SHADOW_BYTES_PER_BLOCK)
> -#define SHADOW_ROWS_AROUND_ADDR 2
> +/* Metadata layout customization. */
> +#define META_BYTES_PER_BLOCK 1
> +#define META_BLOCKS_PER_ROW 16
> +#define META_BYTES_PER_ROW (META_BLOCKS_PER_ROW * META_BYTES_PER_BLOCK)
> +#define META_ROWS_AROUND_ADDR 2
>  
>  static unsigned long kasan_flags;
>  
> @@ -238,7 +238,7 @@ static void print_address_description(void *addr, u8 tag)
>  
>  static bool row_is_guilty(const void *row, const void *guilty)
>  {
> -	return (row <= guilty) && (guilty < row + SHADOW_BYTES_PER_ROW);
> +	return (row <= guilty) && (guilty < row + META_BYTES_PER_ROW);
>  }
>  
>  static int shadow_pointer_offset(const void *row, const void *shadow)
> @@ -247,7 +247,7 @@ static int shadow_pointer_offset(const void *row, const void *shadow)
>  	 *    3 + (BITS_PER_LONG/8)*2 chars.
>  	 */
>  	return 3 + (BITS_PER_LONG/8)*2 + (shadow - row)*2 +
> -		(shadow - row) / SHADOW_BYTES_PER_BLOCK + 1;
> +		(shadow - row) / META_BYTES_PER_BLOCK + 1;
>  }
>  
>  static void print_memory_metadata(const void *addr)
> @@ -257,15 +257,15 @@ static void print_memory_metadata(const void *addr)
>  	const void *shadow_row;
>  
>  	shadow_row = (void *)round_down((unsigned long)shadow,
> -					SHADOW_BYTES_PER_ROW)
> -		- SHADOW_ROWS_AROUND_ADDR * SHADOW_BYTES_PER_ROW;
> +					META_BYTES_PER_ROW)
> +		- META_ROWS_AROUND_ADDR * META_BYTES_PER_ROW;
>  
>  	pr_err("Memory state around the buggy address:\n");
>  
> -	for (i = -SHADOW_ROWS_AROUND_ADDR; i <= SHADOW_ROWS_AROUND_ADDR; i++) {
> +	for (i = -META_ROWS_AROUND_ADDR; i <= META_ROWS_AROUND_ADDR; i++) {
>  		const void *kaddr = kasan_shadow_to_mem(shadow_row);
>  		char buffer[4 + (BITS_PER_LONG/8)*2];
> -		char shadow_buf[SHADOW_BYTES_PER_ROW];
> +		char shadow_buf[META_BYTES_PER_ROW];
>  
>  		snprintf(buffer, sizeof(buffer),
>  			(i == 0) ? ">%px: " : " %px: ", kaddr);
> @@ -274,17 +274,17 @@ static void print_memory_metadata(const void *addr)
>  		 * function, because generic functions may try to
>  		 * access kasan mapping for the passed address.
>  		 */
> -		memcpy(shadow_buf, shadow_row, SHADOW_BYTES_PER_ROW);
> +		memcpy(shadow_buf, shadow_row, META_BYTES_PER_ROW);
>  		print_hex_dump(KERN_ERR, buffer,
> -			DUMP_PREFIX_NONE, SHADOW_BYTES_PER_ROW, 1,
> -			shadow_buf, SHADOW_BYTES_PER_ROW, 0);
> +			DUMP_PREFIX_NONE, META_BYTES_PER_ROW, 1,
> +			shadow_buf, META_BYTES_PER_ROW, 0);
>  
>  		if (row_is_guilty(shadow_row, shadow))
>  			pr_err("%*c\n",
>  				shadow_pointer_offset(shadow_row, shadow),
>  				'^');
>  
> -		shadow_row += SHADOW_BYTES_PER_ROW;
> +		shadow_row += META_BYTES_PER_ROW;
>  	}
>  }
>  
> -- 
> 2.28.0.681.g6f77f65b4e-goog
>
diff mbox series

Patch

diff --git a/mm/kasan/report.c b/mm/kasan/report.c
index 67aa30b45805..13b27675a696 100644
--- a/mm/kasan/report.c
+++ b/mm/kasan/report.c
@@ -31,11 +31,11 @@ 
 #include "kasan.h"
 #include "../slab.h"
 
-/* Shadow layout customization. */
-#define SHADOW_BYTES_PER_BLOCK 1
-#define SHADOW_BLOCKS_PER_ROW 16
-#define SHADOW_BYTES_PER_ROW (SHADOW_BLOCKS_PER_ROW * SHADOW_BYTES_PER_BLOCK)
-#define SHADOW_ROWS_AROUND_ADDR 2
+/* Metadata layout customization. */
+#define META_BYTES_PER_BLOCK 1
+#define META_BLOCKS_PER_ROW 16
+#define META_BYTES_PER_ROW (META_BLOCKS_PER_ROW * META_BYTES_PER_BLOCK)
+#define META_ROWS_AROUND_ADDR 2
 
 static unsigned long kasan_flags;
 
@@ -238,7 +238,7 @@  static void print_address_description(void *addr, u8 tag)
 
 static bool row_is_guilty(const void *row, const void *guilty)
 {
-	return (row <= guilty) && (guilty < row + SHADOW_BYTES_PER_ROW);
+	return (row <= guilty) && (guilty < row + META_BYTES_PER_ROW);
 }
 
 static int shadow_pointer_offset(const void *row, const void *shadow)
@@ -247,7 +247,7 @@  static int shadow_pointer_offset(const void *row, const void *shadow)
 	 *    3 + (BITS_PER_LONG/8)*2 chars.
 	 */
 	return 3 + (BITS_PER_LONG/8)*2 + (shadow - row)*2 +
-		(shadow - row) / SHADOW_BYTES_PER_BLOCK + 1;
+		(shadow - row) / META_BYTES_PER_BLOCK + 1;
 }
 
 static void print_memory_metadata(const void *addr)
@@ -257,15 +257,15 @@  static void print_memory_metadata(const void *addr)
 	const void *shadow_row;
 
 	shadow_row = (void *)round_down((unsigned long)shadow,
-					SHADOW_BYTES_PER_ROW)
-		- SHADOW_ROWS_AROUND_ADDR * SHADOW_BYTES_PER_ROW;
+					META_BYTES_PER_ROW)
+		- META_ROWS_AROUND_ADDR * META_BYTES_PER_ROW;
 
 	pr_err("Memory state around the buggy address:\n");
 
-	for (i = -SHADOW_ROWS_AROUND_ADDR; i <= SHADOW_ROWS_AROUND_ADDR; i++) {
+	for (i = -META_ROWS_AROUND_ADDR; i <= META_ROWS_AROUND_ADDR; i++) {
 		const void *kaddr = kasan_shadow_to_mem(shadow_row);
 		char buffer[4 + (BITS_PER_LONG/8)*2];
-		char shadow_buf[SHADOW_BYTES_PER_ROW];
+		char shadow_buf[META_BYTES_PER_ROW];
 
 		snprintf(buffer, sizeof(buffer),
 			(i == 0) ? ">%px: " : " %px: ", kaddr);
@@ -274,17 +274,17 @@  static void print_memory_metadata(const void *addr)
 		 * function, because generic functions may try to
 		 * access kasan mapping for the passed address.
 		 */
-		memcpy(shadow_buf, shadow_row, SHADOW_BYTES_PER_ROW);
+		memcpy(shadow_buf, shadow_row, META_BYTES_PER_ROW);
 		print_hex_dump(KERN_ERR, buffer,
-			DUMP_PREFIX_NONE, SHADOW_BYTES_PER_ROW, 1,
-			shadow_buf, SHADOW_BYTES_PER_ROW, 0);
+			DUMP_PREFIX_NONE, META_BYTES_PER_ROW, 1,
+			shadow_buf, META_BYTES_PER_ROW, 0);
 
 		if (row_is_guilty(shadow_row, shadow))
 			pr_err("%*c\n",
 				shadow_pointer_offset(shadow_row, shadow),
 				'^');
 
-		shadow_row += SHADOW_BYTES_PER_ROW;
+		shadow_row += META_BYTES_PER_ROW;
 	}
 }