x86/shadow: adjust and move sh_type_to_size[]

Drop the SH_type_none entry - there are no allocation attempts with
this type, and there also shouldn't be any. Adjust the shadow_size()
alternative path to match that change. Also generalize two related
assertions.

While there move the entire table and the respective part of the comment
there to hvm.c, resulting in one less #ifdef. In the course of the
movement switch to using designated initializers.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
This commit is contained in:
Jan Beulich committed 2022-12-22 10:07:50 +01:00
1 parent f90a265f5b
commit 4fec945409
3 files changed
+34 -36

No files matched your search

+2 -35
View File
@@ -833,44 +833,11 @@ sh_validate_guest_entry(struct vcpu *v, mfn_t gmfn, void *entry, u32 size)
* not contiguous in memory; functions for handling offsets into them are * not contiguous in memory; functions for handling offsets into them are
* defined in shadow/multi.c (shadow_l1_index() etc.) * defined in shadow/multi.c (shadow_l1_index() etc.)
* *
* This table shows the allocation behaviour of the different modes:
*
* Xen paging 64b 64b 64b
* Guest paging 32b pae 64b
* PV or HVM HVM HVM *
* Shadow paging pae pae 64b
*
* sl1 size 8k 4k 4k
* sl2 size 16k 4k 4k
* sl3 size - - 4k
* sl4 size - - 4k
*
* In HVM guests, the p2m table is built out of shadow pages, and we provide * In HVM guests, the p2m table is built out of shadow pages, and we provide
* a function for the p2m management to steal pages, in max-order chunks, from * a function for the p2m management to steal pages, in max-order chunks, from
* the free pool. * the free pool.
*/ */
#ifdef CONFIG_HVM
const u8 sh_type_to_size[] = {
1, /* SH_type_none */
2, /* SH_type_l1_32_shadow */
2, /* SH_type_fl1_32_shadow */
4, /* SH_type_l2_32_shadow */
1, /* SH_type_l1_pae_shadow */
1, /* SH_type_fl1_pae_shadow */
1, /* SH_type_l2_pae_shadow */
1, /* SH_type_l1_64_shadow */
1, /* SH_type_fl1_64_shadow */
1, /* SH_type_l2_64_shadow */
1, /* SH_type_l2h_64_shadow */
1, /* SH_type_l3_64_shadow */
1, /* SH_type_l4_64_shadow */
1, /* SH_type_p2m_table */
1, /* SH_type_monitor_table */
1 /* SH_type_oos_snapshot */
};
#endif
/* /*
* Figure out the least acceptable quantity of shadow memory. * Figure out the least acceptable quantity of shadow memory.
* The minimum memory requirement for always being able to free up a * The minimum memory requirement for always being able to free up a
@@ -1116,7 +1083,7 @@ mfn_t shadow_alloc(struct domain *d,
unsigned int i; unsigned int i;
ASSERT(paging_locked_by_me(d)); ASSERT(paging_locked_by_me(d));
ASSERT(shadow_type != SH_type_none); ASSERT(pages);
perfc_incr(shadow_alloc); perfc_incr(shadow_alloc);
if ( d->arch.paging.free_pages < pages ) if ( d->arch.paging.free_pages < pages )
@@ -1196,9 +1163,9 @@ void shadow_free(struct domain *d, mfn_t smfn)
perfc_incr(shadow_free); perfc_incr(shadow_free);
shadow_type = sp->u.sh.type; shadow_type = sp->u.sh.type;
ASSERT(shadow_type != SH_type_none);
ASSERT(sp->u.sh.head || (shadow_type > SH_type_max_shadow)); ASSERT(sp->u.sh.head || (shadow_type > SH_type_max_shadow));
pages = shadow_size(shadow_type); pages = shadow_size(shadow_type);
ASSERT(pages);
pin_list = &d->arch.paging.shadow.pinned_shadows; pin_list = &d->arch.paging.shadow.pinned_shadows;
for ( i = 0; i < pages; i++ ) for ( i = 0; i < pages; i++ )
+31
View File
@@ -33,6 +33,37 @@
#include "private.h" #include "private.h"
/*
* This table shows the allocation behaviour of the different modes:
*
* Xen paging 64b 64b 64b
* Guest paging 32b pae 64b
* PV or HVM HVM HVM *
* Shadow paging pae pae 64b
*
* sl1 size 8k 4k 4k
* sl2 size 16k 4k 4k
* sl3 size - - 4k
* sl4 size - - 4k
*/
const uint8_t sh_type_to_size[] = {
[SH_type_l1_32_shadow] = 2,
[SH_type_fl1_32_shadow] = 2,
[SH_type_l2_32_shadow] = 4,
[SH_type_l1_pae_shadow] = 1,
[SH_type_fl1_pae_shadow] = 1,
[SH_type_l2_pae_shadow] = 1,
[SH_type_l1_64_shadow] = 1,
[SH_type_fl1_64_shadow] = 1,
[SH_type_l2_64_shadow] = 1,
[SH_type_l2h_64_shadow] = 1,
[SH_type_l3_64_shadow] = 1,
[SH_type_l4_64_shadow] = 1,
[SH_type_p2m_table] = 1,
[SH_type_monitor_table] = 1,
[SH_type_oos_snapshot] = 1,
};
/**************************************************************************/ /**************************************************************************/
/* x86 emulator support for the shadow code /* x86 emulator support for the shadow code
*/ */
+1 -1
View File
@@ -363,7 +363,7 @@ shadow_size(unsigned int shadow_type)
return sh_type_to_size[shadow_type]; return sh_type_to_size[shadow_type];
#else #else
ASSERT(shadow_type < SH_type_unused); ASSERT(shadow_type < SH_type_unused);
return 1; return shadow_type != SH_type_none;
#endif #endif
} }
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.