2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2021 The FreeBSD Foundation
5 * Copyright (c) 2023 Juniper Networks, Inc.
7 * This software was developed by Mark Johnston under sponsorship from the
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #ifndef _MACHINE_MSAN_H_
33 #define _MACHINE_MSAN_H_
39 #include <vm/vm_page.h>
40 #include <machine/vmparam.h>
42 typedef uint32_t msan_orig_t;
45 * Our 32-bit origin cells encode a 2-bit type and 30-bit pointer to a kernel
46 * instruction. The pointer is compressed by making it a positive offset
47 * relative to KERNBASE.
49 #define KMSAN_ORIG_TYPE_SHIFT 30u
50 #define KMSAN_ORIG_PTR_MASK ((1ul << KMSAN_ORIG_TYPE_SHIFT) - 1)
52 static inline msan_orig_t
53 kmsan_md_orig_encode(int type, uintptr_t ptr)
55 return ((type << KMSAN_ORIG_TYPE_SHIFT) |
56 ((ptr & KMSAN_ORIG_PTR_MASK)));
60 kmsan_md_orig_decode(msan_orig_t orig, int *type, uintptr_t *ptr)
62 *type = orig >> KMSAN_ORIG_TYPE_SHIFT;
63 *ptr = (orig & KMSAN_ORIG_PTR_MASK) | KERNBASE;
66 static inline vm_offset_t
67 kmsan_md_addr_to_shad(vm_offset_t addr)
69 return (addr - VM_MIN_KERNEL_ADDRESS + KMSAN_SHAD_MIN_ADDRESS);
72 static inline vm_offset_t
73 kmsan_md_addr_to_orig(vm_offset_t addr)
75 return (addr - VM_MIN_KERNEL_ADDRESS + KMSAN_ORIG_MIN_ADDRESS);
79 kmsan_md_unsupported(vm_offset_t addr)
82 * It would be cheaper to use VM_MAX_KERNEL_ADDRESS as the upper bound,
83 * but we need to exclude device mappings above kernel_vm_end but within
86 return (addr < VM_MIN_KERNEL_ADDRESS || addr >= kernel_vm_end);
91 #endif /* !_MACHINE_MSAN_H_ */