From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:38930) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvqNz-00080h-MP for qemu-devel@nongnu.org; Thu, 17 Jan 2013 09:24:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TvqNw-0007LY-T4 for qemu-devel@nongnu.org; Thu, 17 Jan 2013 09:24:07 -0500 Received: from e06smtp15.uk.ibm.com ([195.75.94.111]:40079) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvqNw-0007LC-KU for qemu-devel@nongnu.org; Thu, 17 Jan 2013 09:24:04 -0500 Received: from /spool/local by e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 17 Jan 2013 14:23:01 -0000 Received: from d06av01.portsmouth.uk.ibm.com (d06av01.portsmouth.uk.ibm.com [9.149.37.212]) by b06cxnps4076.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r0HENpXL19267602 for ; Thu, 17 Jan 2013 14:23:51 GMT Received: from d06av01.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av01.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r0HENxEQ017867 for ; Thu, 17 Jan 2013 07:23:59 -0700 From: Cornelia Huck Date: Thu, 17 Jan 2013 15:23:47 +0100 Message-Id: <1358432637-42512-3-git-send-email-cornelia.huck@de.ibm.com> In-Reply-To: <1358432637-42512-1-git-send-email-cornelia.huck@de.ibm.com> References: <1358432637-42512-1-git-send-email-cornelia.huck@de.ibm.com> Subject: [Qemu-devel] [PATCH 02/12] s390: Lowcore mapping helper. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel , KVM , linux-s390 Cc: Carsten Otte , Anthony Liguori , Gleb Natapov , Sebastian Ott , Marcelo Tosatti , Heiko Carstens , Alexander Graf , Christian Borntraeger , Martin Schwidefsky Create a lowcore mapping helper that includes a check for sufficient length. Signed-off-by: Cornelia Huck --- target-s390x/helper.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/target-s390x/helper.c b/target-s390x/helper.c index 9a132e6..bf2b4d3 100644 --- a/target-s390x/helper.c +++ b/target-s390x/helper.c @@ -471,13 +471,32 @@ static uint64_t get_psw_mask(CPUS390XState *env) return r; } +static LowCore *cpu_map_lowcore(CPUS390XState *env, hwaddr *len) +{ + LowCore *lowcore; + + if (*len < sizeof(LowCore)) { + cpu_abort(env, "Insufficient length %d for mapping lowcore\n", + (int) *len); + } + + lowcore = cpu_physical_memory_map(env->psa, len, 1); + + return lowcore; +} + +static void cpu_unmap_lowcore(LowCore *lowcore, hwaddr len) +{ + cpu_physical_memory_unmap(lowcore, len, 1, len); +} + static void do_svc_interrupt(CPUS390XState *env) { uint64_t mask, addr; LowCore *lowcore; hwaddr len = TARGET_PAGE_SIZE; - lowcore = cpu_physical_memory_map(env->psa, &len, 1); + lowcore = cpu_map_lowcore(env, &len); lowcore->svc_code = cpu_to_be16(env->int_svc_code); lowcore->svc_ilen = cpu_to_be16(env->int_svc_ilen); @@ -486,7 +505,7 @@ static void do_svc_interrupt(CPUS390XState *env) mask = be64_to_cpu(lowcore->svc_new_psw.mask); addr = be64_to_cpu(lowcore->svc_new_psw.addr); - cpu_physical_memory_unmap(lowcore, len, 1, len); + cpu_unmap_lowcore(lowcore, len); load_psw(env, mask, addr); } @@ -513,7 +532,7 @@ static void do_program_interrupt(CPUS390XState *env) qemu_log_mask(CPU_LOG_INT, "%s: code=0x%x ilen=%d\n", __func__, env->int_pgm_code, ilen); - lowcore = cpu_physical_memory_map(env->psa, &len, 1); + lowcore = cpu_map_lowcore(env, &len); lowcore->pgm_ilen = cpu_to_be16(ilen); lowcore->pgm_code = cpu_to_be16(env->int_pgm_code); @@ -522,7 +541,7 @@ static void do_program_interrupt(CPUS390XState *env) mask = be64_to_cpu(lowcore->program_new_psw.mask); addr = be64_to_cpu(lowcore->program_new_psw.addr); - cpu_physical_memory_unmap(lowcore, len, 1, len); + cpu_unmap_lowcore(lowcore, len); DPRINTF("%s: %x %x %" PRIx64 " %" PRIx64 "\n", __func__, env->int_pgm_code, ilen, env->psw.mask, @@ -549,7 +568,7 @@ static void do_ext_interrupt(CPUS390XState *env) } q = &env->ext_queue[env->ext_index]; - lowcore = cpu_physical_memory_map(env->psa, &len, 1); + lowcore = cpu_map_lowcore(env, &len); lowcore->ext_int_code = cpu_to_be16(q->code); lowcore->ext_params = cpu_to_be32(q->param); @@ -560,7 +579,7 @@ static void do_ext_interrupt(CPUS390XState *env) mask = be64_to_cpu(lowcore->external_new_psw.mask); addr = be64_to_cpu(lowcore->external_new_psw.addr); - cpu_physical_memory_unmap(lowcore, len, 1, len); + cpu_unmap_lowcore(lowcore, len); env->ext_index--; if (env->ext_index == -1) { -- 1.7.12.4