Skip to content

Commit b684452

Browse files
committed
Merge branch 'stable/for-linus-fixes-3.2' of git://git.kernel.org/pub/scm/linux/kernel/git/konrad/xen
* 'stable/for-linus-fixes-3.2' of git://git.kernel.org/pub/scm/linux/kernel/git/konrad/xen: xen-gntalloc: signedness bug in add_grefs() xen-gntalloc: integer overflow in gntalloc_ioctl_alloc() xen-gntdev: integer overflow in gntdev_alloc_map() xen:pvhvm: enable PVHVM VCPU placement when using more than 32 CPUs. xen/balloon: Avoid OOM when requesting highmem xen: Remove hanging references to CONFIG_XEN_PLATFORM_PCI xen: map foreign pages for shared rings by updating the PTEs directly
2 parents 15bd1cf + 99cb2dd commit b684452

10 files changed

Lines changed: 36 additions & 35 deletions

File tree

‎arch/x86/xen/enlighten.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,7 @@ static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self,
13561356
int cpu = (long)hcpu;
13571357
switch (action) {
13581358
case CPU_UP_PREPARE:
1359-
per_cpu(xen_vcpu, cpu) = &HYPERVISOR_shared_info->vcpu_info[cpu];
1359+
xen_vcpu_setup(cpu);
13601360
if (xen_have_vector_callback)
13611361
xen_init_lock_cpu(cpu);
13621362
break;
@@ -1386,7 +1386,6 @@ static void __init xen_hvm_guest_init(void)
13861386
xen_hvm_smp_init();
13871387
register_cpu_notifier(&xen_hvm_cpu_notifier);
13881388
xen_unplug_emulated_devices();
1389-
have_vcpu_info_placement = 0;
13901389
x86_init.irqs.intr_init = xen_init_IRQ;
13911390
xen_hvm_init_time_ops();
13921391
xen_hvm_init_mmu_ops();

‎arch/x86/xen/grant-table.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ int arch_gnttab_map_shared(unsigned long *frames, unsigned long nr_gframes,
7171

7272
if (shared == NULL) {
7373
struct vm_struct *area =
74-
alloc_vm_area(PAGE_SIZE * max_nr_gframes);
74+
alloc_vm_area(PAGE_SIZE * max_nr_gframes, NULL);
7575
BUG_ON(area == NULL);
7676
shared = area->addr;
7777
*__shared = shared;

‎drivers/xen/balloon.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ EXPORT_SYMBOL_GPL(balloon_set_new_target);
501501
* alloc_xenballooned_pages - get pages that have been ballooned out
502502
* @nr_pages: Number of pages to get
503503
* @pages: pages returned
504-
* @highmem: highmem or lowmem pages
504+
* @highmem: allow highmem pages
505505
* @return 0 on success, error otherwise
506506
*/
507507
int alloc_xenballooned_pages(int nr_pages, struct page **pages, bool highmem)
@@ -511,7 +511,7 @@ int alloc_xenballooned_pages(int nr_pages, struct page **pages, bool highmem)
511511
mutex_lock(&balloon_mutex);
512512
while (pgno < nr_pages) {
513513
page = balloon_retrieve(highmem);
514-
if (page && PageHighMem(page) == highmem) {
514+
if (page && (highmem || !PageHighMem(page))) {
515515
pages[pgno++] = page;
516516
} else {
517517
enum bp_state st;

‎drivers/xen/gntalloc.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ static int add_grefs(struct ioctl_gntalloc_alloc_gref *op,
135135
/* Grant foreign access to the page. */
136136
gref->gref_id = gnttab_grant_foreign_access(op->domid,
137137
pfn_to_mfn(page_to_pfn(gref->page)), readonly);
138-
if (gref->gref_id < 0) {
138+
if ((int)gref->gref_id < 0) {
139139
rc = gref->gref_id;
140140
goto undo;
141141
}
@@ -280,7 +280,7 @@ static long gntalloc_ioctl_alloc(struct gntalloc_file_private_data *priv,
280280
goto out;
281281
}
282282

283-
gref_ids = kzalloc(sizeof(gref_ids[0]) * op.count, GFP_TEMPORARY);
283+
gref_ids = kcalloc(op.count, sizeof(gref_ids[0]), GFP_TEMPORARY);
284284
if (!gref_ids) {
285285
rc = -ENOMEM;
286286
goto out;

‎drivers/xen/gntdev.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@ static struct grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count)
114114
if (NULL == add)
115115
return NULL;
116116

117-
add->grants = kzalloc(sizeof(add->grants[0]) * count, GFP_KERNEL);
118-
add->map_ops = kzalloc(sizeof(add->map_ops[0]) * count, GFP_KERNEL);
119-
add->unmap_ops = kzalloc(sizeof(add->unmap_ops[0]) * count, GFP_KERNEL);
120-
add->kmap_ops = kzalloc(sizeof(add->kmap_ops[0]) * count, GFP_KERNEL);
121-
add->pages = kzalloc(sizeof(add->pages[0]) * count, GFP_KERNEL);
117+
add->grants = kcalloc(count, sizeof(add->grants[0]), GFP_KERNEL);
118+
add->map_ops = kcalloc(count, sizeof(add->map_ops[0]), GFP_KERNEL);
119+
add->unmap_ops = kcalloc(count, sizeof(add->unmap_ops[0]), GFP_KERNEL);
120+
add->kmap_ops = kcalloc(count, sizeof(add->kmap_ops[0]), GFP_KERNEL);
121+
add->pages = kcalloc(count, sizeof(add->pages[0]), GFP_KERNEL);
122122
if (NULL == add->grants ||
123123
NULL == add->map_ops ||
124124
NULL == add->unmap_ops ||

‎drivers/xen/xenbus/xenbus_client.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <linux/vmalloc.h>
3636
#include <linux/export.h>
3737
#include <asm/xen/hypervisor.h>
38+
#include <asm/xen/page.h>
3839
#include <xen/interface/xen.h>
3940
#include <xen/interface/event_channel.h>
4041
#include <xen/events.h>
@@ -436,19 +437,20 @@ EXPORT_SYMBOL_GPL(xenbus_free_evtchn);
436437
int xenbus_map_ring_valloc(struct xenbus_device *dev, int gnt_ref, void **vaddr)
437438
{
438439
struct gnttab_map_grant_ref op = {
439-
.flags = GNTMAP_host_map,
440+
.flags = GNTMAP_host_map | GNTMAP_contains_pte,
440441
.ref = gnt_ref,
441442
.dom = dev->otherend_id,
442443
};
443444
struct vm_struct *area;
445+
pte_t *pte;
444446

445447
*vaddr = NULL;
446448

447-
area = alloc_vm_area(PAGE_SIZE);
449+
area = alloc_vm_area(PAGE_SIZE, &pte);
448450
if (!area)
449451
return -ENOMEM;
450452

451-
op.host_addr = (unsigned long)area->addr;
453+
op.host_addr = arbitrary_virt_to_machine(pte).maddr;
452454

453455
if (HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1))
454456
BUG();
@@ -527,6 +529,7 @@ int xenbus_unmap_ring_vfree(struct xenbus_device *dev, void *vaddr)
527529
struct gnttab_unmap_grant_ref op = {
528530
.host_addr = (unsigned long)vaddr,
529531
};
532+
unsigned int level;
530533

531534
/* It'd be nice if linux/vmalloc.h provided a find_vm_area(void *addr)
532535
* method so that we don't have to muck with vmalloc internals here.
@@ -548,6 +551,8 @@ int xenbus_unmap_ring_vfree(struct xenbus_device *dev, void *vaddr)
548551
}
549552

550553
op.handle = (grant_handle_t)area->phys_addr;
554+
op.host_addr = arbitrary_virt_to_machine(
555+
lookup_address((unsigned long)vaddr, &level)).maddr;
551556

552557
if (HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1))
553558
BUG();

‎include/linux/vmalloc.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ unmap_kernel_range(unsigned long addr, unsigned long size)
119119
#endif
120120

121121
/* Allocate/destroy a 'vmalloc' VM area. */
122-
extern struct vm_struct *alloc_vm_area(size_t size);
122+
extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
123123
extern void free_vm_area(struct vm_struct *area);
124124

125125
/* for /dev/kmem */

‎include/xen/platform_pci.h‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
static inline int xen_must_unplug_nics(void) {
3030
#if (defined(CONFIG_XEN_NETDEV_FRONTEND) || \
3131
defined(CONFIG_XEN_NETDEV_FRONTEND_MODULE)) && \
32-
(defined(CONFIG_XEN_PLATFORM_PCI) || \
33-
defined(CONFIG_XEN_PLATFORM_PCI_MODULE))
32+
defined(CONFIG_XEN_PVHVM)
3433
return 1;
3534
#else
3635
return 0;
@@ -40,8 +39,7 @@ static inline int xen_must_unplug_nics(void) {
4039
static inline int xen_must_unplug_disks(void) {
4140
#if (defined(CONFIG_XEN_BLKDEV_FRONTEND) || \
4241
defined(CONFIG_XEN_BLKDEV_FRONTEND_MODULE)) && \
43-
(defined(CONFIG_XEN_PLATFORM_PCI) || \
44-
defined(CONFIG_XEN_PLATFORM_PCI_MODULE))
42+
defined(CONFIG_XEN_PVHVM)
4543
return 1;
4644
#else
4745
return 0;

‎mm/nommu.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ void __attribute__((weak)) vmalloc_sync_all(void)
454454
* between processes, it syncs the pagetable across all
455455
* processes.
456456
*/
457-
struct vm_struct *alloc_vm_area(size_t size)
457+
struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes)
458458
{
459459
BUG();
460460
return NULL;

‎mm/vmalloc.c‎

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,23 +2141,30 @@ void __attribute__((weak)) vmalloc_sync_all(void)
21412141

21422142
static int f(pte_t *pte, pgtable_t table, unsigned long addr, void *data)
21432143
{
2144-
/* apply_to_page_range() does all the hard work. */
2144+
pte_t ***p = data;
2145+
2146+
if (p) {
2147+
*(*p) = pte;
2148+
(*p)++;
2149+
}
21452150
return 0;
21462151
}
21472152

21482153
/**
21492154
* alloc_vm_area - allocate a range of kernel address space
21502155
* @size: size of the area
2156+
* @ptes: returns the PTEs for the address space
21512157
*
21522158
* Returns: NULL on failure, vm_struct on success
21532159
*
21542160
* This function reserves a range of kernel address space, and
21552161
* allocates pagetables to map that range. No actual mappings
2156-
* are created. If the kernel address space is not shared
2157-
* between processes, it syncs the pagetable across all
2158-
* processes.
2162+
* are created.
2163+
*
2164+
* If @ptes is non-NULL, pointers to the PTEs (in init_mm)
2165+
* allocated for the VM area are returned.
21592166
*/
2160-
struct vm_struct *alloc_vm_area(size_t size)
2167+
struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes)
21612168
{
21622169
struct vm_struct *area;
21632170

@@ -2171,19 +2178,11 @@ struct vm_struct *alloc_vm_area(size_t size)
21712178
* of kernel virtual address space and mapped into init_mm.
21722179
*/
21732180
if (apply_to_page_range(&init_mm, (unsigned long)area->addr,
2174-
area->size, f, NULL)) {
2181+
size, f, ptes ? &ptes : NULL)) {
21752182
free_vm_area(area);
21762183
return NULL;
21772184
}
21782185

2179-
/*
2180-
* If the allocated address space is passed to a hypercall
2181-
* before being used then we cannot rely on a page fault to
2182-
* trigger an update of the page tables. So sync all the page
2183-
* tables here.
2184-
*/
2185-
vmalloc_sync_all();
2186-
21872186
return area;
21882187
}
21892188
EXPORT_SYMBOL_GPL(alloc_vm_area);

0 commit comments

Comments
 (0)