Skip to contentSkip to conversation

[4.15] x86/shadow: replace bogus return path in shadow_get_page_from_l1e()

PATCH In review Jan Beulich 4 participants 6 messages Feb 26, 2021 – Mar 1, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 [4.15] x86/shadow: replace bogus return path in shadow_get_page_from_l1e()

Prior to be640b1800bb ("x86: make get_page_from_l1e() return a proper error code") a positive return value did indicate an error. Said commit failed to adjust this return path, but luckily the only caller has always been inside a shadow_mode_refcounts() conditional.

Subsequent changes caused 1 to end up at the default (error) label in the caller's switch() again, but the returning of 1 (== _PAGE_PRESENT) is still rather confusing here, and a latent risk.

Convert to an ASSERT() instead, just in case any new caller would appear.

xen/arch/x86/mm/shadow/multi.c +1 -3
@@ -802,9 +802,7 @@ shadow_get_page_from_l1e(shadow_l1e_t sl
     struct domain *owner;
 
     ASSERT(!sh_l1e_is_magic(sl1e));
-
-    if ( !shadow_mode_refcounts(d) )
-        return 1;
+    ASSERT(shadow_mode_refcounts(d));
 
     res = get_page_from_l1e(sl1e, d, d);
 
#1 lore raw
Quoted 8 lines · Jan Beulich

Prior to be640b1800bb ("x86: make get_page_from_l1e() return a proper error code") a positive return value did indicate an error. Said commit failed to adjust this return path, but luckily the only caller has always been inside a shadow_mode_refcounts() conditional.

Subsequent changes caused 1 to end up at the default (error) label in the caller's switch() again, but the returning of 1 (== _PAGE_PRESENT) is still rather confusing here, and a latent risk.

The confusion on my part was so significant that I screwed up the shadow mode fix for "VMX: use a single, global APIC access page" (which turned out to be necessary) initially. Hence my proposing this for 4.15. I'm on the edge at this point whether I'd even consider this a backporting candidate.

Jan

#2 lore raw

Jan Beulich writes ("Re: [PATCH][4.15] x86/shadow: replace bogus return path in shadow_get_page_from_l1e()"):

Quoted 6 lines · Jan Beulich
Quoted 5 lines

Prior to be640b1800bb ("x86: make get_page_from_l1e() return a proper error code") a positive return value did indicate an error. Said commit failed to adjust this return path, but luckily the only caller has always been inside a shadow_mode_refcounts() conditional.

Quoted 8 lines
Quoted 3 lines

Subsequent changes caused 1 to end up at the default (error) label in the caller's switch() again, but the returning of 1 (== _PAGE_PRESENT) is still rather confusing here, and a latent risk.

The confusion on my part was so significant that I screwed up the shadow mode fix for "VMX: use a single, global APIC access page" (which turned out to be necessary) initially. Hence my proposing this for 4.15.

Right. I'm sympathetic, but I would like to hear from another maintainer of this code, as to their opinion about how much this change removes the potential for confusion.

Quoted 2 lines

I'm on the edge at this point whether
I'd even consider this a backporting candidate.

I think you mean you think that even though the code does not compile to something actually buggy now, this is sufficiently bad a confusion that it risks bugs in stable trees, so you are considering backporting.

Thanks, that is a useful piece of perspective.

Ian.

Reviewed-by on v1 1/1
#3 lore raw
In reply to Jan Beulich
Quoted 5 lines · Jan Beulich

Prior to be640b1800bb ("x86: make get_page_from_l1e() return a proper error code") a positive return value did indicate an error. Said commit failed to adjust this return path, but luckily the only caller has always been inside a shadow_mode_refcounts() conditional.

Quoted 8 lines

Subsequent changes caused 1 to end up at the default (error) label in the caller's switch() again, but the returning of 1 (== _PAGE_PRESENT) is still rather confusing here, and a latent risk.

Convert to an ASSERT() instead, just in case any new caller would appear.

Yikes, and only 9 years to notice.

#4 lore raw

Andrew Cooper writes ("Re: [PATCH][4.15] x86/shadow: replace bogus return path in shadow_get_page_from_l1e()"):

Quoted 10 lines · Jan Beulich
Quoted 9 lines

Prior to be640b1800bb ("x86: make get_page_from_l1e() return a proper error code") a positive return value did indicate an error. Said commit failed to adjust this return path, but luckily the only caller has always been inside a shadow_mode_refcounts() conditional.

Subsequent changes caused 1 to end up at the default (error) label in the caller's switch() again, but the returning of 1 (== _PAGE_PRESENT) is still rather confusing here, and a latent risk.

Quoted 8 lines
Quoted 4 lines

Convert to an ASSERT() instead, just in case any new caller would appear.

Yikes, and only 9 years to notice.

Ah here we are,

Thanks

Acked-by on v1 1/1
#5 lore raw
In reply to Jan Beulich
Quoted 5 lines · Jan Beulich

Prior to be640b1800bb ("x86: make get_page_from_l1e() return a proper error code") a positive return value did indicate an error. Said commit failed to adjust this return path, but luckily the only caller has always been inside a shadow_mode_refcounts() conditional.

Quoted 8 lines

Subsequent changes caused 1 to end up at the default (error) label in the caller's switch() again, but the returning of 1 (== _PAGE_PRESENT) is still rather confusing here, and a latent risk.

Convert to an ASSERT() instead, just in case any new caller would appear.