From nobody Tue May 23 13:59:11 2023 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 4QQbXH34nKz4CWMf; Tue, 23 May 2023 13:59:11 +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 4QQbXH2XG5z40jQ; Tue, 23 May 2023 13:59:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1684850351; 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=Qdpj660ds/sqyfTDKU4+dTX1SfpaNLAjPVwwc2rfUMM=; b=b/o8C7ZQz6PwhKo0XnxsSMSvOghg/EcjV6/2fhFNngtSSG2sI4SwurMGM1e/m1IvYKSzmD 1HbHjskd2tSTDX+XIh9zd0dSQ4DiRPz6L1m+oEar+Sh5NoBVSWBpcg0infQkjzN6ahHBUg uzds5GvyPQTsYkcyxm+dnoDFUaazjHLzJIzb+CkyoX3nAtaEjWTttHF0TDelTgOgJwnco8 5D6XZ8An7urTZN/qbYzszO8z21V8vPmaS1GQ94yoU7qE0ulcZ1cDwgAWoI96VQWXH/GL7U yzBoUejs4xRBD4LEguS6K6Z9KBkTuZY7yiIaVZ0OZegpwylTRH/uFLkurcxbZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1684850351; 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=Qdpj660ds/sqyfTDKU4+dTX1SfpaNLAjPVwwc2rfUMM=; b=AhtIxDdvIQhp9Q970JcAmz+4pBCSYO77cVrj0X5riX4NdQOcR0+PfZZmmIhPzSB+bDqO0W +O/4HNCowNBisDIpjRxdegHbO9IUrAL/qbn/JlOm/M51A+XVaJ5Y9QKwR3tHMmyTgbGXKo H3rI6TfPfAnyqB2uajnQE9B7W17WkUWSOM6uJzTw/FUKFQbXlfMz7xKPYkegP8V6+BBdXt W4yTjYncE+5w4pvvSii5PZsd+g+9EXhLz7fqWvbM6vPWflJzLDdt/viD8TTETXDT1xUgNM 4HACLCsdTUzpzV36krsC/EQ1bpy+41Bcu3x+oSrsITXd9BjXsCq1op98UVdBYQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1684850351; a=rsa-sha256; cv=none; b=sHGjJhopDMCndMWfcGkxfPmjfVCVg698tkNOamKxV9oorEH+3CelEOlJqyassir+7o3vhC gm9yGRHv+ncQrnfcYhL1UgLqoPktimZgAMD/7zoZVS335idpJAqKVoOYLH9BWLMiEskoHZ G/5pyg3UQ5m1kjjqHPlmEWxjIjkor9klWRshrjGwhFRe1mFVKpnQtH5yA1gSaZahU7PuU6 +w/sNW6vG0lEWNraaF9ZXEpYkjSkRn/C/1PyOMPa7W0CmdWjndRqwyFR9NM+m0xP5ujdFz TznRbRUZR/DznMyglOTxcaupVlVAh2nESDG2yhznspJcnRU/EPLnf86gOi+nDg== 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 4QQbXH1cV4z12w8; Tue, 23 May 2023 13:59:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 34NDxBmP065804; Tue, 23 May 2023 13:59:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 34NDxBb7065803; Tue, 23 May 2023 13:59:11 GMT (envelope-from git) Date: Tue, 23 May 2023 13:59:11 GMT Message-Id: <202305231359.34NDxBb7065803@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Christos Margiolis Subject: git: ecca3180855a - main - kinst: replace KINST_TRAMP_INIT 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: christos X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ecca3180855a2aa7eb394706c7ae69d9c67b87b5 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=ecca3180855a2aa7eb394706c7ae69d9c67b87b5 commit ecca3180855a2aa7eb394706c7ae69d9c67b87b5 Author: Christos Margiolis AuthorDate: 2023-05-23 13:58:36 +0000 Commit: Christos Margiolis CommitDate: 2023-05-23 13:58:36 +0000 kinst: replace KINST_TRAMP_INIT The current implementation of KINST_TRAMP_INIT is working only on amd64, where the breakpoint instruction is one byte long, which might not be the case for other architectures (e.g in RISC-V it's either 2 or 4 bytes). This patch introduces two machine-dependent constants, KINST_TRAMP_FILL_PATTERN and KINST_TRAMP_FILL_SIZE, which hold the fill instruction and the size of that instruction in bytes respectively. Reviewed by: markj Approved by: markj (mentor) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D39504 --- sys/cddl/dev/kinst/amd64/kinst_isa.h | 12 ++++-------- sys/cddl/dev/kinst/trampoline.c | 22 +++++++++++++++++----- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/sys/cddl/dev/kinst/amd64/kinst_isa.h b/sys/cddl/dev/kinst/amd64/kinst_isa.h index 4c6387b8cb50..eb4f79c4c726 100644 --- a/sys/cddl/dev/kinst/amd64/kinst_isa.h +++ b/sys/cddl/dev/kinst/amd64/kinst_isa.h @@ -17,14 +17,10 @@ * have 2 instructions stored in the trampoline, and each of them can take up * to 16 bytes, 32 bytes is enough to cover even the worst case scenario. */ -#define KINST_TRAMP_SIZE 32 -#define KINST_TRAMPCHUNK_SIZE PAGE_SIZE - -/* - * Fill the trampolines with breakpoint instructions so that the kernel will - * crash cleanly if things somehow go wrong. - */ -#define KINST_TRAMP_INIT(t, s) memset((t), KINST_PATCHVAL, (s)) +#define KINST_TRAMP_SIZE 32 +#define KINST_TRAMPCHUNK_SIZE PAGE_SIZE +#define KINST_TRAMP_FILL_PATTERN ((uint8_t []){KINST_PATCHVAL}) +#define KINST_TRAMP_FILL_SIZE sizeof(uint8_t) typedef uint8_t kinst_patchval_t; diff --git a/sys/cddl/dev/kinst/trampoline.c b/sys/cddl/dev/kinst/trampoline.c index 6614a6ed9302..5575503f60fb 100644 --- a/sys/cddl/dev/kinst/trampoline.c +++ b/sys/cddl/dev/kinst/trampoline.c @@ -28,9 +28,6 @@ #include "kinst.h" #include "kinst_isa.h" -/* - * We can have 4KB/32B = 128 trampolines per chunk. - */ #define KINST_TRAMPS_PER_CHUNK (KINST_TRAMPCHUNK_SIZE / KINST_TRAMP_SIZE) struct trampchunk { @@ -47,6 +44,21 @@ SX_SYSINIT(kinst_tramp_sx, &kinst_tramp_sx, "kinst tramp"); static eventhandler_tag kinst_thread_ctor_handler; static eventhandler_tag kinst_thread_dtor_handler; +/* + * Fill the trampolines with KINST_TRAMP_FILL_PATTERN so that the kernel will + * crash cleanly if things somehow go wrong. + */ +static void +kinst_trampoline_fill(uint8_t *addr, int size) +{ + int i; + + for (i = 0; i < size; i += KINST_TRAMP_FILL_SIZE) { + memcpy(&addr[i], KINST_TRAMP_FILL_PATTERN, + KINST_TRAMP_FILL_SIZE); + } +} + static struct trampchunk * kinst_trampchunk_alloc(void) { @@ -77,7 +89,7 @@ kinst_trampchunk_alloc(void) M_WAITOK | M_EXEC); KASSERT(error == KERN_SUCCESS, ("kmem_back failed: %d", error)); - KINST_TRAMP_INIT((void *)trampaddr, KINST_TRAMPCHUNK_SIZE); + kinst_trampoline_fill((uint8_t *)trampaddr, KINST_TRAMPCHUNK_SIZE); /* Allocate a tracker for this chunk. */ chunk = malloc(sizeof(*chunk), M_KINST, M_WAITOK); @@ -171,7 +183,7 @@ kinst_trampoline_dealloc_locked(uint8_t *tramp, bool freechunks) TAILQ_FOREACH(chunk, &kinst_trampchunks, next) { for (off = 0; off < KINST_TRAMPS_PER_CHUNK; off++) { if (chunk->addr + off * KINST_TRAMP_SIZE == tramp) { - KINST_TRAMP_INIT(tramp, KINST_TRAMP_SIZE); + kinst_trampoline_fill(tramp, KINST_TRAMP_SIZE); BIT_SET(KINST_TRAMPS_PER_CHUNK, off, &chunk->free); if (freechunks &&