All of lore.kernel.org
 help / color / mirror / Atom feed
From: Julien Grall <julien.grall@arm.com>
To: xen-devel@lists.xenproject.org
Cc: Oleksandr_Tyshchenko@epam.com,
	Julien Grall <julien.grall@arm.com>,
	sstabellini@kernel.org, Andrii_Anisov@epam.com
Subject: [PATCH 03/12] xen/arm: mm: Move out of xen_pt_update() the logic to update an entry
Date: Wed, 24 Apr 2019 17:59:46 +0100	[thread overview]
Message-ID: <20190424165955.23718-4-julien.grall@arm.com> (raw)
In-Reply-To: <20190424165955.23718-1-julien.grall@arm.com>

In preparation of rework of the Xen PT, the logic to update an entry
in moved out in a separate function.

Signed-off-by: Julien Grall <julien.grall@arm.com>
---
 xen/arch/arm/mm.c | 140 +++++++++++++++++++++++++++++-------------------------
 1 file changed, 74 insertions(+), 66 deletions(-)

diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c
index df2ec3a36b..6b1d41cfba 100644
--- a/xen/arch/arm/mm.c
+++ b/xen/arch/arm/mm.c
@@ -963,6 +963,76 @@ enum xenmap_operation {
     RESERVE
 };
 
+static int xen_pt_update_entry(enum xenmap_operation op, unsigned long addr,
+                               mfn_t mfn, unsigned int flags)
+{
+    lpae_t pte, *entry;
+    lpae_t *third = NULL;
+
+    entry = &xen_second[second_linear_offset(addr)];
+    if ( !lpae_is_valid(*entry) || !lpae_is_table(*entry, 2) )
+    {
+        int rc = create_xen_table(entry);
+        if ( rc < 0 ) {
+            printk("%s: L2 failed\n", __func__);
+            return rc;
+        }
+    }
+
+    BUG_ON(!lpae_is_valid(*entry));
+
+    third = mfn_to_virt(lpae_get_mfn(*entry));
+    entry = &third[third_table_offset(addr)];
+
+    switch ( op ) {
+        case INSERT:
+        case RESERVE:
+            if ( lpae_is_valid(*entry) )
+            {
+                printk("%s: trying to replace an existing mapping addr=%lx mfn=%"PRI_mfn"\n",
+                       __func__, addr, mfn_x(mfn));
+                return -EINVAL;
+            }
+            if ( op == RESERVE )
+                break;
+            pte = mfn_to_xen_entry(mfn, PAGE_AI_MASK(flags));
+            pte.pt.ro = PAGE_RO_MASK(flags);
+            pte.pt.xn = PAGE_XN_MASK(flags);
+            BUG_ON(!pte.pt.ro && !pte.pt.xn);
+            pte.pt.table = 1;
+            write_pte(entry, pte);
+            break;
+        case MODIFY:
+        case REMOVE:
+            if ( !lpae_is_valid(*entry) )
+            {
+                printk("%s: trying to %s a non-existing mapping addr=%lx\n",
+                       __func__, op == REMOVE ? "remove" : "modify", addr);
+                return -EINVAL;
+            }
+            if ( op == REMOVE )
+                pte.bits = 0;
+            else
+            {
+                pte = *entry;
+                pte.pt.ro = PAGE_RO_MASK(flags);
+                pte.pt.xn = PAGE_XN_MASK(flags);
+                if ( !pte.pt.ro && !pte.pt.xn )
+                {
+                    printk("%s: Incorrect combination for addr=%lx\n",
+                           __func__, addr);
+                    return -EINVAL;
+                }
+            }
+            write_pte(entry, pte);
+            break;
+        default:
+            BUG();
+    }
+
+    return 0;
+}
+
 static DEFINE_SPINLOCK(xen_pt_lock);
 
 static int xen_pt_update(enum xenmap_operation op,
@@ -973,78 +1043,16 @@ static int xen_pt_update(enum xenmap_operation op,
 {
     int rc = 0;
     unsigned long addr = virt, addr_end = addr + nr_mfns * PAGE_SIZE;
-    lpae_t pte, *entry;
-    lpae_t *third = NULL;
 
     spin_lock(&xen_pt_lock);
 
     for(; addr < addr_end; addr += PAGE_SIZE, mfn = mfn_add(mfn, 1))
     {
-        entry = &xen_second[second_linear_offset(addr)];
-        if ( !lpae_is_valid(*entry) || !lpae_is_table(*entry, 2) )
-        {
-            rc = create_xen_table(entry);
-            if ( rc < 0 ) {
-                printk("%s: L2 failed\n", __func__);
-                goto out;
-            }
-        }
-
-        BUG_ON(!lpae_is_valid(*entry));
-
-        third = mfn_to_virt(lpae_get_mfn(*entry));
-        entry = &third[third_table_offset(addr)];
-
-        switch ( op ) {
-            case INSERT:
-            case RESERVE:
-                if ( lpae_is_valid(*entry) )
-                {
-                    printk("%s: trying to replace an existing mapping addr=%lx mfn=%"PRI_mfn"\n",
-                           __func__, addr, mfn_x(mfn));
-                    rc = -EINVAL;
-                    goto out;
-                }
-                if ( op == RESERVE )
-                    break;
-                pte = mfn_to_xen_entry(mfn, PAGE_AI_MASK(flags));
-                pte.pt.ro = PAGE_RO_MASK(flags);
-                pte.pt.xn = PAGE_XN_MASK(flags);
-                BUG_ON(!pte.pt.ro && !pte.pt.xn);
-                pte.pt.table = 1;
-                write_pte(entry, pte);
-                break;
-            case MODIFY:
-            case REMOVE:
-                if ( !lpae_is_valid(*entry) )
-                {
-                    printk("%s: trying to %s a non-existing mapping addr=%lx\n",
-                           __func__, op == REMOVE ? "remove" : "modify", addr);
-                    rc = -EINVAL;
-                    goto out;
-                }
-                if ( op == REMOVE )
-                    pte.bits = 0;
-                else
-                {
-                    pte = *entry;
-                    pte.pt.ro = PAGE_RO_MASK(flags);
-                    pte.pt.xn = PAGE_XN_MASK(flags);
-                    if ( !pte.pt.ro && !pte.pt.xn )
-                    {
-                        printk("%s: Incorrect combination for addr=%lx\n",
-                               __func__, addr);
-                        rc = -EINVAL;
-                        goto out;
-                    }
-                }
-                write_pte(entry, pte);
-                break;
-            default:
-                BUG();
-        }
+        rc = xen_pt_update_entry(op, addr, mfn, flags);
+        if ( rc )
+            break;
     }
-out:
+
     /*
      * Flush the TLBs even in case of failure because we may have
      * partially modified the PT. This will prevent any unexpected
-- 
2.11.0


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

WARNING: multiple messages have this Message-ID (diff)
From: Julien Grall <julien.grall@arm.com>
To: xen-devel@lists.xenproject.org
Cc: Oleksandr_Tyshchenko@epam.com,
	Julien Grall <julien.grall@arm.com>,
	sstabellini@kernel.org, Andrii_Anisov@epam.com
Subject: [Xen-devel] [PATCH 03/12] xen/arm: mm: Move out of xen_pt_update() the logic to update an entry
Date: Wed, 24 Apr 2019 17:59:46 +0100	[thread overview]
Message-ID: <20190424165955.23718-4-julien.grall@arm.com> (raw)
Message-ID: <20190424165946.0w8wqEk4dyX1_QfsWSIa5ux-xH_16eR1VsFoxzRHlBw@z> (raw)
In-Reply-To: <20190424165955.23718-1-julien.grall@arm.com>

In preparation of rework of the Xen PT, the logic to update an entry
in moved out in a separate function.

Signed-off-by: Julien Grall <julien.grall@arm.com>
---
 xen/arch/arm/mm.c | 140 +++++++++++++++++++++++++++++-------------------------
 1 file changed, 74 insertions(+), 66 deletions(-)

diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c
index df2ec3a36b..6b1d41cfba 100644
--- a/xen/arch/arm/mm.c
+++ b/xen/arch/arm/mm.c
@@ -963,6 +963,76 @@ enum xenmap_operation {
     RESERVE
 };
 
+static int xen_pt_update_entry(enum xenmap_operation op, unsigned long addr,
+                               mfn_t mfn, unsigned int flags)
+{
+    lpae_t pte, *entry;
+    lpae_t *third = NULL;
+
+    entry = &xen_second[second_linear_offset(addr)];
+    if ( !lpae_is_valid(*entry) || !lpae_is_table(*entry, 2) )
+    {
+        int rc = create_xen_table(entry);
+        if ( rc < 0 ) {
+            printk("%s: L2 failed\n", __func__);
+            return rc;
+        }
+    }
+
+    BUG_ON(!lpae_is_valid(*entry));
+
+    third = mfn_to_virt(lpae_get_mfn(*entry));
+    entry = &third[third_table_offset(addr)];
+
+    switch ( op ) {
+        case INSERT:
+        case RESERVE:
+            if ( lpae_is_valid(*entry) )
+            {
+                printk("%s: trying to replace an existing mapping addr=%lx mfn=%"PRI_mfn"\n",
+                       __func__, addr, mfn_x(mfn));
+                return -EINVAL;
+            }
+            if ( op == RESERVE )
+                break;
+            pte = mfn_to_xen_entry(mfn, PAGE_AI_MASK(flags));
+            pte.pt.ro = PAGE_RO_MASK(flags);
+            pte.pt.xn = PAGE_XN_MASK(flags);
+            BUG_ON(!pte.pt.ro && !pte.pt.xn);
+            pte.pt.table = 1;
+            write_pte(entry, pte);
+            break;
+        case MODIFY:
+        case REMOVE:
+            if ( !lpae_is_valid(*entry) )
+            {
+                printk("%s: trying to %s a non-existing mapping addr=%lx\n",
+                       __func__, op == REMOVE ? "remove" : "modify", addr);
+                return -EINVAL;
+            }
+            if ( op == REMOVE )
+                pte.bits = 0;
+            else
+            {
+                pte = *entry;
+                pte.pt.ro = PAGE_RO_MASK(flags);
+                pte.pt.xn = PAGE_XN_MASK(flags);
+                if ( !pte.pt.ro && !pte.pt.xn )
+                {
+                    printk("%s: Incorrect combination for addr=%lx\n",
+                           __func__, addr);
+                    return -EINVAL;
+                }
+            }
+            write_pte(entry, pte);
+            break;
+        default:
+            BUG();
+    }
+
+    return 0;
+}
+
 static DEFINE_SPINLOCK(xen_pt_lock);
 
 static int xen_pt_update(enum xenmap_operation op,
@@ -973,78 +1043,16 @@ static int xen_pt_update(enum xenmap_operation op,
 {
     int rc = 0;
     unsigned long addr = virt, addr_end = addr + nr_mfns * PAGE_SIZE;
-    lpae_t pte, *entry;
-    lpae_t *third = NULL;
 
     spin_lock(&xen_pt_lock);
 
     for(; addr < addr_end; addr += PAGE_SIZE, mfn = mfn_add(mfn, 1))
     {
-        entry = &xen_second[second_linear_offset(addr)];
-        if ( !lpae_is_valid(*entry) || !lpae_is_table(*entry, 2) )
-        {
-            rc = create_xen_table(entry);
-            if ( rc < 0 ) {
-                printk("%s: L2 failed\n", __func__);
-                goto out;
-            }
-        }
-
-        BUG_ON(!lpae_is_valid(*entry));
-
-        third = mfn_to_virt(lpae_get_mfn(*entry));
-        entry = &third[third_table_offset(addr)];
-
-        switch ( op ) {
-            case INSERT:
-            case RESERVE:
-                if ( lpae_is_valid(*entry) )
-                {
-                    printk("%s: trying to replace an existing mapping addr=%lx mfn=%"PRI_mfn"\n",
-                           __func__, addr, mfn_x(mfn));
-                    rc = -EINVAL;
-                    goto out;
-                }
-                if ( op == RESERVE )
-                    break;
-                pte = mfn_to_xen_entry(mfn, PAGE_AI_MASK(flags));
-                pte.pt.ro = PAGE_RO_MASK(flags);
-                pte.pt.xn = PAGE_XN_MASK(flags);
-                BUG_ON(!pte.pt.ro && !pte.pt.xn);
-                pte.pt.table = 1;
-                write_pte(entry, pte);
-                break;
-            case MODIFY:
-            case REMOVE:
-                if ( !lpae_is_valid(*entry) )
-                {
-                    printk("%s: trying to %s a non-existing mapping addr=%lx\n",
-                           __func__, op == REMOVE ? "remove" : "modify", addr);
-                    rc = -EINVAL;
-                    goto out;
-                }
-                if ( op == REMOVE )
-                    pte.bits = 0;
-                else
-                {
-                    pte = *entry;
-                    pte.pt.ro = PAGE_RO_MASK(flags);
-                    pte.pt.xn = PAGE_XN_MASK(flags);
-                    if ( !pte.pt.ro && !pte.pt.xn )
-                    {
-                        printk("%s: Incorrect combination for addr=%lx\n",
-                               __func__, addr);
-                        rc = -EINVAL;
-                        goto out;
-                    }
-                }
-                write_pte(entry, pte);
-                break;
-            default:
-                BUG();
-        }
+        rc = xen_pt_update_entry(op, addr, mfn, flags);
+        if ( rc )
+            break;
     }
-out:
+
     /*
      * Flush the TLBs even in case of failure because we may have
      * partially modified the PT. This will prevent any unexpected
-- 
2.11.0


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

  parent reply	other threads:[~2019-04-24 17:00 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-24 16:59 [PATCH 00/12] xen/arm: Provide a generic function to update Xen PT Julien Grall
2019-04-24 16:59 ` [Xen-devel] " Julien Grall
2019-04-24 16:59 ` [PATCH 01/12] xen/arm: lpae: Add a macro to generate offsets from an address Julien Grall
2019-04-24 16:59   ` [Xen-devel] " Julien Grall
2019-05-06 12:47   ` Andrii Anisov
2019-05-06 12:47     ` [Xen-devel] " Andrii Anisov
2019-04-24 16:59 ` [PATCH 02/12] xen/arm: mm: Rename create_xen_entries() to xen_pt_update() Julien Grall
2019-04-24 16:59   ` [Xen-devel] " Julien Grall
2019-05-06 12:48   ` Andrii Anisov
2019-05-06 12:48     ` [Xen-devel] " Andrii Anisov
2019-04-24 16:59 ` Julien Grall [this message]
2019-04-24 16:59   ` [Xen-devel] [PATCH 03/12] xen/arm: mm: Move out of xen_pt_update() the logic to update an entry Julien Grall
2019-05-06 12:48   ` Andrii Anisov
2019-05-06 12:48     ` [Xen-devel] " Andrii Anisov
2019-04-24 16:59 ` [PATCH 04/12] xen/arm: mm: Introduce _PAGE_PRESENT and _PAGE_POPULATE Julien Grall
2019-04-24 16:59   ` [Xen-devel] " Julien Grall
2019-05-06 12:48   ` Andrii Anisov
2019-05-06 12:48     ` [Xen-devel] " Andrii Anisov
2019-04-24 16:59 ` [PATCH 05/12] xen/arm: mm: Only increment mfn when valid in xen_pt_update Julien Grall
2019-04-24 16:59   ` [Xen-devel] " Julien Grall
2019-05-06 12:48   ` Andrii Anisov
2019-05-06 12:48     ` [Xen-devel] " Andrii Anisov
2019-04-24 16:59 ` [PATCH 06/12] xen/arm: mm: Sanity check any update of Xen page tables Julien Grall
2019-04-24 16:59   ` [Xen-devel] " Julien Grall
2019-05-06 12:48   ` Andrii Anisov
2019-05-06 12:48     ` [Xen-devel] " Andrii Anisov
2019-05-06 17:01     ` Julien Grall
2019-05-06 17:01       ` [Xen-devel] " Julien Grall
2019-05-07  7:38       ` Andrii Anisov
2019-05-07  7:38         ` [Xen-devel] " Andrii Anisov
2019-04-24 16:59 ` [PATCH 07/12] xen/arm: mm: Rework xen_pt_update_entry to avoid use xenmap_operation Julien Grall
2019-04-24 16:59   ` [Xen-devel] " Julien Grall
2019-05-06 12:48   ` Andrii Anisov
2019-05-06 12:48     ` [Xen-devel] " Andrii Anisov
2019-04-24 16:59 ` [PATCH 08/12] xen/arm: mm: Remove enum xenmap_operation Julien Grall
2019-04-24 16:59   ` [Xen-devel] " Julien Grall
2019-05-06 12:48   ` Andrii Anisov
2019-05-06 12:48     ` [Xen-devel] " Andrii Anisov
2019-04-24 16:59 ` [PATCH 09/12] xen/arm: mm: Use {, un}map_domain_page() to map/unmap Xen page-tables Julien Grall
2019-04-24 16:59   ` [Xen-devel] " Julien Grall
2019-05-06 12:48   ` Andrii Anisov
2019-05-06 12:48     ` [Xen-devel] " Andrii Anisov
2019-04-24 16:59 ` [PATCH 10/12] xen/arm: mm: Rework Xen page-tables walk during update Julien Grall
2019-04-24 16:59   ` [Xen-devel] " Julien Grall
2019-05-06 12:49   ` Andrii Anisov
2019-05-06 12:49     ` [Xen-devel] " Andrii Anisov
2019-04-24 16:59 ` [PATCH 11/12] xen/arm: mm: Don't open-code Xen PT update in {set, clear}_fixmap() Julien Grall
2019-04-24 16:59   ` [Xen-devel] " Julien Grall
2019-05-06 12:49   ` Andrii Anisov
2019-05-06 12:49     ` [Xen-devel] " Andrii Anisov
2019-04-24 16:59 ` [PATCH 12/12] xen/arm: mm: Remove set_pte_flags_on_range() Julien Grall
2019-04-24 16:59   ` [Xen-devel] " Julien Grall
2019-05-06 12:49   ` Andrii Anisov
2019-05-06 12:49     ` [Xen-devel] " Andrii Anisov

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=20190424165955.23718-4-julien.grall@arm.com \
    --to=julien.grall@arm.com \
    --cc=Andrii_Anisov@epam.com \
    --cc=Oleksandr_Tyshchenko@epam.com \
    --cc=sstabellini@kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.