From patchwork Thu Mar 17 09:41:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 63956 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp355897lbc; Thu, 17 Mar 2016 02:47:36 -0700 (PDT) X-Received: by 10.31.5.134 with SMTP id 128mr10465475vkf.29.1458208056885; Thu, 17 Mar 2016 02:47:36 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id x67si5870135vkx.5.2016.03.17.02.47.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Mar 2016 02:47:36 -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 1agUVl-0006Wn-Kh; Thu, 17 Mar 2016 09:46:33 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1agUVk-0006WT-U0 for xen-devel@lists.xen.org; Thu, 17 Mar 2016 09:46:33 +0000 Received: from [193.109.254.147] by server-3.bemta-14.messagelabs.com id 9A/58-03304-8FC7AE65; Thu, 17 Mar 2016 09:46:32 +0000 X-Env-Sender: zhaoshenglong@huawei.com X-Msg-Ref: server-10.tower-27.messagelabs.com!1458207987!31897724!1 X-Originating-IP: [119.145.14.65] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTE5LjE0NS4xNC42NSA9PiA3NzQ2Mw==\n X-StarScan-Received: X-StarScan-Version: 8.11; banners=-,-,- X-VirusChecked: Checked Received: (qmail 59408 invoked from network); 17 Mar 2016 09:46:30 -0000 Received: from szxga02-in.huawei.com (HELO szxga02-in.huawei.com) (119.145.14.65) by server-10.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 17 Mar 2016 09:46:30 -0000 Received: from 172.24.1.49 (EHLO szxeml432-hub.china.huawei.com) ([172.24.1.49]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DDR51894; Thu, 17 Mar 2016 17:43:03 +0800 (CST) Received: from HGHY1Z002260041.china.huawei.com (10.177.16.142) by szxeml432-hub.china.huawei.com (10.82.67.209) with Microsoft SMTP Server id 14.3.235.1; Thu, 17 Mar 2016 17:41:46 +0800 From: Shannon Zhao To: Date: Thu, 17 Mar 2016 17:41:03 +0800 Message-ID: <1458207668-12012-18-git-send-email-zhaoshenglong@huawei.com> X-Mailer: git-send-email 1.9.0.msysgit.0 In-Reply-To: <1458207668-12012-1-git-send-email-zhaoshenglong@huawei.com> References: <1458207668-12012-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.0A020205.56EA7C28.0094, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: bac6c636a8d56c742379c944ad3d80c9 Cc: julien.grall@arm.com, zhaoshenglong@huawei.com, stefano.stabellini@citrix.com, shannon.zhao@linaro.org, peter.huangpeng@huawei.com Subject: [Xen-devel] [PATCH v6 17/22] 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 --- v6: use SZ_64K for GICv3 distributor --- xen/arch/arm/gic-v2.c | 31 +++++++++++++++++++++++++++++++ xen/arch/arm/gic-v3.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/gic.c | 5 +++++ xen/include/asm-arm/gic.h | 3 +++ 4 files changed, 84 insertions(+) diff --git a/xen/arch/arm/gic-v2.c b/xen/arch/arm/gic-v2.c index 02db5f2..186f944 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 @@ -714,6 +715,31 @@ static u32 gicv2_make_hwdom_madt(const struct domain *d, u32 offset) return table_len; } +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); +} + static int __init gic_acpi_parse_madt_cpu(struct acpi_subtable_header *header, const unsigned long end) @@ -809,6 +835,10 @@ static u32 gicv2_make_hwdom_madt(const struct domain *d, u32 offset) { return 0; } +static int gicv2_iomem_deny_access(const struct domain *d) +{ + return 0; +} #endif static int __init gicv2_init(void) @@ -902,6 +932,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 d9fce4b..7f9634d 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 @@ -1278,6 +1279,45 @@ static u32 gicv3_make_hwdom_madt(const struct domain *d, u32 offset) return table_len; } +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; +} + static int __init gic_acpi_parse_madt_cpu(struct acpi_subtable_header *header, const unsigned long end) @@ -1426,6 +1466,10 @@ static u32 gicv3_make_hwdom_madt(const struct domain *d, u32 offset) { return 0; } +static int gicv3_iomem_deny_access(const struct domain *d) +{ + return 0; +} #endif /* Set up the GIC */ @@ -1521,6 +1565,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 6d32432..65022ee 100644 --- a/xen/arch/arm/gic.c +++ b/xen/arch/arm/gic.c @@ -744,6 +744,11 @@ u32 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 4cf003d..932fc02 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 */ u32 (*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); u32 gic_make_hwdom_madt(const struct domain *d, u32 offset); +int gic_iomem_deny_access(const struct domain *d); #endif /* __ASSEMBLY__ */ #endif