From nobody Tue Jan 07 14:34:54 2025 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 4YSD8v4mV1z5kfd9; Tue, 07 Jan 2025 14:34:55 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YSD8v154sz4KwL; Tue, 7 Jan 2025 14:34:55 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736260495; 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=r1Qd3bJqF1J06xQEp4+VKEBzrtxPwOP3kWi3UISmrWg=; b=YcTzMJCCZ2IU50pyzMxeQ+w7yMBD1oR8dUB7ICeIst2AX7kHA5YWM4CqvSrjeJjcuS8xs4 JZQQ/8LJnS85nkGNOoNfcyZCSvCPsDIy+0gZ5uHWiq0uRoy0Dc9KH6z+FW161ElG99+Fz9 R18Hg55k0HWlPv5XL9IA5lwQwVbf6l0h+4LnMNkYoJwHfXA5s2ASPQyPSehx+DdOhIrN5z qER8sGLTe1OSmu01pYXAqPbdyjTBxHpQH5J9XrwcXnWnWWgg97cFp6YXex3hiAwxhqGSKM P7z6aFYhUEF5XPkypWSrceesTB2Q8aqoCZ4H4goZOrWLFQ7hSkg/b/IdZ43m4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736260495; 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=r1Qd3bJqF1J06xQEp4+VKEBzrtxPwOP3kWi3UISmrWg=; b=VM9M4bnQxKiid1Y5Y5PmPDyD5FQYRiKGBZ2KUqTedpWT2f+6wiDc7DtM2mODyLvqpYUxIQ kn7E35Ri0BAjl8dfWinPS8WYX/wphhxwSaQsy79b5A3GugNIlaGEUOzOQ3TES2Jjju4df8 UyTFg4IlsxXylzm7gqJWBvhnSAS9G5Yyt5M1rKuYk/SrbMcrW2I3VdLDz+z1BfvbXLQW3P GemaR0SINq7/8FlTVrscH2oRPvc/s48j8K+tvhW8Mcjj4CTVlzvvTAz0rgZ5pt1mPw6Wld TlRioGJatCRjuzByX4VL1fBKMmFBDXWING051szAggTxeZa/Z/zNlrhLwoRTsw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1736260495; a=rsa-sha256; cv=none; b=j1MYxQURxXQoP2hpT3LVFlsWvLIljSvQ7l4zgEfDhB61PplCjxrci/wHMPHozi9gXYEmO/ oK2TB3WthE1NCNU/QEvs2h7X+2r+RFfXm4uJUHeWyM6DFczoWUHt1Ky78G3FCUea0tTiH1 1a6a25aHP2iM4W2ip98stYGbMSy43JxCjJ8pjKHO0YSZ2Q02BlHcBJ2MZyYDshsMNq7HO7 iKhU72QhO5aucAMV1md6jJYIWGJRUVpN/PZi6tScjIr944+/TPB1JLGR5DvRLD8/q8lmYA bFfK96N7Gnz9qChE2QQAhsLhbmx8j/4yF3O/Ef7on+knOx42iR1cqQmliq9N8Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4YSD8v0X8jz1ClK; Tue, 07 Jan 2025 14:34:55 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 507EYsCZ016587; Tue, 7 Jan 2025 14:34:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 507EYsja016584; Tue, 7 Jan 2025 14:34:54 GMT (envelope-from git) Date: Tue, 7 Jan 2025 14:34:54 GMT Message-Id: <202501071434.507EYsja016584@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: d3bdfa583044 - main - bhyve: Use a non-blocking read in slirp_recv() 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d3bdfa583044dbfb76ef777939b86bb68baebee7 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=d3bdfa583044dbfb76ef777939b86bb68baebee7 commit d3bdfa583044dbfb76ef777939b86bb68baebee7 Author: Mark Johnston AuthorDate: 2025-01-07 14:33:06 +0000 Commit: Mark Johnston CommitDate: 2025-01-07 14:33:06 +0000 bhyve: Use a non-blocking read in slirp_recv() When using the slirp backend with the e1000 frontend, I otherwise get hangs in readv(), caused by the e1000 emulation not checking whether bytes are available before trying to read them. In particular, that device model expects the recv callback to return 0 if no bytes are available, and with slirp it would end up blocking forever. The virtio device model uses the peek_recvlen to check first, so I didn't notice the problem when implementing the slirp backend. Make the slirp backend more flexible to accommodate e1000. MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D48164 --- usr.sbin/bhyve/net_backend_slirp.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/usr.sbin/bhyve/net_backend_slirp.c b/usr.sbin/bhyve/net_backend_slirp.c index 5ae33801387c..d070d2cdfdb6 100644 --- a/usr.sbin/bhyve/net_backend_slirp.c +++ b/usr.sbin/bhyve/net_backend_slirp.c @@ -609,11 +609,22 @@ static ssize_t slirp_recv(struct net_backend *be, const struct iovec *iov, int iovcnt) { struct slirp_priv *priv = NET_BE_PRIV(be); + struct msghdr hdr; ssize_t n; - n = readv(priv->pipe[0], iov, iovcnt); - if (n < 0) + hdr.msg_name = NULL; + hdr.msg_namelen = 0; + hdr.msg_iov = __DECONST(struct iovec *, iov); + hdr.msg_iovlen = iovcnt; + hdr.msg_control = NULL; + hdr.msg_controllen = 0; + hdr.msg_flags = 0; + n = recvmsg(priv->pipe[0], &hdr, MSG_DONTWAIT); + if (n < 0) { + if (errno == EWOULDBLOCK) + return (0); return (-1); + } assert(n <= SLIRP_MTU); return (n); }