Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'for-linus-6.2-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip

Pull xen updates from Juergen Gross:

- fix memory leaks in error paths

- add support for virtio PCI-devices in Xen guests on ARM

- two minor fixes

* tag 'for-linus-6.2-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip:
xen/privcmd: Fix a possible warning in privcmd_ioctl_mmap_resource()
x86/xen: Fix memory leak in xen_init_lock_cpu()
x86/xen: Fix memory leak in xen_smp_intr_init{_pv}()
xen: fix xen.h build for CONFIG_XEN_PVH=y
xen/virtio: Handle PCI devices which Host controller is described in DT
xen/virtio: Optimize the setup of "xen-grant-dma" devices

+84 -91
+1 -1
arch/arm/xen/enlighten.c
··· 445 445 return 0; 446 446 447 447 if (IS_ENABLED(CONFIG_XEN_VIRTIO)) 448 - virtio_set_mem_acc_cb(xen_virtio_mem_acc); 448 + virtio_set_mem_acc_cb(xen_virtio_restricted_mem_acc); 449 449 450 450 if (!acpi_disabled) 451 451 xen_acpi_guest_init();
+12 -12
arch/x86/xen/smp.c
··· 32 32 33 33 void xen_smp_intr_free(unsigned int cpu) 34 34 { 35 + kfree(per_cpu(xen_resched_irq, cpu).name); 36 + per_cpu(xen_resched_irq, cpu).name = NULL; 35 37 if (per_cpu(xen_resched_irq, cpu).irq >= 0) { 36 38 unbind_from_irqhandler(per_cpu(xen_resched_irq, cpu).irq, NULL); 37 39 per_cpu(xen_resched_irq, cpu).irq = -1; 38 - kfree(per_cpu(xen_resched_irq, cpu).name); 39 - per_cpu(xen_resched_irq, cpu).name = NULL; 40 40 } 41 + kfree(per_cpu(xen_callfunc_irq, cpu).name); 42 + per_cpu(xen_callfunc_irq, cpu).name = NULL; 41 43 if (per_cpu(xen_callfunc_irq, cpu).irq >= 0) { 42 44 unbind_from_irqhandler(per_cpu(xen_callfunc_irq, cpu).irq, NULL); 43 45 per_cpu(xen_callfunc_irq, cpu).irq = -1; 44 - kfree(per_cpu(xen_callfunc_irq, cpu).name); 45 - per_cpu(xen_callfunc_irq, cpu).name = NULL; 46 46 } 47 + kfree(per_cpu(xen_debug_irq, cpu).name); 48 + per_cpu(xen_debug_irq, cpu).name = NULL; 47 49 if (per_cpu(xen_debug_irq, cpu).irq >= 0) { 48 50 unbind_from_irqhandler(per_cpu(xen_debug_irq, cpu).irq, NULL); 49 51 per_cpu(xen_debug_irq, cpu).irq = -1; 50 - kfree(per_cpu(xen_debug_irq, cpu).name); 51 - per_cpu(xen_debug_irq, cpu).name = NULL; 52 52 } 53 + kfree(per_cpu(xen_callfuncsingle_irq, cpu).name); 54 + per_cpu(xen_callfuncsingle_irq, cpu).name = NULL; 53 55 if (per_cpu(xen_callfuncsingle_irq, cpu).irq >= 0) { 54 56 unbind_from_irqhandler(per_cpu(xen_callfuncsingle_irq, cpu).irq, 55 57 NULL); 56 58 per_cpu(xen_callfuncsingle_irq, cpu).irq = -1; 57 - kfree(per_cpu(xen_callfuncsingle_irq, cpu).name); 58 - per_cpu(xen_callfuncsingle_irq, cpu).name = NULL; 59 59 } 60 60 } 61 61 ··· 65 65 char *resched_name, *callfunc_name, *debug_name; 66 66 67 67 resched_name = kasprintf(GFP_KERNEL, "resched%d", cpu); 68 + per_cpu(xen_resched_irq, cpu).name = resched_name; 68 69 rc = bind_ipi_to_irqhandler(XEN_RESCHEDULE_VECTOR, 69 70 cpu, 70 71 xen_reschedule_interrupt, ··· 75 74 if (rc < 0) 76 75 goto fail; 77 76 per_cpu(xen_resched_irq, cpu).irq = rc; 78 - per_cpu(xen_resched_irq, cpu).name = resched_name; 79 77 80 78 callfunc_name = kasprintf(GFP_KERNEL, "callfunc%d", cpu); 79 + per_cpu(xen_callfunc_irq, cpu).name = callfunc_name; 81 80 rc = bind_ipi_to_irqhandler(XEN_CALL_FUNCTION_VECTOR, 82 81 cpu, 83 82 xen_call_function_interrupt, ··· 87 86 if (rc < 0) 88 87 goto fail; 89 88 per_cpu(xen_callfunc_irq, cpu).irq = rc; 90 - per_cpu(xen_callfunc_irq, cpu).name = callfunc_name; 91 89 92 90 if (!xen_fifo_events) { 93 91 debug_name = kasprintf(GFP_KERNEL, "debug%d", cpu); 92 + per_cpu(xen_debug_irq, cpu).name = debug_name; 94 93 rc = bind_virq_to_irqhandler(VIRQ_DEBUG, cpu, 95 94 xen_debug_interrupt, 96 95 IRQF_PERCPU | IRQF_NOBALANCING, ··· 98 97 if (rc < 0) 99 98 goto fail; 100 99 per_cpu(xen_debug_irq, cpu).irq = rc; 101 - per_cpu(xen_debug_irq, cpu).name = debug_name; 102 100 } 103 101 104 102 callfunc_name = kasprintf(GFP_KERNEL, "callfuncsingle%d", cpu); 103 + per_cpu(xen_callfuncsingle_irq, cpu).name = callfunc_name; 105 104 rc = bind_ipi_to_irqhandler(XEN_CALL_FUNCTION_SINGLE_VECTOR, 106 105 cpu, 107 106 xen_call_function_single_interrupt, ··· 111 110 if (rc < 0) 112 111 goto fail; 113 112 per_cpu(xen_callfuncsingle_irq, cpu).irq = rc; 114 - per_cpu(xen_callfuncsingle_irq, cpu).name = callfunc_name; 115 113 116 114 return 0; 117 115
+6 -6
arch/x86/xen/smp_pv.c
··· 97 97 98 98 void xen_smp_intr_free_pv(unsigned int cpu) 99 99 { 100 + kfree(per_cpu(xen_irq_work, cpu).name); 101 + per_cpu(xen_irq_work, cpu).name = NULL; 100 102 if (per_cpu(xen_irq_work, cpu).irq >= 0) { 101 103 unbind_from_irqhandler(per_cpu(xen_irq_work, cpu).irq, NULL); 102 104 per_cpu(xen_irq_work, cpu).irq = -1; 103 - kfree(per_cpu(xen_irq_work, cpu).name); 104 - per_cpu(xen_irq_work, cpu).name = NULL; 105 105 } 106 106 107 + kfree(per_cpu(xen_pmu_irq, cpu).name); 108 + per_cpu(xen_pmu_irq, cpu).name = NULL; 107 109 if (per_cpu(xen_pmu_irq, cpu).irq >= 0) { 108 110 unbind_from_irqhandler(per_cpu(xen_pmu_irq, cpu).irq, NULL); 109 111 per_cpu(xen_pmu_irq, cpu).irq = -1; 110 - kfree(per_cpu(xen_pmu_irq, cpu).name); 111 - per_cpu(xen_pmu_irq, cpu).name = NULL; 112 112 } 113 113 } 114 114 ··· 118 118 char *callfunc_name, *pmu_name; 119 119 120 120 callfunc_name = kasprintf(GFP_KERNEL, "irqwork%d", cpu); 121 + per_cpu(xen_irq_work, cpu).name = callfunc_name; 121 122 rc = bind_ipi_to_irqhandler(XEN_IRQ_WORK_VECTOR, 122 123 cpu, 123 124 xen_irq_work_interrupt, ··· 128 127 if (rc < 0) 129 128 goto fail; 130 129 per_cpu(xen_irq_work, cpu).irq = rc; 131 - per_cpu(xen_irq_work, cpu).name = callfunc_name; 132 130 133 131 if (is_xen_pmu) { 134 132 pmu_name = kasprintf(GFP_KERNEL, "pmu%d", cpu); 133 + per_cpu(xen_pmu_irq, cpu).name = pmu_name; 135 134 rc = bind_virq_to_irqhandler(VIRQ_XENPMU, cpu, 136 135 xen_pmu_irq_handler, 137 136 IRQF_PERCPU|IRQF_NOBALANCING, ··· 139 138 if (rc < 0) 140 139 goto fail; 141 140 per_cpu(xen_pmu_irq, cpu).irq = rc; 142 - per_cpu(xen_pmu_irq, cpu).name = pmu_name; 143 141 } 144 142 145 143 return 0;
+3 -3
arch/x86/xen/spinlock.c
··· 75 75 cpu, per_cpu(lock_kicker_irq, cpu)); 76 76 77 77 name = kasprintf(GFP_KERNEL, "spinlock%d", cpu); 78 + per_cpu(irq_name, cpu) = name; 78 79 irq = bind_ipi_to_irqhandler(XEN_SPIN_UNLOCK_VECTOR, 79 80 cpu, 80 81 dummy_handler, ··· 86 85 if (irq >= 0) { 87 86 disable_irq(irq); /* make sure it's never delivered */ 88 87 per_cpu(lock_kicker_irq, cpu) = irq; 89 - per_cpu(irq_name, cpu) = name; 90 88 } 91 89 92 90 printk("cpu %d spinlock event irq %d\n", cpu, irq); ··· 98 98 if (!xen_pvspin) 99 99 return; 100 100 101 + kfree(per_cpu(irq_name, cpu)); 102 + per_cpu(irq_name, cpu) = NULL; 101 103 /* 102 104 * When booting the kernel with 'mitigations=auto,nosmt', the secondary 103 105 * CPUs are not activated, and lock_kicker_irq is not initialized. ··· 110 108 111 109 unbind_from_irqhandler(irq, NULL); 112 110 per_cpu(lock_kicker_irq, cpu) = -1; 113 - kfree(per_cpu(irq_name, cpu)); 114 - per_cpu(irq_name, cpu) = NULL; 115 111 } 116 112 117 113 PV_CALLEE_SAVE_REGS_THUNK(xen_vcpu_stolen);
+58 -47
drivers/xen/grant-dma-ops.c
··· 10 10 #include <linux/module.h> 11 11 #include <linux/dma-map-ops.h> 12 12 #include <linux/of.h> 13 + #include <linux/pci.h> 13 14 #include <linux/pfn.h> 14 15 #include <linux/xarray.h> 15 16 #include <linux/virtio_anchor.h> ··· 293 292 .dma_supported = xen_grant_dma_supported, 294 293 }; 295 294 296 - static bool xen_is_dt_grant_dma_device(struct device *dev) 295 + static struct device_node *xen_dt_get_node(struct device *dev) 297 296 { 298 - struct device_node *iommu_np; 299 - bool has_iommu; 297 + if (dev_is_pci(dev)) { 298 + struct pci_dev *pdev = to_pci_dev(dev); 299 + struct pci_bus *bus = pdev->bus; 300 300 301 - iommu_np = of_parse_phandle(dev->of_node, "iommus", 0); 302 - has_iommu = iommu_np && 303 - of_device_is_compatible(iommu_np, "xen,grant-dma"); 304 - of_node_put(iommu_np); 301 + /* Walk up to the root bus to look for PCI Host controller */ 302 + while (!pci_is_root_bus(bus)) 303 + bus = bus->parent; 305 304 306 - return has_iommu; 307 - } 305 + return of_node_get(bus->bridge->parent->of_node); 306 + } 308 307 309 - bool xen_is_grant_dma_device(struct device *dev) 310 - { 311 - /* XXX Handle only DT devices for now */ 312 - if (dev->of_node) 313 - return xen_is_dt_grant_dma_device(dev); 314 - 315 - return false; 316 - } 317 - 318 - bool xen_virtio_mem_acc(struct virtio_device *dev) 319 - { 320 - if (IS_ENABLED(CONFIG_XEN_VIRTIO_FORCE_GRANT) || xen_pv_domain()) 321 - return true; 322 - 323 - return xen_is_grant_dma_device(dev->dev.parent); 308 + return of_node_get(dev->of_node); 324 309 } 325 310 326 311 static int xen_dt_grant_init_backend_domid(struct device *dev, 327 - struct xen_grant_dma_data *data) 312 + struct device_node *np, 313 + domid_t *backend_domid) 328 314 { 329 - struct of_phandle_args iommu_spec; 315 + struct of_phandle_args iommu_spec = { .args_count = 1 }; 330 316 331 - if (of_parse_phandle_with_args(dev->of_node, "iommus", "#iommu-cells", 332 - 0, &iommu_spec)) { 333 - dev_err(dev, "Cannot parse iommus property\n"); 334 - return -ESRCH; 317 + if (dev_is_pci(dev)) { 318 + struct pci_dev *pdev = to_pci_dev(dev); 319 + u32 rid = PCI_DEVID(pdev->bus->number, pdev->devfn); 320 + 321 + if (of_map_id(np, rid, "iommu-map", "iommu-map-mask", &iommu_spec.np, 322 + iommu_spec.args)) { 323 + dev_dbg(dev, "Cannot translate ID\n"); 324 + return -ESRCH; 325 + } 326 + } else { 327 + if (of_parse_phandle_with_args(np, "iommus", "#iommu-cells", 328 + 0, &iommu_spec)) { 329 + dev_dbg(dev, "Cannot parse iommus property\n"); 330 + return -ESRCH; 331 + } 335 332 } 336 333 337 334 if (!of_device_is_compatible(iommu_spec.np, "xen,grant-dma") || 338 335 iommu_spec.args_count != 1) { 339 - dev_err(dev, "Incompatible IOMMU node\n"); 336 + dev_dbg(dev, "Incompatible IOMMU node\n"); 340 337 of_node_put(iommu_spec.np); 341 338 return -ESRCH; 342 339 } ··· 345 346 * The endpoint ID here means the ID of the domain where the 346 347 * corresponding backend is running 347 348 */ 348 - data->backend_domid = iommu_spec.args[0]; 349 + *backend_domid = iommu_spec.args[0]; 349 350 350 351 return 0; 351 352 } 352 353 353 - void xen_grant_setup_dma_ops(struct device *dev) 354 + static int xen_grant_init_backend_domid(struct device *dev, 355 + domid_t *backend_domid) 356 + { 357 + struct device_node *np; 358 + int ret = -ENODEV; 359 + 360 + np = xen_dt_get_node(dev); 361 + if (np) { 362 + ret = xen_dt_grant_init_backend_domid(dev, np, backend_domid); 363 + of_node_put(np); 364 + } else if (IS_ENABLED(CONFIG_XEN_VIRTIO_FORCE_GRANT) || xen_pv_domain()) { 365 + dev_info(dev, "Using dom0 as backend\n"); 366 + *backend_domid = 0; 367 + ret = 0; 368 + } 369 + 370 + return ret; 371 + } 372 + 373 + static void xen_grant_setup_dma_ops(struct device *dev, domid_t backend_domid) 354 374 { 355 375 struct xen_grant_dma_data *data; 356 376 ··· 383 365 if (!data) 384 366 goto err; 385 367 386 - if (dev->of_node) { 387 - if (xen_dt_grant_init_backend_domid(dev, data)) 388 - goto err; 389 - } else if (IS_ENABLED(CONFIG_XEN_VIRTIO_FORCE_GRANT)) { 390 - dev_info(dev, "Using dom0 as backend\n"); 391 - data->backend_domid = 0; 392 - } else { 393 - /* XXX ACPI device unsupported for now */ 394 - goto err; 395 - } 368 + data->backend_domid = backend_domid; 396 369 397 370 if (store_xen_grant_dma_data(dev, data)) { 398 371 dev_err(dev, "Cannot store Xen grant DMA data\n"); ··· 401 392 402 393 bool xen_virtio_restricted_mem_acc(struct virtio_device *dev) 403 394 { 404 - bool ret = xen_virtio_mem_acc(dev); 395 + domid_t backend_domid; 405 396 406 - if (ret) 407 - xen_grant_setup_dma_ops(dev->dev.parent); 397 + if (!xen_grant_init_backend_domid(dev->dev.parent, &backend_domid)) { 398 + xen_grant_setup_dma_ops(dev->dev.parent, backend_domid); 399 + return true; 400 + } 408 401 409 - return ret; 402 + return false; 410 403 } 411 404 412 405 MODULE_DESCRIPTION("Xen grant DMA-mapping layer");
+1 -1
drivers/xen/privcmd.c
··· 760 760 goto out; 761 761 } 762 762 763 - pfns = kcalloc(kdata.num, sizeof(*pfns), GFP_KERNEL); 763 + pfns = kcalloc(kdata.num, sizeof(*pfns), GFP_KERNEL | __GFP_NOWARN); 764 764 if (!pfns) { 765 765 rc = -ENOMEM; 766 766 goto out;
+1 -3
include/xen/arm/xen-ops.h
··· 8 8 static inline void xen_setup_dma_ops(struct device *dev) 9 9 { 10 10 #ifdef CONFIG_XEN 11 - if (xen_is_grant_dma_device(dev)) 12 - xen_grant_setup_dma_ops(dev); 13 - else if (xen_swiotlb_detect()) 11 + if (xen_swiotlb_detect()) 14 12 dev->dma_ops = &xen_swiotlb_dma_ops; 15 13 #endif 16 14 }
-16
include/xen/xen-ops.h
··· 216 216 #endif /* CONFIG_XEN_PV && !CONFIG_PREEMPTION */ 217 217 218 218 #ifdef CONFIG_XEN_GRANT_DMA_OPS 219 - void xen_grant_setup_dma_ops(struct device *dev); 220 - bool xen_is_grant_dma_device(struct device *dev); 221 - bool xen_virtio_mem_acc(struct virtio_device *dev); 222 219 bool xen_virtio_restricted_mem_acc(struct virtio_device *dev); 223 220 #else 224 - static inline void xen_grant_setup_dma_ops(struct device *dev) 225 - { 226 - } 227 - static inline bool xen_is_grant_dma_device(struct device *dev) 228 - { 229 - return false; 230 - } 231 - 232 221 struct virtio_device; 233 - 234 - static inline bool xen_virtio_mem_acc(struct virtio_device *dev) 235 - { 236 - return false; 237 - } 238 222 239 223 static inline bool xen_virtio_restricted_mem_acc(struct virtio_device *dev) 240 224 {
+2 -2
include/xen/xen.h
··· 2 2 #ifndef _XEN_XEN_H 3 3 #define _XEN_XEN_H 4 4 5 + #include <linux/types.h> 6 + 5 7 enum xen_domain_type { 6 8 XEN_NATIVE, /* running on bare hardware */ 7 9 XEN_PV_DOMAIN, /* running in a PV domain */ ··· 26 24 #define xen_pv_domain() (xen_domain_type == XEN_PV_DOMAIN) 27 25 #define xen_hvm_domain() (xen_domain_type == XEN_HVM_DOMAIN) 28 26 #define xen_pvh_domain() (xen_pvh) 29 - 30 - #include <linux/types.h> 31 27 32 28 extern uint32_t xen_start_flags; 33 29