From: Daniel De Graaf Subject: Re: Frame buffer mmap not working in pvops dom0 Date: Wed, 21 Jul 2010 11:26:51 -0400 Message-ID: <4C4711BB.5090905@tycho.nsa.gov> References: <4C46FA8D.6040809@tycho.nsa.gov> <20100721141613.GG17817@reaktio.net> <20100721144209.GA5031@phenom.dumpdata.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------060500010300080701020800" Return-path: In-Reply-To: <20100721144209.GA5031@phenom.dumpdata.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Konrad Rzeszutek Wilk Cc: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org This is a multi-part message in MIME format. --------------060500010300080701020800 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 07/21/2010 10:42 AM, Konrad Rzeszutek Wilk wrote: > On Wed, Jul 21, 2010 at 05:16:13PM +0300, Pasi K=E4rkk=E4inen wrote: >> On Wed, Jul 21, 2010 at 09:47:57AM -0400, Daniel De Graaf wrote: >>> I'm trying to confirm the fix to the VESA fbdev mmap issue that was >>> brought up a few months ago >>> (http://marc.info/?l=3Dxen-devel&m=3D126842551306571&w=3D2). The wiki= page at >=20 > Weird. I don't remember seeing that e-mail.. >=20 >>> http://wiki.xensource.com/xenwiki/XenPVOPSDRM says that this bug shou= ld >>> be fixed, but doesn't point to a patch for the fix. I am still able t= o >>> reproduce the issue both on real hardware and by running Xen under qe= mu >>> (using cirrusfb on the dom0). Eamon (the original reporter) has also = not >>> been able to confirm a fix. >>> >>> I'm currently testing using Xen 4.1 built from hg 21831:6bebaf40e925 = and >>> a pvops dom0 from xen/stable-2.6.32.x revid c0a00fbe. >>> >>> So far, I've been able to determine that an mmap requesting multiple >>> pages from /dev/fb0 will result in page table entries all pointing to >>> the same physical page, which is not in the framebuffer address space= . >>> Writing to the mapped page ends up corrupting parts of kernel memory. >>> I'd be happy to run further tests, try patches, or provide more >>> information if needed. >=20 > Goodies. Let me fix up a tree that cleanly merges with Jeremy's xen/nex= t > (or xen/stable-2.6.32.x) and give you a go with that. And then from > there we can come up with a fix. >=20 > Can you tell me how you came up with the analysis? (that should speed u= p > finding the culprit). Any serial/dmesg outputs would be appreciated. >=20 I have been dumping the page tables (using the attached pt-dump script, as qemu's "info tlb" only works on i386) from a paused qemu instance that is running a simple mmap-and-spin program (also attached). All 100 pages map to physical memory address 39a4c000. >From a bit more debugging, I've been able to trace the correct address (0xf0000000) being lost when it is passed by xen_make_pte to pte_pfn_to_mfn and eventually to get_phys_to_machine(0xf0000) which returns -1. Still not sure where the final physical address is coming from, but I'm guessing this is part of the problem. >=20 > Daniel, >=20 > I honestly don't remember which patch I thought fixed it. But I do know > that when the /dev/fb0 was backed by DRM (nvidia) it worked (I used the= =20 > below program). >=20 > Granted now that I tested it with fbxine and it hangs with a Xen error. > Let me start using Eamon's program. >=20 The attached program has no visible effect on the screen when run, so it's likely also not working here. --=20 Daniel De Graaf National Security Agency --------------060500010300080701020800 Content-Type: text/plain; name="mmap-hold.c" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="mmap-hold.c" #include #include #include #include #include #include #include static void bail(int cond, const char *msg) { if (cond) { perror(msg); exit(1); } } #define COUNT 100 volatile int wobble; int main(int argc, char** argv) { int fd = open("/dev/fb0", O_RDWR); unsigned char *addr; wobble = 42; bail(fd < 0, "/dev/fb0"); printf("Ready to map\n"); if (argc == 1) while (wobble == 42); addr = mmap(NULL, 4096*COUNT, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); printf("Mapped at %p\n", addr); bail(addr == MAP_FAILED, "mmap"); int i,j=0; while (wobble != 42); // fault the pages in if they need to be for(i=0; i < COUNT; i++) j += addr[i*4096]; while (wobble == 42); } --------------060500010300080701020800 Content-Type: text/plain; name="pt-dump" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="pt-dump" #!/usr/bin/perl -w # # Page Table Dump of running process in qemu-x86_64 # # Run on a stopped VM for reliable output # use strict; use IO::Socket::UNIX; die "Use: $0 unix-monitor [cr3]" unless @ARGV; my $mon = IO::Socket::UNIX->new(Type => SOCK_STREAM, Peer => shift); my $cr3; if (@ARGV) { $cr3 = shift; print "Looking up page tables as if CR3=$cr3\n"; } else { print $mon "info registers\n"; while (<$mon>) { m/^RIP=([0-9a-f]{16}) / and print "RIP=$1 "; m/ CR3=([0-9a-f]{16}) / and $cr3 = $1; last if / XMM15=/; } die unless defined $cr3; $cr3 = hex $cr3; printf "CR3=%016x\n", $cr3; } sub xp { my $ma = shift; my $res = sprintf "%016x: 0x([0-9a-f]+)", $ma; print $mon "xp $ma\n"; while (<$mon>) { return hex $1 if /$res/; } die; } my $pml4 = $cr3 & 0xFFFFFFFFFFFFF000; my($vstart, $pstart, $vcurr, $pcurr, $fcurr) = (1,0,1,0,0); sub txpage { my($vaddr, $paddr, $psiz, $flags) = @_; if ($vaddr == $vcurr && $paddr == $pcurr && $flags == $fcurr) { $vcurr += $psiz; $pcurr += $psiz; return; } if ($vstart != 1) { my $len = $vcurr - $vstart; printf " Translation: %16x -> %12x %8x f=%012b\n", $vstart, $pstart, $len, $fcurr; } $vstart = $vcurr = $vaddr; $pstart = $pcurr = $paddr; $fcurr = $flags; $vcurr = $vaddr + $psiz; $pcurr = $paddr + $psiz; } for my $pml4i (0..0x1FF) { my $pml4e1 = xp $pml4 + $pml4i * 0x8; my $pml4e2 = xp $pml4 + $pml4i * 0x8 + 4; next unless $pml4e1 & 1; my $pdpt = (($pml4e2 << 32) | $pml4e1) & 0xFFFFFFFFF000; printf "Using PML4 entry %03x %12x f=%012b\n", $pml4i << 3, $pdpt, $pml4e1 & 0xFFF; for my $pdpti (0..0x1FF) { my $pdpte1 = xp $pdpt + $pdpti * 0x8; my $pdpte2 = xp $pdpt + $pdpti * 0x8 + 4; next unless $pdpte1 & 1; if ($pdpte1 & 0x80) { print "TODO: 1GB page\n"; next; } my $pd = (($pdpte2 << 32) | $pdpte1) & 0xFFFFFFFFF000; printf " Using PDPT entry %03x %12x f=%012b\n", $pdpti << 2, $pd, $pdpte1 & 0xFFF; for my $pdi (0..0x1FF) { my $pde1 = xp $pd + $pdi * 0x8; my $pde2 = xp $pd + $pdi * 0x8 + 4; next unless $pde1 & 1; if ($pde1 & 0x80) { my $vaddr = ($pml4i << 39) | ($pdpti << 30) | ($pdi << 21); my $paddr = (($pde2 << 32) | $pde1) & 0xFFFFFFE00000; txpage $vaddr, $paddr, 0x200000, $pde1 & 0xFFF; next; } my $pt = (($pde2 << 32) | $pde1) & 0xFFFFFFFFF000; printf " Using PD entry %03x %12x f=%012b\n", $pdi << 1, $pt, $pde1 & 0xFFF; for my $pti (0..0x1FF) { my $pte1 = xp $pt + $pti * 0x8; my $pte2 = xp $pt + $pti * 0x8 + 4; next unless $pte1 & 1; my $vaddr = ($pml4i << 39) | ($pdpti << 30) | ($pdi << 21) | ($pti << 12); my $paddr = (($pte2 << 32) | $pte1) & 0xFFFFFFFFF000; txpage $vaddr, $paddr, 0x1000, $pde1 & 0xFFF; } txpage 1,1,1; } txpage 1,1,1; } txpage 1,1,1; } --------------060500010300080701020800 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --------------060500010300080701020800--