This commit is contained in:
attilio 2012-06-23 14:15:13 +00:00
commit a22108a261
13 changed files with 324 additions and 323 deletions

View File

@ -1147,22 +1147,15 @@ camperiphdone(struct cam_periph *periph, union ccb *done_ccb)
union ccb *saved_ccb;
cam_status status;
struct scsi_start_stop_unit *scsi_cmd;
int error_code, sense_key, asc, ascq;
scsi_cmd = (struct scsi_start_stop_unit *)
&done_ccb->csio.cdb_io.cdb_bytes;
status = done_ccb->ccb_h.status;
if ((status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
if ((status & CAM_STATUS_MASK) == CAM_SCSI_STATUS_ERROR &&
(status & CAM_AUTOSNS_VALID)) {
struct scsi_sense_data *sense;
int error_code, sense_key, asc, ascq, sense_len;
sense = &done_ccb->csio.sense_data;
sense_len = done_ccb->csio.sense_len -
done_ccb->csio.sense_resid;
scsi_extract_sense_len(sense, sense_len, &error_code,
&sense_key, &asc, &ascq, /*show_errors*/ 1);
if (scsi_extract_sense_ccb(done_ccb,
&error_code, &sense_key, &asc, &ascq)) {
/*
* If the error is "invalid field in CDB",
* and the load/eject flag is set, turn the
@ -1421,12 +1414,8 @@ camperiphscsisenseerror(union ccb *ccb, union ccb **orig,
cgd.ccb_h.func_code = XPT_GDEV_TYPE;
xpt_action((union ccb *)&cgd);
if ((ccb->ccb_h.status & CAM_AUTOSNS_VALID) != 0)
err_action = scsi_error_action(&ccb->csio,
&cgd.inq_data,
sense_flags);
else
err_action = SS_RETRY|SSQ_DECREMENT_COUNT|EIO;
err_action = scsi_error_action(&ccb->csio, &cgd.inq_data,
sense_flags);
error = err_action & SS_ERRMASK;
/*

View File

@ -2834,11 +2834,10 @@ scsi_error_action(struct ccb_scsiio *csio, struct scsi_inquiry_data *inq_data,
int error_code, sense_key, asc, ascq;
scsi_sense_action action;
scsi_extract_sense_len(&csio->sense_data, csio->sense_len -
csio->sense_resid, &error_code,
&sense_key, &asc, &ascq, /*show_errors*/ 1);
if ((error_code == SSD_DEFERRED_ERROR)
if (!scsi_extract_sense_ccb((union ccb *)csio,
&error_code, &sense_key, &asc, &ascq)) {
action = SS_RETRY | SSQ_DECREMENT_COUNT | SSQ_PRINT_SENSE | EIO;
} else if ((error_code == SSD_DEFERRED_ERROR)
|| (error_code == SSD_DESC_DEFERRED_ERROR)) {
/*
* XXX dufault@FreeBSD.org
@ -4621,6 +4620,36 @@ scsi_extract_sense(struct scsi_sense_data *sense_data, int *error_code,
sense_key, asc, ascq, /*show_errors*/ 0);
}
/*
* Extract basic sense information from SCSI I/O CCB structure.
*/
int
scsi_extract_sense_ccb(union ccb *ccb,
int *error_code, int *sense_key, int *asc, int *ascq)
{
struct scsi_sense_data *sense_data;
/* Make sure there are some sense data we can access. */
if (ccb->ccb_h.func_code != XPT_SCSI_IO ||
(ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_SCSI_STATUS_ERROR ||
(ccb->csio.scsi_status != SCSI_STATUS_CHECK_COND) ||
(ccb->ccb_h.status & CAM_AUTOSNS_VALID) == 0 ||
(ccb->ccb_h.flags & CAM_SENSE_PHYS))
return (0);
if (ccb->ccb_h.flags & CAM_SENSE_PTR)
bcopy(&ccb->csio.sense_data, &sense_data,
sizeof(struct scsi_sense_data *));
else
sense_data = &ccb->csio.sense_data;
scsi_extract_sense_len(sense_data,
ccb->csio.sense_len - ccb->csio.sense_resid,
error_code, sense_key, asc, ascq, 1);
if (*error_code == -1)
return (0);
return (1);
}
/*
* Extract basic sense information. If show_errors is set, sense values
* will be set to -1 if they are not present.

View File

@ -2388,6 +2388,8 @@ int scsi_devid_match(uint8_t *rhs, size_t rhs_len,
void scsi_extract_sense(struct scsi_sense_data *sense, int *error_code,
int *sense_key, int *asc, int *ascq);
int scsi_extract_sense_ccb(union ccb *ccb, int *error_code, int *sense_key,
int *asc, int *ascq);
void scsi_extract_sense_len(struct scsi_sense_data *sense,
u_int sense_len, int *error_code, int *sense_key,
int *asc, int *ascq, int show_errors);

View File

@ -1676,7 +1676,6 @@ cddone(struct cam_periph *periph, union ccb *done_ccb)
return;
} else if (error != 0) {
struct scsi_sense_data *sense;
int asc, ascq;
int sense_key, error_code;
int have_sense;
@ -1699,20 +1698,12 @@ cddone(struct cam_periph *periph, union ccb *done_ccb)
cgd.ccb_h.func_code = XPT_GDEV_TYPE;
xpt_action((union ccb *)&cgd);
if (((csio->ccb_h.flags & CAM_SENSE_PHYS) != 0)
|| ((csio->ccb_h.flags & CAM_SENSE_PTR) != 0)
|| ((status & CAM_AUTOSNS_VALID) == 0))
have_sense = FALSE;
else
if (scsi_extract_sense_ccb(done_ccb,
&error_code, &sense_key, &asc, &ascq))
have_sense = TRUE;
else
have_sense = FALSE;
if (have_sense) {
sense = &csio->sense_data;
scsi_extract_sense_len(sense,
csio->sense_len - csio->sense_resid,
&error_code, &sense_key, &asc,
&ascq, /*show_errors*/ 1);
}
/*
* Attach to anything that claims to be a
* CDROM or WORM device, as long as it
@ -3138,7 +3129,7 @@ cderror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
{
struct cd_softc *softc;
struct cam_periph *periph;
int error;
int error, error_code, sense_key, asc, ascq;
periph = xpt_path_periph(ccb->ccb_h.path);
softc = (struct cd_softc *)periph->softc;
@ -3152,19 +3143,10 @@ cderror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
*/
if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INVALID) {
error = cd6byteworkaround(ccb);
} else if (((ccb->ccb_h.status & CAM_STATUS_MASK) ==
CAM_SCSI_STATUS_ERROR)
&& (ccb->ccb_h.status & CAM_AUTOSNS_VALID)
&& (ccb->csio.scsi_status == SCSI_STATUS_CHECK_COND)
&& ((ccb->ccb_h.flags & CAM_SENSE_PHYS) == 0)
&& ((ccb->ccb_h.flags & CAM_SENSE_PTR) == 0)) {
int sense_key, error_code, asc, ascq;
scsi_extract_sense_len(&ccb->csio.sense_data,
ccb->csio.sense_len - ccb->csio.sense_resid, &error_code,
&sense_key, &asc, &ascq, /*show_errors*/ 1);
} else if (scsi_extract_sense_ccb(ccb,
&error_code, &sense_key, &asc, &ascq)) {
if (sense_key == SSD_KEY_ILLEGAL_REQUEST)
error = cd6byteworkaround(ccb);
error = cd6byteworkaround(ccb);
}
if (error == ERESTART)

View File

@ -2254,7 +2254,6 @@ dadone(struct cam_periph *periph, union ccb *done_ccb)
*/
return;
} else if (error != 0) {
struct scsi_sense_data *sense;
int asc, ascq;
int sense_key, error_code;
int have_sense;
@ -2277,20 +2276,12 @@ dadone(struct cam_periph *periph, union ccb *done_ccb)
cgd.ccb_h.func_code = XPT_GDEV_TYPE;
xpt_action((union ccb *)&cgd);
if (((csio->ccb_h.flags & CAM_SENSE_PHYS) != 0)
|| ((csio->ccb_h.flags & CAM_SENSE_PTR) != 0)
|| ((status & CAM_AUTOSNS_VALID) == 0))
have_sense = FALSE;
else
if (scsi_extract_sense_ccb(done_ccb,
&error_code, &sense_key, &asc, &ascq))
have_sense = TRUE;
else
have_sense = FALSE;
if (have_sense) {
sense = &csio->sense_data;
scsi_extract_sense_len(sense,
csio->sense_len - csio->sense_resid,
&error_code, &sense_key, &asc,
&ascq, /*show_errors*/ 1);
}
/*
* If we tried READ CAPACITY(16) and failed,
* fallback to READ CAPACITY(10).
@ -2428,7 +2419,7 @@ daerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
{
struct da_softc *softc;
struct cam_periph *periph;
int error;
int error, error_code, sense_key, asc, ascq;
periph = xpt_path_periph(ccb->ccb_h.path);
softc = (struct da_softc *)periph->softc;
@ -2440,16 +2431,8 @@ daerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
error = 0;
if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INVALID) {
error = cmd6workaround(ccb);
} else if (((ccb->ccb_h.status & CAM_STATUS_MASK) ==
CAM_SCSI_STATUS_ERROR)
&& (ccb->ccb_h.status & CAM_AUTOSNS_VALID)
&& (ccb->csio.scsi_status == SCSI_STATUS_CHECK_COND)
&& ((ccb->ccb_h.flags & CAM_SENSE_PHYS) == 0)
&& ((ccb->ccb_h.flags & CAM_SENSE_PTR) == 0)) {
int sense_key, error_code, asc, ascq;
scsi_extract_sense(&ccb->csio.sense_data,
&error_code, &sense_key, &asc, &ascq);
} else if (scsi_extract_sense_ccb(ccb,
&error_code, &sense_key, &asc, &ascq)) {
if (sense_key == SSD_KEY_ILLEGAL_REQUEST)
error = cmd6workaround(ccb);
/*

View File

@ -2567,6 +2567,7 @@ kern/kern_rmlock.c standard
kern/kern_rwlock.c standard
kern/kern_sdt.c optional kdtrace_hooks
kern/kern_sema.c standard
kern/kern_sharedpage.c standard
kern/kern_shutdown.c standard
kern/kern_sig.c standard
kern/kern_switch.c standard

View File

@ -426,8 +426,10 @@ adb_kbd_receive_packet(device_t dev, u_char status,
/* 0x7f is always the power button */
if (data[0] == 0x7f && devctl_process_running()) {
devctl_notify("PMU", "Button", "pressed", NULL);
mtx_unlock(&sc->sc_mutex);
return (0);
} else if (data[0] == 0xff) {
mtx_unlock(&sc->sc_mutex);
return (0); /* Ignore power button release. */
}
if ((data[0] & 0x7f) == 57 && sc->buffers < 7) {

View File

@ -28,7 +28,6 @@
__FBSDID("$FreeBSD$");
#include "opt_capsicum.h"
#include "opt_compat.h"
#include "opt_hwpmc_hooks.h"
#include "opt_kdtrace.h"
#include "opt_ktrace.h"
@ -65,7 +64,6 @@ __FBSDID("$FreeBSD$");
#include <sys/sysent.h>
#include <sys/shm.h>
#include <sys/sysctl.h>
#include <sys/vdso.h>
#include <sys/vnode.h>
#include <sys/stat.h>
#ifdef KTRACE
@ -1513,204 +1511,3 @@ exec_unregister(execsw_arg)
execsw = newexecsw;
return (0);
}
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);
}
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);
}
static int
shared_page_alloc_locked(int size, int align)
{
int res;
res = roundup(shared_page_free, align);
if (res + size >= IDX_TO_OFF(shared_page_obj->size))
res = -1;
else
shared_page_free = res + size;
return (res);
}
int
shared_page_alloc(int size, int align)
{
int res;
sx_xlock(&shared_page_alloc_sx);
res = shared_page_alloc_locked(size, align);
sx_xunlock(&shared_page_alloc_sx);
return (res);
}
int
shared_page_fill(int size, int align, const void *data)
{
int res;
sx_xlock(&shared_page_alloc_sx);
res = shared_page_alloc_locked(size, align);
if (res != -1)
shared_page_write(res, size, data);
sx_xunlock(&shared_page_alloc_sx);
return (res);
}
static void
shared_page_init(void *dummy __unused)
{
vm_page_t m;
sx_init(&shared_page_alloc_sx, "shpsx");
shared_page_obj = vm_pager_allocate(OBJT_PHYS, 0, PAGE_SIZE,
VM_PROT_DEFAULT, 0, NULL);
VM_OBJECT_LOCK(shared_page_obj);
m = vm_page_grab(shared_page_obj, 0, VM_ALLOC_RETRY | VM_ALLOC_NOBUSY |
VM_ALLOC_ZERO);
m->valid = VM_PAGE_BITS_ALL;
VM_OBJECT_UNLOCK(shared_page_obj);
}
SYSINIT(shp, SI_SUB_EXEC, SI_ORDER_FIRST, (sysinit_cfunc_t)shared_page_init,
NULL);
static void
timehands_update(void *arg)
{
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));
idx = sv->sv_timekeep_curr;
atomic_store_rel_32(&tk->tk_th[idx].th_gen, 0);
if (++idx >= VDSO_TH_NUM)
idx = 0;
sv->sv_timekeep_curr = idx;
if (++sv->sv_timekeep_gen == 0)
sv->sv_timekeep_gen = 1;
th.th_gen = 0;
if (enabled)
tk->tk_th[idx] = th;
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)
{
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));
idx = sv->sv_timekeep_curr;
atomic_store_rel_32(&tk->tk_th[idx].th_gen, 0);
if (++idx >= VDSO_TH_NUM)
idx = 0;
sv->sv_timekeep_curr = idx;
if (++sv->sv_timekeep_gen == 0)
sv->sv_timekeep_gen = 1;
th.th_gen = 0;
if (enabled)
tk->tk_th[idx] = th;
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
void
exec_sysvec_init(void *param)
{
struct sysentvec *sv;
int tk_base;
uint32_t tk_ver;
sv = (struct sysentvec *)param;
if ((sv->sv_flags & SV_SHP) == 0)
return;
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);
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);
} 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);
#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);
}

240
sys/kern/kern_sharedpage.c Normal file
View File

@ -0,0 +1,240 @@
/*-
* Copyright (c) 2010, 2012 Konstantin Belousov <kib@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include "opt_compat.h"
#include "opt_vm.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/sysent.h>
#include <sys/sysctl.h>
#include <sys/vdso.h>
#include <vm/vm.h>
#include <vm/vm_param.h>
#include <vm/pmap.h>
#include <vm/vm_extern.h>
#include <vm/vm_kern.h>
#include <vm/vm_map.h>
#include <vm/vm_object.h>
#include <vm/vm_page.h>
#include <vm/vm_pager.h>
static struct sx shared_page_alloc_sx;
static vm_object_t shared_page_obj;
static int shared_page_free;
char *shared_page_mapping;
void
shared_page_write(int base, int size, const void *data)
{
bcopy(data, shared_page_mapping + base, size);
}
static int
shared_page_alloc_locked(int size, int align)
{
int res;
res = roundup(shared_page_free, align);
if (res + size >= IDX_TO_OFF(shared_page_obj->size))
res = -1;
else
shared_page_free = res + size;
return (res);
}
int
shared_page_alloc(int size, int align)
{
int res;
sx_xlock(&shared_page_alloc_sx);
res = shared_page_alloc_locked(size, align);
sx_xunlock(&shared_page_alloc_sx);
return (res);
}
int
shared_page_fill(int size, int align, const void *data)
{
int res;
sx_xlock(&shared_page_alloc_sx);
res = shared_page_alloc_locked(size, align);
if (res != -1)
shared_page_write(res, size, data);
sx_xunlock(&shared_page_alloc_sx);
return (res);
}
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,
VM_PROT_DEFAULT, 0, NULL);
VM_OBJECT_LOCK(shared_page_obj);
m = vm_page_grab(shared_page_obj, 0, VM_ALLOC_RETRY | VM_ALLOC_NOBUSY |
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(struct sysentvec *sv)
{
struct vdso_timehands th;
struct vdso_timekeep *tk;
uint32_t enabled, idx;
enabled = tc_fill_vdso_timehands(&th);
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)
idx = 0;
sv->sv_timekeep_curr = idx;
if (++sv->sv_timekeep_gen == 0)
sv->sv_timekeep_gen = 1;
th.th_gen = 0;
if (enabled)
tk->tk_th[idx] = th;
tk->tk_enabled = enabled;
atomic_store_rel_32(&tk->tk_th[idx].th_gen, sv->sv_timekeep_gen);
tk->tk_current = idx;
}
#ifdef COMPAT_FREEBSD32
static void
timehands_update32(struct sysentvec *sv)
{
struct vdso_timekeep32 *tk;
struct vdso_timehands32 th;
uint32_t enabled, idx;
enabled = tc_fill_vdso_timehands32(&th);
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)
idx = 0;
sv->sv_timekeep_curr = idx;
if (++sv->sv_timekeep_gen == 0)
sv->sv_timekeep_gen = 1;
th.th_gen = 0;
if (enabled)
tk->tk_th[idx] = th;
tk->tk_enabled = enabled;
atomic_store_rel_32(&tk->tk_th[idx].th_gen, sv->sv_timekeep_gen);
tk->tk_current = idx;
}
#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)
{
struct sysentvec *sv;
int tk_base;
uint32_t tk_ver;
sv = (struct sysentvec *)param;
if ((sv->sv_flags & SV_SHP) == 0)
return;
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"));
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"));
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;
timekeep_push_vdso();
}

View File

@ -31,7 +31,6 @@ __FBSDID("$FreeBSD$");
#include <sys/systm.h>
#include <sys/timeffc.h>
#include <sys/timepps.h>
#include <sys/taskqueue.h>
#include <sys/timetc.h>
#include <sys/timex.h>
#include <sys/vdso.h>
@ -121,12 +120,8 @@ SYSCTL_INT(_kern_timecounter, OID_AUTO, stepwarnings, CTLFLAG_RW,
&timestepwarnings, 0, "Log time steps");
static void tc_windup(void);
static void tc_windup_push_vdso(void *ctx, int pending);
static void cpu_tick_calibrate(int);
static struct task tc_windup_push_vdso_task = TASK_INITIALIZER(0,
tc_windup_push_vdso, 0);
static int
sysctl_kern_boottime(SYSCTL_HANDLER_ARGS)
{
@ -1367,7 +1362,7 @@ tc_windup(void)
#endif
timehands = th;
taskqueue_enqueue_fast(taskqueue_fast, &tc_windup_push_vdso_task);
timekeep_push_vdso();
}
/* Report or change the active timecounter hardware. */
@ -1394,7 +1389,7 @@ sysctl_kern_timecounter_hardware(SYSCTL_HANDLER_ARGS)
(void)newtc->tc_get_timecount(newtc);
timecounter = newtc;
EVENTHANDLER_INVOKE(tc_windup);
timekeep_push_vdso();
return (0);
}
return (EINVAL);
@ -1865,7 +1860,7 @@ sysctl_fast_gettime(SYSCTL_HANDLER_ARGS)
if (error != 0)
return (error);
vdso_th_enable = old_vdso_th_enable;
EVENTHANDLER_INVOKE(tc_windup);
timekeep_push_vdso();
return (0);
}
SYSCTL_PROC(_kern_timecounter, OID_AUTO, fast_gettime,
@ -1877,19 +1872,15 @@ tc_fill_vdso_timehands(struct vdso_timehands *vdso_th)
{
struct timehands *th;
uint32_t enabled;
int gen;
do {
th = timehands;
gen = th->th_generation;
vdso_th->th_algo = VDSO_TH_ALGO_1;
vdso_th->th_scale = th->th_scale;
vdso_th->th_offset_count = th->th_offset_count;
vdso_th->th_counter_mask = th->th_counter->tc_counter_mask;
vdso_th->th_offset = th->th_offset;
vdso_th->th_boottime = boottimebin;
enabled = cpu_fill_vdso_timehands(vdso_th);
} while (gen == 0 || timehands->th_generation != gen);
th = timehands;
vdso_th->th_algo = VDSO_TH_ALGO_1;
vdso_th->th_scale = th->th_scale;
vdso_th->th_offset_count = th->th_offset_count;
vdso_th->th_counter_mask = th->th_counter->tc_counter_mask;
vdso_th->th_offset = th->th_offset;
vdso_th->th_boottime = boottimebin;
enabled = cpu_fill_vdso_timehands(vdso_th);
if (!vdso_th_enable)
enabled = 0;
return (enabled);
@ -1901,30 +1892,19 @@ tc_fill_vdso_timehands32(struct vdso_timehands32 *vdso_th32)
{
struct timehands *th;
uint32_t enabled;
int gen;
do {
th = timehands;
gen = th->th_generation;
vdso_th32->th_algo = VDSO_TH_ALGO_1;
*(uint64_t *)&vdso_th32->th_scale[0] = th->th_scale;
vdso_th32->th_offset_count = th->th_offset_count;
vdso_th32->th_counter_mask = th->th_counter->tc_counter_mask;
vdso_th32->th_offset.sec = th->th_offset.sec;
*(uint64_t *)&vdso_th32->th_offset.frac[0] = th->th_offset.frac;
vdso_th32->th_boottime.sec = boottimebin.sec;
*(uint64_t *)&vdso_th32->th_boottime.frac[0] = boottimebin.frac;
enabled = cpu_fill_vdso_timehands32(vdso_th32);
} while (gen == 0 || timehands->th_generation != gen);
th = timehands;
vdso_th32->th_algo = VDSO_TH_ALGO_1;
*(uint64_t *)&vdso_th32->th_scale[0] = th->th_scale;
vdso_th32->th_offset_count = th->th_offset_count;
vdso_th32->th_counter_mask = th->th_counter->tc_counter_mask;
vdso_th32->th_offset.sec = th->th_offset.sec;
*(uint64_t *)&vdso_th32->th_offset.frac[0] = th->th_offset.frac;
vdso_th32->th_boottime.sec = boottimebin.sec;
*(uint64_t *)&vdso_th32->th_boottime.frac[0] = boottimebin.frac;
enabled = cpu_fill_vdso_timehands32(vdso_th32);
if (!vdso_th_enable)
enabled = 0;
return (enabled);
}
#endif
static void
tc_windup_push_vdso(void *ctx, int pending)
{
EVENTHANDLER_INVOKE(tc_windup);
}

View File

@ -568,7 +568,8 @@ ipfw_lookup_table_extended(struct ip_fw_chain *ch, uint16_t tbl, void *paddr,
break;
case IPFW_TABLE_INTERFACE:
KEY_LEN(iface) = strlcpy(iface.ifname, (char *)paddr, IF_NAMESIZE);
KEY_LEN(iface) = KEY_LEN_IFACE +
strlcpy(iface.ifname, (char *)paddr, IF_NAMESIZE);
/* Assume direct match */
/* FIXME: Add interface pattern matching */
xent = (struct table_xentry *)(rnh->rnh_lookup(&iface, NULL, rnh));

View File

@ -260,13 +260,10 @@ int lkmressys(struct thread *, struct nosys_args *);
int syscall_thread_enter(struct thread *td, struct sysent *se);
void syscall_thread_exit(struct thread *td, struct sysent *se);
struct sf_buf;
int shared_page_alloc(int size, int align);
int shared_page_fill(int size, int align, const void *data);
void shared_page_write(int base, int size, const void *data);
void exec_sysvec_init(void *param);
struct sf_buf *shared_page_write_start(int base);
void shared_page_write_end(struct sf_buf *sf);
#define INIT_SYSENTVEC(name, sv) \
SYSINIT(name, SI_SUB_EXEC, SI_ORDER_ANY, \

View File

@ -29,7 +29,6 @@
#define _SYS_VDSO_H
#include <sys/types.h>
#include <sys/eventhandler.h>
#include <machine/vdso.h>
struct vdso_timehands {
@ -74,6 +73,8 @@ u_int __vdso_gettc(const struct vdso_timehands *vdso_th);
#ifdef _KERNEL
void timekeep_push_vdso(void);
uint32_t tc_fill_vdso_timehands(struct vdso_timehands *vdso_th);
/*
@ -86,9 +87,6 @@ uint32_t tc_fill_vdso_timehands(struct vdso_timehands *vdso_th);
*/
uint32_t cpu_fill_vdso_timehands(struct vdso_timehands *vdso_th);
typedef void (*tc_windup_fn)(void *);
EVENTHANDLER_DECLARE(tc_windup, tc_windup_fn);
#define VDSO_TH_NUM 4
#ifdef COMPAT_FREEBSD32