From nobody Mon Mar 11 21:23:23 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 4TtqWb6b6Pz5DlMj; Mon, 11 Mar 2024 21:23:23 +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 4TtqWb5ky2z413C; Mon, 11 Mar 2024 21:23:23 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1710192203; 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=L7Kyc6AA5xx3X9mcAJoRjoTEP6FljAzY/uJnXBwW10k=; b=Kpvz8zTDB9lV5ei3TDGFjzYYD9EMliF0kI+Yu17CmTYSde/P+6ga+DoBwlG1R1xz0ZFLRZ HphF9On7IRPKtFE5xi3PthUZFVtJhpE+P6qqRT19EeiiFfeoozel92hfTIV2u/uemIyUtQ 1HXMoRB2PR4JlP9fj7hkBZUWTGMhGV/wHA5C+nCKOBIpI5mS+M6tVw9xAWdluqjo7XrdFW ZwYX5A8GpjCS56grGK3UISF9YhecqkbUidOhsRTDDkFEB4d7WBR3Rzoie6VzmfdUayeivs 08ONtwsLbDeq4ZDORV++thEPOKF0sJ2bG2kaU+uIWZR06i1cP4DPAmIj1sgD7w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1710192203; a=rsa-sha256; cv=none; b=GePh/hEcu1GvsJnbLbAurlJboz09LZuTmKzZspOZ/pYo7BK0wpKdowRdrrzmeyjhp3/D6Y o2CUZzQT1lwuj8q+UmdHvWwS6OsOQ8bp9MQxtZJGE3BJh8Ow+41Q7GQ4ZOytwakPOWssda oNIYpnP+EHTTZR0hwVIyeSx0d9+0HNmzHHvVanXwyVBO6ncuhk499bvga9Mk6/MdYYkXaU 1C5ImIhLE+4xDvHsDTkV8Z3cPHcmEsu9aLmD1TfQjqVKLyqw1x/uN/v0FYoRi2DybuNORT Dr9DxWRQXYST47HjG+mYGoRuY5+HYd+WL7KBWvvl2gW1LNrqpeTseH5lDs9nbw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1710192203; 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=L7Kyc6AA5xx3X9mcAJoRjoTEP6FljAzY/uJnXBwW10k=; b=ChrpXQ/F5BjZBwlePmQHrK+BI/RJ0LGvsNB/f9eBQwMxj4wOF6s1CLwIqPAGi2d65zH155 T1yDw0Fwk1RYhgDQ3x/0Cr84f6ptivhU4bbZu6VGW3ZzgOSmzhUW+gkE1cfFAiKDa2TLUP QVryoBCljF243cDctigUCYUewpfEcDyblzJU5MXwqbpvtH/hpaNG9IZ+Sg4iFAKFoeDHCf KiIUHm8uEbNados7WOoV7xcWvPnZ5QMyvuppkFU99o8Eeu40uSIL7QG5X+1o9/mK/eJAyi Djp3rCTVolHZlQSO5909Mla9zKTcDIXMpZ/URy134deVnl+yuXjF96EnOx110A== 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 4TtqWb51tTzmXC; Mon, 11 Mar 2024 21:23:23 +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 42BLNNaC025480; Mon, 11 Mar 2024 21:23:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 42BLNNDg025477; Mon, 11 Mar 2024 21:23:23 GMT (envelope-from git) Date: Mon, 11 Mar 2024 21:23:23 GMT Message-Id: <202403112123.42BLNNDg025477@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 3ae18fdfbcaa - main - kboot: Create function for error checking. 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: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 3ae18fdfbcaad827defdc217386e73c993beeba0 Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=3ae18fdfbcaad827defdc217386e73c993beeba0 commit 3ae18fdfbcaad827defdc217386e73c993beeba0 Author: Warner Losh AuthorDate: 2024-03-11 20:15:03 +0000 Commit: Warner Losh CommitDate: 2024-03-11 21:21:51 +0000 kboot: Create function for error checking. Linux has the convention of returning -ERRNO to flag errors from its system calls. Sometimes other negative values are returned that are success... However, only values -1 to -4096 (inclusive) are really errors. The rest are either truncated values that only look negative (so use long instead of int), or are things like addresses or legal unsigned file offsets or similar that are successful returns. Filter out the latter. Sponsored by: Netflix --- stand/kboot/include/host_syscall.h | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/stand/kboot/include/host_syscall.h b/stand/kboot/include/host_syscall.h index fd3b7a0f362b..68106093ce1f 100644 --- a/stand/kboot/include/host_syscall.h +++ b/stand/kboot/include/host_syscall.h @@ -190,20 +190,36 @@ ssize_t host_write(int fd, const void *buf, size_t nbyte); host_mmap(0, size, HOST_PROT_READ | HOST_PROT_WRITE, \ HOST_MAP_PRIVATE | HOST_MAP_ANONYMOUS, -1, 0); +/* + * Since we have to interface with the 'raw' system call, we have to cope with + * Linux's conventions. To run on the most architectures possible, they don't + * return errors through some CPU flag, but instead, return a negative value for + * an error, and a positive one for success. However, there's some issues since + * addresses have to be returned, some of which are also negative, so Linus + * declared that no successful result could be -4096 to 0. This implements + * that quirk so we can check return values easily. + */ +static __inline bool +is_linux_error(long e) +{ + return (e < 0 && e >= -4096); +} + /* * Translate Linux errno to FreeBSD errno. The two system have idenitcal errors * for 1-34. After that, they differ. Linux also has errno that don't map * exactly to FreeBSD's errno, plus the Linux errno are arch dependent > * 34. Since we just need to do this for simple cases, use the simple mapping * function where -1 to -34 are translated to 1 to 34 and all others are EINVAL. - * Pass the linux return value, which will be the -errno. + * Pass the linux return value, which will be the -errno. Linux returns these + * values as a 'long' which has to align to CPU register size, so accept that + * size as the error so the assert can catch more values. */ static __inline int -host_to_stand_errno(int e) +host_to_stand_errno(long e) { - assert(e < 0); + assert(is_linux_error(e)); return((-e) > 34 ? EINVAL : (-e)); } - #endif