Commit Graph

62 Commits

Author SHA1 Message Date
bouyer
bb4d9fb08c Make Xen kernels compile without DIAGNOSTIC 2014-09-21 12:46:15 +00:00
christos
e93b33c96c correct/add protection against snprintf overflow. 2014-03-27 18:22:56 +00:00
riz
6ec333eb37 Catch up to recent changes in config_pending_{incr,decr}(). 2013-10-13 06:55:34 +00:00
royger
f301a1b2e9 xen: prevent adding duplicate xenwatches
When a xenstore watch triggers, the event is processed on process_msg
and if a valid handle it's found the handler is queued for execution
on the pending xen watches queue (watch_events).

This may present a problem if we trigger a xenwatch several times and
then disconnect the device. If several xenwatch events are added to
the watch_events queue and the device is disconnected afterwards, the
first processed xenwatch event will disconnect the device, remove the
watch and free all resources. This triggers a panic if there are
pending xenwatch events for that device already queued in the local
queue of the function xenwatch_thread, since when the next watch that
has the same handler tries to execute we get a panic due to the fact
that the device is already disconnected and all resources had been
freed:

xenbus_watch: 0xffffa0000b7cd1d0
xbw_callback: 0xffffffff80755dd4
otherend_changed: backend/vif/1/0
backend/vif/1/0/state 6
backend/vif/1/0 -> Closed
backend/vif/1/0 -> backend_device, b_detach: 0xffffffff8075a2bf
xenbus_watch: 0xffffa0000b7cd1d0
xbw_callback: 0xfc5ec02183e547a8
fatal protection fault in supervisor mode
trap type 4 code 0 rip ffffffff80756596 cs e030 rflags 10246 cr2
7f7ff7b4c020 ilevel 0 rsp ffffa000e6d82c50
curlwp 0xffffa0000a72d580 pid 0 lid 36 lowest kstack
0xffffa000e6d7f000
kernel: protection fault trap, code=0
Stopped in pid 0.36 (system) at netbsd:xenwatch_thread+0xc7:    call
*10(%rax
)
xenwatch_thread() at netbsd:xenwatch_thread+0xc7
ds          f
es          5987
fs          2c40
gs          1460
rdi         ffffa0000b7cd1d0
rsi         ffffa0000a5477f0
rbp         ffffa000e6d82c70
rbx         ffffa0000b7c14c0
rdx         2
rcx         f
rax         ffffa0000b7cd1d0
r8          78
r9          ffffffef
r10         deadbeef
r11         1
r12         ffffa000e6d82c50
r13         ffffa0000a72d580
r14         ffffa0000a72d580
r15         0
rip         ffffffff80756596    xenwatch_thread+0xc7
cs          e030
rflags      10246
rsp         ffffa000e6d82c50
ss          e02b
netbsd:xenwatch_thread+0xc7:    call    *10(%rax)
2012-11-28 16:26:59 +00:00
sborrill
469cc9aebf Fix problem where devices with ID 0 were skipped as invalid as it didn't
distinguish between numerical zero and invalid numeric string.
2012-06-07 14:05:13 +00:00
sborrill
100e1d86bf 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@
2012-06-05 10:58:56 +00:00
jym
afeabb041e 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).
2011-09-22 23:02:34 +00:00
jym
eba16022d3 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.
2011-09-20 00:12:23 +00:00
matt
6ed2595d7e Change a cast to appease gcc4.5 2011-07-27 23:11:23 +00:00
joerg
3eb244d801 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.
2011-07-17 20:54:30 +00:00
jym
6d90e19e1d Remove all return error checks for event_set_handler(...). It either
succeeds or end in panic.
2011-07-02 19:07:56 +00:00
bouyer
1d34d759fe check that the list is empty before calling cv_wait(). Otherwise
we may sleep waiting for an event which is already in the queue.
2011-06-07 13:52:30 +00:00
rmind
5df9d86377 - Replace uses of simple_lock and ltsleep with mutex and condvar.
- Improve some parts of the code to be more MP-friendly.

Tested by jakllsch@.
2011-05-22 04:27:15 +00:00
jym
6b3956d6d5 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.
2011-04-18 01:36:24 +00:00
cegger
448664b81b 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.
2011-04-12 05:09:32 +00:00
cegger
ae26631de3 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.
2011-04-11 15:00:49 +00:00
jym
2f91f085df (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.
2011-03-30 22:34:03 +00:00
cherry
c971211b47 The Xen balloon driver enables growing and shrinking
PV domains on the fly, by collaborating with UVM and the hypervisor
2010-07-06 15:00:09 +00:00
cegger
18c8862fdc sprintf -> snprintf 2009-04-28 05:44:43 +00:00
cegger
962766853c ansify function definitions 2009-03-16 05:59:21 +00:00
jym
f0ba6e4c1b Replace x86 memory fences in Xen drivers by their Xen equivalents, to reduce
MD dependency:

x86_lfence() => xen_rmb()
x86_sfence() => xen_wmb()
x86_mfence() => xen_mb()

Discussed in
http://mail-index.netbsd.org/port-xen/2009/01/15/msg004655.html

Ok by bouyer@.
2009-01-16 20:16:47 +00:00
jym
ae69d2f013 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.
2009-01-09 22:26:25 +00:00
cegger
3449eda978 remove unused malloc.h 2008-12-18 12:18:20 +00:00
cegger
77abfb89c8 include <xen/xen.h> for xendomain_is_dom0() 2008-10-29 13:53:15 +00:00
jym
4f26afe701 - 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@).
2008-10-24 21:09:24 +00:00
jym
507459d7a0 - printf -> aprint_*
- fix and add comments
- make some panic/error messages more relevant
- remove last '\n' in DPRINTK() macros, not required as it is already part of format string.

No functional changes.
2008-10-24 18:02:58 +00:00
cegger
397d181874 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.
2008-10-21 21:55:44 +00:00
cegger
7395238cc5 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
2008-10-21 21:28:05 +00:00
cegger
2de31871b9 introduce two macros: xendomain_is_dom0() and xendomain_is_privileged(). Use them. 2008-10-21 15:46:32 +00:00
tron
0f256b9d59 Compile NetBSD/amd64 kernels with "-Wextra". Patches contributed by
Juan RP in PR port-amd64/39266.
2008-09-05 13:37:24 +00:00
cegger
5f767a47d6 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.
2008-06-02 20:54:59 +00:00
cegger
af33bdeef3 device_t / softc split
reviewed, tested and approved by bouyer
2008-04-16 18:41:48 +00:00
cegger
f5bd7c2196 use aprint_*_dev and device_xname 2008-04-06 07:23:57 +00:00
bouyer
9cde455f5c Add swedge support to xbd backed, and make the virtual block device handle
sizes larger than 4TB. Tested by Jukka Marin.
Should fix kern/37370.
2008-03-13 22:19:39 +00:00
bouyer
26315d042c Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
  pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
  the build will find them via the xen-ma/machine link.
2008-01-11 20:00:13 +00:00
perry
9b2b412c19 __FUNCTION__ -> __func__ 2007-12-15 00:39:14 +00:00
ad
065b6ba2fb lockmgr -> mutex 2007-12-06 17:00:31 +00:00
pooka
f9379f7719 a_l -> curlwp 2007-11-27 11:37:27 +00:00
bouyer
4e54134323 Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
2007-11-22 16:16:40 +00:00
garbled
d974db0ada 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.
2007-10-17 19:52:51 +00:00
dogcow
1367780514 Looks like this was part of a botched merge; apply he@'s patch to make
everything compile/link again.
2007-07-11 04:07:08 +00:00
ad
88ab7da936 Merge some of the less invasive changes from the vmlocking branch:
- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
2007-07-09 20:51:58 +00:00
dogcow
82e011bdfd unb0rk build. 2007-03-14 22:26:02 +00:00
christos
53524e44ef Kill caddr_t; there will be some MI fallout, but it will be fixed shortly. 2007-03-04 05:59:00 +00:00
christos
ca42d11f95 Coverity CID 3786: Fix memory leak (from Arnaud Lacombe) 2006-09-29 14:36:30 +00:00
yamt
467e0c9853 "xm shutdown" support for xen3. ok'ed by Manuel Bouyer. 2006-08-11 13:22:43 +00:00
bouyer
2613e19eec Add a 'base' argument to xenbus_read_ul, so that we can read number is base
other than 10.
2006-06-25 16:46:59 +00:00
bouyer
237137c875 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.
2006-05-23 21:07:56 +00:00
bouyer
3a0a2e12df Call xb_init_comms() once the event channel has been allocated for dom0. 2006-05-07 21:50:32 +00:00
bouyer
621b16009d Fix read for /kern/xen/xenbus: ignore offset. 2006-05-07 21:49:56 +00:00