xen/p2m: Using INVALID_MFN instead of mfn_valid
PATCH 2/3 xen/p2m: Using INVALID_MFN instead of mfn_valid
64 bits big bar's MMIO address may out of the highest gfn, then mfn_valid may return failure, so using INVALID_MFN to measure.
xen/arch/x86/mm/p2m-ept.c +1 -1
@@ -428,7 +428,7 @@ ept_set_entry(struct p2m_domain *p2m, un }/* Track the highest gfn for which we have ever had a valid mapping */ -if (mfn_valid (mfn_x (mfn)) && +if ( (mfn_x (mfn) !=INVALID_MFN ) && (gfn + (1UL << order) -1 > p2m->max_mapped_pfn) ) p2m->max_mapped_pfn = gfn + (1UL << order) -1 ;
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Xudong Hao
64 bits big bar's MMIO address may out of the highest gfn, then
mfn_validmay return failure, so usingINVALID_MFNto measure.
Hmm, that can be true for 32-bit BARs too (on systems with less than 4Gb).
Quoted 7 lines
Signed-off-by Xiantao Zhang <[email protected]>Signed-off-by Xudong Hao <[email protected]>diff -r
663eb766cddexen/arch/x86/mm/p2m-ept.c
xen/arch/x86/mm/p2m-ept.c ept_set_entry(struct p2m_domain *p2m, un · line 433
Quoted 7 lines
xen/arch/x86/mm/p2m-ept.c +1
-1@@ -428,7 +428,7 @@ ept_set_entry(struct p2m_domain *p2m, un }/* Track the highest gfn for which we have ever had a valid mapping */ -if (mfn_valid (mfn_x (mfn)) && +if ( (mfn_x (mfn) !=INVALID_MFN ) && (gfn + (1UL << order) -1 > p2m->max_mapped_pfn) ) p2m->max_mapped_pfn = gfn + (1UL << order) -1 ;
Depending on how the above comment gets addressed (i.e. whether MMIO MFNs are to be considered here at all), this might need changing anyway, as this a huge max_mapped_pfn value likely wouldn't be very useful anymore.
Jan
Quoted 8 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: Wednesday, August 15, 2012 5:22 PM
To: Hao, Xudong
Cc: Zhang, Xiantao; [email protected]; [email protected]
Subject: Re: [Xen-devel] [PATCH 2/3] xen/p2m: UsingINVALID_MFNinstead ofmfn_valid
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Xudong Hao
64 bits big bar's MMIO address may out of the highest gfn, then
mfn_validmay return failure, so usingINVALID_MFNto measure.Hmm, that can be true for 32-bit BARs too (on systems with less than 4Gb).
Exactly right, thanks comments.
Quoted 9 lines
Quoted 9 lines
Signed-off-by Xiantao Zhang <[email protected]>Signed-off-by Xudong Hao <[email protected]>diff -r
663eb766cddexen/arch/x86/mm/p2m-ept.cxen/arch/x86/mm/p2m-ept.c +0
-0@@ -428,7 +428,7 @@ ept_set_entry(struct p2m_domain *p2m, un }
Quoted 11 lines
xen/arch/x86/mm/p2m-ept.c ept_set_entry(struct p2m_domain *p2m, un · line 433
Quoted 5 lines
xen/arch/x86/mm/p2m-ept.c +1
-1/* Track the highest gfn for which we have ever had a valid mapping */ -if (mfn_valid (mfn_x (mfn)) && +if ( (mfn_x (mfn) !=INVALID_MFN ) && (gfn + (1UL << order) -1 > p2m->max_mapped_pfn) ) p2m->max_mapped_pfn = gfn + (1UL << order) -1 ;Depending on how the above comment gets addressed (i.e. whether MMIO MFNs are to be considered here at all), this might need changing anyway, as this a huge
max_mapped_pfnvalue likely wouldn't be very useful anymore.
Jan,
Your viewpoint is similar with us. Here max_mapped_pfn value is for memory but not for MMIO. I think this is a simple changes, do you have another suggestion?
Quoted 2 lines
Jan
Quoted 19 lines
Quoted 8 lines
Quoted 1 line · Xudong
From: Jan Beulich [mailto:[email protected]]
Quoted 6 lines
Quoted 1 line
Quoted 1 line · Xudong Hao
xen/arch/x86/mm/p2m-ept.c +0
-0@@ -428,7 +428,7 @@ ept_set_entry(struct p2m_domain *p2m, un }Quoted 10 lines
xen/arch/x86/mm/p2m-ept.c ept_set_entry(struct p2m_domain *p2m, un · line 433
Quoted 5 lines
xen/arch/x86/mm/p2m-ept.c +1
-1/* Track the highest gfn for which we have ever had a valid mapping */ -if (mfn_valid (mfn_x (mfn)) && +if ( (mfn_x (mfn) !=INVALID_MFN ) && (gfn + (1UL << order) -1 > p2m->max_mapped_pfn) ) p2m->max_mapped_pfn = gfn + (1UL << order) -1 ;Depending on how the above comment gets addressed (i.e. whether MMIO MFNs are to be considered here at all), this might need changing anyway, as this a huge
max_mapped_pfnvalue likely wouldn't be very useful anymore.
Quoted 3 lines
Your viewpoint is similar with us. Here
max_mapped_pfnvalue is for memory but not for MMIO. I think this is a simple changes, do you have another suggestion?
The question is why this needs to be changed at all. If this is only about RAM, then mfn_valid() is the right thing to use. If this is about MMIO too, then the condition is wrong already (since, as we appear to agree, even now there can be MMIO above RAM, provided there's little enough RAM).
Jan
Quoted 32 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: Thursday, August 16, 2012 6:12 PM
To: Hao, Xudong
Cc: Zhang, Xiantao; [email protected]; [email protected]
Subject: RE: [Xen-devel] [PATCH 2/3] xen/p2m: UsingINVALID_MFNinstead ofmfn_validQuoted 9 lines
Quoted 9 lines
Quoted 1 line · Xudong
From: Jan Beulich [mailto:[email protected]]
xen/arch/x86/mm/p2m-ept.c ept_set_entry(struct p2m_domain *p2m, un · line 430
Quoted 7 lines
Quoted 1 line
Quoted 1 line · Xudong Hao
xen/arch/x86/mm/p2m-ept.c +0
-0@@ -428,7 +428,7 @@ ept_set_entry(struct p2m_domain *p2m, un }/* Track the highest gfn for which we have ever had a valid mapping */
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
xen/arch/x86/mm/p2m-ept.c +1
-1-if (mfn_valid (mfn_x (mfn)) && +if ( (mfn_x (mfn) !=INVALID_MFN ) && (gfn + (1UL << order) -1 > p2m->max_mapped_pfn) ) p2m->max_mapped_pfn = gfn + (1UL << order) -1 ;Quoted 8 lines
Quoted 4 lines
Depending on how the above comment gets addressed (i.e. whether MMIO MFNs are to be considered here at all), this might need changing anyway, as this a huge
max_mapped_pfnvalue likely wouldn't be very useful anymore.Your viewpoint is similar with us. Here
max_mapped_pfnvalue is for memory but not for MMIO. I think this is a simple changes, do you have another suggestion?
Quoted 6 lines
The question is why this needs to be changed at all. If this is only about RAM, then
mfn_valid()is the right thing to use. If this is about MMIO too, then the condition is wrong already (since, as we appear to agree, even now there can be MMIO above RAM, provided there's little enough RAM).
The original code considered EPT only, now for the device assignment, it need to consider MMIO. So how about remove the mfn_valid() here?
Quoted 1 line
Jan
Quoted 40 lines
Quoted 33 lines
Quoted 1 line · Xudong
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: Thursday, August 16, 2012 6:12 PM
To: Hao, Xudong
Cc: Zhang, Xiantao; [email protected]; [email protected]
Subject: RE: [Xen-devel] [PATCH 2/3] xen/p2m: UsingINVALID_MFNinstead ofmfn_validQuoted 9 lines
Quoted 9 lines
Quoted 1 line · Xudong
From: Jan Beulich [mailto:[email protected]]
xen/arch/x86/mm/p2m-ept.c ept_set_entry(struct p2m_domain *p2m, un · line 430
Quoted 7 lines
Quoted 1 line
Quoted 1 line · Xudong Hao
xen/arch/x86/mm/p2m-ept.c +0
-0@@ -428,7 +428,7 @@ ept_set_entry(struct p2m_domain *p2m, un }/* Track the highest gfn for which we have ever had a valid mapping */
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
xen/arch/x86/mm/p2m-ept.c +1
-1-if (mfn_valid (mfn_x (mfn)) && +if ( (mfn_x (mfn) !=INVALID_MFN ) && (gfn + (1UL << order) -1 > p2m->max_mapped_pfn) ) p2m->max_mapped_pfn = gfn + (1UL << order) -1 ;Quoted 8 lines
Quoted 4 lines
Depending on how the above comment gets addressed (i.e. whether MMIO MFNs are to be considered here at all), this might need changing anyway, as this a huge
max_mapped_pfnvalue likely wouldn't be very useful anymore.Your viewpoint is similar with us. Here
max_mapped_pfnvalue is for memory but not for MMIO. I think this is a simple changes, do you have another suggestion?Quoted 6 lines
The question is why this needs to be changed at all. If this is only about RAM, then
mfn_valid()is the right thing to use. If this is about MMIO too, then the condition is wrong already (since, as we appear to agree, even now there can be MMIO above RAM, provided there's little enough RAM).
Quoted 2 lines
The original code considered EPT only, now for the device assignment, it need to consider MMIO. So how about remove the
mfn_valid()here?
I don't think it's there without reason, but I'm not sure. Tim?
Jan
Quoted 30 lines · Jan Beulich
Quoted 30 lines
Quoted 29 lines
Quoted 8 lines · Xudong
Quoted 7 lines
xen/arch/x86/mm/p2m-ept.c ept_set_entry(struct p2m_domain *p2m, un · line 430
Quoted 7 lines
Quoted 1 line
Quoted 1 line · Xudong Hao
xen/arch/x86/mm/p2m-ept.c +0
-0@@ -428,7 +428,7 @@ ept_set_entry(struct p2m_domain *p2m, un }/* Track the highest gfn for which we have ever had a valid mapping */
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
xen/arch/x86/mm/p2m-ept.c +1
-1-if (mfn_valid (mfn_x (mfn)) && +if ( (mfn_x (mfn) !=INVALID_MFN ) && (gfn + (1UL << order) -1 > p2m->max_mapped_pfn) ) p2m->max_mapped_pfn = gfn + (1UL << order) -1 ;Quoted 8 lines
Quoted 4 lines
Depending on how the above comment gets addressed (i.e. whether MMIO MFNs are to be considered here at all), this might need changing anyway, as this a huge
max_mapped_pfnvalue likely wouldn't be very useful anymore.Your viewpoint is similar with us. Here
max_mapped_pfnvalue is for memory but not for MMIO. I think this is a simple changes, do you have another suggestion?The question is why this needs to be changed at all. If this is only about RAM, then
mfn_valid()is the right thing to use. If this is about MMIO too, then the condition is wrong already (since, as we appear to agree, even now there can be MMIO above RAM, provided there's little enough RAM).
Quoted 4 lines
Quoted 2 lines
The original code considered EPT only, now for the device assignment, it need to consider MMIO. So how about remove the
mfn_valid()here?I don't think it's there without reason, but I'm not sure. Tim?
max_mapped_pfn should be the highest entry that's even had a mapping in the p2m. Its intent was to provide a fast path exit from p2m lookups in the (at the time) common case where _emulated_ MMIO addresses were higher than all the actual p2m mappings, and the cost of a failed lookup (on 32-bit) was a page fault in the linear map. Also, at the time, the p2m wasn't typed and we didn't support direct MMIO, so mfn_valid() was equivalent to 'entry is present'.
These days, I'm not sure how useful max_mapped_pfn is, since (a) for any VM with >3GB RAM the emulated MMIO lookups are not avoided, and (b) on 64-bit builds there's not pagefault for a failed lookup. Also it seems to have been abused in a few places to do for() loops that touch every PFN instead of just walking the tries. So I might get rid of it after 4.2 is out.
In the meantime, the patch at the top of this thread is definitely an improvement. However, I think this is a better fix:
xen/arch/x86/mm/p2m-ept.c +1 -1
@@ -428,7 +428,7 @@ ept_set_entry(struct p2m_domain *p2m, un }/* Track the highest gfn for which we have ever had a valid mapping */ -if (mfn_valid (mfn_x (mfn)) && +if ( p2mt != p2m_invalid && (gfn + (1UL << order) -1 > p2m->max_mapped_pfn) ) p2m->max_mapped_pfn = gfn + (1UL << order) -1 ;
xen/arch/x86/mm/p2m-pt.c +1 -1
@@ -454,7 +454,7 @@ p2m_set_entry(struct p2m_domain *p2m, un }/* Track the highest gfn for which we have ever had a valid mapping */ -if (mfn_valid (mfn) +if ( p2mt != p2m_invalid && (gfn + (1UL << page_order) -1 > p2m->max_mapped_pfn) ) p2m->max_mapped_pfn = gfn + (1UL << page_order) -1 ;
and I'll commit it this afternoon or tomorrow.
Tim.
Quoted 6 lines · Xudong
Quoted 6 lines
*/
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
xen/arch/x86/mm/p2m-ept.c +1
-1-if (mfn_valid (mfn_x (mfn)) && +if ( (mfn_x (mfn) !=INVALID_MFN ) && (gfn + (1UL << order) -1 > p2m->max_mapped_pfn) ) p2m->max_mapped_pfn = gfn + (1UL << order) -1 ;
BTW, here's the change in my PVH/hybrid tree that Tim D had suggested couple months ago:
/* Track the highest gfn for which we have ever had a valid mapping */
- if ( mfn_valid(mfn_x(mfn)) &&
+ if ( p2mt != p2m_invalid && p2mt != p2m_mmio_dm &&
(gfn + (1UL << order) - 1 > p2m->max_mapped_pfn) )
p2m->max_mapped_pfn = gfn + (1UL << order) - 1;thanks,
Mukesh