summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorRenato Botelho <renato@netgate.com>2016-03-14 07:56:21 -0300
committerRenato Botelho <renato@netgate.com>2016-03-14 07:56:21 -0300
commita26e4b3de35515ec3eaf2eb76b001a6a502bf56c (patch)
tree66dd86f3e16db9b45f07c989e95501b6456cf6a5 /sys
parent7d66bf7f17e48798ec04b7a6d99daff1820e28f8 (diff)
parenta64e8d254dc9ecd38594b71dcd7d53c6084c5abc (diff)
downloadFreeBSD-src-a26e4b3de35515ec3eaf2eb76b001a6a502bf56c.zip
FreeBSD-src-a26e4b3de35515ec3eaf2eb76b001a6a502bf56c.tar.gz
Merge remote-tracking branch 'origin/stable/10' into devel
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/filemon/filemon.c33
-rw-r--r--sys/dev/filemon/filemon_lock.c14
-rw-r--r--sys/dev/filemon/filemon_wrapper.c75
-rw-r--r--sys/dev/hwpmc/hwpmc_mod.c8
-rw-r--r--sys/kern/kern_proc.c19
-rw-r--r--sys/kern/link_elf.c24
-rw-r--r--sys/kern/link_elf_obj.c57
-rw-r--r--sys/kern/subr_turnstile.c9
8 files changed, 74 insertions, 165 deletions
diff --git a/sys/dev/filemon/filemon.c b/sys/dev/filemon/filemon.c
index 352f682..cd40c5a 100644
--- a/sys/dev/filemon/filemon.c
+++ b/sys/dev/filemon/filemon.c
@@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
#include <sys/file.h>
#include <sys/systm.h>
#include <sys/buf.h>
+#include <sys/capsicum.h>
#include <sys/condvar.h>
#include <sys/conf.h>
#include <sys/fcntl.h>
@@ -52,10 +53,6 @@ __FBSDID("$FreeBSD$");
#include <sys/sysproto.h>
#include <sys/uio.h>
-#if __FreeBSD_version >= 900041
-#include <sys/capsicum.h>
-#endif
-
#include "filemon.h"
#if defined(COMPAT_IA32) || defined(COMPAT_FREEBSD32) || defined(COMPAT_ARCH32)
@@ -71,8 +68,6 @@ extern struct sysentvec elf64_freebsd_sysvec;
static d_close_t filemon_close;
static d_ioctl_t filemon_ioctl;
static d_open_t filemon_open;
-static int filemon_unload(void);
-static void filemon_load(void *);
static struct cdevsw filemon_cdevsw = {
.d_version = D_VERSION,
@@ -130,7 +125,7 @@ filemon_dtr(void *data)
/* Follow same locking order as filemon_pid_check. */
filemon_lock_write();
- filemon_filemon_lock(filemon);
+ sx_xlock(&filemon->lock);
/* Remove from the in-use list. */
TAILQ_REMOVE(&filemons_inuse, filemon, link);
@@ -143,7 +138,7 @@ filemon_dtr(void *data)
TAILQ_INSERT_TAIL(&filemons_free, filemon, link);
/* Give up write access. */
- filemon_filemon_unlock(filemon);
+ sx_xunlock(&filemon->lock);
filemon_unlock_write();
if (fp != NULL)
@@ -158,25 +153,23 @@ filemon_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag __unused,
int error = 0;
struct filemon *filemon;
struct proc *p;
-#if __FreeBSD_version >= 900041
cap_rights_t rights;
-#endif
if ((error = devfs_get_cdevpriv((void **) &filemon)) != 0)
return (error);
- filemon_filemon_lock(filemon);
+ sx_xlock(&filemon->lock);
switch (cmd) {
/* Set the output file descriptor. */
case FILEMON_SET_FD:
- if (filemon->fp != NULL)
- fdrop(filemon->fp, td);
+ if (filemon->fp != NULL) {
+ error = EEXIST;
+ break;
+ }
error = fget_write(td, *(int *)data,
-#if __FreeBSD_version >= 900041
cap_rights_init(&rights, CAP_PWRITE),
-#endif
&filemon->fp);
if (error == 0)
/* Write the file header. */
@@ -198,7 +191,7 @@ filemon_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag __unused,
break;
}
- filemon_filemon_unlock(filemon);
+ sx_xunlock(&filemon->lock);
return (error);
}
@@ -308,6 +301,14 @@ filemon_modevent(module_t mod __unused, int type, void *data)
error = filemon_unload();
break;
+ case MOD_QUIESCE:
+ /*
+ * The wrapper implementation is unsafe for reliable unload.
+ * Require forcing an unload.
+ */
+ error = EBUSY;
+ break;
+
case MOD_SHUTDOWN:
break;
diff --git a/sys/dev/filemon/filemon_lock.c b/sys/dev/filemon/filemon_lock.c
index a0347000..5cac47c 100644
--- a/sys/dev/filemon/filemon_lock.c
+++ b/sys/dev/filemon/filemon_lock.c
@@ -29,20 +29,6 @@
__FBSDID("$FreeBSD$");
static __inline void
-filemon_filemon_lock(struct filemon *filemon)
-{
-
- sx_xlock(&filemon->lock);
-}
-
-static __inline void
-filemon_filemon_unlock(struct filemon *filemon)
-{
-
- sx_xunlock(&filemon->lock);
-}
-
-static __inline void
filemon_lock_read(void)
{
diff --git a/sys/dev/filemon/filemon_wrapper.c b/sys/dev/filemon/filemon_wrapper.c
index 40e09e3..ccadbce 100644
--- a/sys/dev/filemon/filemon_wrapper.c
+++ b/sys/dev/filemon/filemon_wrapper.c
@@ -36,27 +36,6 @@ __FBSDID("$FreeBSD$");
#include "opt_compat.h"
-#if __FreeBSD_version > 800032
-#define FILEMON_HAS_LINKAT
-#endif
-
-#if __FreeBSD_version < 900044 /* r225617 (2011-09-16) failed to bump
- __FreeBSD_version. This really should
- be based on "900045". "900044" is r225469
- (2011-09-10) so this code is broken for
- 9-CURRENT September 10th-16th. */
-#define sys_chdir chdir
-#define sys_link link
-#define sys_open open
-#define sys_rename rename
-#define sys_stat stat
-#define sys_symlink symlink
-#define sys_unlink unlink
-#ifdef FILEMON_HAS_LINKAT
-#define sys_linkat linkat
-#endif
-#endif /* __FreeBSD_version */
-
static eventhandler_tag filemon_exec_tag;
static eventhandler_tag filemon_exit_tag;
static eventhandler_tag filemon_fork_tag;
@@ -80,7 +59,8 @@ filemon_output(struct filemon *filemon, char *msg, size_t len)
auio.uio_td = curthread;
auio.uio_offset = (off_t) -1;
- bwillwrite();
+ if (filemon->fp->f_type == DTYPE_VNODE)
+ bwillwrite();
fo_write(filemon->fp, &auio, curthread->td_ucred, 0, curthread);
}
@@ -100,7 +80,7 @@ filemon_pid_check(struct proc *p)
TAILQ_FOREACH(filemon, &filemons_inuse, link) {
if (p == filemon->p) {
sx_sunlock(&proctree_lock);
- filemon_filemon_lock(filemon);
+ sx_xlock(&filemon->lock);
filemon_unlock_read();
return (filemon);
}
@@ -131,8 +111,7 @@ filemon_wrapper_chdir(struct thread *td, struct chdir_args *uap)
filemon_output(filemon, filemon->msgbufr, len);
- /* Unlock the found filemon structure. */
- filemon_filemon_unlock(filemon);
+ sx_xunlock(&filemon->lock);
}
}
@@ -160,8 +139,7 @@ filemon_event_process_exec(void *arg __unused, struct proc *p,
filemon_output(filemon, filemon->msgbufr, len);
- /* Unlock the found filemon structure. */
- filemon_filemon_unlock(filemon);
+ sx_xunlock(&filemon->lock);
free(freepath, M_TEMP);
}
@@ -199,8 +177,7 @@ filemon_wrapper_open(struct thread *td, struct open_args *uap)
curproc->p_pid, filemon->fname1);
filemon_output(filemon, filemon->msgbufr, len);
- /* Unlock the found filemon structure. */
- filemon_filemon_unlock(filemon);
+ sx_xunlock(&filemon->lock);
}
}
@@ -252,8 +229,7 @@ filemon_wrapper_openat(struct thread *td, struct openat_args *uap)
curproc->p_pid, filemon->fname2, filemon->fname1);
filemon_output(filemon, filemon->msgbufr, len);
- /* Unlock the found filemon structure. */
- filemon_filemon_unlock(filemon);
+ sx_xunlock(&filemon->lock);
}
}
@@ -281,8 +257,7 @@ filemon_wrapper_rename(struct thread *td, struct rename_args *uap)
filemon_output(filemon, filemon->msgbufr, len);
- /* Unlock the found filemon structure. */
- filemon_filemon_unlock(filemon);
+ sx_xunlock(&filemon->lock);
}
}
@@ -310,8 +285,7 @@ filemon_wrapper_link(struct thread *td, struct link_args *uap)
filemon_output(filemon, filemon->msgbufr, len);
- /* Unlock the found filemon structure. */
- filemon_filemon_unlock(filemon);
+ sx_xunlock(&filemon->lock);
}
}
@@ -339,15 +313,13 @@ filemon_wrapper_symlink(struct thread *td, struct symlink_args *uap)
filemon_output(filemon, filemon->msgbufr, len);
- /* Unlock the found filemon structure. */
- filemon_filemon_unlock(filemon);
+ sx_xunlock(&filemon->lock);
}
}
return (ret);
}
-#ifdef FILEMON_HAS_LINKAT
static int
filemon_wrapper_linkat(struct thread *td, struct linkat_args *uap)
{
@@ -369,14 +341,12 @@ filemon_wrapper_linkat(struct thread *td, struct linkat_args *uap)
filemon_output(filemon, filemon->msgbufr, len);
- /* Unlock the found filemon structure. */
- filemon_filemon_unlock(filemon);
+ sx_xunlock(&filemon->lock);
}
}
return (ret);
}
-#endif
static int
filemon_wrapper_stat(struct thread *td, struct stat_args *uap)
@@ -397,8 +367,7 @@ filemon_wrapper_stat(struct thread *td, struct stat_args *uap)
filemon_output(filemon, filemon->msgbufr, len);
- /* Unlock the found filemon structure. */
- filemon_filemon_unlock(filemon);
+ sx_xunlock(&filemon->lock);
}
}
@@ -426,8 +395,7 @@ filemon_wrapper_freebsd32_stat(struct thread *td,
filemon_output(filemon, filemon->msgbufr, len);
- /* Unlock the found filemon structure. */
- filemon_filemon_unlock(filemon);
+ sx_xunlock(&filemon->lock);
}
}
@@ -462,8 +430,7 @@ filemon_event_process_exit(void *arg __unused, struct proc *p)
filemon->p = NULL;
}
- /* Unlock the found filemon structure. */
- filemon_filemon_unlock(filemon);
+ sx_xunlock(&filemon->lock);
}
}
@@ -486,8 +453,7 @@ filemon_wrapper_unlink(struct thread *td, struct unlink_args *uap)
filemon_output(filemon, filemon->msgbufr, len);
- /* Unlock the found filemon structure. */
- filemon_filemon_unlock(filemon);
+ sx_xunlock(&filemon->lock);
}
}
@@ -508,8 +474,7 @@ filemon_event_process_fork(void *arg __unused, struct proc *p1,
filemon_output(filemon, filemon->msgbufr, len);
- /* Unlock the found filemon structure. */
- filemon_filemon_unlock(filemon);
+ sx_xunlock(&filemon->lock);
}
}
@@ -530,9 +495,7 @@ filemon_wrapper_install(void)
sv_table[SYS_unlink].sy_call = (sy_call_t *) filemon_wrapper_unlink;
sv_table[SYS_link].sy_call = (sy_call_t *) filemon_wrapper_link;
sv_table[SYS_symlink].sy_call = (sy_call_t *) filemon_wrapper_symlink;
-#ifdef FILEMON_HAS_LINKAT
sv_table[SYS_linkat].sy_call = (sy_call_t *) filemon_wrapper_linkat;
-#endif
#if defined(COMPAT_IA32) || defined(COMPAT_FREEBSD32) || defined(COMPAT_ARCH32)
sv_table = ia32_freebsd_sysvec.sv_table;
@@ -545,9 +508,7 @@ filemon_wrapper_install(void)
sv_table[FREEBSD32_SYS_unlink].sy_call = (sy_call_t *) filemon_wrapper_unlink;
sv_table[FREEBSD32_SYS_link].sy_call = (sy_call_t *) filemon_wrapper_link;
sv_table[FREEBSD32_SYS_symlink].sy_call = (sy_call_t *) filemon_wrapper_symlink;
-#ifdef FILEMON_HAS_LINKAT
sv_table[FREEBSD32_SYS_linkat].sy_call = (sy_call_t *) filemon_wrapper_linkat;
-#endif
#endif /* COMPAT_ARCH32 */
filemon_exec_tag = EVENTHANDLER_REGISTER(process_exec,
@@ -575,9 +536,7 @@ filemon_wrapper_deinstall(void)
sv_table[SYS_unlink].sy_call = (sy_call_t *)sys_unlink;
sv_table[SYS_link].sy_call = (sy_call_t *)sys_link;
sv_table[SYS_symlink].sy_call = (sy_call_t *)sys_symlink;
-#ifdef FILEMON_HAS_LINKAT
sv_table[SYS_linkat].sy_call = (sy_call_t *)sys_linkat;
-#endif
#if defined(COMPAT_IA32) || defined(COMPAT_FREEBSD32) || defined(COMPAT_ARCH32)
sv_table = ia32_freebsd_sysvec.sv_table;
@@ -590,9 +549,7 @@ filemon_wrapper_deinstall(void)
sv_table[FREEBSD32_SYS_unlink].sy_call = (sy_call_t *)sys_unlink;
sv_table[FREEBSD32_SYS_link].sy_call = (sy_call_t *)sys_link;
sv_table[FREEBSD32_SYS_symlink].sy_call = (sy_call_t *)sys_symlink;
-#ifdef FILEMON_HAS_LINKAT
sv_table[FREEBSD32_SYS_linkat].sy_call = (sy_call_t *)sys_linkat;
-#endif
#endif /* COMPAT_ARCH32 */
EVENTHANDLER_DEREGISTER(process_exec, filemon_exec_tag);
diff --git a/sys/dev/hwpmc/hwpmc_mod.c b/sys/dev/hwpmc/hwpmc_mod.c
index 46dd0c3..c8a8526 100644
--- a/sys/dev/hwpmc/hwpmc_mod.c
+++ b/sys/dev/hwpmc/hwpmc_mod.c
@@ -1014,14 +1014,14 @@ pmc_attach_one_process(struct proc *p, struct pmc *pm)
/* issue an attach event to a configured log file */
if (pm->pm_owner->po_flags & PMC_PO_OWNS_LOGFILE) {
- pmc_getfilename(p->p_textvp, &fullpath, &freepath);
if (p->p_flag & P_KTHREAD) {
fullpath = kernelname;
freepath = NULL;
- } else
+ } else {
+ pmc_getfilename(p->p_textvp, &fullpath, &freepath);
pmclog_process_pmcattach(pm, p->p_pid, fullpath);
- if (freepath)
- free(freepath, M_TEMP);
+ }
+ free(freepath, M_TEMP);
if (PMC_IS_SAMPLING_MODE(PMC_TO_MODE(pm)))
pmc_log_process_mappings(pm->pm_owner, p);
}
diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c
index cfaa354..e45fc99 100644
--- a/sys/kern/kern_proc.c
+++ b/sys/kern/kern_proc.c
@@ -2908,6 +2908,12 @@ static SYSCTL_NODE(_kern_proc, KERN_PROC_SIGTRAMP, sigtramp, CTLFLAG_RD |
int allproc_gen;
+/*
+ * stop_all_proc() purpose is to stop all process which have usermode,
+ * except current process for obvious reasons. This makes it somewhat
+ * unreliable when invoked from multithreaded process. The service
+ * must not be user-callable anyway.
+ */
void
stop_all_proc(void)
{
@@ -2916,17 +2922,6 @@ stop_all_proc(void)
bool restart, seen_stopped, seen_exiting, stopped_some;
cp = curproc;
- /*
- * stop_all_proc() assumes that all process which have
- * usermode must be stopped, except current process, for
- * obvious reasons. Since other threads in the process
- * establishing global stop could unstop something, disable
- * calls from multithreaded processes as precaution. The
- * service must not be user-callable anyway.
- */
- KASSERT((cp->p_flag & P_HADTHREADS) == 0 ||
- (cp->p_flag & P_KTHREAD) != 0, ("mt stop_all_proc"));
-
allproc_loop:
sx_xlock(&allproc_lock);
gen = allproc_gen;
@@ -3013,7 +3008,7 @@ resume_all_proc(void)
sx_xunlock(&allproc_lock);
}
-#define TOTAL_STOP_DEBUG 1
+/* #define TOTAL_STOP_DEBUG 1 */
#ifdef TOTAL_STOP_DEBUG
volatile static int ap_resume;
#include <sys/mount.h>
diff --git a/sys/kern/link_elf.c b/sys/kern/link_elf.c
index c2cceff..0293299 100644
--- a/sys/kern/link_elf.c
+++ b/sys/kern/link_elf.c
@@ -1027,10 +1027,8 @@ out:
vn_close(nd.ni_vp, FREAD, td->td_ucred, td);
if (error != 0 && lf != NULL)
linker_file_unload(lf, LINKER_UNLOAD_FORCE);
- if (shdr != NULL)
- free(shdr, M_LINKER);
- if (firstpage != NULL)
- free(firstpage, M_LINKER);
+ free(shdr, M_LINKER);
+ free(firstpage, M_LINKER);
return (error);
}
@@ -1092,19 +1090,13 @@ link_elf_unload_file(linker_file_t file)
+ (ef->object->size << PAGE_SHIFT));
}
#else
- if (ef->address != NULL)
- free(ef->address, M_LINKER);
+ free(ef->address, M_LINKER);
#endif
- if (ef->symbase != NULL)
- free(ef->symbase, M_LINKER);
- if (ef->strbase != NULL)
- free(ef->strbase, M_LINKER);
- if (ef->ctftab != NULL)
- free(ef->ctftab, M_LINKER);
- if (ef->ctfoff != NULL)
- free(ef->ctfoff, M_LINKER);
- if (ef->typoff != NULL)
- free(ef->typoff, M_LINKER);
+ free(ef->symbase, M_LINKER);
+ free(ef->strbase, M_LINKER);
+ free(ef->ctftab, M_LINKER);
+ free(ef->ctfoff, M_LINKER);
+ free(ef->typoff, M_LINKER);
}
static void
diff --git a/sys/kern/link_elf_obj.c b/sys/kern/link_elf_obj.c
index dc13283..0aa1326 100644
--- a/sys/kern/link_elf_obj.c
+++ b/sys/kern/link_elf_obj.c
@@ -896,8 +896,7 @@ out:
vn_close(nd.ni_vp, FREAD, td->td_ucred, td);
if (error && lf)
linker_file_unload(lf, LINKER_UNLOAD_FORCE);
- if (hdr)
- free(hdr, M_LINKER);
+ free(hdr, M_LINKER);
return error;
}
@@ -928,18 +927,12 @@ link_elf_unload_file(linker_file_t file)
}
}
if (ef->preloaded) {
- if (ef->reltab)
- free(ef->reltab, M_LINKER);
- if (ef->relatab)
- free(ef->relatab, M_LINKER);
- if (ef->progtab)
- free(ef->progtab, M_LINKER);
- if (ef->ctftab)
- free(ef->ctftab, M_LINKER);
- if (ef->ctfoff)
- free(ef->ctfoff, M_LINKER);
- if (ef->typoff)
- free(ef->typoff, M_LINKER);
+ free(ef->reltab, M_LINKER);
+ free(ef->relatab, M_LINKER);
+ free(ef->progtab, M_LINKER);
+ free(ef->ctftab, M_LINKER);
+ free(ef->ctfoff, M_LINKER);
+ free(ef->typoff, M_LINKER);
if (file->filename != NULL)
preload_delete_name(file->filename);
/* XXX reclaim module memory? */
@@ -947,37 +940,25 @@ link_elf_unload_file(linker_file_t file)
}
for (i = 0; i < ef->nreltab; i++)
- if (ef->reltab[i].rel)
- free(ef->reltab[i].rel, M_LINKER);
+ free(ef->reltab[i].rel, M_LINKER);
for (i = 0; i < ef->nrelatab; i++)
- if (ef->relatab[i].rela)
- free(ef->relatab[i].rela, M_LINKER);
- if (ef->reltab)
- free(ef->reltab, M_LINKER);
- if (ef->relatab)
- free(ef->relatab, M_LINKER);
- if (ef->progtab)
- free(ef->progtab, M_LINKER);
+ free(ef->relatab[i].rela, M_LINKER);
+ free(ef->reltab, M_LINKER);
+ free(ef->relatab, M_LINKER);
+ free(ef->progtab, M_LINKER);
if (ef->object) {
vm_map_remove(kernel_map, (vm_offset_t) ef->address,
(vm_offset_t) ef->address +
(ef->object->size << PAGE_SHIFT));
}
- if (ef->e_shdr)
- free(ef->e_shdr, M_LINKER);
- if (ef->ddbsymtab)
- free(ef->ddbsymtab, M_LINKER);
- if (ef->ddbstrtab)
- free(ef->ddbstrtab, M_LINKER);
- if (ef->shstrtab)
- free(ef->shstrtab, M_LINKER);
- if (ef->ctftab)
- free(ef->ctftab, M_LINKER);
- if (ef->ctfoff)
- free(ef->ctfoff, M_LINKER);
- if (ef->typoff)
- free(ef->typoff, M_LINKER);
+ free(ef->e_shdr, M_LINKER);
+ free(ef->ddbsymtab, M_LINKER);
+ free(ef->ddbstrtab, M_LINKER);
+ free(ef->shstrtab, M_LINKER);
+ free(ef->ctftab, M_LINKER);
+ free(ef->ctfoff, M_LINKER);
+ free(ef->typoff, M_LINKER);
}
static const char *
diff --git a/sys/kern/subr_turnstile.c b/sys/kern/subr_turnstile.c
index 221916c..20614aa 100644
--- a/sys/kern/subr_turnstile.c
+++ b/sys/kern/subr_turnstile.c
@@ -1027,8 +1027,7 @@ print_thread(struct thread *td, const char *prefix)
{
db_printf("%s%p (tid %d, pid %d, \"%s\")\n", prefix, td, td->td_tid,
- td->td_proc->p_pid, td->td_name[0] != '\0' ? td->td_name :
- td->td_name);
+ td->td_proc->p_pid, td->td_name);
}
static void
@@ -1110,8 +1109,7 @@ print_lockchain(struct thread *td, const char *prefix)
*/
while (!db_pager_quit) {
db_printf("%sthread %d (pid %d, %s) ", prefix, td->td_tid,
- td->td_proc->p_pid, td->td_name[0] != '\0' ? td->td_name :
- td->td_name);
+ td->td_proc->p_pid, td->td_name);
switch (td->td_state) {
case TDS_INACTIVE:
db_printf("is inactive\n");
@@ -1194,8 +1192,7 @@ print_sleepchain(struct thread *td, const char *prefix)
*/
while (!db_pager_quit) {
db_printf("%sthread %d (pid %d, %s) ", prefix, td->td_tid,
- td->td_proc->p_pid, td->td_name[0] != '\0' ? td->td_name :
- td->td_name);
+ td->td_proc->p_pid, td->td_name);
switch (td->td_state) {
case TDS_INACTIVE:
db_printf("is inactive\n");
OpenPOWER on IntegriCloud