From nobody Thu Feb 02 20:10:21 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 4P78zK6wtHz3kX2w; Thu, 2 Feb 2023 20:10:21 +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 4P78zK5csnz4JSj; Thu, 2 Feb 2023 20:10:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675368621; 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=tQA8ZNZBHk9+cQkuGKKCLPN7qx5jI8fkk5J0WdENT3c=; b=Be5XCzV2AUTeH0YpcIkP9A7xAnvCxgl6+csgWme4Qr++WptsOQBh541QFbULdHRZwdPQ5Z 3XZY7n1IqHnPB+at0KVpfNOOfB6nIZQZOwb8vTuu95VPwjPf81u5H4Uhorh7o8zn4PTjw3 sVR68B9IIIznXXe4meagjiyXnd+t6Nw+ja1YGxFTo7oTrzCbF+es3pSmZ6pu3g5j2uKGt/ nde/vbUIuEzrR0WTvBOh67/Z5HAT2iSZp85SHnj+n/tlabqroerDaq2PQO2B7a4GzhaeVN fNRYsedC8gOhzAD+bbhDFezVIq0Ha8/rd8P+QKhtGnCyyua/2JQ8Slqld/VQkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675368621; 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=tQA8ZNZBHk9+cQkuGKKCLPN7qx5jI8fkk5J0WdENT3c=; b=O9u8O+YDPwEyZwjevSsmV5opqxD33vL+71G7pYnXTApG3d8sbzM1+KEqujBCNWU6VULU0i mFDviuTI2VVw82m28u5qUKKS24mljx13bA183adaaHOT/LOrH2Tcf6vV7292Y+Eflj5smR ae1sMkVnVExkwffDAXN3QG85ns+0VPgl9Dbd6jCVDFjEYDywjKa40f8Tv+pQ61r1bPcwqj 7XIIMTYY/Bn5RXOa8fY2rxJBN3yzFLA+X1Tk4FHmmb5AXKJFpCCyiJGxjSOKz/hOX2q17D IcyHH2SdBA7/7nxyegXdjgrecD9GykGZL6xOq7rtzN7OK4Ap01IdVwExBHhWqQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675368621; a=rsa-sha256; cv=none; b=npFvx8h9I1D3YPjx1f1Dm2NZe6R3PtiAmwjS7TkkkA3mnqcY7cE2cawws2Fs5m3uLISmfp VVq7BJKxYan6B1Hk68uPQxzHxgMzATceMJcfYzmu5RKXuzU3jy6FRfdC2Npl8QpJDMgjfG qhTjyhGRnmLCobbTVjEhvm+x1EqftCxIgE6WQOXX0BxJwloQRiivgKjHL99GHCkkFH7YjV mLQtwEvwZJc4oQMKKAjvG2q0RLN/BFtRbeFrLtNQyHPalLvwhPgxshblKaecxbD+GISNPG L1+Od3H1BVVq6PgeKT3SIk05isZcf20zd6dIm1CiY8Jm0qoTvaTUmrh3VbW03A== 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 4P78zK42xnz16tD; Thu, 2 Feb 2023 20:10:21 +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 312KALEE044885; Thu, 2 Feb 2023 20:10:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 312KALBP044884; Thu, 2 Feb 2023 20:10:21 GMT (envelope-from git) Date: Thu, 2 Feb 2023 20:10:21 GMT Message-Id: <202302022010.312KALBP044884@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: 2e1edd04eb01 - main - kboot: For hostfs, return better errors from read, where possible. 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: 2e1edd04eb01bac15628185686cbf615d80de7de Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=2e1edd04eb01bac15628185686cbf615d80de7de commit 2e1edd04eb01bac15628185686cbf615d80de7de Author: Warner Losh AuthorDate: 2023-02-02 20:06:24 +0000 Commit: Warner Losh CommitDate: 2023-02-02 20:06:31 +0000 kboot: For hostfs, return better errors from read, where possible. Translate the Linux error return from read to a FreeBSD errno. We use a simplified translation: 1-34 are the same between the systems, so any of those will be returned directly. All other errno map to EINVAL. This will suffice for some code that reads /dev/mem in producing the right diagnostic. A fully generalized version is much harder. Linux has a number of errno that don't translate well and has architecture dependent encodings. Avoid this mess with a simple macro for now. Add comment explaining why we use the simple method we do. Sponsored by: Netflix Reviewed by: kevans, andrew Differential Revision: https://reviews.freebsd.org/D38265 --- stand/kboot/host_syscall.h | 10 ++++++++++ stand/kboot/hostfs.c | 5 ++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/stand/kboot/host_syscall.h b/stand/kboot/host_syscall.h index 38f0fb04aa95..75394afcde6c 100644 --- a/stand/kboot/host_syscall.h +++ b/stand/kboot/host_syscall.h @@ -206,4 +206,14 @@ 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); +/* + * 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. + */ +#define host_to_stand_errno(e) ((-e) > 34 ? EINVAL : (-e)) + #endif diff --git a/stand/kboot/hostfs.c b/stand/kboot/hostfs.c index 08f532999abe..02afa885d833 100644 --- a/stand/kboot/hostfs.c +++ b/stand/kboot/hostfs.c @@ -112,9 +112,8 @@ hostfs_read(struct open_file *f, void *start, size_t size, size_t *resid) ssize_t sz; sz = host_read(hf->hf_fd, start, size); - if (sz < 0) { - return (EINVAL); - } + if (sz < 0) + return (host_to_stand_errno(sz)); *resid = size - sz; return (0);