[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [win-pv-devel] [PATCH] Improve auditing in CACHE and GNTTAB interfaces
Add 'Get' and 'Put' counters to CACHEs which can then be checked for equality at destruction time to make sure all objects have been returned. Also add a list of GNTTAB caches so that the code can BUG on any outstanding caches at Release. Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx> --- src/xenbus/cache.c | 31 ++++++++++++++++++++++--------- src/xenbus/gnttab.c | 21 ++++++++++++++++++++- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/xenbus/cache.c b/src/xenbus/cache.c index ba7dcdf..83993ca 100644 --- a/src/xenbus/cache.c +++ b/src/xenbus/cache.c @@ -79,8 +79,10 @@ struct _XENBUS_CACHE { VOID (*ReleaseLock)(PVOID); PVOID Argument; LIST_ENTRY GetList; + LONG GetCount; PLIST_ENTRY PutList; - LONG ObjectCount; + LONG PutCount; + LONG ListCount; PXENBUS_CACHE_MAGAZINE Magazine; ULONG MagazineCount; XENBUS_CACHE_FIST FIST; @@ -225,7 +227,7 @@ CacheGetObjectFromList( KIRQL Irql = PASSIVE_LEVEL; NTSTATUS status; - Count = InterlockedDecrement(&Cache->ObjectCount); + Count = InterlockedDecrement(&Cache->ListCount); status = STATUS_NO_MEMORY; if (Count < 0) @@ -255,7 +257,7 @@ CacheGetObjectFromList( return Object; fail1: - (VOID) InterlockedIncrement(&Cache->ObjectCount); + (VOID) InterlockedIncrement(&Cache->ListCount); return NULL; } @@ -294,7 +296,7 @@ CachePutObjectToList( KeMemoryBarrier(); - (VOID) InterlockedIncrement(&Cache->ObjectCount); + (VOID) InterlockedIncrement(&Cache->ListCount); } static PVOID @@ -305,6 +307,7 @@ CacheGetObjectFromMagazine( { PXENBUS_CACHE_MAGAZINE Magazine; + ASSERT3U(Index, <, Cache->MagazineCount); Magazine = &Cache->Magazine[Index]; for (Index = 0; Index < XENBUS_CACHE_MAGAZINE_SLOTS; Index++) { @@ -330,6 +333,7 @@ CachePutObjectToMagazine( { PXENBUS_CACHE_MAGAZINE Magazine; + ASSERT3U(Index, <, Cache->MagazineCount); Magazine = &Cache->Magazine[Index]; for (Index = 0; Index < XENBUS_CACHE_MAGAZINE_SLOTS; Index++) { @@ -385,6 +389,8 @@ CacheGet( done: KeLowerIrql(Irql); + (VOID) InterlockedIncrement(&Cache->GetCount); + return Object; } @@ -401,6 +407,8 @@ CachePut( UNREFERENCED_PARAMETER(Interface); + (VOID) InterlockedIncrement(&Cache->PutCount); + KeRaiseIrql(DISPATCH_LEVEL, &Irql); Index = KeGetCurrentProcessorNumberEx(NULL); @@ -679,17 +687,22 @@ CacheDestroy( RtlZeroMemory(&Cache->ListEntry, sizeof (LIST_ENTRY)); + ASSERT3U(Cache->PutCount, ==, Cache->GetCount); + Cache->PutCount = 0; + Cache->GetCount = 0; + Cache->Reservation = 0; CacheFlushMagazines(Cache); - CacheSpill(Cache, Cache->ObjectCount); - - ASSERT3U(Cache->ObjectCount, ==, 0); ASSERT(IsZeroMemory(Cache->Magazine, sizeof (XENBUS_CACHE_MAGAZINE) * Cache->MagazineCount)); __CacheFree(Cache->Magazine); Cache->Magazine = NULL; Cache->MagazineCount = 0; + CacheSpill(Cache, Cache->ListCount); + ASSERT3U(Cache->ListCount, ==, 0); + + ASSERT(IsListEmpty(&Cache->GetList)); RtlZeroMemory(&Cache->GetList, sizeof (LIST_ENTRY)); RtlZeroMemory(&Cache->FIST, sizeof (XENBUS_CACHE_FIST)); @@ -737,7 +750,7 @@ CacheDebugCallback( &Context->DebugInterface, "- %s: Count = %d (Reservation = %d)\n", Cache->Name, - Cache->ObjectCount, + Cache->ListCount, Cache->Reservation); } } @@ -793,7 +806,7 @@ CacheMonitor( Cache = CONTAINING_RECORD(ListEntry, XENBUS_CACHE, ListEntry); - Count = Cache->ObjectCount; + Count = Cache->ListCount; if (Count < Cache->Reservation) CacheFill(Cache, Cache->Reservation - Count); diff --git a/src/xenbus/gnttab.c b/src/xenbus/gnttab.c index 3912028..165e38f 100644 --- a/src/xenbus/gnttab.c +++ b/src/xenbus/gnttab.c @@ -53,8 +53,9 @@ #define MAXNAMELEN 128 struct _XENBUS_GNTTAB_CACHE { - PXENBUS_GNTTAB_CONTEXT Context; + LIST_ENTRY ListEntry; CHAR Name[MAXNAMELEN]; + PXENBUS_GNTTAB_CONTEXT Context; VOID (*AcquireLock)(PVOID); VOID (*ReleaseLock)(PVOID); PVOID Argument; @@ -81,6 +82,7 @@ struct _XENBUS_GNTTAB_CONTEXT { PXENBUS_SUSPEND_CALLBACK SuspendCallbackEarly; XENBUS_DEBUG_INTERFACE DebugInterface; PXENBUS_DEBUG_CALLBACK DebugCallback; + LIST_ENTRY List; }; #define XENBUS_GNTTAB_TAG 'TTNG' @@ -321,6 +323,7 @@ GnttabCreateCache( ) { PXENBUS_GNTTAB_CONTEXT Context = Interface->Context; + KIRQL Irql; NTSTATUS status; *Cache = __GnttabAllocate(sizeof (XENBUS_GNTTAB_CACHE)); @@ -356,6 +359,10 @@ GnttabCreateCache( if (!NT_SUCCESS(status)) goto fail3; + KeAcquireSpinLock(&Context->Lock, &Irql); + InsertTailList(&Context->List, &(*Cache)->ListEntry); + KeReleaseSpinLock(&Context->Lock, Irql); + return STATUS_SUCCESS; fail3: @@ -388,6 +395,13 @@ GnttabDestroyCache( ) { PXENBUS_GNTTAB_CONTEXT Context = Interface->Context; + KIRQL Irql; + + KeAcquireSpinLock(&Context->Lock, &Irql); + RemoveEntryList(&Cache->ListEntry); + KeReleaseSpinLock(&Context->Lock, Irql); + + RtlZeroMemory(&Cache->ListEntry, sizeof (LIST_ENTRY)); XENBUS_CACHE(Destroy, &Context->CacheInterface, @@ -717,6 +731,9 @@ GnttabRelease( Trace("====>\n"); + if (!IsListEmpty(&Context->List)) + BUG("OUTSTANDING CACHES"); + XENBUS_DEBUG(Deregister, &Context->DebugInterface, Context->DebugCallback); @@ -816,6 +833,7 @@ GnttabInitialize( ASSERT(NT_SUCCESS(status)); ASSERT((*Context)->DebugInterface.Interface.Context != NULL); + InitializeListHead(&(*Context)->List); KeInitializeSpinLock(&(*Context)->Lock); (*Context)->Fdo = Fdo; @@ -878,6 +896,7 @@ GnttabTeardown( Context->Fdo = NULL; RtlZeroMemory(&Context->Lock, sizeof (KSPIN_LOCK)); + RtlZeroMemory(&Context->List, sizeof (LIST_ENTRY)); RtlZeroMemory(&Context->DebugInterface, sizeof (XENBUS_DEBUG_INTERFACE)); -- 2.1.1 _______________________________________________ win-pv-devel mailing list win-pv-devel@xxxxxxxxxxxxxxxxxxxx http://lists.xenproject.org/cgi-bin/mailman/listinfo/win-pv-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |