All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Tamas K Lengyel <tamas.lengyel@zentific.com>, xen-devel@lists.xen.org
Cc: kevin.tian@intel.com, wei.liu2@citrix.com,
	ian.campbell@citrix.com, stefano.stabellini@eu.citrix.com,
	tim@xen.org, steve@zentific.com, jbeulich@suse.com,
	eddie.dong@intel.com, andres@lagarcavilla.org,
	jun.nakajima@intel.com, rshriram@cs.ubc.ca, keir@xen.org,
	dgdegra@tycho.nsa.gov, yanghy@cn.fujitsu.com,
	ian.jackson@eu.citrix.com
Subject: Re: [PATCH V5 10/12] xen/vm_event: Relocate memop checks
Date: Fri, 13 Feb 2015 21:23:56 +0000	[thread overview]
Message-ID: <54DE6B6C.70401@citrix.com> (raw)
In-Reply-To: <1423845203-18941-11-git-send-email-tamas.lengyel@zentific.com>

On 13/02/15 16:33, Tamas K Lengyel wrote:
> The memop handler function for paging/sharing responsible for calling XSM
> doesn't really have anything to do with vm_event, thus in this patch we
> relocate it into mem_paging_memop and mem_sharing_memop. This has already
> been the approach in mem_access_memop, so in this patch we just make it
> consistent.
>
> Signed-off-by: Tamas K Lengyel <tamas.lengyel@zentific.com>
> ---
>  xen/arch/x86/mm/mem_paging.c      | 36 ++++++++++++++-----
>  xen/arch/x86/mm/mem_sharing.c     | 76 ++++++++++++++++++++++++++-------------
>  xen/arch/x86/x86_64/compat/mm.c   | 28 +++------------
>  xen/arch/x86/x86_64/mm.c          | 26 +++-----------
>  xen/common/vm_event.c             | 43 ----------------------
>  xen/include/asm-x86/mem_paging.h  |  7 +++-
>  xen/include/asm-x86/mem_sharing.h |  4 +--
>  xen/include/xen/vm_event.h        |  1 -
>  8 files changed, 97 insertions(+), 124 deletions(-)
>
> diff --git a/xen/arch/x86/mm/mem_paging.c b/xen/arch/x86/mm/mem_paging.c
> index e63d8c1..4aee6b7 100644
> --- a/xen/arch/x86/mm/mem_paging.c
> +++ b/xen/arch/x86/mm/mem_paging.c
> @@ -21,28 +21,45 @@
>   */
>  
>  
> +#include <xen/guest_access.h>
>  #include <asm/p2m.h>
> -#include <xen/vm_event.h>
> +#include <xsm/xsm.h>

Order of includes.

>  
> -
> -int mem_paging_memop(struct domain *d, xen_mem_paging_op_t *mpo)
> +int mem_paging_memop(unsigned long cmd,

I don't believe cmd is a useful parameter to pass.  You know that its
value is XENMEM_paging_op by virtue of being in this function.

> +                     XEN_GUEST_HANDLE_PARAM(xen_mem_paging_op_t) arg)
>  {
> -    int rc = -ENODEV;
> +    int rc;
> +    xen_mem_paging_op_t mpo;
> +    struct domain *d;
> +
> +    rc = -EFAULT;
> +    if ( copy_from_guest(&mpo, arg, 1) )
> +        return rc;
> +
> +    rc = rcu_lock_live_remote_domain_by_id(mpo.domain, &d);
> +    if ( rc )
> +        return rc;
> +
> +    rc = xsm_vm_event_op(XSM_DM_PRIV, d, XENMEM_paging_op);
> +    if ( rc )
> +        return rc;
> +
> +    rc = -ENODEV;
>      if ( unlikely(!d->vm_event->paging.ring_page) )
>          return rc;
>  
> -    switch( mpo->op )
> +    switch( mpo.op )
>      {
>      case XENMEM_paging_op_nominate:
> -        rc = p2m_mem_paging_nominate(d, mpo->gfn);
> +        rc = p2m_mem_paging_nominate(d, mpo.gfn);
>          break;
>  
>      case XENMEM_paging_op_evict:
> -        rc = p2m_mem_paging_evict(d, mpo->gfn);
> +        rc = p2m_mem_paging_evict(d, mpo.gfn);
>          break;
>  
>      case XENMEM_paging_op_prep:
> -        rc = p2m_mem_paging_prep(d, mpo->gfn, mpo->buffer);
> +        rc = p2m_mem_paging_prep(d, mpo.gfn, mpo.buffer);
>          break;
>  
>      default:
> @@ -50,6 +67,9 @@ int mem_paging_memop(struct domain *d, xen_mem_paging_op_t *mpo)
>          break;
>      }
>  
> +    if ( !rc && __copy_to_guest(arg, &mpo, 1) )
> +        rc = -EFAULT;

Do any of the paging ops need to be copied back?  Nothing appears to
write into mpo in this function.  (The original code looks to be overly
pessimistic).

> +
>      return rc;
>  }
>  
> diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c
> index 4959407..612ed89 100644
> --- a/xen/arch/x86/mm/mem_sharing.c
> +++ b/xen/arch/x86/mm/mem_sharing.c
> @@ -28,6 +28,7 @@
>  #include <xen/grant_table.h>
>  #include <xen/sched.h>
>  #include <xen/rcupdate.h>
> +#include <xen/guest_access.h>
>  #include <xen/vm_event.h>
>  #include <asm/page.h>
>  #include <asm/string.h>
> @@ -1293,30 +1294,52 @@ int relinquish_shared_pages(struct domain *d)
>      return rc;
>  }
>  
> -int mem_sharing_memop(struct domain *d, xen_mem_sharing_op_t *mec)
> +int mem_sharing_memop(unsigned long cmd,
> +                      XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg)
>  {
> -    int rc = 0;
> +    int rc;
> +    xen_mem_sharing_op_t mso;
> +    struct domain *d;
> +
> +    rc = -EFAULT;
> +    if ( copy_from_guest(&mso, arg, 1) )
> +        return rc;
> +
> +    if ( mso.op == XENMEM_sharing_op_audit )
> +        return mem_sharing_audit();
> +
> +    rc = rcu_lock_live_remote_domain_by_id(mso.domain, &d);
> +    if ( rc )
> +        return rc;
>  
>      /* Only HAP is supported */
>      if ( !hap_enabled(d) || !d->arch.hvm_domain.mem_sharing_enabled )
>           return -ENODEV;
>  
> -    switch(mec->op)
> +    rc = xsm_vm_event_op(XSM_DM_PRIV, d, XENMEM_sharing_op);
> +    if ( rc )
> +        return rc;
> +
> +    rc = -ENODEV;
> +    if ( unlikely(!d->vm_event->share.ring_page) )
> +        return rc;
> +
> +    switch(mso.op)

Style ( spaces )

> @@ -1465,6 +1488,9 @@ int mem_sharing_memop(struct domain *d, xen_mem_sharing_op_t *mec)
>              break;
>      }
>  
> +    if ( !rc && __copy_to_guest(arg, &mso, 1) )
> +        return -EFAULT;

Only certain subops need to copy information back.  It is common to have
a function-level bool_t copyback which relevant subops sets.

~Andrew

> +
>      return rc;
>  }

  reply	other threads:[~2015-02-13 21:23 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-13 16:33 [PATCH V5 00/12] xen: Clean-up of mem_event subsystem Tamas K Lengyel
2015-02-13 16:33 ` [PATCH V5 01/12] xen/mem_event: Cleanup of mem_event structures Tamas K Lengyel
2015-02-13 17:23   ` Andrew Cooper
2015-02-13 18:03     ` Tamas K Lengyel
2015-02-13 18:09       ` Andrew Cooper
2015-02-13 18:13         ` Tamas K Lengyel
2015-02-17 11:48         ` Jan Beulich
2015-02-13 16:33 ` [PATCH V5 02/12] xen/mem_event: Cleanup mem_event ring names and domctls Tamas K Lengyel
2015-02-13 17:53   ` Andrew Cooper
2015-02-13 18:06     ` Tamas K Lengyel
2015-02-13 16:33 ` [PATCH V5 03/12] xen/mem_paging: Convert mem_event_op to mem_paging_op Tamas K Lengyel
2015-02-13 18:17   ` Andrew Cooper
2015-02-13 18:30     ` Tamas K Lengyel
2015-02-13 16:33 ` [PATCH V5 04/12] xen: Rename mem_event to vm_event Tamas K Lengyel
2015-02-13 18:31   ` Andrew Cooper
2015-02-13 16:33 ` [PATCH V5 05/12] tools/tests: Clean-up tools/tests/xen-access Tamas K Lengyel
2015-02-13 16:33 ` [PATCH V5 06/12] x86/hvm: factor out and rename vm_event related functions Tamas K Lengyel
2015-02-13 18:41   ` Andrew Cooper
2015-02-17 11:56   ` Jan Beulich
2015-02-17 17:37     ` Tamas K Lengyel
2015-02-18  9:07       ` Jan Beulich
2015-02-18 12:09         ` Tamas K Lengyel
2015-02-13 16:33 ` [PATCH V5 07/12] xen: Introduce monitor_op domctl Tamas K Lengyel
2015-02-13 20:09   ` Andrew Cooper
2015-02-17 14:02   ` Jan Beulich
2015-02-17 18:20     ` Tamas K Lengyel
2015-02-17 18:37       ` Andrew Cooper
2015-02-17 18:48         ` Tamas K Lengyel
2015-02-17 22:59       ` Tamas K Lengyel
2015-02-18  9:26       ` Jan Beulich
2015-02-18 12:11         ` Tamas K Lengyel
2015-02-13 16:33 ` [PATCH V5 08/12] xen/vm_event: Check for VM_EVENT_FLAG_DUMMY only in Debug builds Tamas K Lengyel
2015-02-13 20:14   ` Andrew Cooper
2015-02-13 22:48     ` Tamas K Lengyel
2015-02-13 22:53       ` Tamas K Lengyel
2015-02-13 23:00         ` Andrew Cooper
2015-02-13 23:02           ` Tamas K Lengyel
2015-02-13 16:33 ` [PATCH V5 09/12] xen/vm_event: Decouple vm_event and mem_access Tamas K Lengyel
2015-02-13 21:05   ` Andrew Cooper
2015-02-13 23:00     ` Tamas K Lengyel
2015-02-17 14:17   ` Jan Beulich
2015-02-17 18:30     ` Tamas K Lengyel
2015-02-17 18:34       ` Andrew Cooper
2015-02-17 18:49         ` Tamas K Lengyel
2015-02-13 16:33 ` [PATCH V5 10/12] xen/vm_event: Relocate memop checks Tamas K Lengyel
2015-02-13 21:23   ` Andrew Cooper [this message]
2015-02-13 23:20     ` Tamas K Lengyel
2015-02-13 23:24       ` Tamas K Lengyel
2015-02-17 14:25   ` Jan Beulich
2015-02-17 18:47     ` Tamas K Lengyel
2015-02-18  9:29       ` Jan Beulich
2015-02-18 12:13         ` Tamas K Lengyel
2015-02-13 16:33 ` [PATCH V5 11/12] xen/xsm: Split vm_event_op into three separate labels Tamas K Lengyel
2015-02-13 21:25   ` Andrew Cooper
2015-02-13 16:33 ` [PATCH V5 12/12] xen/vm_event: Add RESUME option to vm_event_op domctl Tamas K Lengyel
2015-02-13 21:44   ` Andrew Cooper
2015-02-13 23:10     ` Tamas K Lengyel
2015-02-17 14:31   ` Jan Beulich
2015-02-17 18:32     ` Tamas K Lengyel
2015-02-18  9:31       ` Jan Beulich
2015-02-18 12:18         ` Tamas K Lengyel

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=54DE6B6C.70401@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=andres@lagarcavilla.org \
    --cc=dgdegra@tycho.nsa.gov \
    --cc=eddie.dong@intel.com \
    --cc=ian.campbell@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=jun.nakajima@intel.com \
    --cc=keir@xen.org \
    --cc=kevin.tian@intel.com \
    --cc=rshriram@cs.ubc.ca \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=steve@zentific.com \
    --cc=tamas.lengyel@zentific.com \
    --cc=tim@xen.org \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    --cc=yanghy@cn.fujitsu.com \
    /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.