Subject: port-i386/33320: i386_iopl(2) is not LWP aware
To: None <port-i386-maintainer@netbsd.org, gnats-admin@netbsd.org,>
From: None <M.Drochner@fz-juelich.de>
List: netbsd-bugs
Date: 04/20/2006 20:25:00
>Number:         33320
>Category:       port-i386
>Synopsis:       i386_iopl(2) is not LWP aware
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    port-i386-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Apr 20 20:25:00 +0000 2006
>Originator:     Matthias Drochner
>Release:        current
>Organization:
KFA Juelich
>Environment:
NetBSD zel216 3.99.18 NetBSD 3.99.18 (ZEL216+ACPI.DEBUG) #26: Thu Apr 20 11:56:4
3 MEST 2006  drochner@zel216:/home/drochner/netbsd/sys.work/arch/i386/compile/ZE
L216+ACPI.DEBUG i386

>Description:
i386_iopl(2) does only set the iopl bits for the currently
active LWP. It should work per-process.

This also applies to i386_{get,set}_ioperm(2),
but since this is being revoked (guess by whom:-)
I don't think this needs to be fixed.

>How-To-Repeat:
#include <stdlib.h>
#include <unistd.h>
#include <err.h>
#include <pthread.h>
#include <sys/types.h>
#include <machine/sysarch.h>
#include <machine/pio.h>

void *
ioperm(void *d)
{
        int res;
        char buf[1];

        res = i386_iopl(1);
        if (res < 0)
                err(1, "iopl");
        read(0, &buf, sizeof(buf)); /* block, force new LWP */
        return (0);
}

int
main()
{
        int res;
        pthread_t t;

        res = pthread_create(&t, 0, ioperm, 0);
        if (res)
                err(1, "pthread_create");
        sleep(1); /* wait for thread to block */
        inb(0x61);
        exit (0);
}

>Fix:
The only solution I can imagine which would also work with
multiple threads on multiple processors is to lazy-evaluate
the io permission on faults.