Skip to contentSkip to conversation

x86/P2M: correct type use in p2m_put_gfn()

PATCH In review Jan Beulich 2 participants 5 messages Feb 3 – Feb 4

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/P2M: correct type use in p2m_put_gfn()

Everywhere else gfn_t are passed into respective GFN locking macros: Do so here as well.

Amends: 819cdc5a7301 ("x86/p2m: re-arrange {,__}put_gfn()")

---
Easy to spot by adding ASSERT(!gfn_eq(g, INVALID_GFN)) to the respective macros. While imo that should be a correct thing to do (as with hypothetical split locks a valid GFN would really need passing in, in order to be able to figure out which lock to use), we can't do so right
now: The lock is acquired ahead of respective checking in a number of places, e.g. in p2m_get_gfn_type_access().

There's no clear Fixes: tag to use, I think - the problem looks to have been introduced by the gradual conversion to gfn_t. I probably should not have added gfn_x() in the referenced commit, to unbreak things already at that time.

xen/arch/x86/mm/p2m.c +2 -2
@@ -338,9 +338,9 @@ mfn_t p2m_get_gfn_type_access(struct p2m
 
 void p2m_put_gfn(struct p2m_domain *p2m, gfn_t gfn)
 {
-    ASSERT(gfn_locked_by_me(p2m, gfn_x(gfn)));
+    ASSERT(gfn_locked_by_me(p2m, gfn));
 
-    gfn_unlock(p2m, gfn_x(gfn), 0);
+    gfn_unlock(p2m, gfn, 0);
 }
 
 static struct page_info *get_page_from_mfn_and_type(
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Jan Beulich

Everywhere else gfn_t are passed into respective GFN locking macros: Do so here as well.

Amends: 819cdc5a7301 ("x86/p2m: re-arrange {,__}put_gfn()")

Quoted 7 lines

---
Easy to spot by adding ASSERT(!gfn_eq(g, INVALID_GFN)) to the respective macros. While imo that should be a correct thing to do (as with hypothetical split locks a valid GFN would really need passing in, in order to be able to figure out which lock to use), we can't do so right
now: The lock is acquired ahead of respective checking in a number of places, e.g. in p2m_get_gfn_type_access().

Could we convert those macros into static inlines? It's dangerous to use macros like those when the parameters are dropped, as the parameter is not evaluated at all.

Thanks, Roger.

#2 lore raw
Quoted 8 lines · Roger Pau Monné
Quoted 5 lines · Jan Beulich

Everywhere else gfn_t are passed into respective GFN locking macros: Do so here as well.

Amends: 819cdc5a7301 ("x86/p2m: re-arrange {,__}put_gfn()")

Thanks.

Quoted 11 lines
Quoted 7 lines

---
Easy to spot by adding ASSERT(!gfn_eq(g, INVALID_GFN)) to the respective macros. While imo that should be a correct thing to do (as with hypothetical split locks a valid GFN would really need passing in, in order to be able to figure out which lock to use), we can't do so right
now: The lock is acquired ahead of respective checking in a number of places, e.g. in p2m_get_gfn_type_access().

Could we convert those macros into static inlines? It's dangerous to use macros like those when the parameters are dropped, as the parameter is not evaluated at all.

It is. Seeing how the header is used, converting may be possible. There's one slight concern I'd have with doing so: It would move us one step closer to giving the impression that the arguments passed are correct at all use sites (while as long as they're entirely ignored, that's kind of a hint that they may need checking). I can't point at it right now, but I'm pretty sure I had come across at least one place where they're pretty clearly wrong.

Jan

#3 lore raw
Quoted 24 lines · Jan Beulich
Quoted 8 lines · Roger Pau Monné
Quoted 5 lines · Jan Beulich

Everywhere else gfn_t are passed into respective GFN locking macros: Do so here as well.

Amends: 819cdc5a7301 ("x86/p2m: re-arrange {,__}put_gfn()")

Thanks.

Quoted 11 lines
Quoted 7 lines

---
Easy to spot by adding ASSERT(!gfn_eq(g, INVALID_GFN)) to the respective macros. While imo that should be a correct thing to do (as with hypothetical split locks a valid GFN would really need passing in, in order to be able to figure out which lock to use), we can't do so right
now: The lock is acquired ahead of respective checking in a number of places, e.g. in p2m_get_gfn_type_access().

Could we convert those macros into static inlines? It's dangerous to use macros like those when the parameters are dropped, as the parameter is not evaluated at all.

Quoted 7 lines

It is. Seeing how the header is used, converting may be possible. There's one slight concern I'd have with doing so: It would move us one step closer to giving the impression that the arguments passed are correct at all use sites (while as long as they're entirely ignored, that's kind of a hint that they may need checking). I can't point at it right now, but I'm pretty sure I had come across at least one place where they're pretty clearly wrong.

Well, having at least the type check is better than not checking anything at all. By clearly wrong you mean passing INVALID_GFN, or a random GFN that had something do to with the context?

Thanks, Roger.

#4 lore raw
Quoted 23 lines · Roger Pau Monné
Quoted 14 lines · Jan Beulich
Quoted 9 lines · Roger Pau Monné
Quoted 7 lines · Jan Beulich

---
Easy to spot by adding ASSERT(!gfn_eq(g, INVALID_GFN)) to the respective macros. While imo that should be a correct thing to do (as with hypothetical split locks a valid GFN would really need passing in, in order to be able to figure out which lock to use), we can't do so right
now: The lock is acquired ahead of respective checking in a number of places, e.g. in p2m_get_gfn_type_access().

Quoted 3 lines

Could we convert those macros into static inlines? It's dangerous to use macros like those when the parameters are dropped, as the parameter is not evaluated at all.

Quoted 7 lines

It is. Seeing how the header is used, converting may be possible. There's one slight concern I'd have with doing so: It would move us one step closer to giving the impression that the arguments passed are correct at all use sites (while as long as they're entirely ignored, that's kind of a hint that they may need checking). I can't point at it right now, but I'm pretty sure I had come across at least one place where they're pretty clearly wrong.

Quoted 3 lines

Well, having at least the type check is better than not checking anything at all. By clearly wrong you mean passing INVALID_GFN, or a random GFN that had something do to with the context?

What I seem to recall is a bogus order value being passed somewhere.

Jan