Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 9351f13

Browse files
committed
Merge tag 'for-linus-6.10a-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip
Pull xen updates from Juergen Gross: - a small cleanup in the drivers/xen/xenbus Makefile - a fix of the Xen xenstore driver to improve connecting to a late started Xenstore - an enhancement for better support of ballooning in PVH guests - a cleanup using try_cmpxchg() instead of open coding it * tag 'for-linus-6.10a-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip: drivers/xen: Improve the late XenStore init protocol xen/xenbus: Use *-y instead of *-objs in Makefile xen/x86: add extra pages to unpopulated-alloc if available locking/x86/xen: Use try_cmpxchg() in xen_alloc_p2m_entry()
2 parents 02c438b + a360758 commit 9351f13

File tree

4 files changed

+67
-27
lines changed

4 files changed

+67
-27
lines changed

arch/x86/xen/enlighten.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,3 +379,36 @@ void __init xen_add_extra_mem(unsigned long start_pfn, unsigned long n_pfns)
379379

380380
memblock_reserve(PFN_PHYS(start_pfn), PFN_PHYS(n_pfns));
381381
}
382+
383+
#ifdef CONFIG_XEN_UNPOPULATED_ALLOC
384+
int __init arch_xen_unpopulated_init(struct resource **res)
385+
{
386+
unsigned int i;
387+
388+
if (!xen_domain())
389+
return -ENODEV;
390+
391+
/* Must be set strictly before calling xen_free_unpopulated_pages(). */
392+
*res = &iomem_resource;
393+
394+
/*
395+
* Initialize with pages from the extra memory regions (see
396+
* arch/x86/xen/setup.c).
397+
*/
398+
for (i = 0; i < XEN_EXTRA_MEM_MAX_REGIONS; i++) {
399+
unsigned int j;
400+
401+
for (j = 0; j < xen_extra_mem[i].n_pfns; j++) {
402+
struct page *pg =
403+
pfn_to_page(xen_extra_mem[i].start_pfn + j);
404+
405+
xen_free_unpopulated_pages(1, &pg);
406+
}
407+
408+
/* Zero so region is not also added to the balloon driver. */
409+
xen_extra_mem[i].n_pfns = 0;
410+
}
411+
412+
return 0;
413+
}
414+
#endif

arch/x86/xen/p2m.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,6 @@ int xen_alloc_p2m_entry(unsigned long pfn)
555555
/* Separately check the mid mfn level */
556556
unsigned long missing_mfn;
557557
unsigned long mid_mfn_mfn;
558-
unsigned long old_mfn;
559558

560559
mid_mfn = alloc_p2m_page();
561560
if (!mid_mfn)
@@ -565,12 +564,12 @@ int xen_alloc_p2m_entry(unsigned long pfn)
565564

566565
missing_mfn = virt_to_mfn(p2m_mid_missing_mfn);
567566
mid_mfn_mfn = virt_to_mfn(mid_mfn);
568-
old_mfn = cmpxchg(top_mfn_p, missing_mfn, mid_mfn_mfn);
569-
if (old_mfn != missing_mfn) {
570-
free_p2m_page(mid_mfn);
571-
mid_mfn = mfn_to_virt(old_mfn);
572-
} else {
567+
/* try_cmpxchg() updates missing_mfn on failure. */
568+
if (try_cmpxchg(top_mfn_p, &missing_mfn, mid_mfn_mfn)) {
573569
p2m_top_mfn_p[topidx] = mid_mfn;
570+
} else {
571+
free_p2m_page(mid_mfn);
572+
mid_mfn = mfn_to_virt(missing_mfn);
574573
}
575574
}
576575
} else {

drivers/xen/xenbus/Makefile

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
# SPDX-License-Identifier: GPL-2.0
22
obj-y += xenbus.o
3-
obj-y += xenbus_dev_frontend.o
43

5-
xenbus-objs =
6-
xenbus-objs += xenbus_client.o
7-
xenbus-objs += xenbus_comms.o
8-
xenbus-objs += xenbus_xs.o
9-
xenbus-objs += xenbus_probe.o
4+
xenbus-y := xenbus_client.o
5+
xenbus-y += xenbus_comms.o
6+
xenbus-y += xenbus_xs.o
7+
xenbus-y += xenbus_probe.o
108

11-
xenbus-be-objs-$(CONFIG_XEN_BACKEND) += xenbus_probe_backend.o
12-
xenbus-objs += $(xenbus-be-objs-y)
9+
xenbus-$(CONFIG_XEN_BACKEND) += xenbus_probe_backend.o
1310

11+
obj-y += xenbus_dev_frontend.o
1412
obj-$(CONFIG_XEN_BACKEND) += xenbus_dev_backend.o
1513
obj-$(CONFIG_XEN_XENBUS_FRONTEND) += xenbus_probe_frontend.o

drivers/xen/xenbus/xenbus_probe.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,17 @@
6565
#include "xenbus.h"
6666

6767

68-
static int xs_init_irq;
68+
static int xs_init_irq = -1;
6969
int xen_store_evtchn;
7070
EXPORT_SYMBOL_GPL(xen_store_evtchn);
7171

7272
struct xenstore_domain_interface *xen_store_interface;
7373
EXPORT_SYMBOL_GPL(xen_store_interface);
7474

75+
#define XS_INTERFACE_READY \
76+
((xen_store_interface != NULL) && \
77+
(xen_store_interface->connection == XENSTORE_CONNECTED))
78+
7579
enum xenstore_init xen_store_domain_type;
7680
EXPORT_SYMBOL_GPL(xen_store_domain_type);
7781

@@ -751,19 +755,19 @@ static void xenbus_probe(void)
751755
{
752756
xenstored_ready = 1;
753757

754-
if (!xen_store_interface) {
758+
if (!xen_store_interface)
755759
xen_store_interface = memremap(xen_store_gfn << XEN_PAGE_SHIFT,
756760
XEN_PAGE_SIZE, MEMREMAP_WB);
757-
/*
758-
* Now it is safe to free the IRQ used for xenstore late
759-
* initialization. No need to unbind: it is about to be
760-
* bound again from xb_init_comms. Note that calling
761-
* unbind_from_irqhandler now would result in xen_evtchn_close()
762-
* being called and the event channel not being enabled again
763-
* afterwards, resulting in missed event notifications.
764-
*/
761+
/*
762+
* Now it is safe to free the IRQ used for xenstore late
763+
* initialization. No need to unbind: it is about to be
764+
* bound again from xb_init_comms. Note that calling
765+
* unbind_from_irqhandler now would result in xen_evtchn_close()
766+
* being called and the event channel not being enabled again
767+
* afterwards, resulting in missed event notifications.
768+
*/
769+
if (xs_init_irq >= 0)
765770
free_irq(xs_init_irq, &xb_waitq);
766-
}
767771

768772
/*
769773
* In the HVM case, xenbus_init() deferred its call to
@@ -822,7 +826,7 @@ static int __init xenbus_probe_initcall(void)
822826
if (xen_store_domain_type == XS_PV ||
823827
(xen_store_domain_type == XS_HVM &&
824828
!xs_hvm_defer_init_for_callback() &&
825-
xen_store_interface != NULL))
829+
XS_INTERFACE_READY))
826830
xenbus_probe();
827831

828832
/*
@@ -831,7 +835,7 @@ static int __init xenbus_probe_initcall(void)
831835
* started, then probe. It will be triggered when communication
832836
* starts happening, by waiting on xb_waitq.
833837
*/
834-
if (xen_store_domain_type == XS_LOCAL || xen_store_interface == NULL) {
838+
if (xen_store_domain_type == XS_LOCAL || !XS_INTERFACE_READY) {
835839
struct task_struct *probe_task;
836840

837841
probe_task = kthread_run(xenbus_probe_thread, NULL,
@@ -1014,6 +1018,12 @@ static int __init xenbus_init(void)
10141018
xen_store_interface =
10151019
memremap(xen_store_gfn << XEN_PAGE_SHIFT,
10161020
XEN_PAGE_SIZE, MEMREMAP_WB);
1021+
if (!xen_store_interface) {
1022+
pr_err("%s: cannot map HVM_PARAM_STORE_PFN=%llx\n",
1023+
__func__, v);
1024+
err = -EINVAL;
1025+
goto out_error;
1026+
}
10171027
if (xen_store_interface->connection != XENSTORE_CONNECTED)
10181028
wait = true;
10191029
}

0 commit comments

Comments
 (0)