[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [xen master] x86/shadow: Fix PV32 shadowing when CONFIG_HVM is enabled
commit 10b80ee5588e8928b266dea02a5e99d098bd227a Author: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> AuthorDate: Wed Jan 25 16:18:16 2023 +0000 Commit: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> CommitDate: Thu Jan 26 12:15:59 2023 +0000 x86/shadow: Fix PV32 shadowing when CONFIG_HVM is enabled The OSSTest bisector identified an issue with c/s 1894049fa283 ("x86/shadow: L2H shadow type is PV32-only") in !HVM builds. The bug is ultimately caused by sh_type_to_size[] not actually being specific to HVM guests, and it's position in shadow/hvm.c mislead the reasoning. To fix the issue that OSSTest identified, SH_type_l2h_64_shadow must still have the value 1 in any CONFIG_PV32 build. But simply adjusting this leaves us with misleading logic, and a reasonable chance of making a related error again in the future. In hindsight, moving sh_type_to_size[] out of common.c in the first place a mistake. Therefore, move sh_type_to_size[] back to living in common.c, leaving a comment explaining why it happens to be inside an HVM conditional. This effectively reverts the second half of 4fec945409fc ("x86/shadow: adjust and move sh_type_to_size[]") while retaining the other improvements from the same changeset. While making this change, also adjust the sh_type_to_size[] declaration to match its definition. Fixes: 4fec945409fc ("x86/shadow: adjust and move sh_type_to_size[]") Fixes: 1894049fa283 ("x86/shadow: L2H shadow type is PV32-only") Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> Acked-by: George Dunlap <george.dunlap@xxxxxxxxx> --- xen/arch/x86/mm/shadow/common.c | 38 ++++++++++++++++++++++++++++++++++++++ xen/arch/x86/mm/shadow/hvm.c | 31 ------------------------------- xen/arch/x86/mm/shadow/private.h | 2 +- 3 files changed, 39 insertions(+), 32 deletions(-) diff --git a/xen/arch/x86/mm/shadow/common.c b/xen/arch/x86/mm/shadow/common.c index 26901b8b3b..a74b15e3e7 100644 --- a/xen/arch/x86/mm/shadow/common.c +++ b/xen/arch/x86/mm/shadow/common.c @@ -39,6 +39,44 @@ #include <public/sched.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 + * + * Note: our accessor, shadow_size(), can optimise out this table in PV-only + * builds. + */ +#ifdef CONFIG_HVM +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, +#ifdef CONFIG_PV32 + [SH_type_l2h_64_shadow] = 1, +#endif + [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, +}; +#endif /* CONFIG_HVM */ + DEFINE_PER_CPU(uint32_t,trace_shadow_path_flags); static int cf_check sh_enable_log_dirty(struct domain *, bool log_global); diff --git a/xen/arch/x86/mm/shadow/hvm.c b/xen/arch/x86/mm/shadow/hvm.c index 918865cf1b..88c3c16322 100644 --- a/xen/arch/x86/mm/shadow/hvm.c +++ b/xen/arch/x86/mm/shadow/hvm.c @@ -33,37 +33,6 @@ #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, PV32-only */ - [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 */ diff --git a/xen/arch/x86/mm/shadow/private.h b/xen/arch/x86/mm/shadow/private.h index 7d6c846c80..79d82364fc 100644 --- a/xen/arch/x86/mm/shadow/private.h +++ b/xen/arch/x86/mm/shadow/private.h @@ -362,7 +362,7 @@ static inline int mfn_oos_may_write(mfn_t gmfn) #endif /* (SHADOW_OPTIMIZATIONS & SHOPT_OUT_OF_SYNC) */ /* Figure out the size (in pages) of a given shadow type */ -extern const u8 sh_type_to_size[SH_type_unused]; +extern const uint8_t sh_type_to_size[SH_type_unused]; static inline unsigned int shadow_size(unsigned int shadow_type) { -- generated by git-patchbot for /home/xen/git/xen.git#master
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |