Skip to contentSkip to conversation

[4.17?] x86/pv-shim: ballooning fixes

PATCH In review Jan Beulich 3 participants 6 messages Oct 28, 2022

lore
Share & tools
lore
#0 lore raw

cover [4.17?] x86/pv-shim: ballooning fixes

These patches have (as a single, monolithic one) been living in the XenServer patch queue for quite some time. While preparing for this upstream submission, I've left the code largely as is (only a few cosmetic adjustments, but no functional changes), so the series can be assumed to have been properly tested. What I did fully alter though are the descriptions.

1: correctly ignore empty onlining requests
2: correct ballooning up for compat guests
3: correct ballooning down for compat guests

Jan

#1 lore raw

PATCH 1/3 [4.17?] x86/pv-shim: correctly ignore empty onlining requests

From: Igor Druzhinin <[email protected]>

Mem-op requests may have zero extents. Such requests need treating as no-ops. pv_shim_online_memory(), however, would have tried to take 2³²-1 order-sized pages from its balloon list (to then populate them), typically ending when the entire set of ballooned pages of this order was consumed.

Note that pv_shim_offline_memory() does not have such an issue.

Fixes b2245acc60c3 ("xen/pvshim: memory hotplug")
xen/arch/x86/pv/shim.c +3 -0
@@ -944,6 +944,9 @@ void pv_shim_online_memory(unsigned int
     struct page_info *page, *tmp;
     PAGE_LIST_HEAD(list);
 
+    if ( !nr )
+        return;
+
     spin_lock(&balloon_lock);
     page_list_for_each_safe ( page, tmp, &balloon )
     {
#2 lore raw

PATCH 2/3 [4.17?] x86/pv-shim: correct ballooning up for compat guests

In reply to Jan Beulich

From: Igor Druzhinin <[email protected]>

The compat layer for multi-extent memory ops may need to split incoming requests. Since the guest handles in the interface structures may not be altered, it does so by leveraging do_memory_op()'s continuation
handling: It hands on non-initial requests with a non-zero start extent, with the (native) handle suitably adjusted down. As a result do_memory_op() sees only the first of potentially several requests with start extent being zero. It's only that case when the function would issue a call to pv_shim_online_memory(), yet the range then covers only the first sub-range that results from the split.

Address that breakage by making a complementary call to pv_shim_online_memory() in compat layer.

Fixes b2245acc60c3 ("xen/pvshim: memory hotplug")
xen/common/compat/memory.c +5 -1
@@ -7,6 +7,7 @@ EMIT_FILE;
 #include <xen/event.h>
 #include <xen/mem_access.h>
 #include <asm/current.h>
+#include <asm/guest.h>
 #include <compat/memory.h>
 
 #define xen_domid_t domid_t
@@ -146,7 +147,10 @@ int compat_memory_op(unsigned int cmd, X
                 nat.rsrv->nr_extents = end_extent;
                 ++split;
             }
-
+           /* Avoid calling pv_shim_online_memory() when in a continuation. */
+           if ( pv_shim && op != XENMEM_decrease_reservation && !start_extent )
+               pv_shim_online_memory(cmp.rsrv.nr_extents - nat.rsrv->nr_extents,
+                                     cmp.rsrv.extent_order);
             break;
 
         case XENMEM_exchange:
#3 lore raw

PATCH 3/3 [4.17?] x86/pv-shim: correct ballooning down for compat guests

In reply to Jan Beulich

From: Igor Druzhinin <[email protected]>

The compat layer for multi-extent memory ops may need to split incoming requests. Since the guest handles in the interface structures may not be altered, it does so by leveraging do_memory_op()'s continuation
handling: It hands on non-initial requests with a non-zero start extent, with the (native) handle suitably adjusted down. As a result do_memory_op() sees only the first of potentially several requests with start extent being zero. In order to be usable as overall result, the function accumulates args.nr_done, i.e. it initialized the field with the start extent. Therefore non-initial requests resulting from the split would pass too large a number into pv_shim_offline_memory().

Address that breakage by always calling pv_shim_offline_memory() regardless of current hypercall preemption status, with a suitably adjusted first argument. Note that this is correct also for the native guest case: We now simply "commit" what was completed right away, rather than at the end of a series of preemption/re-start cycles. In fact this improves overall preemption behavior: There's no longer a potentially big chunk of work done non-preemptively at the end of the last "iteration".

Fixes b2245acc60c3 ("xen/pvshim: memory hotplug")
xen/common/memory.c +7 -12
@@ -1461,22 +1461,17 @@ long do_memory_op(unsigned long cmd, XEN
 
         rc = args.nr_done;
 
-        if ( args.preempted )
-            return hypercall_create_continuation(
-                __HYPERVISOR_memory_op, "lh",
-                op | (rc << MEMOP_EXTENT_SHIFT), arg);
-
 #ifdef CONFIG_X86
         if ( pv_shim && op == XENMEM_decrease_reservation )
-            /*
-             * Only call pv_shim_offline_memory when the hypercall has
-             * finished. Note that nr_done is used to cope in case the
-             * hypercall has failed and only part of the extents where
-             * processed.
-             */
-            pv_shim_offline_memory(args.nr_done, args.extent_order);
+            pv_shim_offline_memory(args.nr_done - start_extent,
+                                   args.extent_order);
 #endif
 
+        if ( args.preempted )
+           return hypercall_create_continuation(
+                __HYPERVISOR_memory_op, "lh",
+                op | (rc << MEMOP_EXTENT_SHIFT), arg);
+
         break;
 
     case XENMEM_exchange:
Acked-by on the v1 series
#4 lore raw
In reply to Jan Beulich
Quoted 10 lines · Jan Beulich

These patches have (as a single, monolithic one) been living in the XenServer patch queue for quite some time. While preparing for this upstream submission, I've left the code largely as is (only a few cosmetic adjustments, but no functional changes), so the series can be assumed to have been properly tested. What I did fully alter though are the descriptions.

1: correctly ignore empty onlining requests
2: correct ballooning up for compat guests
3: correct ballooning down for compat guests

Thanks for doing this.  From our side, they all came from testing where we took our existing PV guest tests and ran the guests shimmed.

I'm reasonably sure there are more issues lurking, but this is definitely an improvement on its own.

They want backporting (in due course), so should be considered for 4.17 seeing as they're ready now.

Acked-by Andrew Cooper
#5 lore raw

Hi Andrew and Jan,

Sorry for top posting, I don't really want to block this series so I am answering this on my phone.

I saw Andrew provided his ack, since this series is ported from XenServer and should be included in 4.17.

Kind regards,
Henry

获取 Outlook for iOS<https://aka.ms/o0ukef>
________________________________
发件人: Andrew Cooper <[email protected]>
发送时间: 星期五, 十月 28, 2022 19:11
收件人: Jan Beulich <[email protected]>; [email protected] <[email protected]>
抄送: Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>; Henry Wang <[email protected]>; George Dunlap <[email protected]> 主题: Re: [PATCH 0/3][4.17?] x86/pv-shim: ballooning fixes

Quoted 10 lines · Jan Beulich

These patches have (as a single, monolithic one) been living in the XenServer patch queue for quite some time. While preparing for this upstream submission, I've left the code largely as is (only a few cosmetic adjustments, but no functional changes), so the series can be assumed to have been properly tested. What I did fully alter though are the descriptions.

1: correctly ignore empty onlining requests
2: correct ballooning up for compat guests
3: correct ballooning down for compat guests

Thanks for doing this. From our side, they all came from testing where we took our existing PV guest tests and ran the guests shimmed.

I'm reasonably sure there are more issues lurking, but this is definitely an improvement on its own.

They want backporting (in due course), so should be considered for 4.17 seeing as they're ready now.