Commit Graph

1120 Commits

Author SHA1 Message Date
bouyer
d010654c5e Redo previous the correct way: Xen expects a u_long * for vcpumask,
so use 2 uint32_t on LP64.
2012-08-21 09:06:02 +00:00
rmind
6ff25eebbe Fix Xen build. Make xcpumask uint32_t, fits 32 CPUs (can increase). 2012-08-21 01:17:46 +00:00
mlelstv
8ce4433821 Do not call setroot() from MD code and from MI code, which has
unwanted sideeffects in the RB_ASKNAME case. This fixes PR/46732.

No longer wrap MD cpu_rootconf(), as hp300 port stores reboot information
as a side effect. Instead call MI rootconf() from MD code which makes
rootconf() now a wrapper to setroot().

Adjust several MD routines to set the global booted_device,booted_partition
variables instead of passing partial information to setroot().

Make cpu_rootconf(9) describe the calling order.
2012-07-29 18:05:39 +00:00
matt
efbf8fe2cd Fix some -fno-common fallout. 2012-07-28 02:08:50 +00:00
jym
82b5b80a5d Add more ratechecks to avoid console spam when the backend gets a
stream of errors.

Remove the unused xbdi_errps (error per second) variable. Errors should
rather be tracked in absolute, with a threshold that forces a time penalty
to the xbdback thread when frontend goes nuts.
2012-07-23 01:31:01 +00:00
jym
ede9b84cdc Don't leak stack content when reading the Xen suspend value.
XXX pull-up to -6.
2012-07-22 19:30:19 +00:00
jym
6f78ccc10d Use setter to set xenguest_handles. 2012-06-30 23:36:20 +00:00
jym
4b5a093d68 Extend the xpmap API, as described in [1]. This change is mechanical and
avoids exposing the MD phys_to_machine/machine_to_phys tables directly.
Added:

- xpmap_ptom handles PFN (pseudo physical) to MFN (machine frame number)
translations, and is under control of the domain.
- xpmap_mtop is its counterpart (MFN to PFN), and is under control of
hypervisor.

xpmap_ptom_map()      map a pseudo-phys address to a machine address
xpmap_ptom_unmap()    unmap a pseudo-phys address (invalidation)
xpmap_ptom_isvalid()  check for pseudo-phys address validity

The parameters are physical/machine addresses, like bus_dma/bus_space(9).
As x86 MFNs are tracked by u_long (Xen's choice) while machine addresses
can be 64 bits entities (PAE), use ptoa() to avoid truncation when bit
shifting by PAGE_SHIFT.

I kept the same namespace (xpmap_) to avoid code churn.

[1] http://mail-index.netbsd.org/port-xen/2009/05/09/msg004951.html

XXX will document ptoa/atop/trunc_page separately.
2012-06-30 22:50:36 +00:00
jym
b6169c060b Retire XEN_COMPAT_030001 as detailed on port-xen@:
http://mail-index.netbsd.org/port-xen/2012/06/25/msg007431.html

The xen_p2m API comes next.

ok bouyer@.
Tested on i386 PAE and amd64 (Xen 3.3 on private test bed, and
Xen 3.4 for Amazon EC2).

FWIW, Amazon always reported:

hypervisor0 at mainbus0: Xen version 3.4.3-kaos_t1micro

multiple times for Europe and US West-1, so I guess they are now at
3.4 (32 and 64 bits).
2012-06-27 00:37:07 +00:00
jym
23a2531c0e Enable the map/unmap recursive mapping functions for all Xen ports for
save/restore.

For an unknown reason (to me) Xen refuses to update VM translations
when the entry is pointing back to itself (which is precisely
what our recursive VM model does). So enable the functions that take
care of this, which will avoid all sort of memory corruption upon restore
leading domU to trample upon itself.

Save/restore works again for amd64. The occasional domU frontend corruption is
still present, but is harmless to dom0. Now we have a working shell and
ddb inside domU, that helps debugging a tiny bit.

XXX pull-up to -6.
2012-06-24 18:31:52 +00:00
jym
39b8d4bd9a Update comment: we stopped using xcall to sync PTP between CPUs.
pmap_kpm_sync_xcall => xen_kpm_sync
2012-06-24 13:56:10 +00:00
mlelstv
5741661f64 Make detection of root on wedges (dk(4)) machine independent. Remove
MD code for x86, xen, sparc64.
2012-06-10 17:05:18 +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
rmind
e75fa0930a Few fixes for Xen:
- cpu_load_pmap: use atomic kcpuset(9) operations; fixes rare crashes.
- Add kcpuset_copybits(9) and replace xen_kcpuset2bits().  Avoids incorrect
  ncpu problem in early boot.  Also, micro-optimises xen_mcast_invlpg() and
  xen_mcast_tlbflush() routines.

Tested by chs@.
2012-06-06 22:22:41 +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
elric
7fd7d3916e Update xdb_xenbus.c to new usage of routines in dksubr.c. 2012-05-25 15:03:38 +00:00
cegger
b2cdc990ec destroy mutex and cv first.
Fixes LOCKDEBUG crash when a guest shut down.
2012-05-23 10:01:51 +00:00
jym
8cf41b7663 Merge i386 and amd64 version of db_memrw.c.
Use this opportunity to skip calculating the VA of the page. Let the CPU
deal with the invalidation itself through invlpg + destination address to
avoid converting between canonical/non canonical forms.
2012-05-07 17:45:28 +00:00
rmind
0c79472223 - Convert x86 MD code, mainly pmap(9) e.g. TLB shootdown code, to use
kcpuset(9) and thus replace hardcoded CPU bitmasks.  This removes the
  limitation of maximum CPUs.

- Support up to 256 CPUs on amd64 architecture by default.

Bug fixes, improvements, completion of Xen part and testing on 64-core
AMD Opteron(tm) Processor 6282 SE (also, as Xen HVM domU with 128 CPUs)
by Manuel Bouyer.
2012-04-20 22:23:24 +00:00
riz
2658d1ab38 Retrive and print the hypervisor "extra" (teeny) version.
From Manuel Bouyer.
2012-04-06 03:20:43 +00:00
jym
5b037abc92 Split the map/unmap code from the sync/flush code: move xpq_flush_queue()
calls after pmap_{,un}map_recursive_entries() so that pmap's handlers
handle the flush themselves.

Now pmap_{,un}map_recursive_entries() do what their names imply, nothing more.

Fix pmap_xen_suspend()'s comment: APDPs are now gone.

pmap's handlers are called deep during kernel save/restore. We already
are at IPL_VM + kpreemption disabled. No need to wrap the xpq_flush_queue()
with splvm/splx.
2012-03-11 17:14:30 +00:00
jym
9506b7bd53 Typo fix. 2012-03-11 16:16:44 +00:00
jakllsch
24400823a3 As per xpci_conf_read, use size argument in xpci_conf_write. 2012-03-05 16:53:59 +00:00
bouyer
dfde48d707 Add some more KASSERT() 2012-03-02 16:38:14 +00:00
bouyer
6132369235 MMUEXT_INVLPG_MULTI and MMUEXT_TLB_FLUSH_MULTI use a long as cpu mask,
not uint32_t, so  pass a pointer of the right type.
While there, cleanup includes and delete local, redundant define of PG_k.
2012-03-02 16:37:38 +00:00
bouyer
d50505c826 The code assumes that ci_index is also the Xen's cpunum, and that
cpunum is less than XEN_LEGACY_MAX_VCPUS. KASSERT both.
2012-02-25 18:57:50 +00:00
bouyer
d8304c6be9 Don't maintain ci_cpumask for physical CPUs, it's not used. 2012-02-24 11:43:06 +00:00
bouyer
b0388defd1 Get rid of phycpus_attached bitmask; it's maintained but not used and
will limit the number of physical CPUs to 32 without good reasons.
2012-02-24 11:31:23 +00:00
cherry
a9b15e0f47 (xen) - remove the (*xpq_cpu)() shim.We hasten the %fs/%gs setup process during boot.Although this is hacky, it lets us use the non-xen specificpmap_pte_xxx() functions in pmap code (and others). 2012-02-24 08:06:07 +00:00
bouyer
d13f34107d Fix locking; xengnt_get_entry() needs to have the lock held to avoid
allocating the same entry twice. xengnt_more_entries() also needs the lock
for the same reason.
2012-02-23 19:17:32 +00:00
bouyer
fa9d8fcc5b On Xen, there is variable-sized Xen data after the kernel's text+data+bss
(this include the physical->machine table).
(vaddr_t)(KERNBASE + NKL2_KIMG_ENTRIES * NBPD_L2) is after text+data+bss but,
on a domU with lots of RAM (more than 4GB) (so large
xpmap_phys_to_machine_mapping table) this can point to some of Xen's data
setup at bootstrap (either the xpmap_phys_to_machine_mapping table,
some page shared with the hypervisor, or our kernel page table). Using it for
early_zerop will cause of these pages to be unmapped after bootstrap.
This will cause a kernel page fault for the domU, either immediatly or
eventually much later, depending on where early_zerop points to.
To fix this, account for early_zerop when building the bootstrap pages,
and its VA from here.

May fix PR port-xen/38699
2012-02-23 18:59:21 +00:00
cherry
ad6a7fcd5d Cleanup.
- Remove cruft from native x86 origin.
 - Remove access to privileged MSRs.
 - Cleanup stale comments.
2012-02-23 07:30:30 +00:00
cherry
b82beb15c7 cpu_load_pmap() should not be used to load pmap_kernel(), since in the
x86 model, its mappings are shared across pmaps. KASSERT() for this
and remove unused codepaths.
2012-02-23 04:10:51 +00:00
bouyer
57679fba67 Allocating a fixed, limited number of buffers for receive and sending them
to the network stack is a bad idea, because if all receive buffers sits
in socket queues, the interface receive stalls by lack of buffers.
Instead, get receive pages from a pool_cache(9). Copying to a mbuf cluser
would work too, but testings shows this has an important performance hit.
This also simplifies locking.

While there, notify the dom0 when we add some receive buffers (older
linux dom0 didn't care, but newer one do).

Problem reported and fix tested by Brian Marcotte on port-xen
2012-02-22 18:54:51 +00:00
bouyer
94e365bdd2 use pmap_protect() instead of pmap_kenter_pa() to remap R/O an exiting
page. This gets rid of the last "mapping already present" warnings.
2012-02-22 18:29:31 +00:00
jakllsch
680da2b613 Only attempt to handle as much data as we can handle.
Per my testing, allows normal MAXPHYS on domU kernels.
2012-02-22 16:53:46 +00:00
jakllsch
70c8dc7b72 Define XBD_MAX_XFER instead of using (PAGE_SIZE * BLKIF_MAX_SEGMENTS_PER_REQUEST) directly. 2012-02-22 16:50:46 +00:00
bouyer
5dfe2dddcc Avoid early use of xen_kpm_sync(); locks are not available at this time.
Don't call cpu_init() twice.

Makes LOCKDEBUG kernels boot again
2012-02-21 19:10:13 +00:00
jakllsch
ee9ab39a12 Add and use xbdminphys() to handle transfer segmentation/size limit.
Should allow us to use a normal MAXPHYS in domU kernels.
2012-02-21 01:47:50 +00:00
bouyer
6a41d6825d - make xen_version globally available, with macros to access major and
minor xen version.
- In xen_initclocks(), do a VCPUOP_stop_periodic_timer only for Xen 3.1
  and later
Should fix PR port-xen/45961
2012-02-17 19:00:45 +00:00
bouyer
54fb8a3972 - make xen_version globally available, with macros to access major and
minor xen version.
- In xen_initclocks(), do a VCPUOP_stop_periodic_timer only for Xen 3.1
  and later
Should fix PR port-xen/45961
2012-02-17 18:42:19 +00:00
bouyer
d3ccea851c Apply patch proposed in PR port-xen/45975 (this does not solve the exact
problem reported here but is part of the solution):
xen_kpm_sync() is not working as expected,
leading to races between CPUs.
1 the check (xpq_cpu != &x86_curcpu) is always false because we
  have different x86_curcpu symbols with different addresses in the kernel.
  Fortunably, all addresses dissaemble to the same code.
  Because of this we always use the code intended for bootstrap, which doesn't
  use cross-calls or lock.

2 once 1 above is fixed, xen_kpm_sync() will use xcalls to sync other CPUs,
  which cause it to sleep and pmap.c doesn't like that. It triggers this
  KASSERT() in pmap_unmap_ptes():
  KASSERT(pmap->pm_ncsw == curlwp->l_ncsw);
3 pmap->pm_cpus is not safe for the purpose of xen_kpm_sync(), which
  needs to know on which CPU a pmap is loaded *now*:
  pmap->pm_cpus is cleared before cpu_load_pmap() is called to switch
  to a new pmap, leaving a window where a pmap is still in a CPU's
  ci_kpm_pdir but not in pm_cpus. As a virtual CPU may be preempted
  by the hypervisor at any time, it can be large enough to let another
  CPU free the PTP and reuse it as a normal page.

To fix 2), avoid cross-calls and IPIs completely, and instead
use a mutex to update all CPU's ci_kpm_pdir from the local CPU.
It's safe because we just need to update the table page, a tlbflush IPI will
happen later. As a side effect, we don't need a different code for bootstrap,
fixing 1). The mutex added to struct cpu needs a small headers reorganisation.

to fix 3), introduce a pm_xen_ptp_cpus which is updated from
cpu_pmap_load(), whith the ci_kpm_mtx mutex held. Checking it with
ci_kpm_mtx held will avoid overwriting the wrong pmap's ci_kpm_pdir.

While there I removed the unused pmap_is_active() function;
and added some more details to DIAGNOSTIC panics.
2012-02-17 18:40:18 +00:00
jym
b3430e5626 PAT flags are not under control of Xen domains currently, so there is no
point in enabling them.

Avoids:
- a warning logged by hypervisor when a domain attempts to modify the PAT
MSR.
- an error during domain resuming, where a PAT flag has been set on a page
while the hypervisor does not allow it.

ok releng@.
2012-02-13 23:54:58 +00:00
jym
ab7c6049a8 Xen clock management routines keep track of CPU (following MP merge).
Reflect this change in the suspend/resume routines so they can cope with
domU CPU suspend, instead of setting their cpu_info pointer to NULL.

Avoid copy/pasting by using the resume routines during attachement.

ok releng@.

No regression observed, and allows domU to suspend successfully again.
Restore is a different beast as PD/PT flags are marked "invalid" by Xen-4
hypervisor, and blocks resuming. Looking into it.
2012-02-12 14:38:18 +00:00
jym
03e761965c Xen MP merge introduced MP safety around ipl handlers. When removing an
event handler, check handler's function and arguments against the real
ones, not the ones from wrappers.

This fixes a bug where !mpsafe events could not be removed from the handler
chain, thereby blocking suspension of a domU.

ok releng@.
2012-02-12 14:24:08 +00:00
riz
6c09d8d673 Add a 'void' to unbreak this with -Wold-style-definition 2012-02-04 02:00:07 +00:00
para
1cf29b36a2 call uvm_km_kmem_alloc with right arguments
fixes: kern/45913
2012-02-02 20:11:26 +00:00
tls
7b0b7dedd9 Entropy-pool implementation move and cleanup.
1) Move core entropy-pool code and source/sink/sample management code
   to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
   source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
   avoid expensive operations on disabled entropy sources; make the
   rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
   have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
   system events, and skew between clocks, with a sample implementation
   for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files).  Tested with release
builds on amd64 and evbarm and live testing on amd64.
2012-02-02 19:42:57 +00:00
cherry
cbdea16d58 Update comments to remove references to alternate pte space. 2012-01-28 12:15:19 +00:00
cherry
6bed7d4e8c stop using alternate pde mapping in xen pmap 2012-01-28 07:19:17 +00:00