From nobody Tue Apr 16 20:13:31 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 4VJwGM4pZnz5H0YZ; Tue, 16 Apr 2024 20:13:31 +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 4VJwGM19gkz4vYy; Tue, 16 Apr 2024 20:13:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1713298411; 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=30ShAClxbcopui2KuBI4c6Nwg/bkft2tXjqa8s7hRi0=; b=yHEtINY+G1wEbm6ylgng26Fz2EhpduhHvpBBu1JtksSahAo1j+eFHZ0PwuIIk8NykGGu0u sSQzgRtAvRko/fCz+1KLEjGYmWjsyl4F4iLPsCcDIwk9arsPVQOLZE4EsMYNP0SP7ADPW3 3sbGWjlvKBZb+zMyN7QFcNcnf0RpxtjlFLRs0JKFL9hZt3n4IyCUjazue0FdGpGXGpPSoW ZG3QNErMVRGy0GQSg9D8X/4vt3nvb8kQqxWR9HSSfzgCX8RpBrXdiATvAf5t3bamutNqAj +NxPNL2hiIS7yE9W6luYnY+MdI/RrZjIQu+LVd6AXhgKDSkppTHPkQ1Hg2MnhQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1713298411; a=rsa-sha256; cv=none; b=ZLT56CKVXuj9GMP2RntwvABigAH8O/hUV3povDCtmvuCkkI9YBW4HJgHM2WYMT5jVZf43T g9jI44btaV4fr2kKn4ed10F+7WpHy343IQl2uVEzW+6AvDuPV3Pqv4wtYQpeDJcWdkoRYy EIB8o89dJ3bjHNdROe9b6UCWY9JZ2AxeCBswnChZ1ZWmdcBRHO9zAMxzLrzE/Dr6jooMEh D+0J1yL0/1A/2GKhsXYfqheLgTwsEK8RtIdhwvIkvhdVVx9mcWm8TS8mwCa2q3cbK2UlIL RxlIxWsJvvZSOZkArcv49CsxRfRpLJOoBKXU3lwZuogQa4WN7e1rh96LbaZ/yQ== 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=1713298411; 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=30ShAClxbcopui2KuBI4c6Nwg/bkft2tXjqa8s7hRi0=; b=uqxl0lpX0/vu1z0PdFJYseycsBeRe/ukT+pn4WxOY/1+2VDVViYfAYbEB7DgG/+nPldZFw 2bl72yLqfinfVja5VZNpkEzfJKEHKWrJ41Rj+wRAclgcOWPmOld5LS01waL0ULRhMvXi9W kSMrHFl+DwCsr6TCJNc9ZCISV173ACUslirZCDLNNl9PrLFX4d/cQ4vRtd8HI/S7BcDHF1 xw9uqcjQC33VqAMPRBLJBNQU8gLotxvg7g6ish8Mk7rsQLhtuCD7K9FAVg8HuZTyoOO+Lz abBJRoOvjpTk8AeKWpMmL9TO1rl1m2gZA4mYHatpb193XRzKPyB+aXvYJ+oHdw== 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 4VJwGM0lr0zxPV; Tue, 16 Apr 2024 20:13:31 +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 43GKDVl6039755; Tue, 16 Apr 2024 20:13:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 43GKDVhw039752; Tue, 16 Apr 2024 20:13:31 GMT (envelope-from git) Date: Tue, 16 Apr 2024 20:13:31 GMT Message-Id: <202404162013.43GKDVhw039752@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Warner Losh Subject: git: 649cc3598192 - stable/14 - 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-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/stable/14 X-Git-Reftype: branch X-Git-Commit: 649cc3598192b6c03a5165010a97a3778dd3f0e1 Auto-Submitted: auto-generated The branch stable/14 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=649cc3598192b6c03a5165010a97a3778dd3f0e1 commit 649cc3598192b6c03a5165010a97a3778dd3f0e1 Author: Warner Losh AuthorDate: 2024-03-11 20:15:03 +0000 Commit: Warner Losh CommitDate: 2024-04-16 19:54:29 +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 (cherry picked from commit 3ae18fdfbcaad827defdc217386e73c993beeba0) --- 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