xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Wei Liu <wei.liu2@citrix.com>
To: Xen-devel <xen-devel@lists.xenproject.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	Wei Liu <wei.liu2@citrix.com>, Jan Beulich <JBeulich@suse.com>
Subject: [PATCH v6 3/9] x86/mm: add disallow_mask parameter to get_page_from_l1e
Date: Tue, 13 Feb 2018 20:04:02 +0000	[thread overview]
Message-ID: <20180213200408.5463-4-wei.liu2@citrix.com> (raw)
In-Reply-To: <20180213200408.5463-1-wei.liu2@citrix.com>

This will make moving pv mm code easier. To retain same behaviour the
base mask is copied to shadow code.

No functional change.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
 xen/arch/x86/mm.c               | 13 +++++++------
 xen/arch/x86/mm/shadow/multi.c  | 15 ++++++++++++---
 xen/arch/x86/pv/ro-page-fault.c |  2 +-
 xen/include/asm-x86/mm.h        |  3 ++-
 4 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index bfa0a6436c..53212bcce3 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -831,7 +831,8 @@ static int print_mmio_emul_range(unsigned long s, unsigned long e, void *arg)
  */
 int
 get_page_from_l1e(
-    l1_pgentry_t l1e, struct domain *l1e_owner, struct domain *pg_owner)
+    l1_pgentry_t l1e, struct domain *l1e_owner, struct domain *pg_owner,
+    uint32_t disallow_mask)
 {
     unsigned long mfn = l1e_get_pfn(l1e);
     struct page_info *page = mfn_to_page(_mfn(mfn));
@@ -843,10 +844,9 @@ get_page_from_l1e(
     if ( !(l1f & _PAGE_PRESENT) )
         return 0;
 
-    if ( unlikely(l1f & l1_disallow_mask(l1e_owner)) )
+    if ( unlikely(l1f & disallow_mask) )
     {
-        gdprintk(XENLOG_WARNING, "Bad L1 flags %x\n",
-                 l1f & l1_disallow_mask(l1e_owner));
+        gdprintk(XENLOG_WARNING, "Bad L1 flags %x\n", l1f & disallow_mask);
         return -EINVAL;
     }
 
@@ -1318,7 +1318,7 @@ static int alloc_l1_table(struct page_info *page)
 
     for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ )
     {
-        switch ( ret = get_page_from_l1e(pl1e[i], d, d) )
+        switch ( ret = get_page_from_l1e(pl1e[i], d, d, l1_disallow_mask(d)) )
         {
         default:
             goto fail;
@@ -1957,7 +1957,8 @@ static int mod_l1_entry(l1_pgentry_t *pl1e, l1_pgentry_t nl1e,
             return rc ? 0 : -EBUSY;
         }
 
-        switch ( rc = get_page_from_l1e(nl1e, pt_dom, pg_dom) )
+        switch ( rc = get_page_from_l1e(nl1e, pt_dom, pg_dom,
+                                        l1_disallow_mask(pt_dom)) )
         {
         default:
             if ( page )
diff --git a/xen/arch/x86/mm/shadow/multi.c b/xen/arch/x86/mm/shadow/multi.c
index a6372e3a02..02c2198c9b 100644
--- a/xen/arch/x86/mm/shadow/multi.c
+++ b/xen/arch/x86/mm/shadow/multi.c
@@ -858,13 +858,21 @@ shadow_get_page_from_l1e(shadow_l1e_t sl1e, struct domain *d, p2m_type_t type)
     int res;
     mfn_t mfn;
     struct domain *owner;
+    /* The disallow mask is taken from arch/x86/mm.c for HVM guest */
+    uint32_t disallow_mask =
+        ~(_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | _PAGE_ACCESSED |
+          _PAGE_DIRTY | _PAGE_AVAIL | _PAGE_AVAIL_HIGH | _PAGE_NX);
 
+    disallow_mask = (disallow_mask | _PAGE_GNTTAB) & ~_PAGE_GLOBAL;
+    disallow_mask &= ~PAGE_CACHE_ATTRS;
+
+    ASSERT(is_hvm_domain(d));
     ASSERT(!sh_l1e_is_magic(sl1e));
 
     if ( !shadow_mode_refcounts(d) )
         return 1;
 
-    res = get_page_from_l1e(sl1e, d, d);
+    res = get_page_from_l1e(sl1e, d, d, disallow_mask);
 
     // If a privileged domain is attempting to install a map of a page it does
     // not own, we let it succeed anyway.
@@ -877,7 +885,7 @@ shadow_get_page_from_l1e(shadow_l1e_t sl1e, struct domain *d, p2m_type_t type)
     {
         res = xsm_priv_mapping(XSM_TARGET, d, owner);
         if ( !res ) {
-            res = get_page_from_l1e(sl1e, d, owner);
+            res = get_page_from_l1e(sl1e, d, owner, disallow_mask);
             SHADOW_PRINTK("privileged domain %d installs map of mfn %"PRI_mfn" "
                            "which is owned by d%d: %s\n",
                            d->domain_id, mfn_x(mfn), owner->domain_id,
@@ -896,7 +904,8 @@ shadow_get_page_from_l1e(shadow_l1e_t sl1e, struct domain *d, p2m_type_t type)
            we can just grab a reference directly. */
         mfn = shadow_l1e_get_mfn(sl1e);
         if ( mfn_valid(mfn) )
-            res = get_page_from_l1e(sl1e, d, page_get_owner(mfn_to_page(mfn)));
+            res = get_page_from_l1e(sl1e, d, page_get_owner(mfn_to_page(mfn)),
+                                    disallow_mask);
     }
 
     if ( unlikely(res < 0) )
diff --git a/xen/arch/x86/pv/ro-page-fault.c b/xen/arch/x86/pv/ro-page-fault.c
index 7e0e7e8dfc..04b4e455f5 100644
--- a/xen/arch/x86/pv/ro-page-fault.c
+++ b/xen/arch/x86/pv/ro-page-fault.c
@@ -127,7 +127,7 @@ static int ptwr_emulated_update(unsigned long addr, paddr_t old, paddr_t val,
 
     /* Check the new PTE. */
     nl1e = l1e_from_intpte(val);
-    switch ( ret = get_page_from_l1e(nl1e, d, d) )
+    switch ( ret = get_page_from_l1e(nl1e, d, d, l1_disallow_mask(d)) )
     {
     default:
         if ( is_pv_32bit_domain(d) && (bytes == 4) && (unaligned_addr & 4) &&
diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h
index 741c98575e..dca1831382 100644
--- a/xen/include/asm-x86/mm.h
+++ b/xen/include/asm-x86/mm.h
@@ -376,7 +376,8 @@ int  put_page_type_preemptible(struct page_info *page);
 int  get_page_type_preemptible(struct page_info *page, unsigned long type);
 int  put_old_guest_table(struct vcpu *);
 int  get_page_from_l1e(
-    l1_pgentry_t l1e, struct domain *l1e_owner, struct domain *pg_owner);
+    l1_pgentry_t l1e, struct domain *l1e_owner, struct domain *pg_owner,
+    uint32_t disallow_mask);
 void put_page_from_l1e(l1_pgentry_t l1e, struct domain *l1e_owner);
 
 static inline struct page_info *get_page_from_mfn(mfn_t mfn, struct domain *d)
-- 
2.11.0


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2018-02-13 20:05 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-13 20:03 [PATCH v6 0/9] x86: refactor mm.c Wei Liu
2018-02-13 20:04 ` [PATCH v6 1/9] x86/mm: add pv prefix to {alloc, free}_page_type Wei Liu
2018-03-08 17:03   ` Jan Beulich
2018-03-08 17:05   ` Jan Beulich
2018-02-13 20:04 ` [PATCH v6 2/9] x86/mm: move disallow masks to pv/mm.h Wei Liu
2018-02-13 20:04 ` Wei Liu [this message]
2018-03-13 15:54   ` [PATCH v6 3/9] x86/mm: add disallow_mask parameter to get_page_from_l1e Jan Beulich
2018-03-19 12:10     ` Tim Deegan
2018-02-13 20:04 ` [PATCH v6 4/9] x86/mm: add pv prefix to _put_final_page_type Wei Liu
2018-03-13 15:55   ` Jan Beulich
2018-02-13 20:04 ` [PATCH v6 5/9] x86/mm: factor out pv_dec_linear_pt Wei Liu
2018-03-13 15:59   ` Jan Beulich
2018-02-13 20:04 ` [PATCH v6 6/9] x86/mm: export set_tlbflush_timestamp Wei Liu
2018-03-13 16:06   ` Jan Beulich
2018-02-13 20:04 ` [PATCH v6 7/9] x86/mm: provide put_page_type_ptpg{, _preemptible} Wei Liu
2018-03-13 16:10   ` Jan Beulich
2018-03-13 16:17   ` Jan Beulich
2018-02-13 20:04 ` [PATCH v6 8/9] x86/mm: move PV code to pv/mm.c Wei Liu
2018-02-13 20:04 ` [PATCH v6 9/9] x86/mm: remove now unused inclusion of pv/mm.h Wei Liu
2018-03-08 12:17 ` [PATCH v6 0/9] x86: refactor mm.c Wei Liu
2018-03-08 12:36   ` Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180213200408.5463-4-wei.liu2@citrix.com \
    --to=wei.liu2@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).