diff options
-rw-r--r-- | arch/x86/xen/mmu.c | 7 | ||||
-rw-r--r-- | drivers/xen/balloon.c | 15 | ||||
-rw-r--r-- | include/xen/interface/memory.h | 8 |
3 files changed, 19 insertions, 11 deletions
diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c index a5577f59416a..9e0d82fc21e4 100644 --- a/arch/x86/xen/mmu.c +++ b/arch/x86/xen/mmu.c | |||
@@ -70,6 +70,13 @@ | |||
70 | 70 | ||
71 | #define MMU_UPDATE_HISTO 30 | 71 | #define MMU_UPDATE_HISTO 30 |
72 | 72 | ||
73 | /* | ||
74 | * Protects atomic reservation decrease/increase against concurrent increases. | ||
75 | * Also protects non-atomic updates of current_pages and driver_pages, and | ||
76 | * balloon lists. | ||
77 | */ | ||
78 | DEFINE_SPINLOCK(xen_reservation_lock); | ||
79 | |||
73 | #ifdef CONFIG_XEN_DEBUG_FS | 80 | #ifdef CONFIG_XEN_DEBUG_FS |
74 | 81 | ||
75 | static struct { | 82 | static struct { |
diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index 1a0d8c2a0354..500290b150bb 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c | |||
@@ -85,13 +85,6 @@ static struct sys_device balloon_sysdev; | |||
85 | 85 | ||
86 | static int register_balloon(struct sys_device *sysdev); | 86 | static int register_balloon(struct sys_device *sysdev); |
87 | 87 | ||
88 | /* | ||
89 | * Protects atomic reservation decrease/increase against concurrent increases. | ||
90 | * Also protects non-atomic updates of current_pages and driver_pages, and | ||
91 | * balloon lists. | ||
92 | */ | ||
93 | static DEFINE_SPINLOCK(balloon_lock); | ||
94 | |||
95 | static struct balloon_stats balloon_stats; | 88 | static struct balloon_stats balloon_stats; |
96 | 89 | ||
97 | /* We increase/decrease in batches which fit in a page */ | 90 | /* We increase/decrease in batches which fit in a page */ |
@@ -210,7 +203,7 @@ static int increase_reservation(unsigned long nr_pages) | |||
210 | if (nr_pages > ARRAY_SIZE(frame_list)) | 203 | if (nr_pages > ARRAY_SIZE(frame_list)) |
211 | nr_pages = ARRAY_SIZE(frame_list); | 204 | nr_pages = ARRAY_SIZE(frame_list); |
212 | 205 | ||
213 | spin_lock_irqsave(&balloon_lock, flags); | 206 | spin_lock_irqsave(&xen_reservation_lock, flags); |
214 | 207 | ||
215 | page = balloon_first_page(); | 208 | page = balloon_first_page(); |
216 | for (i = 0; i < nr_pages; i++) { | 209 | for (i = 0; i < nr_pages; i++) { |
@@ -254,7 +247,7 @@ static int increase_reservation(unsigned long nr_pages) | |||
254 | balloon_stats.current_pages += rc; | 247 | balloon_stats.current_pages += rc; |
255 | 248 | ||
256 | out: | 249 | out: |
257 | spin_unlock_irqrestore(&balloon_lock, flags); | 250 | spin_unlock_irqrestore(&xen_reservation_lock, flags); |
258 | 251 | ||
259 | return rc < 0 ? rc : rc != nr_pages; | 252 | return rc < 0 ? rc : rc != nr_pages; |
260 | } | 253 | } |
@@ -299,7 +292,7 @@ static int decrease_reservation(unsigned long nr_pages) | |||
299 | kmap_flush_unused(); | 292 | kmap_flush_unused(); |
300 | flush_tlb_all(); | 293 | flush_tlb_all(); |
301 | 294 | ||
302 | spin_lock_irqsave(&balloon_lock, flags); | 295 | spin_lock_irqsave(&xen_reservation_lock, flags); |
303 | 296 | ||
304 | /* No more mappings: invalidate P2M and add to balloon. */ | 297 | /* No more mappings: invalidate P2M and add to balloon. */ |
305 | for (i = 0; i < nr_pages; i++) { | 298 | for (i = 0; i < nr_pages; i++) { |
@@ -315,7 +308,7 @@ static int decrease_reservation(unsigned long nr_pages) | |||
315 | 308 | ||
316 | balloon_stats.current_pages -= nr_pages; | 309 | balloon_stats.current_pages -= nr_pages; |
317 | 310 | ||
318 | spin_unlock_irqrestore(&balloon_lock, flags); | 311 | spin_unlock_irqrestore(&xen_reservation_lock, flags); |
319 | 312 | ||
320 | return need_sleep; | 313 | return need_sleep; |
321 | } | 314 | } |
diff --git a/include/xen/interface/memory.h b/include/xen/interface/memory.h index af36ead16817..e6adce6bc75c 100644 --- a/include/xen/interface/memory.h +++ b/include/xen/interface/memory.h | |||
@@ -9,6 +9,8 @@ | |||
9 | #ifndef __XEN_PUBLIC_MEMORY_H__ | 9 | #ifndef __XEN_PUBLIC_MEMORY_H__ |
10 | #define __XEN_PUBLIC_MEMORY_H__ | 10 | #define __XEN_PUBLIC_MEMORY_H__ |
11 | 11 | ||
12 | #include <linux/spinlock.h> | ||
13 | |||
12 | /* | 14 | /* |
13 | * Increase or decrease the specified domain's memory reservation. Returns a | 15 | * Increase or decrease the specified domain's memory reservation. Returns a |
14 | * -ve errcode on failure, or the # extents successfully allocated or freed. | 16 | * -ve errcode on failure, or the # extents successfully allocated or freed. |
@@ -142,4 +144,10 @@ struct xen_translate_gpfn_list { | |||
142 | }; | 144 | }; |
143 | DEFINE_GUEST_HANDLE_STRUCT(xen_translate_gpfn_list); | 145 | DEFINE_GUEST_HANDLE_STRUCT(xen_translate_gpfn_list); |
144 | 146 | ||
147 | |||
148 | /* | ||
149 | * Prevent the balloon driver from changing the memory reservation | ||
150 | * during a driver critical region. | ||
151 | */ | ||
152 | extern spinlock_t xen_reservation_lock; | ||
145 | #endif /* __XEN_PUBLIC_MEMORY_H__ */ | 153 | #endif /* __XEN_PUBLIC_MEMORY_H__ */ |