Re: Shared memory not SMP safe to user-mode code.

Richard B. Johnson (root@chaos.analogic.com)
Tue, 30 Nov 1999 15:29:13 -0500 (EST)


On Tue, 30 Nov 1999, Andrea Arcangeli wrote:

> On Tue, 30 Nov 1999, Richard B. Johnson wrote:
>
> >The problem is not that deadlocks occasionally occur. The problem
> >is that, on a SMP machine, what was written by one CPU does not
> >appear in shared memory when viewed by another CPU. This is a bug.
>
> The kernel can do nothing to serialize you. Attaching a shared memory
> segment in memory from physical point of view is exactly as running SMP
> threaded with clone. The difference is only in the amount of memory
> that you share across the tasks.
>
> You have the same physical page shared and writeable by lots of tasks at
> the same time. So all tasks can read and write on the same page at the
> same time.
>

If, at the point, one task discovered that a lock was not obtained and
subtracted its key, user-code could execute "invlpg", forcing what
was written to appear to another CPU, resolving the issue. The
problem is that user-mode code isn't allowed, even under iopl(3) to
use that instruction. I will experiment with a "far" jump to see if
I can do the same thing.

In the kernel, everything is easy. Just use a spin-lock, but that's
not the point. What I need to do is let user-mode code access a
shared-memory board that has NVRAM values that 'eventually' take effect.
Currently, the maximum rate at which I can write a word is the HZ
rate (100 Hz) because the CPU dosn't seem to "know" it's been written
until a context-switch occurs, invalidating the cache.

Currently, if you were to do the trivial:

*ptr = shared_memory;

while (!*ptr)
;

This will loop forever, even when hardware writes non-zero to shared
memory. This is because the CPU "knows" that it didn't write something
there since the last time it read, so the data from the last read remains
in its cache, never updated. Once a task-switch occurs, the loop
will be broken. However, this limits the maximum data-change-rate
to 100 Hz (the task-switch time).

I attempted to emulate the same thing in software. Many reviewing
the software didn't understand what it was supposed to do (they
read the code, not the text).

Cheers,
Dick Johnson

Penguin : Linux version 2.3.13 on an i686 machine (400.59 BogoMips).
Warning : It's hard to remain at the trailing edge of technology.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/