pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Patch to use |ExAllocateFromNPagedLookasideList()|&co for |nfs41_updowncall_entry| allocations, 2024-10-11
Posted by Anonymous on Fri 11th Oct 2024 16:00
raw | new post

  1. From 935092b719621697107576ef920daeb74da2c833 Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Fri, 11 Oct 2024 15:36:46 +0200
  4. Subject: [PATCH] sys: Use |ExAllocateFromNPagedLookasideList()|&co for
  5.  |nfs41_updowncall_entry| allocations
  6.  
  7. Use |ExAllocateFromNPagedLookasideList()|&co for
  8. |nfs41_updowncall_entry| allocations.
  9.  
  10. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  11. ---
  12.  sys/nfs41_debug.c  |  14 ++++++
  13.  sys/nfs41_debug.h  |   3 ++
  14.  sys/nfs41_driver.c | 106 +++++++++++++++++++++++++++++++++++++++++----
  15.  3 files changed, 115 insertions(+), 8 deletions(-)
  16.  
  17. diff --git a/sys/nfs41_debug.c b/sys/nfs41_debug.c
  18. index d794cd4..23673bf 100644
  19. --- a/sys/nfs41_debug.c
  20. +++ b/sys/nfs41_debug.c
  21. @@ -1002,3 +1002,17 @@ const char *fsctl2string(ULONG fscontrolcode)
  22.  
  23.      /* not reached */
  24.  }
  25. +
  26. +#ifdef USE_LOOKASIDELISTS_FOR_UPDOWNCALLENTRY_MEM
  27. +void print_lookasidelist_stat(const char *label, PNPAGED_LOOKASIDE_LIST ll)
  28. +{
  29. +    DbgP("#### lookasidelist stat '%s': "
  30. +        "{ TotalAllocates=%ld, AllocateMisses=%ld, FreeMisses=%ld, Depth=%ld, MaximumDepth=%ld\n",
  31. +        label,
  32. +        (long)ll->L.TotalAllocates,
  33. +        (long)ll->L.AllocateMisses,
  34. +        (long)ll->L.FreeMisses,
  35. +        (long)ll->L.Depth,
  36. +        (long)ll->L.MaximumDepth);
  37. +}
  38. +#endif /* USE_LOOKASIDELISTS_FOR_UPDOWNCALLENTRY_MEM */
  39. diff --git a/sys/nfs41_debug.h b/sys/nfs41_debug.h
  40. index 0c3f7c4..5799929 100644
  41. --- a/sys/nfs41_debug.h
  42. +++ b/sys/nfs41_debug.h
  43. @@ -56,6 +56,9 @@ void print_wait_status(int on, const char *str, NTSTATUS status,
  44.                         const char *opcode, PVOID entry, LONGLONG xid);
  45.  void print_acl_args(SECURITY_INFORMATION info);
  46.  const char *fsctl2string(ULONG fsctl);
  47. +#ifdef USE_LOOKASIDELISTS_FOR_UPDOWNCALLENTRY_MEM
  48. +void print_lookasidelist_stat(const char *label, PNPAGED_LOOKASIDE_LIST ll);
  49. +#endif /* USE_LOOKASIDELISTS_FOR_UPDOWNCALLENTRY_MEM */
  50.  
  51.  #define PTR2PTRDIFF_T(p) (((char *)(p))-((char *)0))
  52.  #define PsGetCurrentProcessShortDebugId() ((int)PTR2PTRDIFF_T(PsGetCurrentProcessId()))
  53. diff --git a/sys/nfs41_driver.c b/sys/nfs41_driver.c
  54. index 77a454c..d222acb 100644
  55. --- a/sys/nfs41_driver.c
  56. +++ b/sys/nfs41_driver.c
  57. @@ -51,6 +51,9 @@
  58.  #endif
  59.  #endif /* _MSC_VER >= 1900 */
  60.  
  61. +/* Driver build config */
  62. +#define USE_LOOKASIDELISTS_FOR_UPDOWNCALLENTRY_MEM 1
  63. +// #define LOOKASIDELISTS_STATS 1
  64.  
  65.  #define MINIRDR__NAME "Value is ignored, only fact of definition"
  66.  #include <rx.h>
  67. @@ -574,6 +577,80 @@ typedef enum _NULMRX_STORAGE_TYPE_CODES {
  68.  nfs41_init_driver_state nfs41_init_state = NFS41_INIT_DRIVER_STARTABLE;
  69.  nfs41_start_driver_state nfs41_start_state = NFS41_START_DRIVER_STARTABLE;
  70.  
  71. +#ifdef USE_LOOKASIDELISTS_FOR_UPDOWNCALLENTRY_MEM
  72. +NPAGED_LOOKASIDE_LIST updowncall_entry_upcall_lookasidelist;
  73. +NPAGED_LOOKASIDE_LIST updowncall_entry_downcall_lookasidelist;
  74. +#endif /* USE_LOOKASIDELISTS_FOR_UPDOWNCALLENTRY_MEM */
  75. +
  76. +static
  77. +nfs41_updowncall_entry *nfs41_upcall_allocate_updowncall_entry(void)
  78. +{
  79. +    nfs41_updowncall_entry *e;
  80. +#ifdef USE_LOOKASIDELISTS_FOR_UPDOWNCALLENTRY_MEM
  81. +    e = ExAllocateFromNPagedLookasideList(
  82. +        &updowncall_entry_upcall_lookasidelist);
  83. +
  84. +#ifdef LOOKASIDELISTS_STATS
  85. +    volatile static long cnt = 0;
  86. +    if ((cnt++ % 100) == 0) {
  87. +        print_lookasidelist_stat("updowncall_entry_upcall",
  88. +            &updowncall_entry_upcall_lookasidelist);
  89. +    }
  90. +#endif /* LOOKASIDELISTS_STATS */
  91. +#else
  92. +    e = RxAllocatePoolWithTag(NonPagedPoolNx,
  93. +        sizeof(nfs41_updowncall_entry),
  94. +        NFS41_MM_POOLTAG_UP);
  95. +#endif /* USE_LOOKASIDELISTS_FOR_UPDOWNCALLENTRY_MEM */
  96. +
  97. +    return e;
  98. +}
  99. +
  100. +static
  101. +void nfs41_upcall_free_updowncall_entry(nfs41_updowncall_entry *entry)
  102. +{
  103. +#ifdef USE_LOOKASIDELISTS_FOR_UPDOWNCALLENTRY_MEM
  104. +    ExFreeToNPagedLookasideList(&updowncall_entry_upcall_lookasidelist,
  105. +        entry);
  106. +#else
  107. +    RxFreePool(entry);
  108. +#endif /* USE_LOOKASIDELISTS_FOR_UPDOWNCALLENTRY_MEM */
  109. +}
  110. +
  111. +static
  112. +nfs41_updowncall_entry *nfs41_downcall_allocate_updowncall_entry(void)
  113. +{
  114. +    nfs41_updowncall_entry *e;
  115. +#ifdef USE_LOOKASIDELISTS_FOR_UPDOWNCALLENTRY_MEM
  116. +    e = ExAllocateFromNPagedLookasideList(
  117. +        &updowncall_entry_downcall_lookasidelist);
  118. +
  119. +#ifdef LOOKASIDELISTS_STATS
  120. +    volatile static long cnt = 0;
  121. +    if ((cnt++ % 100) == 0) {
  122. +        print_lookasidelist_stat("updowncall_entry_downcall",
  123. +            &updowncall_entry_downcall_lookasidelist);
  124. +    }
  125. +#endif /* LOOKASIDELISTS_STATS */
  126. +#else
  127. +    e = RxAllocatePoolWithTag(NonPagedPoolNx,
  128. +        sizeof(nfs41_updowncall_entry),
  129. +        NFS41_MM_POOLTAG_DOWN);
  130. +#endif /* USE_LOOKASIDELISTS_FOR_UPDOWNCALLENTRY_MEM */
  131. +    return e;
  132. +}
  133. +
  134. +static
  135. +void nfs41_downcall_free_updowncall_entry(nfs41_updowncall_entry *entry)
  136. +{
  137. +#ifdef USE_LOOKASIDELISTS_FOR_UPDOWNCALLENTRY_MEM
  138. +    ExFreeToNPagedLookasideList(&updowncall_entry_downcall_lookasidelist,
  139. +        entry);
  140. +#else
  141. +    RxFreePool(entry);
  142. +#endif /* USE_LOOKASIDELISTS_FOR_UPDOWNCALLENTRY_MEM */
  143. +}
  144. +
  145.  /* Local prototypes */
  146.  static NTSTATUS map_mount_errors(
  147.      DWORD status);
  148. @@ -1650,8 +1727,7 @@ static NTSTATUS nfs41_UpcallCreate(
  149.      SECURITY_SUBJECT_CONTEXT sec_ctx;
  150.      SECURITY_QUALITY_OF_SERVICE sec_qos;
  151.  
  152. -    entry = RxAllocatePoolWithTag(NonPagedPoolNx, sizeof(nfs41_updowncall_entry),
  153. -                NFS41_MM_POOLTAG_UP);
  154. +    entry = nfs41_upcall_allocate_updowncall_entry();
  155.      if (entry == NULL) {
  156.          status = STATUS_INSUFFICIENT_RESOURCES;
  157.          goto out;
  158. @@ -1693,8 +1769,8 @@ static NTSTATUS nfs41_UpcallCreate(
  159.                  "SeCreateClientSecurityFromSubjectContext() "
  160.                  "failed with 0x%x\n",
  161.                  status);
  162. -            RxFreePool(entry);
  163. -           entry = NULL;
  164. +            nfs41_upcall_free_updowncall_entry(entry);
  165. +            entry = NULL;
  166.          }
  167.  
  168.          SeReleaseSubjectContext(&sec_ctx);
  169. @@ -1727,7 +1803,7 @@ static void nfs41_UpcallDestroy(nfs41_updowncall_entry *entry)
  170.          ObDereferenceObject(entry->psec_ctx_clienttoken);
  171.      }
  172.  
  173. -    RxFreePool(entry);
  174. +    nfs41_upcall_free_updowncall_entry(entry);
  175.  }
  176.  
  177.  
  178. @@ -2140,8 +2216,7 @@ static NTSTATUS nfs41_downcall(
  179.      print_hexbuf("downcall buffer", buf, in_len);
  180.  #endif /* DEBUG_PRINT_DOWNCALL_HEXBUF */
  181.  
  182. -    tmp = RxAllocatePoolWithTag(NonPagedPoolNx, sizeof(nfs41_updowncall_entry),
  183. -            NFS41_MM_POOLTAG_DOWN);
  184. +    tmp = nfs41_downcall_allocate_updowncall_entry();
  185.      if (tmp == NULL) goto out;
  186.  
  187.      unmarshal_nfs41_header(tmp, &buf);
  188. @@ -2270,7 +2345,7 @@ static NTSTATUS nfs41_downcall(
  189.          KeSetEvent(&cur->cond, 0, FALSE);
  190.  
  191.  out_free:
  192. -    RxFreePool(tmp);
  193. +    nfs41_downcall_free_updowncall_entry(tmp);
  194.  out:
  195.      return status;
  196.  }
  197. @@ -7977,6 +8052,21 @@ NTSTATUS DriverEntry(
  198.      InitializeListHead(&upcall.head);
  199.      InitializeListHead(&downcall.head);
  200.      InitializeListHead(&openlist.head);
  201. +#ifdef USE_LOOKASIDELISTS_FOR_UPDOWNCALLENTRY_MEM
  202. +    /*
  203. +     * The |Depth| parameter is unfortunately ignored in Win10,
  204. +     * otherwise we could use |MmQuerySystemSize()| to scale the
  205. +     * lookasidelists
  206. +     */
  207. +    ExInitializeNPagedLookasideList(
  208. +        &updowncall_entry_upcall_lookasidelist, NULL, NULL,
  209. +        POOL_NX_ALLOCATION, sizeof(nfs41_updowncall_entry),
  210. +        NFS41_MM_POOLTAG_UP, 0);
  211. +    ExInitializeNPagedLookasideList(
  212. +        &updowncall_entry_downcall_lookasidelist, NULL, NULL,
  213. +        POOL_NX_ALLOCATION, sizeof(nfs41_updowncall_entry),
  214. +        NFS41_MM_POOLTAG_DOWN, 0);
  215. +#endif /* USE_LOOKASIDELISTS_FOR_UPDOWNCALLENTRY_MEM */
  216.      InitializeObjectAttributes(&oattrs, NULL, OBJ_KERNEL_HANDLE, NULL, NULL);
  217.      status = PsCreateSystemThread(&dev_exts->openlistHandle, mask,
  218.          &oattrs, NULL, NULL, &fcbopen_main, NULL);
  219. --
  220. 2.45.1

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.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at