9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Sean Quinlan sean@CS.Stanford.EDU
Subject: No subject
Date: Tue,  1 Mar 1994 19:47:03 -0500	[thread overview]
Message-ID: <19940302004703.Eh4jscjan5FlmUNoydmcK4Gww4V082zozs4et7dBQ_k@z> (raw)


There is a problem with the plan9 memory management system for the PC
due to one of the brain dead features of the 386 architecture.
In particular, the R/W bit in a user page table entry is ignored when
the processor is in supervisor mode.  This means that copy on write will
not work when the kernel is copying into user space.
For example the following code segment exhibits the problem.

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

char    buf[1024];

main()
{
        int i;

        if (fork() == 0) {
                /* make sure memory is allocated RONLY */
                i = buf[0];

                read(0, buf, 1024);
                print("%s\n", buf);
                exits(0);
        }

        /* wait a second so the child completes */

        sleep(1000);

        buf[1023] = 0;

        print("parent -> %s\n", buf);
}

On plan 9 for the pc, the data read into buf will incorrectly appear in both
the child and parent process.

The 486 (and higher?) fixed the problem but to maintain compatibility
it defaults to the 386 behavior.  On a 486 you need to set bit 16 in CR0
to get the correct behavior for the R/W bit.  Of course, if you have a
386, then copy on write can not be fixed, but you can still run plan9
with a copy on reference scheme... unfortunately, this means your 386
machine runs slower and requires more memory...

The complete fix of the problem, thanks to Dave Presotto, follows:

Here's the changes.  It works on a couple of 486's and 386's so its
probably right.

In l.s (around line 131) change

        ORL     $0X80000000,AX
        ANDL    $~(0x8|0x2),AX  /* TS=0, MP=0 */

to

        ORL     $0X80010000,AX
        ANDL    $~(0x40000000|0x20000000|0x8|0x2),AX    /* CD=0, NW=0, TS=0, MP=0 */

This also turns on internal caching in case it was off.

In l.s add the routine

/*
 *  return cpu type (what is a pentium?)
 */
TEXT    x86(SB),$0

        PUSHFL
        MOVL    0(SP),AX
        ORL     $0x40000,AX
        PUSHL   AX
        POPFL
        PUSHFL
        POPL    AX
        ANDL    $0x40000,AX
        JZ      is386
        MOVL    $486,AX
        JMP     done
is386:
        MOVL    $386,AX
done:
        POPFL
        RET

This returns the number 386 or 486 depending.  I guess it'll return
586 also when I get a chance at a Pentium.

In fns.h add a definition for it:

        int     x86(void);

In main.c in confinit() change

        conf.copymode = 0;      /* copy on write */

to

        switch(x86()){
        case 386:
                conf.copymode = 1;      /* copy on reference */
                break;
        default:
        case 486:
                conf.copymode = 0;      /* copy on write */
                break;
        }

and you're done.




             reply	other threads:[~1994-03-02  0:47 UTC|newest]

Thread overview: 296+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-03-02  0:47 Sean [this message]
  -- strict thread matches above, loose matches on Subject: below --
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2009-05-04 19:42 bogus
2000-05-26 15:25 
2000-05-14  3:59 Russ
2000-05-08 12:56 presotto
2000-04-27 20:17 Christian
2000-04-26  6:02 Christian
2000-04-24 23:29 Christian
2000-04-13 23:25 root
2000-04-13 22:25 root
2000-04-13 22:24 root
2000-04-13 22:24 root
2000-04-13 22:24 root
2000-04-13 22:24 root
2000-04-13 21:44 root
2000-04-13 21:44 root
2000-04-13 21:44 root
2000-04-13 21:31 root
2000-04-13 21:31 root
2000-04-13 21:31 root
2000-04-13 21:31 root
2000-04-13 21:31 root
1999-12-13 16:37 rob
1999-05-21  1:10 Andrew
1999-05-21  1:08 Scott
1999-05-21  0:58 Andrew
1999-01-31 17:56 presotto
1998-10-03 10:00 arisawa
1998-10-03  9:57 arisawa
1998-10-03  9:34 arisawa
1998-10-03  8:58 arisawa
1998-09-22  9:28 okamoto
1998-09-21  9:43 Elliott
1998-09-08 16:10 Tom
1998-09-08 13:44 Russ
1998-09-08  8:44 okamoto
1998-09-03 10:00 Kenji
1998-09-03  7:00 okamoto
1998-08-27 14:08 Russ
1998-08-27  7:55 arisawa
1998-08-25  8:34 Elliott
1998-08-17 18:08 Lucio
1998-04-15  4:15 Steve
1998-03-21  2:11 arisawa
1998-03-20 19:28 arisawa
1998-02-08 11:41 forsyth
1998-01-06 16:03 Mark
1997-12-12 18:00 Rob
1997-10-22 16:08 FODEMESI
1997-10-18 14:13 Kenji
1997-10-18 14:12 Kenji
1997-09-30 19:07 schwartz
1997-09-14 15:09 bobf
1997-09-12 20:43 bobf
1997-08-15 18:00 tab
1997-08-04 18:39 tab
1997-07-29 21:55 beto
1997-07-29 21:25 seanq
1997-07-09  2:46 Scott
1997-07-08 23:06 rob
1997-07-08 22:05 Scott
1997-05-30  4:10 ken
1997-05-29 19:54 Anthony
1997-05-02  9:47 forsyth
1997-04-22 15:59 jm
1997-04-19 21:36 bobf
1997-03-21 18:28 presotto
1997-03-21 17:39 presotto
1997-02-20 22:16 bobf
1997-01-23 14:14 tab
1997-01-20  3:03 Scott
1997-01-15 15:14 presotto
1997-01-02 14:13 Steve
1997-01-02 13:58 tab
1996-12-20 15:09 tab
1996-12-18 19:32 tab
1996-12-01 17:04 forsyth
1996-12-01 16:09 presotto
1996-12-01 14:24 Jean
1996-10-17 21:08 presotto
1996-10-17 14:56 presotto
1996-10-15 11:36 forsyth
1996-10-11 16:00 Boyd
1996-10-11 12:29 Thomas
1996-10-11 12:25 Thomas
1996-10-11 11:54 Thomas
1996-10-11 11:53 Thomas
1996-10-11 11:50 Thomas
1996-10-11 10:16 Thomas
1996-09-30 14:24 Markus
1996-09-30  1:27 James
1996-09-03 15:40 philw
1996-09-02  4:16 scott
1996-08-24  4:18 Scott
1996-08-23 22:03 philw
1996-08-07  1:50 scott
1996-08-04 21:00 scott
1996-07-29 16:29 Rob
1996-07-20  7:44 Laurent
1996-07-06 23:23 Raj
1996-07-01 20:31 Scott
1996-07-01 19:03 Min
1996-06-07 22:04 Michael
1996-06-07 21:18 Scott
1996-06-07 20:05 Raj
1996-05-07 13:39 Finn
1996-04-11 19:23 philw
1996-04-07 13:07 forsyth
1996-04-07  5:49 scott
1996-03-25  4:59 scott
1996-03-21 14:31 Nigel
1996-03-21 14:13 Dave
1996-03-21  4:26 Thomas
1996-03-21  3:11 Thomas
1996-03-14 19:00 postmaster
1996-03-11  3:08 Steve
1996-03-11  0:22 Ken
1996-03-10 20:16 Scott
1996-03-10  4:19 Dave
1996-03-09 21:34 Thomas
1996-02-26 20:53 Luther
1996-02-26 20:20 Rob
1996-02-15 22:36 Berry
1996-02-15 22:10 Ken.Goldsholl.Atlas.Computer.Equipment
1996-01-24  4:30 Ken
1996-01-18  1:06 Berry
1996-01-17 22:38 steve
1995-12-07  8:39 Nigel
1995-12-06 21:34 philw
1995-11-16  4:02 steve
1995-11-15 22:10 jim
1995-11-15 13:14 Thomas
1995-11-10 20:40 presotto
1995-11-09 13:31 ken
1995-10-26  0:21 Scott
1995-10-25 21:31 Ashish
1995-10-19 10:46 dhog
1995-10-18 21:47 schwartz
1995-10-18 19:32 Joshua
1995-10-13 15:00 presotto
1995-09-30 11:41 forsyth
1995-09-26  2:43 jmk
1995-09-26  2:25 presotto
1995-09-22 20:51 ken
1995-09-22  4:18 Scott
1995-08-31 20:31 presotto
1995-08-29 21:32 presotto
1995-08-27 18:36 Scott
1995-08-27 17:41 Murali
1995-08-25 21:34 rob
1995-08-22 23:35 jmk
1995-08-22 21:02 Scott
1995-08-22 17:30 Steve
1995-08-22 16:06 Scott
1995-08-18  3:31 presotto
1995-08-18  0:02 Boyd
1995-08-08 13:12 presotto
1995-08-08  7:07 dhog
1995-08-08  4:22 seanq
1995-08-08  2:10 Scott
1995-08-08  1:33 Scott
1995-08-07 23:54 philw
1995-08-07 23:15 philw
1995-08-07 23:08 Scott
1995-08-07 21:52 Scott
1995-08-05 16:38 rob
1995-08-03  4:20 boyd
1995-08-01 16:24 9fans-outgoing-owner
1995-08-01 16:24 9fans-outgoing-owner
1995-08-01 16:24 9fans-outgoing-owner
1995-08-01 16:24 9fans-outgoing-owner
1995-08-01 16:24 9fans-outgoing-owner
1995-08-01 16:24 9fans-outgoing-owner
1995-08-01 15:01 ken
1995-07-29 16:51 rob
1995-07-28 21:36 Scott
1995-07-27 22:33 Scott
1995-07-27 12:31 rob
1995-07-26 21:39 Scott
1995-07-24 12:51 Henner
1995-07-21 15:40 Henner
1995-07-17 20:26 Frank
1995-07-17 20:20 rob
1995-07-17 19:55 philw
1995-07-17 19:11 Frank
1995-07-17 19:02 Frank
1995-06-02 18:44 rob
1995-05-18 22:51 Scott
1995-04-25  1:29 Scott
1995-04-09  8:21 Scott
1995-04-07 23:09 Scott
1995-04-06 21:15 Bob
1995-04-06 19:09 rob
1995-04-06  5:02 rob
1995-04-05  7:31 Amos
1995-04-05  2:42 Scott
1995-04-03  4:12 Scott
1995-04-03  2:07 philw
1995-03-31 15:24 rob
1995-03-30 21:26 Berry
1995-03-30 17:34 Frederick
1995-03-30  7:41 Mark
1995-03-30  3:57 Scott
1995-03-30  3:35 John
1995-03-30  2:45 Christopher.Vance
1995-03-30  2:33 Cort
1995-03-30  2:02 Steve
1995-03-30  1:56 Cort
1995-03-30  1:36 Andrew
1995-03-30  1:18 rob
1995-03-17  5:00 Scott
1995-03-17  4:15 philw
1995-03-17  3:39 Scott
1995-03-17  1:18 philw
1995-03-16 23:37 Scott
1995-03-16 20:06 mccartyb
1995-02-11 22:41 rob
1995-02-08 19:48 rob
1995-01-14 14:46 rob
1994-09-09  3:52 Fariborz
1994-09-08 19:44 Victor
1994-09-08 18:13 bobf
1994-07-04 14:25 rob
1994-06-14 19:47 rob
1994-05-11 18:34 forsyth
1994-05-07  2:18 Scott
1994-05-07  1:22 philw
1994-05-06 23:00 philw
1994-03-28 15:06 rob
1994-03-03 17:40 Vijay
1994-02-16  4:11 rob
1994-02-10  3:28 rob
1994-02-10  3:19 rob
1994-02-08 16:51 geoff
1994-02-07 21:42 Vijay
1994-01-29  0:30 rob
1994-01-29  0:25 Scott
1994-01-29  0:01 rob
1994-01-27 18:46 rob
1994-01-13 21:05 philw
1994-01-13 20:08 Scott
1994-01-09  2:41 rob
1994-01-09  2:18 Scott
1993-10-22  3:30 rob
1993-10-22  3:05 Scott
1993-10-22  2:45 Neil
1993-10-22  0:06 Scott
1993-10-21 23:39 rob
1993-10-21 17:39 philw
1993-10-20 22:45 Scott
1993-08-16 23:25 presotto
1993-08-12 22:56 philw
1993-07-30 15:48 forsyth
1993-07-27 15:20 rob
1993-07-27 14:12 rob
1993-07-26 14:30 plan.9
1993-07-15  4:08 Bob
1993-07-15  3:33 Jerry
1993-07-13 19:25 jwjohn
1993-07-05 15:59 rob

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=19940302004703.Eh4jscjan5FlmUNoydmcK4Gww4V082zozs4et7dBQ_k@z \
    --to=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).