From nobody Tue Oct 19 16:48:28 2021 X-Original-To: dev-commits-src-main@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 88B4C180A252; Tue, 19 Oct 2021 16:48:28 +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 4HYfnm3L7lz4h3L; Tue, 19 Oct 2021 16:48:28 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 5269417B1A; Tue, 19 Oct 2021 16:48:28 +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 19JGmSHL002764; Tue, 19 Oct 2021 16:48:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 19JGmSOL002763; Tue, 19 Oct 2021 16:48:28 GMT (envelope-from git) Date: Tue, 19 Oct 2021 16:48:28 GMT Message-Id: <202110191648.19JGmSOL002763@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Toomas Soome Subject: git: 98e805b4a18d - main - loader: net_open() should not replace f->f_devdata List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: tsoome X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 98e805b4a18d6ef4d3c9924166e1217e0430290d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by tsoome: URL: https://cgit.FreeBSD.org/src/commit/?id=98e805b4a18d6ef4d3c9924166e1217e0430290d commit 98e805b4a18d6ef4d3c9924166e1217e0430290d Author: Toomas Soome AuthorDate: 2021-09-24 15:04:31 +0000 Commit: Toomas Soome CommitDate: 2021-10-19 16:43:56 +0000 loader: net_open() should not replace f->f_devdata net_open() does replace f_devdata with pointer to netdev_sock, this will cause memory leak when device is closed, but also does alter the devopen() logic. We should store &netdev_sock to dev->d_opendata instead, this would preserve and follow the devopen() logic. Fixes network boot on aarch64 (tested by bz). Reviewed-by: imp MFC After: 2 weeks Differential Revision: https://reviews.freebsd.org/D32227 --- stand/common/dev_net.c | 8 +++++--- stand/libsa/nfs.c | 4 +++- stand/libsa/tftp.c | 7 +++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/stand/common/dev_net.c b/stand/common/dev_net.c index db13e618e822..70b571047d56 100644 --- a/stand/common/dev_net.c +++ b/stand/common/dev_net.c @@ -114,7 +114,7 @@ net_init(void) /* * Called by devopen after it sets f->f_dev to our devsw entry. - * This opens the low-level device and sets f->f_devdata. + * This opens the low-level device and sets dev->d_opendata. * This is declared with variable arguments... */ static int @@ -193,20 +193,22 @@ net_open(struct open_file *f, ...) } netdev_opens++; - f->f_devdata = &netdev_sock; + dev->d_opendata = &netdev_sock; return (error); } static int net_close(struct open_file *f) { + struct devdesc *dev; #ifdef NETIF_DEBUG if (debug) printf("%s: opens=%d\n", __func__, netdev_opens); #endif - f->f_devdata = NULL; + dev = f->f_devdata; + dev->d_opendata = NULL; return (0); } diff --git a/stand/libsa/nfs.c b/stand/libsa/nfs.c index 084c7261f054..5757395caba2 100644 --- a/stand/libsa/nfs.c +++ b/stand/libsa/nfs.c @@ -464,6 +464,7 @@ nfs_readdata(struct nfs_iodesc *d, off_t off, void *addr, size_t len) int nfs_open(const char *upath, struct open_file *f) { + struct devdesc *dev; struct iodesc *desc; struct nfs_iodesc *currfd = NULL; char buf[2 * NFS_V3MAXFHSIZE + 3]; @@ -484,6 +485,7 @@ nfs_open(const char *upath, struct open_file *f) if (netproto != NET_NFS) return (EINVAL); + dev = f->f_devdata; #ifdef NFS_DEBUG if (debug) printf("nfs_open: %s (rootip=%s rootpath=%s)\n", upath, @@ -497,7 +499,7 @@ nfs_open(const char *upath, struct open_file *f) if (f->f_dev->dv_type != DEVT_NET) return (EINVAL); - if (!(desc = socktodesc(*(int *)(f->f_devdata)))) + if (!(desc = socktodesc(*(int *)(dev->d_opendata)))) return (EINVAL); /* Bind to a reserved port. */ diff --git a/stand/libsa/tftp.c b/stand/libsa/tftp.c index 22e03ab58da1..01f5753a2163 100644 --- a/stand/libsa/tftp.c +++ b/stand/libsa/tftp.c @@ -37,7 +37,8 @@ __FBSDID("$FreeBSD$"); /* * Simple TFTP implementation for libsa. * Assumes: - * - socket descriptor (int) at open_file->f_devdata + * - socket descriptor (int) at dev->d_opendata, dev stored at + * open_file->f_devdata * - server host IP in global rootip * Restrictions: * - read only @@ -432,6 +433,7 @@ tftp_getnextblock(struct tftp_handle *h) static int tftp_open(const char *path, struct open_file *f) { + struct devdesc *dev; struct tftp_handle *tftpfile; struct iodesc *io; int res; @@ -452,7 +454,8 @@ tftp_open(const char *path, struct open_file *f) return (ENOMEM); tftpfile->tftp_blksize = TFTP_REQUESTED_BLKSIZE; - tftpfile->iodesc = io = socktodesc(*(int *)(f->f_devdata)); + dev = f->f_devdata; + tftpfile->iodesc = io = socktodesc(*(int *)(dev->d_opendata)); if (io == NULL) { free(tftpfile); return (EINVAL);