1 /******************************************************************************
2  * arch/x86/mm/mem_paging.c
3  *
4  * Memory paging support.
5  *
6  * Copyright (c) 2009 Citrix Systems, Inc. (Patrick Colp)
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 
23 #include <asm/p2m.h>
24 #include <xen/guest_access.h>
25 #include <xen/vm_event.h>
26 #include <xsm/xsm.h>
27 
mem_paging_memop(XEN_GUEST_HANDLE_PARAM (xen_mem_paging_op_t)arg)28 int mem_paging_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_paging_op_t) arg)
29 {
30     int rc;
31     xen_mem_paging_op_t mpo;
32     struct domain *d;
33     bool_t copyback = 0;
34 
35     if ( copy_from_guest(&mpo, arg, 1) )
36         return -EFAULT;
37 
38     rc = rcu_lock_live_remote_domain_by_id(mpo.domain, &d);
39     if ( rc )
40         return rc;
41 
42     rc = xsm_mem_paging(XSM_DM_PRIV, d);
43     if ( rc )
44         goto out;
45 
46     rc = -ENODEV;
47     if ( unlikely(!vm_event_check_ring(d->vm_event_paging)) )
48         goto out;
49 
50     switch( mpo.op )
51     {
52     case XENMEM_paging_op_nominate:
53         rc = p2m_mem_paging_nominate(d, mpo.gfn);
54         break;
55 
56     case XENMEM_paging_op_evict:
57         rc = p2m_mem_paging_evict(d, mpo.gfn);
58         break;
59 
60     case XENMEM_paging_op_prep:
61         rc = p2m_mem_paging_prep(d, mpo.gfn, mpo.buffer);
62         if ( !rc )
63             copyback = 1;
64         break;
65 
66     default:
67         rc = -ENOSYS;
68         break;
69     }
70 
71     if ( copyback && __copy_to_guest(arg, &mpo, 1) )
72         rc = -EFAULT;
73 
74 out:
75     rcu_unlock_domain(d);
76     return rc;
77 }
78 
79 
80 /*
81  * Local variables:
82  * mode: C
83  * c-file-style: "BSD"
84  * c-basic-offset: 4
85  * indent-tabs-mode: nil
86  * End:
87  */
88