Re: Something seems weird at main-n287304-8a14fcd23a20

David Wolfskill <[email protected]> Wed, 8 Jul 2026 08:50:12 -0700
Newsgroups gmane.os.freebsd.current
Message-ID <[email protected]>
On Wed, Jul 08, 2026 at 05:55:56PM +0300, Konstantin Belousov wrote:
> ...
> > Hope this helps finding a fix!
> 
> Try this
> 
> commit 6c34a1e68116cfcebd327fbe93bcf0428dec1ae1
> Author: Konstantin Belousov <[email protected]>
> Date:   Wed Jul 8 17:54:25 2026 +0300
> 
>     kern_filewrite(): unconditionally calculate cnt
>     
>     Fixes:  dfad790c8cca ("sendfile: stop abusing kern_writev()")
> 
> diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c
> index 079bd7b347d7..d5145d6cf322 100644
> --- a/sys/kern/sys_generic.c
> +++ b/sys/kern/sys_generic.c
> @@ -595,9 +595,9 @@ kern_filewrite(struct thread *td, int fd, struct file *fp, struct uio *auio,
>  #endif
>  	cnt = auio->uio_resid;
>  	error = fo_write(fp, auio, td->td_ucred, flags, td);
> +	cnt -= auio->uio_resid;
>  #ifdef KTRACE
>  	if (ktruio != NULL) {
> -		cnt -= auio->uio_resid;
>  		if (error == 0)
>  			ktruio->uio_resid = cnt;
>  		ktrgenio(fd, UIO_WRITE, ktruio, error);

The above worked for me:

freebeast(16.0-C)[1] uname -aUK
FreeBSD freebeast.catwhisker.org 16.0-CURRENT FreeBSD 16.0-CURRENT #628 main-n287304-8a14fcd23a20-dirty: Wed Jul  8 15:37:10 UTC 2026     [email protected]:/common/S3/obj/usr/src/amd64.amd64/sys/GENERIC amd64 1600019 1600019
freebeast(16.0-C)[2] ls -lT s3
-rw-r--r--  1 david wheel 12490214 Jul  8 08:42:09 2026 s3
freebeast(16.0-C)[3] scp !$ albert:/tmp
scp s3 albert:/tmp
s3                                            100%   12MB 106.2MB/s   00:00
freebeast(16.0-C)[4]

freebeast(16.0-C)[1] git -C /usr/src status
On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   sys/kern/sys_generic.c

no changes added to commit (use "git add" and/or "git commit -a")
freebeast(16.0-C)[2] git -C /usr/src -P diff sys/kern/sys_generic.c
diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c
index 079bd7b347d7..d5145d6cf322 100644
--- a/sys/kern/sys_generic.c
+++ b/sys/kern/sys_generic.c
@@ -595,9 +595,9 @@ kern_filewrite(struct thread *td, int fd, struct file *fp, struct uio *auio,
 #endif
        cnt = auio->uio_resid;
        error = fo_write(fp, auio, td->td_ucred, flags, td);
+       cnt -= auio->uio_resid;
 #ifdef KTRACE
        if (ktruio != NULL) {
-               cnt -= auio->uio_resid;
                if (error == 0)
                        ktruio->uio_resid = cnt;
                ktrgenio(fd, UIO_WRITE, ktruio, error);

Peace,
david
-- 
David H. Wolfskill                              [email protected]

See https://www.catwhisker.org/~david/publickey.gpg for my public key.
signature.asc (application/pgp-signature, 395 B)
-----BEGIN PGP SIGNATURE-----

iPEEARYKAJkWIQRCec5RsK7Enudh3yGB9MJ9AwUELQUCak5xtBsUgAAAAAAEAA5t
YW51MiwyLjUrMS4xMiwyLDNfFIAAAAAALgAoaXNzdWVyLWZwckBub3RhdGlvbnMu
b3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDQyNzlDRTUxQjBBRUM0OUVFNzYxREYy
MTgxRjRDMjdEMDMwNTA0MkQACgkQgfTCfQMFBC1H0AEAoskjQnz60Az+/Z4vGcF5
ezyWJreJ1zYo9EGMvZe+9XkA+wRA1dM9eisgu7v/+96UzJSxyXdzIwWQ54JTXJbw
OtAO
=HBHW
-----END PGP SIGNATURE-----