summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomáš Mózes <hydrapolic@gmail.com>2023-04-14 17:59:27 +0200
committerTomáš Mózes <hydrapolic@gmail.com>2023-04-14 17:59:27 +0200
commit83c3b8b1a5486948521768ca2f2ef6de59357210 (patch)
tree23673f3e5851b792c908fdc602c3a3a8ab5c2133 /0043-x86-altp2m-help-gcc13-to-avoid-it-emitting-a-warning.patch
parentXen 4.16.3-pre-patchset-1 (diff)
downloadxen-upstream-patches-83c3b8b1a5486948521768ca2f2ef6de59357210.tar.gz
xen-upstream-patches-83c3b8b1a5486948521768ca2f2ef6de59357210.tar.bz2
xen-upstream-patches-83c3b8b1a5486948521768ca2f2ef6de59357210.zip
Xen 4.16.4-pre-patchset-04.16.4-pre-patchset-0
Signed-off-by: Tomáš Mózes <hydrapolic@gmail.com>
Diffstat (limited to '0043-x86-altp2m-help-gcc13-to-avoid-it-emitting-a-warning.patch')
-rw-r--r--0043-x86-altp2m-help-gcc13-to-avoid-it-emitting-a-warning.patch129
1 files changed, 129 insertions, 0 deletions
diff --git a/0043-x86-altp2m-help-gcc13-to-avoid-it-emitting-a-warning.patch b/0043-x86-altp2m-help-gcc13-to-avoid-it-emitting-a-warning.patch
new file mode 100644
index 0000000..0e040ad
--- /dev/null
+++ b/0043-x86-altp2m-help-gcc13-to-avoid-it-emitting-a-warning.patch
@@ -0,0 +1,129 @@
+From cdde3171a2a932a6836b094c4387412e27414ec9 Mon Sep 17 00:00:00 2001
+From: Jan Beulich <jbeulich@suse.com>
+Date: Tue, 21 Mar 2023 13:51:42 +0100
+Subject: [PATCH 43/61] x86/altp2m: help gcc13 to avoid it emitting a warning
+
+Switches of altp2m-s always expect a valid altp2m to be in place (and
+indeed altp2m_vcpu_initialise() sets the active one to be at index 0).
+The compiler, however, cannot know that, and hence it cannot eliminate
+p2m_get_altp2m()'s case of returnin (literal) NULL. If then the compiler
+decides to special case that code path in the caller, the dereference in
+instances of
+
+ atomic_dec(&p2m_get_altp2m(v)->active_vcpus);
+
+can, to the code generator, appear to be NULL dereferences, leading to
+
+In function 'atomic_dec',
+ inlined from '...' at ...:
+./arch/x86/include/asm/atomic.h:182:5: error: array subscript 0 is outside array bounds of 'int[0]' [-Werror=array-bounds=]
+
+Aid the compiler by adding a BUG_ON() checking the return value of the
+problematic p2m_get_altp2m(). Since with the use of the local variable
+the 2nd p2m_get_altp2m() each will look questionable at the first glance
+(Why is the local variable not used here?), open-code the only relevant
+piece of p2m_get_altp2m() there.
+
+To avoid repeatedly doing these transformations, and also to limit how
+"bad" the open-coding really is, convert the entire operation to an
+inline helper, used by all three instances (and accepting the redundant
+BUG_ON(idx >= MAX_ALTP2M) in two of the three cases).
+
+Reported-by: Charles Arnold <carnold@suse.com>
+Signed-off-by: Jan Beulich <jbeulich@suse.com>
+Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
+master commit: be62b1fc2aa7375d553603fca07299da765a89fe
+master date: 2023-03-13 15:16:21 +0100
+---
+ xen/arch/x86/hvm/vmx/vmx.c | 8 +-------
+ xen/arch/x86/mm/p2m.c | 14 ++------------
+ xen/include/asm-x86/p2m.h | 20 ++++++++++++++++++++
+ 3 files changed, 23 insertions(+), 19 deletions(-)
+
+diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
+index 094141be9a..c8a839cd5e 100644
+--- a/xen/arch/x86/hvm/vmx/vmx.c
++++ b/xen/arch/x86/hvm/vmx/vmx.c
+@@ -4036,13 +4036,7 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs)
+ }
+ }
+
+- if ( idx != vcpu_altp2m(v).p2midx )
+- {
+- BUG_ON(idx >= MAX_ALTP2M);
+- atomic_dec(&p2m_get_altp2m(v)->active_vcpus);
+- vcpu_altp2m(v).p2midx = idx;
+- atomic_inc(&p2m_get_altp2m(v)->active_vcpus);
+- }
++ p2m_set_altp2m(v, idx);
+ }
+
+ /* XXX: This looks ugly, but we need a mechanism to ensure
+diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c
+index 8781df9dda..2d41446a69 100644
+--- a/xen/arch/x86/mm/p2m.c
++++ b/xen/arch/x86/mm/p2m.c
+@@ -2194,13 +2194,8 @@ bool_t p2m_switch_vcpu_altp2m_by_id(struct vcpu *v, unsigned int idx)
+
+ if ( d->arch.altp2m_eptp[idx] != mfn_x(INVALID_MFN) )
+ {
+- if ( idx != vcpu_altp2m(v).p2midx )
+- {
+- atomic_dec(&p2m_get_altp2m(v)->active_vcpus);
+- vcpu_altp2m(v).p2midx = idx;
+- atomic_inc(&p2m_get_altp2m(v)->active_vcpus);
++ if ( p2m_set_altp2m(v, idx) )
+ altp2m_vcpu_update_p2m(v);
+- }
+ rc = 1;
+ }
+
+@@ -2471,13 +2466,8 @@ int p2m_switch_domain_altp2m_by_id(struct domain *d, unsigned int idx)
+ if ( d->arch.altp2m_visible_eptp[idx] != mfn_x(INVALID_MFN) )
+ {
+ for_each_vcpu( d, v )
+- if ( idx != vcpu_altp2m(v).p2midx )
+- {
+- atomic_dec(&p2m_get_altp2m(v)->active_vcpus);
+- vcpu_altp2m(v).p2midx = idx;
+- atomic_inc(&p2m_get_altp2m(v)->active_vcpus);
++ if ( p2m_set_altp2m(v, idx) )
+ altp2m_vcpu_update_p2m(v);
+- }
+
+ rc = 0;
+ }
+diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h
+index 2db9ab0122..f92bb97394 100644
+--- a/xen/include/asm-x86/p2m.h
++++ b/xen/include/asm-x86/p2m.h
+@@ -841,6 +841,26 @@ static inline struct p2m_domain *p2m_get_altp2m(struct vcpu *v)
+ return v->domain->arch.altp2m_p2m[index];
+ }
+
++/* set current alternate p2m table */
++static inline bool p2m_set_altp2m(struct vcpu *v, unsigned int idx)
++{
++ struct p2m_domain *orig;
++
++ BUG_ON(idx >= MAX_ALTP2M);
++
++ if ( idx == vcpu_altp2m(v).p2midx )
++ return false;
++
++ orig = p2m_get_altp2m(v);
++ BUG_ON(!orig);
++ atomic_dec(&orig->active_vcpus);
++
++ vcpu_altp2m(v).p2midx = idx;
++ atomic_inc(&v->domain->arch.altp2m_p2m[idx]->active_vcpus);
++
++ return true;
++}
++
+ /* Switch alternate p2m for a single vcpu */
+ bool_t p2m_switch_vcpu_altp2m_by_id(struct vcpu *v, unsigned int idx);
+
+--
+2.40.0
+