From patchwork Wed Mar 30 10:08:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 64669 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp2500762lbc; Wed, 30 Mar 2016 03:11:08 -0700 (PDT) X-Received: by 10.55.41.205 with SMTP id p74mr8619715qkp.65.1459332649264; Wed, 30 Mar 2016 03:10:49 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id 21si2979189qkz.109.2016.03.30.03.10.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Mar 2016 03:10:49 -0700 (PDT) Received-SPF: neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1alD3y-0002YS-Pi; Wed, 30 Mar 2016 10:09:22 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1alD3x-0002XO-2W for xen-devel@lists.xen.org; Wed, 30 Mar 2016 10:09:21 +0000 Received: from [85.158.139.211] by server-9.bemta-5.messagelabs.com id 9C/ED-22144-0D5ABF65; Wed, 30 Mar 2016 10:09:20 +0000 X-Env-Sender: zhaoshenglong@huawei.com X-Msg-Ref: server-13.tower-206.messagelabs.com!1459332556!31769413!1 X-Originating-IP: [119.145.14.66] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTE5LjE0NS4xNC42NiA9PiA4NTI3\n X-StarScan-Received: X-StarScan-Version: 8.11; banners=-,-,- X-VirusChecked: Checked Received: (qmail 1218 invoked from network); 30 Mar 2016 10:09:19 -0000 Received: from szxga03-in.huawei.com (HELO szxga03-in.huawei.com) (119.145.14.66) by server-13.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 30 Mar 2016 10:09:19 -0000 Received: from 172.24.1.50 (EHLO SZXEML423-HUB.china.huawei.com) ([172.24.1.50]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id BYZ04465; Wed, 30 Mar 2016 18:09:08 +0800 (CST) Received: from HGHY1Z002260041.china.huawei.com (10.177.16.142) by SZXEML423-HUB.china.huawei.com (10.82.67.154) with Microsoft SMTP Server id 14.3.235.1; Wed, 30 Mar 2016 18:09:01 +0800 From: Shannon Zhao To: Date: Wed, 30 Mar 2016 18:08:10 +0800 Message-ID: <1459332494-18964-18-git-send-email-zhaoshenglong@huawei.com> X-Mailer: git-send-email 1.9.0.msysgit.0 In-Reply-To: <1459332494-18964-1-git-send-email-zhaoshenglong@huawei.com> References: <1459332494-18964-1-git-send-email-zhaoshenglong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.16.142] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020201.56FBA5C5.0015, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 82a0ff0f07c48d12c80f1de41b03fd19 Cc: sstabellini@kernel.org, peter.huangpeng@huawei.com, julien.grall@arm.com, stefano.stabellini@citrix.com, shannon.zhao@linaro.org, zhaoshenglong@huawei.com Subject: [Xen-devel] [PATCH v8 17/21] arm/gic: Add a new callback to deny Dom0 access to GIC regions X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" From: Shannon Zhao Add a new member in gic_hw_operations which is used to deny Dom0 access to GIC regions. Signed-off-by: Shannon Zhao Reviewed-by: Stefano Stabellini Acked-by: Julien Grall --- xen/arch/arm/gic-v2.c | 27 +++++++++++++++++++++++++++ xen/arch/arm/gic-v3.c | 41 +++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/gic.c | 5 +++++ xen/include/asm-arm/gic.h | 3 +++ 4 files changed, 76 insertions(+) diff --git a/xen/arch/arm/gic-v2.c b/xen/arch/arm/gic-v2.c index 38e3216..450755f 100644 --- a/xen/arch/arm/gic-v2.c +++ b/xen/arch/arm/gic-v2.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -684,6 +685,31 @@ static void __init gicv2_dt_init(void) csize, vsize); } +static int gicv2_iomem_deny_access(const struct domain *d) +{ + int rc; + unsigned long gfn, nr; + + gfn = dbase >> PAGE_SHIFT; + rc = iomem_deny_access(d, gfn, gfn + 1); + if ( rc ) + return rc; + + gfn = hbase >> PAGE_SHIFT; + rc = iomem_deny_access(d, gfn, gfn + 1); + if ( rc ) + return rc; + + gfn = cbase >> PAGE_SHIFT; + nr = DIV_ROUND_UP(csize, PAGE_SIZE); + rc = iomem_deny_access(d, gfn, gfn + nr); + if ( rc ) + return rc; + + gfn = vbase >> PAGE_SHIFT; + return iomem_deny_access(d, gfn, gfn + nr); +} + #ifdef CONFIG_ACPI static int gicv2_make_hwdom_madt(const struct domain *d, u32 offset) { @@ -910,6 +936,7 @@ const static struct gic_hw_operations gicv2_ops = { .read_apr = gicv2_read_apr, .make_hwdom_dt_node = gicv2_make_hwdom_dt_node, .make_hwdom_madt = gicv2_make_hwdom_madt, + .iomem_deny_access = gicv2_iomem_deny_access, }; /* Set up the GIC */ diff --git a/xen/arch/arm/gic-v3.c b/xen/arch/arm/gic-v3.c index 52ee23c..a095064 100644 --- a/xen/arch/arm/gic-v3.c +++ b/xen/arch/arm/gic-v3.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -1235,6 +1236,45 @@ static void __init gicv3_dt_init(void) &vbase, &vsize); } +static int gicv3_iomem_deny_access(const struct domain *d) +{ + int rc, i; + unsigned long gfn, nr; + + gfn = dbase >> PAGE_SHIFT; + nr = DIV_ROUND_UP(SZ_64K, PAGE_SIZE); + rc = iomem_deny_access(d, gfn, gfn + nr); + if ( rc ) + return rc; + + for ( i = 0; i < gicv3.rdist_count; i++ ) + { + gfn = gicv3.rdist_regions[i].base >> PAGE_SHIFT; + nr = DIV_ROUND_UP(gicv3.rdist_regions[i].size, PAGE_SIZE); + rc = iomem_deny_access(d, gfn, gfn + nr); + if ( rc ) + return rc; + } + + if ( cbase != INVALID_PADDR ) + { + gfn = cbase >> PAGE_SHIFT; + nr = DIV_ROUND_UP(csize, PAGE_SIZE); + rc = iomem_deny_access(d, gfn, gfn + nr); + if ( rc ) + return rc; + } + + if ( vbase != INVALID_PADDR ) + { + gfn = vbase >> PAGE_SHIFT; + nr = DIV_ROUND_UP(csize, PAGE_SIZE); + return iomem_deny_access(d, gfn, gfn + nr); + } + + return 0; +} + #ifdef CONFIG_ACPI static int gicv3_make_hwdom_madt(const struct domain *d, u32 offset) { @@ -1530,6 +1570,7 @@ static const struct gic_hw_operations gicv3_ops = { .secondary_init = gicv3_secondary_cpu_init, .make_hwdom_dt_node = gicv3_make_hwdom_dt_node, .make_hwdom_madt = gicv3_make_hwdom_madt, + .iomem_deny_access = gicv3_iomem_deny_access, }; static int __init gicv3_dt_preinit(struct dt_device_node *node, const void *data) diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c index b3c1eb3..2bfe4de 100644 --- a/xen/arch/arm/gic.c +++ b/xen/arch/arm/gic.c @@ -744,6 +744,11 @@ int gic_make_hwdom_madt(const struct domain *d, u32 offset) return gic_hw_ops->make_hwdom_madt(d, offset); } +int gic_iomem_deny_access(const struct domain *d) +{ + return gic_hw_ops->iomem_deny_access(d); +} + /* * Local variables: * mode: C diff --git a/xen/include/asm-arm/gic.h b/xen/include/asm-arm/gic.h index 8130136..cd97bb2 100644 --- a/xen/include/asm-arm/gic.h +++ b/xen/include/asm-arm/gic.h @@ -360,6 +360,8 @@ struct gic_hw_operations { const struct dt_device_node *gic, void *fdt); /* Create MADT table for the hardware domain */ int (*make_hwdom_madt)(const struct domain *d, u32 offset); + /* Deny access to GIC regions */ + int (*iomem_deny_access)(const struct domain *d); }; void register_gic_ops(const struct gic_hw_operations *ops); @@ -367,6 +369,7 @@ int gic_make_hwdom_dt_node(const struct domain *d, const struct dt_device_node *gic, void *fdt); int gic_make_hwdom_madt(const struct domain *d, u32 offset); +int gic_iomem_deny_access(const struct domain *d); #endif /* __ASSEMBLY__ */ #endif