xen: Pack some hvmop memory structures better
PATCH 1/1 xen: Pack some hvmop memory structures better
Some of the hvmop memory structures have a shocking amount of unnecesssary padding in them. Elements which can have only 3 values are given 64 bits of memory, and then aligned (so that there is padding behind them).
This patch resizes and reorganizes in the following way, (hopefully) without introducing any differences between the layout for 32- and 64-bit.
xen_hvm_set_mem_type:
hvmmem_type -> 16 bits
nr -> 32 bits (limiting us to setting 16TB at a time)
xen_hvm_set_mem_access:
hvmmem_access -> 16 bits
nr -> 32 bits
xen_hvm_get_mem_access:
hvmmem_access -> 16 bits
xen/include/public/hvm/hvm_op.h +8 -10
@@ -119,11 +119,11 @@/* Domain to be updated. */ domid_t domid;/* Memory type */ -uint64_aligned_t hvmmem_type; +uint16_t hvmmem_type; +/* Number of pages. */ +uint32_t nr;/* First pfn. */ uint64_aligned_t first_pfn; -/* Number of pages. */ -uint64_aligned_t nr; };typedef struct xen_hvm_set_mem_type xen_hvm_set_mem_type_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_set_mem_type_t);
@@ -176,13 +176,12 @@struct xen_hvm_set_mem_access {/* Domain to be updated. */ domid_t domid; -uint16_t pad[3 ];/* align next field on 8-byte boundary */ /* Memory type */ -uint64_t hvmmem_access;/* hvm_access_t */ +uint16_t hvmmem_access;/* hvm_access_t */ +/* Number of pages, ignored on setting default access */ +uint32_t nr;/* First pfn, or ~0ull to set the default access for new pages */ uint64_t first_pfn; -/* Number of pages, ignored on setting default access */ -uint64_t nr; };typedef struct xen_hvm_set_mem_access xen_hvm_set_mem_access_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_set_mem_access_t);
@@ -192,11 +191,10 @@struct xen_hvm_get_mem_access {/* Domain to be queried. */ domid_t domid; -uint16_t pad[3 ];/* align next field on 8-byte boundary */ /* Memory type: OUT */ -uint64_t hvmmem_access;/* hvm_access_t */ +uint16_t hvmmem_access;/* hvm_access_t */ /* pfn, or ~0ull for default access for new pages. IN */ -uint64_t pfn; +uint64_aligned_t pfn; };typedef struct xen_hvm_get_mem_access xen_hvm_get_mem_access_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_get_mem_access_t);
Quoted 6 lines · George Dunlap
Some of the hvmop memory structures have a shocking amount of unnecesssary padding in them. Elements which can have only 3 values are given 64 bits of memory, and then aligned (so that there is padding behind them).
This patch resizes and reorganizes in the following way, (hopefully) without introducing any differences between the layout for 32- and 64-bit.
Am I missing something glaring, or this is breaking the ABI between hypervisor and kernels?
Paolo
Quoted 2 lines · Paolo Bonzini
Am I missing something glaring, or this is breaking the ABI between hypervisor and kernels?
It only breaks the ABI between xen and tools, which are supposed always to be version-matched. I'm not sure that it's particularly worthwhile though - at first glance it's saving about ten bytes of argument space. Unless these operations are happening in large batches?
Tim.
Signature · 3 lines
Tim Deegan <[email protected]> Principal Software Engineer, Xen Platform Team Citrix Systems UK Ltd. (Company #02937203, SL9 0BG)
Quoted 10 lines · George Dunlap
Quoted 4 lines · Tim Deegan
It only breaks the ABI between xen and tools, which are supposed always to be version-matched. I'm not sure that it's particularly worthwhile though - at first glance it's saving about ten bytes of argument space. Unless these operations are happening in large batches?
It's mostly about just making things cleaner. It does, however, have the advantage that the hvmop structure then fits within 7 32-bit words; and thus can be simply copied directly into a xentrace record, rather than having to be marshalled on a per-hvmop basis.
That's good enough for me. Also, I see Keir's applied it already. :)
Tim.
Signature · 3 lines
Tim Deegan <[email protected]> Principal Software Engineer, Xen Platform Team Citrix Systems UK Ltd. (Company #02937203, SL9 0BG)
Quoted 7 lines
Quoted 1 line
Quoted 1 line · Tim Deegan
Quoted 2 lines · Paolo Bonzini
Am I missing something glaring, or this is breaking the ABI between hypervisor and kernels?
It only breaks the ABI between xen and tools, which are supposed always to be version-matched. I'm not sure that it's particularly worthwhile
According to x86's do_hvm_op() I would say a HVM guest can issue HVMOP_set_mem_type for itself. Is that perhaps a mistake?
Similarly, HVMOP_[gs]et_mem_access bail on current->domain->domain_id == a.domid, but rcu_lock_target_domain_by_id() happily accepts DOMID_SELF without any further checks. At least for the "set" variant this very much looks like a mistake to me.
Quoted 2 lines
though - at first glance it's saving about ten bytes of argument space. Unless these operations are happening in large batches?
Jan