From: Boris Derzhavets Subject: Re: [PATCH] privcmd: MMAPBATCH: Fix error handling/reporting Date: Wed, 20 May 2009 12:22:02 -0700 (PDT) Message-ID: <786988.36456.qm@web56101.mail.re3.yahoo.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0605433035==" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com Cc: Jeremy Fitzhardinge , Ian Campbell List-Id: xen-devel@lists.xenproject.org --===============0605433035== Content-Type: multipart/alternative; boundary="0-1084724026-1242847322=:36456" --0-1084724026-1242847322=:36456 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable How long it takes for your patches to get in=20 git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.git ? Boris. --- On Wed, 5/20/09, Ian Campbell wrote: From: Ian Campbell Subject: [Xen-devel] [PATCH] privcmd: MMAPBATCH: Fix error handling/reporti= ng To: xen-devel@lists.xensource.com Cc: "Jeremy Fitzhardinge" , "Ian Campbell" Date: Wednesday, May 20, 2009, 10:45 AM On error IOCTL_PRIVCMD_MMAPBATCH is expected to set the top nibble of the effected MFN and return 0. Currently it leaves the MFN unmodified and returns the number of failures. Therefore: - reimplement remap_domain_mfn_range() using direct =A0 HYPERVISOR_mmu_update() calls and small batches. The xen_set_domain_pte= () =A0 interface does not report errors and since some failures are =A0 expected/normal using the multicall infrastructure is too noisy. - return 0 as expected - writeback the updated MFN list to mmapbatch->arr not over mmapbatch, =A0 smashing the caller's stack. - remap_domain_mfn_range can be static. With this change I am able to start an HVM domain. Signed-off-by: Ian Campbell Cc: Jeremy Fitzhardinge --- drivers/xen/xenfs/privcmd.c |=A0=A0=A056 +++++++++++++++++++++++++++++++--= --------- 1 files changed, 41 insertions(+), 15 deletions(-) diff --git a/drivers/xen/xenfs/privcmd.c b/drivers/xen/xenfs/privcmd.c index 263f622..110b062 100644 --- a/drivers/xen/xenfs/privcmd.c +++ b/drivers/xen/xenfs/privcmd.c @@ -31,14 +31,16 @@ #include #include =20 +#define REMAP_BATCH_SIZE 16 + #ifndef HAVE_ARCH_PRIVCMD_MMAP static int privcmd_enforce_singleshot_mapping(struct vm_area_struct *vma); #endif =20 struct remap_data { =A0=A0=A0 unsigned long mfn; -=A0=A0=A0 unsigned domid; =A0=A0=A0 pgprot_t prot; +=A0=A0=A0 struct mmu_update *mmu_update; }; =20 static int remap_area_mfn_pte_fn(pte_t *ptep, pgtable_t token, @@ -47,17 +49,23 @@ static int remap_area_mfn_pte_fn(pte_t *ptep, pgtable_t= token, =A0=A0=A0 struct remap_data *rmd =3D data; =A0=A0=A0 pte_t pte =3D pte_mkspecial(pfn_pte(rmd->mfn++, rmd->prot)); =20 -=A0=A0=A0 xen_set_domain_pte(ptep, pte, rmd->domid); +=A0=A0=A0 rmd->mmu_update->ptr =3D arbitrary_virt_to_machine(ptep).maddr; +=A0=A0=A0 rmd->mmu_update->val =3D pte_val_ma(pte); +=A0=A0=A0 rmd->mmu_update++; =20 =A0=A0=A0 return 0; } =20 -int remap_domain_mfn_range(struct vm_area_struct *vma, unsigned long addr, -=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0unsigned long mfn, unsigned long si= ze, -=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0pgprot_t prot, unsigned domid) +static int remap_domain_mfn_range(struct vm_area_struct *vma, +=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0 unsigned long addr, +=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0 unsigned long mfn, int nr, +=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0 pgprot_t prot, unsigned domid) { =A0=A0=A0 struct remap_data rmd; -=A0=A0=A0 int err; +=A0=A0=A0 struct mmu_update mmu_update[REMAP_BATCH_SIZE]; +=A0=A0=A0 int batch; +=A0=A0=A0 unsigned long range; +=A0=A0=A0 int err =3D 0; =20 =A0=A0=A0 prot =3D __pgprot(pgprot_val(prot) | _PAGE_IOMAP); =20 @@ -65,10 +73,29 @@ int remap_domain_mfn_range(struct vm_area_struct *vma, = unsigned long addr, =20 =A0=A0=A0 rmd.mfn =3D mfn; =A0=A0=A0 rmd.prot =3D prot; -=A0=A0=A0 rmd.domid =3D domid; =20 -=A0=A0=A0 err =3D apply_to_page_range(vma->vm_mm, addr, size, -=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0 remap_area_mfn_pte_fn, &rmd); +=A0=A0=A0 while (nr) { +=A0=A0=A0 =A0=A0=A0 batch =3D min(REMAP_BATCH_SIZE, nr); +=A0=A0=A0 =A0=A0=A0 range =3D (unsigned long)batch << PAGE_SHIFT; + +=A0=A0=A0 =A0=A0=A0 rmd.mmu_update =3D mmu_update; +=A0=A0=A0 =A0=A0=A0 err =3D apply_to_page_range(vma->vm_mm, addr, range, +=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0 remap_area_mfn_pte_f= n, &rmd); +=A0=A0=A0 =A0=A0=A0 if (err) +=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 goto out; + +=A0=A0=A0 =A0=A0=A0 err =3D -EFAULT; +=A0=A0=A0 =A0=A0=A0 if (HYPERVISOR_mmu_update(mmu_update, batch, NULL, dom= id) < 0) +=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 goto out; + +=A0=A0=A0 =A0=A0=A0 nr -=3D batch; +=A0=A0=A0 =A0=A0=A0 addr +=3D range; +=A0=A0=A0 } + +=A0=A0=A0 err =3D 0; +out: + +=A0=A0=A0 flush_tlb_all(); =20 =A0=A0=A0 return err; } @@ -157,7 +184,7 @@ static int traverse_pages(unsigned nelem, size_t size, { =A0=A0=A0 void *pagedata; =A0=A0=A0 unsigned pageidx; -=A0=A0=A0 int ret; +=A0=A0=A0 int ret =3D 0; =20 =A0=A0=A0 BUG_ON(size > PAGE_SIZE); =20 @@ -207,8 +234,7 @@ static int mmap_mfn_range(void *data, void *state) =20 =A0=A0=A0 rc =3D remap_domain_mfn_range(vma, =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0 =A0 msg->va & PAGE_MASK, -=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0 =A0 msg->mfn, -=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0 =A0 msg->npages << PAGE_SHIFT, +=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0 =A0 msg->mfn, msg->npages, =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0 =A0 vma->vm_page_prot, =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0 =A0 st->domain); =A0=A0=A0 if (rc < 0) @@ -289,7 +315,7 @@ static int mmap_batch_fn(void *data, void *state) =A0=A0=A0 struct mmap_batch_state *st =3D state; =20 =A0=A0=A0 if (remap_domain_mfn_range(st->vma, st->va & PAGE_MASK, -=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0*mfnp, PAGE_SIZE, +=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0*mfnp, 1, =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0st->vma->vm_page_prot, st= ->domain) < 0) { =A0=A0=A0 =A0=A0=A0 *mfnp |=3D 0xf0000000U; =A0=A0=A0 =A0=A0=A0 st->err++; @@ -361,9 +387,9 @@ static long privcmd_ioctl_mmap_batch(void __user *udata= ) =A0=A0=A0 up_write(&mm->mmap_sem); =20 =A0=A0=A0 if (state.err > 0) { -=A0=A0=A0 =A0=A0=A0 ret =3D state.err; +=A0=A0=A0 =A0=A0=A0 ret =3D 0; =20 -=A0=A0=A0 =A0=A0=A0 state.user =3D udata; +=A0=A0=A0 =A0=A0=A0 state.user =3D m.arr; =A0=A0=A0 =A0=A0=A0 traverse_pages(m.num, sizeof(xen_pfn_t), =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0 =A0 =A0=A0=A0&pagelist, =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0 =A0 =A0=A0=A0mmap_return_errors, &state)= ; --=20 1.5.6.5 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel =0A=0A=0A --0-1084724026-1242847322=:36456 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable
How long it takes for your patches to get in =
git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.git ?
=
Boris.

--- On Wed, 5/20/09, Ian Campbell <ian.cam= pbell@citrix.com> wrote:

From: I= an Campbell <ian.campbell@citrix.com>
Subject: [Xen-devel] [PATCH]= privcmd: MMAPBATCH: Fix error handling/reporting
To: xen-devel@lists.xe= nsource.com
Cc: "Jeremy Fitzhardinge" <jeremy@goop.org>, "Ian Camp= bell" <ian.campbell@citrix.com>
Date: Wednesday, May 20, 2009, 10:= 45 AM

On error IOCTL_PRIVCMD_MMAPBATCH is e= xpected to set the top nibble of
the effected MFN and return 0. Currentl= y it leaves the MFN unmodified
and returns the number of failures. Therefore:

- reimplement remap_domain_mfn_range() using direct
&= nbsp; HYPERVISOR_mmu_update() calls and small batches. The xen_set_domain_p= te()
  interface does not report errors and since some failures are=
  expected/normal using the multicall infrastructure is too noisy.=
- return 0 as expected
- writeback the updated MFN list to mmapbatch= ->arr not over mmapbatch,
  smashing the caller's stack.
- re= map_domain_mfn_range can be static.

With this change I am able to st= art an HVM domain.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Cc: Jeremy Fitzhardinge <jer= emy@goop.org>
---
drivers/xen/xenfs/privcmd.c |  &n= bsp;56 +++++++++++++++++++++++++++++++-----------
1 files changed, 41 insertions(+), 15 deletions(-)

diff --git a/drivers/xen/xenfs/privc= md.c b/drivers/xen/xenfs/privcmd.c
index 263f622..110b062 100644
--- = a/drivers/xen/xenfs/privcmd.c
+++ b/drivers/xen/xenfs/privcmd.c
@@ -3= 1,14 +31,16 @@
#include <xen/features.h>
#include <xen/pag= e.h>

+#define REMAP_BATCH_SIZE 16
+
#ifndef HAVE_ARCH_PRI= VCMD_MMAP
static int privcmd_enforce_singleshot_mapping(struct vm_area_= struct *vma);
#endif

struct remap_data {
   = ; unsigned long mfn;
-    unsigned domid;
  = ;  pgprot_t prot;
+    struct mmu_update *mmu_update= ;
};

static int remap_area_mfn_pte_fn(pte_t *ptep, pgtable_t t= oken,
@@ -47,17 +49,23 @@ static int remap_area_mfn_pte_fn(pte_t *ptep, = pgtable_t token,
    struct remap_data *rmd =3D data;     pte_t pte =3D pte_mkspecial(pfn_pte(rmd->mfn++, rmd->prot));

-    xen_set_domain_pte(ptep, pte, = rmd->domid);
+    rmd->mmu_update->ptr =3D arbit= rary_virt_to_machine(ptep).maddr;
+    rmd->mmu_update= ->val =3D pte_val_ma(pte);
+    rmd->mmu_update++;<= br>
    return 0;
}

-int remap_domain_mfn_r= ange(struct vm_area_struct *vma, unsigned long addr,
-   =            unsigned long mfn,= unsigned long size,
-          =      pgprot_t prot, unsigned domid)
+static int rema= p_domain_mfn_range(struct vm_area_struct *vma,
+     = ;             unsigned long ad= dr,
+             &nbs= p;    unsigned long mfn, int nr,
+                  pgprot_t p= rot, unsigned domid)
{
    struct remap_data rmd;-    int err;
+    struct mmu_update mmu_= update[REMAP_BATCH_SIZE];
+    int batch;
+  = ;  unsigned long range;
+    int err =3D 0;

=     prot =3D __pgprot(pgprot_val(prot) | _PAGE_IOMAP);
=
@@ -65,10 +73,29 @@ int remap_domain_mfn_range(struct vm_area_struct *v= ma, unsigned long addr,

    rmd.mfn =3D mfn;
&n= bsp;   rmd.prot =3D prot;
-    rmd.domid =3D do= mid;

-    err =3D apply_to_page_range(vma->vm_mm,= addr, size,
-            &= nbsp;     remap_area_mfn_pte_fn, &rmd);
+  =   while (nr) {
+        batch =3D min(REMAP_BATCH_SIZE, nr);
+        range= =3D (unsigned long)batch << PAGE_SHIFT;
+
+    =     rmd.mmu_update =3D mmu_update;
+    &n= bsp;   err =3D apply_to_page_range(vma->vm_mm, addr, range,+              &nbs= p;       remap_area_mfn_pte_fn, &rmd);
+ &n= bsp;      if (err)
+      &= nbsp;     goto out;
+
+      =   err =3D -EFAULT;
+        if (HYPER= VISOR_mmu_update(mmu_update, batch, NULL, domid) < 0)
+  &n= bsp;         goto out;
+
+  &= nbsp;     nr -=3D batch;
+      =   addr +=3D range;
+    }
+
+   = ; err =3D 0;
+out:
+
+    flush_tlb_all();

&nbs= p;   return err;
}
@@ -157,7 +184,7 @@ static int traverse= _pages(unsigned nelem, size_t size,
{
    void *page= data;
    unsigned pageidx;
-    int r= et;
+    int ret =3D 0;

    BUG_O= N(size > PAGE_SIZE);

@@ -207,8 +234,7 @@ static int mmap_mfn_ran= ge(void *data, void *state)

    rc =3D remap_domain= _mfn_range(vma,
           = ;         msg->va & PAGE_MASK,
- &n= bsp;                =   msg->mfn,
-          &= nbsp;         msg->npages << PAGE_SHIFT,<= br>+                    msg->mfn, msg->npages,
 &n= bsp;                =   vma->vm_page_prot,
        &nbs= p;           st->domain);
 &= nbsp;  if (rc < 0)
@@ -289,7 +315,7 @@ static int mmap_batch_fn(= void *data, void *state)
    struct mmap_batch_state *st= =3D state;

    if (remap_domain_mfn_range(st->v= ma, st->va & PAGE_MASK,
-        &n= bsp;          *mfnp, PAGE_SIZE,
= +               = ;    *mfnp, 1,
        &nb= sp;          st->vma->vm_page= _prot, st->domain) < 0) {
        *mfnp |=3D 0xf0000000U;
     &n= bsp;  st->err++;
@@ -361,9 +387,9 @@ static long privcmd_ioctl_m= map_batch(void __user *udata)
    up_write(&mm->m= map_sem);

    if (state.err > 0) {
- &nb= sp;      ret =3D state.err;
+    &nbs= p;   ret =3D 0;

-        st= ate.user =3D udata;
+        state.user = =3D m.arr;
        traverse_pages(m.num, = sizeof(xen_pfn_t),
          &n= bsp;        &pagelist,
    =                mmap_= return_errors, &state);
--
1.5.6.5


__________________= _____________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xe= nsource.com/xen-devel

=0A= =0A=0A=0A --0-1084724026-1242847322=:36456-- --===============0605433035== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --===============0605433035==--