summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_exec.c
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2012-06-23 09:33:06 +0000
committerkib <kib@FreeBSD.org>2012-06-23 09:33:06 +0000
commit497817697cfb819824b7ae8619a5094ace1b3698 (patch)
treee776dfcefe80b16e0aa0a27d0fdb364391c6c4b8 /sys/kern/kern_exec.c
parente19c8fe0ffaebe2cb325b0d14102166d51b7429d (diff)
downloadFreeBSD-src-497817697cfb819824b7ae8619a5094ace1b3698.zip
FreeBSD-src-497817697cfb819824b7ae8619a5094ace1b3698.tar.gz
Stop updating the struct vdso_timehands from even handler executed in
the scheduled task from tc_windup(). Do it directly from tc_windup in interrupt context [1]. Establish the permanent mapping of the shared page into the kernel address space, avoiding the potential need to sleep waiting for allocation of sf buffer during vdso_timehands update. As a consequence, shared_page_write_start() and shared_page_write_end() functions are not needed anymore. Guess and memorize the pointers to native host and compat32 sysentvec during initialization, to avoid the need to get shared_page_alloc_sx lock during the update. In tc_fill_vdso_timehands(), do not loop waiting for timehands generation to stabilize, since vdso_timehands is written in the same interrupt context which wrote timehands. Requested by: mav [1] MFC after: 29 days
Diffstat (limited to 'sys/kern/kern_exec.c')
-rw-r--r--sys/kern/kern_exec.c97
1 files changed, 43 insertions, 54 deletions
diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c
index 80502e3..9365223 100644
--- a/sys/kern/kern_exec.c
+++ b/sys/kern/kern_exec.c
@@ -1517,42 +1517,13 @@ exec_unregister(execsw_arg)
static struct sx shared_page_alloc_sx;
static vm_object_t shared_page_obj;
static int shared_page_free;
-
-struct sf_buf *
-shared_page_write_start(int base)
-{
- vm_page_t m;
- struct sf_buf *s;
-
- VM_OBJECT_LOCK(shared_page_obj);
- m = vm_page_grab(shared_page_obj, OFF_TO_IDX(base), VM_ALLOC_RETRY);
- VM_OBJECT_UNLOCK(shared_page_obj);
- s = sf_buf_alloc(m, SFB_DEFAULT);
- return (s);
-}
-
-void
-shared_page_write_end(struct sf_buf *sf)
-{
- vm_page_t m;
-
- m = sf_buf_page(sf);
- sf_buf_free(sf);
- VM_OBJECT_LOCK(shared_page_obj);
- vm_page_wakeup(m);
- VM_OBJECT_UNLOCK(shared_page_obj);
-}
+char *shared_page_mapping;
void
shared_page_write(int base, int size, const void *data)
{
- struct sf_buf *sf;
- vm_offset_t sk;
- sf = shared_page_write_start(base);
- sk = sf_buf_kva(sf);
- bcopy(data, (void *)(sk + (base & PAGE_MASK)), size);
- shared_page_write_end(sf);
+ bcopy(data, shared_page_mapping + base, size);
}
static int
@@ -1596,6 +1567,7 @@ static void
shared_page_init(void *dummy __unused)
{
vm_page_t m;
+ vm_offset_t addr;
sx_init(&shared_page_alloc_sx, "shpsx");
shared_page_obj = vm_pager_allocate(OBJT_PHYS, 0, PAGE_SIZE,
@@ -1605,25 +1577,24 @@ shared_page_init(void *dummy __unused)
VM_ALLOC_ZERO);
m->valid = VM_PAGE_BITS_ALL;
VM_OBJECT_UNLOCK(shared_page_obj);
+ addr = kmem_alloc_nofault(kernel_map, PAGE_SIZE);
+ pmap_qenter(addr, &m, 1);
+ shared_page_mapping = (char *)addr;
}
SYSINIT(shp, SI_SUB_EXEC, SI_ORDER_FIRST, (sysinit_cfunc_t)shared_page_init,
NULL);
static void
-timehands_update(void *arg)
+timehands_update(struct sysentvec *sv)
{
- struct sysentvec *sv;
- struct sf_buf *sf;
struct vdso_timehands th;
struct vdso_timekeep *tk;
uint32_t enabled, idx;
- sv = arg;
- sx_xlock(&shared_page_alloc_sx);
enabled = tc_fill_vdso_timehands(&th);
- sf = shared_page_write_start(sv->sv_timekeep_off);
- tk = (void *)(sf_buf_kva(sf) + (sv->sv_timekeep_off & PAGE_MASK));
+ tk = (struct vdso_timekeep *)(shared_page_mapping +
+ sv->sv_timekeep_off);
idx = sv->sv_timekeep_curr;
atomic_store_rel_32(&tk->tk_th[idx].th_gen, 0);
if (++idx >= VDSO_TH_NUM)
@@ -1637,25 +1608,19 @@ timehands_update(void *arg)
tk->tk_enabled = enabled;
atomic_store_rel_32(&tk->tk_th[idx].th_gen, sv->sv_timekeep_gen);
tk->tk_current = idx;
- shared_page_write_end(sf);
- sx_xunlock(&shared_page_alloc_sx);
}
#ifdef COMPAT_FREEBSD32
static void
-timehands_update32(void *arg)
+timehands_update32(struct sysentvec *sv)
{
- struct sysentvec *sv;
- struct sf_buf *sf;
struct vdso_timekeep32 *tk;
struct vdso_timehands32 th;
uint32_t enabled, idx;
- sv = arg;
- sx_xlock(&shared_page_alloc_sx);
enabled = tc_fill_vdso_timehands32(&th);
- sf = shared_page_write_start(sv->sv_timekeep_off);
- tk = (void *)(sf_buf_kva(sf) + (sv->sv_timekeep_off & PAGE_MASK));
+ tk = (struct vdso_timekeep32 *)(shared_page_mapping +
+ sv->sv_timekeep_off);
idx = sv->sv_timekeep_curr;
atomic_store_rel_32(&tk->tk_th[idx].th_gen, 0);
if (++idx >= VDSO_TH_NUM)
@@ -1669,11 +1634,32 @@ timehands_update32(void *arg)
tk->tk_enabled = enabled;
atomic_store_rel_32(&tk->tk_th[idx].th_gen, sv->sv_timekeep_gen);
tk->tk_current = idx;
- shared_page_write_end(sf);
- sx_xunlock(&shared_page_alloc_sx);
}
#endif
+/*
+ * This is hackish, but easiest way to avoid creating list structures
+ * that needs to be iterated over from the hardclock interrupt
+ * context.
+ */
+static struct sysentvec *host_sysentvec;
+#ifdef COMPAT_FREEBSD32
+static struct sysentvec *compat32_sysentvec;
+#endif
+
+void
+timekeep_push_vdso(void)
+{
+
+ if (host_sysentvec != NULL && host_sysentvec->sv_timekeep_base != 0)
+ timehands_update(host_sysentvec);
+#ifdef COMPAT_FREEBSD32
+ if (compat32_sysentvec != NULL &&
+ compat32_sysentvec->sv_timekeep_base != 0)
+ timehands_update32(compat32_sysentvec);
+#endif
+}
+
void
exec_sysvec_init(void *param)
{
@@ -1688,29 +1674,32 @@ exec_sysvec_init(void *param)
sv->sv_shared_page_obj = shared_page_obj;
sv->sv_sigcode_base = sv->sv_shared_page_base +
shared_page_fill(*(sv->sv_szsigcode), 16, sv->sv_sigcode);
+ if ((sv->sv_flags & SV_ABI_MASK) != SV_ABI_FREEBSD)
+ return;
tk_ver = VDSO_TK_VER_CURR;
#ifdef COMPAT_FREEBSD32
if ((sv->sv_flags & SV_ILP32) != 0) {
tk_base = shared_page_alloc(sizeof(struct vdso_timekeep32) +
sizeof(struct vdso_timehands32) * VDSO_TH_NUM, 16);
KASSERT(tk_base != -1, ("tk_base -1 for 32bit"));
- EVENTHANDLER_REGISTER(tc_windup, timehands_update32, sv,
- EVENTHANDLER_PRI_ANY);
shared_page_write(tk_base + offsetof(struct vdso_timekeep32,
tk_ver), sizeof(uint32_t), &tk_ver);
+ KASSERT(compat32_sysentvec == 0,
+ ("Native compat32 already registered"));
+ compat32_sysentvec = sv;
} else {
#endif
tk_base = shared_page_alloc(sizeof(struct vdso_timekeep) +
sizeof(struct vdso_timehands) * VDSO_TH_NUM, 16);
KASSERT(tk_base != -1, ("tk_base -1 for native"));
- EVENTHANDLER_REGISTER(tc_windup, timehands_update, sv,
- EVENTHANDLER_PRI_ANY);
shared_page_write(tk_base + offsetof(struct vdso_timekeep,
tk_ver), sizeof(uint32_t), &tk_ver);
+ KASSERT(host_sysentvec == 0, ("Native already registered"));
+ host_sysentvec = sv;
#ifdef COMPAT_FREEBSD32
}
#endif
sv->sv_timekeep_base = sv->sv_shared_page_base + tk_base;
sv->sv_timekeep_off = tk_base;
- EVENTHANDLER_INVOKE(tc_windup);
+ timekeep_push_vdso();
}
OpenPOWER on IntegriCloud