From patchwork Wed Mar 12 16:16:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 26148 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f198.google.com (mail-ie0-f198.google.com [209.85.223.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 266B3203AB for ; Wed, 12 Mar 2014 16:18:01 +0000 (UTC) Received: by mail-ie0-f198.google.com with SMTP id to1sf39704550ieb.5 for ; Wed, 12 Mar 2014 09:18:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:list-id:list-unsubscribe:list-post :list-help:list-subscribe:mime-version:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list :list-archive:content-type:content-transfer-encoding; bh=m9znqMWufoQrMVVh+bbcLIkF4KJg49kniYRxrqAIcIQ=; b=ZKT/UFzDjA5jE/Ydhlf3ohyvUh3qmIGa7FQVEYbfi906lve1dsfN8XMh0iP0T/N9Lf cpkacjZX26xxIXEQSR10eftYg1KXMapl0MOLbeDL928RzS15yHhWDxMbPNNS7RGKeFWR L+UtdNF4EakC5KQ9oxgNnlxBvXdIzLWaf2TGlDSrUW9l/Ugt17lZ3C37g+YhmXS8hl/N 00fdl89NSCAuxSX1paPYipuPXGLuVFTSTMmahXAEFz3qa89dMYbOA6HngfNeXlgiON9S GE9LkayYTjAPiu81rRXhbtm8JpOe2gDH+vSWZ42J6MEv2DZ+VdFJeHOwegyYrTYmssOB Q4gw== X-Gm-Message-State: ALoCoQma1OSlt1dXqUMbGbm49nxAWsUYmhrtt6ktYxVOCi5nBk18zPcwoTIN9JjRe04zwePwxvKg X-Received: by 10.51.16.65 with SMTP id fu1mr12748557igd.3.1394641081511; Wed, 12 Mar 2014 09:18:01 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.47.50 with SMTP id l47ls2956574qga.49.gmail; Wed, 12 Mar 2014 09:18:01 -0700 (PDT) X-Received: by 10.52.69.146 with SMTP id e18mr31099463vdu.15.1394641081123; Wed, 12 Mar 2014 09:18:01 -0700 (PDT) Received: from mail-ve0-f177.google.com (mail-ve0-f177.google.com [209.85.128.177]) by mx.google.com with ESMTPS id f9si4498278vck.112.2014.03.12.09.18.01 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 12 Mar 2014 09:18:01 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.177; Received: by mail-ve0-f177.google.com with SMTP id sa20so10175169veb.8 for ; Wed, 12 Mar 2014 09:18:01 -0700 (PDT) X-Received: by 10.220.136.6 with SMTP id p6mr33359614vct.9.1394641081014; Wed, 12 Mar 2014 09:18:01 -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.220.78.9 with SMTP id i9csp301348vck; Wed, 12 Mar 2014 09:18:00 -0700 (PDT) X-Received: by 10.224.43.200 with SMTP id x8mr49158222qae.43.1394641080505; Wed, 12 Mar 2014 09:18:00 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id 107si13173535qgn.158.2014.03.12.09.17.59 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 12 Mar 2014 09:18:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xen.org designates 50.57.142.19 as permitted sender) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WNlqC-00084L-Le; Wed, 12 Mar 2014 16:17:12 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WNlqA-00081W-GN for xen-devel@lists.xenproject.org; Wed, 12 Mar 2014 16:17:10 +0000 Received: from [85.158.137.68:22879] by server-13.bemta-3.messagelabs.com id 29/D8-18692-58880235; Wed, 12 Mar 2014 16:17:09 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-5.tower-31.messagelabs.com!1394640993!189089!1 X-Originating-IP: [209.85.212.180] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.11.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 731 invoked from network); 12 Mar 2014 16:16:33 -0000 Received: from mail-wi0-f180.google.com (HELO mail-wi0-f180.google.com) (209.85.212.180) by server-5.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 12 Mar 2014 16:16:33 -0000 Received: by mail-wi0-f180.google.com with SMTP id hm4so2628836wib.7 for ; Wed, 12 Mar 2014 09:16:33 -0700 (PDT) X-Received: by 10.194.63.145 with SMTP id g17mr2041041wjs.72.1394640993537; Wed, 12 Mar 2014 09:16:33 -0700 (PDT) Received: from belegaer.uk.xensource.com. ([185.25.64.249]) by mx.google.com with ESMTPSA id dk9sm70840335wjb.4.2014.03.12.09.16.32 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Mar 2014 09:16:32 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 12 Mar 2014 16:16:04 +0000 Message-Id: <1394640969-25583-10-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1394640969-25583-1-git-send-email-julien.grall@linaro.org> References: <1394640969-25583-1-git-send-email-julien.grall@linaro.org> Cc: stefano.stabellini@citrix.com, Daniel De Graaf , Julien Grall , tim@xen.org, ian.campbell@citrix.com Subject: [Xen-devel] [RFC 09/14] xen/xsm: flask: MSI is PCI specific X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) 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 List-Archive: MSI is not yet support on ARM and will break the compilation when XSM_ENABLE=y. Signed-off-by: Julien Grall Cc: Daniel De Graaf Acked-by: Daniel De Graaf --- xen/xsm/flask/hooks.c | 72 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 20 deletions(-) diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c index 65343f3..56c7645 100644 --- a/xen/xsm/flask/hooks.c +++ b/xen/xsm/flask/hooks.c @@ -19,7 +19,9 @@ #include #include #include +#ifdef HAS_PCI #include +#endif #include #include #include @@ -100,7 +102,6 @@ static int domain_has_xen(struct domain *d, u32 perms) static int get_irq_sid(int irq, u32 *sid, struct avc_audit_data *ad) { - struct irq_desc *desc = irq_to_desc(irq); if ( irq >= nr_irqs || irq < 0 ) return -EINVAL; if ( irq < nr_static_irqs ) { @@ -110,15 +111,21 @@ static int get_irq_sid(int irq, u32 *sid, struct avc_audit_data *ad) } return security_irq_sid(irq, sid); } - if ( desc->msi_desc && desc->msi_desc->dev ) { - struct pci_dev *dev = desc->msi_desc->dev; - u32 sbdf = (dev->seg << 16) | (dev->bus << 8) | dev->devfn; - if (ad) { - AVC_AUDIT_DATA_INIT(ad, DEV); - ad->device = sbdf; +#ifdef HAS_PCI + { + struct irq_desc *desc = irq_to_desc(irq); + if ( desc->msi_desc && desc->msi_desc->dev ) { + struct pci_dev *dev = desc->msi_desc->dev; + u32 sbdf = (dev->seg << 16) | (dev->bus << 8) | dev->devfn; + if (ad) { + AVC_AUDIT_DATA_INIT(ad, DEV); + ad->device = sbdf; + } + return security_device_sid(sbdf, sid); } - return security_device_sid(sbdf, sid); } +#endif + if (ad) { AVC_AUDIT_DATA_INIT(ad, IRQ); ad->irq = irq; @@ -825,21 +832,34 @@ static int flask_map_domain_pirq (struct domain *d) return current_has_perm(d, SECCLASS_RESOURCE, RESOURCE__ADD); } +static int flask_map_domain_msi (struct domain *d, int irq, void *data, + u32 *sid, struct avc_audit_data *ad) +{ +#ifdef HAS_PCI + struct msi_info *msi = data; + + u32 machine_bdf = (msi->seg << 16) | (msi->bus << 8) | msi->devfn; + AVC_AUDIT_DATA_INIT(ad, DEV); + ad->device = machine_bdf; + + return security_device_sid(machine_bdf, sid); +#else + return -EINVAL; +#endif +} + static int flask_map_domain_irq (struct domain *d, int irq, void *data) { u32 sid, dsid; int rc = -EPERM; - struct msi_info *msi = data; struct avc_audit_data ad; - if ( irq >= nr_static_irqs && msi ) { - u32 machine_bdf = (msi->seg << 16) | (msi->bus << 8) | msi->devfn; - AVC_AUDIT_DATA_INIT(&ad, DEV); - ad.device = machine_bdf; - rc = security_device_sid(machine_bdf, &sid); + if ( irq >= nr_static_irqs && data ) { + rc = flask_map_domain_msi(d, irq, data, &sid, &ad); } else { rc = get_irq_sid(irq, &sid, &ad); } + if ( rc ) return rc; @@ -858,18 +878,30 @@ static int flask_unmap_domain_pirq (struct domain *d) return current_has_perm(d, SECCLASS_RESOURCE, RESOURCE__REMOVE); } +static int flask_unmap_domain_msi (struct domain *d, int irq, void *data, + u32 *sid, struct avc_audit_data *ad) +{ +#ifdef HAS_PCI + struct msi_info *msi = data; + u32 machine_bdf = (msi->seg << 16) | (msi->bus << 8) | msi->devfn; + + AVC_AUDIT_DATA_INIT(ad, DEV); + ad->device = machine_bdf; + + return security_device_sid(machine_bdf, sid); +#else + return -EINVAL; +#endif +} + static int flask_unmap_domain_irq (struct domain *d, int irq, void *data) { u32 sid; int rc = -EPERM; - struct msi_info *msi = data; struct avc_audit_data ad; - if ( irq >= nr_static_irqs && msi ) { - u32 machine_bdf = (msi->seg << 16) | (msi->bus << 8) | msi->devfn; - AVC_AUDIT_DATA_INIT(&ad, DEV); - ad.device = machine_bdf; - rc = security_device_sid(machine_bdf, &sid); + if ( irq >= nr_static_irqs && data ) { + rc = flask_unmap_domain_msi(d, irq, data, &sid, &ad); } else { rc = get_irq_sid(irq, &sid, &ad); }