two virtual address pointing to same physical address

Valdis.Kletnieks at vt.edu Valdis.Kletnieks at vt.edu
Mon May 19 22:28:54 EDT 2014


On Tue, 20 May 2014 00:39:26 -0000, Chan Kim said:
> But still it's confusing. Can two virtual addresses from the "same process"
> (in init process, one for nocache pool, the other not) point to the same
> physical address?

I'm not sure what you're trying to say there.  In general, the hardware
tags like non-cacheable and write-combining are applied to physical addresses,
not virtual.

And a moment's thought will show that treating the same address (whether it's
virtual or physical) as caching in one place and non-caching in another is just
*asking* for a stale-data bug when the non-caching reference updates data and
the caching reference thinks it's OK to use the non-flushed non-refreshed
cached data.

It's easy enough to test if two addresses from a single process can
point to the same physical address - do something like this:

	/* just ensure these two map the same thing at different addresses */
	foo = mmap(something,yaddayadda);
 	bar = mmap(something,yaddayadda);
	/* modify via one reference */
	*foo = 23;
	/* you probably want a barrier call here so gcc doesn't screw you */
	/* Now dereference it via the other reference */
	printf("And what we read back is %d\n", *bar);

(Making this work is left as an exercise for the student :)

And figuring out why you need a barrier is fundamental to writing bug-free
code that uses shared memory. The file Documentation/memory-barriers.txt
is a good place to start.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 848 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140519/b17a2440/attachment.bin 


More information about the Kernelnewbies mailing list