Commit graph

737 commits

Author SHA1 Message Date
aiju 6f30420136 add dtracy support to mkdevc and enable dtracy with plan9.ini 2018-12-11 07:44:34 +00:00
aiju ca851bbb5e dtracy: call dtptrigger with a struct pointer rather than a list of arguments; put return value in arg9 2018-12-09 21:43:22 +00:00
aiju 58fa29447b dtracy: add support for aggregations 2018-12-08 15:07:53 +00:00
cinap_lenrek 6891093034 kernel: remove unused static variable "sofar" from timerintr() (thanks mischief) 2018-12-05 03:59:08 +01:00
cinap_lenrek d15aca0532 kernel: fix tprof on multiprocessor
segclock() has to be called from hzclock(), otherwise
only processes running on cpu0 would catche the interrupt
and the time delta would be wrong.

lock the segment when allocating Seg->profile as
profile ctl might be issued from multiple processes.
Proc->debug qlock is not sufficient.

Seg->profile can never be freed or reallocated once
set as the timer interrupt accesses it without any
locking.
2018-12-05 01:43:19 +01:00
mischief a25418fddc devbridge: fix runt packets going through the bridge (thanks cinap)
linux will send small, unpadded arp packets which may arrive over
wifi, so allow small packets into the bridge and pad any packets that
are too small when going out.
2018-11-17 17:23:56 -08:00
aiju e6d99771e5 adding dtracy (crude early version) 2018-11-10 13:46:16 +00:00
cinap_lenrek 2ee4c08974 devuart: don't sleep in uartdrainoutput() when called splhi or without a process
uartdrainoutput() might be called in early initialization
from uartctl() without a process.
2018-10-27 20:00:12 +02:00
cinap_lenrek 37dcb25eee kernel: fix allocb for BLOCKALIGN*2 >= Hdrspc 2018-10-20 19:52:54 +02:00
cinap_lenrek c4ec69045e devusb: use Enotconf[] string constant 2018-10-20 19:41:37 +02:00
cinap_lenrek bd49212b46 kernel: fix livelock in rebalance (thanks Richard Miller)
Once a second rebalance() is called on cpu0 to adjust priorities,
so cpu-bound processes won't lock others out.  However it was only
adjusting processes which were running on cpu0.  This was observed
to lead to livelock, eg when a higher-priority process spin-waits
for a lock held by a lower priority one.
2018-09-18 00:53:05 +02:00
mischief 5ea7337ae7 port: sync two longjmp fixes from drawterm
see drawterm commits f5e26ae93a6a and fa388286b4ca
2018-09-12 00:35:45 -07:00
cinap_lenrek 670137bf0a devdraw: zero initialize DImage.dscreen pointer (vnc, drawterm) 2018-08-19 22:00:45 +02:00
cinap_lenrek 445fc8e5a7 merge 2018-08-06 23:14:59 +02:00
cinap_lenrek abe463b931 wifi: lilu dallas multirate
now handle the supported rates element properly, only
providing the intersecting set of rates that the bss
advertises and what the driver supports, putting the
basic rates first.

also avoid using usupported rates.
2018-08-06 23:13:23 +02:00
mischief eb1be5b4df devaoe: really fix unit numbering, to be 0-based 2018-08-06 09:41:28 -07:00
mischief 796c41092a devaoe: fix unit numbering for Qdevlinkdir
a side effect of 3c77cd3ae664 changed the unit ordering to start at one, so fix the condition accordingly.
2018-08-06 08:50:40 -07:00
cinap_lenrek d07fb3261f devmouse: produce signed msec timestamp in /dev/mouse, accept unsigned on write 2018-07-23 19:29:15 +02:00
cinap_lenrek 0d7bbda9b9 devmnt: make sure auth chan is on said conection in mntattach() 2018-07-16 01:35:02 +02:00
cinap_lenrek eed90aa0ad kernel: don't cap the minimum sleep time to TK2MS(1) for syssleep()
on HZ 100 systems like pc and pc64, the minium sleep time
was 10ms, which is quite high. the cap isnt really needed
as arch specific timerset() enforces its own limit, but on
a higher resolution.

background:

from Charles Forsyth:

I haven't really got an opinion on it. The 10ms interval was first used on
machines that were much slower.
I thought someone did set HZ to a bigger value, partly to support better
in-kernel timing. I haven't done it because I never had a need for it.
If I were doing (say) protocol implementation in user mode, I'd certainly
reconsider. Sleep itself forces at best ms granularity,
and for some applications that's too big.

initial mail from qwx raising the issue:

> Hello,
>
> I found out recently that sleep(2)'s resolution on 386 and 9front's amd64
> kernel is 10 ms rather than 1 ms.  The reason is that on those kernels,
> HZ is set to 100 rather than say 1000.  In syssleep, we get 1 tich every
> 10 ms.
>
> What is unclear is why.
>
> To paraphrase cinap_lenrek's answer to my question:
>
> In syssleep:
>                 if(ms < TK2MS(1))
>                         ms = TK2MS(1);
>                 tsleep(&up->sleep, return0, 0, ms);
>
> "TK2MS(1)" can be replaced with just "1", and the arch specific
> timerset() routine would do its own capping of the period if it's too
> small for the timer resolution, and make better decisions based on what
> the minimum timer period should be given the latency overhead of the
> given arch's interrupt handling and performance characteristics.
>
> Alternatively, HZ could be raised to 500 or 1000.
>
> It seems it's just trying to prevent excessive context switches and
> interrupts, but it seems somewhat arbitrary.  A ton of syscalls can be
> done in 1 ms, and it's the lowest we can go without changing the unit.
>
>
> What do you think?
>
> Thanks in advance,
>
> qwx
2018-06-10 19:47:21 +02:00
cinap_lenrek 56ffc907ac kernel: stop the practice of passing DMDIR to devir() perm argument
devdir internally replicates the qid in ther perm stat field
already and the practice of explicitely passing just causing
confusion when done inconsistently.
2018-06-03 23:33:35 +02:00
cinap_lenrek 8c70c09bfd devaoe: fix dotdot walk in devlinkdir, make perms consistent 2018-06-03 23:30:57 +02:00
cinap_lenrek a2623fd82a devenv: make #ec files not show up as world writable 2018-06-03 23:30:05 +02:00
cinap_lenrek 16c87febd3 sdram: properly support multiple ramdisks, so that ramdiskX corresponds to sdZX 2018-05-29 22:50:04 +02:00
cinap_lenrek 5da4f0fc0f sdram: experimental ramdisk driver
this driver makes regions of physical memory accessible as a disk.

to use it, ramdiskinit() has to be called before confinit(), so
that conf.mem[] banks can be reserved. currently, only pc and pc64
kernel use it, but otherwise the implementation is portable.

ramdisks are not zeroed when allocated, so that the contents are
preserved across warm reboots.

to not waste memory, physical segments do not allocate Page structures
or populate the segment pte's anymore. theres also a new SG_CHACHED
attribute.
2018-05-27 22:59:19 +02:00
aiju 0e5888a0cf add usb tablet support 2018-05-08 08:28:48 +00:00
cinap_lenrek c96fb5471a devusb: fix format print warnings for ep->ntds and ep->uframes 2018-03-17 21:55:39 +01:00
qwx 199f090b6a devfs: revert commit 4000
induces a kernel panic under normal circumstances
2018-03-17 11:25:27 +02:00
qwx 14cd988a48 devfs: only set configed flag if config was read successfully
this is just to retry reading the configuration at least once after an error
2018-03-17 01:00:51 +02:00
aiju 56405e0919 usbehci: catch interrupt in tsleep 2018-03-07 08:45:06 +00:00
aiju 9226caf2a3 usbehci: add uframes control request to return uframes one at a time 2018-03-06 17:18:48 +00:00
cinap_lenrek 6f70699aec usbehci: fix medium- to low quality highspeed isochronous transfers
everything was broken. strting with hsinit not even chaining
the itd's into a ring. followed by broken buffer pointer pages.
finally, the interrupt handler's read transaction length
calculation was completely bugged, using the *FRAME* index
to access descriptors csw[] fields and not reseting tdi->ndata
thru the loop.

minor stuff:

iso->data needs to be freed with ctlr->dmafree()

put ival in iso->ival so ctl message cannot override the endpoints
pollival and screw up deallocation.
2018-03-05 06:09:31 +01:00
cinap_lenrek 6728a5ec23 devloopback: reassign device letter from #X to #λ to avoid collision with devvmx 2018-02-25 19:06:37 +01:00
cinap_lenrek b2d7992025 kernel: properly handle bad attach specifiers
- only accept decimal for numeric device id's
- exclude negative device id's
- device id's out of range yield Enodev
2018-02-25 17:11:18 +01:00
cinap_lenrek f0a314605f devether: remove (unimplemented) detach, allow device creation on attach
we allow devether to create ethernet cards on attach. this is useull
for virtual cards like the sink driver, so we can create a sink
by simply: bind -a '#l2:sink ea=112233445566' /net

the detach routine was never called, so remove it from the few drivers
that attempted to implement it.
2018-02-25 03:42:38 +01:00
cinap_lenrek 05cd5cb200 ns, devproc: quote path and spec arguments for /proc/$pid/ns, namespace(6) does support quoting 2018-02-25 03:24:31 +01:00
cinap_lenrek 729c9c39d9 devether: mux bridges, portable netconsole 2018-02-18 19:56:01 +01:00
cinap_lenrek 120ab04dd2 kernel: fix missing header dependency for ethersink.$O 2018-02-18 02:05:22 +01:00
cinap_lenrek df6a30f3c0 if ether, then etherif.h 2018-02-12 19:05:01 +01:00
cinap_lenrek 57c53564b3 ethersink: after the experiment, the zeros get dismantled. and then destroyed. 2018-02-12 01:48:20 +01:00
cinap_lenrek 3d0f4da104 ethersink: provide promisc and multicast functions for v6, set out queue limit to 0 on attach, add to pc64 config 2018-02-11 19:51:23 +01:00
cinap_lenrek d6e0e9c402 kernel: move devether and wifi to port/
the only architecture dependence of devether was enabling interrupts,
which is now done at the end of the driver's reset() function now.

the wifi stack and dummy ethersink also go to port/.

do the IRQ2->IRQ9 hack for pc kernels in intrenabale(), so not
every caller of intrenable() has to be aware of it.
2018-02-11 18:08:03 +01:00
cinap_lenrek b437065950 stats: show amount of reclaimable pages (add -r flag)
reclaimable pages are user pages that are used for
caches like the image cache, mount cache and swap cache.
2018-01-05 00:52:14 +01:00
cinap_lenrek 8040a878de devtls, devssl: avoid ~0UL comparsion (from drawterm) 2017-12-28 19:13:53 +01:00
cinap_lenrek 80185daba9 devmnt: use u32int for tagmask, simplify alloctag() 2017-12-28 18:25:15 +01:00
cinap_lenrek 1f80d31f41 devbridge: disable write blocking on ethernets 2017-12-18 20:44:53 +01:00
cinap_lenrek 520c938f0b devbridge: fix mss clamping
- use protocol constants from ip/ip.h and ip/ipv6.h
- support mss clamping for ipv6
- fix padding bug on 64 bit machines (can't use sizeof(Tcphdr))
2017-12-17 20:30:24 +01:00
cinap_lenrek af20ba6746 devvga: re-render text from kmesg after resize 2017-11-26 04:49:30 +01:00
cinap_lenrek 24057fd4f4 kernel: introduce per process FPU struct (PFPU) for more flexible machine specific fpu handling
introducing the PFPU structue which allows the machine specific
code some flexibility on how to handle the FPU process state.

for example, in the pc and pc64 kernel, the FPsave structure is
arround 512 bytes. with avx512, it could grow up to 2K. instead
of embedding that into the Proc strucutre, it is more effective
to allocate it on first use of the fpu, as most processes do not
use simd or floating point in the first place. also, the FPsave
structure has special 16 byte alignment constraint, which further
favours dynamic allocation.

this gets rid of the memmoves in pc/pc64 kernels for the aligment.

there is also devproc, which is now checking if the fpsave area
is actually valid before reading it, avoiding debuggers to see
garbage data.

the Notsave structure is gone now, as it was not used on any
machine.
2017-11-04 20:08:22 +01:00
cinap_lenrek 7e619e59e4 devcons: remove obsolete comment 2017-10-30 01:24:18 +01:00
cinap_lenrek 5a93b4fe2d kernel: track more header dependencies in port/portmkfile 2017-10-30 01:23:48 +01:00
cinap_lenrek b815eaca42 devswap: fix mistake 2017-10-29 23:24:42 +01:00
cinap_lenrek f3f9392517 kernel: introduce devswap #¶ to serve /dev/swap and handle swapfile encryption 2017-10-29 23:09:54 +01:00
cinap_lenrek 93117262c2 devfs: rewrite cryptio()
adjust to new aes_xts routines.

allow optional offset in the 4th argument where the encrypted
sectors start instead of hardcoding the 64K header area for
cryptsetup.

avoid allocating temporary buffer for cryptio() reads, we can
just decrypt in place there.

use sdmalloc() to allocate the temporary buffer for cryptio()
writes so that devsd wont need to allocate and copy in case
it didnt like our alignment.

do not duplicate the error reporting code, just use io()
that is what it is for.

allow 2*256 bit keys in addition to 2*128 bit keys.
2017-10-29 22:01:58 +01:00
cinap_lenrek c4e51c5678 devdup: remove useless OCEXEC check, handled by namec() 2017-08-28 19:45:49 +02:00
cinap_lenrek c492a8009a devsegment: handle ORCLOSE on segment directory correctly, fix wrong qid, missing COPEN flag for segmentcreate() 2017-08-28 19:40:53 +02:00
cinap_lenrek 6b999263ae kernel: double READSTR buffer size to 8000 bytes for devusb 2017-08-11 01:32:24 +02:00
cinap_lenrek 7dab492324 devusb: superspeed bandwidth allocation handled by controller, skip usbload() calculation
with xhci, bandwidth allocations are handled by the controller
and there are various speed settings possible that currently
not exposed in the Udev. so just keep usbload() as it is for
usb2 and keep ep->load as zero for superspeed.
2017-08-11 01:08:13 +02:00
cinap_lenrek 83b87729d9 usbxhci: handle out of memory in controller initialization 2017-08-02 21:17:50 +02:00
cinap_lenrek 6e65596827 xhci: experimental usb3 support 2017-07-31 03:22:23 +02:00
cinap_lenrek d46099e3af usbehci: fix crash in cancelisoio() for highspeed device due to wrong pollival 2017-07-31 03:07:14 +02:00
cinap_lenrek a397bfd48c usb: fix wrong pollival calculation in setmaxpkt() 2017-07-24 23:47:55 +02:00
cinap_lenrek 5e6f1b5769 usbxhci: commit work in progress xhci driver, no config yet 2017-07-16 22:29:29 +02:00
cinap_lenrek befdd7d755 kernel: pass bootargs also in multiboot command line, retire the bootline mechanism to pass arguments to /boot/boot 2017-06-28 18:56:16 +02:00
cinap_lenrek 2723c9fc77 kernel: add support for sticky segments (cached, preallocated, never paged) 2017-06-20 21:53:45 +02:00
aiju dea6bc51bc pc/pc64: debugexc: ignore exception if in kernel mode and can't get hold of up->debug 2017-06-12 22:58:25 +00:00
aiju cd1f44b5c0 kernel: reset nwatchpt in pexit 2017-06-12 19:19:05 +00:00
aiju 773be02aa1 kernel: add support for hardware watchpoints 2017-06-12 19:03:07 +00:00
cinap_lenrek 94e26e7576 kernel: make statistics counters skipscheds and preempts unsigned 2017-06-03 18:59:48 +02:00
cinap_lenrek 3d1908d762 kernel: don't preempt pager during fscache reclaim
the fscache image is the main source for pages once
the page freelist got exhausted, so delay scheduling
until they release the fscache lock.
2017-06-02 17:02:43 +02:00
cinap_lenrek 1bc20697ed devsegment: return proper write count for ctl message 2017-05-30 16:08:47 +02:00
cinap_lenrek 760e539811 kernel: avoid panic with segio and SG_FAULT segments
the problem is that segio doesnt check segment attributes
and it can't really in case of SG_FAULT which can be
inherited from pseg and toggle at any time.

so instead of returning -1 from fault into the fault$cputype
handler which then panics when fault happend kernel mode,
we jump into segio's waserror() block just like in the
demand load i/o error case (faulterror()).
2017-05-21 16:36:11 +02:00
cinap_lenrek 7327bd43c0 kernel: fix namelenerror(), avoid memrchr() and make it static
make sure the loop terminates and doesnt get stuck at
name == aname. avoid memrchr() as it conflicts with
libc on unix (drawterm). declare namelenerror() as
static.
2017-05-07 18:13:37 +02:00
cinap_lenrek f317d233f4 devproc: can't wait for ourselfs to stop (thanks Shamar) 2017-05-06 00:49:47 +02:00
cinap_lenrek 24420ab9eb kernel: fix rewinding in directories with pread() offset
reading directories with pread() offset has to work the same
way as read(), otherwise exportfs breaks rewinding in directories.
2017-04-30 01:51:07 +02:00
cinap_lenrek 3c894ece0c devdraw: ignore drawdebug command 2017-04-29 21:09:11 +02:00
cinap_lenrek 00fbdd622a kernel: avoid waserror() botch in devwalk (from drawterm, thanks aiju)
calculate alloc flag before waserror(), as compilers like
gcc will not notice the value changing later because
setjump() restores the old value due to callee-saves.

change is applies here to make it easier to merge with
drawterm.

thanks to aiju for debugging this; used to cause drawterm
memory leak until compiled with gcc -O0.
2017-04-05 00:34:07 +02:00
cinap_lenrek 30c05fe3dd kernel: fix memory leak in checkpagerefs() debug function (thanks aiju) 2017-04-04 20:13:31 +02:00
cinap_lenrek 0c1110ace2 kernel: fix twakeup()/timerdel() race condition
timerdel() did not make sure that the timer function
is not active (on another cpu). just acquiering the
Timer lock in the timer function only blocks the caller
of timerdel()/timeradd() but not the other way arround
(on a multiprocessor).

this changes the timer code to track activity of
the timer function, having timerdel() wait until
the timer has finished executing.
2017-03-29 00:30:53 +02:00
cinap_lenrek f59ef5e8e7 devsd: handle case where theres no ifc->enable() function 2017-03-26 16:53:19 +02:00
cinap_lenrek 019bb580da devsd: check return value of ifc->enable(), don't leak unit name/user strings 2017-03-26 16:45:34 +02:00
cinap_lenrek 1a2aefcf11 devmouse: refactor screen blanking logic
devmouse controls the screen blanking timeout, so move the
code there avoiding cross calls between modules. the only
function that needs to be provided is blankscreen(), which
gets called with drawlock locked.

the blank timeout is set thru /dev/mousectl now, so kernels
without devvga can set it.

blanking now only happens while /dev/mouse is read. so this
avoids accidentally blanking the screen on cpu servers that
do not have a mouse to unblank it.
2017-03-18 16:58:27 +01:00
cinap_lenrek 8177d20fb2 kernel: get rid of active.Lock and active.thunderbirdsargo 2017-03-11 16:30:51 +01:00
cinap_lenrek 47f07b2669 kernel: make the mntcache robust against fileserver like fossil that do not change the qid.vers on wstat
introducing new ctrunc() function that invalidates any caches
for the passed in chan, invoked when handling wstat with a
specified file length or on file creation/truncation.

test program to reproduce the problem:

#include <u.h>
#include <libc.h>
#include <libsec.h>

void
main(int argc, char *argv[])
{
	int fd;
	Dir *d, nd;

	fd = create("xxx", ORDWR, 0666);
	write(fd, "1234", 4);
	d = dirstat("xxx");
	assert(d->length == 4);
	nulldir(&nd);
	nd.length = 0;
	dirwstat("xxx", &nd);
	d = dirstat("xxx");
	assert(d->length == 0);
	fd = open("xxx", OREAD);
	assert(read(fd, (void*)&d, 4) == 0);
}
2017-01-12 20:13:20 +01:00
cinap_lenrek 5d353d62fe devmouse: remove unused static map[] array 2016-12-11 16:02:30 +01:00
cinap_lenrek b3c1fa9ecf devmouse: change msec argument of *mousetrack() to ulong 2016-12-10 16:12:18 +01:00
cinap_lenrek 9a55346264 devmouse: various bugfixes, simplify
the assumption of only one producer ((abs)moustratrack()) is not true
for external mouse events from /dev/mousein, so protect the mouse state
and queue with ilock().

get rid of mousecreate(), just use devcreate().

reset cursor when all instances of /dev/mouse and /dev/cursor got closed,
instead of also considering /dev/mousectl. the reason is that kbdfs keeps
the mousectl file open. so exiting a program that has the cursor changed
will properly reset the cursor to arrow.

don't access user buffer while holding cursor spinlock! the memory access
can fault. theres also no lock needed there, we'r just copying *from* the
cursor memory.

fix use of strtol(), p will always be set, check for end of string.

keep pointer coordinates onscreen (off by one).

make lastms() function to get the last millisecond delta of last
call for resynchronization.

fix msg[3] buffer overflow in m5mouseputc().

get rid of mouseshifted logic, it is not used.
2016-11-29 21:11:48 +01:00
cinap_lenrek dd4de0b0fa devtls: remove unused get32() function 2016-11-17 18:14:06 +01:00
cinap_lenrek c86b5ddaa6 kernel/qio: make readblist() offset of type ulong as the rest 2016-11-12 17:41:58 +01:00
cinap_lenrek 2127b8c552 kernel/qio: get rid of unused qcopycnt debug variable 2016-11-12 16:05:00 +01:00
cinap_lenrek d2ad8df947 kernel/qio: implement concatblock() with pullupblock() 2016-11-09 19:44:38 +01:00
cinap_lenrek 58fe71b2f5 devbridge: simplify etherwrite() as we dont deal with block lists 2016-11-08 21:06:06 +01:00
cinap_lenrek 5cbffd6e6b kernel/qio: maintain Block.next pointer in padblock() 2016-11-08 21:03:08 +01:00
cinap_lenrek b431b6c169 kernel/qio: fix comments, fix qiwrite() on close queue, remove debug setmalloctag() call in qwrite() 2016-11-08 00:38:07 +01:00
cinap_lenrek 32dfbc7c50 devcons: simplify putstrn0() 2016-11-08 00:34:59 +01:00
cinap_lenrek 48b49361d8 devbridge: various bugfixes and improvements from charles forsyth 2016-11-07 22:43:37 +01:00
cinap_lenrek a54d1cd95e kernel/qio: big cleanup of qio functions
remove bl2mem(), it is broken. a fault while copying to memory
yields a partially freed block list. it can be simply replaced
by readblist() and freeblist(), which we also use for qcopy()
now.

remove mem2bl(), and handle putting back remainer from a short
read internally (splitblock()) avoiding the releasing and re-
acquiering of the ilock.

always attempt to free blocks outside of the ilock.

have qaddlist() return the number of bytes enqueued, which
avoids walking the block list twice.
2016-11-07 22:20:10 +01:00
cinap_lenrek 23d217afb4 devloopback: simplify loopoput()
remove unneeded waserror() block, loopoput is alled from
loopbackbwrite only so we will always get called with a
*single* block, so the concatblock() is not needed.
2016-11-07 22:08:21 +01:00
cinap_lenrek c1fd7c210b kernel: fix missing ; in panic() call 2016-11-05 20:08:20 +01:00
cinap_lenrek 963497f06b kernel: avoid padblock copying for devtls/devssl/esp, cleanup debugging
to avoid copying in padblock() when adding cryptographics macs to a block
in devtls/devssl/esp we reserve 16 extra bytes to the allocation.

remove qio ixsummary() function and add acid function qiostats() to
/sys/lib/acid/kernel

simplify iallocb(), remove iallocsummary() statitics.
2016-11-05 20:05:40 +01:00
cinap_lenrek fa5bd71218 devmnt: avoid memory copies of I/O rpc buffer by using bwrite()
given that devmnt will almost always write into a pipe
or a network connection, which supports te bwrite routine,
we can avoid the memory copy that would have been done by
devbwrite(). this also means the i/o buffer for writes
will get freed sooner without having to wait for the 9p
rpc to get a response, saving memory.

theres one case where we have to keep the rpc arround and
that is when we write to a cached file, as we want to update
the cache with the data that was written, but the user buffer
cannot be trusted to stay the same during the rpc.
2016-11-05 18:26:12 +01:00
cinap_lenrek 5c1feb0ef0 libc: move calloc() into its own compilation unit
move calloc() in its own compilation unit to avoid
code duplication. also, calloc() is used rarely in
plan9 programs.
2016-11-05 18:00:10 +01:00
cinap_lenrek 234137bce3 fix bugs and cleanup cryptsetup code
devfs:

- fix memory leak in devfs leaking the aes key
- allocate aes-xts cipher state in secure memory
- actually check if the hexkey got fully parsed

cryptsetup:

- get rid of stupid "type YES" prompt
- use genrandom() to generate salts and keys
- rewrite cryptsetup to use common pbkdf2 and readcons routines
- fix alot of error handling and simplify the code
- move cryptsetup command to disk/cryptsetup
- update cryptsetup(8) manual page
2016-10-24 20:56:11 +02:00
cinap_lenrek c0a9c3b551 kernel: rekey chacha state on each randomread() invocation
we can encrypt the 256 bit chacha key on each invocation
making it hard to reconstruct previous outputs of the
generator given the current state (backtracking resiatance).
2016-09-11 19:07:17 +02:00
cinap_lenrek 36c9a2489d devcons: remove /dev/reboot "halt" command...
the "halt" command written to /dev/reboot just causes the
machine to crash... its also undocumented... removing it.

--
cinap
2016-09-11 14:12:39 +02:00
cinap_lenrek 95c9f5bf37 kernel: better nonce partitioning for chacha random number generator
leave the block counter to chacha_encrypt() and increment the 96 bit
iv instead.
2016-09-11 03:18:48 +02:00
cinap_lenrek 10275ad6dd kernel: xoroshiro128+ generator for rand()/nrand()
the kernels custom rand() and nrand() functions where not working
as specified in rand(2). now we just use libc's rand() and nrand()
functions but provide a custom lrand() impelmenting the xoroshiro128+
algorithm as proposed by aiju.
2016-09-11 02:10:25 +02:00
cinap_lenrek 7713145638 kernel: make randomread() fault reentrant
we now access the user buffer in randomread() outside of the lock,
only copying and advancing the chacha state under the lock. this
means we can use randomread() within the fault handling path now
without fearing deadlock. this also allows multiple readers to
generate random numbers in parallel.
2016-09-11 02:09:07 +02:00
cinap_lenrek a121806126 kernel: replace various custom random iv buffer filling functions with calls to prng() 2016-09-11 01:54:06 +02:00
cinap_lenrek ed38b5e9cb kernel: fix type for utime/stime in pexit(), fix debug format strings 2016-09-08 01:49:25 +02:00
cinap_lenrek 5d9deb77e9 kernel: make sure procalarm() remaining time doesnt become negative 2016-09-08 01:28:34 +02:00
cinap_lenrek 01b4c2a63d kernel: always do unsigned subtractions for m->ticks delta for updatecpu() and rebalance(), handle ticks wrap arround in hzsched() 2016-09-08 00:44:38 +02:00
cinap_lenrek bd3429304c kernel: use tk2ms() instead of TK2MS macro for process time conversion
this code isnt time critical and process TReal delta can become
very long, so use tk2ms() which is less prone to overflow.
2016-09-07 23:39:10 +02:00
cinap_lenrek 1848f4e946 kernel: tsemacquire() use MACHP(0)->ticks for time delta
we might wake up on a different cpu after the sleep so
delta from machX->ticks - machY->ticks can become negative
giving spurious timeouts. to avoid this always use the
same mach 0 tick counter for the delta.
2016-09-07 23:36:04 +02:00
cinap_lenrek bfd8098b8d devcap: timeout capabilities after a minute, fix memory leak, paranoia
the manpage states that capabilities time out after a minute,
so we add ticks field into the Caphash struct and record the
time when the capability was inserted. freeing old capabilities
is handled in trimcaps(), which makes room for one extra cap
and frees timed out ones.

we also limit the capuse write size to less than 1024 bytes to
prevent denial of service as we have to copy the user buffer.
(memory exhaustion).

we have to check the from user *before* attempting to remove
the capability! the wrong user shouldnt be able to change any
state. this fixes the memory leak of the caphash.

do the hash comparsion with tsmemcmp(), avoiding timing
side channels.

allocate the capabilities in secret memory pool to prevent
debugger access.
2016-09-07 21:14:23 +02:00
cinap_lenrek cf78fd37cb devproc: do unsigned subtraction to get MACHP(0)->ticks - up->times[TReal] delta 2016-09-06 22:27:26 +02:00
cinap_lenrek 0a5f81a442 kernel: switch to fast portable chacha based seed-once random number generator 2016-08-27 20:42:31 +02:00
cinap_lenrek 71ac88392f devsdp: keep cipher states in secret memory 2016-08-27 20:39:36 +02:00
cinap_lenrek 2967f942ea devtls: allocate cipher states in secret memory 2016-08-27 20:37:31 +02:00
cinap_lenrek 7250c438bb devssl: allocate cipher states in secret memory 2016-08-27 20:37:14 +02:00
cinap_lenrek 0f97eb3a60 kernel: add secalloc() and secfree() functions for secret memory allocation
The kernel needs to keep cryptographic keys and cipher states
confidential. secalloc() allocates memory from the secret pool
which is protected from debuggers reading the memory thru devproc.
secfree() releases the memory, overriding the data with garbage.
2016-08-27 20:33:03 +02:00
cinap_lenrek 713beb6d42 devmnt: fix mistake in mntrahread()
mntrahread() had the prefetch window condition wrong so
it would very agressively prefetch ignoring the prefetch
window.
2016-08-16 18:06:22 +02:00
cinap_lenrek 409babb990 devtls, devssl: make sure channel has ORDWR mode and is not a mount chan on fdtochan() 2016-07-24 03:24:42 +02:00
cinap_lenrek 8173223f43 swap: make sure swap chan has ORDWR mode on fdtochan() 2016-07-24 03:23:01 +02:00
cinap_lenrek 093eaec219 kernel: dont pprint() into 9p channels
when fd 2 (stderr) points to a mount channel, dont
cause protocol confusion by dumping error strings
into it.
2016-07-19 22:10:52 +02:00
cinap_lenrek a99cf56c7d kernel: more (arm) compiler friendly mul64fract()
the arm compiler can lift long->vlong casts on multiplcation
and convert 64x64->64 multiplication into a 32x32->64 one
with optional 64 bit accumulate.
2016-06-26 15:13:10 +02:00
cinap_lenrek b6005f3a45 avoid updating offset in pread; avoid diagnostic about vlong mask (charles forsyth) 2016-05-16 21:11:54 +02:00
cinap_lenrek 29c7ca80c9 correct check for segment overlap (rmiller) 2016-05-16 21:10:08 +02:00
cinap_lenrek cb4b187f10 devssl, devtls: fix permission checks 2016-05-11 02:10:05 +02:00
cinap_lenrek 66719fb3ea kernel: fix cb->f[0] nil dereferences due to short control request 2016-05-05 18:54:58 +02:00
cinap_lenrek 0237b58390 kernel: always clunk closed fids asynchronously, regardless of caching 2016-04-01 14:12:50 +02:00
cinap_lenrek df53b2d69b kernel: remove unused NSMAX, NSLOG, NSCACHE constants from portdat.h 2016-03-31 04:23:27 +02:00
cinap_lenrek 1057a859b8 devsegment: cleanups
- return distinct error message when attempting to create Globalseg with physseg name
- copy directory name to up->genbuf so it stays valid after we unlock(&glogalseglock)
- cleanup wstat() handling, allow changing uid
- make sure global segment size is below SEGMAXSIZE
- move isoverlap() check from globalsegattach() into segattach()
- remove Proc* argument from globalsegattach(), segattach() and isoverlap()
- make Physseg.attr and segattach attr parameter an int for consistency
2016-03-30 22:49:13 +02:00
cinap_lenrek e6b30b287c kernel: fix procflushmmu()
fix bug introduced in previous change for zynq, broke
procflushseg() function only flushing the first proc
matching the segment.
2016-03-29 02:09:49 +02:00
cinap_lenrek ce00c68059 kernel: print pid as %lud instead %lux (in tsleep() debug print) 2016-03-28 23:01:54 +02:00
cinap_lenrek 89f9966aed devtls: print the path of the underlying chan in status file
to figure out what network connection a particular tls
conversation refers to, we add the path of the underlying
we send the encrypted tls traffic over in the status file,
example:

term% grep -n '^Chan:' '#a'/tls/*/status
#a/tls/0/status:7: Chan: /net/tcp/6/data
#a/tls/1/status:7: Chan: /net/tcp/0/data
2016-03-28 20:12:54 +02:00
cinap_lenrek 04c3a6f66e zynq: introduce SG_FAULT to prevent access to AXI segment while PL is not ready
access to the axi segment hangs the machine when the fpga
is not programmed yet. to prevent access, we introduce a
new SG_FAULT flag, that when set on the Segment.type or
Physseg.attr, causes the fault handler to immidiately
return with an error (as if the segment would not be mapped).

during programming, we temporarily set the SG_FAULT flag
on the axi physseg, flush all processes tlb's that have
the segment mapped and when programming is done, we clear
the flag again.
2016-03-27 20:57:01 +02:00
cinap_lenrek 9aa6573359 kernel: fix tsleep()/twakeup()/tsemacquire() race
tsleep() used to cancel the timer with:

if(up->tt != nil)
	timerdel(up);

which still can result in twakeup() to fire after tsleep()
returns (because we set Timer.tt to nil *before* we call the tfn).
in most cases, this is not an issue as the Rendez*
usually is just &up->sleep, but when it is dynamically allocated
or on the stack like in tsemacquire(), twakeup() will call
wakeup() on a potentially garbage Rendez structure!

to fix the race, we execute the wakup() with the Timer lock
held, and set p->trend to nil only after we called wakeup().

that way, the timerdel(); which unconditionally locks the Timer;
can act as a proper barrier and use up->trend == nil as the
condition if the timer has already fired.
2016-03-26 02:37:42 +01:00
cinap_lenrek e7bc98b057 devtls: zero secret information before freeing, cleanup 2016-03-23 13:50:58 +01:00
cinap_lenrek aa6673fcfb add portable AES-GCM (Galois/Counter Mode) implementation to libsec and devtls 2016-03-23 02:45:35 +01:00
cinap_lenrek a2be120ea9 abandon streaming experiment
for queue like non-seekable files, it is impossible to implement an
exportfs because one has to run the kernels devtab read() and write()
in separate processes, and that makes it impossible to maintain 9p message
order as the scheduler can come in and randomly schedule one process before
another.

so as soon as we have a transition from 9p -> syscalls, we'r screwed.

i currently see just two possibilities:

- introduce special file type like QTSEQ with strictly ordered i/o semantics
- fix all fileservers and exportfs to only do one outstanding i/o to QTSEQ files
which means maintaining a queue per fid

this doesnt propagate. so exporting slow 9p mount again will be limited
again by latency of the inner mount.

other option:

- return offset in Rread, so client can bring responses back into order. this
requires changing all fileservers and drivers to maintain such an per fid offset
and change the protocol to include it in the response, and also pass it to userspace
(new syscalls or pass it in TOS)

this only works for read pipelining, write is still screwed.

both options suck.

--
cinap
2016-03-17 17:48:19 +01:00
cinap_lenrek 0276031c01 make kernel UTFmax and Runemax consistent with libc (21-bit runes) (thanks maurice) 2016-03-10 20:02:36 +01:00
cinap_lenrek 28bd8adce7 devcons: nil vs 0 2016-03-10 03:28:36 +01:00
cinap_lenrek 595501b005 kernel: make fversion()/mntversion() types consistent 2016-03-10 03:02:28 +01:00
cinap_lenrek 0aa5b01fab devtls: fix wrong iounit
devtls writes are only atomic up to MaxRecLen as this is the
maximum payload size we put in a record application message.
2016-03-09 19:54:33 +01:00
cinap_lenrek 5ebb1a29d8 devdraw: remove unused Edepth[] 2016-02-28 03:06:42 +01:00
cinap_lenrek b450cb7e32 devmnt: deal with partial response for Tversion request in mntversion() 2016-02-15 01:03:44 +01:00
cinap_lenrek ecebba779f provide /n and /mnt early in bootrc to allow consistent use in /lib/namespace
theres a bootstrap problem:

when /bin/init is run, it processes /lib/namespace where we might want to
mount or bind resources to /n or /mnt. but mntgen was run later in
cpurc/termrc so these mounts would be ignored.

we already have mntgen in bootfs, so we can provide these mountpoints early.

i keep the termrc/cpurc mntgens where they are, but ignore the error
prints. this way old kernels will continue to work.
2016-02-14 01:42:32 +01:00
cinap_lenrek 21b70c782a devssl: use tsmemcmp() to compare mac to close timing side channel 2016-01-13 21:48:09 +01:00
cinap_lenrek 5afa5f5c0b kernel: remove todfix overflow iprint() spam 2016-01-07 19:37:05 +01:00
cinap_lenrek 772afbe98c format pointer subtraction results with %zd instead of %ld (for long -> intptr on amd64) 2016-01-07 04:44:13 +01:00
cinap_lenrek 3e38194d72 introduce signed intptr and %z format modifier for formating uintptr and intptr 2016-01-07 04:39:09 +01:00
cinap_lenrek 41383ad012 kernel: change active.machs from bitmap to char array to support up to 64 cpus on pc64 2016-01-05 05:32:40 +01:00
cinap_lenrek 9b0de7f9d6 tls: implement chacha20/poly1305 aead cipher suits 2015-12-21 04:55:54 +01:00
cinap_lenrek d19144155e kernel: missing changes for ibrk() prototype 2015-12-21 04:49:29 +01:00
cinap_lenrek b6f04b77e3 devprov: remove unused extern int unfair 2015-12-16 21:07:24 +01:00
cinap_lenrek 7be7d0681f kernel: use uintptr for ibrk() return value (for base >2GB) and clarify segbrk(2) 2015-12-16 21:06:51 +01:00
cinap_lenrek 7f3659e78f kernel: cleanup exit()/shutdown()/reboot() code
introduce cpushutdown() function that does the common
operation of initiating shutdown, returning once all
cpu's got the message and are about to shutdown. this
avoids duplicated code which isnt really machine specific.

automatic reboot on panic only when *debug= is not set
and the machine is a cpu server or has no display,
otherwise just hang.
2015-11-30 14:56:00 +01:00
cinap_lenrek 98363cb272 devenv: fix ORCLOSE handling
when opening a /env file ORCLOSE, and the process exits, envgrp() would
return nil can crash in envremove() because procexit will have set up->egrp
to nil before calling closefgrp().

the solution is to capture the environment on open, keeping a reference in
Chan.aux, so it doesnt matter on what process the close happens and a
env chan will always refer to its original environment group.
2015-11-22 02:39:57 +01:00
cinap_lenrek 00572496ce kernel: use nicer check in okaddr(), wet floor signs in fixfault()
instead of checking addr+len >= addr, check len >= -addr so
that addr == 0 is never valid for len > 0 even if we decide
to have memory at the zero page so theres never any chance
user can pass in "nil" pointers.

put up some signs where we fall thru the switch cases in
fixfault()
2015-11-06 17:27:15 +01:00
cinap_lenrek b32300deb0 kernel: fix okaddr() check 2015-11-06 02:53:30 +01:00
cinap_lenrek cd3053a3cc devtls: reject SHA2_256 mac for SSL, but TLS is fine
sha256 is only defined for TLS1.2, however, technically, theres
no reason not to use it in TLS1.0/TLS1.1. the choice is up to
tlshand and pushtls, not the kernel.
2015-10-28 17:09:22 +01:00
mischief 08e2333cc1 port: fix typo in devmnt mntproc name 2015-10-07 21:45:03 -07:00
cinap_lenrek 12f7fc7a08 devsd: handle SYNCHRONIZE CACHE scsi commands as nops in sdfakescsi() 2015-09-20 14:54:49 +02:00
cinap_lenrek fa769a8f9d sdmmc: handle fakescsi emulation 2015-09-20 14:53:44 +02:00
cinap_lenrek c7c58ef8bb devsd: remove unused timeout field from SDreq 2015-09-20 14:27:41 +02:00
cinap_lenrek 6fb9ae8f43 usbehci: clean cache unconditionally before handing a buffer to the hardware
even in the read case, we need to clean the cache
so the cpu will not flush out old changes while
the hardware updates the buffer.
2015-09-05 10:14:19 +02:00
mischief 163a772124 devtls: add sha256 mac 2015-08-27 01:46:28 -07:00
glenda c4fdc6bfdb fix fuckup 2015-08-25 09:35:10 +00:00
mischief 6b402b83cf import E script from bell labs 2015-08-25 02:07:46 -07:00
cinap_lenrek 74d1f67b05 devtls: TLS1.1 explicit iv support
using nrand() to fill the explicit iv, which isnt great but better
than no iv.
2015-08-15 17:50:44 +02:00
cinap_lenrek 76f21ca715 kernel: try freebroken() *before* killbig() (thanks aiju) 2015-08-14 14:45:19 +02:00
cinap_lenrek 7ba3be82a7 kernel: move "setargs" field in Proc structure after "nargs" and "args" 2015-08-09 21:48:58 +02:00
cinap_lenrek b4f56f1f4e kernel: mount flag is int not ulong, reduce size of Mount struct by putting mflag field in what would be wasted as padding 2015-08-09 21:35:50 +02:00
cinap_lenrek 9f4eac5292 kernel: pgrpcpy(), simplify Mount structure
instead of ordering the source mount list, order the new destination
list which has the advantage that we do not need to wlock the source
namespace, so copying can be done in parallel and we do not need the
copy forward pointer in the Mount structure.

the Mhead back pointer in the Mount strcture was unused, removed.
2015-08-09 21:16:10 +02:00
cinap_lenrek 3af236b5e3 kernel: fix Mheadache
there was a race between cunmount() and walk() on Mhead.from as Mhead.from was
unconditionally freed when we cunmount(), but findmount might have already
returned the Mhead in walk(). we have to ensure that Mhead.from is not freed
before the Mhead itself (now done in putmhead() once the reference count of the
Mhead drops to zero).

the Mhead struct contained two unused locks, removing.

no need to hold Pgrp.ns lock in closegrp() as nobody can get to it (refcount
droped to zero).

avoid cclose() and freemount() while holding Mhead.lock or Pgrp.ns locks as
it might block on a hung up fileserver.

remove the debug prints...

cleanup: use nil for pointers, remove redundant nil checks before putmhead().
2015-08-09 18:19:47 +02:00
cinap_lenrek 8ce456bd19 kernel: remove unused MAXCRYPT constant from portdat.h 2015-08-06 13:35:03 +02:00
cinap_lenrek 87d7a3c875 kernel: have to validate argv[] again when copying to the new stack
we have to validaddr() and vmemchr() all argv[] elements a second
time when we copy to the new stack to deal with the fact that another
process can come in and modify the memory of the process doing the
exec. so the argv[] strings could have changed and increased in
length. we just make sure the data being copied will fit into the
new stack and error when we would overflow.

also make sure to free the ESEG in case the copy pass errors.
2015-08-06 13:20:41 +02:00
cinap_lenrek 281729551f kernel: limit argv[] strings to the USTKSIZE to avoid overflow
argv[] strings get copied to the new processes stack segment, which
has a maximum size of USTKSIZE, so limit the size of the strings to
that and check early for overflow.
2015-08-06 11:51:23 +02:00
cinap_lenrek b09cd67860 kernel: validnamedup() the name argument for segattach()
this moves the name validation out of segattach() to syssegattach()
to make sure the segment name cannot be changed by the user while
segattach looks at it.
2015-08-06 11:48:51 +02:00
cinap_lenrek d275add1a8 kernel: fix indention in validname0() 2015-08-06 11:43:22 +02:00
cinap_lenrek 9585e9b7f8 kernel: limit syscallfmt user strings to 64K (as in validname) 2015-08-06 11:42:05 +02:00
cinap_lenrek 86eb8ea6bb kernel: change vmemchr() length argument to ulong and simplify 2015-08-06 10:15:07 +02:00
cinap_lenrek 8d196aeec7 kernel: use Etoolong[] constant instead of string literal in validname0() 2015-08-06 10:01:45 +02:00
cinap_lenrek 9110ae6eae kernel: make shargs() function static in sysproc.c 2015-08-06 09:09:57 +02:00
cinap_lenrek 2acb02f29b kernel: reject empty argv (argv[0] == nil) in sysexec()
when executing a script, we did advance argp0 unconditionally
to replace argv[0] with the script name. this fails when
argv[] is empty, then we'd advance argp0 past the nil terminator.

the alternative would be to *not* advance if *argp0 == nil, but that
would require another validaddr() check for a case that is unlikely
to have been anticipated in most programs being invoked as
libc's ARGBEGIN macro assumes argv[0] being non-nil as it also
unconditionally advances the argv pointer.

to keep us sane, we now reject an empty argv[]. on entry, we
verify that argv[] is valid for at least two elements:
- the program name argv[0], has to be non-nil
- the first potential nil terminator in argv[1]

when argv[0] == nil, we throw Ebadarg "bad arg in system call"
2015-08-06 08:47:38 +02:00
cinap_lenrek 145624eec2 kernel: remove unused qstate() function 2015-08-04 13:52:29 +02:00
cinap_lenrek 1b7e120c09 kernel: dont rely on atoi() parsing hex for netif/devbridge 2015-08-03 16:24:14 +02:00
cinap_lenrek d5d6724805 devenv: simplify envremove(), cleanup 2015-08-03 22:08:10 +02:00
cinap_lenrek 37e4ce0ea7 devenv: avoid indirection, keep Evalue's allocated in an array
avoid the indirection for envlookup() by allocating Evalue structs
together in an array. remove unused link field in Evalue.
2015-08-02 21:39:33 +02:00
cinap_lenrek 27445c5768 kernel: cleanup qlock.c to use nil instead of 0 for pointers 2015-08-02 05:36:35 +02:00
cinap_lenrek ee86d3cb52 devmnt: fix mntcache()
make sure mntcache() wont cache data beyond what was read from
the block list.
2015-07-30 21:00:13 +02:00
cinap_lenrek 20da5094d9 kernel: remove obsolete comment from namec() 2015-07-28 10:01:05 +02:00
cinap_lenrek 4bd9ed80c3 kernel: export mntattach() from devmnt.c avoiding bogus struct passing and special case in namec()
we already export mntauth() and mntversion(), so why not stop
being sneaky and just export mntattach() so bindmount() and
devshr can just call it directly with proper arguments being
checked.

we can also avoid handling #M attach specially in namec()
by having the devmnt's attach function do error(Enoattach).
2015-07-28 09:52:21 +02:00
cinap_lenrek 652a641704 kernel: clunk the cache when removing cache flag on a channel, only call cread() chen CCACHE flag is set
to avoid double caching, attachimage() and setswapchan() clear
the CCACHE flag on the channel but this keeps the read ahread
state of the cache arround (until the chan gets closed), so also
call cclunk() to detach the mcp and free the read ahead state.

avoid the call to cread() when CCACHE flag is clear.
2015-07-27 06:42:41 +02:00
cinap_lenrek ff494b954f devmnt: use c->iounit instead of msize-IOHDRSZ to chunk reads and writes, reduce memory overhead for Mntrpc, mntalloc lock
use the actual iounit returned from Ropen/Rcreate to chunk reads and writes
instead of c->mux->msize-IOHDRSZ.

dont preallocate the rpc buffers to msize, most 9p requests are rather small
(except Twrite of course). so we allocate the buffer on demand in mountio()
with some rounding to avoid frequent reallocations.

avoid malloc()/free() while holding mntalloc lock.
2015-07-27 04:33:46 +02:00
cinap_lenrek 23f7840056 devmnt: dont reset readahead window when requested offset still has pending rpc 2015-07-26 13:55:51 +02:00
cinap_lenrek 6617c63a37 kernel: pipelined read ahead for the mount cache
this changes devmnt adding mntrahread() function and some helpers
for it to do pipelined sequential read ahead for the mount cache.

basically, cread() calls mntrahread() with Mntrah structure and it
figures out if we where reading sequentially and if thats the case
issues reads of c->iounit size in advance.

the read ahead state (Mntrah) is kept in the mount cache so we can
handle (read ahead) cache invalidation in the presence of writes.
2015-07-26 05:43:26 +02:00
cinap_lenrek 497daed116 kernel: make sure fd is in range in fdclose()
as the Fgrp can be shared with other processes, we have to
recheck the fd index after locking the Fgrp in fdclose()
to make sure not to read beyond the bounds of the fd array.
2015-07-23 22:56:49 +02:00
cinap_lenrek 323184d775 kernel: simplify syspipe() 2015-07-23 22:34:58 +02:00