From nobody Thu Dec 18 18:23:10 2025 X-Original-To: dev-commits-src-branches@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 4dXJv26q9qz6LTrW for ; Thu, 18 Dec 2025 18:23:10 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dXJv24rQ2z47FX for ; Thu, 18 Dec 2025 18:23:10 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1766082190; 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=BvA1ek2IBTyfNQGD672pvFy7DU/WdDqfPKvnmeCmcJw=; b=GIwmKq+hOKn0IT1huEvgwop6MNW8oESE8+inCRT5L7Xzhprbn8fslzcaexNQXMMThTdOEO Tr0OexcvvZeXz7WJGpBJr5gBtA3FP6AeZ9+0bxeDhRgnzmsoHayNKmxoVZ5IVuXP8jBTdE it6cuq4DtIgjJDPE5fFvg98KIHXy33YcMGCgAB035xYBe3vhGQhCW7PmcHgis1x7mcvLrC ma1WGyeUW1pu7SdAriENS4o3je35TL+tSxj8IU4sM4DfOtWojnuEqFdpu3VQquTjuPf1We BJhpILJDFT1WxxgV3ynJBtKlY/Kk0rFzQLpMa/4g048imzVq7YTdIa/xuh1RbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1766082190; 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=BvA1ek2IBTyfNQGD672pvFy7DU/WdDqfPKvnmeCmcJw=; b=HEwcYiL9d9xVveUpVonpFKAirKFqpny7rxHE+YbAZLR/jce/4SJqK0GFgIWVIP7RvgUzpH Y2KbAVQzB+c8BN72FICUUFQ4rhcI+RRTQu8bIAt97ne3X0ZOAX4lDSoTuF9s3hVLwIZxnz bkRtPfjD5noQFN7+BZKOIkFOzgspxyORlw98eyNu5+0eYXvKLkNSR2InYFVasSYqFMqwfK E0nxcMmbTLVzxv6hSorXIXBXJ0ryMccasyHD/lvLNGc1jJzMv23BFiv1xqQtCcGTCnQ4vA cqZrq+vBCkFTM0nK1bkcYhjFvKgN+clyooQoDMzdwCHQxE5kliZxutYz72770Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1766082190; a=rsa-sha256; cv=none; b=qY2CppmXgVN0OLkxdGRjmeBnHys1BCWO4HBz0S8bOLkgmAb91Zh+/a6I0y3mSqU31FxtdL 9v1JfQg6H/QjQdm5N81TdOjKwULxIR/f6DzjNa+ouedgmZSfcQM84bQczd/N3vTGzx8kYM pr3O6AqlTWFQXOSguTwOWJL5kkbQFzvB37SK3fcqakBhOOR+qa4L//Fui5VGRJ4DuKOVaG ZNlLEEcNbV2YG958OTJJnoJmlmGLJZwZsSqXarO98b/DeJBv2LM8ofVLDzUeaOBx7nFLCy Izi7hjWEyXzD7lGH7Uwv8hXGkGsTn+nFgvvi6uitMm6bBcvo8J1B+prHO2FV9w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dXJv23yswzpml for ; Thu, 18 Dec 2025 18:23:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 2674f by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 18 Dec 2025 18:23:10 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: b3aada5bfdb9 - stable/14 - fcntl(F_SETFL): Don't unconditionally invoke FIONBIO and FIOASYNC List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: b3aada5bfdb9da22fdd33a67ca508074da6d1b5b Auto-Submitted: auto-generated Date: Thu, 18 Dec 2025 18:23:10 +0000 Message-Id: <6944468e.2674f.2f543ec6@gitrepo.freebsd.org> The branch stable/14 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=b3aada5bfdb9da22fdd33a67ca508074da6d1b5b commit b3aada5bfdb9da22fdd33a67ca508074da6d1b5b Author: John Baldwin AuthorDate: 2025-09-10 14:22:19 +0000 Commit: John Baldwin CommitDate: 2025-12-18 17:01:56 +0000 fcntl(F_SETFL): Don't unconditionally invoke FIONBIO and FIOASYNC Currently, F_SETFL always invokes FIONBIO and FIOASYNC ioctls on the file descriptor even if the state of the associated flag has not changed. This means that a character device driver that implements non-blocking I/O but not async I/O needs a handler for FIOASYNC that permits setting the value to 0. This also means that fcntl(fd, F_SETFL, fcntl(fd, F_GETFL)) can fail for a character device driver that does not handle both FIONBIO and FIOASYNC. These requirements are not obvious nor well documented. Instead, only invoke FIONBIO and FIOASYNC if the relevant flag changes state. This only requires a device driver to implement support for FIONBIO or FIOASYNC if it supports the corresponding flag. While here, if a request aims to toggle both F_NOBLOCK and F_ASYNC and FIOASYNC fails, pass the previous state of F_NONBLOCK to FIONBIO instead of always disabling non-blocking I/O and then possibly reverting the flag back to on in f_flags. Reviewed by: mckusick, imp, kib, emaste Differential Revision: https://reviews.freebsd.org/D52403 (cherry picked from commit 3c152a3de42a7d077e8d19159b679c3fb7572820) --- sys/kern/kern_descrip.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 0e6af0f5deff..e8bbc5d9ee1c 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -578,20 +578,26 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg) } while (atomic_cmpset_int(&fp->f_flag, flg, tmp) == 0); got_set = tmp & ~flg; got_cleared = flg & ~tmp; - tmp = fp->f_flag & FNONBLOCK; - error = fo_ioctl(fp, FIONBIO, &tmp, td->td_ucred, td); - if (error != 0) - goto revert_f_setfl; - tmp = fp->f_flag & FASYNC; - error = fo_ioctl(fp, FIOASYNC, &tmp, td->td_ucred, td); - if (error == 0) { - fdrop(fp, td); - break; + if (((got_set | got_cleared) & FNONBLOCK) != 0) { + tmp = fp->f_flag & FNONBLOCK; + error = fo_ioctl(fp, FIONBIO, &tmp, td->td_ucred, td); + if (error != 0) + goto revert_flags; + } + if (((got_set | got_cleared) & FASYNC) != 0) { + tmp = fp->f_flag & FASYNC; + error = fo_ioctl(fp, FIOASYNC, &tmp, td->td_ucred, td); + if (error != 0) + goto revert_nonblock; + } + fdrop(fp, td); + break; +revert_nonblock: + if (((got_set | got_cleared) & FNONBLOCK) != 0) { + tmp = ~fp->f_flag & FNONBLOCK; + (void)fo_ioctl(fp, FIONBIO, &tmp, td->td_ucred, td); } - atomic_clear_int(&fp->f_flag, FNONBLOCK); - tmp = 0; - (void)fo_ioctl(fp, FIONBIO, &tmp, td->td_ucred, td); -revert_f_setfl: +revert_flags: do { tmp = flg = fp->f_flag; tmp &= ~FCNTLFLAGS;