From patchwork Thu Aug 4 07:02:19 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 108354 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 83739B6EE8 for ; Thu, 4 Aug 2011 17:03:01 +1000 (EST) Received: from localhost ([::1]:57411 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QorxJ-0004Uh-Ja for incoming@patchwork.ozlabs.org; Thu, 04 Aug 2011 03:02:57 -0400 Received: from eggs.gnu.org ([140.186.70.92]:47019) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qorwy-0004AQ-U4 for qemu-devel@nongnu.org; Thu, 04 Aug 2011 03:02:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qorwx-0007Az-4i for qemu-devel@nongnu.org; Thu, 04 Aug 2011 03:02:36 -0400 Received: from ozlabs.org ([203.10.76.45]:45062) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qorww-0007AV-Mw for qemu-devel@nongnu.org; Thu, 04 Aug 2011 03:02:35 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 12D3BB6F7B; Thu, 4 Aug 2011 17:02:29 +1000 (EST) From: David Gibson To: agraf@suse.de Date: Thu, 4 Aug 2011 17:02:19 +1000 Message-Id: <1312441339-22477-7-git-send-email-david@gibson.dropbear.id.au> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1312441339-22477-1-git-send-email-david@gibson.dropbear.id.au> References: <1312441339-22477-1-git-send-email-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 203.10.76.45 Cc: qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 6/6] pseries: More complete WIMG validation in H_ENTER code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Currently our implementation of the H_ENTER hypercall, which inserts a mapping in the hash page table assumes that only ordinary memory is ever mapped, and only permits mapping attribute bits accordingly (WIMG==0010). However, we intend to start adding emulated IO to the pseries platform (and real IO with PCI passthrough on kvm) which means this simple test will no longer suffice. This patch extends the h_enter validation code to check if the given address is a RAM address. If it is it enforces WIMG==0010, otherwise it assumes that it is an IO mapping and instead enforces WIMG=010x. Signed-off-by: David Gibson --- hw/spapr.c | 3 ++- hw/spapr.h | 1 + hw/spapr_hcall.c | 22 ++++++++++++++++++---- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/hw/spapr.c b/hw/spapr.c index cf9f758..7030c17 100644 --- a/hw/spapr.c +++ b/hw/spapr.c @@ -334,7 +334,8 @@ static void ppc_spapr_init(ram_addr_t ram_size, } /* allocate RAM */ - ram_offset = qemu_ram_alloc(NULL, "ppc_spapr.ram", ram_size); + spapr->ram_limit = ram_size; + ram_offset = qemu_ram_alloc(NULL, "ppc_spapr.ram", spapr->ram_limit); cpu_register_physical_memory(0, ram_size, ram_offset); /* allocate hash page table. For now we always make this 16mb, diff --git a/hw/spapr.h b/hw/spapr.h index 263691b..400001e 100644 --- a/hw/spapr.h +++ b/hw/spapr.h @@ -8,6 +8,7 @@ typedef struct sPAPREnvironment { struct VIOsPAPRBus *vio_bus; struct icp_state *icp; + target_phys_addr_t ram_limit; void *htab; long htab_size; target_phys_addr_t fdt_addr, rtas_addr; diff --git a/hw/spapr_hcall.c b/hw/spapr_hcall.c index 89d80d3..822d715 100644 --- a/hw/spapr_hcall.c +++ b/hw/spapr_hcall.c @@ -99,6 +99,8 @@ static target_ulong h_enter(CPUState *env, sPAPREnvironment *spapr, target_ulong pte_index = args[1]; target_ulong pteh = args[2]; target_ulong ptel = args[3]; + target_ulong page_shift = 12; + target_ulong raddr; target_ulong i; uint8_t *hpte; @@ -111,6 +113,7 @@ static target_ulong h_enter(CPUState *env, sPAPREnvironment *spapr, #endif if ((ptel & 0xff000) == 0) { /* 16M page */ + page_shift = 24; /* lowest AVA bit must be 0 for 16M pages */ if (pteh & 0x80) { return H_PARAMETER; @@ -120,12 +123,23 @@ static target_ulong h_enter(CPUState *env, sPAPREnvironment *spapr, } } - /* FIXME: bounds check the pa? */ + raddr = (ptel & HPTE_R_RPN) & ~((1ULL << page_shift) - 1); - /* Check WIMG */ - if ((ptel & HPTE_R_WIMG) != HPTE_R_M) { - return H_PARAMETER; + if (raddr < spapr->ram_limit) { + /* Regular RAM - should have WIMG=0010 */ + if ((ptel & HPTE_R_WIMG) != HPTE_R_M) { + return H_PARAMETER; + } + } else { + /* Looks like an IO address */ + /* FIXME: What WIMG combinations could be sensible for IO? + * For now we allow WIMG=010x, but are there others? */ + /* FIXME: Should we check against registered IO addresses? */ + if ((ptel & (HPTE_R_W | HPTE_R_I | HPTE_R_M)) != HPTE_R_I) { + return H_PARAMETER; + } } + pteh &= ~0x60ULL; if ((pte_index * HASH_PTE_SIZE_64) & ~env->htab_mask) {