From patchwork Fri Mar 25 13:48:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 8671641 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B306D9FC57 for ; Fri, 25 Mar 2016 13:51:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B34B42034A for ; Fri, 25 Mar 2016 13:51:46 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 53F59202E9 for ; Fri, 25 Mar 2016 13:51:45 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ajS8D-00029u-Kq; Fri, 25 Mar 2016 13:50:29 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ajS8C-00027o-Bd for xen-devel@lists.xen.org; Fri, 25 Mar 2016 13:50:28 +0000 Received: from [85.158.137.68] by server-11.bemta-3.messagelabs.com id 2F/2E-02978-32245F65; Fri, 25 Mar 2016 13:50:27 +0000 X-Env-Sender: shannon.zhao@linaro.org X-Msg-Ref: server-8.tower-31.messagelabs.com!1458913825!31541478!1 X-Originating-IP: [209.85.192.179] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 8.11; banners=-,-,- X-VirusChecked: Checked Received: (qmail 12385 invoked from network); 25 Mar 2016 13:50:26 -0000 Received: from mail-pf0-f179.google.com (HELO mail-pf0-f179.google.com) (209.85.192.179) by server-8.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 25 Mar 2016 13:50:26 -0000 Received: by mail-pf0-f179.google.com with SMTP id n5so83054264pfn.2 for ; Fri, 25 Mar 2016 06:50:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=hIk/UvMllPSY6eyYqg8FM1DEkuAQpSZukX+gB6lQtow=; b=aFi2eBMxO88K5wFaDiVCCngghg8sudT4kzWv4PLUA7rIvz2iDoyu029xpI//ytAQNN J/QBvMD/gT30cixozA2IuQBJ9H1oxN/aD1tWNN8ftxbFsVy/OqTVN7XNuQKc1QxPYWb/ YstZ5PnFU+IiVPVj5SdilOOSEVbWXLobWjqpk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=hIk/UvMllPSY6eyYqg8FM1DEkuAQpSZukX+gB6lQtow=; b=Q/OU11UC+732iOqGPrFciJe3E9bPrfJif43HNUP5SfsPKHg4xxQrWopCJ/WwdXH0+Y FZuozNQdlVcxl1LO/M3ftYWhkF1qIZsrQ1QF2nu9AuPWR3J7hNNu20Y+yjeFMpoyeURL 6wghb2Bt3vvjK++viUHVme7S0VxM63cPj7gYun9zlpdJ0YjkDkvm1VA8RD3Xcvg6TOUU sgRJ+2k6QXg1bYXqBeqnXjsMwMR0TPTSm4PH86QahSE023bJyJCocTnCFKHNYNFGAeTW cA+9WV6orEVvTXMt1Mz4fg5Wcbu0fvollyCjmpJjyqasgcq7bD6NIFJHbcLfZ9IYwZhs AvJw== X-Gm-Message-State: AD7BkJIJTPN6ZJ9AM9pq6NFc8UtDMPQpX0YSJW5mvY3TwxGADNlYqgNtQYYzdtWODKHLVCrh X-Received: by 10.98.86.157 with SMTP id h29mr21187231pfj.105.1458913825006; Fri, 25 Mar 2016 06:50:25 -0700 (PDT) Received: from localhost.localdomain ([45.56.152.2]) by smtp.gmail.com with ESMTPSA id w20sm16744178pfi.31.2016.03.25.06.50.20 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 25 Mar 2016 06:50:24 -0700 (PDT) From: Shannon Zhao To: xen-devel@lists.xen.org Date: Fri, 25 Mar 2016 21:48:50 +0800 Message-Id: <1458913735-2678-18-git-send-email-shannon.zhao@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1458913735-2678-1-git-send-email-shannon.zhao@linaro.org> References: <1458913735-2678-1-git-send-email-shannon.zhao@linaro.org> Cc: julien.grall@arm.com, shannon.zhao@linaro.org, stefano.stabellini@citrix.com, peter.huangpeng@huawei.com, zhaoshenglong@huawei.com Subject: [Xen-devel] [PATCH v7 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: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- v7: move them out of CONFIG_ACPI --- 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