Merge tag 'xfs-5.20-merge-6' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
[linux-2.6-microblaze.git] / mm / kasan / report_hw_tags.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * This file contains hardware tag-based KASAN specific error reporting code.
4  *
5  * Copyright (c) 2020 Google, Inc.
6  * Author: Andrey Konovalov <andreyknvl@google.com>
7  */
8
9 #include <linux/kasan.h>
10 #include <linux/kernel.h>
11 #include <linux/memory.h>
12 #include <linux/mm.h>
13 #include <linux/string.h>
14 #include <linux/types.h>
15
16 #include "kasan.h"
17
18 void *kasan_find_first_bad_addr(void *addr, size_t size)
19 {
20         /* Return the same value regardless of whether addr_has_metadata(). */
21         return kasan_reset_tag(addr);
22 }
23
24 void kasan_metadata_fetch_row(char *buffer, void *row)
25 {
26         int i;
27
28         for (i = 0; i < META_BYTES_PER_ROW; i++)
29                 buffer[i] = hw_get_mem_tag(row + i * KASAN_GRANULE_SIZE);
30 }
31
32 void kasan_print_tags(u8 addr_tag, const void *addr)
33 {
34         u8 memory_tag = hw_get_mem_tag((void *)addr);
35
36         pr_err("Pointer tag: [%02x], memory tag: [%02x]\n",
37                 addr_tag, memory_tag);
38 }