From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Thread: fdd80,5cdb0c1dbaceb85b X-Google-NewGroupId: yes X-Google-Thread: ffc31,5cdb0c1dbaceb85b X-Google-NewGroupId: yes X-Google-Thread: 1164f8,5cdb0c1dbaceb85b X-Google-NewGroupId: yes X-Google-Attributes: gide311f70d09,gidf4c4f7386e,gidd180ab3bd8,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.221.4 with SMTP id qa4mr17355189pbc.7.1329924361617; Wed, 22 Feb 2012 07:26:01 -0800 (PST) Path: wr5ni55644pbc.0!nntp.google.com!news1.google.com!goblin3!goblin.stu.neva.ru!news.cgarbs.de!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!cs.uu.nl!news.stack.nl!newsfeed.Update.UU.SE!news.Update.UU.SE!not-for-mail From: Johnny Billquist Newsgroups: alt.sys.pdp11,vmsnet.pdp-11,comp.sys.dec Subject: Re: PDP11 Values from MFPT Date: Wed, 22 Feb 2012 16:26:00 +0100 Organization: Update Computer Club Message-ID: References: <4f3f4ae9.40953632@nntp.aioe.org> <4f3f6194.19510701@nntp.aioe.org> <4f41dd56.1857737@nntp.aioe.org> <4f4434a7.18816544@nntp.aioe.org> <4f43806e.38215767@nntp.aioe.org> <4f45b539.51730368@nntp.aioe.org> <4f45dd3a.40560415@nntp.aioe.org> NNTP-Posting-Host: 2620:0:105f:b:462a:60ff:fefb:aad8 Mime-Version: 1.0 X-Trace: Iltempo.Update.UU.SE 1329924360 15681 2620:0:105f:b:462a:60ff:fefb:aad8 (22 Feb 2012 15:26:00 GMT) X-Complaints-To: newsmaster@Update.UU.SE NNTP-Posting-Date: Wed, 22 Feb 2012 15:26:00 +0000 (UTC) User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 In-Reply-To: <4f45dd3a.40560415@nntp.aioe.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 2012-02-22 13.21, paramucho wrote: > On Tue, 21 Feb 2012 20:43:34 +0100, Johnny Billquist > wrote: > >>> System waits ("blocks") may terminate prematurely because of various >>> conditions, including stuff that ASTs do. So, when a system wait >>> returns, the routine has to make sure that it's actual condition has >>> been satisfied, and if it hasn't then it reissues the system wait. The >>> stack is not a problem. >> >> So you need to restart the system call. What if it is a system call that >> have been partially completed? The wait does not happen as a unique part >> of the call. > > A system wait *is* a unique part of a system call. You don't need to > restart the system call. The "wait" is a loop which retests a wait > condition. That's all. But there is a problem here. Can't you see it? If you are sitting in a wait loop in the kernel, how do you get back out to user state in a way that will allow you to get back into the wait loop with a preserved context, without exposing the kernel to userspace manipulatio? Normally this is not a problem, because you do not call out from kernel to userspace. Userspace do a system call, and eventually it returns. You do not have code in kernel space escaping back out into userspace, and then userspace returns back into kernelspace, where execution continues. Therein lies the problem. From userspace, the system call is a single instruction. It is either performed, or not. Not half-done. However, by having the kernel call back out to user space in the middle of a system call, you both violate that view, and you require kernel context to be kept around while back in user space, at which time a context switch can again take place, not to mention other system calls taking place. So, how do you keep the context for the first system call around when the next system call happens? And what do you expect to be on the stack? And what if the second system call also cause a wait? There is a big can of worms here. >> Oh, wait, I bet you are thinking in terms of RT-11 here, where the >> distinction between user mode and kernel mode is rather blurry. >> >> In Unix, as an example, there is no context around to restart in the >> middle of a system call. What you have left is the context at user mode, >> which is then the start of the system call again. >> And this is because a signal is delivered in user mode, so the process >> gets out of the kernel, in order to run the signal handler. There is no >> way you can keep the kernel context for the user process around at that >> point. It can not live on the kernel stack, since you exited from the >> kernel. It can not live on the user stack, since that would allow you to >> break the security of the kernel. > > I don't know anything about Unix internals but I have the feeling that > it's not a good example because, like RSX, it doesn't have a reentrant > kernel where RT, RUST and VMS do. This is not about reentrancy. And yes, the Unix kernel is reentrant. You can have several processes doing and blocking on the same system call in parallel. Since RSX don't really have the scenario at all, it isn't really helpful to talk about reentrancy in the RSX case. But as far as anything is concerned, most anything is reentrant in RSX. But even bring that term up is a red herring. > I still think your looking at the issue from an RSX angle when you say > "exited from the kernel", in particular when you say the context "can > not live on the kernel stack". Kernel and user mode context are both > active during all process activity. The key piece of kernel > information to save across the ast is in fact the kernel fp/sp before > the ast. When an ast exits it returns to a piece of code which issues > a system call to handle ast exit. Nope. Since this isn't even a problem in RSX. It is a problem in Unix, it is a problem in VMS. Both of them have system calls that can be aborted with the error code that you need to redo the system call again. Which is the Unix solution to the problem. Other systems instead backs out and redo the system call after it has been interrupted. You seem to be pretty alone in thinking that you can just ignore it. > There are rules which forbid one or two scenarios. For example, I > don't think you can run a kernel ast when a user ast is running. In > such cases the kernel ast is delayed. Don't know about RT-11, but in VMS, as well as RSX, when one AST is executing, all other ASTs are blocked for that process. All ASTs are queued for the process, and kernel ASTs are added to the head of the queue, while user ASTs are added to the tail. So all ASTs (no matter which type) are delayed when an AST is in progress. > However, there is nothing in the VMS sources about restarting system > calls because of ASTs, or anything else for that matter. My memory was incorrect. I can't find anything about aborting system calls because of ASTs. I'll look some more. The only errors meaning please restart system calls are from resource shortages. However, VMS can block processes, making them deaf and dumb instead, which seems to be the normal behavior there. That's all your resource waits. No wonder VMS have lousy response times. You cannot be sure ASTs are delivered anywhere near the time they were queued. And resource waits are basically mutexes for the process. And they can happen for a number of reasons. And no, you do not break out of a resource wait just because you get an AST. In Unix, you get the system call aborted. In VMS, at some sensitive places you instead have the process go deaf and dumb. Now, if you consider that better or worse than Unix, I don't know. I totally dislike both solutions. >>> In the RT-11 sources you'll see a bunch of calls to $SYSWT which >>> implement this logic for RT-11. $SYSWT uses co-routines, so they're >>> even more convoluted than RT-11 usually is. >>> >>> I had a look at my RUST/XM system wait code tonight, and I think I >>> understand it. The "$stall #10$, prwhi" issues the system wait, with >>> 10$ as the continuation address after the system wait and prwhi. >>> (hibernation) as the system wait state. >>> >>> em$spd:: ;suspend >>> 10$: mov p$hpcr,r4 ;get the pcr >>> $float ;stop the scheduler >>> mov pr.sta(r4),r0 ;get the status >>> bic #prwak$,pr.sta(r4) ;clear the bit >>> bit #stact$,p$hast ;are we in an AST? >>> bne 20$ ;yes - forget the rest >>> bit #prwak$,r0 ;did we get a wake up? >>> bne 20$ ;yes >>> $stall #10$, prwhi. ;hibernate >>> 20$: $land >>> return >>> >>> em$rsm:: ;resume >>> mov p$hpcr,r4 ;get the pcr >>> bis #prwak$,pr.sta(r4) ;set wake pending >>> return >>> >>>> See http://en.wikipedia.org/wiki/PCLSRing for more details. >>> >>> That seems to be some other issue. >> >> No. It is totally the issue. See my comments above. >> >> RT-11 can, however, get away with some things that you cannot do in >> systems where user mode and kernel mode are totally separate and >> isolated from each other. > > What do you think the (RUST) code above is "getting away with"? I did not initially even look at your code, since it didn't seem that relevant. Code in RT-11 in general do not (nor need) the strict separation between userspace and kernel space. That is what I was referring to with the "get away with" comment. It is much more ok to call back from the kernel to the user program in RT-11, since there are no security considerations to take. But if I read things right, you get to em$spd when you are about to suspend a process, and call em$rsm to wake a process up? So, if you are in an AST, you will never suspend, otherwise you will unless the wake bit have been set. There is way too little here to see or comment much more about. How do you deliver an AST? Where does that happen, and in which context? How is the AST invoked, and how is it returned from? What happens if you do system calls in the AST routine? And if those need to block? > BTW: user mode and kernel mode have the same memory map in VMS. They > are certainly not totally isolated. In mapped RT-11 and RUST systems > they are quite separate. Since in VMS (well, on a VAX anyway, but I assume on all architectures) you only have one memory map, that is not really relevant. User mode cannot access, or even see pages in the kernel. And cannot access the kernel stack. The kernel is totally isolated from the user mode. Kernel can, however, access all memory of the user. Not really different than from a PDP-11, even though there you have different mappings depending on which mode the processor is in. The only way to get from user mode to kernel mode is by causing a trap, which the kernel will handle, and then do something (for example a system call). You cannot "return" from user mode to kernel mode, or call random addresses in kernel mode from user mode, or even check any data the kernel holds. >> Assuming I'm right, I can see why a lot of discussion and confusion >> comes up between us. The conditions in RT-11 are rather different than >> other systems, meaning you can do stuff that is totally impossible in >> other OSes. > > There is a good deal of flexibility unmapped RT-11 systems (e.g. > RT-11/SJ, RT-11/FB and RUST/SJ), but in the mapped systems (RT-11/XM, > RUST/XM) much of that flexibility is lost. I guess some of it must be lost by just having memory being mapped away in different directions. Johnny