From patchwork Sun Jan 1 16:37:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Gordeev X-Patchwork-Id: 9492919 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CF73160416 for ; Sun, 1 Jan 2017 16:37:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BBCD21FF35 for ; Sun, 1 Jan 2017 16:37:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B0A1C223B2; Sun, 1 Jan 2017 16:37:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68E4E1FF35 for ; Sun, 1 Jan 2017 16:37:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932329AbdAAQhs (ORCPT ); Sun, 1 Jan 2017 11:37:48 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36124 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932333AbdAAQhq (ORCPT ); Sun, 1 Jan 2017 11:37:46 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B8AB44E339 for ; Sun, 1 Jan 2017 16:37:46 +0000 (UTC) Received: from dhcp-27-118.brq.redhat.com (dhcp-27-122.brq.redhat.com [10.34.27.122]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v01GbZLR019089; Sun, 1 Jan 2017 11:37:45 -0500 From: Alexander Gordeev To: kvm@vger.kernel.org Cc: Alexander Gordeev , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Subject: [kvm-unit-tests RFC PATCH 09/10] x86: vm: Enable non-identity paging Date: Sun, 1 Jan 2017 17:37:31 +0100 Message-Id: <1483288652-18983-10-git-send-email-agordeev@redhat.com> In-Reply-To: <1483288652-18983-1-git-send-email-agordeev@redhat.com> References: <1483288652-18983-1-git-send-email-agordeev@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Sun, 01 Jan 2017 16:37:46 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is a prerequisite to enable non-identity mapped paging Cc: Radim Krčmář Signed-off-by: Alexander Gordeev --- lib/x86/vm.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/x86/vm.c b/lib/x86/vm.c index b3d547a2a7f1..85625e5c934e 100644 --- a/lib/x86/vm.c +++ b/lib/x86/vm.c @@ -96,7 +96,7 @@ unsigned long *install_page(unsigned long *cr3, } -static void setup_mmu_range(unsigned long *cr3, unsigned long start, +static void setup_mmu_range(unsigned long *cr3, unsigned long start, void *virt, unsigned long len) { u64 max = (u64)len + (u64)start; @@ -105,16 +105,19 @@ static void setup_mmu_range(unsigned long *cr3, unsigned long start, while (phys + PAGE_SIZE <= max) { if (!(phys % LARGE_PAGE_SIZE)) break; - install_page(cr3, phys, (void *)(ulong)phys); + install_page(cr3, phys, virt); phys += PAGE_SIZE; + virt += PAGE_SIZE; } while (phys + LARGE_PAGE_SIZE <= max) { - install_large_page(cr3, phys, (void *)(ulong)phys); + install_large_page(cr3, phys, virt); phys += LARGE_PAGE_SIZE; + virt += LARGE_PAGE_SIZE; } while (phys + PAGE_SIZE <= max) { - install_page(cr3, phys, (void *)(ulong)phys); + install_page(cr3, phys, virt); phys += PAGE_SIZE; + virt += PAGE_SIZE; } } @@ -128,14 +131,14 @@ static void setup_mmu(unsigned long len) if (len < (1ul << 32)) len = (1ul << 32); /* map mmio 1:1 */ - setup_mmu_range(cr3, 0, len); + setup_mmu_range(cr3, 0, (void *)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)); + setup_mmu_range(cr3, 0, (void *)0, len); + setup_mmu_range(cr3, 3ul << 30, (void *)(3ul << 30), (1ul << 30)); vfree_top = (void*)(3ul << 30); #endif