From patchwork Wed Dec 22 15:06:23 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gleb Natapov X-Patchwork-Id: 427931 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oBMF6qIc013964 for ; Wed, 22 Dec 2010 15:06:53 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753518Ab0LVPGn (ORCPT ); Wed, 22 Dec 2010 10:06:43 -0500 Received: from mx1.redhat.com ([209.132.183.28]:32909 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753407Ab0LVPGc (ORCPT ); Wed, 22 Dec 2010 10:06:32 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oBMF6Wxx015816 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 22 Dec 2010 10:06:32 -0500 Received: from dhcp-1-237.tlv.redhat.com (dhcp-1-237.tlv.redhat.com [10.35.1.237]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id oBMF6VpM021229; Wed, 22 Dec 2010 10:06:31 -0500 Received: by dhcp-1-237.tlv.redhat.com (Postfix, from userid 13519) id B1CC018D3F7; Wed, 22 Dec 2010 17:06:29 +0200 (IST) From: Gleb Natapov To: avi@redhat.com, mtosatti@redhat.com Cc: kvm@vger.kernel.org Subject: [PATCH unit-tests 10/16] Fix mmu on 32 bit. Date: Wed, 22 Dec 2010 17:06:23 +0200 Message-Id: <1293030389-1143-11-git-send-email-gleb@redhat.com> In-Reply-To: <1293030389-1143-1-git-send-email-gleb@redhat.com> References: <1293030389-1143-1-git-send-email-gleb@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Wed, 22 Dec 2010 15:06:54 +0000 (UTC) diff --git a/lib/x86/vm.c b/lib/x86/vm.c index b34449f..4d0a955 100644 --- a/lib/x86/vm.c +++ b/lib/x86/vm.c @@ -135,23 +135,43 @@ struct ljmp { unsigned short seg; }; +static void setup_mmu_range(unsigned long *cr3, unsigned long start, + unsigned long len) +{ + u64 max = (u64)len + (u64)start; + u64 phys = start; + + while (phys + LARGE_PAGE_SIZE <= max) { + install_large_page(cr3, phys, (void *)(ulong)phys); + phys += LARGE_PAGE_SIZE; + } + while (phys + PAGE_SIZE <= max) { + install_page(cr3, phys, (void *)(ulong)phys); + phys += PAGE_SIZE; + } +} + static void setup_mmu(unsigned long len) { unsigned long *cr3 = alloc_page(); - unsigned long phys = 0; + memset(cr3, 0, PAGE_SIZE); + +#ifdef __x86_64__ if (len < (1ul << 32)) - len = 1ul << 32; /* map mmio 1:1 */ + len = (1ul << 32); /* map mmio 1:1 */ + + setup_mmu_range(cr3, 0, len); +#else + if (len > (1ul << 31)) + len = (1ul << 31); + + /* 0 - 2G memory, 2G-3G valloc area, 3G-4G mmio */ + setup_mmu_range(cr3, 0, len); + setup_mmu_range(cr3, 3ul << 30, (1ul << 30)); + vfree_top = (void*)(3ul << 30); +#endif - memset(cr3, 0, PAGE_SIZE); - while (phys + LARGE_PAGE_SIZE <= len) { - install_large_page(cr3, phys, (void *)phys); - phys += LARGE_PAGE_SIZE; - } - while (phys + PAGE_SIZE <= len) { - install_page(cr3, phys, (void *)phys); - phys += PAGE_SIZE; - } write_cr3(virt_to_phys(cr3)); #ifndef __x86_64__ write_cr4(X86_CR4_PSE);