Commit graph

693 commits

Author SHA1 Message Date
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
cinap_lenrek ff03b72ed5 devaoe: more nil vs. 0 2015-07-23 22:05:46 +02:00
cinap_lenrek 0b3fd7c052 devaoe: fix off by one in aoeerror(), consistent use of nil for pointers, error handling 2015-07-22 21:56:11 +02:00
cinap_lenrek 769b3f1c2f kernel: consistent use of nil for pointer in sysfile.c 2015-07-22 21:54:07 +02:00
cinap_lenrek 1fcc84d072 kernel: cleanup chan.c to consistenly use nil instead of 0 for pointers 2015-07-22 19:17:10 +02:00
cinap_lenrek 8db5af02d8 kernel: make sure the swap device has a reasonable capacity in setswapchan() 2015-07-22 19:15:51 +02:00
cinap_lenrek 47bb311d39 devmnt: do not use user buffer to update the mount cache
using the user buffer has a race where the user can modify
the buffer from another process before it is copied into the cache.
this allows poisoning the cache for every file where the user
has read access.

instead, we update the cache from kernel memory.
2015-07-19 20:25:42 +02:00
cinap_lenrek 157b7751e7 devstream: fix mistake 2015-07-19 03:36:53 +02:00
cinap_lenrek 71cda09d1e devstream: fast sequential file access with 9p pipelining experiment 2015-07-19 03:31:17 +02:00
cinap_lenrek bae3ac29fc devproc: make sure statbufread offset wont turn negative 2015-07-15 17:09:05 +02:00
cinap_lenrek 2aa2f9f359 kernel: remove debugalloc.c 2015-07-14 06:51:02 +02:00
cinap_lenrek b5655b7247 wifi: adjust transmit rate on error (for etheriwl), small mkfile changes
Wnode gets two new counters: txcount and txerror
and actrate pointer that will be between minrate
and maxrate.

driver should use actrate instead of maxrate for
transmission when it can provide error feedback.

when a driver detects a transmission failed, it calls
wifitxfail() with the original packet. wifitxfail() then
reduces wn->actrate.

every 256th packet, we optimistically increase wn->actrate
before transmitting.
2015-07-10 09:04:05 +02:00
cinap_lenrek 4ec93f94c9 kernel: use HDR_MAGIC constant to handle Exec header extension, make rebootcmd() handle AOUT_MAGIC macro 2015-07-10 23:56:39 +02:00
cinap_lenrek 3ca9ac70c4 sysexec(): need () arround AOUT_MAGIC comparsion to handle #define hack on mips 2015-07-09 08:51:38 +02:00
cinap_lenrek e3217c6f6a sysexec(): make the mips compiler happy 2015-07-09 08:34:20 +02:00
cinap_lenrek 9ab096a707 kernel: reject bogus two byte "#!" shell scripts in sysexec()
- reject files smaller or equal to two bytes, they are bogus
- fix out of bounds access in shargs() when n <= 2
- only copy the bytes read into line buffer
- use nil for pointers instead of 0
2015-07-09 08:03:18 +02:00
cinap_lenrek 8ed25f24b7 kernel: various cleanups of imagereclaim(), pagereclaim(), freepages(), putimage()
imagereclaim(), pagereclaim():
- move imagereclaim() and pagereclaim() declarations to portfns.h
- consistently use ulong type for page counts
- name number of pages to free "pages" instead of "min"
- check for pages == 0 on entry

freepages():
- move pagechaindone() call to wakeup newpage() consumers inside
  palloc critical section.

putimage():
- use long type for refcount
2015-07-09 00:01:50 +02:00
cinap_lenrek 1bd4c243ad kernel: ignore last page at the top of virtual kernel address space for xalloc()
avoding kernel address -BY2PG because of end pointer wrapping to zero.
2015-06-19 02:45:58 +02:00
cinap_lenrek 0dab8869ad kernel: ignore memory pages with singular kernel addresses
addresses va's of 0 and -BY2PG cause trouble with some memmove()/memset()
implementations and possibly other code because of the nil pointer
and end pointers wrapping to zero.
2015-06-18 12:15:33 +02:00
cinap_lenrek fd8597ac31 zynq: fix barriers
unlock()/iunlock():

we need to place the coherence() *before* "l->key = 0", so that any
stores that where done while holding the lock become observable
*before* other processors see the lock released.

cas()/tas():

place memory barrier before successfull return to prevent reordering.
2015-06-18 04:35:46 +02:00
cinap_lenrek 58dc03cec0 kernel: do not inherit Proc.dot (current working directory) in kproc()
making sure to close the dot in every kproc appears repetitive,
so instead stop inheriting the dot in kproc() as this is usually
never what you wanted in the first place.
2015-06-18 03:13:50 +02:00
cinap_lenrek b48078c12c kernel: do not inherit current directory channel (dot) to pager
kproc() inherits dot and slash, pager needs to drop these
channels, otherwise it will keep the files open preventing
say, ramfs to exit.
2015-06-18 22:58:56 +02:00
cinap_lenrek 45b79036be devcons: add current pool allocations to #c/swap 2015-06-16 08:05:33 +02:00
cinap_lenrek 6c99d2f028 kernel: remove waserror() arround newpage() in mntcache
newpage() does not raise error().
2015-06-16 06:05:12 +02:00
cinap_lenrek 64ed3658d2 kernel: add pagechaindone() to wakeup processes waiting for memory
we keep the details about palloc in page.c, providing pagechaindone()
for mmu code to be called after a series of pagechainhead() calls.
2015-06-15 17:40:47 +02:00
cinap_lenrek 8a3b388ffe kernel: implement separate wait queues for page allocation
give kernel processes and local disk file servers (procs
having noswap flag set) a clear advantage for page allocation
under starved condition by giving them ther own wait queue so
they get readied as soon as pages become available.
2015-06-15 16:05:00 +02:00
cinap_lenrek d6eb7cc71c kernel: dont use smalloc() to allocate pte array in ibrk()
when we'r out of kernel memory, it is probably better to
let that alloc fail instead of hanging while holding the
segment qlock.
2015-06-13 17:50:26 +02:00
cinap_lenrek 34ae4649cc kernel: fix accounttime() for HZ >= 1000
"milli-CPU's" is too low resolution for the decaying load average
calculation when HZ >= 1000.
2015-06-12 14:28:31 +02:00
cinap_lenrek cda46731d8 devsegment: fix parsecmd() memory leak 2015-06-09 03:33:37 +02:00
cinap_lenrek c5b0edecc9 devfs: remove useless ~OTRUNC mask for openmode 2015-06-07 17:41:43 +02:00
cinap_lenrek 5c6357de8b devtls: ignore UnrecogniedName (112) alert message (for SNI) 2015-06-01 01:32:57 +02:00
cinap_lenrek 646062da1c kernel: state errstr.h dependency for proc.acid target (fixes acid kinit() on cleaned kernel source tree) 2015-05-11 05:09:31 +02:00
cinap_lenrek 82a797da70 kernel: leave shared, physical and fixed segments alone in killbig() 2015-04-16 16:30:14 +02:00
cinap_lenrek ef647a54c0 kernel: cannot interrupt segmentio commands
once we submit a command to segmentio process, we have to wait
for it to complete even if we got interrupted.
2015-04-16 16:07:36 +02:00
cinap_lenrek 39cf6b34e3 kernel: avoid posting note to kernel process in faulterror()
the intend of posting a note to the faulting process is to
interrupt the syscall to give the note handler a chance
to handle it. kernel processes however, have no note handlers
and all the postnote() does is set up->notepending which will
make the next attempt to sleep raise an Eintr[] error. this
is harmless, but usually not what we want.
2015-04-16 15:31:51 +02:00
cinap_lenrek bcf54c0bfb kernel: pass segio error string by pointer
there's no need to waste space for a error buffer in the Segio
structure, as the segmentio kproc will be waiting for the next
command after an error and will not overwite it until we issue
another command.
2015-04-16 01:20:30 +02:00
cinap_lenrek 46070c3122 kernel: add segio() function for reading/writing segments
devproc's procctlmemio() did not handle physical segment
types correctly, as it assumed it can just kmap() the page
in question and write to it. physical segments however
need to be mapped uncached but kmap() will always map
cached as it assumes normal memory. on some machines with
aliasing memory with different cache attributes
leads to undefined behaviour!

we borrow the code from devsegment and provide a generic
segio() function to read and write user segments which
handles all the cases without using kmap by just spawning
a kproc that attaches the segment that needs to be read
from or written to. fault() will setup the right mmu
attributes for us. it will also properly flush pages for
segments that maintain instruction cache when written.
however, tlb's have to be flushed separately.

segio() is used for devsegment and devproc now, which
also allows for simplification of fixfault() as there is no
special error handling case anymore as fixfault() is now
called from faulting process *only*.

reads from /proc/$pid/mem can now span multiple pages.
2015-04-16 00:45:25 +02:00
cinap_lenrek 35e1aa1bfa segment: don't store pointers in a long 2015-04-13 23:35:36 +02:00
cinap_lenrek 656dd953a8 segment: fix read/write g->dlen race, avoid copying kernel memory, qlock
code like "return g->dlen;" is wrong as we do not hold the
qlock of the global segment. another process could come in
and override g->dlen making us return the wrong byte count.

avoid copying when we already got a kernel address (kernel memory
is the same on processes) which is the case with bread()/bwrite().
this is the same optimization that devsd does.

also avoid allocating/freeing and copying while holding the qlock.
when we copy to/from user memory, we might fault preventing
others from accessing the segment while fault handling is in
progress.
2015-04-13 23:18:56 +02:00
cinap_lenrek a43321946e segment: speed up fixedseg() doing single pass over freelist
walking the freelist for every page is too slow. as we
are freeing a range, we can do a single pass unlinking all
pages in our range and at the end, check if all pages
where freed, if not put the pages that we did free back
and retry, otherwise we'r done.
2015-04-12 18:08:06 +02:00
cinap_lenrek 647a1da108 segment: fix print buffer overflow, map fixed segments uncached, add to zynq kernel 2015-04-12 16:05:05 +02:00
cinap_lenrek 461c2b68a1 kernel: fixed segment support (for fpga experiments)
fixed segments are continuous in physical memory but
allocated in user pages. unlike shared segments, they
are not allocated on demand but the pages are allocated
on creation time (devsegment). fixed segments are
never swapped out, segfreed or resized and can only be
destroyed as a whole.

the physical base address can be discovered by userspace
reading the ctl file in devsegment.
2015-04-12 22:30:30 +02:00
cinap_lenrek 49fe7b0dd0 kernel: move arrow cursor definition to port/devmouse.c 2015-04-07 22:05:48 +02:00
cinap_lenrek 8caec8564d vl, libmach, kernel: mips has 16K alignment for segments (for bigpages) 2015-03-22 17:49:28 +01:00
cinap_lenrek 972cd5e3fc kernel: get rid of auxpage() and preserve cache index bits in Page.va in mount cache
the mount cache uses Page.va to store cached range offset and
limit, but mips kernel uses cache index bits from Page.va to
maintain page coloring. Page.va was not initialized by auxpage().

this change removes auxpage() which was primarily used only
by the mount cache and use newpage() with cache file offset
page as va so we will get a page of the right color.

mount cache keeps the index bits intact by only using the top
and buttom PGSHIFT bits of Page.va for the range offset/limit.
2015-03-16 05:46:08 +01:00
cinap_lenrek d0b1db98bc kernel: avoid repeated calls to reclaim(), dont miss last page in Pte
when we are skipping a process because we could not acquire
its segment lock, dont call reclaim() again (which is pointless
as we didnt pageout any pages), instead try the next process.

the Pte.last pointer is inclusive, so don't miss the last page
in pageout().
2015-03-16 05:23:38 +01:00
cinap_lenrek 4d211fdd48 kernel: fix integer overflow in syssegflush(), segment code cleanup
mcountseg(), mfreeseg():
use Pte.first/last pointers when possible and avoid constructs
like s->map[i]->pages[j].

freepte():
do not zero entries in freepte(), the segment is going away and
here is no point in zeroing page pointers. hoist common code at
the top avoiding duplication.

segpage(), fixfault():
avoid load after store for Pte** pointer.

fixfault():
return -1 in default case to avoid the "used but not set" warning
for mmuphys and get rid of the useless initialization.

syssegflush():
due to len being unsigned, the pe = PGROUND(pe) can make "chunk"
bigger than len causing a overflow. rewrite the function and deal
with page alignment and errors at the beginning.

syssegflush(), segpage(), fixfault(), putseg(), relocateseg(),
mcountseg(), mfreeseg():
keep naming consistent.
2015-03-10 18:16:08 +01:00
cinap_lenrek fcc336b902 kernel: catch address overflow in syssegfree()
the "to" address can overflow in syssegfree() causing wrong
number of pages to be passed to mfreeseg(). with the current
implementation of mfreeseg() however, this doesnt cause any
data corruption but was just freeing an unexpected number of
pages.

this change checks for this condition in syssegfree() and
errors out instead. also mfreeseg() was changed to take
ulong argument for number of pages instead of int to keep
it consistent with other routines that work with page counts.
2015-03-07 18:59:06 +01:00
cinap_lenrek 374d4ec2c1 devsd: always page align sd buffers
sdbio() tests if it can pass the buffer pointer directly to
the driver when it is already in kernel memory. we also need
to check if the buffer is properly aligned but alignment
requirement is handled in system specific sdmalloc() and
was not known to devsd.

to solve this, we *always* page align sd buffers and get rid
of the system specific sdmalloc() macro (was only used in bcm
kernel).
2015-03-06 16:16:45 +01:00
cinap_lenrek eaf91d0f8e kernel: fix physical segment handling
ignore physical segments in mcountseg() and mfreeseg(). physical
segments are not backed by user pages, and doing putpage() on
physical segment pages in mfreeseg() is an error.

do now allow physical segemnts to be resized. the segment size
is only checked in segattach() to be within the physical segment!

ignore physical segments in portcountpagerefs() as pagenumber()
does not work on the malloced page structures of a physical segment.

get rid of Physseg.pgalloc() and Physseg.pgfree() indirection as
this was never used and if theres a need to do more efficient
allocation, it should be done in a portable way.
2015-03-03 13:08:29 +01:00
cinap_lenrek fc1ff7705b devmnt: remove unused mntstats fields from Mntrpc 2015-03-01 18:56:45 +01:00
cinap_lenrek 6f1787adcb devusb: check for nil hp->dump and hp->seprintep 2015-02-20 18:56:22 +01:00
cinap_lenrek 173bafd800 devusb: fix debug ctl nil crash 2015-02-20 18:42:24 +01:00
cinap_lenrek 995379e388 usbehci: initial support for usb on zynq, remove uncached.h
the following hooks have been added to the ehci Ctlr
structore to handle cache coherency (on arm):

	void*	(*tdalloc)(ulong,int,ulong);
	void*	(*dmaalloc)(ulong);
	void	(*dmafree)(void*);
	void	(*dmaflush)(int,void*,ulong);

tdalloc() is used to allocate descriptors and the periodic
frame schedule array. on arm, this needs to return uncached
memory. tdalloc()ed memory is never freed.

dmaalloc()/dmafree() is used for io buffers. this can return
cached memory when when hardware maintains cache coherency (pc)
or dmaflush() is provided to flush/invalidate the cache (zynq),
otherwise needs to return uncached memory.

dmaflush() is used to flush/invalidate the cache. the first
argument tells us if we need to flush (non zero) or
invalidate (zero).

uncached.h is gone now. this change makes the handling explicit.
2015-02-14 03:00:31 +01:00
cinap_lenrek e8760ba636 kernel: make pagereclaim() a bit less stupid
put recently used pages at the head of ther image hash
chains, and reclaim pages from the tail first.
2015-02-07 03:01:59 +01:00
cinap_lenrek b8cf3cb879 kernel: reduce Page structure size by changing Page.cachectl[]
there are no kernels currently that do page coloring,
so the only use of cachectl[] is flushing the icache
(on arm and ppc).

on pc64, cachectl consumes 32 bytes in each page resulting
in over 200 megabytes of overhead for 32gb of ram with 4K
pages.

this change removes cachectl[] and adds txtflush ulong
that is set to ~0 by pio() to instruct putmmu() to flush
the icache.
2015-02-07 02:52:23 +01:00
cinap_lenrek b76b5901ff kernel: increase size of palloc.mem[] user page bank array
we'r hitting the limit of user page banks on some asrock mainboard,
so doubling the size of the array twice to make running out unlikely.
2015-01-30 14:50:28 +01:00
cinap_lenrek e823ddb3b0 devmnt: handle rpc buffer exhaustion on mntflushalloc()
this bug happens when the kernel runs out of mount rpc
buffers when allocating a flush rpc. in this case, mntflushalloc()
will errorjump out of mountio() leaving the currently in
flight rpc in the mount. the caller of mountrpc()/mountio()
frees the rpc thats still queued in the mount leaving
to interesting results.

for the fix, we add a waserror() arround mntflushalloc() and
handle the error case like a mount rpc failure which will
properly dequeue the rpc's in flight.
2015-01-27 22:14:26 +01:00
cinap_lenrek 68b8351f8c devdraw: remove broken color palette blanking
the code did not work as drawactive() was called with
the drawlock held. instead of fixing, the code for
palette blanking has been removed.
2015-01-02 18:48:22 +01:00
cinap_lenrek cb35d1a132 kernel: avoid inconsistent reads in /proc/#/fd and /proc/#/ns
to allow bytewise access to /proc/#/fd, the contents of the file where
recreated on each call. if fd's had been closed or reassigned between
the reads, the offset would be inconsistent and a read could start off
in the middle of a line. this happens when you cat /proc/#/fd file of
a busy process that mutates its filedescriptor table.

to fix this, we now return one line record at a time. if the line
fits in the read size, then this means the next read will always start
at the beginning of the next line record. we remember the consumed
byte count in Chan.mrock and the current record in Chan.nrock. (these
fields are free to usefor non-directory files)

if a read comes in and the offset is the same as c->mrock, we do not
need to regenerate the file and just render the next c->nrock's record.

for reads smaller than the line count, we have to regenerate the content
up to the offset and the race is still possible, but this should not
be the common case.

the same algorithm is now used for /proc/#/ns file, allowing a simpler
reimplementation and getting rid of Mntwalk state strcture.
2014-12-21 04:46:22 +01:00
cinap_lenrek e3a77e594f sdloop: hardcode Enotup[] string to avoid devaoe dependency 2014-12-19 02:38:36 +01:00
cinap_lenrek 9df9a3625c sdaoe: allow aoedev= shorthand for id!lun -> id!#æ/aoe/lun
we cannot type æ character in the bootloader console, so allow
the shorthand syntax id!lun which gets translated to id!#æ/aoe/lun.
2014-12-19 02:37:40 +01:00
cinap_lenrek d9c4637a5f kernel: remove "checked xxx page table entries" print from checkpages()
the purpose of checkpages() is to verify consitency of the hardware mmu state,
not to notify on the console that a program faulted. a program could also
continue after handling the note. (this seems to be the case in go programs)
2014-12-18 23:53:32 +01:00
cinap_lenrek f52e85826f kernel: print addresses in hex and sizes in decimal in xallocsummary 2014-12-18 23:06:39 +01:00
cinap_lenrek 0e03a5f9fd kernel: replace ulong with uintptr in ucallocb() and fix unneeded parentheses 2014-12-16 09:41:05 +01:00
cinap_lenrek 5c29603f50 kernel: remove obsolete comment regarding Mntcache size in */main.c 2014-12-16 08:11:21 +01:00
cinap_lenrek 8309f15c36 kernel: new mount cache
this is a new more simple version of the mount cache
that does not require dynamic allocations for extends.

the Mntcache structure now contains a page bitmap
that is used for quick page invalidation. the size
of the bitmap is proportional to MAXCACHE.

instead of keeping track of cached range in the
Extend data structure, we keep all the information
in the Page itself. the offset from the page where
the cache range starts is in the low PGSHIT bits and
the end in the top bits of Page.va.

we choose Page.daddr to map 1:1 the Mountcache number
and page number (pn) in the Mountcache. to find a page,
we first check the bitmap if the page is there and then
do a pagelookup() with the daddr key.
2014-12-16 05:41:20 +01:00
cinap_lenrek 523c33bb6f kernel: minor changes to mount cache
change page cache ids (bid) to uintptr so we use the full
address space of Page.daddr.

make maxcache offset check consistent in cread().

use consistent types in cupdate() and simplify with goto.

make internal functions static.

use nil instead of 0 for pointers.
2014-12-15 06:28:27 +01:00
cinap_lenrek 8d6171f1ae kernel: remove *.acid files in nuke target instead of $CONF.clean target 2014-12-14 22:25:15 +01:00
cinap_lenrek 67bed722f2 kernel: get rid of /boot/boot parametrization
there is no use for "bootdisk" variable parametrization
of /boot/boot and no point for the boot section with its
boot methods in the kernel configuration anymore. so
mkboot and boot$CONF.out are gone.

move the rules for bootfs.paq creation in 9/boot/bootmkfile.
location of bootfs.proto is now in 9/boot/bootfs.proto.
our /boot/boot target is now just "boot".
2014-12-14 22:10:34 +01:00
cinap_lenrek 4afb56f570 kernel: evaluate dependencies of bootfs.proto files for bootfs.paq
expand the list of files specified in bootfs.proto and use them
as dependencies to bootfs.paq rule. this way, bootfs.paq is
regenerated when the to be included files have been modified.
2014-12-14 00:00:59 +01:00
cinap_lenrek feb7702c9e kernel: correct dependency for printstub.$O instead of print.$O 2014-12-13 21:44:51 +01:00
cinap_lenrek 6a3b9012d5 kernel: generate dummy bootscreeninit() function when building without vga device 2014-12-13 05:29:51 +01:00
cinap_lenrek ba6cd37412 bootfs: remove disk/kfs fileserver, nobody uses it 2014-12-10 03:22:59 +01:00
cinap_lenrek 23b3407663 bootrc: add ndb/dnsgetip resolver to bootfs so domain names can be used for fs=, auth= and secstore= (thanks mischief) 2014-12-10 03:22:14 +01:00
mischief 98645db9ab devsegment: fix segmentcreate function signature 2014-12-08 23:16:22 -08:00
cinap_lenrek 9840ce91cf kernel: make use of nil vs 0 consistent in qio.c (sorry) 2014-11-13 16:46:41 +01:00
cinap_lenrek b18a641397 kernel: remove implicit Proc* argument from procctl()
procctl() is always called with up and it would not
work correctly if passed a different process, so
remove the Proc* argument and use up directly.
2014-11-09 08:19:28 +01:00
cinap_lenrek 1ffcdbab88 dont flush screen when hiding software cursor
we can avoid some flickering when removing the software cursor
from the shadow framebuffer by avoiding the flushscreenimage()
call.

once the cursor is redrawn, we flush the combined rect of its
old and new position in one go.
2014-11-08 11:48:38 +01:00
cinap_lenrek a0e001a234 devproc: reset p->pdbg under p->debug qlock in procstopwait()
theres a race where procstopwait() is interrupted by a note,
setting p->pdbg to nil *before* acquiering the lock and
and pexit() and procctl() accessing it assuming it doesnt
change under them while they are holding the lock.
2014-11-07 05:21:42 +01:00
cinap_lenrek eb6a4fc1a4 devcons: avoid division by zero reading Qsysstat
alexchandel got the kernel to crash with divide error
on qemu 2.1.2/macosx at this location. probably
caused by perfticks()/tsc being wrong or accounttime()
not having been called yet from timer interrupt yet for
some reason.
2014-09-28 02:42:33 +02:00
cinap_lenrek 19a8f66eec pc64: syscallfmt for nsec syscall 2014-09-20 01:37:11 +02:00
cinap_lenrek acd15f13c4 pc64: put return value of nsec syscall in register on amd64
WHAT WHERE THEY *THINKING*??!?!

unlike seek, the (new) nsec syscall (not used in 9front libc)
returns the time value in register (from nix), so do the same
for compatibility.
2014-09-20 01:07:46 +02:00
cinap_lenrek 694597de3b devtls: fix typo in debug print 2014-09-15 08:19:51 +02:00
cinap_lenrek e9fddbaad8 kernel: fix segattach() rounding of va+len (thanks kenji arisawa)
from segattach(2):

          Va and len specify the position of the segment in the
          process's address space.  Va is rounded down to the nearest
          page boundary and va+len is rounded up.  The system does not
          permit segments to overlap.  If va is zero, the system will
          choose a suitable address.

just rounding up len isnt enougth. we have to round up va+len
instead of just len so that the span [va, va+len) is covered
even if va is not page aligned.

kenjis example:

	print("%p\n",ap);	// 206cb0
	ap = segattach(0, "shared", ap, 1024);
	print("%p\n",ap);	// 206000

term% cat /proc/612768/segment
Stack     defff000 dffff000    1
Text   R      1000     6000    1
Data          6000     7000    1
Bss           7000     7000    1
Shared      206000   207000    1
term%

note that 0x206cb0 + 0x400 > 0x20700.
2014-09-14 16:04:22 +02:00
cinap_lenrek 3b661a96ef kernel: make noswap flag exclude processes from killbig() if not eve, reset noswap flag on exec 2014-08-17 00:50:20 +02:00
cinap_lenrek 773b57b676 kernel: fix todfix() race
we have to recheck the condition under tod lock, otherwise
another process can come in and updated tod.last and
tod.off and once we have the lock, we would make time
jump backwards.
2014-08-16 21:04:41 +02:00
cinap_lenrek ce0b77e2b9 kernel: xinit() use ulong for page counts, cleanup 2014-08-16 17:26:12 +02:00
cinap_lenrek bedffdd8c3 devenv: prevent non-hostowner from creating or removing variables in '#ec', cleanup 2014-08-13 23:09:47 +02:00
cinap_lenrek daa15d1edb kernel: more nil vs 0 cleanup in chan.c 2014-08-08 17:02:10 +02:00
cinap_lenrek ee6409366e kernel: use nil for pointers instead of 0, zero channel umc and dirrock in newchan() 2014-08-08 16:44:41 +02:00
cinap_lenrek 45333cdc92 devmnt: fix potential race with mntflushfree(), remove mntstats, 0 vs nil cleanup
when mountmux() completes a request for another process, enforce odering
of the loads and stores to the request prior to writing q->done = 1
so mntflushfree() sees q->done != 0 only when the request has actually
completed. otherwise, the q->done = 1 store could have been reordered
before the load from q->z, reading from already freed request and causing
spurious wakeups.

removing unused mntstats callback.

use nil for pointers instead of 0.
2014-08-08 23:28:47 +02:00
cinap_lenrek 0a101736b8 pc, pc64: make pc kaddr() check reject -KZERO address (thanks aiju) 2014-08-07 21:11:11 +02:00
cinap_lenrek 4f3724e6e1 devproc: nil 2014-07-15 18:51:58 +02:00
cinap_lenrek 3d3a29cd84 devproc: fix syscalltrace error handling, conistent use of nil for pointers 2014-07-15 07:54:22 +02:00
cinap_lenrek e4db040bcf devproc: fix mistake 2014-07-14 06:45:23 +02:00
cinap_lenrek 655ec332a7 devproc: fix proccrlmemio bugs
dont kill the calling process when demand load fails if fixfault()
is called from devproc. this happens when you delete the binary
of a running process and try to debug the process accessing uncached
pages thru /proc/$pid/mem file.

fixes to procctlmemio():

- fix missed unlock as txt2data() can error
- make sure the segment isnt freed by taking a reference (under p->seglock)
- access the page with segment locked (see comment)
- get rid of the segment stealer lock

other stuff:

- move txt2data() and data2txt() to segment.c
- add procpagecount() function
- make return type mcounseg() to ulong
2014-07-14 06:02:21 +02:00
cinap_lenrek 03f68c49f6 kernel: only complain about no images when theres nothing more to reclaim
uncaching a thousand pages (arround 4MB) might not be
enougth. so keep on reclaiming pages and only complain
once theres nothing more to reclaim.
2014-07-11 03:57:21 +02:00
cinap_lenrek fa03455b50 kernel: more proc.c cleanup 2014-06-23 21:51:34 +02:00
cinap_lenrek 6a05751132 kernel: make use of nil and 0 consistent in proc.c
always explicitely compare with nil if pointer.
sorry for the noise. :(
2014-06-23 21:24:12 +02:00
cinap_lenrek 7cf6a35486 kernel: fix cooperative scheduling for wired processes 2014-06-23 20:29:10 +02:00
cinap_lenrek d4d86df2ab kernel: new pagecache, remove Lock from page, use cmpswap for Ref instead of Lock
make the Page stucture less than half its original size by getting rid of
the Lock and the lru.

The Lock was required to coordinate the unchaining of pages that where
both cached and on the lru freelist.

now pages have a single next pointer that is used for palloc.head
freelist xor for page cache hash chains in Image.pghash[].

cached pages are not on the freelist anymore, but will be reclaimed
from images by the pager when the freelist runs out of pages.

each Image has its own 512 hash chains for cached page lookup. That is
2MB worth of pages and there should be no collisions for most text images.

page reclaiming can be done without holding palloc.lock as the Image is
the owner of the page hash chains protected by the Image's lock.

reclaiming Image structures can be done quickly by only reclaiming pages from
inactive images, that is images which are not currently in use by segments.

the Ref structure has no Lock anymore. Only a single long that is atomically
incremented or decremnted using cmpswap().

there are various other changes as a consequence code. and lots of pikeshedding,
sorry.
2014-06-22 15:12:45 +02:00
cinap_lenrek 1b8fb4fec3 swap: make sure swap address sticks arround until page is written to swap
we have to make sure the *swap address* doesnt go away,
after putting the swap address in the segment pte.

after we unlock the segment, the process could be
killed or fault which would cause the swap address to
be freed *before* we write the page to disk when it
pulls the page from the cache and putswap() swap pte.

keeping a reference to the page is no good. we have
to hold on the swap address. this also has the advantage
that we can now test if the swap address is still
referenced and can avoid writing to disk.
2014-06-08 17:39:40 +02:00
cinap_lenrek 72ba3571a3 kernel: remove _xinc()/_xdec()
as with the Block refcount changes, _xinc() and _xdec() arent
used anymore, so remove them.

architecure can still define ainc()/adec() when it needs them.
2014-06-08 01:35:22 +02:00
cinap_lenrek be3a5a6dc3 kernel: remove Block refcounting (thanks erik) 2014-06-08 00:19:33 +02:00
cinap_lenrek 91614f582f kernel: dont use atomic increment for Proc.nlocks, maintain Lock.m for lock(), use uintptr intstead of long for pc values
change Proc.nlocks from Ref to int and just use normal increment and decrelemt
as done in erik quanstros 9atom.

It is not clear why we used atomic increment in the fist place as even if we
get preempted by interrupt and scheduled before we write back the incremented
value, it shouldnt be a problem and we'll just continue where we left off as
our process is the only one that can write to it.

Yoann Padioleau found that the Mach pointer Lock.m wasnt maintained
consistently for lock() vs canlock() and ilock(). Fixed.

Use uintptr instead of ulong for maxlockpc, maxilockpc and ilockpc debug variables.
2014-06-05 21:54:32 +02:00
cinap_lenrek 0aa3af0934 kernel: remove wrong and needles mapsize check in newseg() (thanks Yoann Padioleau) 2014-06-03 07:47:09 +02:00
cinap_lenrek c9f91d5015 pc64: allocate palloc.pages from upages
the palloc.pages array takes arround 5% of the upages which
gives us:

16GB = ~0.8GB
32GB = ~1.6GB
64GB = ~3.2GB

we only have 2GB of address space above KZERO so this will not
work for long.

instead, pageinit() was altered to accept a preallocated memory
in palloc.pages. and preallocpages() in pc64/main.c allocates the
in upages memory, mapping it in the VMAP area (which has 512GB).

the drawback is that we cannot poke at Page structures now from
/proc/n/mem as the VMAP area is not accessible from it.
2014-06-01 03:13:58 +02:00
cinap_lenrek 15fc6c1cc0 devproc: handle 64bit address writes to /proc/n/mem files
procwrite() did truncate the offset to 32bit ulong.
introduce off2addr() function that does the sign
extension hack and use it conststently for Qmem
reads and writes.
2014-05-26 00:27:06 +02:00
cinap_lenrek 9ebbfae28b kernel: simplify fdclose() 2014-05-26 22:47:34 +02:00
cinap_lenrek 89acedb9b8 devproc: fix close and closefiles procctl
for the CMclose procctl, the fd number was not
bounds checked before indexing in the Fgrp.fd
array.

for the CMclosefiles, we looped fd from 0..maxfd-1,
but need to loop from 0..maxfd as maxfd is inclusive.
2014-05-26 22:43:21 +02:00
cinap_lenrek 2185188f83 kernel: fix read size calculation in pio() demand load
on amd64, the text segment is aligned and padded to
2MB, but segment granularity is 4K which can give
us page faults that are beyond the highest file
offset. this is perfectly valid, but was not handled
correctly in pio().
2014-05-24 01:27:57 +02:00
cinap_lenrek 3207e8b6a4 add _nsec() syscall 53 for binary compatibility with labs distribution
the new syscall is added under the symbol _nsec() for
binary compatibility.

nsec() is still a library function reading /dev/bintime.
2014-05-20 05:06:31 +02:00
cinap_lenrek a2d96d47c9 kernel: always reset notepending in eqlock, handle forceclosefgrp in eqlocks 2014-04-29 21:17:07 +02:00
cinap_lenrek b7d8431036 kernel: stop queue bloat before allocating blocks 2014-04-29 21:15:09 +02:00
cinap_lenrek 40b6959788 devmnt: make abandoning fid on botched clunk handle flushes
make mntflushfree() return the original rpc and do the
botched clunk check on the original instead of the
current rpc.

so if we get a botched flush of a clunk, we abandon the
fid of the channel as well.
2014-04-28 06:55:06 +02:00
cinap_lenrek 2c2a71cd51 devmnt: abandon fid on botched Tclunk or Tremove
if theres an error transmitting a Tclunk or Tremove request,
we cannot assume the fid to be clunked. in case this was
a transient error, reusing the fid on further requests
will fail.

as a work arround, we zero the channels fid and allocate
a new fid before the chan is reused.

this is not correct as we essentially leak the fid
on the fileserver, but we will still be able to use
the mount.
2014-04-28 05:59:10 +02:00
cinap_lenrek 41908149de nusb: resolve endpoint id conflict with different input and output types
ftrvxmtrx repots devices that use the endpoint number for
input and output of different types like:

 nusb/ether:             parsedesc endpoint 5[7]  07 05 81 03 08 00 09	# ep1 in intr
 nusb/ether:             parsedesc endpoint 5[7]  07 05 82 02 00 02 00
 nusb/ether:             parsedesc endpoint 5[7]  07 05 01 02 00 02 00	# ep1 out bulk

the previous change tried to work arround this but had the
concequence that only the lastly defined endpoint was
usable.

this change addresses the issue by allowing up to 32 endpoints
per device (16 output + 16 input endpoints) in devusb. the
hci driver will ignore the 4th bit and will only use the
lower 4 bits as endpoint address when talking to the usb
device.

when we encounter a conflict, we map the input endpoint
to the upper id range 16..31 and the output endpoint
to id 0..15 so two distinct endpoints are created.
2014-04-23 20:03:01 +02:00
cinap_lenrek fc15a01d1d kernel: add secstore and wpa to bootfs 2014-04-18 20:44:40 +02:00
cinap_lenrek 66aa949039 kernel: fix printing wrong memory sizes in pageinit(), overflowed on amd64 (thanks aram) 2014-04-15 21:34:41 +02:00
cinap_lenrek 5d3d085492 devproc: change address format in segment file to %8p (thanks eekee)
the original format for addresses was %8lux which was changed
to %p for amd64. this broke linuxemu which assumes fixed format
in the segment file. as a compromize we change it to %8p and
amd64 port of linuxemu will hopefully use a more robust parser :)
2014-04-01 19:28:10 +02:00
cinap_lenrek 4a6939c2ce devfs: fix cclose() crash in devfs error handling 2014-03-21 18:12:06 +01:00
cinap_lenrek f2f46f4a33 pc64: amd64 kernel reboot support 2014-03-16 20:22:59 +01:00
cinap_lenrek 316d8ad76b pc64: fix segattach
the comment about Physseg.size being in pages is wrong,
change type to uintptr and correct the comment.

change the length parameter of segattach() and isoverlap()
to uintptr as well. segments can grow over 4GB in pc64 now
and globalsegattach() in devsegment calculates len argument
of isoverlap() by s->top - s->bot. note that the syscall
still takes 32bit ulong argument for the length!

check for integer overflow in segattach(), make sure segment
goes not beyond USTKTOP.

change PTEMAPMEM constant to uvlong as it is used to calculate
SEGMAXSIZE.
2014-03-04 22:37:15 +01:00
cinap_lenrek 9405f4c95f kernel: getting rid of duppage() (thanks charles)
simplifying paging code by getting rid of duppage(). instead,
fixfault() now always makes a copy of the shared/cached page
and leaves the cache alone. newpage() uncaches pages as
neccesary.

thanks charles forsyth for the suggestion.

from http://9fans.net/archive/2014/03/26:

> It isn't needed at all. When a cached page is written, it's trying hard to
> replace the page in the cache by a new copy,
> to return the previously cached page. Instead, I copy the cached page and
> return the copy, which is what it already
> does in another instance. ...
2014-03-02 20:55:26 +01:00
mischief 774ccb19e4 devtls: spelling 2014-02-25 16:57:22 -08:00
cinap_lenrek 521a34d33b kernel: keep cached pages continuous at the end of the page list on imagereclaim()
imagereclaim() sabotaged itself by breaking the invariant
that cached pages are kept at the end of the page list.

once we made a hole of uncached pages, we would stop
reclaiming cached pages before it as the loop breaks
once it hits a uncached page. (we iterate backwards from
the tail to the head of the pagelist until pages have been
reclaimed or we hit a uncached page).

the solution is to move pages to the head of the pagelist
after removing them from the image cache.
2014-02-24 22:42:22 +01:00
cinap_lenrek 6b146c70c2 pc64: handle negative file offsets when accessing kernel memory with devproc
file offset is 64 bit signed integer, negative offsets
are invalid and rejected by the kernel. to still access
kernel memory on amd64, we unconditionally clear the sign
bit of the 64 bit offset in libmach and devproc sign
extends the offset back to a 64 bit address.
2014-02-08 03:50:41 +01:00
cinap_lenrek 0fdb1578ef pc64: fix devcons format strings for memory sizes 2014-02-07 23:35:27 +01:00
cinap_lenrek c3917ec566 pc64: fix poolsummary() string format 2014-02-07 23:02:56 +01:00
cinap_lenrek 868a262bb8 pc64: dont 4 byte align stack pointer for amd64 in sysexec() 2014-02-05 19:48:36 +01:00
cinap_lenrek ccfb6168c8 kernel: dont double ptemap size in newseg()
this doubling affects all segment types, not just bss.
(tho text/data are usually small...)

and theres no telling if the segment will actually
grow in the future justifying the reduction of memmove
overhead in ibrk().

some ape programs are approaching the 16mb ssegmap size
so that code might trigger.

removing the smarts...
2014-02-03 20:04:43 +01:00
cinap_lenrek f556fd2437 devdraw: screenid is BGLONG, not BGSHORT 2014-02-03 03:52:27 +01:00
cinap_lenrek b7b3406657 malloctag: only store lower 32bit of malloc tag, fix getrealloctag
as erik quanstro suggests, theres not much of a point in
storing the full 64bit pc as one cannot get a code segment
bigger than 4G and amd64 makes it hard to use a pc that
isnt 64bit sign extension of 32bit.

instead, we only store ulong (as originally), but sign
extend back when returning in getmalloctag() and
getrealloctag().

getrealloctag() used to be broken. its now fixed.
2014-02-02 16:03:59 +01:00
cinap_lenrek 0cdb32cc18 kernel: fix bogus free in sysexec.
we free the wrong pointer in the waserror() block.
2014-02-02 15:11:19 +01:00
cinap_lenrek 29eea45931 kernel: do not pass user address of fd[2] array to newfd2()
access to user memory can pagefault and newfd2() holds
fgrp spinlock while writing to it. make temporary copy
on the stack in syspipe().
2014-02-02 10:41:51 +01:00
cinap_lenrek 0b95485db7 kernel: use uintptr when appropriate in syssegflush() 2014-02-02 09:59:54 +01:00
cinap_lenrek 56343cafcf add experimental pc64 kernel 2014-02-01 10:25:10 +01:00
cinap_lenrek 06bc19c28f kernel: usb fixes for amd64 2014-02-01 10:20:43 +01:00
cinap_lenrek dcea714680 kernel: fix pointer truncation in xspanalloc(), fix format prints 2014-02-01 10:17:53 +01:00
cinap_lenrek 7613608b23 kernel: handle amd64 40 byte headers in exec() 2014-02-01 10:16:55 +01:00
cinap_lenrek 520957e254 kernel: fix ulong abuse in xalloc 2014-01-21 22:12:25 +01:00
cinap_lenrek ebfb4fdf29 kernel: convert putmmu() to uintptr for va and pa 2014-01-20 03:17:55 +01:00
cinap_lenrek ad1eefb355 kernel: various cleanups 2014-01-20 02:16:42 +01:00
cinap_lenrek 6c2e983d32 kernel: apply uintptr for ulong when a pointer is stored
this change is in preparation for amd64. the systab calling
convention was also changed to return uintptr (as segattach
returns a pointer) and the arguments are now passed as
va_list which handles amd64 arguments properly (all arguments
are passed in 64bit quantities on the stack, tho the upper
part will not be initialized when the element is smaller
than 8 bytes).

this is partial. xalloc needs to be converted in the future.
2014-01-20 00:47:55 +01:00
cinap_lenrek b99ecee6cd malloc: change malloc and realloc tag types to uintptr 2014-01-20 00:09:53 +01:00
cinap_lenrek 8a72dc1c6b kernel: fix declaration of getcallerpc() 2014-01-19 03:32:50 +01:00
cinap_lenrek 79e8f53e89 devdraw: fix memory corruption reading draw ctl file
when user does read of exactly 12*12 bytes on draw
ctl file, the snprint() adds one more \0 byte writing
beyond the user buffer and corrupting memory.

fix this by not snprint()ing the final space and add
it manually.
2014-01-14 00:22:13 +01:00
cinap_lenrek 5d9f0ed326 netif: fix wrong qid in 3rd level stats/ifstats files (thanks burnzez)
the stats and ifstats files in the 3rd level of a netif
are not per connection, but for the interface.

this made fstat fail for /net/ether0/N/*stats where N > 0
as the NETID() bits in the qid didnt compare.
2014-01-11 16:07:35 +01:00
cinap_lenrek 784e6ff8cd kernel: fix fairshare formula in comment (thanks erik) 2014-01-10 15:12:28 +01:00
cinap_lenrek 6929f0a986 kernel: simplify procalarm() 2014-01-03 02:16:18 +01:00
cinap_lenrek 8ebe3f680e alarm: skip timed out alarms when inserting in procalarm() (thanks erik)
from erik quanstros 9fans post:

i think the list insertion code needs a single-read
test that f->alarm != 0. to prevent the 0 from
acting like a fencepost.  e.g. trying to insert -10 into
list -40 -30 0 -20.

	if(alarms.head) {
		l = &alarms.head;
		for(f = *l; f; f = f->palarm) {
>>			fw = f->alarm;
>>			if(fw != 0 && (long)(fw - when) >= 0) {
				up->palarm = f;
				*l = up;
				goto done;
			}
			l = &f->palarm;
		}
		*l = up;
	}
2014-01-03 01:40:17 +01:00
cinap_lenrek 1a02a45883 kernel: nil check, exited procs handling in postnote()
make sure not to dereference Proc* nil pointer. this can potentially
happen from devip which has code like:

	if(er->read4p)
		postnote(er->read4p, 1, "unbind", 0);

the process it is about to kill can zero er->read4p at any time,
so there is the possibility of the condition to be true and then
er->read4p becoming nil.

check if the process has already exited (p->pid == 0) in postnote()
under p->debug qlock.
2014-01-01 07:39:17 +01:00
cinap_lenrek 9a98f28f1e kernel: remove error label in pgrpnote() arround postnote
postnote does not raise error, so the error label is not
neccesary.
2014-01-01 05:16:41 +01:00
cinap_lenrek f481ac716d kernel: fix alarm postnote race
when alarmkproc is commited to send the alarm note to the process,
the process might have exited already, or worse, being reused for
another process. pexit() zeros p->alarm at the beginning, but the
kalarmproc() might read p->alarm before pexit() zeroed it, decide
to send the note, then get preempted and pexit() releases the proc.
once kalarmproc() is resumed, the proc might be already something
different and we send the note to the wrong thing.

we now check p->alarm under the debug qlock. that way, pexit()
cannot make progress while we test the condition.

remove the error label arround postnote(). postnote does not raise
error.
2014-01-01 05:14:38 +01:00
cinap_lenrek 0feb6e06af devproc: fix noteid permission checks for none
make sure noteid is valid (>0).

prohibit changing note group of kernel processes. this is also
checked for in pgrpnote().

prevent "none" user from changing its note group to another "none"
sessions. this would allow him to send notes other none processes
other than its own.
2013-12-31 12:23:55 +01:00
cinap_lenrek 00ff4beaa7 kernel: check for error label stack underflow in nexterror() 2013-12-31 07:29:55 +01:00
cinap_lenrek 4c8cfe7284 kernel: remove unused debug cprint() function from port/cache.c
the cache can be inspected more easily with acid kernel library.
2013-12-29 07:50:58 +01:00
cinap_lenrek 42074003ca kernel: dont call pprint() while holding up->debug qlock
pprint() might block or even (maliciously) call into
devproc write which will corrupt the qlock chain on attempt
to qlock up->debug again.
2013-12-29 07:48:19 +01:00
cinap_lenrek afc2d547e1 kernel: make sure user text, data and bss wont overlap the stack segment in sysexec() 2013-12-29 06:11:18 +01:00
cinap_lenrek bb4aba830b devmouse: exclude sroll-wheel buttons from differential button handling
preventing wheel buttons 4 and 5 fron getting stuck
with multiple input devices.
2013-12-25 16:52:55 +01:00
cinap_lenrek 3f9867c4ce devdraw: fix drawdelname() string memory leak 2013-12-25 14:55:16 +01:00
cinap_lenrek 6946118644 devssl: use parsecmd() to process control message to get rid of 128 byte stack buffer limit
(11:02:29 PM) me: why is buf in /sys/src/9/port/devssl.c:/^sslwrite only 128 bytes?
 (11:02:58 PM) me: it makes it so you can't use a 128 bytes secret as negotiated by infauth in a secretin or secretout ctl message
 (11:03:30 PM) me: which in turn means you can't use such a secret with pushssl(2)
 (11:06:15 PM) me: inferno's sslwrite is limited to 32 bytes, but its ssl library writes to the secret files instead of to the ctl file
 (11:08:50 PM) mischief: what should it be instead of 128 bytes
 (11:08:58 PM) me: larger
 (11:09:16 PM) mischief: how about 129 bytes?
 (11:09:59 PM) me: also broken in 9front, by the way
 (11:15:14 PM) me: i guess it should be replaced with parsecmd
2013-12-16 10:06:34 +01:00
cinap_lenrek d7f90a9096 kernel: simplify pexit(), avoid making wait record for RFNOWAIT (parentless) procs
replaced the p->pid != 0 check with up->parentpid != 0 so
p->pid == up->parentpid is never true for p->pid == 0.

avoid allocating the wait records when up->parentpid == 0.
2013-12-07 08:25:26 +01:00
cinap_lenrek 7761128093 devproc: make sure /proc/n/wait waits for the right process children
theres a race when we wait for a process children and that
process exits before we sleep().
2013-12-07 07:17:32 +01:00
cinap_lenrek 4fd55abb8e kernel: fix pexit() Waitmsg memory leak.
when a process got forked with RFNOWAIT, its p->parent will still
point to the parent process, but its p->parentpid == 0.

this causes the "parent still alive" check in pexit to get confused
as it only checked p->pid == up->parentpid. this condition is *TRUE*
in the case of RFNOWAIT when the parent process is actually dead
(p->pid == 0) so we attached the wait structure to the dead parent
leaking the memory.
2013-12-07 05:38:31 +01:00
cinap_lenrek df6b68092c kernel: kproc error and exit
catch the error() that can be thrown by sleep() and tsleep()
in kprocs.

add missing pexit() calls.

always set the freemem argument to pexit() from kproc otherwise
the process gets added to the broken list.
2013-11-22 22:28:20 +01:00
cinap_lenrek def87d6016 devsd: fix scsi emulation for disks bigger than 4 billion sectors (from erik quanstros 9atom)
for read capacity (10 (0x25) if we have more than
4 billion sectors, we must not return nsectors % (1<<32),
we must return 0xffffffff.
2013-11-12 20:00:15 +01:00
cinap_lenrek 2bc9e8e5e3 kernel: make image cache not hold onto the channel, remove nocache flag
the image cache should not hold onto the text file channel
when not neccesary. now, the image keeps track of the number
of page cache references in Image.pgref. if the number of
page cache references and Image.ref are equal, this means
all the references to this image are from the page cache.
so no segments are using this image. in that case, we can
close the channel, but keep the Image in the hash table.

when attachimage() finds our image, it will check if Image.c
is nil and reattach the channel to the image before it is
used.

the Image.nocache flag isnt needed anymore.
2013-11-08 22:31:26 +01:00
cinap_lenrek 7211fd7ce7 fix devshr related panic caused by Mount.to being nil (thanks mischief!)
the shr mount is linked into the Mhead with m->to initially nil. only
after the the server has been attached is m->to set. just check for
it in createdir().
2013-10-30 21:24:44 +01:00
cinap_lenrek 8cdade591e kernel: dont spawn closeprocs from closechanq
make closeproc() spawn more procs on demand insead of
doing it from closechanq(). this avoids the palloc lock
checks and simplifies the logic.
2013-10-25 19:51:46 +02:00
cinap_lenrek c7c7e7ee2a kernel: disable freelist page caching for executables run from uncached mount
the image cache has the property of keeping a channel
for the executable binary arround which prevents the
mountpoint from going away.

this can easily be reproduced by running:

@{rfork n; ramfs; cp /bin/echo /tmp; /tmp/echo}

observe how ramfs stays arround until the image is
reclaimed. the echo binary is also cached but is
unreachable from any namespace.

we now restrict the caching to mounts that use the client
cache (-C flag) only. this should always be the case
for /bin. places where this isnt the case might observe
a performance regression.
2013-10-25 02:42:35 +02:00
cinap_lenrek b66c4a6232 kernel: keep one closeproc arround in case we are unable to fork a new one
closechanq() is unable to fork a new closeproc when palloc
is locked. so we spawn a closeproc early in chandevinit()
and make sure theres always one process arround to handle
the queue.
2013-10-25 01:54:09 +02:00
cinap_lenrek 6c6bd66ed1 devmouse: differential handling of /dev/mousein buttons 2013-10-07 06:34:24 +02:00
cinap_lenrek da2d0ee780 audiohda: allow manual pin routing, more verbose audiostat, initial mute of al widgets
the automatic routing from jack to dac/adc sometimes gets us
a path thats not audible. manually specifying a route path
gets us arround these. the syntax is just a comma separated
list of node ids in the "pin" and "inpin" audioctl commands
instead of a single pin node id.

to find alternative paths, audiostat now lists all the widgets;
not just the pins; and ther input connections.

initially mute all pins and amps of all function groups.
connectpath() and disconnectpath() will mute and unmute
the widgets as required later.
2013-09-29 15:44:26 +02:00
cinap_lenrek 62b3eea271 syssem*: eleminate redundant validaddr() checks
validaddr looks up the segments for an address range
and checks the flags and if the address range lies
within bounds on the segments.

as we'r going to lookup the segment in the syssem*
syscalls anyway, we can do the checks ourselfs avoiding
the double segment array lookups.

the implication of this tho is that now a semaphore cannot
span multiple segments. but this would be highly unusual
given that segments are page aligned.
2013-09-24 01:52:20 +02:00
cinap_lenrek b4cdfc6c55 devproc: check for p->dot == nil, run closeproc with up->dot = up->slash
p->dot can be nil when process exits (see pexit())

set closeprocs dot to up->slash so it will show up
right in devproc.
2013-09-22 19:49:59 +02:00
cinap_lenrek 34cd9dc4c4 kernel: reset up->setargs on sysexec(), fix race with devproc
up->setargs wasnt reset in sysexec(). also, up->args should only
be exchanged/freed under up->debug qlock. otherwise double free
could happen.
2013-09-18 01:07:06 +02:00
cinap_lenrek f104cc9d79 usbehci: portreset timing
assert port reset for 50ms, not 10ms.
2013-08-30 16:00:03 +02:00
cinap_lenrek 12ecb3e568 usbehci: fix portreset.
Port Reset R/W. 1=Port is in Reset. 0=Port is not in Reset. Default = 0. When
software writes a one to this bit (from a zero), the bus reset sequence as defined in the
USB Specification Revision 2.0 is started. Software writes a zero to this bit to terminate
the bus reset sequence. Software must keep this bit at a one long enough to ensure the
reset sequence, as specified in the USB Specification Revision 2.0, completes. Note:
when software writes this bit to a one, it must also write a zero to the Port Enable bit.
Note that when software writes a zero to this bit there may be a delay before the bit
status changes to a zero. The bit status will not read as a zero until after the reset
has completed.
2013-08-27 19:01:41 +02:00
cinap_lenrek 43d3c87294 devproc: properly handle exclusive refcount for /proc/trace 2013-08-27 23:57:17 +02:00
cinap_lenrek 84109a3159 devshr, devaudio: openmode()/devopen() error handling 2013-08-27 23:27:46 +02:00
cinap_lenrek 52a84514ac devmouse: fix openmode() handling
openmode() can raise error with invalid mode passed, but we already
incremented the exclusive mouse refcount at that point! call openmode()
early to avoid this.
2013-08-27 23:26:30 +02:00
cinap_lenrek 808480f76b usbehci, usbuhci: paranoia
double the td abort delay and make sure the tsleep() isnt
shortened by a pending note. in that case, tsleep() would
raise error(Eintr); immidiately and would not sleep the
requested amount potentially cauing us to release active
dma memory too early! so we wrap the tsleep() call in a
while(waserror()) so we will at least wait the Abortdelay
amount if error is raised.

also, only try to idle the still active td's.

do not copy data in epio() when there was an error, theres
no reason to touch user buffer in that case.

for uhci, we also check that theres not more data in the
buffers than requested to avoid overflowing user buffer
in epio(). this should not happen but we'r paranoid.

for ehci, we also halt the queue head first in aborttds().
mark the queue heads as Qfree after unlinking and remove
some silly nil checks that are impossible.
2013-08-25 22:03:02 +02:00
cinap_lenrek aa671181e8 add ricoh pci sdmmc host controller driver for X230
the driver should work for standard sdhc
(see http://www.sdcard.org/) controllers,
but matches for the ricoh controller only
as it was the only one i have for testing.
2013-07-14 01:33:07 +02:00
cinap_lenrek 58f8d7874b alarm: run checkalarms() only on cpu0 (from eriks alarm-once patch) 2013-06-22 09:53:14 +02:00
cinap_lenrek 769fcc82ef devcons: change /dev/kmesg buffer back to normal 16K
this makes it consistent with the manual again.
2013-06-22 01:18:27 +02:00
cinap_lenrek d7c7c7e4b3 devsrv, devshr: wstat permissions
update permissions last in wstat so it will only get changed when there was
no error.
2013-06-18 22:09:40 +02:00
cinap_lenrek 4b9845d942 devshr: fix wstat, style
- same problem with wstat, if we error then owner has been already updated...
- avoid smalloc while holding qlock in wstat, do it before
- pikeshedd style...
2013-06-18 22:02:07 +02:00
cinap_lenrek b302cc1097 devsrv: fix wstat(), srvname(), avoid smalloc() while holding srv qlock, style
- wstat would half update the Srv data structure if name was too long
- srvname() walked the linked srv list without holding srv qlock
- dont access sp->chan while not holding srv qlock in srvopen()
- dont modify sp->owner while not holding srv qlock in srvcreate()
- avoid smalloc() allocations while holding srv qlock
- style pikeshedding, sorry
2013-06-17 21:58:38 +02:00
cinap_lenrek d84aeddee7 devmnt: add debug print for convS2M failing, suspecting this causing zero length writes 2013-06-16 06:16:43 +02:00
cinap_lenrek 177c175fda kernel: allow sysr1 debugging only for hostowner 2013-06-10 01:09:52 +02:00
cinap_lenrek 723018c1de merge 2013-05-28 23:42:59 +02:00
cinap_lenrek 8cce104fcb kernel: sysrfork abortion
when we fail to fork resources for the child due to resource
exhaustion, make the half forked child process call pexit()
to free the resources that where allocated and error out.
2013-05-28 23:41:54 +02:00
cinap_lenrek 71a3ab3f13 kernel: make imagereclaim() skip notext pages (prevent it from blowing the mount cache)
imagereclaim would happily uncache pages from the mountcache (port/cache.c)
without ever getting a Image* released from it. simple fix, just check for
p->image->notext but make sure todo it under the page lock :)
2013-05-27 03:26:53 +02:00
cinap_lenrek 44e4aad870 kernel: dont copy fpsave on fork, simplify freeing waitq in pexit(), remove unused semlock from Proc sturcure 2013-05-27 01:17:11 +02:00
cinap_lenrek 410d6bea6a devfs/devsd: fix waserror() and unused variable compiler problem
the compiler optimizes setting unused variables out, which is
problematic if they are used in waserror() handler which the
compiler isnt aware of. rearrange the code to avoid this problem.
2013-05-27 01:12:21 +02:00
cinap_lenrek c4153b7755 kernel: closechanq error
catch potential interrupt error from kproc(). this can happen when
we run out of processes, then newproc() will call rsrcwait()
which does tsleep(). if the process gets a note, this might
raise a interrupt error.
2013-05-27 01:09:34 +02:00
cinap_lenrek 24b908be8a kernel: image reclaim pauses
get a bit more verbose about process image exhaustion and make
imagreclaim() try to get at least one image on the freelist.

use rsrcwait() to notify the state, and call freebroken() in
case imagereclaim() couldnt free any images.
2013-05-27 01:04:53 +02:00
cinap_lenrek 3e567afed5 kernel: fix sysexec() error handling compiler problem, sysrendez() busyloop
the variables elem and file0 and commited are explicitely
set to avoid that they get freed in ther waserror() handlers.

but it turns out the compiler optimizes this out as he
thinks the variables arent used any further. (the compiler
is not aware of the waserror() / longjmp() semantics).

rearrange the code to account for this. instead of using
a local variable to check for point of no return (commited),
we use up->seg[SSEG] to figure it out.

for file0 and elem, we just rearrange the code. elem can be
checked in the error handler if it was already assigned to
up->text, and file0 is just free()'d after the poperror().

remove silly busy loop in sysrendez. it is not needed.
dequeueproc() will make sure that the process has come to
rest.
2013-05-27 00:59:43 +02:00
cinap_lenrek 257c7e958e keep fpregs always in sse (FXSAVE) format, adapt libmach and acid files for new format
we now always use the new FXSAVE format in FPsave structure and fpregs
file, converting back and forth in fpx87save() and fpx87restore().

document that fprestore() is a destructive operation now.

change fp register definition in libmach and adapt fpr() acid funciton.

avoid unneccesary copy of fpstate and fpsave in sysfork(). functions
including syscalls do not preserve the fp registers and copying fpstate
from the current process would mean we had to fpsave(&up->fpsave); first.
simply not doing it, new process starts in FPinit state.
2013-05-26 22:41:40 +02:00
cinap_lenrek 92b550d665 kernel: prevent alarm(2) from returning instantly when the tick timer wraps. (from erik quanstros alarmwrap patch) 2013-05-21 19:31:41 +02:00
cinap_lenrek 8a3a36fc05 kernel: make allocb() wait instead of panic() when possible
as long as our process doesnt hold any locks or ilocks, we
can try to wait for the memory to become available instead of
panicing.
2013-05-21 02:29:46 +02:00
cinap_lenrek 18b8ae56e8 use resrcwait() when waiting for memory to become available
use resrcwait() when waiting for memory to become available. randomize
the sleep time and properly restore old process status in case tsleep()
gets interrupted.
2013-05-20 23:55:38 +02:00
cinap_lenrek f97798e710 devsd: don't raise Enomem error if sdmalloc() fails, instead wait for the memory to become available
filesystems do not handle i/o errors well (cwfs will abandon the blocks),
and temporary exhaustion of kernel memory (because of too many i/o's in
parallel) causes read and write on the partition to fail.

i think it is better to wait for the memory to become available in
this case. the single allocation is at max SDmaxio bytes, which makes
it likely to become available. if we havnt even enought fo that, then
rebooting the machine would be the best option. (aux/reboot)
2013-05-19 20:59:55 +02:00
cinap_lenrek 3cccb8fb12 devaoe: avoid panic on malloc() error by using smalloc() instead. 2013-05-12 19:04:07 +02:00
cinap_lenrek 25bc4e84e9 devmnt: fix mount device leak and allocation error handling in mntversion()
the fist problem is that qopen() might return nil and that kstrdup() will
sleep, so we should try to avoid holding the mntalloc lock. so we move
the kstrdup() and qopen() calls before the Mnt allocation, and properly
recover the memory if we fail later.

the second problem was that we error(Eshort) after we already created the Mnt
when returnlen < sizeof(f.version). this check has to happen *before* we
even attempt to allocate the Mnt structures. note that we only copy the
version string once everything is in the clear, so the semantics of the
user buffer not being modified in case of error is not changed.

a little cleanup in muxclose(), getting rid of mntptfree()...
2013-05-11 20:54:50 +02:00
cinap_lenrek 78794f03dd devsd: initialize unit->sense[0] in sdsetsense() (from erik quanstroms 9atom) 2013-05-02 23:12:37 +02:00
cinap_lenrek d0bb0f7757 chan: fix potential path leak on clone in namec() (from erik quanstroms 9atom) 2013-05-01 21:56:02 +02:00
cinap_lenrek 91818e7081 devpipe: fix channel and queue leaks (from erik quanstroms 9atom) 2013-05-01 19:03:56 +02:00
cinap_lenrek 0124d865a6 aoe: updating aoe driver from erik quanstros 9atom
1  the config string was grabbed Aoehsz too far into the packet due to using the wrong pointer to start.
  2  never accept a response with tag Tmgmt or Tfree.
  3  defend against "malicious" responses; ones with a response Aoehdr.type != request Aoehdr.type. this previously could
 cause the initiator to crash.
  4  vendor commands were improperly filtered out.
2013-05-01 18:50:07 +02:00
cinap_lenrek d4414b3959 devloopback: fix potential channel leak on allocation error (from eriks 9atom) 2013-05-01 18:31:13 +02:00
cinap_lenrek 4fcc5efce5 mouse: fix cursor redraw to prevent screen blanking (thanks erik) 2013-04-16 18:52:49 +02:00
cinap_lenrek c31c4ca7b3 devmouse: remove unneeded reference to kerndate 2013-04-14 18:28:55 +02:00
cinap_lenrek 3045d63969 reduce software cursor flickering
the software cursor starts flickering and reacts bumby if a process
spends most of its time with drawlock acquired because the timer interrupt
thats supposed to redraw the cursor fails to acquire the lock at the time
the timer fires.

instead of trying to draw the cursor on the screen from a timer interrupt
30 times per second, devmouse now creates a process calling cursoron() and
cursoroff() when the cursor needs to be redrawn. this allows the swcursor
to schedule a redraw while holding the drawlock in swcursoravoid() and
cursoron()/cursoroff() are now able to wait for a qlock (drawlock) because
they get called from process context.

the overall responsiveness is also improved with this change as the cursor
redraw rate isnt limited to 30 times a second anymore.
2013-04-14 16:28:54 +02:00
cinap_lenrek 800670da4e usbehci: align page td buffer for >16K transfers, fix isohsinit()
from ehci spec:

The buffer pointer list in the qTD is long enough to support a maximum
transfer size of 20K bytes. This case occurs when all five buffer pointers
are used and the first offset is zero. A qTD handles a 16Kbyte buffer
with any starting buffer alignment.
2013-04-12 22:14:32 +02:00
cinap_lenrek f37465fd7f sysexec: fix possible segment overlap with temporary stack
the kernel uses fixed area (TSTKTOP, TSTKSIZ) of the address
space to temporarily map the new stack segment for exec. for
386 and arm, this area was right below the stack segment which
has the problem that the program can map arbitrary segments
there (even readonly).

alpha and ppc dont have this problem as they map the temporary
exec stack *above* the user reachable stack segement and segattach
prevents one from mapping anything above or overlaping the stack.

lots of arch code assumes USTKTOP being the end of userspace
address space and changing this to TSTKTOP would work, but results
in lots of hard to test changes.

instead, we'r going to map the temporary stack programmatically
finding a hole in the address space where to map it. we also lift
the size limitation for arguments and allow arguments to fill
the whole new stack segement.

the TSTKTOP and TSTKSIZ are not used anymore so they where removed.

references:

http://9fans.net/archive/2013/03/203
http://9fans.net/archive/2013/03/202
http://9fans.net/archive/2013/03/197
http://9fans.net/archive/2013/03/195
http://9fans.net/archive/2013/03/181
2013-03-16 02:37:07 +01:00
cinap_lenrek 5bcc932168 netif: fix stat() on "stats" and "ifstats" files in network interface
the kernel would go into endless loop when stating "stats" and "ifstats"
files and the network interface having no connections, or otherwise return
wrong stat info.
2013-02-21 16:10:28 +01:00
cinap_lenrek 9ba9b846ee etheriwl: add /lib/firmware to bootfs.paq proto file 2013-02-10 05:04:31 +01:00
cinap_lenrek d41f67c2b9 audio: fix delay control, increase default buffer delay to 40ms
just doing a single sleep isnt enougth, as we get woken
up for every block!
2013-02-01 15:23:38 +01:00
cinap_lenrek 5a93a2a983 usbehci: remove panic() calls from interrupts if stuff isnt ready (spurious interrupts?) 2013-01-31 23:43:04 +01:00
cinap_lenrek c1cb685a32 audioac97: fix inverted recgain control, init to zero recgain
some controls are inverted. we reflect this by specifying
negative range in the volume table now and let genaudiovolread()
and genaudiovolwrite() do the conversion.
2013-01-27 17:20:42 +01:00
cinap_lenrek 43e09c468b omap: update omap kernel (from sources)
refactors of the usb ehci code and adds vfp support
2013-01-26 17:32:08 +01:00
cinap_lenrek 44eb643cb2 devuart: export uartenable() 2013-01-26 17:26:28 +01:00
cinap_lenrek 7592fa3e68 kernel: add portable uncached memory allocator (ucalloc) (from sources) 2013-01-26 17:25:23 +01:00
cinap_lenrek 14d663b169 kernel: add portable sd mmc interface (from sources) 2013-01-26 17:06:28 +01:00
cinap_lenrek e4875c1ae7 audiohda: first attempt on audio recording support for intel hda audio, distinguish mode in audio code 2013-01-19 01:12:39 +01:00
cinap_lenrek 6a0e85ad9c audioac97: audio recording 2013-01-18 13:12:41 +01:00
cinap_lenrek aa0627162b remove non standard COM3 (eia2) serial port from i8250 uart.
access to non standard serial port COM3 at i/o port 0x200 causes
kernel panic on some machines (Toshiba Sattelite 1415-S115). also,
some machines have gameport at 0x200.

i readded uartisa to the pcf and pccpuf kernel configurations so
one can use plan9.ini to add non standard uarts like:

uart2=type=isa port=0x200 irq=5
2013-01-13 10:23:31 +01:00
cinap_lenrek 77438f99c8 devtls: fix hmac buffer size for SHA1 hashes (from erik)
the buffer isn't big enough for SHA1 hashes, which are larger than MD5
hashes.
2013-01-09 06:39:20 +01:00
cinap_lenrek 8c81499659 scsi: do only 36 byte inquiry
some devices freeze up with inqiry allocation length
other than 36 bytes. as we do not really care about
the vendor specific part of the inquiry, lets only do
36 byte inquiry for now.
2013-01-03 20:46:25 +01:00
cinap_lenrek 7d8664db07 devmouse: deduplicate some code by using absmousetrack() 2013-01-03 16:05:06 +01:00
cinap_lenrek 6cadd03bbe fix utf and rune handling in preparation for 32bit runes 2012-12-31 21:09:46 +01:00
cinap_lenrek 4a4c8218ee devsd: fix possible sdbio() race with inquiry data changing (due to ahci hotplug)
the unit inquiry data might change in case the drive got pulled
with ahci. so keep track if we locked the ctl in a local stack
variable instead of relying on that the inquiry data stays the
same.
2012-12-26 17:53:12 +01:00
cinap_lenrek 5a138029db move devusb to port
moved devusb to port, shifting the responsibility of how
to enable interrupts to the arch specific hci driver.
2012-12-06 18:53:17 +01:00
cinap_lenrek 0750687012 move usb ethernet in bootfs.paq 2012-12-05 13:53:34 +01:00
cinap_lenrek 96cc3eb2ee devtls: add support for aes_128_cbc and aes_256_cbc (import from sources) 2012-12-04 10:53:53 +01:00
cinap_lenrek b296b96c68 devssl: handle bad secretin/secretout ctl arguments (import from sources) 2012-12-04 10:52:42 +01:00
cinap_lenrek b142e2a308 devpipe: import pipe wstat() support to change permissions (import from sources) 2012-12-04 10:40:08 +01:00
cinap_lenrek a8fc4ddc6d usbehci: route ports to all ehci controllers, not just the first
i belive the seizing up was a side effect of broken
bios handover. ehci will not work on the other controllers
if we do not route the ports to them.
2012-11-28 07:35:28 +01:00
cinap_lenrek 4b4070a8b9 ratrace: fix race conditions and range check
the syscallno check in syscallfmt() was wrong. the unsigned
syscall number was cast to an signed integer. so negative
values would pass the check provoking bad memory access from
kernel. the check also has an off by one. one has to check
syscallno >= nsyscalls instead of syscallno > nsyscalls.

access to the p->syscalltrace string was not protected
from modification in devproc. you could awake the process
and cause it to free the string giving an opportunity for
the kernel to access bad memory. or someone could kill the
process (pexit would just free it).

now the string is protected by the usual p->debug qlock. we
also keep the string arround until it is overwritten again
or the process exists. this has the nice side effect that
one can inspect it after the process crashed.

another problem was that our validaddr() would error() instead
of pexiting the current process. the code was changed to only
access up->s.args after it was validated and copied instead of
accessing the user stack directly. this also prevents a sneaky
multithreaded process from chaning the arguments under us.

in case our validaddr() errors, we cannot assume valid user
stack after the waserror() if block. use up->s.arg[0] for the
noted() call to avoid bad access.
2012-11-23 20:27:09 +01:00
cinap_lenrek 6f1efd37a2 limit clunk queue length for cclose()
dont let the clunk queue grow too large if we are allowed to
block (cclose) as the fileserver might run out of fids.
2012-11-07 22:04:29 +01:00
cinap_lenrek 6c8097a84d fix spurious kproc ppid
newproc() didnt zero parentpid and kproc() didnt set it, so
kprocs ended up with random parent pid. this is harmless as
kprocs have no up->parent but it gives confusing results in
pstree(1).

now we zero parentpid in newproc(), and set it in sysrfork()
unless RFNOWAIT has been set.
2012-11-07 20:46:30 +01:00
cinap_lenrek 2c4a77f21f devproc: remove pgrpid == 1 check for notepg open
assuming that this check tried to prevent the hostowner
from killing init, it is silly because init would just
handle the note.

with kbdfs, we actually want to send interrupt note to
the initial process group so instead of working arround
this with rfork(RFNOTEG|RFNAMEG), we remove the check.
2012-11-07 18:57:02 +01:00
cinap_lenrek 90cbdce8ab devdraw: fix stats for #i/winname (thanks jas) 2012-10-27 22:27:19 +02:00
cinap_lenrek 22c7584780 devproc: fix another channel leak, move the cclose(c) from proctext() to procopen. 2012-10-22 21:59:52 +02:00
cinap_lenrek 6680d50d4b fix devproc text chan leak 2012-10-22 18:51:19 +02:00
cinap_lenrek 1ee5cd7425 kernel: mnt cache rework
avoid double entries in the cache for copen() and properly handle
locking so we wont just give up if we cant lock the Mntcache entry,
but drop the cache lock, qlock the Mntcache entry, and then recheck
the cache.

general cleanup (cdev -> ccache, use eqchantdqid())
2012-10-17 15:48:30 +02:00
cinap_lenrek fcacce0f2f kernel: duppage cleanup
remove the sched() call and retry loop from duppage() and just
drop the page lock, then reacquire it after lock(&palloc).
2012-10-16 16:10:26 +02:00
cinap_lenrek 45b99937be kernel: cachedel() lock order, lookpage, cleanup
the lock order of page.Lock -> palloc.hashlock was
violated in cachedel() which is called from the
pager. change the code to do it in the right oder
to prevent deadlock.

change lookpage to retry on false hit. i assume that
a false hit means:

a) we'r low on memory -> cached page got uncached/reused

b) duppage() got called on the page, meaning theres another
cached copy in the image now.

paging in is expensive compared to the hashtable lookup, so
i think retrying is better.

cleanup fixfault, adding comments.
2012-10-16 14:12:21 +02:00
cinap_lenrek 1335be8276 swap: track swap pages with > 255 references, setswapchan() swapimage.c
swaped pages use a 8bit refcount where as the Page uses a 16bit one.
this might be exploited with having a process having a single page
swaped out and then forking 255 times to make the swap map refcount
overflow and panic the kernel.

this condition is probably very rare. so instead of doubling the
size of the swap map, we add a single 32bit refcount swapalloc.xref
which will keep the combined refcount of all swap map entries who
exceeded 255 references.

zero swapimage.c in setswapchan() after closing it as the stat() call
below might error leaving a dangeling pointer.
2012-10-15 14:04:30 +02:00
cinap_lenrek 2f732e9a85 kernel: attachimage / exec error handling
attachimage()'s approach to handling newseg() error is flawed:

a) the the image is on the hash table, but ref is still 0, and
there is no segment/pages attached to it so nobody is going to
reclaim / putimage() it -> leak

b) calling pexit() would deadlock us because exec has acquired
up->seglock when calling attachimage(), so this would just deadlock.

the fix does the following:

attachimage() will putimage() and nexterror() if newseg() fails
instead of pexit(). this is less surprising.

exec now keeps the condition variable commit which is set once
we are commited / reached the point of no return and check this
variable in the highest waserror() handler and pexit() us there.

this way we have released up all the locks and pexit() will
cleanup.

note: this bug shouldnt us hit in with the current newseg()
implementation as it uses smalloc() which would wait to
satisfy the allocation instead of erroring.
2012-10-14 19:48:46 +02:00
cinap_lenrek 16d61d3c97 kernel: try to catch some (rare) mistakes
kstrcpy() did not null terminate for < 4 byte buffers. fixed,
but i dont think there is any case where this can happen in
practice.

always set malloctag in kstrdup(), cleanup.

always use ERRMAX bounded kstrcpy() to set up->errstr, q->err
and note[]->msg. paranoia.

instead of silently truncating interface name in netifinit(),
panic the kernel if interface name is too long as this case
is clearly a mistake.

panic kernel when filename is too long for addbootfile() in
devroot. this might happen if your kernel configuration is
messed up.
2012-10-11 17:29:16 +02:00
cinap_lenrek 73e7e47d5b kenrel: simplify image cache by use of ccloseq() 2012-10-10 08:22:35 +02:00
cinap_lenrek 9e7ecc41d5 devproc buffer overflow, strncpy
in devproc status read handler the p->status, p->text and p->user
could overflow the local statbuf buffer as they where copied into
it with code like: memmove(statbuf+someoff, p->text, strlen(p->text)).
now using readstr() which will truncate if the string is too long.

make strncpy() usage consistent, make sure results are always null
terminated.
2012-10-01 02:52:05 +02:00
cinap_lenrek 5d64e428eb fix devproc and killbig segment race
we have to acquire p->seglock before we lock the individual
segments of the process and lock them. if we dont then pexit()
might free the segments before we can lock them causing the
"qunlock called with qlock not held, from ..." prints.
2012-09-30 16:14:27 +02:00
cinap_lenrek 336df4d4ae Qcoalesce patch to satisfy full read length 2012-09-14 03:35:15 +02:00
cinap_lenrek 9c18f300a4 devshr: honor noattach 2012-09-06 01:05:37 +02:00
cinap_lenrek 0c52215ae3 usb: fix potential isoread overruns, error instead of panic on isoread in ohci 2012-09-03 04:23:02 +02:00
cinap_lenrek cfd25faa28 usb: fix isowrite putsamples race 2012-09-03 01:54:34 +02:00
aiju 5ba4ccd30e fixed RFNOMNT 2012-08-27 17:50:48 +02:00
cinap_lenrek 3ac4524e4a syscallfmt: use up->syserrstr instead of up->errstr (import from sources) 2012-08-24 15:53:35 +02:00
cinap_lenrek 86f323290c wait: always check up->nchild before going to sleep
always make sure that there are child processes we can wait for
before sleeping.

put pwait() sleep into a loop and recheck. this is not strictly
neccesary but prevents accidents if there are spurious wakeups
or a bug.
2012-08-24 13:11:04 +02:00
cinap_lenrek d404e9e9f8 devmnt: more carefull wakeup in mountmux
once we set q->done = 1 in mountmux, the sleeper might return freeing q
so the wakeup might access invalid memory. we change the embedded Rendez
structure in the Mntrpc into a pointer to the sleeping procs up->sleep
rendez so the rendez is always going to be valid even if the rpc has been
freed.

the call to mntstats was moved before we set q->done also to prevent
accessing invalid memory.
2012-08-24 13:00:14 +02:00
aiju b21b9ba89c added hjfs 2012-08-07 17:57:04 +02:00
cinap_lenrek 36adf27af8 add Echange[] error string 2012-08-07 07:15:41 +02:00
cinap_lenrek fcc5e75d07 tsemacquire: manpage and syscallfmt 2012-07-30 22:45:49 +02:00
cinap_lenrek 49ac0b93d3 add tsemacquire syscall for go 2012-07-29 20:26:49 +02:00
cinap_lenrek a360bddee7 qio: raise critical queue bloat threshold from 2 to 10 times to queue limit
the limit for overqueueing was too small for stuff like fcp
on a fileserver connected with a standard 32K limit pipe like
ramfs.

fcp usesd 8K*16procs > 32K*2

the biggest queue limit used in the kernel is 256K making
the maximum queue bloat 2.5MB or 320K for standard pipes.
that should be big enougth to never happen in practice
unless there is a bug which we like to catch before we
exhaust all kernel memory.
2012-07-08 19:11:29 +02:00
cinap_lenrek 1de9ca2de5 bring back il protocol support 2012-05-03 10:47:40 +02:00
cinap_lenrek 7f04d86dfb kernel: move duplicated random.c to port 2012-05-03 08:49:25 +02:00
cinap_lenrek 1d42b2dac1 avoid leaking up->dot into the closeproc 2012-04-28 09:12:04 +02:00
cinap_lenrek e440d414d5 fix missed clunkq wakeup race 2012-04-27 18:51:15 +02:00
cinap_lenrek 6bd82b34fd async clunk for cached mounts, fix closeproc explosion 2012-04-27 17:51:20 +02:00
cinap_lenrek 73b7f5f12c panic: trailing newlines 2012-03-28 18:13:45 +02:00
cinap_lenrek c3004ddf25 port/chan.c: fix locking issue 2012-03-28 18:11:09 +02:00
cinap_lenrek f0facb2ed8 usbehci: import changes from sources (portreset, port handover handling), set interrupt threshold to 1 uframe 2012-03-07 23:50:58 +01:00
cinap_lenrek f2b6ec3140 correcting unicode superscripts for 1 2 and 3 2012-02-23 16:58:53 +01:00
cinap_lenrek 5b07f6238b devdraw: use QLock to serialize sleep on refresh to prevent double sleep 2012-02-20 10:49:14 +01:00
cinap_lenrek 77c21a062c kernel: remove duppage debug, add comments, cleanup 2012-02-16 18:04:08 +01:00
cinap_lenrek 083612b34e kernel: duppage checking 2012-02-16 11:38:50 +01:00
cinap_lenrek 4780a7ff56 devmouse: add twitch mousectl command 2012-02-13 07:06:08 +01:00
cinap_lenrek 061d55111b add Etoolong error string, cleanup genbuf truncation fix 2012-02-08 02:32:03 +01:00
cinap_lenrek 022fd02b96 fix endless devwalk loops caused by genbuf truncation 2012-02-08 00:00:42 +01:00
cinap_lenrek 5acde1e791 make smalloc() uninterruptable as most callers cant handle it anyway 2012-02-06 05:28:57 +01:00
cinap_lenrek 9d60d8262e fix potential double ready in postnote() for rendezvous 2012-02-06 00:23:38 +01:00
cinap_lenrek 3599f733ee more checking for eqlock 2012-02-05 20:52:12 +01:00
cinap_lenrek 8d22d0b165 devuart: fix no memory panic with zero number of uarts 2012-02-04 16:41:46 +01:00
cinap_lenrek 8ef32ed38c fix double free in exec 2012-01-23 05:12:05 +01:00
cinap_lenrek e2bbb41a30 fix unlock(&procalloc) race on mp systems 2012-01-22 22:33:15 +01:00
cinap_lenrek 413ab7785f eqlock: cleanup 2012-01-15 14:31:53 +01:00
cinap_lenrek 577d31ab13 fix race condition of the CCACHE flag by clearing the flag in
attachimage() instead of temporarily reseting in pio().
2012-01-12 12:54:45 +01:00
cinap_lenrek 659943558f kernel: keep segment locked for data2txt 2012-01-09 21:33:22 +01:00
cinap_lenrek 85fd5bf58d eqlock: dont rely on notepending flag when detecting eqlock interruption 2012-01-09 21:18:03 +01:00
cinap_lenrek 2131248411 swap: make sure swapchan doesnt use the mntcache 2011-12-22 02:33:49 +01:00
cinap_lenrek ea5a23d39a kernel: make mntcache effective, be carefull 2011-12-22 02:17:29 +01:00
cinap_lenrek 4fe344847c kernel: better pidalloc() 2011-12-21 23:08:15 +01:00
cinap_lenrek 2450b55c7b kernel: add pidalloc() and reuse pid once the counter wraps arround 2011-12-20 22:22:08 +01:00
cinap_lenrek bef3c5a3c5 devfs: dont raise "no more trees" if malloc fails 2011-12-13 16:12:40 +01:00
cinap_lenrek 1238374df9 killbig(): fix crash if no process could be found 2011-12-13 16:10:37 +01:00
cinap_lenrek 36dc22fd57 panic(): dont print message twice. for terminals, dont auto reboot. 2011-12-13 16:07:52 +01:00
cinap_lenrek f32ef135d4 devbridge: fix 2011-12-12 19:28:21 +01:00
cinap_lenrek 3028437f8b glitch :-) 2011-12-12 19:20:40 +01:00
cinap_lenrek 8cb8043d0e kernel: fix more malloc/smalloc errors 2011-12-12 19:17:58 +01:00
cinap_lenrek 304ee3b2b5 devfs: fix cryptio memory leak 2011-12-12 19:17:24 +01:00
cinap_lenrek bf3476d661 kernel: fix inproper use of malloc/smalloc 2011-12-12 16:55:26 +01:00
cinap_lenrek 589f99915e devssl: tiny fixes (from plan 9) 2011-12-12 14:59:14 +01:00
cinap_lenrek 077537baeb fix cdrom media change 2011-12-06 14:49:40 +01:00
cinap_lenrek 30907f1d00 devmouse: allow multiple writers on /dev/mousein 2011-11-03 02:33:09 +01:00
cinap_lenrek 4c05d129e2 eqlock: fix postnote/qunlock race 2011-11-02 21:39:30 +01:00
cinap_lenrek 3fce94e785 fix _tos->pcycles, make _tos->kcycles actually count cycles executing kernel code on behalf of the process 2011-10-25 20:17:39 +02:00
cinap_lenrek 0089c44663 devcons: readd dummy consctl file so telnetd has something to bind on 2011-09-17 02:35:03 +02:00
cinap_lenrek 513bdcccdc chan: use chanpath() in chan DBG, do more checking in cclose and cclone 2011-09-02 14:12:39 +02:00
cinap_lenrek cd47b3e9d4 bootrc: prefer 9660 filesystem as default on cdboot, restart factotum, delay for usb 2011-08-28 20:37:20 +02:00
cinap_lenrek a6e3c9fd83 calculate the real number of pages used by segments and use it for killbig and proc 2011-08-26 04:47:34 +02:00
cinap_lenrek cf974eb852 fix kernel: pio()/mfreeseg() race 2011-08-24 14:43:15 +02:00
cinap_lenrek 61a0117ea5 swap: do less print spamming, sched after killbig so killed proc can get released 2011-08-24 07:58:14 +02:00
cinap_lenrek 5182bb7ecf dont hang if swap is full 2011-08-24 06:52:24 +02:00
aiju 8434f98cdd added interrupt proc ctl message 2011-08-20 12:30:06 +02:00
cinap_lenrek 79a044e38e usb: fix potential uninterruptable calls 2011-08-19 05:19:10 +02:00
cinap_lenrek c44b78f739 change definition of Chan.create to return a chan like open 2011-08-17 23:27:31 +02:00
cinap_lenrek 72304eb350 fix broken cross platform build 2011-08-17 23:25:22 +02:00
cinap_lenrek f682600440 serial console stuff 2011-08-16 10:15:36 +02:00
cinap_lenrek cb9e638c00 bind devshr to /shr 2011-08-16 01:49:37 +02:00
cinap_lenrek b39d5fbbef devshr: security! 2011-08-15 18:27:30 +02:00
cinap_lenrek 945e2a7aa1 devshr/devsrv 2011-08-14 11:11:51 +02:00
cinap_lenrek 4ec0e921e5 eqlock(): use eqlock when interruption is possible 2011-08-11 04:25:51 +02:00
cinap_lenrek e9d441fccf eqlock(): use separate lock to protect eql, fix missing unlock 2011-08-11 23:02:48 +02:00
cinap_lenrek 4b506cd0ae qio: fix block leak introduced by eqlock change 2011-08-10 17:26:05 +02:00
cinap_lenrek 70e4b8d1f9 added eqlock(), a interruptable version of qlock. addresses issue #81 2011-08-10 16:21:17 +02:00
cinap_lenrek 676a876df6 usb: added buffer delay control 2011-08-01 19:02:50 +02:00
aiju 6aed9711b4 devshr: changed #σc to contain directories
nusb: detaching
2011-07-30 14:30:27 +02:00
cinap_lenrek f9846213d1 nusb: change usbevent format, put nusbrc in bootfs 2011-07-30 07:23:26 +02:00
aiju 27fd88af23 devshr: rename hook 2011-07-28 14:22:39 +02:00
aiju c08f86254e devshr: fixed crash 2011-07-27 10:40:21 +02:00
aiju d2a1d1fb37 devshr: fixed memory leaks / race condition 2011-07-25 10:10:11 +02:00
aiju e1260aa4d6 devshr: added unmounting 2011-07-24 14:51:49 +02:00
aiju 8784d2d0ea added devshr 2011-07-24 22:12:01 +02:00
cinap_lenrek a7a56b9a48 devaudio: ignore non absolute volume items with range 0 2011-07-21 01:24:18 +02:00
aiju 11bf57fb2c add message on OOM kill, fix issue #70 2011-07-18 10:12:45 +02:00
cinap_lenrek c6c2e04d4a segdesc: add /dev/^(ldt gdt) support 2011-07-12 15:46:22 +02:00
cinap_lenrek c2fc2fad13 merge sd changes from 9atom 2011-07-10 14:14:23 +02:00
cinap_lenrek b222c16a38 qio: naive fixing attempt on issue #64 2011-07-09 13:15:39 +02:00
cinap_lenrek b274842f5c audio: cleanup 2011-07-03 05:56:53 +02:00
cinap_lenrek 86f316987d audio: add delay control 2011-07-03 03:42:37 +02:00