git: 4c4195700249 - main - sys: use curthread_pflags_set/restore to manage TDP_DEADLKTREAT for uio

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Tue, 23 Jun 2026 14:42:17 UTC
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=4c419570024951ad1e477c8d6c3d9968199faf4a

commit 4c419570024951ad1e477c8d6c3d9968199faf4a
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-06-21 18:48:06 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-06-23 14:42:03 +0000

    sys: use curthread_pflags_set/restore to manage TDP_DEADLKTREAT for uio
    
    For i386, remove now unused label.
    Remove unneeded initialization of the 'save' local.
    
    Reviewed bu:    brooks
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D57726
---
 sys/amd64/amd64/uio_machdep.c     |  9 +++------
 sys/arm/arm/uio_machdep.c         |  9 +++------
 sys/arm64/arm64/uio_machdep.c     |  9 +++------
 sys/i386/i386/uio_machdep.c       | 10 +++-------
 sys/kern/subr_uio.c               |  6 +++---
 sys/powerpc/powerpc/uio_machdep.c |  9 +++------
 sys/riscv/riscv/uio_machdep.c     |  9 +++------
 7 files changed, 21 insertions(+), 40 deletions(-)

diff --git a/sys/amd64/amd64/uio_machdep.c b/sys/amd64/amd64/uio_machdep.c
index 9fdfc898172b..851d8c6a02e0 100644
--- a/sys/amd64/amd64/uio_machdep.c
+++ b/sys/amd64/amd64/uio_machdep.c
@@ -57,13 +57,12 @@
 int
 uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
 {
-	struct thread *td = curthread;
 	struct iovec *iov;
 	void *cp, *vaddr;
 	vm_offset_t page_offset;
 	size_t cnt;
 	int error = 0;
-	int save = 0;
+	int save;
 	bool mapped;
 
 	KASSERT(uio->uio_rw == UIO_READ || uio->uio_rw == UIO_WRITE,
@@ -73,8 +72,7 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
 	KASSERT(uio->uio_resid >= 0,
 	    ("%s: uio %p resid underflow", __func__, uio));
 
-	save = td->td_pflags & TDP_DEADLKTREAT;
-	td->td_pflags |= TDP_DEADLKTREAT;
+	save = curthread_pflags_set(TDP_DEADLKTREAT);
 	mapped = false;
 	while (n > 0 && uio->uio_resid) {
 		KASSERT(uio->uio_iovcnt > 0,
@@ -111,8 +109,7 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
 		offset += cnt;
 		n -= cnt;
 	}
-	if (save == 0)
-		td->td_pflags &= ~TDP_DEADLKTREAT;
+	curthread_pflags_restore(save);
 	return (error);
 }
 
diff --git a/sys/arm/arm/uio_machdep.c b/sys/arm/arm/uio_machdep.c
index 7df6104b25fc..0aebfef07ca3 100644
--- a/sys/arm/arm/uio_machdep.c
+++ b/sys/arm/arm/uio_machdep.c
@@ -56,13 +56,12 @@
 int
 uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
 {
-	struct thread *td = curthread;
 	struct iovec *iov;
 	void *cp;
 	vm_offset_t page_offset;
 	size_t cnt;
 	int error = 0;
-	int save = 0;
+	int save;
 	struct sf_buf *sf;
 
 	KASSERT(uio->uio_rw == UIO_READ || uio->uio_rw == UIO_WRITE,
@@ -72,8 +71,7 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
 	KASSERT(uio->uio_resid >= 0,
 	    ("%s: uio %p resid underflow", __func__, uio));
 
-	save = td->td_pflags & TDP_DEADLKTREAT;
-	td->td_pflags |= TDP_DEADLKTREAT;
+	save = curthread_pflags_set(TDP_DEADLKTREAT);
 	while (n > 0 && uio->uio_resid) {
 		KASSERT(uio->uio_iovcnt > 0,
 		    ("%s: uio %p iovcnt underflow", __func__, uio));
@@ -102,7 +100,6 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
 		offset += cnt;
 		n -= cnt;
 	}
-	if (save == 0)
-		td->td_pflags &= ~TDP_DEADLKTREAT;
+	curthread_pflags_restore(save);
 	return (error);
 }
diff --git a/sys/arm64/arm64/uio_machdep.c b/sys/arm64/arm64/uio_machdep.c
index 77f596498c45..b7191f48ac61 100644
--- a/sys/arm64/arm64/uio_machdep.c
+++ b/sys/arm64/arm64/uio_machdep.c
@@ -53,13 +53,12 @@
 int
 uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
 {
-	struct thread *td = curthread;
 	struct iovec *iov;
 	void *cp, *vaddr;
 	vm_offset_t page_offset;
 	size_t cnt;
 	int error = 0;
-	int save = 0;
+	int save;
 	bool mapped;
 
 	KASSERT(uio->uio_rw == UIO_READ || uio->uio_rw == UIO_WRITE,
@@ -69,8 +68,7 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
 	KASSERT(uio->uio_resid >= 0,
 	    ("%s: uio %p resid underflow", __func__, uio));
 
-	save = td->td_pflags & TDP_DEADLKTREAT;
-	td->td_pflags |= TDP_DEADLKTREAT;
+	save = curthread_pflags_set(TDP_DEADLKTREAT);
 	mapped = false;
 	while (n > 0 && uio->uio_resid) {
 		KASSERT(uio->uio_iovcnt > 0,
@@ -107,7 +105,6 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
 		offset += cnt;
 		n -= cnt;
 	}
-	if (save == 0)
-		td->td_pflags &= ~TDP_DEADLKTREAT;
+	curthread_pflags_restore(save);
 	return (error);
 }
diff --git a/sys/i386/i386/uio_machdep.c b/sys/i386/i386/uio_machdep.c
index 674de877d2a1..2640ef0b9fe8 100644
--- a/sys/i386/i386/uio_machdep.c
+++ b/sys/i386/i386/uio_machdep.c
@@ -56,13 +56,12 @@ int
 uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
 {
 	struct sf_buf *sf;
-	struct thread *td = curthread;
 	struct iovec *iov;
 	void *cp;
 	vm_offset_t page_offset;
 	size_t cnt;
 	int error = 0;
-	int save = 0;
+	int save;
 
 	KASSERT(uio->uio_rw == UIO_READ || uio->uio_rw == UIO_WRITE,
 	    ("uiomove_fromphys: mode"));
@@ -71,8 +70,7 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
 	KASSERT(uio->uio_resid >= 0,
 	    ("%s: uio %p resid underflow", __func__, uio));
 
-	save = td->td_pflags & TDP_DEADLKTREAT;
-	td->td_pflags |= TDP_DEADLKTREAT;
+	save = curthread_pflags_set(TDP_DEADLKTREAT);
 	while (n > 0 && uio->uio_resid) {
 		KASSERT(uio->uio_iovcnt > 0,
 		    ("%s: uio %p iovcnt underflow", __func__, uio));
@@ -103,8 +101,6 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
 		offset += cnt;
 		n -= cnt;
 	}
-out:
-	if (save == 0)
-		td->td_pflags &= ~TDP_DEADLKTREAT;
+	curthread_pflags_restore(save);
 	return (error);
 }
diff --git a/sys/kern/subr_uio.c b/sys/kern/subr_uio.c
index fea1395a7f77..7e492d8aa705 100644
--- a/sys/kern/subr_uio.c
+++ b/sys/kern/subr_uio.c
@@ -241,7 +241,7 @@ uiomove_faultflag(void *cp, int n, struct uio *uio, int nofault)
 	size_t cnt;
 	int error, newflags, save;
 
-	save = error = 0;
+	error = 0;
 
 	KASSERT(uio->uio_rw == UIO_READ || uio->uio_rw == UIO_WRITE,
 	    ("uiomove: mode"));
@@ -264,6 +264,7 @@ uiomove_faultflag(void *cp, int n, struct uio *uio, int nofault)
 		save = curthread_pflags_set(newflags);
 	} else {
 		KASSERT(nofault == 0, ("uiomove: nofault"));
+		save = 0;
 	}
 
 	while (n > 0 && uio->uio_resid) {
@@ -291,8 +292,7 @@ uiomove_faultflag(void *cp, int n, struct uio *uio, int nofault)
 		n -= cnt;
 	}
 out:
-	if (save)
-		curthread_pflags_restore(save);
+	curthread_pflags_restore(save);
 	return (error);
 }
 
diff --git a/sys/powerpc/powerpc/uio_machdep.c b/sys/powerpc/powerpc/uio_machdep.c
index 05d06a95f544..2df39c12ba90 100644
--- a/sys/powerpc/powerpc/uio_machdep.c
+++ b/sys/powerpc/powerpc/uio_machdep.c
@@ -58,14 +58,13 @@
 int
 uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
 {
-	struct thread *td = curthread;
 	struct iovec *iov;
 	void *cp;
 	vm_offset_t page_offset;
 	vm_page_t m;
 	size_t cnt;
 	int error = 0;
-	int save = 0;
+	int save;
 	struct sf_buf *sf;
 
 	KASSERT(uio->uio_rw == UIO_READ || uio->uio_rw == UIO_WRITE,
@@ -75,8 +74,7 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
 	KASSERT(uio->uio_resid >= 0,
 	    ("%s: uio %p resid underflow", __func__, uio));
 
-	save = td->td_pflags & TDP_DEADLKTREAT;
-	td->td_pflags |= TDP_DEADLKTREAT;
+	save = curthread_pflags_set(TDP_DEADLKTREAT);
 	while (n > 0 && uio->uio_resid) {
 		KASSERT(uio->uio_iovcnt > 0,
 		    ("%s: uio %p iovcnt underflow", __func__, uio));
@@ -108,7 +106,6 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
 		offset += cnt;
 		n -= cnt;
 	}
-	if (save == 0)
-		td->td_pflags &= ~TDP_DEADLKTREAT;
+	curthread_pflags_restore(save);
 	return (error);
 }
diff --git a/sys/riscv/riscv/uio_machdep.c b/sys/riscv/riscv/uio_machdep.c
index 77f596498c45..b7191f48ac61 100644
--- a/sys/riscv/riscv/uio_machdep.c
+++ b/sys/riscv/riscv/uio_machdep.c
@@ -53,13 +53,12 @@
 int
 uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
 {
-	struct thread *td = curthread;
 	struct iovec *iov;
 	void *cp, *vaddr;
 	vm_offset_t page_offset;
 	size_t cnt;
 	int error = 0;
-	int save = 0;
+	int save;
 	bool mapped;
 
 	KASSERT(uio->uio_rw == UIO_READ || uio->uio_rw == UIO_WRITE,
@@ -69,8 +68,7 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
 	KASSERT(uio->uio_resid >= 0,
 	    ("%s: uio %p resid underflow", __func__, uio));
 
-	save = td->td_pflags & TDP_DEADLKTREAT;
-	td->td_pflags |= TDP_DEADLKTREAT;
+	save = curthread_pflags_set(TDP_DEADLKTREAT);
 	mapped = false;
 	while (n > 0 && uio->uio_resid) {
 		KASSERT(uio->uio_iovcnt > 0,
@@ -107,7 +105,6 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio)
 		offset += cnt;
 		n -= cnt;
 	}
-	if (save == 0)
-		td->td_pflags &= ~TDP_DEADLKTREAT;
+	curthread_pflags_restore(save);
 	return (error);
 }