From nobody Thu May 11 18:23:43 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 4QHKz33BNWz49ZdD; Thu, 11 May 2023 18:23:43 +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 4QHKz32XNFz3Q1p; Thu, 11 May 2023 18:23:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1683829423; 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=5MKX+ztBH3wc4BVv4MYKpmK/IVL2b3hL84GEVZx30rw=; b=lWs2liKXlizeT8MjECrDICZFDNHQvhpoSDQ/3OHFtky6h4SDhrbH3EZToV2BG6kyVc9gZO /0w2rqyWW8VsdbMIQbuEERkgwR32NDX6gAQyzXIHxHw3VqlpdJw/kGizPUeTr94HIz+pmD euJjkqjAYZvBGYLwH5v6n4+dZjFMqdzNrdcjkM1bCREQ+mHN+m4MCcR6zsvvY+qbbPCuRK pbzsnEwbgii6h8Vs9cByo++37mz23cS5QO8RXzOjPWp8z7JjuwryyMmifoxxXSPlxW2zz5 TV95lvUghzSPJtVUZqx7rROtlzblHnsLBTNN6XIzX0snoOZNS8ouqWxwcZodwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1683829423; 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=5MKX+ztBH3wc4BVv4MYKpmK/IVL2b3hL84GEVZx30rw=; b=neyqhoQgGiktfuq4zVT2tLp1tvCDoXbl3NuF9FCoRXDOnt6V3/ZL4eW55EIBNAwfhev73O 5A0DzJP1HfOpIWq1Vf6zn+/PwaVDSYpMquiTb4UBfiFkDw212iXHGlyoSMTH+zmYg1LV7m jocITCLkqzdD25Ju0dPoCbM80Etj74brUVlsNU2oQli6xtDQqhkkKFbxX2rFDAkW4nlpG6 p4/99/0jc91AD2/je+KdcvGzNMWFMPEqqiaZEEBZ5Z/XZFIZo1qt5qUHxc5NPJhE5yNrtx TtZlmYyLL2IR8I/VBCSydqrZZCwC61QQNDFRNYF0bS4Ngw8l4WkUdLw4RK1nKQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1683829423; a=rsa-sha256; cv=none; b=mLEITz6XelZP+dpbvP032Q939iy7QZ1F3M1XfTtno7nfPBUY88RvP2DGQao61rqYLfMGwm 6BKzSx7Aaemk8IA9BJMQubZQ18028b/7W2bRNHwNtgap22tOZE0RL11PABfWnpK3wvfjAM hnS4pswhITCK/MLH5jBnjUpGGpDV3N8Rd9qbNsOctnFylIEcBjZlsnGsq/fRIM2C9Q1NnR tmRUWu4UnVWDPsnIY5aqsqKZtbsytZSxeCP6ZgkUQ3OKtyHW2V97QZ/Es9frEwsyeHfBcK 0etVbRfSZ13HA05geyxOHNEMHjFXO7uZPenh0bXAeo5E3pOAtuazo7SjQW4hLQ== 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 4QHKz31cc8z13JN; Thu, 11 May 2023 18:23:43 +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 34BINhpo054798; Thu, 11 May 2023 18:23:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 34BINh7o054797; Thu, 11 May 2023 18:23:43 GMT (envelope-from git) Date: Thu, 11 May 2023 18:23:43 GMT Message-Id: <202305111823.34BINh7o054797@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: 86c31aca33ff - main - arm64: add swapueword8/32 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: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 86c31aca33ff771b845acbbed3b3659fde7e710f Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=86c31aca33ff771b845acbbed3b3659fde7e710f commit 86c31aca33ff771b845acbbed3b3659fde7e710f Author: Kyle Evans AuthorDate: 2023-05-11 18:23:03 +0000 Commit: Kyle Evans CommitDate: 2023-05-11 18:23:14 +0000 arm64: add swapueword8/32 Much like casueword*, except just a plain old swap. Maintains a similar interface to casu(9)- return value -1 (fault), 0 (success), or 1 (fail), and also both ll/sc and LSE variants are implemented. These will be used to implement 32-bit swp/swpb emulation on aarch64. Reveiwed by: andrew Sponsored by: Stormshield Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D39837 --- sys/arm64/arm64/support.S | 92 +++++++++++++++++++++++++++++++++++++++++ sys/arm64/arm64/support_ifunc.c | 24 +++++++++++ sys/arm64/include/md_var.h | 11 +++++ 3 files changed, 127 insertions(+) diff --git a/sys/arm64/arm64/support.S b/sys/arm64/arm64/support.S index 28ac1d553fbc..f7e9abcd910c 100644 --- a/sys/arm64/arm64/support.S +++ b/sys/arm64/arm64/support.S @@ -55,6 +55,98 @@ fsu_fault_nopcb: ret END(fsu_fault) +/* + * int swapueword8_llsc(volatile uint8_t *, uint8_t *) + */ +ENTRY(swapueword8_llsc) + check_user_access 0, (VM_MAXUSER_ADDRESS-3), fsu_fault_nopcb + adr x6, fsu_fault /* Load the fault handler */ + SET_FAULT_HANDLER(x6, x4) /* And set it */ + ENTER_USER_ACCESS(w6, x4) + + ldrb w7, [x1] + + ldxrb w2, [x0] + stxrb w3, w7, [x0] + cbnz w3, 1f + + strb w2, [x1] /* Stash old value in *val */ + +1: EXIT_USER_ACCESS(w6) + SET_FAULT_HANDLER(xzr, x6) + mov w0, w3 + ret +END(swapueword8_llsc) + +/* + * int swapueword8_lse(volatile uint8_t *, uint8_t *) + */ +ENTRY(swapueword8_lse) + check_user_access 0, (VM_MAXUSER_ADDRESS-3), fsu_fault_nopcb + adr x6, fsu_fault /* Load the fault handler */ + SET_FAULT_HANDLER(x6, x4) /* And set it */ + ENTER_USER_ACCESS(w6, x4) + + ldrb w7, [x1] + + .arch_extension lse + swpb w7, w2, [x0] + .arch_extension nolse + + strb w2, [x1] /* Stash old value in *val */ + + EXIT_USER_ACCESS(w6) + SET_FAULT_HANDLER(xzr, x6) + mov w0, #0 + ret +END(swapueword8_lse) + +/* + * int swapueword32_llsc(volatile uint32_t *, uint32_t *) + */ +ENTRY(swapueword32_llsc) + check_user_access 0, (VM_MAXUSER_ADDRESS-3), fsu_fault_nopcb + adr x6, fsu_fault /* Load the fault handler */ + SET_FAULT_HANDLER(x6, x4) /* And set it */ + ENTER_USER_ACCESS(w6, x4) + + ldr w7, [x1] + + ldxr w2, [x0] /* Stash the old value in w2 */ + stxr w3, w7, [x0] /* Store new value */ + cbnz w3, 1f + + str w2, [x1] /* Stash old value in *val */ + +1: EXIT_USER_ACCESS(w6) + SET_FAULT_HANDLER(xzr, x6) + mov w0, w3 + ret +END(swapueword32_llsc) + +/* + * int swapueword32_lse(volatile uint32_t *, uint32_t *) + */ +ENTRY(swapueword32_lse) + check_user_access 0, (VM_MAXUSER_ADDRESS-3), fsu_fault_nopcb + adr x6, fsu_fault /* Load the fault handler */ + SET_FAULT_HANDLER(x6, x4) /* And set it */ + ENTER_USER_ACCESS(w6, x4) + + ldr w7, [x1] + + .arch_extension lse + swp w7, w2, [x0] + .arch_extension nolse + + str w2, [x1] /* Stash old value in *val */ + + EXIT_USER_ACCESS(w6) + SET_FAULT_HANDLER(xzr, x6) + mov w0, #0 + ret +END(swapueword32_llsc) + /* * int casueword32_llsc(volatile uint32_t *, uint32_t, uint32_t *, uint32_t) */ diff --git a/sys/arm64/arm64/support_ifunc.c b/sys/arm64/arm64/support_ifunc.c index 8abf3f3c75af..8cbe1c97b0a1 100644 --- a/sys/arm64/arm64/support_ifunc.c +++ b/sys/arm64/arm64/support_ifunc.c @@ -32,6 +32,8 @@ #include #include +#define _MD_WANT_SWAPWORD +#include int casueword32_llsc(volatile uint32_t *, uint32_t, uint32_t *, uint32_t); int casueword32_lse(volatile uint32_t *, uint32_t, uint32_t *, uint32_t); @@ -39,6 +41,12 @@ int casueword32_lse(volatile uint32_t *, uint32_t, uint32_t *, uint32_t); int casueword_llsc(volatile u_long *, u_long, u_long *, u_long); int casueword_lse(volatile u_long *, u_long, u_long *, u_long); +int swapueword8_llsc(volatile uint8_t *, uint8_t *); +int swapueword8_lse(volatile uint8_t *, uint8_t *); + +int swapueword32_llsc(volatile uint32_t *, uint32_t *); +int swapueword32_lse(volatile uint32_t *, uint32_t *); + DEFINE_IFUNC(, int, casueword32, (volatile uint32_t *base, uint32_t oldval, uint32_t *oldvalp, uint32_t newval)) { @@ -56,3 +64,19 @@ DEFINE_IFUNC(, int, casueword, (volatile u_long *base, u_long oldval, return (casueword_llsc); } + +DEFINE_IFUNC(, int, swapueword8, (volatile uint8_t *base, uint8_t *val)) +{ + if (lse_supported) + return (swapueword8_lse); + + return (swapueword8_llsc); +} + +DEFINE_IFUNC(, int, swapueword32, (volatile uint32_t *base, uint32_t *val)) +{ + if (lse_supported) + return (swapueword32_lse); + + return (swapueword32_llsc); +} diff --git a/sys/arm64/include/md_var.h b/sys/arm64/include/md_var.h index 6c78317c830c..d6c1b4ca2764 100644 --- a/sys/arm64/include/md_var.h +++ b/sys/arm64/include/md_var.h @@ -57,4 +57,15 @@ void generic_bs_poke_2(void) __asm(__STRING(generic_bs_poke_2)); void generic_bs_poke_4(void) __asm(__STRING(generic_bs_poke_4)); void generic_bs_poke_8(void) __asm(__STRING(generic_bs_poke_8)); +#ifdef _MD_WANT_SWAPWORD +/* + * XXX These are implemented primarily for swp/swpb emulation at the moment, and + * should be used sparingly with consideration -- they aren't implemented for + * any other platform. If we use them anywhere else, at a minimum they need + * KASAN/KMSAN interceptors added. + */ +int swapueword8(volatile uint8_t *base, uint8_t *val); +int swapueword32(volatile uint32_t *base, uint32_t *val); +#endif + #endif /* !_MACHINE_MD_VAR_H_ */