1 /******************************************************************************
2  * mem_access.h
3  *
4  * Memory access support.
5  *
6  * Copyright (c) 2011 Virtuata, Inc.
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 #ifndef _XEN_MEM_ACCESS_H
23 #define _XEN_MEM_ACCESS_H
24 
25 #include <xen/types.h>
26 #include <xen/mm.h>
27 #include <public/memory.h>
28 #include <public/vm_event.h>
29 #include <asm/mem_access.h>
30 
31 /*
32  * Additional access types, which are used to further restrict
33  * the permissions given my the p2m_type_t memory type.  Violations
34  * caused by p2m_access_t restrictions are sent to the vm_event
35  * interface.
36  *
37  * The access permissions are soft state: when any ambiguous change of page
38  * type or use occurs, or when pages are flushed, swapped, or at any other
39  * convenient type, the access permissions can get reset to the p2m_domain
40  * default.
41  */
42 typedef enum {
43     /* Code uses bottom three bits with bitmask semantics */
44     p2m_access_n     = 0, /* No access allowed. */
45     p2m_access_r     = 1 << 0,
46     p2m_access_w     = 1 << 1,
47     p2m_access_x     = 1 << 2,
48     p2m_access_rw    = p2m_access_r | p2m_access_w,
49     p2m_access_rx    = p2m_access_r | p2m_access_x,
50     p2m_access_wx    = p2m_access_w | p2m_access_x,
51     p2m_access_rwx   = p2m_access_r | p2m_access_w | p2m_access_x,
52 
53     p2m_access_rx2rw = 8, /* Special: page goes from RX to RW on write */
54     p2m_access_n2rwx = 9, /* Special: page goes from N to RWX on access, *
55                            * generates an event but does not pause the
56                            * vcpu */
57 
58     /* NOTE: Assumed to be only 4 bits right now on x86. */
59 } p2m_access_t;
60 
61 /*
62  * Set access type for a region of gfns.
63  * If gfn == INVALID_GFN, sets the default access type.
64  */
65 long p2m_set_mem_access(struct domain *d, gfn_t gfn, uint32_t nr,
66                         uint32_t start, uint32_t mask, xenmem_access_t access,
67                         unsigned int altp2m_idx);
68 
69 long p2m_set_mem_access_multi(struct domain *d,
70                               const XEN_GUEST_HANDLE(const_uint64) pfn_list,
71                               const XEN_GUEST_HANDLE(const_uint8) access_list,
72                               uint32_t nr, uint32_t start, uint32_t mask,
73                               unsigned int altp2m_idx);
74 
75 /*
76  * Get access type for a gfn.
77  * If gfn == INVALID_GFN, gets the default access type.
78  */
79 int p2m_get_mem_access(struct domain *d, gfn_t gfn, xenmem_access_t *access);
80 
81 #ifdef CONFIG_HAS_MEM_ACCESS
82 int mem_access_memop(unsigned long cmd,
83                      XEN_GUEST_HANDLE_PARAM(xen_mem_access_op_t) arg);
84 #else
85 static inline
mem_access_memop(unsigned long cmd,XEN_GUEST_HANDLE_PARAM (xen_mem_access_op_t)arg)86 int mem_access_memop(unsigned long cmd,
87                      XEN_GUEST_HANDLE_PARAM(xen_mem_access_op_t) arg)
88 {
89     return -ENOSYS;
90 }
91 #endif /* CONFIG_HAS_MEM_ACCESS */
92 
93 #endif /* _XEN_MEM_ACCESS_H */
94 
95 /*
96  * Local variables:
97  * mode: C
98  * c-file-style: "BSD"
99  * c-basic-offset: 4
100  * indent-tabs-mode: nil
101  * End:
102  */
103