From nobody Thu Feb 8 16:36:33 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TW2gQ3QVNz5B0VH; Thu, 8 Feb 2024 16:36:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TW2gQ1WGqz4N8T; Thu, 8 Feb 2024 16:36:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707410194; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mptK5UCZfNvWV9XP8cxJStaKjc2tmrtwTn5UhISWywo=; b=mEK19BYSpFvU6VrZNLNHDOO5+Iv494lQEHOYupVBuo8ycDdzq3YnrE+PkU9ebvJuShi/xt RixDrgu7bETY3TjltJCtue8vBcP2qz5aJEpwLLTts0ZHL/vNs0ydQr5kYEAa/w696jPuu5 eb334CCi5IY+24qM+u4naO3nTA1p+8L6UwT+nv4lDy8Hw/EeELFVVOJO4ZvovxVsSpjCKR sGSveS/hV/UX1USp1DXwTAf8H4kDWNTUHy1bvkXa+dO3pNFVgO1Wn7VvSa4o5Cxbsl4vJ6 bBlb7HsJfvOSEGUnAX8/U/H+rTjzIuke3S/Ri9G6Lji4Rx6N+mPHYd355OD/lQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707410194; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mptK5UCZfNvWV9XP8cxJStaKjc2tmrtwTn5UhISWywo=; b=eVCQeAkN9Lc9pFK7Siy5UuSXrC62nrKKCImzEav+EFd8cfZYQy2Tqf0yorSWDmMhgSPOaV +LH7zTDYuexaIKMTYIKJFGKyd2+Z+nDP6j79iAMoGJivg9B0C7Ke0CjJkKk0Ejn0pIvn1H qk/Rfy4kNdjuxnEQZbLVPLaaPMICMCP8QRstK/mTw8N6vvqdNiey/mXsljseCtL66c/90l kLmdcR+XWjn+7DXBODDeKjkj0gUajByHCS3t1J2G5V7V6Bzs1tIGDrw0ixEXMqlyhk8Vgi ZZBW43g3eUrbS371+e+IS08hJ8GBo3eIzMPOUDDCYzaX0OIUIEKtuGthk/tNJg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1707410194; a=rsa-sha256; cv=none; b=ZtaEx/awT6A5T+1DMdi0iAiLwPmmFLEP0mooUjtU85hlvg4s73wuSdtnRqN/riJZcK/p0/ FANZT/4Z28xuWOkxYdBa0dnQU6qKIyp9Do8GX4RXVPmWzcKg84ChBz/b9QhDhLcUq98+oB 0qd+bqkxMlPvdydL8wrVFIubEJax81xC29YJLxKdIyC6KMoJks+7snyLiEwsvlPyWgYMKn mIScLbkv4RA2Vr+gYFWEaJu/ar2XTr8g1t/9HSdDBEfkfoUzSakZmJD0MF3f8IElNS7crO jvySX622L7cUZYWGdwYSJKHiSK78+S6GaxMBiWNILwePb3eR57o/Y2OHTQDDww== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TW2gQ0dSczxFC; Thu, 8 Feb 2024 16:36:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 418GaXch020774; Thu, 8 Feb 2024 16:36:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 418GaXmt020771; Thu, 8 Feb 2024 16:36:33 GMT (envelope-from git) Date: Thu, 8 Feb 2024 16:36:33 GMT Message-Id: <202402081636.418GaXmt020771@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 90010126b03b - main - arm64: Add msan.h List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 90010126b03b098edc70a5a0e63c1c0a65cd47fb Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=90010126b03b098edc70a5a0e63c1c0a65cd47fb commit 90010126b03b098edc70a5a0e63c1c0a65cd47fb Author: Mark Johnston AuthorDate: 2024-02-08 16:00:40 +0000 Commit: Mark Johnston CommitDate: 2024-02-08 16:35:11 +0000 arm64: Add msan.h This is mostly a copy of amd64's msan.h, except that we currently do not avoid shadowing the kernel itself, and we need a more restrictive upper bound in kmsan_md_unsupported() to avoid probing non-existent shadow mappings of device mappings. Reviewed by: imp MFC after: 2 weeks Sponsored by: Klara, Inc. Sponsored by: Juniper Networks, Inc. Differential Revision: https://reviews.freebsd.org/D43156 --- sys/arm64/include/msan.h | 91 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/sys/arm64/include/msan.h b/sys/arm64/include/msan.h new file mode 100644 index 000000000000..48be55af44b6 --- /dev/null +++ b/sys/arm64/include/msan.h @@ -0,0 +1,91 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2021 The FreeBSD Foundation + * Copyright (c) 2023 Juniper Networks, Inc. + * + * This software was developed by Mark Johnston under sponsorship from the + * FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _MACHINE_MSAN_H_ +#define _MACHINE_MSAN_H_ + +#ifdef KMSAN + +#include +#include +#include +#include + +typedef uint32_t msan_orig_t; + +/* + * Our 32-bit origin cells encode a 2-bit type and 30-bit pointer to a kernel + * instruction. The pointer is compressed by making it a positive offset + * relative to KERNBASE. + */ +#define KMSAN_ORIG_TYPE_SHIFT 30u +#define KMSAN_ORIG_PTR_MASK ((1ul << KMSAN_ORIG_TYPE_SHIFT) - 1) + +static inline msan_orig_t +kmsan_md_orig_encode(int type, uintptr_t ptr) +{ + return ((type << KMSAN_ORIG_TYPE_SHIFT) | + ((ptr & KMSAN_ORIG_PTR_MASK))); +} + +static inline void +kmsan_md_orig_decode(msan_orig_t orig, int *type, uintptr_t *ptr) +{ + *type = orig >> KMSAN_ORIG_TYPE_SHIFT; + *ptr = (orig & KMSAN_ORIG_PTR_MASK) | KERNBASE; +} + +static inline vm_offset_t +kmsan_md_addr_to_shad(vm_offset_t addr) +{ + return (addr - VM_MIN_KERNEL_ADDRESS + KMSAN_SHAD_MIN_ADDRESS); +} + +static inline vm_offset_t +kmsan_md_addr_to_orig(vm_offset_t addr) +{ + return (addr - VM_MIN_KERNEL_ADDRESS + KMSAN_ORIG_MIN_ADDRESS); +} + +static inline bool +kmsan_md_unsupported(vm_offset_t addr) +{ + /* + * It would be cheaper to use VM_MAX_KERNEL_ADDRESS as the upper bound, + * but we need to exclude device mappings above kernel_vm_end but within + * the kernel map. + */ + return (addr < VM_MIN_KERNEL_ADDRESS || addr >= kernel_vm_end); +} + +#endif /* KMSAN */ + +#endif /* !_MACHINE_MSAN_H_ */