* [9fans] kernel bug
@ 2014-06-03 1:14 Yoann Padioleau
2014-06-03 5:49 ` cinap_lenrek
` (3 more replies)
0 siblings, 4 replies; 11+ messages in thread
From: Yoann Padioleau @ 2014-06-03 1:14 UTC (permalink / raw)
To: Fans of the OS Plan 9 from Bell Labs
Hi,
in the newseg() function there is:
mapsize = ROUND(size, PTEPERTAB)/PTEPERTAB;
if(mapsize > nelem(s->ssegmap)){
mapsize *= 2;
if(mapsize > (SEGMAPSIZE*PTEPERTAB))
mapsize = (SEGMAPSIZE*PTEPERTAB);
s->map = smalloc(mapsize*sizeof(Pte*));
s->mapsize = mapsize;
}
else{
s->map = s->ssegmap;
s->mapsize = nelem(s->ssegmap);
}
I think it should be
if(mapsize > (SEGMAPSIZE))
mapsize = SEGMAPSIZE;
Also why in the kernel they use 'struct Pte' instead of the better name Pagetable.
In many places this is very confusing because when I see Pte I think of a Pagetable Entry
where really they are speaking about a Pagetable.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [9fans] kernel bug
2014-06-03 1:14 [9fans] kernel bug Yoann Padioleau
@ 2014-06-03 5:49 ` cinap_lenrek
2014-06-03 6:00 ` Anthony Martin
` (2 subsequent siblings)
3 siblings, 0 replies; 11+ messages in thread
From: cinap_lenrek @ 2014-06-03 5:49 UTC (permalink / raw)
To: 9fans
good catch. thank you.
--
cinap
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [9fans] kernel bug
2014-06-03 1:14 [9fans] kernel bug Yoann Padioleau
2014-06-03 5:49 ` cinap_lenrek
@ 2014-06-03 6:00 ` Anthony Martin
2014-06-03 15:47 ` erik quanstrom
2014-06-03 16:08 ` Charles Forsyth
3 siblings, 0 replies; 11+ messages in thread
From: Anthony Martin @ 2014-06-03 6:00 UTC (permalink / raw)
To: Fans of the OS Plan 9 from Bell Labs
Yoann Padioleau <pad@fb.com> once said:
> in the newseg() function there is:
>
> [...]
>
> I think it should be
> if(mapsize > (SEGMAPSIZE))
> mapsize = SEGMAPSIZE;
Yes, you're correct.
The code allows the creation of a segment VM map with more
than SEGMAPSIZE Ptes.
Personally, I'd remove the check entirely along with the
optimization of doubling the segment size, perhaps moving
it to ibrk. I think it's more likely that the segment will
grow if brk is called at least once.
Anthony
P.S. It looks like this is a 15 year old bug:
1998/0916/sys/src/9/port/segment.c:62,67 - 1998/0919/sys/src/9/port/segment.c:62,70
mapsize = ROUND(size, PTEPERTAB)/PTEPERTAB;
if(mapsize > nelem(s->ssegmap)){
+ mapsize *= 2;
+ if(mapsize > (SEGMAPSIZE*PTEPERTAB))
+ mapsize = (SEGMAPSIZE*PTEPERTAB);
s->map = smalloc(mapsize*sizeof(Pte*));
s->mapsize = mapsize;
}
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [9fans] kernel bug
2014-06-03 1:14 [9fans] kernel bug Yoann Padioleau
2014-06-03 5:49 ` cinap_lenrek
2014-06-03 6:00 ` Anthony Martin
@ 2014-06-03 15:47 ` erik quanstrom
2014-06-03 15:56 ` andrey mirtchovski
2014-06-04 19:12 ` Anthony Martin
2014-06-03 16:08 ` Charles Forsyth
3 siblings, 2 replies; 11+ messages in thread
From: erik quanstrom @ 2014-06-03 15:47 UTC (permalink / raw)
To: 9fans
> I think it should be
> if(mapsize > (SEGMAPSIZE))
> mapsize = SEGMAPSIZE;
hmm. i think this code is correct. ssegmap is a static map
to handle small segments. small segments fit in ssegmap.
the point must have been to avoid malloc.
this test is a little more questionable
> if(mapsize > (SEGMAPSIZE*PTEPERTAB))
> mapsize = (SEGMAPSIZE*PTEPERTAB);
cf. the check in ibrk
if(newsize > (SEGMAPSIZE*PTEPERTAB)) {
qunlock(&s->lk);
error(Enovmem);
}
i think this check is either not wrong, or more extensive rework
is necessary.
@anthony, do you know if this code or similar occurred in even older kernels?
if there was a cap also in ibrk() then i would suspect this code was originally
correct.
i don't know where a history of stuff older than sources (2002) is.
> Also why in the kernel they use 'struct Pte' instead of the better name Pagetable.
> In many places this is very confusing because when I see Pte I think of a Pagetable Entry
> where really they are speaking about a Pagetable.
i would naturally think a Pte* would be an array of Pte's, i.e. a Pte table,
just like an array of uchar* could be used as a table.
- erik
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [9fans] kernel bug
2014-06-03 1:14 [9fans] kernel bug Yoann Padioleau
` (2 preceding siblings ...)
2014-06-03 15:47 ` erik quanstrom
@ 2014-06-03 16:08 ` Charles Forsyth
2014-06-03 17:08 ` erik quanstrom
3 siblings, 1 reply; 11+ messages in thread
From: Charles Forsyth @ 2014-06-03 16:08 UTC (permalink / raw)
To: Fans of the OS Plan 9 from Bell Labs
[-- Attachment #1: Type: text/plain, Size: 436 bytes --]
On 3 June 2014 02:14, Yoann Padioleau <pad@fb.com> wrote:
> if(mapsize > (SEGMAPSIZE*PTEPERTAB))
> mapsize = (SEGMAPSIZE*PTEPERTAB);
>
...
>
>
I made the change you suggest in the PAE kernel but perhaps Erik missed it
during his merge:
if(mapsize > nelem(s->ssegmap)){
mapsize *= 2;
if(mapsize > SEGMAPSIZE)
mapsize = SEGMAPSIZE;
s->map = smalloc(mapsize*sizeof(Pte*));
s->mapsize = mapsize;
}
[-- Attachment #2: Type: text/html, Size: 1689 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [9fans] kernel bug
2014-06-03 16:08 ` Charles Forsyth
@ 2014-06-03 17:08 ` erik quanstrom
2014-06-03 18:04 ` Charles Forsyth
0 siblings, 1 reply; 11+ messages in thread
From: erik quanstrom @ 2014-06-03 17:08 UTC (permalink / raw)
To: 9fans
> I made the change you suggest in the PAE kernel but perhaps Erik missed it
> during his merge:
> if(mapsize > nelem(s->ssegmap)){
> mapsize *= 2;
> if(mapsize > SEGMAPSIZE)
> mapsize = SEGMAPSIZE;
> s->map = smalloc(mapsize*sizeof(Pte*));
> s->mapsize = mapsize;
> }
ok. good. that's what happened. perhaps some change needs
to be made to segattach to mirror this change.
- erik
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2014-06-04 19:12 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-03 1:14 [9fans] kernel bug Yoann Padioleau
2014-06-03 5:49 ` cinap_lenrek
2014-06-03 6:00 ` Anthony Martin
2014-06-03 15:47 ` erik quanstrom
2014-06-03 15:56 ` andrey mirtchovski
2014-06-03 16:04 ` erik quanstrom
2014-06-04 19:12 ` Anthony Martin
2014-06-03 16:08 ` Charles Forsyth
2014-06-03 17:08 ` erik quanstrom
2014-06-03 18:04 ` Charles Forsyth
2014-06-03 18:09 ` Charles Forsyth
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).