/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2021 The FreeBSD Foundation4*5* This software was developed by Mark Johnston under sponsorship from the6* FreeBSD Foundation.7*8* Redistribution and use in source and binary forms, with or without9* modification, are permitted provided that the following conditions are10* met:11* 1. Redistributions of source code must retain the above copyright12* notice, this list of conditions and the following disclaimer.13* 2. Redistributions in binary form must reproduce the above copyright14* notice, this list of conditions and the following disclaimer in15* the documentation and/or other materials provided with the distribution.16*17* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND18* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE19* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE20* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE21* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL22* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS23* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)24* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT25* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY26* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF27* SUCH DAMAGE.28*/2930#ifndef _MACHINE_MSAN_H_31#define _MACHINE_MSAN_H_3233#ifdef KMSAN3435#include <vm/vm.h>36#include <vm/pmap.h>37#include <vm/vm_page.h>38#include <machine/vmparam.h>3940typedef uint32_t msan_orig_t;4142/*43* Our 32-bit origin cells encode a 2-bit type and 30-bit pointer to a kernel44* instruction. The pointer is compressed by making it a positive offset45* relative to KERNBASE.46*/47#define KMSAN_ORIG_TYPE_SHIFT 30u48#define KMSAN_ORIG_PTR_MASK ((1u << KMSAN_ORIG_TYPE_SHIFT) - 1)4950static inline msan_orig_t51kmsan_md_orig_encode(int type, uintptr_t ptr)52{53return ((type << KMSAN_ORIG_TYPE_SHIFT) |54((ptr & KMSAN_ORIG_PTR_MASK)));55}5657static inline void58kmsan_md_orig_decode(msan_orig_t orig, int *type, uintptr_t *ptr)59{60*type = orig >> KMSAN_ORIG_TYPE_SHIFT;61*ptr = (orig & KMSAN_ORIG_PTR_MASK) | KERNBASE;62}6364static inline vm_offset_t65kmsan_md_addr_to_shad(vm_offset_t addr)66{67return (addr - VM_MIN_KERNEL_ADDRESS + KMSAN_SHAD_MIN_ADDRESS);68}6970static inline vm_offset_t71kmsan_md_addr_to_orig(vm_offset_t addr)72{73return (addr - VM_MIN_KERNEL_ADDRESS + KMSAN_ORIG_MIN_ADDRESS);74}7576static inline bool77kmsan_md_unsupported(vm_offset_t addr)78{79/*80* The kernel itself isn't shadowed: for most purposes global variables81* are always initialized, and because KMSAN kernels are large82* (GENERIC-KMSAN is ~80MB at the time of writing), shadowing would83* incur significant memory usage.84*/85return (addr < VM_MIN_KERNEL_ADDRESS || addr >= KERNBASE);86}8788#endif /* KMSAN */8990#endif /* !_MACHINE_MSAN_H_ */919293