Skip to content

Commit

Permalink
Merge branch 'freebsd/current/master' into hardened/current/master
Browse files Browse the repository at this point in the history
* freebsd/current/master:
  exit: get rid of PROC_SLOCK when checking a process to report, take #2
  Give the imx_i2c driver its own name, set up its relationship to ofw_iicbus. Previously it called itself 'iichb' to link up with the EARLY_DRIVER_MODULE declaration in ofw_iicbus.c.
  Fix broken assertion in r329520.
  Allow i2c hardware drivers to declare their own relationships to ofw_iicbus rather than relying on a set of canned EARLY_DRIVER_MODULE() statements in the ofw_iicbus source.  This means hw drivers will no longer be required to use one of a few predefined driver names.  They will also now be able to decide themselves if they want to use DRIVER_MODULE or EARLY_DRIVER_MODULE and to set which pass to attach on for early modules.
  Correct/improve the descriptions if kern.ipc.(shmsegs,sema,msqids).
  Optimise xchg() to use atomic_swap_32() and atomic_swap_64().
  Fix implementation of xchg() function macro in the LinuxKPI. The exchange operation must be atomic.
  • Loading branch information
opntr-auto committed Feb 18, 2018
2 parents ffc2c58 + 7669ad8 commit 00f69db
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 35 deletions.
6 changes: 3 additions & 3 deletions sys/arm/freescale/imx/imx_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,14 @@ static device_method_t i2c_methods[] = {
};

static driver_t i2c_driver = {
"iichb",
"imx_i2c",
i2c_methods,
sizeof(struct i2c_softc),
};
static devclass_t i2c_devclass;

DRIVER_MODULE(i2c, simplebus, i2c_driver, i2c_devclass, 0, 0);
DRIVER_MODULE(iicbus, i2c, iicbus_driver, iicbus_devclass, 0, 0);
DRIVER_MODULE(imx_i2c, simplebus, i2c_driver, i2c_devclass, 0, 0);
DRIVER_MODULE(ofw_iicbus, imx_i2c, ofw_iicbus_driver, ofw_iicbus_devclass, 0, 0);

static phandle_t
i2c_get_node(device_t bus, device_t dev)
Expand Down
41 changes: 35 additions & 6 deletions sys/compat/linuxkpi/common/include/asm/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,41 @@ atomic_cmpxchg(atomic_t *v, int old, int new)

#define cmpxchg_relaxed(...) cmpxchg(__VA_ARGS__)

#define xchg(ptr, v) ({ \
__typeof(*(ptr)) __ret; \
\
__ret = *(ptr); \
*(ptr) = v; \
__ret; \
#define xchg(ptr, new) ({ \
union { \
__typeof(*(ptr)) val; \
u8 u8[0]; \
u16 u16[0]; \
u32 u32[0]; \
u64 u64[0]; \
} __ret, __new = { .val = (new) }; \
\
CTASSERT(sizeof(__ret.val) == 1 || sizeof(__ret.val) == 2 || \
sizeof(__ret.val) == 4 || sizeof(__ret.val) == 8); \
\
switch (sizeof(__ret.val)) { \
case 1: \
__ret.val = READ_ONCE(*ptr); \
while (!atomic_fcmpset_8((volatile u8 *)(ptr), \
__ret.u8, __new.u8[0])) \
; \
break; \
case 2: \
__ret.val = READ_ONCE(*ptr); \
while (!atomic_fcmpset_16((volatile u16 *)(ptr), \
__ret.u16, __new.u16[0])) \
; \
break; \
case 4: \
__ret.u32[0] = atomic_swap_32((volatile u32 *)(ptr), \
__new.u32[0]); \
break; \
case 8: \
__ret.u64[0] = atomic_swap_64((volatile u64 *)(ptr), \
__new.u64[0]); \
break; \
} \
__ret.val; \
})

#define LINUX_ATOMIC_OP(op, c_op) \
Expand Down
2 changes: 2 additions & 0 deletions sys/dev/iicbus/iicbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,7 @@ void iicbus_init_frequency(device_t dev, u_int bus_freq);

extern driver_t iicbus_driver;
extern devclass_t iicbus_devclass;
extern driver_t ofw_iicbus_driver;
extern devclass_t ofw_iicbus_devclass;

#endif
8 changes: 4 additions & 4 deletions sys/dev/iicbus/ofw_iicbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ struct ofw_iicbus_devinfo {
struct ofw_bus_devinfo opd_obdinfo;
};

devclass_t ofwiicbus_devclass;
devclass_t ofw_iicbus_devclass;

DEFINE_CLASS_1(iicbus, ofw_iicbus_driver, ofw_iicbus_methods,
sizeof(struct iicbus_softc), iicbus_driver);
EARLY_DRIVER_MODULE(ofw_iicbus, iicbb, ofw_iicbus_driver, ofwiicbus_devclass,
EARLY_DRIVER_MODULE(ofw_iicbus, iicbb, ofw_iicbus_driver, ofw_iicbus_devclass,
0, 0, BUS_PASS_BUS);
EARLY_DRIVER_MODULE(ofw_iicbus, iichb, ofw_iicbus_driver, ofwiicbus_devclass,
EARLY_DRIVER_MODULE(ofw_iicbus, iichb, ofw_iicbus_driver, ofw_iicbus_devclass,
0, 0, BUS_PASS_BUS);
EARLY_DRIVER_MODULE(ofw_iicbus, twsi, ofw_iicbus_driver, ofwiicbus_devclass,
EARLY_DRIVER_MODULE(ofw_iicbus, twsi, ofw_iicbus_driver, ofw_iicbus_devclass,
0, 0, BUS_PASS_BUS);
MODULE_VERSION(ofw_iicbus, 1);
MODULE_DEPEND(ofw_iicbus, iicbus, 1, 1, 1);
Expand Down
39 changes: 21 additions & 18 deletions sys/kern/kern_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,7 @@ kern_wait6(struct thread *td, idtype_t idtype, id_t id, int *status,
struct proc *p, *q;
pid_t pid;
int error, nfound, ret;
bool report;

AUDIT_ARG_VALUE((int)idtype); /* XXX - This is likely wrong! */
AUDIT_ARG_PID((pid_t)id); /* XXX - This may be wrong! */
Expand Down Expand Up @@ -1225,36 +1226,38 @@ kern_wait6(struct thread *td, idtype_t idtype, id_t id, int *status,
nfound++;
PROC_LOCK_ASSERT(p, MA_OWNED);

if ((options & (WTRAPPED | WUNTRACED)) != 0)
PROC_SLOCK(p);

if ((options & WTRAPPED) != 0 &&
(p->p_flag & P_TRACED) != 0 &&
(p->p_flag & (P_STOPPED_TRACE | P_STOPPED_SIG)) != 0 &&
p->p_suspcount == p->p_numthreads &&
(p->p_flag & P_WAITED) == 0) {
(p->p_flag & P_TRACED) != 0) {
PROC_SLOCK(p);
report =
((p->p_flag & (P_STOPPED_TRACE | P_STOPPED_SIG)) &&
p->p_suspcount == p->p_numthreads &&
(p->p_flag & P_WAITED) == 0);
PROC_SUNLOCK(p);
if (report) {
CTR4(KTR_PTRACE,
"wait: returning trapped pid %d status %#x "
"(xstat %d) xthread %d",
p->p_pid, W_STOPCODE(p->p_xsig), p->p_xsig,
p->p_xthread != NULL ?
p->p_xthread->td_tid : -1);
report_alive_proc(td, p, siginfo, status, options,
CLD_TRAPPED);
return (0);
report_alive_proc(td, p, siginfo, status,
options, CLD_TRAPPED);
return (0);
}
}
if ((options & WUNTRACED) != 0 &&
(p->p_flag & P_STOPPED_SIG) != 0 &&
p->p_suspcount == p->p_numthreads &&
(p->p_flag & P_WAITED) == 0) {
(p->p_flag & P_STOPPED_SIG) != 0) {
PROC_SLOCK(p);
report = (p->p_suspcount == p->p_numthreads &&
((p->p_flag & P_WAITED) == 0));
PROC_SUNLOCK(p);
report_alive_proc(td, p, siginfo, status, options,
CLD_STOPPED);
return (0);
if (report) {
report_alive_proc(td, p, siginfo, status,
options, CLD_STOPPED);
return (0);
}
}
if ((options & (WTRAPPED | WUNTRACED)) != 0)
PROC_SUNLOCK(p);
if ((options & WCONTINUED) != 0 &&
(p->p_flag & P_CONTINUED) != 0) {
report_alive_proc(td, p, siginfo, status, options,
Expand Down
2 changes: 1 addition & 1 deletion sys/kern/sys_capability.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ cap_ioctl_check(struct filedesc *fdp, int fd, u_long cmd)
("%s: invalid fd=%d", __func__, fd));

fdep = fdeget_locked(fdp, fd);
KASSERT(fdep == NULL,
KASSERT(fdep != NULL,
("%s: invalid fd=%d", __func__, fd));

ncmds = fdep->fde_nioctls;
Expand Down
3 changes: 2 additions & 1 deletion sys/kern/sysv_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1494,7 +1494,8 @@ SYSCTL_INT(_kern_ipc, OID_AUTO, msgseg, CTLFLAG_RDTUN, &msginfo.msgseg, 0,
"Number of message segments");
SYSCTL_PROC(_kern_ipc, OID_AUTO, msqids,
CTLTYPE_OPAQUE | CTLFLAG_RD | CTLFLAG_MPSAFE,
NULL, 0, sysctl_msqids, "", "Message queue IDs");
NULL, 0, sysctl_msqids, "",
"Array of struct msqid_kernel for each potential message queue");

static int
msg_prison_check(void *obj, void *data)
Expand Down
3 changes: 2 additions & 1 deletion sys/kern/sysv_sem.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ SYSCTL_INT(_kern_ipc, OID_AUTO, semaem, CTLFLAG_RWTUN, &seminfo.semaem, 0,
"Adjust on exit max value");
SYSCTL_PROC(_kern_ipc, OID_AUTO, sema,
CTLTYPE_OPAQUE | CTLFLAG_RD | CTLFLAG_MPSAFE,
NULL, 0, sysctl_sema, "", "Semaphore id pool");
NULL, 0, sysctl_sema, "",
"Array of struct semid_kernel for each potential semaphore");

static struct syscall_helper_data sem_syscalls[] = {
SYSCALL_INIT_HELPER(__semctl),
Expand Down
2 changes: 1 addition & 1 deletion sys/kern/sysv_shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ SYSCTL_INT(_kern_ipc, OID_AUTO, shm_allow_removed, CTLFLAG_RWTUN,
"Enable/Disable attachment to attached segments marked for removal");
SYSCTL_PROC(_kern_ipc, OID_AUTO, shmsegs, CTLTYPE_OPAQUE | CTLFLAG_RD |
CTLFLAG_MPSAFE, NULL, 0, sysctl_shmsegs, "",
"Current number of shared memory segments allocated");
"Array of struct shmid_kernel for each potential shared memory segment");

static struct sx sysvshmsx;
#define SYSVSHM_LOCK() sx_xlock(&sysvshmsx)
Expand Down

0 comments on commit 00f69db

Please sign in to comment.