Skip to contentSkip to conversation

xen/x86: domain: Free all the pages associated to struct domain

PATCH In review Julien Grall 5 participants 8 messages Jan 20, 2020 – Jan 22, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/x86: domain: Free all the pages associated to struct domain

From: Julien Grall <[email protected]>

The structure domain may be bigger than a page size when lock profiling is enabled. However, the function free_domheap_struct will only free the first page.

This is not a security issue because struct domain can only be bigger than a page size for lock profiling. The feature can only be selected in DEBUG and EXPERT mode.

Fixes 8916fcf4577 ("x86/domain: compile with lock_profile=y enabled")
---
 xen/arch/x86/domain.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/domain.c +1 -1
index 28fefa1f81..a5380b9bab 100644
@@ -344,7 +344,7 @@ struct domain *alloc_domain_struct(void)
 
 void free_domain_struct(struct domain *d)
 {
-    free_xenheap_page(d);
+    free_xenheap_pages(d, get_order_from_bytes(sizeof(*d)));
 }
 
 struct vcpu *alloc_vcpu_struct(const struct domain *d)
Signature · 7 lines
2.17.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Julien Grall

From: Julien Grall <[email protected]>

The structure domain may be bigger than a page size when lock profiling is enabled. However, the function free_domheap_struct will only free the first page.

Quoted 7 lines

This is not a security issue because struct domain can only be bigger than a page size for lock profiling. The feature can only be selected in DEBUG and EXPERT mode.

Fixes 8916fcf4577 ("x86/domain: compile with lock_profile=y enabled")

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by on v1 1/1
#2 lore raw
In reply to Julien Grall
Quoted 6 lines · Julien Grall

From: Julien Grall <[email protected]>

The structure domain may be bigger than a page size when lock profiling is enabled. However, the function free_domheap_struct will only free the first page.

Quoted 7 lines

This is not a security issue because struct domain can only be bigger than a page size for lock profiling. The feature can only be selected in DEBUG and EXPERT mode.

Fixes 8916fcf4577 ("x86/domain: compile with lock_profile=y enabled")

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
In reply to Julien Grall
Quoted 22 lines · Julien Grall

From: Julien Grall <[email protected]>

The structure domain may be bigger than a page size when lock profiling is enabled. However, the function free_domheap_struct will only free the first page.

This is not a security issue because struct domain can only be bigger than a page size for lock profiling. The feature can only be selected in DEBUG and EXPERT mode.

Fixes 8916fcf4577 ("x86/domain: compile with lock_profile=y enabled")
---
 xen/arch/x86/domain.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/domain.c +0 -0
index 28fefa1f81..a5380b9bab 100644

xen/arch/x86/domain.c struct domain *alloc_domain_struct(void) · line 347

Quoted 5 lines
xen/arch/x86/domain.c +1 -1
@@ -344,7 +344,7 @@ struct domain *alloc_domain_struct(void)
 
 void free_domain_struct(struct domain *d)
 {
-    free_xenheap_page(d);
+    free_xenheap_pages(d, get_order_from_bytes(sizeof(*d)));

:(

I'm entirely certain I raised this during the review of the original patch.

I'd much rather see the original patch reverted.  The current size of struct domain with lockprofile enabled is 3200 bytes.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw

Hi Andrew,

Quoted 31 lines · Andrew Cooper
Quoted 22 lines · Julien Grall

From: Julien Grall <[email protected]>

The structure domain may be bigger than a page size when lock profiling is enabled. However, the function free_domheap_struct will only free the first page.

This is not a security issue because struct domain can only be bigger than a page size for lock profiling. The feature can only be selected in DEBUG and EXPERT mode.

Fixes 8916fcf4577 ("x86/domain: compile with lock_profile=y enabled")
---
  xen/arch/x86/domain.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/domain.c +0 -0
index 28fefa1f81..a5380b9bab 100644

xen/arch/x86/domain.c struct domain *alloc_domain_struct(void) · line 347

Quoted 5 lines
xen/arch/x86/domain.c +1 -1
@@ -344,7 +344,7 @@ struct domain *alloc_domain_struct(void)
 
  void free_domain_struct(struct domain *d)
  {
-    free_xenheap_page(d);
+    free_xenheap_pages(d, get_order_from_bytes(sizeof(*d)));

:(

Quoted 4 lines

I'm entirely certain I raised this during the review of the original patch.

I'd much rather see the original patch reverted.  The current size of struct domain with lockprofile enabled is 3200 bytes.

Let me have a look first to see when/why struct domain is less than 4K with lockprofile.

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#5 lore raw
Quoted 34 lines · Julien Grall

Hi Andrew,

Quoted 31 lines · Andrew Cooper
Quoted 23 lines · Julien Grall

From: Julien Grall <[email protected]>

The structure domain may be bigger than a page size when lock profiling is enabled. However, the function free_domheap_struct will only free the
first page.

This is not a security issue because struct domain can only be bigger than a page size for lock profiling. The feature can only be selected in DEBUG and EXPERT mode.

Fixes 8916fcf4577 ("x86/domain: compile with lock_profile=y enabled")

---
  xen/arch/x86/domain.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/domain.c +0 -0
index 28fefa1f81..a5380b9bab 100644

xen/arch/x86/domain.c struct domain *alloc_domain_struct(void) · line 346

Quoted 4 lines
xen/arch/x86/domain.c +1 -1
@@ -344,7 +344,7 @@ struct domain *alloc_domain_struct(void)
     void free_domain_struct(struct domain *d)
   {
-    free_xenheap_page(d);
+    free_xenheap_pages(d, get_order_from_bytes(sizeof(*d)));

:(

Quoted 8 lines
Quoted 5 lines

I'm entirely certain I raised this during the review of the original patch.

I'd much rather see the original patch reverted.  The current size of struct domain with lockprofile enabled is 3200 bytes.

Let me have a look first to see when/why struct domain is less than 4K with lockprofile.

In the intervening time, Juergen has totally rewritten lock profiling, and the virtual timer infrastructure has been taken out-of-line.

Its probably the latter which is the dominating factor.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#6 lore raw
Quoted 10 lines · Andrew Cooper
Quoted 5 lines
Quoted 2 lines

I'd much rather see the original patch reverted. The current size of struct domain with lockprofile enabled is 3200 bytes.

Let me have a look first to see when/why struct domain is less than 4K with lockprofile.

In the intervening time, Juergen has totally rewritten lock profiling, and the virtual timer infrastructure has been taken out-of-line.

Its probably the latter which is the dominating factor.

OK, so if we revert 8916fcf4577 is it reasonable for me to then assume that 'struct domain' will always fit within a page, and declare that live update shall not work to a Xen where that isn't true?

I have a nasty trick in mind...

During live update, we need to do a pass over the live update data in early boot in order to work out which pages to reserve. That part has to be done early, while the boot allocator is active. It works by setting the PGC_allocated bit in the page_info of the reserved pages, so that init_heap_pages() knows not to include them. I've posted that part already.

Also during live update, we need to consume the actual domain state that was passed over from the previous Xen, and fill in the owner (and refcount etc.) in the same page_info structures, before those pages are in a truly consistent state.

Right now, we need the latter to happen *after* the boot allocator is done and we're able to allocate from the heap... because we need to be able to allocate the domain structures, and we don't want to ensure that there's enough space in the LU reserved bootmem for that many domain structures.

Hence the nasty trick: What if we allocate the new struct domain on *top* of the old one, since we happen to know that page *wasn't* used by the previous Xen for anything that needs to be preserved. The structure itself isn't an ABI and never can be, and it will have to be repopulated from the live migration data, of course — but if we can at least make the assumption that it'll *fit*, then perhaps we can manage to do both of the above with only one pass over all the domain pages.

This will have a direct effect on the customer-observed pause time for a live update. So it's kind of icky, but also *very* tempting...

Amazon Development Centre (London) Ltd. Registered in England and Wales with registration number 04543232 with its registered office at 1 Principal Place, Worship Street, London EC2A 2FA, United Kingdom.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#7 lore raw

Hi David,

Quoted 7 lines · David
Quoted 6 lines · Andrew Cooper
Quoted 5 lines
Quoted 2 lines

I'd much rather see the original patch reverted. The current size of struct domain with lockprofile enabled is 3200 bytes.

Let me have a look first to see when/why struct domain is less than 4K with lockprofile.

Quoted 8 lines
Quoted 4 lines

In the intervening time, Juergen has totally rewritten lock profiling, and the virtual timer infrastructure has been taken out-of-line.

Its probably the latter which is the dominating factor.

OK, so if we revert 8916fcf4577 is it reasonable for me to then assume that 'struct domain' will always fit within a page, and declare that live update shall not work to a Xen where that isn't true?

While it is nice to have struct domain small, I would rather not bake to size assumption in live update.

The more on Arm we have been quite often close to the limit. So I don't want to limit my choices.

Quoted 15 lines

I have a nasty trick in mind...

During live update, we need to do a pass over the live update data in early boot in order to work out which pages to reserve. That part has to be done early, while the boot allocator is active. It works by setting the PGC_allocated bit in the page_info of the reserved pages, so that init_heap_pages() knows not to include them. I've posted that part already.

Also during live update, we need to consume the actual domain state that was passed over from the previous Xen, and fill in the owner (and refcount etc.) in the same page_info structures, before those pages are in a truly consistent state.

Quoted 5 lines

Right now, we need the latter to happen *after* the boot allocator is done and we're able to allocate from the heap... because we need to be able to allocate the domain structures, and we don't want to ensure that there's enough space in the LU reserved bootmem for that many domain structures.

As you pointed out above, the struct domain itself is a page (i.e 4KB on x86). Let say you have 256 domains, this would only use 1MB. Which is not too bad to take into account.

But struct domain has a lot of out-of-line allocation. If you are not planning to make struct domain part of the ABI, then you would need quite a few allocations even in your cases.

Of course, you could just half initialize struct domain. However, I would be cautious with this solution as it would be more difficult to chase down bug around struct page. Imagine the domain pointer is accessed earlier than expected.

Quoted 10 lines

Hence the nasty trick: What if we allocate the new struct domain on *top* of the old one, since we happen to know that page *wasn't* used by the previous Xen for anything that needs to be preserved. The structure itself isn't an ABI and never can be, and it will have to be repopulated from the live migration data, of course — but if we can at least make the assumption that it'll *fit*, then perhaps we can manage to do both of the above with only one pass over all the domain pages.

This will have a direct effect on the customer-observed pause time for a live update. So it's kind of icky, but also *very* tempting...

May I recommend to get some numbers with the multiple pass and "nicer" code first? We can decide on that what sort of hackery we need to lower the pause time.

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel