Home | History | Annotate | Download | only in xenbus
History log of /src/sys/arch/xen/xenbus/xenbus_probe.c
RevisionDateAuthorComments
 1.62  06-Feb-2025  bouyer Ignore cdroms only for VM_GUEST_XENPVHVM guests, not for all !XENPV kernels
(we can also have PVH guests with !XENPV kernels)
 1.61  06-Feb-2025  sborrill cdroms as xbd devices are skipped in PVHVM mode to avoid hangs if they
are not ready, i.e. do not contain an ISO image (that they hang is a bug
that should be fixed in itself). They are instead detected as an emulated
cdX which does deal with not being ready.

This leads to a regression in pure PV mode where xbd devices are hot-plugged
when an ISO is mounted and there are no emulated block devices such as cdX.
The xbd devices never appear and thus ISO images are not accessible.

Revert to pre-10 behaviour on pure PV kernels.
 1.60  17-Oct-2023  bouyer branches: 1.60.6;
xenbus: if dom0 support is not compiled in, panic with a usefull message
instead of waiting for an event which will never happen
 1.59  01-Aug-2023  mrg don't test arrays against NULL.

found by GCC 12.
 1.58  07-Aug-2021  thorpej branches: 1.58.6;
Merge thorpej-cfargs2.
 1.57  16-Jun-2021  bouyer branches: 1.57.2;
Grab KERNEL_LOCK before calling config_found()
 1.56  24-Apr-2021  thorpej branches: 1.56.2;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.55  26-May-2020  bouyer branches: 1.55.4;
Add need-flags for kernfs.
Compile Xen kernfs support only if kernfs is compiled in the kernel.
Should fix MODULAR build.
 1.54  14-May-2020  jdolecek fix compile when DPRINK() is defined
 1.53  13-May-2020  jdolecek don't reinitialize mutexes/cv on resume

part of PR port-xen/55207
 1.52  06-May-2020  bouyer Convert remaining splfoo/splx and tsleep/wakeup to mutex and condvar.
Mark kernel threads and interrupt handlers MPSAFE.
 1.51  28-Apr-2020  bouyer Skip block device with device-type "cdrom", as their emulation can't be
disabled; and the backend driver doesn't handle them either.
Fix hang when booting with 'ioemu:hdc:cdrom' type disks.
While there convert some printf to aprint_error()
 1.50  25-Apr-2020  bouyer Merge the bouyer-xenpvh branch, bringing in Xen PV drivers support under HVM
guests in GENERIC.
Xen support can be disabled at runtime with
boot -c
disable hypervisor
 1.49  11-Apr-2020  jdolecek put xenbus dmat into xenbus_device so it's available also for backend
devices which don't use autoconfig, remove from attach args
 1.48  10-Apr-2020  jdolecek add and pass dma tag to PV drivers attached to xenbus, so thay can
use bus_dmamap_load_mbuf() et.al.

due to XENPV override, _BUS_BUS_TO_PHYS() dmamap segment ds_addr
gets filled with ma, so value can be directly used for e.g. grant calls
 1.47  10-Apr-2020  jdolecek g/c unused xenwatch_mutex extern, and streq()
 1.46  07-Apr-2020  jdolecek branches: 1.46.2;
add a small wrapper xenbus_directory_free() to free result of
xenbus_directory(), so that caller doesn't need to be aware how the memory
was allocated
 1.45  07-Apr-2020  jdolecek partially convert to kmem_alloc()

plug memory leak in one xenbus_probe_device_type() error path
when read_backend_details() fails
 1.44  07-Apr-2020  jdolecek convert the node watch code to use kmem_alloc() instead of malloc()
 1.43  07-Apr-2020  jdolecek revert the watch.node change, xenbus_watch_path() and xenbus_watch_path2()
need to use non-constant path
 1.42  07-Apr-2020  jdolecek change xenbus_read() interface so that caller supplies the buffer and it's
size, caller doesn't free(9) the returned value any more
 1.41  07-Apr-2020  jdolecek no need to malloc()+copy watch.node, it's constant string - either "device"
or "backend"; just use the strings direct
 1.40  26-Feb-2019  joerg Compute storage size for a string correctly.
 1.39  07-Jul-2016  msaitoh branches: 1.39.18;
KNF. Remove extra spaces. No functional change.
 1.38  13-Oct-2013  riz branches: 1.38.6;
Catch up to recent changes in config_pending_{incr,decr}().
 1.37  07-Jun-2012  sborrill branches: 1.37.2; 1.37.4;
Fix problem where devices with ID 0 were skipped as invalid as it didn't
distinguish between numerical zero and invalid numeric string.
 1.36  05-Jun-2012  sborrill Sort vif and vbd device IDs numerically so that attach order does not depend
on the order they are passed in through xenstore. While this works for
hand-crafted Xen configuration files, it does not work for XenServer, XCP or
EC2 instances. This means that adding an extra virtual disk can make the
domU unbootable.

ID is actually based on the Linux device major/minor so this approach isn't
entirely correct (for instance, you can specify devices to be non-contiguous
which doesn't fit too well with our autoconf approach), but it works as a
first approximation.

Tested by me on XenServer and riz@ on EC2. OK bouyer@
 1.35  22-Sep-2011  jym branches: 1.35.2; 1.35.8;
Expose Xen kernfs entries inside a domU. Patch originally from sborrill@,
slightly modified by me to profit from runtime checks for dom0 privileges
instead of using compile time macros (DOM0OPS).

It should now be possible to use pkgsrc's sysutils/xentools inside
a domU to query XenStore entries (or even modify part of it if the domain
has enough rights).
 1.34  20-Sep-2011  jym Merge jym-xensuspend branch in -current. ok bouyer@.

Goal: save/restore support in NetBSD domUs, for i386, i386 PAE and amd64.

Executive summary:
- split all Xen drivers (xenbus(4), grant tables, xbd(4), xennet(4))
in two parts: suspend and resume, and hook them to pmf(9).
- modify pmap so that Xen hypervisor does not cry out loud in case
it finds "unexpected" recursive memory mappings
- provide a sysctl(7), machdep.xen.suspend, to command suspend from
userland via powerd(8). Note: a suspend can only be handled correctly
when dom0 requested it, so provide a mechanism that will prevent
kernel to blindly validate user's commands

The code is still in experimental state, use at your own risk: restore
can corrupt backend communications rings; this can completely thrash
dom0 as it will loop at a high interrupt level trying to honor
all domU requests.

XXX PAE suspend does not work in amd64 currently, due to (yet again!)
page validation issues with hypervisor. Will fix.

XXX secondary CPUs are not suspended, I will write the handlers
in sync with cherry's Xen MP work.

Tested under i386 and amd64, bear in mind ring corruption though.

No build break expected, GENERICs and XEN* kernels should be fine.
./build.sh distribution still running. In any case: sorry if it does
break for you, contact me directly for reports.
 1.33  17-Jul-2011  joerg Retire varargs.h support. Move machine/stdarg.h logic into MI
sys/stdarg.h and expect compiler to provide proper builtins, defaulting
to the GCC interface. lint still has a special fallback.
Reduce abuse of _BSD_VA_LIST_ by defining __va_list by default and
derive va_list as required by standards.
 1.32  18-Apr-2011  jym Large rewrite of the balloon driver. This one:

- turns balloon into a driver that attaches to xenbus(4). This allows to
disable the functionality either at compile time or boot time via
userconf(4). Driver can implement detach or pmf(9) hooks if deemed
necessary.

- keeps Cherry's locking model, but simplify it a bit. There is now
only one target value serialized inside balloon, we do not feedback
alternative value to Xenstore (clients are not expected to see its value
evolve behind their back, and can't do much about that either)

- implements min threshold; this is an admin-settable value that tells
driver to "not balloon below this threshold." This can be used by domain
to keep memory reservations, useful if activity is expected in the near
future.

- in addition to min threshold, the driver implements internally a
safeguard value (uvmexp.freemin + 1MiB), so that admin cannot
inadvertently set min to a very low value forcing domain into heavy
memory pressure and swapping.

- create the sysctl(8) kern.xen.balloon tree. 4 nodes are actually present
(values are in KiB):
- min: (rw) an admin-settable value that prevents ballooning below this
mark
- max: (ro) the maximum size for reservation, as set by xm(1) mem-max.
- current: (ro) the current reservation for domain.
- target: (rw) the targetted reservation for domain.

- fix a few limitations here and there, most notably the max_reservation
hypercall, and KiB vs pages representations at interfaces.

The driver is still turned off by default. Enabling it would need more
approval, especially from bouyer@, cherry@ and cegger@.

FWIW: tested it two days long, from amd64 dom0 (with dom0 ballooning
enabled for xend), and bunch of domUs. Did not notice anything suspicious.

XXX it still has one big limitation: it cannot hotplug memory pages in
uvm(9) if they were not present beforehand. Example: ballooning above
physmem will give more pages to domain but it won't use it to serve
allocations, unless we teach uvm(9) how to handle the extra pages.
 1.31  12-Apr-2011  cegger previous fix does not work if there is exactly only one entry where continue
exits the loop.
Apply fix from Konrad Wilke on port-xen@
That makes NetBSD DomU boot on Linux Dom0 with xl.
 1.30  11-Apr-2011  cegger Continue scanning for other frontends when initialization
of one frontend failed. Bug reported by Konrad Wilk on port-xen@.
Fix this for all error pathes within the loop.
 1.29  30-Mar-2011  jym (purely cosmetic changes)

- Use free_otherend_details() instead of calling free() on xbusd_otherend.
- rename talk_to_otherend() to watch_otherend(). We register a watch for
changes in the otherend device "state"; we are not really talking to it.
- add missing prototypes.
 1.28  06-Jul-2010  cherry branches: 1.28.2;
The Xen balloon driver enables growing and shrinking
PV domains on the fly, by collaborating with UVM and the hypervisor
 1.27  09-Jan-2009  jym branches: 1.27.2; 1.27.4; 1.27.6;
Do not probe for console when configuring xenbus devices, as it is
attached earlier during boot, when initializing hypervisor.

This avoids the "unknown type console at xenbus0 id 0 not configured"
autoconf(9) messages, which are misleading during domU's boot.

See also http://mail-index.netbsd.org/port-xen/2009/01/05/msg004621.html

Ok by bouyer@ in private mail.
 1.26  29-Oct-2008  cegger branches: 1.26.2;
include <xen/xen.h> for xendomain_is_dom0()
 1.25  24-Oct-2008  jym branches: 1.25.2;
- rename init_events() to events_init(), to better reflect netbsd semantics

- change unbind_[pv]irq_from_evtch() so that they now return the event
channel the [PV]IRQ was bound to. It reflects the opposite behaviour of the
bind_[pv]irq_to_evtch() functions.

- remove xenbus_suspend() and xenbus_resume() prototypes, as they are not
used anywhere else, and will conflict with the xenbus pmf(9) handlers.

- make start_info aligned on a page boundary, as Xen expects it to be so.

- mask event channel during xbd detach before removing its handler (can
avoid spurious events).

- add the "protocol" entry in xenstore during xbd initialization. Normally
created during domU's boot by xentools, it is under domU's responsibility
in all other cases (save/restore, hot plugging, etc.).

- modifications to xs_init(), so that it can properly return an error.

Reviewed by Christoph (cegger@).
 1.24  21-Oct-2008  cegger The 'sc' in xenbus_sc implies a softc, but it is actually a device_t. Since the device_t/softc split you can't cast a softc out of a device and vice versa.
Therefore rename xenbus_sc to xenbus_dev to prevent any possible confusions.
 1.23  21-Oct-2008  cegger xenbus_probe_init():
- use xendomain_is_dom0() (from jym@)
- replace return with kthread_exit(0) (from jym@)
- cleanup error handling
- plug memory leak in error path
- use aprint_error_dev for error messages (from jym@)

xenbus_attach():
- use aprint_error_dev for error message
 1.22  05-Sep-2008  tron Compile NetBSD/amd64 kernels with "-Wextra". Patches contributed by
Juan RP in PR port-amd64/39266.
 1.21  02-Jun-2008  cegger branches: 1.21.4;
Dom0: Add a delay before registering event handlers. Wait 1s per request from bouyer.

Fixes "Hotplug scripts not working" problems when launching guests.
Reviewed by bouyer.
 1.20  16-Apr-2008  cegger branches: 1.20.2; 1.20.4; 1.20.6;
device_t / softc split
reviewed, tested and approved by bouyer
 1.19  06-Apr-2008  cegger use aprint_*_dev and device_xname
 1.18  15-Dec-2007  perry branches: 1.18.6;
__FUNCTION__ -> __func__
 1.17  22-Nov-2007  bouyer branches: 1.17.2; 1.17.6;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.16  17-Oct-2007  garbled branches: 1.16.2;
Merge the ppcoea-renovation branch to HEAD.

This branch was a major cleanup and rototill of many of the various OEA
cpu based PPC ports that focused on sharing as much code as possible
between the various ports to eliminate near-identical copies of files in
every tree. Additionally there is a new PIC system that unifies the
interface to interrupt code for all different OEA ppc arches. The work
for this branch was done by a variety of people, too long to list here.

TODO:
bebox still needs work to complete the transition to -renovation.
ofppc still needs a bunch of work, which I will be looking at.
ev64260 still needs to be renovated
amigappc was not attempted.

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.
 1.15  09-Jul-2007  ad branches: 1.15.8; 1.15.10; 1.15.14;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.14  29-Sep-2006  christos branches: 1.14.8; 1.14.10; 1.14.16;
Coverity CID 3786: Fix memory leak (from Arnaud Lacombe)
 1.13  11-Aug-2006  yamt branches: 1.13.2; 1.13.4; 1.13.6;
"xm shutdown" support for xen3. ok'ed by Manuel Bouyer.
 1.12  25-Jun-2006  bouyer branches: 1.12.2;
Add a 'base' argument to xenbus_read_ul, so that we can read number is base
other than 10.
 1.11  23-May-2006  bouyer branches: 1.11.2; 1.11.4;
Add needed framework for backend drivers.
As we want some control on the name the backend driver will have we
can't use autoconf(9) here. Instead backend drivers registers to
xenbus, which will call a create callback when a new device is there.
Backend devices won't have a "struct device" in xenbus, use a void pointer
instead.
 1.10  07-May-2006  bouyer branches: 1.10.2;
Call xb_init_comms() once the event channel has been allocated for dom0.
 1.9  11-Apr-2006  bouyer branches: 1.9.2;
Centralize all xenbus /kern entries in xenbus_dev.c, and call
xenbus_kernfs_init() for domain0. Now /kern/xen/xenbus is also present
on domain0.
 1.8  09-Apr-2006  bouyer Move xenkernfs_init() back in hypervisor.c so that /kern/xen/privcmd can
also register properly.
 1.7  09-Apr-2006  bouyer start xenbus support for domain0: allocate the page and the event channel,
and export theses via /kern/xen/xsd_mfn and /kern/xen/xsd_port.
 1.6  09-Apr-2006  bouyer #if out read_frontend_details() for now, so that it compiles with DOM0OPS.
 1.5  26-Mar-2006  bouyer branches: 1.5.2;
Properly handle dynamic attach/detach of device:
- keep a linked list of xenbus_device in the xenbus_infrastructure, and
keep a pointer to struct device for each xenbus_device
- xenbus_probe_device_type(): check that the device is not already attached
- when we get a frontend_changed callback, call xenbus_probe_device_type()
- When a device changes to state XenbusStateClosed, config_detach() it
and free the structures.
While there, move xbusd_path[] to the end of struct xenbus_device, and
allocate only the space needed to store the path. Garbage-collect
struct xenbus_driver, it's not needed.
 1.4  25-Mar-2006  bouyer Initialize memory to 0 when allocating a new xenbus device structure.
Prevents trying to unregister a nonexistant node in talk_to_otherend().
 1.3  15-Mar-2006  bouyer branches: 1.3.2;
Implement watch of xenstore nodes, and install watches for otherend'state
node.
 1.2  06-Mar-2006  bouyer branches: 1.2.2; 1.2.4;
Adapt for NetBSD and add glue for config(9). Enough to get guest domain
virtual devices probed and attached, domain0 and xenstore watch needs to
be done.
 1.1  06-Mar-2006  bouyer branches: 1.1.1;
Initial revision
 1.1.1.1  06-Mar-2006  bouyer Import xenbus sources, from linux sparse tree in the 20060107 xen-3.0
snapshot.
 1.2.4.7  11-Aug-2006  yamt sync with head
 1.2.4.6  26-Jun-2006  yamt sync with head.
 1.2.4.5  24-May-2006  yamt sync with head.
 1.2.4.4  11-Apr-2006  yamt sync with head
 1.2.4.3  01-Apr-2006  yamt sync with head.
 1.2.4.2  13-Mar-2006  yamt sync with head.
 1.2.4.1  06-Mar-2006  yamt file xenbus_probe.c was added on branch yamt-pdpolicy on 2006-03-13 09:07:07 +0000
 1.2.2.2  11-May-2006  elad sync with head
 1.2.2.1  19-Apr-2006  elad sync with head - hopefully this will work
 1.3.2.2  24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.3.2.1  28-Mar-2006  tron Merge 2006-03-28 NetBSD-current into the "peter-altq" branch.
 1.5.2.3  08-Sep-2006  ghen Pull up following revision(s) (requested by jld in ticket #1499):
sys/arch/xen/conf/files.xen: revision 1.46
sys/arch/xen/xen/hypervisor.c: revision 1.26
sys/arch/xen/xen/shutdown_xenbus.c: revision 1.1
sys/arch/xen/xenbus/xenbus_probe.c: revision 1.13
sys/arch/xen/include/shutdown_xenbus.h: revision 1.1
"xm shutdown" support for xen3. ok'ed by Manuel Bouyer.
 1.5.2.2  07-Apr-2006  tron Apply patch (requested by bouyer in ticket #1245):
Pull up Xen3 domU support. This adds support for the Xen-3 memory bootstrap,
xenstore, and block and network device frontend. Xen-3 support is turned
on by 'options XEN3', which disable Xen-2 support.
Changes affecting non-xen3 specific code:
- xbd and xennet at hypervisor now attaches with xbd_hypervisor and
xennet_hypervisor
- x86_atomic_* renamed to xen_atomic_*
- use genassim.cf to pull in more constant from include files for assembly
- Map the shared info page from locore.S instead of the 0xffffffff hack
in xen_machdep.c
- remove some unused code
- some __asm__ __volatile__ -> __asm volatile and __inline__ -> inline
- more debug code
 1.5.2.1  26-Mar-2006  tron file xenbus_probe.c was added on branch netbsd-3 on 2006-04-07 12:51:26 +0000
 1.9.2.3  01-Jun-2006  kardel Sync with head.
 1.9.2.2  22-Apr-2006  simonb Sync with head.
 1.9.2.1  11-Apr-2006  simonb file xenbus_probe.c was added on branch simonb-timecounters on 2006-04-22 11:38:11 +0000
 1.10.2.1  19-Jun-2006  chap Sync with head.
 1.11.4.6  21-Jan-2008  yamt sync with head
 1.11.4.5  07-Dec-2007  yamt sync with head
 1.11.4.4  03-Sep-2007  yamt sync with head.
 1.11.4.3  30-Dec-2006  yamt sync with head.
 1.11.4.2  21-Jun-2006  yamt sync with head.
 1.11.4.1  23-May-2006  yamt file xenbus_probe.c was added on branch yamt-lazymbuf on 2006-06-21 14:58:24 +0000
 1.11.2.1  13-Jul-2006  gdamore Merge from HEAD.
 1.12.2.1  08-Sep-2006  rpaulo Pull up following revision(s) (requested by jld in ticket #129):
sys/arch/xen/conf/files.xen: revision 1.46
sys/arch/xen/xen/hypervisor.c: revision 1.26
sys/arch/xen/xen/shutdown_xenbus.c: revision 1.1
sys/arch/xen/xenbus/xenbus_probe.c: revision 1.13
sys/arch/xen/include/shutdown_xenbus.h: revision 1.1
"xm shutdown" support for xen3. ok'ed by Manuel Bouyer.
 1.13.6.1  22-Oct-2006  yamt sync with head
 1.13.4.2  09-Sep-2006  rpaulo sync with head
 1.13.4.1  11-Aug-2006  rpaulo file xenbus_probe.c was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:45:06 +0000
 1.13.2.1  18-Nov-2006  ad Sync with head.
 1.14.16.1  03-Oct-2007  garbled Sync with HEAD
 1.14.10.1  11-Jul-2007  mjf Sync with head.
 1.14.8.2  03-Dec-2007  ad Sync with HEAD.
 1.14.8.1  15-Jul-2007  ad Sync with head.
 1.15.14.1  17-Oct-2007  bouyer Prepare for xenamd64:
- kill xen/i386/identcpu.c, use i386/i386/identcpu.c instead (with a few
#ifndef XEN)
- move some files that can be shared between i386 and amd64 from
xen/i386 to xen/x86 (or to xen/xen for non-cpu-specific code)
- split assembly out of xen/include/hypervisor.h to xen/include/hypercalls.h
- use <xen/...> instead of <machine/...> for cpu-independant include files.

more work needed here, i386-specific files should got out of arch/xen to
arch/xeni386, and more code shared with arch/i386.
 1.15.10.2  09-Jan-2008  matt sync with HEAD
 1.15.10.1  06-Nov-2007  matt sync with HEAD
 1.15.8.1  27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.16.2.2  27-Dec-2007  mjf Sync with HEAD.
 1.16.2.1  08-Dec-2007  mjf Sync with HEAD.
 1.17.6.1  02-Jan-2008  bouyer Sync with HEAD
 1.17.2.1  26-Dec-2007  ad Sync with head.
 1.18.6.4  17-Jan-2009  mjf Sync with HEAD.
 1.18.6.3  28-Sep-2008  mjf Sync with HEAD.
 1.18.6.2  05-Jun-2008  mjf Sync with HEAD.

Also fix build.
 1.18.6.1  02-Jun-2008  mjf Sync with HEAD.
 1.20.6.2  18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.20.6.1  23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.20.4.2  11-Aug-2010  yamt sync with head.
 1.20.4.1  04-May-2009  yamt sync with head.
 1.20.2.1  04-Jun-2008  yamt sync with head
 1.21.4.2  13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.21.4.1  19-Oct-2008  haad Sync with HEAD.
 1.25.2.1  19-Jan-2009  skrll Sync with HEAD.
 1.26.2.5  12-Jun-2012  riz Pull up following revision(s) (requested by sborrill in ticket #1768):
sys/arch/xen/xenbus/xenbus_probe.c: revision 1.36
sys/arch/xen/xenbus/xenbus_probe.c: revision 1.37
Sort vif and vbd device IDs numerically so that attach order does not depend
on the order they are passed in through xenstore. While this works for
hand-crafted Xen configuration files, it does not work for XenServer, XCP or
EC2 instances. This means that adding an extra virtual disk can make the
domU unbootable.
ID is actually based on the Linux device major/minor so this approach isn't
entirely correct (for instance, you can specify devices to be non-contiguous
which doesn't fit too well with our autoconf approach), but it works as a
first approximation.
Tested by me on XenServer and riz@ on EC2. OK bouyer@
Fix problem where devices with ID 0 were skipped as invalid as it didn't
distinguish between numerical zero and invalid numeric string.
 1.26.2.4  23-Sep-2011  sborrill Pull up the following revisions(s) (requested by jym in ticket #1672):
sys/arch/xen/conf/files.xen: revision 1.123 via patch
sys/arch/xen/xen/hypervisor.c: revision 1.58 via patch
sys/arch/xen/xenbus/xenbus_dev.c: revision 1.9
sys/arch/xen/xenbus/xenbus_probe.c: revision 1.35

Expose Xen kernfs entries inside a domU to make it possible to use pkgsrc's
sysutils/xentools inside a domU to query XenStore entries (or even modify
part of it if the domain has enough rights).
 1.26.2.3  24-Apr-2011  riz Pull up following revision(s) (requested by cegger in ticket #1599):
sys/arch/xen/xenbus/xenbus_probe.c: revision 1.31
previous fix does not work if there is exactly only one entry where continue
exits the loop.
Apply fix from Konrad Wilke on port-xen@
That makes NetBSD DomU boot on Linux Dom0 with xl.
 1.26.2.2  24-Apr-2011  riz Pull up following revision(s) (requested by cegger in ticket #1598):
sys/arch/xen/xenbus/xenbus_probe.c: revision 1.30
Continue scanning for other frontends when initialization
of one frontend failed. Bug reported by Konrad Wilk on port-xen@.
Fix this for all error pathes within the loop.
 1.26.2.1  16-Jan-2009  snj Pull up following revision(s) (requested by jym in ticket #251):
sys/arch/xen/xenbus/xenbus_probe.c: revision 1.27
Do not probe for console when configuring xenbus devices, as it is
attached earlier during boot, when initializing hypervisor.
This avoids the "unknown type console at xenbus0 id 0 not configured"
autoconf(9) messages, which are misleading during domU's boot.
See also http://mail-index.netbsd.org/port-xen/2009/01/05/msg004621.html
Ok by bouyer@ in private mail.
 1.27.6.2  21-Apr-2011  rmind sync with head
 1.27.6.1  05-Mar-2011  rmind sync with head
 1.27.4.1  17-Aug-2010  uebayasi Sync with HEAD.
 1.27.2.9  27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.27.2.8  07-May-2011  jym KNF.
 1.27.2.7  02-May-2011  jym Sync with head.
 1.27.2.6  30-Mar-2011  jym Sync with my commits in HEAD.
 1.27.2.5  24-Oct-2010  jym Sync with HEAD
 1.27.2.4  01-Nov-2009  jym - Upgrade suspend/resume code to comply with Xen2 removal.
- Add support for PAE domUs suspend/resume.
- Fix an issue regarding initialization of the xbd ring I/O that could end
badly during resume, with invalid block operations submitted to dom0 backend.

NetBSD supports PAE under x86_32 by considering the L2 page as being
4 pages long instead of 1.

Xen validates the page types during resume. Sadly, the hypervisor handles
alternative recursive mappings (== PG/PD entries pointing to pages other
than self) inadequately, which could lead to incorrect page pinning.

As a result, the important change with this patch is to clear these alternative
mappings during suspend, and reset them back to their former self upon
resume. For PAE, approx. all 4 PDIR_SLOT_PTEs could be considered as
alternative recursive mappings.

See comments in pmap.c for further details.

Now, let the testing and bug hunting begin.
 1.27.2.3  01-Nov-2009  jym Sync with HEAD.
 1.27.2.2  31-May-2009  jym Modifications for the Xen suspend/migrate/resume branch:

- introduce xenbus_device_{suspend,resume}() functions. These are routines
used to suspend/resume MI parts of the Xenbus device interfaces, like updating
frontend/backend devices' paths found in XenStore.

- introduce HYPERVISOR_sysctl(), an hypercall used only by Xentools to obtain
information from hypervisor (listing VMs, printing console, etc.). I use it
to query xenconsole from ddb(), as a last resort in case of a panic() in
dom0 (xm being not available). Currently unused in the branch; could be, if
requested.

- disable the rwlock(9) used to protect code that could use transient MFNs.
It could trigger nasty context switches in place it should not to.

- fix some bugs in the xennet/xbd suspend/resume pmf(9) handlers.

- following XenSource's design, talk_to_otherend() is now called
watch_otherend(), and free_otherend_details() is used by Xenbus device
suspend/resume routines.

- some slight modifications in pmap regarding APDP. Introduce an inline
function (pmap_unmap_apdp_pde()) that clears APDP entry for the current pmap.

- similarly, implement pmap_unmap_all_apdp_pdes() that iterates through all
pmaps and tears down APDP, as Xen does not handle them properly.

TODO/XXX:

- pmap_unmap_apdp_pde() does not handle APDP shadow entry of PAE. It will,
once I figure out how PAE uses it.

- revisit the pmap locking issue regarding transient MFNs. As NetBSD does not
use kernel preemption and MP for Xen, this could be skipped momentarily. See
http://mail-index.netbsd.org/port-xen/2009/04/27/msg004903.html for details.

- fix a bug regarding grant tables which could technically DoS a dom0 if
ridiculously high consumer/producer indexes are passed down in the ring during
a resume.

All in all, once the grant table index issue and APDP PAE are fixed, next step
is to torture test this branch.

Tested under i386 PAE and non-PAE, Xen3 dom0 and domU. amd64 is only compile
tested.
 1.27.2.1  09-Feb-2009  jym Initial code for xen save/restore/migrate facilities.

- split the attach code of frontends in two half: one that is only needed
during autoconf(9) attach/detach phases, and one used at each save/restore
of device state (between suspend and resume).

Applies to hypervisor, xencons, xenbus, xbd, and xennet.

- add a rwlock(9) ("ptom_lock") to protect the different parts in the kernel
that manipulate MFNs (which could change between a suspend and a resume,
without the kernel noticing it). Parts that require MFNs acquire a reader lock,
while suspend code will acquire a writer lock to ensure that no-other parts
in kernel still use MFNs.

- integrate the suspend code with sysmon.

- various things in pmap(9), and clock.

TODO:
- factorize code a bit more inside frontends drivers.
- remove all alternative recursive (APDP_PDE) mappings found in PD/PT during
suspend, as Xen does not support them.
- abstract the ptom_lock locking, it is only required when kernel preemption
is enabled, or on MP systems.

Current code works mostly. You may experience difficulties in some corner
cases (dom0 warnings about xennet interface errors, and Xen tools failing to
validate NetBSD's alternative pmaps).
 1.28.2.1  06-Jun-2011  jruoho Sync with HEAD.
 1.35.8.1  12-Jun-2012  riz Pull up following revision(s) (requested by sborrill in ticket #313):
sys/arch/xen/xenbus/xenbus_probe.c: revision 1.36
sys/arch/xen/xenbus/xenbus_probe.c: revision 1.37
Sort vif and vbd device IDs numerically so that attach order does not depend
on the order they are passed in through xenstore. While this works for
hand-crafted Xen configuration files, it does not work for XenServer, XCP or
EC2 instances. This means that adding an extra virtual disk can make the
domU unbootable.
ID is actually based on the Linux device major/minor so this approach isn't
entirely correct (for instance, you can specify devices to be non-contiguous
which doesn't fit too well with our autoconf approach), but it works as a
first approximation.
Tested by me on XenServer and riz@ on EC2. OK bouyer@
Fix problem where devices with ID 0 were skipped as invalid as it didn't
distinguish between numerical zero and invalid numeric string.
 1.35.2.2  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.35.2.1  30-Oct-2012  yamt sync with head
 1.37.4.1  18-May-2014  rmind sync with head
 1.37.2.2  03-Dec-2017  jdolecek update from HEAD
 1.37.2.1  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.38.6.1  09-Jul-2016  skrll Sync with HEAD
 1.39.18.2  13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.39.18.1  10-Jun-2019  christos Sync with HEAD
 1.46.2.1  20-Apr-2020  bouyer Sync with HEAD
 1.55.4.3  23-Apr-2021  thorpej No need to be explicit about interface attributes here.
 1.55.4.2  02-Apr-2021  thorpej config_found_ia() -> config_found() w/ CFARG_IATTR.
 1.55.4.1  23-Mar-2021  thorpej Convert config_found_ia() call sites where the device only carries
a single interface attribute to bare config_found() calls.
 1.56.2.1  17-Jun-2021  thorpej Sync w/ HEAD.
 1.57.2.1  04-Aug-2021  thorpej Adapt to CFARGS().
 1.58.6.2  20-Feb-2025  martin Pull up following revision(s) (requested by sborrill in ticket #1050):

sys/arch/xen/xenbus/xenbus_probe.c: revision 1.61
sys/arch/xen/xenbus/xenbus_probe.c: revision 1.62

cdroms as xbd devices are skipped in PVHVM mode to avoid hangs if they
are not ready, i.e. do not contain an ISO image (that they hang is a bug
that should be fixed in itself). They are instead detected as an emulated
cdX which does deal with not being ready.

This leads to a regression in pure PV mode where xbd devices are hot-plugged
when an ISO is mounted and there are no emulated block devices such as cdX.

The xbd devices never appear and thus ISO images are not accessible.

Revert to pre-10 behaviour on pure PV kernels.

Ignore cdroms only for VM_GUEST_XENPVHVM guests, not for all !XENPV kernels
(we can also have PVH guests with !XENPV kernels)
 1.58.6.1  18-Oct-2023  martin Pull up following revision(s) (requested by bouyer in ticket #426):

sys/arch/xen/xenbus/xenbus_probe.c: revision 1.60

xenbus: if dom0 support is not compiled in, panic with a usefull message
instead of waiting for an event which will never happen
 1.60.6.1  02-Aug-2025  perseant Sync with HEAD

RSS XML Feed