From patchwork Thu Oct 30 22:12:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Bellows X-Patchwork-Id: 39948 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DA5A6202FE for ; Fri, 31 Oct 2014 18:00:08 +0000 (UTC) Received: by mail-lb0-f199.google.com with SMTP id n15sf4417644lbi.10 for ; Fri, 31 Oct 2014 11:00:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=i8obewlvT8dgIST8Amu3yhHjKTsGdKtGJQXPcK1CLWQ=; b=ceIec3G2AGV1jurcytAubZ2DxREfUVXRteimkYLqoCvAdBISUZ3pqMiXv2haoUeS0I 0HdtgMFdVX83COdJf55LLufr7Qw2c9+vkfQv+VZORIO4EUPlpJNsd5h3GdsovG/hsCoD osy2mrwsZ2lZ4wbyQeZ0mYw16XKJfd0fPTpATEgX8jZAAzRAnqSx8mW3pz7wYP/FSDjk JEig7dtQZZBPE5H8dkFX1jJe6PA6Znl1Fswql0DPsjK0k8IqeJ1MGzjmOSeJvNUQeIBs jrAnNvlLi4RLaJXIs7M3cIK4WXxzJsUfrIOd0m7ksv7xX3LMcOcHxVivWSNfDXg6Vjbw xQSw== X-Gm-Message-State: ALoCoQkxmWLiD/7t9xEQelb/xorm5ShYf8JCyMOE6iQu3U1UT2q1CG+Ul17T2ABo4tO5Xxdjxj1f X-Received: by 10.194.206.10 with SMTP id lk10mr837942wjc.3.1414778407729; Fri, 31 Oct 2014 11:00:07 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.23.225 with SMTP id p1ls507630laf.70.gmail; Fri, 31 Oct 2014 11:00:07 -0700 (PDT) X-Received: by 10.112.132.104 with SMTP id ot8mr28057560lbb.3.1414778407562; Fri, 31 Oct 2014 11:00:07 -0700 (PDT) Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com. [209.85.217.176]) by mx.google.com with ESMTPS id jd2si17940220lbc.91.2014.10.31.11.00.07 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 31 Oct 2014 11:00:07 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) client-ip=209.85.217.176; Received: by mail-lb0-f176.google.com with SMTP id z11so4422825lbi.7 for ; Fri, 31 Oct 2014 11:00:07 -0700 (PDT) X-Received: by 10.112.77.74 with SMTP id q10mr27903704lbw.66.1414778407479; Fri, 31 Oct 2014 11:00:07 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.84.229 with SMTP id c5csp240020lbz; Fri, 31 Oct 2014 11:00:06 -0700 (PDT) X-Received: by 10.224.151.67 with SMTP id b3mr25035743qaw.6.1414778405745; Fri, 31 Oct 2014 11:00:05 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id w8si18302441qag.4.2014.10.31.11.00.05 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 31 Oct 2014 11:00:05 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:40366 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XkGUW-0000vT-P2 for patch@linaro.org; Fri, 31 Oct 2014 14:00:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43232) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XkE4w-0004cv-3R for qemu-devel@nongnu.org; Fri, 31 Oct 2014 11:26:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xjxxj-0006IV-GE for qemu-devel@nongnu.org; Thu, 30 Oct 2014 18:13:05 -0400 Received: from mail-pd0-f179.google.com ([209.85.192.179]:54003) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xjxxj-0006Hs-7l for qemu-devel@nongnu.org; Thu, 30 Oct 2014 18:12:59 -0400 Received: by mail-pd0-f179.google.com with SMTP id g10so5999787pdj.10 for ; Thu, 30 Oct 2014 15:12:58 -0700 (PDT) X-Received: by 10.68.197.170 with SMTP id iv10mr20372215pbc.135.1414707178696; Thu, 30 Oct 2014 15:12:58 -0700 (PDT) Received: from gbellows-linaro.qualcomm.com (rrcs-67-52-129-61.west.biz.rr.com. [67.52.129.61]) by mx.google.com with ESMTPSA id h3sm7270163pdl.22.2014.10.30.15.12.57 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 30 Oct 2014 15:12:58 -0700 (PDT) From: Greg Bellows To: qemu-devel@nongnu.org, peter.maydell@linaro.org, serge.fdrv@gmail.com, edgar.iglesias@gmail.com, aggelerf@ethz.ch, christoffer.dall@linaro.org Date: Thu, 30 Oct 2014 17:12:10 -0500 Message-Id: <1414707132-24588-15-git-send-email-greg.bellows@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1414707132-24588-1-git-send-email-greg.bellows@linaro.org> References: <1414707132-24588-1-git-send-email-greg.bellows@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.192.179 Cc: daniel.thompson@linaro.org Subject: [Qemu-devel] [PATCH v2 14/16] hw/intc/arm_gic: Restrict priority view 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: greg.bellows@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Fabian Aggeler GICs with Security Extensions restrict the non-secure view of the interrupt priority and priority mask registers. Signed-off-by: Fabian Aggeler --- hw/intc/arm_gic.c | 66 +++++++++++++++++++++++++++++++++++++++++++++----- hw/intc/gic_internal.h | 3 +++ 2 files changed, 63 insertions(+), 6 deletions(-) diff --git a/hw/intc/arm_gic.c b/hw/intc/arm_gic.c index 7eb72df..e01cfdc 100644 --- a/hw/intc/arm_gic.c +++ b/hw/intc/arm_gic.c @@ -258,11 +258,66 @@ uint32_t gic_acknowledge_irq(GICState *s, int cpu) void gic_set_priority(GICState *s, int cpu, int irq, uint8_t val) { + uint8_t prio = val; + + if (s->security_extn && ns_access()) { + if (GIC_TEST_GROUP0(irq, (1 << cpu))) { + return; /* Ignore Non-secure access of Group0 IRQ */ + } + prio = 0x80 | (prio >> 1); /* Non-secure view */ + } + if (irq < GIC_INTERNAL) { - s->priority1[irq][cpu] = val; + s->priority1[irq][cpu] = prio; } else { - s->priority2[(irq) - GIC_INTERNAL] = val; + s->priority2[(irq) - GIC_INTERNAL] = prio; + } +} + +uint32_t gic_get_priority(GICState *s, int cpu, int irq) +{ + uint32_t prio = GIC_GET_PRIORITY(irq, cpu); + + if (s->security_extn && ns_access()) { + if (GIC_TEST_GROUP0(irq, (1 << cpu))) { + return 0; /* Non-secure access cannot read priority of Group0 IRQ */ + } + prio = (prio << 1); /* Non-secure view */ } + return prio; +} + +void gic_set_priority_mask(GICState *s, int cpu, uint8_t val) +{ + uint8_t pmask = (val & 0xff); + + if (s->security_extn && ns_access()) { + if (s->priority_mask[cpu] & 0x80) { + /* Priority Mask in upper half */ + pmask = 0x80 | (pmask >> 1); + } else { + /* Non-secure write ignored if priority mask is in lower half */ + return; + } + } + s->priority_mask[cpu] = pmask; +} + +uint32_t gic_get_priority_mask(GICState *s, int cpu) +{ + uint32_t pmask = s->priority_mask[cpu]; + + if (s->security_extn && ns_access()) { + if (pmask & 0x80) { + /* Priority Mask in upper half, return Non-secure view */ + pmask = (pmask << 1); + } else { + /* Priority Mask in lower half, RAZ */ + pmask = 0; + } + } + return pmask; + } uint32_t gic_get_cpu_control(GICState *s, int cpu) @@ -556,7 +611,7 @@ static uint32_t gic_dist_readb(void *opaque, hwaddr offset) irq = (offset - 0x400) + GIC_BASE_IRQ; if (irq >= s->num_irq) goto bad_reg; - res = GIC_GET_PRIORITY(irq, cpu); + res = gic_get_priority(s, cpu, irq); } else if (offset < 0xc00) { /* Interrupt CPU Target. */ if (s->num_cpu == 1 && s->revision != REV_11MPCORE) { @@ -920,7 +975,7 @@ static uint32_t gic_cpu_read(GICState *s, int cpu, int offset) case 0x00: /* Control */ return gic_get_cpu_control(s, cpu); case 0x04: /* Priority mask */ - return s->priority_mask[cpu]; + return gic_get_priority_mask(s, cpu); case 0x08: /* Binary Point */ if (s->security_extn && ns_access()) { /* BPR is banked. Non-secure copy stored in ABPR. */ @@ -958,8 +1013,7 @@ static void gic_cpu_write(GICState *s, int cpu, int offset, uint32_t value) case 0x00: /* Control */ return gic_set_cpu_control(s, cpu, value); case 0x04: /* Priority mask */ - s->priority_mask[cpu] = (value & 0xff); - break; + return gic_set_priority_mask(s, cpu, value); case 0x08: /* Binary Point */ if (s->security_extn && ns_access()) { /* BPR is banked. Non-secure copy stored in ABPR. */ diff --git a/hw/intc/gic_internal.h b/hw/intc/gic_internal.h index fbb1f66..13fe5a6 100644 --- a/hw/intc/gic_internal.h +++ b/hw/intc/gic_internal.h @@ -76,6 +76,9 @@ void gic_complete_irq(GICState *s, int cpu, int irq); void gic_update(GICState *s); void gic_init_irqs_and_distributor(GICState *s); void gic_set_priority(GICState *s, int cpu, int irq, uint8_t val); +uint32_t gic_get_priority(GICState *s, int cpu, int irq); +void gic_set_priority_mask(GICState *s, int cpu, uint8_t val); +uint32_t gic_get_priority_mask(GICState *s, int cpu); uint32_t gic_get_cpu_control(GICState *s, int cpu); void gic_set_cpu_control(GICState *s, int cpu, uint32_t value); uint8_t gic_get_running_priority(GICState *s, int cpu);