From nobody Fri Jun 17 19:40:31 2022 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 9AE9485D121; Fri, 17 Jun 2022 19:40: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 4LPqC46jsPz3hNX; Fri, 17 Jun 2022 19:40:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655494833; 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=XN52vy4/Sr4sTkb3iQZjqocMW/odrQfahnaL0WPjVjM=; b=mmNUWkaADmwDTkGQlWUT0nTIxh4v2BZMdKV9xQ1CMa3xh4R0UCPdnOZ3bmMdgmyN7CF2b6 /6M/juHaCBrgSO3vC0a3cFZyReSzXfb76LPQORR4Id6gK22DBukKsbER9VJYKQUGY98TBR Mui1wGwJU0hDMuALttREGhr/qUUqQeCYekP5Ktfo9OnkKMZE/to7p4Qz978sGqaQZekv4b zEVMrGDvk03NyPfFDqi9T/lx9jyGum3Vk3iKFjOXP2/wvShwYtmDNqEkp08kV9tLC5jGBk mCPhh0/hKqwQuJ8wPLrP3cni0WPTMIs91b6OtCnuDCeZM7IQ3udZzAH413swkg== 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 62CCD25AEB; Fri, 17 Jun 2022 19:40:31 +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 25HJeVrs025915; Fri, 17 Jun 2022 19:40:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25HJeVV1025914; Fri, 17 Jun 2022 19:40:31 GMT (envelope-from git) Date: Fri, 17 Jun 2022 19:40:31 GMT Message-Id: <202206171940.25HJeVV1025914@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dmitry Chagin Subject: git: 30c8127e3c76 - stable/13 - linux(4): Implement futex_op for arm64. 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: dchagin X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 30c8127e3c76905d05473d1c6200b69cde0bd9e0 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655494833; 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=XN52vy4/Sr4sTkb3iQZjqocMW/odrQfahnaL0WPjVjM=; b=WLYJ5Oi/L0uJQdWTWZXMy1U8YgxnmI79vb3ZiJ+7jx9+ouVJX1WFfn43bNkp5kFffY0LV6 ial8w8QkTePGsBgOzV9LrGhzp1kPoJEQKIr+ESMxfx+yLQBtu8IWq8r/QZ4davkXNtjK5Q 6p0RFoDT1Y0Lg4DrNIlY0UBeUQPsZU+IBEw0OUp8ceF1vRNc13qO6wqKaGWBxNOOX4u3nS fapweDGnfoIPFgSKFC15n5jNDMEP3Pi2HACik7NNab/2eLwHqbwGSMmqbhhHGJQrzwA+kD a3xvAZKDJQ5RiKthx/o/aJjDZ9xd7bVQs6HqFjKSI/VAk8J2oeQE9Efvbv6j0g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1655494833; a=rsa-sha256; cv=none; b=xcRaNi8Ab6Ka4fLAdBMa6ozXRQ2o/S/QyXbVWmUaN0x4q6BmwK8XZjv+VjOzhbgEyrf39W KWQ/NFF4zDV1KEjCyeigcwMsWSkSyBYccu1ifmLO+HWeh3odKnhXodR55XPVKIK4JpN352 yT1+dX0vFsVDKuJthptGYk/ScRAum4B8m8hGlheh7+DZWtviHAHASuk9tHMBeUfHnjMRBv ADZ6Hr5pMDdcWECvBGwFUndAeutU2dQDwiMieUteJlStCE6czhF/3c/ueLBzfOWuobY9sR kKl/5L3D79SX+9WZEhJA8ADxRsCk18k5nXvGDJfzBkjeymYpcjNyIP0Bpd3/ww== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=30c8127e3c76905d05473d1c6200b69cde0bd9e0 commit 30c8127e3c76905d05473d1c6200b69cde0bd9e0 Author: Dmitry Chagin AuthorDate: 2022-05-15 17:49:42 +0000 Commit: Dmitry Chagin CommitDate: 2022-06-17 19:35:19 +0000 linux(4): Implement futex_op for arm64. It's mostly modeled like the Linux does. Differential revision: https://reviews.freebsd.org/D35154 MFC after: 2 weeks (cherry picked from commit 3bae1cd68a2ac3e2c37d54cf550e01257dfb1a04) --- sys/arm64/linux/linux_support.s | 130 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 123 insertions(+), 7 deletions(-) diff --git a/sys/arm64/linux/linux_support.s b/sys/arm64/linux/linux_support.s index 1048e9579627..933930b5096f 100644 --- a/sys/arm64/linux/linux_support.s +++ b/sys/arm64/linux/linux_support.s @@ -2,6 +2,7 @@ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (C) 2018 Turing Robotic Industries Inc. + * Copyright (C) 2022 Dmitry Chagin * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,36 +28,151 @@ * $FreeBSD$ */ -#include "linux_assym.h" #include +__FBSDID("$FreeBSD$"); + +#include +#include + +#include #include "assym.inc" +.macro check_user_access user_arg, limit, bad_addr_func + ldr x7, =(\limit) + cmp x\user_arg, x7 + b.cs \bad_addr_func +.endm + +futex_fault: + SET_FAULT_HANDLER(xzr, x1) + EXIT_USER_ACCESS_CHECK(w0, x1) +futex_fault_nopcb: + mov x0, #EFAULT + ret + +#define LINUX_FUTEX_MAX_LOOPS 128 + /* - * LINUXTODO: implement futex_* + * int oparg, uint32_t *uaddr, int *oldval + * + * Return 0 on success, errno on failure, + * EAGAIN is returned if LL/SC operation fails. + * + * XXX. VM_MAXUSER_ADDRESS is not applicable here, should be replaced + * by something like LINUX_SHAREDPAGE. */ +/* (int *)uaddr2 = oparg */ ENTRY(futex_xchgl) - brk #0 + check_user_access 1, (VM_MAXUSER_ADDRESS-3), futex_fault_nopcb + adr x9, futex_fault /* Load the fault handler */ + SET_FAULT_HANDLER(x9, x4) /* And set it */ + ENTER_USER_ACCESS(w9, x4) + mov w5, #LINUX_FUTEX_MAX_LOOPS + prfm pstl1strm, [x1] + mov w6, w0 /* Save oparg */ +1: ldxr w4, [x1] /* Load oldval from uaddr */ + stlxr w0, w6, [x1] /* Store oparg to uaddr */ + cbz w0, 3f /* Exit on success */ + sub w5, w5, w0 /* Dec loop counter, w0 is 1 */ + cbnz w5, 1b /* Loop */ + mov x0, #EAGAIN /* Store of newval failed */ +3: dmb ish + EXIT_USER_ACCESS(w9) + SET_FAULT_HANDLER(xzr, x9) /* Reset the fault handler */ + str w4, [x2] /* Store oldval */ ret END(futex_xchgl) +/* (int *)uaddr2 += oparg */ ENTRY(futex_addl) - brk #0 + check_user_access 1, (VM_MAXUSER_ADDRESS-3), futex_fault_nopcb + adr x9, futex_fault + SET_FAULT_HANDLER(x9, x4) + ENTER_USER_ACCESS(w9, x4) + mov w5, #LINUX_FUTEX_MAX_LOOPS + prfm pstl1strm, [x1] + mov w6, w0 +1: ldxr w4, [x1] + add w3, w4, w6 /* oldval + oparg */ + stlxr w0, w3, [x1] + cbz w0, 3f + sub w5, w5, w0 + cbnz w5, 1b + mov x0, #EAGAIN +3: dmb ish + EXIT_USER_ACCESS(w9) + SET_FAULT_HANDLER(xzr, x9) + str w4, [x2] ret END(futex_addl) +/* (int *)uaddr2 |= oparg */ ENTRY(futex_orl) - brk #0 + check_user_access 1, (VM_MAXUSER_ADDRESS-3), futex_fault_nopcb + adr x9, futex_fault + SET_FAULT_HANDLER(x9, x4) + ENTER_USER_ACCESS(w9, x4) + mov w5, #LINUX_FUTEX_MAX_LOOPS + prfm pstl1strm, [x1] + mov w6, w0 +1: ldxr w4, [x1] + orr w3, w4, w6 /* oldavl |= oparg */ + stlxr w0, w3, [x1] + cbz w0, 3f + sub w5, w5, w0 + cbnz w5, 1b + mov x0, #EAGAIN +3: dmb ish + EXIT_USER_ACCESS(w9) + SET_FAULT_HANDLER(xzr, x9) + str w4, [x2] ret END(futex_orl) +/* (int *)uaddr2 &= oparg */ ENTRY(futex_andl) - brk #0 + check_user_access 1, (VM_MAXUSER_ADDRESS-3), futex_fault_nopcb + adr x9, futex_fault + SET_FAULT_HANDLER(x9, x4) + ENTER_USER_ACCESS(w9, x4) + mov w5, #LINUX_FUTEX_MAX_LOOPS + prfm pstl1strm, [x1] + mov w6, w0 +1: ldxr w4, [x1] + and w3, w4, w6 /* oldval &= oparg */ + stlxr w0, w3, [x1] + cbz w0, 3f + sub w5, w5, w0 + cbnz w5, 1b + mov x0, #EAGAIN +3: dmb ish + EXIT_USER_ACCESS(w9) + SET_FAULT_HANDLER(xzr, x9) + str w4, [x2] ret END(futex_andl) +/* (int *)uaddr2 ^= oparg */ ENTRY(futex_xorl) - brk #0 + check_user_access 1, (VM_MAXUSER_ADDRESS-3), futex_fault_nopcb + adr x9, futex_fault + SET_FAULT_HANDLER(x9, x4) + ENTER_USER_ACCESS(w9, x4) + mov w5, #LINUX_FUTEX_MAX_LOOPS + prfm pstl1strm, [x1] + mov w6, w0 +1: ldxr w4, [x1] + eor w3, w4, w6 /* oldval ^= oparg */ + stlxr w0, w3, [x1] + cbz w0, 3f + sub w5, w5, w0 + cbnz w5, 1b + mov x0, #EAGAIN +3: dmb ish + EXIT_USER_ACCESS(w9) + SET_FAULT_HANDLER(xzr, x9) + str w4, [x2] ret END(futex_xorl)