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