x86/p2m: fixed p2m_change_type_range() start / end check
PATCH 1/1 x86/p2m: fixed p2m_change_type_range() start / end check
p2m_change_type_range() handles end > max_mapped_pfn, but not start > max_mapped_pfn. Check the latter just after grabbing the lock and bail if true.
--- xen/arch/x86/mm/p2m.c | 7 +++++++ 1 file changed, 7 insertions(+)
xen/arch/x86/mm/p2m.c +7 -0
@@ -976,6 +976,13 @@ void p2m_change_type_range(struct domain *d,ASSERT (p2m_is_changeable (ot) &&p2m_is_changeable (nt));p2m_lock (p2m); + +if ( start > p2m->max_mapped_pfn ) + { +p2m_unlock (p2m); +return ; + } + p2m->defer_nested_flush =1 ;if (unlikely (end > p2m->max_mapped_pfn) )
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
xen/arch/x86/mm/p2m.c void p2m_change_type_range(struct domain *d, · line 984
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 17.04.18 at 19:16, <[email protected]> wrote:
xen/arch/x86/mm/p2m.c +6
-0@@ -976,6 +976,13 @@ void p2m_change_type_range(struct domain *d,ASSERT (p2m_is_changeable (ot) &&p2m_is_changeable (nt));p2m_lock (p2m); + +if ( start > p2m->max_mapped_pfn ) + { +p2m_unlock (p2m); +return ; + }
I realize this is what George has suggested, but I still wonder if this is the right thing to do here: Why is this any more important to check than the more general start >= end (in which case the assertion in the rangeset code would also trigger)? Till now the function assumes "sensible" things to be passed in, but specifically also permitting the [start,~0UL] case (just in a more generalizer fashion). The problem you're trying to fix here is something passing in a nonsense range (starting above the valid range). Yet if we want the function to be immune to nonsense being passed in, I think start < end is what needs checking for, and that check would then perhaps better go after end was already adjusted.
The obvious alternative is for callers to only pass in sane ranges (in which case adding ASSERT() here may be considered, instead of triggering the one in the rangeset code).
In any event you want to add unlikely(), just like the similar end check has.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 25 lines · Jan Beulich
xen/arch/x86/mm/p2m.c void p2m_change_type_range(struct domain *d, · line 984
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 17.04.18 at 19:16, <[email protected]> wrote:
xen/arch/x86/mm/p2m.c +6
-0@@ -976,6 +976,13 @@ void p2m_change_type_range(struct domain *d,ASSERT (p2m_is_changeable (ot) &&p2m_is_changeable (nt));p2m_lock (p2m); + +if ( start > p2m->max_mapped_pfn ) + { +p2m_unlock (p2m); +return ; + }I realize this is what George has suggested, but I still wonder if this is the right thing to do here: Why is this any more important to check than the more general start >= end (in which case the assertion in the rangeset code would also trigger)? Till now the function assumes "sensible" things to be passed in, but specifically also permitting the [start,~0UL] case (just in a more generalizer fashion). The problem you're trying to fix here is something passing in a nonsense range (starting above the valid range). Yet if we want the function to be immune to nonsense being passed in, I think start < end is what needs checking for, and that check would then perhaps better go after end was already adjusted.
Quoted 5 lines
The obvious alternative is for callers to only pass in sane ranges (in which case adding
ASSERT()here may be considered, instead of triggering the one in the rangeset code).In any event you want to add
unlikely(), just like the similar end check has.
FWIW I'll be happy to change the test to unlikely( start < end ), if this is OK with George. I'll test the change now.
Thanks,
Razvan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 26 lines · Razvan Cojocaru
Quoted 25 lines · Jan Beulich
xen/arch/x86/mm/p2m.c void p2m_change_type_range(struct domain *d, · line 984
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 17.04.18 at 19:16, <[email protected]> wrote:
xen/arch/x86/mm/p2m.c +6
-0@@ -976,6 +976,13 @@ void p2m_change_type_range(struct domain *d,ASSERT (p2m_is_changeable (ot) &&p2m_is_changeable (nt));p2m_lock (p2m); + +if ( start > p2m->max_mapped_pfn ) + { +p2m_unlock (p2m); +return ; + }I realize this is what George has suggested, but I still wonder if this is the right thing to do here: Why is this any more important to check than the more general start >= end (in which case the assertion in the rangeset code would also trigger)? Till now the function assumes "sensible" things to be passed in, but specifically also permitting the [start,~0UL] case (just in a more generalizer fashion). The problem you're trying to fix here is something passing in a nonsense range (starting above the valid range). Yet if we want the function to be immune to nonsense being passed in, I think start < end is what needs checking for, and that check would then perhaps better go after end was already adjusted.
Quoted 8 lines
Quoted 5 lines
The obvious alternative is for callers to only pass in sane ranges (in which case adding
ASSERT()here may be considered, instead of triggering the one in the rangeset code).In any event you want to add
unlikely(), just like the similar end check has.FWIW I'll be happy to change the test to unlikely( start < end ), if this is OK with George. I'll test the change now.
Sorry, unlikely(end <= start), obviously.
Thanks,
Razvan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 25 lines · Jan Beulich
xen/arch/x86/mm/p2m.c void p2m_change_type_range(struct domain *d, · line 984
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 17.04.18 at 19:16, <[email protected]> wrote:
xen/arch/x86/mm/p2m.c +6
-0@@ -976,6 +976,13 @@ void p2m_change_type_range(struct domain *d,ASSERT (p2m_is_changeable (ot) &&p2m_is_changeable (nt));p2m_lock (p2m); + +if ( start > p2m->max_mapped_pfn ) + { +p2m_unlock (p2m); +return ; + }I realize this is what George has suggested, but I still wonder if this is the right thing to do here: Why is this any more important to check than the more general start >= end (in which case the assertion in the rangeset code would also trigger)? Till now the function assumes "sensible" things to be passed in, but specifically also permitting the [start,~0UL] case (just in a more generalizer fashion). The problem you're trying to fix here is something passing in a nonsense range (starting above the valid range). Yet if we want the function to be immune to nonsense being passed in, I think start < end is what needs checking for, and that check would then perhaps better go after end was already adjusted.
Quoted 3 lines
The obvious alternative is for callers to only pass in sane ranges (in which case adding
ASSERT()here may be considered, instead of triggering the one in the rangeset code).
The goal of the fix wasn't to get rid of ASSERTs for "nonsense" input entirely, but to accept input which is in fact "sensible" for altp2m systems.
I do agree though, that we should either ASSERT for all "nonsense" input, or handle all such input gracefully. I'm inclined to ASSERT(); in which case maybe it would be best if we put a bunch up front:
ASSERT(start < end);
if ( start > p2m->max_mapped_pfn)
{
ASSERT(!p2m_is_hostp2m(p2m));
...
}if ( end > p2m->max_mapped_pfn )
{
ASSERT(end == ~0UL || !p2m_is_hostp2m(p2m));
...That is, sensible input looks like:
* start < end
* For hostp2ms:
- start <= max_mapped_pfn
- either end <= max_mapped_pfn, or end == ~0UL
(But for altp2ms, start or end > max_mapped_pfn is fine.)
-George
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 18.04.18 at 12:23, <[email protected]> wrote:
That is, sensible input looks like:
* start < end
* For hostp2ms:
- start <=max_mapped_pfn
- either end <=max_mapped_pfn, or end == ~0UL
(But for altp2ms, start or end >max_mapped_pfnis fine.)
So I guess that's part of the difficulty I'm having with the original suggestion:
Why would such input be okay for alternative p2m-s?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 10 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 18.04.18 at 12:23, <[email protected]> wrote:
That is, sensible input looks like:
* start < end
* For hostp2ms:
- start <=max_mapped_pfn
- either end <=max_mapped_pfn, or end == ~0UL
(But for altp2ms, start or end >max_mapped_pfnis fine.)So I guess that's part of the difficulty I'm having with the original suggestion:
Why would such input be okay for alternative p2m-s?
Because altp2ms use max_mapped_pfn to limit what gets propagated to individual altp2m views when the host p2m is updated. See p2m.c:p2m_altp2m_propagate_change().
The motivation for this patch can be found in marc.info/?i=<[email protected]> . In summary:
- Razvan had started keeping more altp2m stuff 'in sync' with the hostp2m, including max_mapped_pfn
- I suggested that was unnecessary, and would reverse the 'filtering' effect that had obviously been put there intentionally
- Razvan posted the above stack trace in which not setting max_mapped_pfn triggered an ASSERT
- I suggested "fixing" p2m_change_type_range() to handle start > max_mapped_pfn instead
You could argue that this 'filtering' is unnecessary, but at the moment that's the way things work; whether it should be changed is a different discussion. You could also argue that we should be doing the filtering before calling p2m_change_type_range(), but it seems to me that this is the right level to do the filtering.
-George
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel