Mailing List Archive

[xen staging] x86/mm: Remove unnecessary mfn_valid() call from get_page_from_l1e()
commit c154abe99d45fad110384e1ea75fad50b65962b3
Author: Andrew Cooper <andrew.cooper3@citrix.com>
AuthorDate: Wed Apr 27 14:43:28 2022 +0100
Commit: Andrew Cooper <andrew.cooper3@citrix.com>
CommitDate: Wed May 18 15:05:18 2022 +0100

x86/mm: Remove unnecessary mfn_valid() call from get_page_from_l1e()

mfn_valid() is not a trivially simple, and contains an evaluate_nospec() for
speculative defence. Avoid calling it redundantly, and just store the result
of the first call.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
xen/arch/x86/mm.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index 67c0427963..796faca641 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -887,7 +887,7 @@ get_page_from_l1e(
uint32_t l1f = l1e_get_flags(l1e);
struct vcpu *curr = current;
struct domain *real_pg_owner;
- bool write;
+ bool write, valid;

if ( unlikely(!(l1f & _PAGE_PRESENT)) )
{
@@ -902,13 +902,15 @@ get_page_from_l1e(
return -EINVAL;
}

- if ( !mfn_valid(_mfn(mfn)) ||
+ valid = mfn_valid(_mfn(mfn));
+
+ if ( !valid ||
(real_pg_owner = page_get_owner_and_reference(page)) == dom_io )
{
int flip = 0;

/* Only needed the reference to confirm dom_io ownership. */
- if ( mfn_valid(_mfn(mfn)) )
+ if ( valid )
put_page(page);

/* DOMID_IO reverts to caller for privilege checks. */
--
generated by git-patchbot for /home/xen/git/xen.git#staging