Skip to content

Commit 0aad568

Browse files
jgross1David Vrabel
authored andcommitted
xen: Hide get_phys_to_machine() to be able to tune common path
Today get_phys_to_machine() is always called when the mfn for a pfn is to be obtained. Add a wrapper __pfn_to_mfn() as inline function to be able to avoid calling get_phys_to_machine() when possible as soon as the switch to a linear mapped p2m list has been done. Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: David Vrabel <david.vrabel@citrix.com> Signed-off-by: David Vrabel <david.vrabel@citrix.com>
1 parent 792230c commit 0aad568

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

arch/x86/include/asm/xen/page.h

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,29 @@ extern int clear_foreign_p2m_mapping(struct gnttab_unmap_grant_ref *unmap_ops,
5959
struct page **pages, unsigned int count);
6060
extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
6161

62+
/*
63+
* When to use pfn_to_mfn(), __pfn_to_mfn() or get_phys_to_machine():
64+
* - pfn_to_mfn() returns either INVALID_P2M_ENTRY or the mfn. No indicator
65+
* bits (identity or foreign) are set.
66+
* - __pfn_to_mfn() returns the found entry of the p2m table. A possibly set
67+
* identity or foreign indicator will be still set. __pfn_to_mfn() is
68+
* encapsulating get_phys_to_machine().
69+
* - get_phys_to_machine() is to be called by __pfn_to_mfn() only to allow
70+
* for future optimizations.
71+
*/
72+
static inline unsigned long __pfn_to_mfn(unsigned long pfn)
73+
{
74+
return get_phys_to_machine(pfn);
75+
}
76+
6277
static inline unsigned long pfn_to_mfn(unsigned long pfn)
6378
{
6479
unsigned long mfn;
6580

6681
if (xen_feature(XENFEAT_auto_translated_physmap))
6782
return pfn;
6883

69-
mfn = get_phys_to_machine(pfn);
84+
mfn = __pfn_to_mfn(pfn);
7085

7186
if (mfn != INVALID_P2M_ENTRY)
7287
mfn &= ~(FOREIGN_FRAME_BIT | IDENTITY_FRAME_BIT);
@@ -79,7 +94,7 @@ static inline int phys_to_machine_mapping_valid(unsigned long pfn)
7994
if (xen_feature(XENFEAT_auto_translated_physmap))
8095
return 1;
8196

82-
return get_phys_to_machine(pfn) != INVALID_P2M_ENTRY;
97+
return __pfn_to_mfn(pfn) != INVALID_P2M_ENTRY;
8398
}
8499

85100
static inline unsigned long mfn_to_pfn_no_overrides(unsigned long mfn)
@@ -113,7 +128,7 @@ static inline unsigned long mfn_to_pfn(unsigned long mfn)
113128
return mfn;
114129

115130
pfn = mfn_to_pfn_no_overrides(mfn);
116-
if (get_phys_to_machine(pfn) != mfn) {
131+
if (__pfn_to_mfn(pfn) != mfn) {
117132
/*
118133
* If this appears to be a foreign mfn (because the pfn
119134
* doesn't map back to the mfn), then check the local override
@@ -129,8 +144,7 @@ static inline unsigned long mfn_to_pfn(unsigned long mfn)
129144
* entry doesn't map back to the mfn and m2p_override doesn't have a
130145
* valid entry for it.
131146
*/
132-
if (pfn == ~0 &&
133-
get_phys_to_machine(mfn) == IDENTITY_FRAME(mfn))
147+
if (pfn == ~0 && __pfn_to_mfn(mfn) == IDENTITY_FRAME(mfn))
134148
pfn = mfn;
135149

136150
return pfn;
@@ -176,7 +190,7 @@ static inline unsigned long mfn_to_local_pfn(unsigned long mfn)
176190
return mfn;
177191

178192
pfn = mfn_to_pfn(mfn);
179-
if (get_phys_to_machine(pfn) != mfn)
193+
if (__pfn_to_mfn(pfn) != mfn)
180194
return -1; /* force !pfn_valid() */
181195
return pfn;
182196
}

arch/x86/xen/mmu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ static pteval_t pte_pfn_to_mfn(pteval_t val)
387387
unsigned long mfn;
388388

389389
if (!xen_feature(XENFEAT_auto_translated_physmap))
390-
mfn = get_phys_to_machine(pfn);
390+
mfn = __pfn_to_mfn(pfn);
391391
else
392392
mfn = pfn;
393393
/*

arch/x86/xen/p2m.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ static int m2p_add_override(unsigned long mfn, struct page *page,
787787
* because mfn_to_pfn (that ends up being called by GUPF) will
788788
* return the backend pfn rather than the frontend pfn. */
789789
pfn = mfn_to_pfn_no_overrides(mfn);
790-
if (get_phys_to_machine(pfn) == mfn)
790+
if (__pfn_to_mfn(pfn) == mfn)
791791
set_phys_to_machine(pfn, FOREIGN_FRAME(mfn));
792792

793793
return 0;
@@ -967,7 +967,7 @@ static int m2p_remove_override(struct page *page,
967967
* pfn again. */
968968
mfn &= ~FOREIGN_FRAME_BIT;
969969
pfn = mfn_to_pfn_no_overrides(mfn);
970-
if (get_phys_to_machine(pfn) == FOREIGN_FRAME(mfn) &&
970+
if (__pfn_to_mfn(pfn) == FOREIGN_FRAME(mfn) &&
971971
m2p_find_override(mfn) == NULL)
972972
set_phys_to_machine(pfn, mfn);
973973

@@ -992,7 +992,7 @@ int clear_foreign_p2m_mapping(struct gnttab_unmap_grant_ref *unmap_ops,
992992
}
993993

994994
for (i = 0; i < count; i++) {
995-
unsigned long mfn = get_phys_to_machine(page_to_pfn(pages[i]));
995+
unsigned long mfn = __pfn_to_mfn(page_to_pfn(pages[i]));
996996
unsigned long pfn = page_to_pfn(pages[i]);
997997

998998
if (mfn == INVALID_P2M_ENTRY || !(mfn & FOREIGN_FRAME_BIT)) {

0 commit comments

Comments
 (0)