[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [win-pv-devel] [PATCH] Don't assume a 32-page grant table
The default grant tabled size in Xen is 32 pages, but it is tunable. This patch allows the XENBUS_GNTTAB interface to take advantage of an inreased grant table size. Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx> --- include/xen.h | 8 +++++ src/xen/grant_table.c | 42 +++++++++++++++++++++++++ src/xenbus/gnttab.c | 87 +++++++++++++++++++++++++++++++-------------------- 3 files changed, 103 insertions(+), 34 deletions(-) diff --git a/include/xen.h b/include/xen.h index c8a8e4c..ae365b7 100644 --- a/include/xen.h +++ b/include/xen.h @@ -277,6 +277,14 @@ GrantTableUnmapForeignPage( IN PHYSICAL_ADDRESS Address ); +__checkReturn +XEN_API +NTSTATUS +GrantTableQuerySize( + OUT uint32_t *Current OPTIONAL, + OUT uint32_t *Maximum OPTIONAL + ); + // SCHED __checkReturn diff --git a/src/xen/grant_table.c b/src/xen/grant_table.c index 53ed035..1006579 100644 --- a/src/xen/grant_table.c +++ b/src/xen/grant_table.c @@ -262,3 +262,45 @@ fail1: return status; } + +__checkReturn +XEN_API +NTSTATUS +GrantTableQuerySize( + OUT uint32_t *Current OPTIONAL, + OUT uint32_t *Maximum OPTIONAL + ) +{ + struct gnttab_query_size op; + LONG_PTR rc; + NTSTATUS status; + + op.dom = DOMID_SELF; + + rc = GrantTableOp(GNTTABOP_query_size, &op, 1); + + if (rc < 0) { + ERRNO_TO_STATUS(-rc, status); + goto fail1; + } + + status = STATUS_UNSUCCESSFUL; + if (op.status != GNTST_okay) + goto fail2; + + if (Current != NULL) + *Current = op.nr_frames; + + if (Maximum != NULL) + *Maximum = op.max_nr_frames; + + return STATUS_SUCCESS; + +fail2: + Error("fail2\n"); + +fail1: + Error("fail1 (%08x)\n", status); + + return status; +} diff --git a/src/xenbus/gnttab.c b/src/xenbus/gnttab.c index f3fcc7c..bb11250 100644 --- a/src/xenbus/gnttab.c +++ b/src/xenbus/gnttab.c @@ -42,7 +42,6 @@ #include "util.h" #include "hash_table.h" -#define XENBUS_GNTTAB_MAXIMUM_FRAME_COUNT 32 #define XENBUS_GNTTAB_ENTRY_PER_FRAME (PAGE_SIZE / sizeof (grant_entry_v1_t)) // Xen requires that we avoid the first 8 entries of the table and @@ -78,6 +77,7 @@ struct _XENBUS_GNTTAB_CONTEXT { PXENBUS_FDO Fdo; KSPIN_LOCK Lock; LONG References; + ULONG MaximumFrameCount; PHYSICAL_ADDRESS Address; LONG FrameIndex; grant_entry_v1_t *Table; @@ -124,8 +124,8 @@ GnttabExpand( Index = InterlockedIncrement(&Context->FrameIndex); status = STATUS_INSUFFICIENT_RESOURCES; - ASSERT3U(Index, <=, XENBUS_GNTTAB_MAXIMUM_FRAME_COUNT); - if (Index == XENBUS_GNTTAB_MAXIMUM_FRAME_COUNT) + ASSERT3U(Index, <=, Context->MaximumFrameCount); + if (Index == Context->MaximumFrameCount) goto fail1; Address = Context->Address; @@ -134,7 +134,8 @@ GnttabExpand( status = MemoryAddToPhysmap((PFN_NUMBER)(Address.QuadPart >> PAGE_SHIFT), XENMAPSPACE_grant_table, Index); - ASSERT(NT_SUCCESS(status)); + if (!NT_SUCCESS(status)) + goto fail2; LogPrintf(LOG_LEVEL_INFO, "GNTTAB: MAP XENMAPSPACE_grant_table[%d] @ %08x.%08x\n", @@ -152,17 +153,20 @@ GnttabExpand( Start, End + 1 - Start); if (!NT_SUCCESS(status)) - goto fail2; + goto fail3; Info("added references [%08llx - %08llx]\n", Start, End); return STATUS_SUCCESS; -fail2: - Error("fail2\n"); +fail3: + Error("fail3\n"); // Not clear what to do here +fail2: + Error("fail2\n"); + fail1: Error("fail1 (%08x)\n", status); @@ -719,41 +723,49 @@ GnttabAcquire( Trace("====>\n"); - Size = XENBUS_GNTTAB_MAXIMUM_FRAME_COUNT * PAGE_SIZE; + status = GrantTableQuerySize(NULL, &Context->MaximumFrameCount); + if (!NT_SUCCESS(status)) + goto fail1; + + LogPrintf(LOG_LEVEL_INFO, + "GNTTAB: MAX FRAMES = %u\n", + Context->MaximumFrameCount); + + Size = Context->MaximumFrameCount * PAGE_SIZE; status = FdoAllocateIoSpace(Fdo, Size, &Context->Address); if (!NT_SUCCESS(status)) - goto fail1; + goto fail2; Context->Table = (grant_entry_v1_t *)MmMapIoSpace(Context->Address, Size, MmCached); status = STATUS_UNSUCCESSFUL; if (Context->Table == NULL) - goto fail2; + goto fail3; Context->FrameIndex = -1; status = XENBUS_RANGE_SET(Acquire, &Context->RangeSetInterface); if (!NT_SUCCESS(status)) - goto fail3; + goto fail4; status = XENBUS_RANGE_SET(Create, &Context->RangeSetInterface, "gnttab", &Context->RangeSet); if (!NT_SUCCESS(status)) - goto fail4; + goto fail5; status = XENBUS_CACHE(Acquire, &Context->CacheInterface); if (!NT_SUCCESS(status)) - goto fail5; + goto fail6; status = XENBUS_SUSPEND(Acquire, &Context->SuspendInterface); if (!NT_SUCCESS(status)) - goto fail6; + goto fail7; status = XENBUS_SUSPEND(Register, &Context->SuspendInterface, @@ -762,11 +774,11 @@ GnttabAcquire( Context, &Context->SuspendCallbackEarly); if (!NT_SUCCESS(status)) - goto fail7; + goto fail8; status = XENBUS_DEBUG(Acquire, &Context->DebugInterface); if (!NT_SUCCESS(status)) - goto fail8; + goto fail9; status = XENBUS_DEBUG(Register, &Context->DebugInterface, @@ -775,7 +787,7 @@ GnttabAcquire( Context, &Context->DebugCallback); if (!NT_SUCCESS(status)) - goto fail9; + goto fail10; Trace("<====\n"); @@ -784,31 +796,31 @@ done: return STATUS_SUCCESS; -fail9: - Error("fail9\n"); +fail10: + Error("fail10\n"); XENBUS_DEBUG(Release, &Context->DebugInterface); -fail8: - Error("fail8\n"); +fail9: + Error("fail9\n"); XENBUS_SUSPEND(Deregister, &Context->SuspendInterface, Context->SuspendCallbackEarly); Context->SuspendCallbackEarly = NULL; -fail7: - Error("fail7\n"); +fail8: + Error("fail8\n"); XENBUS_SUSPEND(Release, &Context->SuspendInterface); -fail6: - Error("fail6\n"); +fail7: + Error("fail7\n"); XENBUS_CACHE(Release, &Context->CacheInterface); -fail5: - Error("fail5\n"); +fail6: + Error("fail6\n"); GnttabContract(Context); ASSERT3S(Context->FrameIndex, ==, -1); @@ -820,25 +832,30 @@ fail5: Context->FrameIndex = 0; -fail4: - Error("fail4\n"); +fail5: + Error("fail5\n"); XENBUS_RANGE_SET(Release, &Context->RangeSetInterface); -fail3: - Error("fail3\n"); +fail4: + Error("fail4\n"); MmUnmapIoSpace(Context->Table, Size); Context->Table = NULL; -fail2: - Error("fail2\n"); +fail3: + Error("fail3\n"); FdoFreeIoSpace(Fdo, Context->Address, Size); Context->Address.QuadPart = 0; +fail2: + Error("fail2\n"); + + Context->MaximumFrameCount = 0; + fail1: Error("fail1 (%08x)\n", status); @@ -897,7 +914,7 @@ GnttabRelease( XENBUS_RANGE_SET(Release, &Context->RangeSetInterface); - Size = XENBUS_GNTTAB_MAXIMUM_FRAME_COUNT * PAGE_SIZE; + Size = Context->MaximumFrameCount * PAGE_SIZE; MmUnmapIoSpace(Context->Table, Size); Context->Table = NULL; @@ -907,6 +924,8 @@ GnttabRelease( Size); Context->Address.QuadPart = 0; + Context->MaximumFrameCount = 0; + Trace("<====\n"); done: -- 2.1.1 _______________________________________________ win-pv-devel mailing list win-pv-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/cgi-bin/mailman/listinfo/win-pv-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |