- From 05730ef9dd72acbad774e10f108a01a10eba9daf Mon Sep 17 00:00:00 2001
- From: Roland Mainz <roland.mainz@nrubsig.org>
- Date: Mon, 11 Aug 2025 11:15:05 +0200
- Subject: [PATCH 1/7] sys: |nfs41_downcall()| does not need to clear temporary
- |nfs41_updowncall_entry|
- |nfs41_downcall()| does not need to clear temporary |nfs41_updowncall_entry|.
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- sys/nfs41sys_updowncall.c | 5 +----
- 1 file changed, 1 insertion(+), 4 deletions(-)
- diff --git a/sys/nfs41sys_updowncall.c b/sys/nfs41sys_updowncall.c
- index 0b3b39c..3a1c135 100644
- --- a/sys/nfs41sys_updowncall.c
- +++ b/sys/nfs41sys_updowncall.c
- @@ -144,8 +144,6 @@ static void unmarshal_nfs41_header(
- nfs41_updowncall_entry *tmp,
- unsigned char **buf)
- {
- - RtlZeroMemory(tmp, sizeof(nfs41_updowncall_entry));
- -
- RtlCopyMemory(&tmp->xid, *buf, sizeof(tmp->xid));
- *buf += sizeof(tmp->xid);
- RtlCopyMemory(&tmp->opcode, *buf, sizeof(tmp->opcode));
- @@ -646,9 +644,8 @@ NTSTATUS nfs41_downcall(
- #endif /* DEBUG_PRINT_DOWNCALL_HEXBUF */
- #ifdef USE_STACK_FOR_DOWNCALL_UPDOWNCALLENTRY_MEM
- - nfs41_updowncall_entry stacktmp;
- + nfs41_updowncall_entry stacktmp; /* rename this to |header_tmp| */
- - (void)memset(&stacktmp, 0, sizeof(stacktmp));
- tmp = &stacktmp;
- #else
- tmp = nfs41_downcall_allocate_updowncall_entry();
- --
- 2.45.1
- From 8ba45eaf5cdc22d9006976e448b4ca28d3e5bda1 Mon Sep 17 00:00:00 2001
- From: Roland Mainz <roland.mainz@nrubsig.org>
- Date: Mon, 11 Aug 2025 11:18:23 +0200
- Subject: [PATCH 2/7] daemon: downcall should use the actual bytes written back
- to kernel for |DeviceIoControl()|
- Downcall should use the actual bytes written back to kernel for
- |DeviceIoControl()|, and not the maximum buffer size.
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- daemon/nfs41_daemon.c | 12 +++++++++---
- daemon/open.c | 7 ++++++-
- daemon/symlink.c | 4 ++++
- daemon/upcall.c | 9 ++++++++-
- 4 files changed, 27 insertions(+), 5 deletions(-)
- diff --git a/daemon/nfs41_daemon.c b/daemon/nfs41_daemon.c
- index 12d18b0..c798c28 100644
- --- a/daemon/nfs41_daemon.c
- +++ b/daemon/nfs41_daemon.c
- @@ -138,7 +138,7 @@ static unsigned int nfsd_worker_thread_main(void *args)
- // buffer used to process upcall, assumed to be fixed size.
- // if we ever need to handle non-cached IO, need to make it dynamic
- unsigned char outbuf[UPCALL_BUF_SIZE], inbuf[UPCALL_BUF_SIZE];
- - DWORD inbuf_len = UPCALL_BUF_SIZE, outbuf_len;
- + DWORD inbuf_len, outbuf_len;
- nfs41_upcall upcall;
- /*
- @@ -213,7 +213,7 @@ write_downcall:
- "get_last_error=%d\n", upcall.xid, opcode2string(upcall.opcode),
- upcall.status, upcall.last_error));
- - upcall_marshall(&upcall, inbuf, (uint32_t)inbuf_len, (uint32_t*)&outbuf_len);
- + upcall_marshall(&upcall, inbuf, UPCALL_BUF_SIZE, (uint32_t*)&inbuf_len);
- /*
- * Note: Caller impersonation ends with |IOCTL_NFS41_WRITE| -
- @@ -223,7 +223,13 @@ write_downcall:
- (void)CloseHandle(upcall.currentthread_token);
- upcall.currentthread_token = INVALID_HANDLE_VALUE;
- - DPRINTF(2, ("making a downcall: outbuf_len %ld\n\n", outbuf_len));
- + DPRINTF(2,
- + ("making a downcall: "
- + "xid=%lld inbuf_len=%ld opcode='%s' status=%d\n",
- + upcall.xid,
- + (long)inbuf_len,
- + opcode2string(upcall.opcode),
- + upcall.status));
- status = DeviceIoControl(pipe, IOCTL_NFS41_WRITE,
- inbuf, inbuf_len, NULL, 0, (LPDWORD)&outbuf_len, NULL);
- if (!status) {
- diff --git a/daemon/open.c b/daemon/open.c
- index d2c8bf3..ae1540c 100644
- --- a/daemon/open.c
- +++ b/daemon/open.c
- @@ -1227,7 +1227,10 @@ static int marshall_open(unsigned char *buffer, uint32_t *length, nfs41_upcall *
- if (status) goto out;
- status = safe_write(&buffer, length, &len, sizeof(len));
- if (status) goto out;
- - /* convert args->symlink to wchar */
- + /*
- + * convert args->symlink to wchar
- + * FIXME: What about |len| if we have characters outside the BMP ?
- + */
- if (*length <= len || !MultiByteToWideChar(CP_UTF8,
- MB_ERR_INVALID_CHARS,
- args->symlink.path, args->symlink.len,
- @@ -1235,6 +1238,8 @@ static int marshall_open(unsigned char *buffer, uint32_t *length, nfs41_upcall *
- status = ERROR_BUFFER_OVERFLOW;
- goto out;
- }
- +
- + *length -= len;
- }
- DPRINTF(2, ("NFS41_SYSOP_OPEN: downcall "
- "open_state=0x%p "
- diff --git a/daemon/symlink.c b/daemon/symlink.c
- index 8ddd70e..0a53de4 100644
- --- a/daemon/symlink.c
- +++ b/daemon/symlink.c
- @@ -297,6 +297,7 @@ static int marshall_symlink_get(unsigned char *buffer, uint32_t *length,
- goto out;
- }
- + /* FIXME: What about |len| if we have characters outside the BMP ? */
- if (!MultiByteToWideChar(CP_UTF8,
- MB_ERR_INVALID_CHARS,
- args->target_get.path, args->target_get.len,
- @@ -307,6 +308,9 @@ static int marshall_symlink_get(unsigned char *buffer, uint32_t *length,
- status = ERROR_BUFFER_OVERFLOW;
- goto out;
- }
- +
- + *length -= len;
- +
- out:
- return status;
- }
- diff --git a/daemon/upcall.c b/daemon/upcall.c
- index 93fc329..45e0729 100644
- --- a/daemon/upcall.c
- +++ b/daemon/upcall.c
- @@ -232,8 +232,15 @@ write_downcall:
- /* marshall the operation's results */
- op = g_upcall_op_table[upcall->opcode];
- if (op && op->marshall) {
- - if ((upcall->status = op->marshall(buffer, &length, upcall)))
- + if ((upcall->status = op->marshall(buffer, &length, upcall))) {
- + DPRINTF(0,
- + ("upcall_marshall: "
- + "marshall failed, op='%s' *length=%ld, status=0x%lx\n",
- + opcode2string(upcall->opcode),
- + (long)length,
- + (long)upcall->status));
- goto write_downcall;
- + }
- }
- out:
- *length_out = total - length;
- --
- 2.45.1
- From fba8c60743e5eb0dfe70bc16c42c528bb61fa8b9 Mon Sep 17 00:00:00 2001
- From: Roland Mainz <roland.mainz@nrubsig.org>
- Date: Mon, 11 Aug 2025 11:41:24 +0200
- Subject: [PATCH 3/7] sys: |IoCompleteRequest()| and |KeSetEvent()| should use
- priority boost
- |IoCompleteRequest()| and |KeSetEvent()| should use priority boost like
- the Windows SMB driver does.
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- sys/nfs41sys_driver.c | 2 +-
- sys/nfs41sys_driver.h | 3 +++
- sys/nfs41sys_mount.c | 4 ++--
- sys/nfs41sys_updowncall.c | 11 ++++++-----
- 4 files changed, 12 insertions(+), 8 deletions(-)
- diff --git a/sys/nfs41sys_driver.c b/sys/nfs41sys_driver.c
- index 628789f..7cf2445 100644
- --- a/sys/nfs41sys_driver.c
- +++ b/sys/nfs41sys_driver.c
- @@ -976,7 +976,7 @@ NTSTATUS nfs41_FsdDispatch(
- print_error("*** not ours ***\n");
- Irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
- Irp->IoStatus.Information = 0;
- - IoCompleteRequest(Irp, IO_NO_INCREMENT );
- + IoCompleteRequest(Irp, IO_NFS41FS_INCREMENT);
- status = STATUS_INVALID_DEVICE_REQUEST;
- goto out;
- }
- diff --git a/sys/nfs41sys_driver.h b/sys/nfs41sys_driver.h
- index 6f57818..17965a7 100644
- --- a/sys/nfs41sys_driver.h
- +++ b/sys/nfs41sys_driver.h
- @@ -92,6 +92,9 @@ typedef struct __nfs41_timings {
- } nfs41_timings;
- #endif /* ENABLE_TIMINGS */
- +/* Windows SMB driver also uses |IO_NFS41FS_INCREMENT| */
- +#define IO_NFS41FS_INCREMENT IO_NETWORK_INCREMENT
- +
- #define DISABLE_CACHING 0
- #define ENABLE_READ_CACHING 1
- #define ENABLE_WRITE_CACHING 2
- diff --git a/sys/nfs41sys_mount.c b/sys/nfs41sys_mount.c
- index f2d7d81..9fa2ccd 100644
- --- a/sys/nfs41sys_mount.c
- +++ b/sys/nfs41sys_mount.c
- @@ -1414,7 +1414,7 @@ NTSTATUS nfs41_FinalizeNetRoot(
- DbgP("Removing entry from upcall list\n");
- nfs41_RemoveEntry(upcallLock, tmp);
- tmp->status = STATUS_INSUFFICIENT_RESOURCES;
- - KeSetEvent(&tmp->cond, 0, FALSE);
- + (void)KeSetEvent(&tmp->cond, IO_NFS41FS_INCREMENT, FALSE);
- } else
- break;
- } while (1);
- @@ -1425,7 +1425,7 @@ NTSTATUS nfs41_FinalizeNetRoot(
- DbgP("Removing entry from downcall list\n");
- nfs41_RemoveEntry(downcallLock, tmp);
- tmp->status = STATUS_INSUFFICIENT_RESOURCES;
- - KeSetEvent(&tmp->cond, 0, FALSE);
- + (void)KeSetEvent(&tmp->cond, IO_NFS41FS_INCREMENT, FALSE);
- } else
- break;
- } while (1);
- diff --git a/sys/nfs41sys_updowncall.c b/sys/nfs41sys_updowncall.c
- index 3a1c135..deba9d6 100644
- --- a/sys/nfs41sys_updowncall.c
- +++ b/sys/nfs41sys_updowncall.c
- @@ -257,7 +257,7 @@ NTSTATUS handle_upcall(
- switch(entry->opcode) {
- case NFS41_SYSOP_SHUTDOWN:
- status = marshal_nfs41_shutdown(entry, pbOut, cbOut, len);
- - KeSetEvent(&entry->cond, 0, FALSE);
- + (void)KeSetEvent(&entry->cond, IO_NFS41FS_INCREMENT, FALSE);
- break;
- case NFS41_SYSOP_MOUNT:
- status = marshal_nfs41_mount(entry, pbOut, cbOut, len);
- @@ -518,7 +518,7 @@ NTSTATUS nfs41_UpcallWaitForReply(
- FsRtlEnterFileSystem();
- nfs41_AddEntry(upcallLock, upcall, entry);
- - KeSetEvent(&upcallEvent, 0, FALSE);
- + (void)KeSetEvent(&upcallEvent, IO_NFS41FS_INCREMENT, FALSE);
- if (entry->async_op)
- goto out;
- @@ -597,7 +597,7 @@ process_upcall:
- ExReleaseFastMutex(&entry->lock);
- if (status) {
- entry->status = status;
- - KeSetEvent(&entry->cond, 0, FALSE);
- + (void)KeSetEvent(&entry->cond, IO_NFS41FS_INCREMENT, FALSE);
- RxContext->InformationToReturn = 0;
- } else
- RxContext->InformationToReturn = len;
- @@ -807,8 +807,9 @@ NTSTATUS nfs41_downcall(
- (int)cur->opcode);
- break;
- }
- - } else
- - KeSetEvent(&cur->cond, 0, FALSE);
- + } else {
- + (void)KeSetEvent(&cur->cond, IO_NFS41FS_INCREMENT, FALSE);
- + }
- out_free:
- #ifdef USE_STACK_FOR_DOWNCALL_UPDOWNCALLENTRY_MEM
- --
- 2.45.1
- From f336f52a31acef508fd54bfbd1bb4263c876f5a4 Mon Sep 17 00:00:00 2001
- From: Dan Shelton <dan.f.shelton@gmail.com>
- Date: Mon, 11 Aug 2025 12:04:57 +0200
- Subject: [PATCH 4/7] sys: Driver should use ExAcquireFastMutexUnsafe() and
- ExReleaseFastMutexUnsafe()
- ExAcquireFastMutexUnsafe() and ExReleaseFastMutexUnsafe() inside
- FsRtlEnterFileSystem()/FsRtlExitFileSystem().
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- sys/nfs41sys_driver.c | 20 ++++++++++----------
- sys/nfs41sys_driver.h | 24 ++++++++++++------------
- sys/nfs41sys_mount.c | 8 ++++----
- sys/nfs41sys_updowncall.c | 29 +++++++++++++++++++----------
- 4 files changed, 45 insertions(+), 36 deletions(-)
- diff --git a/sys/nfs41sys_driver.c b/sys/nfs41sys_driver.c
- index 7cf2445..bfde496 100644
- --- a/sys/nfs41sys_driver.c
- +++ b/sys/nfs41sys_driver.c
- @@ -686,7 +686,7 @@ VOID nfs41_remove_fcb_entry(
- {
- PLIST_ENTRY pEntry;
- nfs41_fcb_list_entry *cur;
- - ExAcquireFastMutex(&fcblistLock);
- + ExAcquireFastMutexUnsafe(&fcblistLock);
- pEntry = openlist.head.Flink;
- while (!IsListEmpty(&openlist.head)) {
- @@ -709,7 +709,7 @@ VOID nfs41_remove_fcb_entry(
- }
- pEntry = pEntry->Flink;
- }
- - ExReleaseFastMutex(&fcblistLock);
- + ExReleaseFastMutexUnsafe(&fcblistLock);
- }
- static
- @@ -720,7 +720,7 @@ VOID nfs41_invalidate_fobx_entry(
- nfs41_fcb_list_entry *cur;
- __notnull PNFS41_FOBX nfs41_fobx = NFS41GetFobxExtension(pFobx);
- - ExAcquireFastMutex(&fcblistLock);
- + ExAcquireFastMutexUnsafe(&fcblistLock);
- pEntry = openlist.head.Flink;
- while (!IsListEmpty(&openlist.head)) {
- @@ -743,7 +743,7 @@ VOID nfs41_invalidate_fobx_entry(
- }
- pEntry = pEntry->Flink;
- }
- - ExReleaseFastMutex(&fcblistLock);
- + ExReleaseFastMutexUnsafe(&fcblistLock);
- }
- NTSTATUS nfs41_Flush(
- @@ -788,7 +788,7 @@ VOID nfs41_update_fcb_list(
- {
- PLIST_ENTRY pEntry;
- nfs41_fcb_list_entry *cur;
- - ExAcquireFastMutex(&fcblistLock);
- + ExAcquireFastMutexUnsafe(&fcblistLock);
- pEntry = openlist.head.Flink;
- while (!IsListEmpty(&openlist.head)) {
- cur = (nfs41_fcb_list_entry *)CONTAINING_RECORD(pEntry,
- @@ -815,7 +815,7 @@ VOID nfs41_update_fcb_list(
- }
- pEntry = pEntry->Flink;
- }
- - ExReleaseFastMutex(&fcblistLock);
- + ExReleaseFastMutexUnsafe(&fcblistLock);
- }
- NTSTATUS nfs41_IsValidDirectory (
- @@ -903,7 +903,7 @@ void enable_caching(
- RxChangeBufferingState((PSRV_OPEN)SrvOpen, ULongToPtr(flag), 1);
- - ExAcquireFastMutex(&fcblistLock);
- + ExAcquireFastMutexUnsafe(&fcblistLock);
- pEntry = openlist.head.Flink;
- while (!IsListEmpty(&openlist.head)) {
- cur = (nfs41_fcb_list_entry *)CONTAINING_RECORD(pEntry,
- @@ -943,7 +943,7 @@ void enable_caching(
- nfs41_fobx->deleg_type = 0;
- }
- out_release_fcblistlock:
- - ExReleaseFastMutex(&fcblistLock);
- + ExReleaseFastMutexUnsafe(&fcblistLock);
- }
- NTSTATUS nfs41_CompleteBufferingStateChangeRequest(
- @@ -1231,7 +1231,7 @@ VOID fcbopen_main(PVOID ctx)
- PLIST_ENTRY pEntry;
- nfs41_fcb_list_entry *cur;
- status = KeDelayExecutionThread(KernelMode, TRUE, &timeout);
- - ExAcquireFastMutex(&fcblistLock);
- + ExAcquireFastMutexUnsafe(&fcblistLock);
- pEntry = openlist.head.Flink;
- while (!IsListEmpty(&openlist.head)) {
- PNFS41_NETROOT_EXTENSION pNetRootContext;
- @@ -1328,7 +1328,7 @@ out:
- }
- pEntry = pEntry->Flink;
- }
- - ExReleaseFastMutex(&fcblistLock);
- + ExReleaseFastMutexUnsafe(&fcblistLock);
- }
- // DbgEx();
- }
- diff --git a/sys/nfs41sys_driver.h b/sys/nfs41sys_driver.h
- index 17965a7..a2d5ed6 100644
- --- a/sys/nfs41sys_driver.h
- +++ b/sys/nfs41sys_driver.h
- @@ -354,41 +354,41 @@ typedef struct _nfs41_mount_list {
- } nfs41_mount_list;
- #define nfs41_AddEntry(lock,list,pEntry) \
- - ExAcquireFastMutex(&lock); \
- + ExAcquireFastMutexUnsafe(&lock); \
- InsertTailList(&(list).head, &(pEntry)->next); \
- - ExReleaseFastMutex(&lock);
- + ExReleaseFastMutexUnsafe(&lock);
- #define nfs41_RemoveFirst(lock,list,pEntry) \
- - ExAcquireFastMutex(&lock); \
- + ExAcquireFastMutexUnsafe(&lock); \
- pEntry = (IsListEmpty(&(list).head) \
- ? NULL \
- : RemoveHeadList(&(list).head)); \
- - ExReleaseFastMutex(&lock);
- + ExReleaseFastMutexUnsafe(&lock);
- #define nfs41_RemoveEntry(lock,pEntry) \
- - ExAcquireFastMutex(&lock); \
- + ExAcquireFastMutexUnsafe(&lock); \
- RemoveEntryList(&pEntry->next); \
- - ExReleaseFastMutex(&lock);
- + ExReleaseFastMutexUnsafe(&lock);
- #define nfs41_IsListEmpty(lock,list,flag) \
- - ExAcquireFastMutex(&lock); \
- + ExAcquireFastMutexUnsafe(&lock); \
- flag = IsListEmpty(&(list).head); \
- - ExReleaseFastMutex(&lock);
- + ExReleaseFastMutexUnsafe(&lock);
- #define nfs41_GetFirstEntry(lock,list,pEntry) \
- - ExAcquireFastMutex(&lock); \
- + ExAcquireFastMutexUnsafe(&lock); \
- pEntry = (IsListEmpty(&(list).head) \
- ? NULL \
- : (nfs41_updowncall_entry *) \
- (CONTAINING_RECORD((list).head.Flink, \
- nfs41_updowncall_entry, \
- next))); \
- - ExReleaseFastMutex(&lock);
- + ExReleaseFastMutexUnsafe(&lock);
- #define nfs41_GetFirstMountEntry(lock,list,pEntry) \
- - ExAcquireFastMutex(&lock); \
- + ExAcquireFastMutexUnsafe(&lock); \
- pEntry = (IsListEmpty(&(list).head) \
- ? NULL \
- : (nfs41_mount_entry *) \
- (CONTAINING_RECORD((list).head.Flink, \
- nfs41_mount_entry, \
- next))); \
- - ExReleaseFastMutex(&lock);
- + ExReleaseFastMutexUnsafe(&lock);
- typedef struct _NFS41_NETROOT_EXTENSION {
- diff --git a/sys/nfs41sys_mount.c b/sys/nfs41sys_mount.c
- index 9fa2ccd..4ed1e1c 100644
- --- a/sys/nfs41sys_mount.c
- +++ b/sys/nfs41sys_mount.c
- @@ -954,7 +954,7 @@ NTSTATUS nfs41_CreateVNetRoot(
- status = STATUS_NFS_SHARE_NOT_MOUNTED;
- - ExAcquireFastMutex(&pNetRootContext->mountLock);
- + ExAcquireFastMutexUnsafe(&pNetRootContext->mountLock);
- pEntry = &pNetRootContext->mounts.head;
- pEntry = pEntry->Flink;
- while (pEntry != NULL) {
- @@ -1007,7 +1007,7 @@ NTSTATUS nfs41_CreateVNetRoot(
- status = STATUS_SUCCESS;
- }
- #endif /* NFS41_DRIVER_SYSTEM_LUID_MOUNTS_ARE_GLOBAL */
- - ExReleaseFastMutex(&pNetRootContext->mountLock);
- + ExReleaseFastMutexUnsafe(&pNetRootContext->mountLock);
- if (status != STATUS_SUCCESS) {
- DbgP("No existing mount found, "
- @@ -1085,7 +1085,7 @@ NTSTATUS nfs41_CreateVNetRoot(
- } else {
- PLIST_ENTRY pEntry;
- - ExAcquireFastMutex(&pNetRootContext->mountLock);
- + ExAcquireFastMutexUnsafe(&pNetRootContext->mountLock);
- pEntry = &pNetRootContext->mounts.head;
- pEntry = pEntry->Flink;
- while (pEntry != NULL) {
- @@ -1135,7 +1135,7 @@ NTSTATUS nfs41_CreateVNetRoot(
- break;
- pEntry = pEntry->Flink;
- }
- - ExReleaseFastMutex(&pNetRootContext->mountLock);
- + ExReleaseFastMutexUnsafe(&pNetRootContext->mountLock);
- #ifdef DEBUG_MOUNT
- if (!found_matching_flavor)
- DbgP("Didn't find matching security flavor\n");
- diff --git a/sys/nfs41sys_updowncall.c b/sys/nfs41sys_updowncall.c
- index deba9d6..cf5be35 100644
- --- a/sys/nfs41sys_updowncall.c
- +++ b/sys/nfs41sys_updowncall.c
- @@ -553,9 +553,9 @@ retry_wait:
- }
- /* fall-through */
- default:
- - ExAcquireFastMutex(&entry->lock);
- + ExAcquireFastMutexUnsafe(&entry->lock);
- if (entry->state == NFS41_DONE_PROCESSING) {
- - ExReleaseFastMutex(&entry->lock);
- + ExReleaseFastMutexUnsafe(&entry->lock);
- break;
- }
- DbgP("[upcall] abandoning '%s' entry=0x%p xid=%lld\n",
- @@ -563,7 +563,7 @@ retry_wait:
- entry,
- (entry?entry->xid:-1LL));
- entry->state = NFS41_NOT_WAITING;
- - ExReleaseFastMutex(&entry->lock);
- + ExReleaseFastMutexUnsafe(&entry->lock);
- goto out;
- }
- nfs41_RemoveEntry(downcallLock, entry);
- @@ -581,6 +581,8 @@ NTSTATUS nfs41_upcall(
- ULONG len = 0;
- PLIST_ENTRY pEntry = NULL;
- + FsRtlEnterFileSystem();
- +
- process_upcall:
- nfs41_RemoveFirst(upcallLock, upcall, pEntry);
- if (pEntry) {
- @@ -588,13 +590,13 @@ process_upcall:
- entry = (nfs41_updowncall_entry *)CONTAINING_RECORD(pEntry,
- nfs41_updowncall_entry, next);
- - ExAcquireFastMutex(&entry->lock);
- + ExAcquireFastMutexUnsafe(&entry->lock);
- nfs41_AddEntry(downcallLock, downcall, entry);
- status = handle_upcall(RxContext, entry, &len);
- if (status == STATUS_SUCCESS &&
- entry->state == NFS41_WAITING_FOR_UPCALL)
- entry->state = NFS41_WAITING_FOR_DOWNCALL;
- - ExReleaseFastMutex(&entry->lock);
- + ExReleaseFastMutexUnsafe(&entry->lock);
- if (status) {
- entry->status = status;
- (void)KeSetEvent(&entry->cond, IO_NFS41FS_INCREMENT, FALSE);
- @@ -622,7 +624,10 @@ process_upcall:
- goto out;
- }
- }
- +
- out:
- + FsRtlExitFileSystem();
- +
- return status;
- }
- @@ -639,6 +644,8 @@ NTSTATUS nfs41_downcall(
- nfs41_updowncall_entry *tmp, *cur= NULL;
- BOOLEAN found = 0;
- + FsRtlEnterFileSystem();
- +
- #ifdef DEBUG_PRINT_DOWNCALL_HEXBUF
- print_hexbuf("downcall buffer", buf, in_len);
- #endif /* DEBUG_PRINT_DOWNCALL_HEXBUF */
- @@ -657,7 +664,7 @@ NTSTATUS nfs41_downcall(
- unmarshal_nfs41_header(tmp, &buf);
- - ExAcquireFastMutex(&downcallLock);
- + ExAcquireFastMutexUnsafe(&downcallLock);
- pEntry = &downcall.head;
- pEntry = pEntry->Flink;
- while (pEntry != NULL) {
- @@ -671,7 +678,7 @@ NTSTATUS nfs41_downcall(
- break;
- pEntry = pEntry->Flink;
- }
- - ExReleaseFastMutex(&downcallLock);
- + ExReleaseFastMutexUnsafe(&downcallLock);
- SeStopImpersonatingClient();
- if (!found) {
- print_error("Didn't find xid=%lld entry\n", tmp->xid);
- @@ -679,7 +686,7 @@ NTSTATUS nfs41_downcall(
- goto out_free;
- }
- - ExAcquireFastMutex(&cur->lock);
- + ExAcquireFastMutexUnsafe(&cur->lock);
- if (cur->state == NFS41_NOT_WAITING) {
- DbgP("[downcall] Nobody is waiting for this request!!!\n");
- switch(cur->opcode) {
- @@ -719,7 +726,7 @@ NTSTATUS nfs41_downcall(
- }
- break;
- }
- - ExReleaseFastMutex(&cur->lock);
- + ExReleaseFastMutexUnsafe(&cur->lock);
- nfs41_RemoveEntry(downcallLock, cur);
- nfs41_UpcallDestroy(cur);
- status = STATUS_UNSUCCESSFUL;
- @@ -782,7 +789,7 @@ NTSTATUS nfs41_downcall(
- break;
- }
- }
- - ExReleaseFastMutex(&cur->lock);
- + ExReleaseFastMutexUnsafe(&cur->lock);
- if (cur->async_op) {
- switch (cur->opcode) {
- case NFS41_SYSOP_WRITE:
- @@ -819,5 +826,7 @@ out_free:
- out:
- #endif /* USE_STACK_FOR_DOWNCALL_UPDOWNCALLENTRY_MEM */
- + FsRtlExitFileSystem();
- +
- return status;
- }
- --
- 2.45.1
- From d22f8522de9b6b33248d263be8cb3b6a65143b0e Mon Sep 17 00:00:00 2001
- From: Dan Shelton <dan.f.shelton@gmail.com>
- Date: Mon, 11 Aug 2025 12:24:12 +0200
- Subject: [PATCH 5/7] include,sys: Cleanup kernel module C preprocessor macros
- for ReactOS/clang
- Cleanup kernel module C preprocessor macros for ReactOS/clang.
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- include/nfs41_driver.h | 5 +++-
- sys/nfs41sys_driver.h | 54 ++++++++++++++++++++++++++----------------
- 2 files changed, 37 insertions(+), 22 deletions(-)
- diff --git a/include/nfs41_driver.h b/include/nfs41_driver.h
- index 31dd4c8..bf956f4 100644
- --- a/include/nfs41_driver.h
- +++ b/include/nfs41_driver.h
- @@ -38,7 +38,10 @@
- // See "Defining I/O Control Codes" in WDK docs
- #define _RDR_CTL_CODE(code, method) \
- - CTL_CODE(FILE_DEVICE_NETWORK_REDIRECTOR, 0x800 | (code), method, FILE_ANY_ACCESS)
- + CTL_CODE(FILE_DEVICE_NETWORK_REDIRECTOR, \
- + (0x800 | (code)), \
- + (method), \
- + FILE_ANY_ACCESS)
- #define IOCTL_NFS41_START _RDR_CTL_CODE(0, METHOD_BUFFERED)
- #define IOCTL_NFS41_STOP _RDR_CTL_CODE(1, METHOD_NEITHER)
- diff --git a/sys/nfs41sys_driver.h b/sys/nfs41sys_driver.h
- index a2d5ed6..b1db3f5 100644
- --- a/sys/nfs41sys_driver.h
- +++ b/sys/nfs41sys_driver.h
- @@ -354,41 +354,53 @@ typedef struct _nfs41_mount_list {
- } nfs41_mount_list;
- #define nfs41_AddEntry(lock,list,pEntry) \
- - ExAcquireFastMutexUnsafe(&lock); \
- + { \
- + ExAcquireFastMutexUnsafe(&(lock)); \
- InsertTailList(&(list).head, &(pEntry)->next); \
- - ExReleaseFastMutexUnsafe(&lock);
- + ExReleaseFastMutexUnsafe(&(lock)); \
- + }
- #define nfs41_RemoveFirst(lock,list,pEntry) \
- - ExAcquireFastMutexUnsafe(&lock); \
- - pEntry = (IsListEmpty(&(list).head) \
- + { \
- + ExAcquireFastMutexUnsafe(&(lock)); \
- + (pEntry) = (IsListEmpty(&(list).head) \
- ? NULL \
- : RemoveHeadList(&(list).head)); \
- - ExReleaseFastMutexUnsafe(&lock);
- + ExReleaseFastMutexUnsafe(&(lock)); \
- + }
- #define nfs41_RemoveEntry(lock,pEntry) \
- - ExAcquireFastMutexUnsafe(&lock); \
- - RemoveEntryList(&pEntry->next); \
- - ExReleaseFastMutexUnsafe(&lock);
- + { \
- + ExAcquireFastMutexUnsafe(&(lock)); \
- + RemoveEntryList(&(pEntry)->next); \
- + ExReleaseFastMutexUnsafe(&(lock)); \
- + }
- #define nfs41_IsListEmpty(lock,list,flag) \
- - ExAcquireFastMutexUnsafe(&lock); \
- - flag = IsListEmpty(&(list).head); \
- - ExReleaseFastMutexUnsafe(&lock);
- + { \
- + ExAcquireFastMutexUnsafe(&(lock)); \
- + (flag) = IsListEmpty(&(list).head); \
- + ExReleaseFastMutexUnsafe(&(lock)); \
- + }
- #define nfs41_GetFirstEntry(lock,list,pEntry) \
- - ExAcquireFastMutexUnsafe(&lock); \
- - pEntry = (IsListEmpty(&(list).head) \
- + { \
- + ExAcquireFastMutexUnsafe(&(lock)); \
- + (pEntry) = (IsListEmpty(&(list).head) \
- ? NULL \
- : (nfs41_updowncall_entry *) \
- (CONTAINING_RECORD((list).head.Flink, \
- nfs41_updowncall_entry, \
- next))); \
- - ExReleaseFastMutexUnsafe(&lock);
- + ExReleaseFastMutexUnsafe(&(lock)); \
- + }
- #define nfs41_GetFirstMountEntry(lock,list,pEntry) \
- - ExAcquireFastMutexUnsafe(&lock); \
- - pEntry = (IsListEmpty(&(list).head) \
- + { \
- + ExAcquireFastMutexUnsafe(&(lock)); \
- + (pEntry) = (IsListEmpty(&(list).head) \
- ? NULL \
- : (nfs41_mount_entry *) \
- (CONTAINING_RECORD((list).head.Flink, \
- nfs41_mount_entry, \
- next))); \
- - ExReleaseFastMutexUnsafe(&lock);
- + ExReleaseFastMutexUnsafe(&(lock)); \
- + }
- typedef struct _NFS41_NETROOT_EXTENSION {
- @@ -477,8 +489,8 @@ typedef struct _NFS41_DEVICE_EXTENSION {
- } NFS41_DEVICE_EXTENSION, *PNFS41_DEVICE_EXTENSION;
- #define NFS41GetDeviceExtension(RxContext,pExt) \
- - PNFS41_DEVICE_EXTENSION pExt = (PNFS41_DEVICE_EXTENSION) \
- - ((PBYTE)(RxContext->RxDeviceObject) + sizeof(RDBSS_DEVICE_OBJECT))
- + PNFS41_DEVICE_EXTENSION (pExt) = (PNFS41_DEVICE_EXTENSION) \
- + ((PBYTE)((RxContext)->RxDeviceObject) + sizeof(RDBSS_DEVICE_OBJECT))
- typedef struct _nfs41_fcb_list_entry {
- LIST_ENTRY next;
- @@ -498,8 +510,8 @@ typedef enum _NULMRX_STORAGE_TYPE_CODES {
- NTC_NFS41_DEVICE_EXTENSION = (NODE_TYPE_CODE)0xFC00,
- } NFS41_STORAGE_TYPE_CODES;
- #define RxDefineNode( node, type ) \
- - node->NodeTypeCode = NTC_##type; \
- - node->NodeByteSize = sizeof(type);
- + (node)->NodeTypeCode = NTC_##type; \
- + (node)->NodeByteSize = sizeof(type);
- #define RDR_NULL_STATE 0
- #define RDR_UNLOADED 1
- --
- 2.45.1
- From 9b32fbd7dec343051d6bcbf54506aa2ce90d438b Mon Sep 17 00:00:00 2001
- From: Dan Shelton <dan.f.shelton@gmail.com>
- Date: Mon, 11 Aug 2025 13:12:21 +0200
- Subject: [PATCH 6/7] daemon: Add {...} brackets to debug macros
- Add {...} brackets to debug macros to avoid confusion in nested
- if()/else statements.
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- daemon/daemon_debug.h | 88 ++++++++++++++++++++++++-------------------
- 1 file changed, 49 insertions(+), 39 deletions(-)
- diff --git a/daemon/daemon_debug.h b/daemon/daemon_debug.h
- index 16e450b..896481b 100644
- --- a/daemon/daemon_debug.h
- +++ b/daemon/daemon_debug.h
- @@ -56,55 +56,65 @@
- #endif /* _WIN64 */
- #define EASSERT(exp) \
- - if (!(exp)) { \
- - DWORD d_saved_lasterr = GetLastError(); \
- - eprintf("ASSERTION '%s' in '%s'/%ld failed.\n", \
- - ""#exp"", __FILE__, (long)__LINE__); \
- - SetLastError(d_saved_lasterr); \
- + { \
- + if (!(exp)) { \
- + DWORD d_saved_lasterr = GetLastError(); \
- + eprintf("ASSERTION '%s' in '%s'/%ld failed.\n", \
- + ""#exp"", __FILE__, (long)__LINE__); \
- + SetLastError(d_saved_lasterr); \
- + } \
- }
- #define EASSERT_MSG(exp, msg) \
- - if (!(exp)) { \
- - DWORD d_saved_lasterr = GetLastError(); \
- - eprintf("ASSERTION '%s' in '%s'/%ld failed, msg=", \
- - ""#exp"", __FILE__, (long)__LINE__); \
- - eprintf_out msg ; \
- - SetLastError(d_saved_lasterr); \
- + { \
- + if (!(exp)) { \
- + DWORD d_saved_lasterr = GetLastError(); \
- + eprintf("ASSERTION '%s' in '%s'/%ld failed, msg=", \
- + ""#exp"", __FILE__, (long)__LINE__); \
- + eprintf_out msg ; \
- + SetLastError(d_saved_lasterr); \
- + } \
- }
- #define DASSERT(exp, level) \
- - if (!(exp) && DPRINTF_LEVEL_ENABLED(level)) { \
- - DWORD d_saved_lasterr = GetLastError(); \
- - dprintf_out("ASSERTION '%s' in '%s'/%ld failed.\n", \
- - ""#exp"", __FILE__, (long)__LINE__); \
- - SetLastError(d_saved_lasterr); \
- + { \
- + if ((!(exp)) && DPRINTF_LEVEL_ENABLED(level)) { \
- + DWORD d_saved_lasterr = GetLastError(); \
- + dprintf_out("ASSERTION '%s' in '%s'/%ld failed.\n", \
- + ""#exp"", __FILE__, (long)__LINE__); \
- + SetLastError(d_saved_lasterr); \
- + } \
- }
- #define DASSERT_MSG(exp, level, msg) \
- - if (!(exp) && DPRINTF_LEVEL_ENABLED(level)) { \
- - DWORD d_saved_lasterr = GetLastError(); \
- - dprintf_out("ASSERTION '%s' in '%s'/%ld failed, msg=", \
- - ""#exp"", __FILE__, (long)__LINE__); \
- - dprintf_out msg ; \
- - SetLastError(d_saved_lasterr); \
- + { \
- + if (!(exp) && DPRINTF_LEVEL_ENABLED(level)) { \
- + DWORD d_saved_lasterr = GetLastError(); \
- + dprintf_out("ASSERTION '%s' in '%s'/%ld failed, msg=", \
- + ""#exp"", __FILE__, (long)__LINE__); \
- + dprintf_out msg ; \
- + SetLastError(d_saved_lasterr); \
- + } \
- }
- -
- #define DASSERT_IS_VALID_NON_NULL_PTR(exp, level) \
- - if (!DEBUG_IS_VALID_NON_NULL_PTR(exp) && \
- - DPRINTF_LEVEL_ENABLED(level)) { \
- - DWORD d_saved_lasterr = GetLastError(); \
- - dprintf_out("ASSERTION " \
- - "!DEBUG_IS_VALID_NON_NULL_PTR('%s'=0x%p) " \
- - "in '%s'/%ld failed.\n", \
- - ""#exp"", (void *)(exp), __FILE__, (long)__LINE__); \
- - SetLastError(d_saved_lasterr); \
- + { \
- + if (!DEBUG_IS_VALID_NON_NULL_PTR(exp) && \
- + DPRINTF_LEVEL_ENABLED(level)) { \
- + DWORD d_saved_lasterr = GetLastError(); \
- + dprintf_out("ASSERTION " \
- + "!DEBUG_IS_VALID_NON_NULL_PTR('%s'=0x%p) " \
- + "in '%s'/%ld failed.\n", \
- + ""#exp"", (void *)(exp), __FILE__, (long)__LINE__); \
- + SetLastError(d_saved_lasterr); \
- + } \
- }
- -
- #define EASSERT_IS_VALID_NON_NULL_PTR(exp) \
- - if (!DEBUG_IS_VALID_NON_NULL_PTR(exp)) { \
- - DWORD d_saved_lasterr = GetLastError(); \
- - eprintf("ASSERTION " \
- - "!DEBUG_IS_VALID_NON_NULL_PTR('%s'=0x%p) " \
- - "in '%s'/%ld failed.\n", \
- - ""#exp"", (void *)(exp), __FILE__, (long)__LINE__); \
- - SetLastError(d_saved_lasterr); \
- + { \
- + if (!DEBUG_IS_VALID_NON_NULL_PTR(exp)) { \
- + DWORD d_saved_lasterr = GetLastError(); \
- + eprintf("ASSERTION " \
- + "!DEBUG_IS_VALID_NON_NULL_PTR('%s'=0x%p) " \
- + "in '%s'/%ld failed.\n", \
- + ""#exp"", (void *)(exp), __FILE__, (long)__LINE__); \
- + SetLastError(d_saved_lasterr); \
- + } \
- }
- extern int g_debug_level;
- --
- 2.45.1
- From 9afa46207675fcbfb7a68b93de5e08f365bd6bd5 Mon Sep 17 00:00:00 2001
- From: Dan Shelton <dan.f.shelton@gmail.com>
- Date: Mon, 11 Aug 2025 15:47:38 +0200
- Subject: [PATCH 7/7] sys: Cleanup NFS41GetDeviceExtension() macro
- Cleanup NFS41GetDeviceExtension() macro.
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- sys/nfs41sys_driver.c | 9 ++++++---
- sys/nfs41sys_driver.h | 6 +++---
- sys/nfs41sys_mount.c | 14 ++++++++------
- 3 files changed, 17 insertions(+), 12 deletions(-)
- diff --git a/sys/nfs41sys_driver.c b/sys/nfs41sys_driver.c
- index bfde496..c312ce2 100644
- --- a/sys/nfs41sys_driver.c
- +++ b/sys/nfs41sys_driver.c
- @@ -387,7 +387,8 @@ NTSTATUS nfs41_Start(
- IN OUT PRDBSS_DEVICE_OBJECT dev)
- {
- NTSTATUS status;
- - NFS41GetDeviceExtension(RxContext, DevExt);
- + PNFS41_DEVICE_EXTENSION DevExt =
- + NFS41GetDeviceExtension(RxContext->RxDeviceObject);
- DbgEn();
- @@ -411,7 +412,8 @@ NTSTATUS nfs41_Stop(
- IN OUT PRDBSS_DEVICE_OBJECT dev)
- {
- NTSTATUS status;
- - NFS41GetDeviceExtension(RxContext, DevExt);
- + PNFS41_DEVICE_EXTENSION DevExt =
- + NFS41GetDeviceExtension(RxContext->RxDeviceObject);
- DbgEn();
- status = SharedMemoryFree(DevExt->SharedMemorySection);
- DbgEx();
- @@ -444,7 +446,8 @@ NTSTATUS nfs41_DevFcbXXXControlFile(
- ULONG fsop = io_ctx->ParamsFor.FsCtl.FsControlCode, state;
- ULONG in_len = io_ctx->ParamsFor.IoCtl.InputBufferLength;
- DWORD *buf = io_ctx->ParamsFor.IoCtl.pInputBuffer;
- - NFS41GetDeviceExtension(RxContext, DevExt);
- + PNFS41_DEVICE_EXTENSION DevExt =
- + NFS41GetDeviceExtension(RxContext->RxDeviceObject);
- DWORD nfs41d_version = 0;
- //DbgEn();
- diff --git a/sys/nfs41sys_driver.h b/sys/nfs41sys_driver.h
- index b1db3f5..6c6db57 100644
- --- a/sys/nfs41sys_driver.h
- +++ b/sys/nfs41sys_driver.h
- @@ -488,9 +488,9 @@ typedef struct _NFS41_DEVICE_EXTENSION {
- HANDLE openlistHandle;
- } NFS41_DEVICE_EXTENSION, *PNFS41_DEVICE_EXTENSION;
- -#define NFS41GetDeviceExtension(RxContext,pExt) \
- - PNFS41_DEVICE_EXTENSION (pExt) = (PNFS41_DEVICE_EXTENSION) \
- - ((PBYTE)((RxContext)->RxDeviceObject) + sizeof(RDBSS_DEVICE_OBJECT))
- +#define NFS41GetDeviceExtension(DeviceObject) \
- + ((PNFS41_DEVICE_EXTENSION) \
- + (((PBYTE)(DeviceObject)) + sizeof(RDBSS_DEVICE_OBJECT)))
- typedef struct _nfs41_fcb_list_entry {
- LIST_ENTRY next;
- diff --git a/sys/nfs41sys_mount.c b/sys/nfs41sys_mount.c
- index 4ed1e1c..a1e7f61 100644
- --- a/sys/nfs41sys_mount.c
- +++ b/sys/nfs41sys_mount.c
- @@ -819,7 +819,9 @@ NTSTATUS nfs41_CreateVNetRoot(
- NFS41GetVNetRootExtension(pVNetRoot);
- __notnull PNFS41_NETROOT_EXTENSION pNetRootContext =
- NFS41GetNetRootExtension(pNetRoot);
- - NFS41GetDeviceExtension(pCreateNetRootContext->RxContext,DevExt);
- + PRX_CONTEXT RxContext = pCreateNetRootContext->RxContext;
- + PNFS41_DEVICE_EXTENSION DevExt =
- + NFS41GetDeviceExtension(RxContext->RxDeviceObject);
- DWORD nfs41d_version = DevExt->nfs41d_version;
- nfs41_mount_entry *existing_mount = NULL;
- LUID luid;
- @@ -875,17 +877,17 @@ NTSTATUS nfs41_CreateVNetRoot(
- }
- nfs41_MountConfig_InitDefaults(Config);
- - if (pCreateNetRootContext->RxContext->Create.EaLength) {
- + if (RxContext->Create.EaLength) {
- /* Codepath for nfs_mount.exe */
- DbgP("Codepath for nfs_mount.exe, "
- "Create->{ EaBuffer=0x%p, EaLength=%ld }\n",
- - pCreateNetRootContext->RxContext->Create.EaBuffer,
- - (long)pCreateNetRootContext->RxContext->Create.EaLength);
- + RxContext->Create.EaBuffer,
- + (long)RxContext->Create.EaLength);
- /* parse the extended attributes for mount options */
- status = nfs41_MountConfig_ParseOptions(
- - pCreateNetRootContext->RxContext->Create.EaBuffer,
- - pCreateNetRootContext->RxContext->Create.EaLength,
- + RxContext->Create.EaBuffer,
- + RxContext->Create.EaLength,
- Config);
- if (status != STATUS_SUCCESS) {
- DbgP("nfs41_MountConfig_ParseOptions() failed\n");
- --
- 2.45.1
msnfs41client: Patches for kernel performance improvements+cleanup+misc, 2025-08-12
Posted by Anonymous on Tue 12th Aug 2025 17:53
raw | new post
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.