From patchwork Mon Jun 16 16:17:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 31996 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f199.google.com (mail-ob0-f199.google.com [209.85.214.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 97E5420E7A for ; Mon, 16 Jun 2014 16:20:45 +0000 (UTC) Received: by mail-ob0-f199.google.com with SMTP id va2sf32039982obc.6 for ; Mon, 16 Jun 2014 09:20:45 -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=Brn0K++uDo39y7ToJUDK+ddrtMRjzeV76tb5/c6zKRo=; b=JgXP4PfGPoWB0wd04uE+Qz6SmprPqsBLmQeWtIkIsC8kNezKp4SlbuQhPT0Vjq8nHO of5Vk8SyPiPRb7SBEX9BqdTMs3I40HTwIt51KD/JPyeXxEuEO/FlTvvZe/YKCtDC+O3l pwPKfsFPcxSEi+onJmi9yVHX1E/4w1Y/r6pt03JWYurniiR/9YaAMT5GfQZCro8wpWDv ajpAQC89Zj/b9OfO25YEFYn9VVKQubM/LWyusiMv/+17mMAHe/cBFscxE1qdk25ICOsU 7pZfvJ0QEbcEKKdCayCtzneXz9deT9HerFfRyviusG8TOcia0H2Xnbhodu2mLCeLeQds m1dg== X-Gm-Message-State: ALoCoQn7PxgsoQaWer+I1+iLU2cnwiSW2EHPfEgdSWJ0nkMBae/F+ARu8QJQC56UXvI5kKl6m+/i X-Received: by 10.182.27.40 with SMTP id q8mr3145397obg.22.1402935645276; Mon, 16 Jun 2014 09:20:45 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.23.212 with SMTP id 78ls863829qgp.39.gmail; Mon, 16 Jun 2014 09:20:45 -0700 (PDT) X-Received: by 10.58.108.129 with SMTP id hk1mr400113veb.68.1402935645183; Mon, 16 Jun 2014 09:20:45 -0700 (PDT) Received: from mail-vc0-f175.google.com (mail-vc0-f175.google.com [209.85.220.175]) by mx.google.com with ESMTPS id e7si4285183vey.73.2014.06.16.09.20.45 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 16 Jun 2014 09:20:45 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.175 as permitted sender) client-ip=209.85.220.175; Received: by mail-vc0-f175.google.com with SMTP id hy4so5078406vcb.20 for ; Mon, 16 Jun 2014 09:20:45 -0700 (PDT) X-Received: by 10.220.44.141 with SMTP id a13mr385507vcf.71.1402935645106; Mon, 16 Jun 2014 09:20:45 -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.221.54.6 with SMTP id vs6csp146227vcb; Mon, 16 Jun 2014 09:20:44 -0700 (PDT) X-Received: by 10.224.161.138 with SMTP id r10mr29194750qax.2.1402935644717; Mon, 16 Jun 2014 09:20:44 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id q8si13825844qai.25.2014.06.16.09.20.44 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 16 Jun 2014 09:20:44 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) 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 1WwZcA-0006pD-1I; Mon, 16 Jun 2014 16:18:34 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WwZc9-0006nV-89 for xen-devel@lists.xenproject.org; Mon, 16 Jun 2014 16:18:33 +0000 Received: from [85.158.139.211:10869] by server-13.bemta-5.messagelabs.com id 28/0B-02995-8D81F935; Mon, 16 Jun 2014 16:18:32 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-16.tower-206.messagelabs.com!1402935511!7376298!1 X-Originating-IP: [74.125.82.51] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 24347 invoked from network); 16 Jun 2014 16:18:31 -0000 Received: from mail-wg0-f51.google.com (HELO mail-wg0-f51.google.com) (74.125.82.51) by server-16.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 16 Jun 2014 16:18:31 -0000 Received: by mail-wg0-f51.google.com with SMTP id x12so5698351wgg.34 for ; Mon, 16 Jun 2014 09:18:31 -0700 (PDT) X-Received: by 10.180.76.132 with SMTP id k4mr28796797wiw.1.1402935511658; Mon, 16 Jun 2014 09:18:31 -0700 (PDT) Received: from belegaer.uk.xensource.com ([185.25.64.249]) by mx.google.com with ESMTPSA id l45sm34836161eep.25.2014.06.16.09.18.30 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Jun 2014 09:18:30 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 16 Jun 2014 17:17:59 +0100 Message-Id: <1402935486-29136-13-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1402935486-29136-1-git-send-email-julien.grall@linaro.org> References: <1402935486-29136-1-git-send-email-julien.grall@linaro.org> Cc: stefano.stabellini@citrix.com, Julien Grall , tim@xen.org, ian.campbell@citrix.com Subject: [Xen-devel] [RFC 12/19] xen/passthrough: iommu_deassign_device_dt: By default reassign device to nobody 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=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.175 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 List-Archive: Currently, when the device is deassigned from a domain, we directly reassign to DOM0. As the device may not have been correctly reset, this may lead to corrupt or expose some part of DOM0 memory. If Xen reassigns the device to "nobody", it may receive some global/context fault because the transaction has failed (indeed the context has been marked invalid). DOM0 will have to issue an hypercall to assign the device to itself if it wants to use it. Signed-off-by: Julien Grall --- xen/drivers/passthrough/arm/smmu.c | 7 ++++--- xen/drivers/passthrough/device_tree.c | 8 +++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c index f4eb2a2..b25034e 100644 --- a/xen/drivers/passthrough/arm/smmu.c +++ b/xen/drivers/passthrough/arm/smmu.c @@ -1245,8 +1245,8 @@ static int arm_smmu_reassign_dt_dev(struct domain *s, struct domain *t, { int ret = 0; - /* Don't allow remapping on other domain than hwdom */ - if ( t != hardware_domain ) + /* Allow remapping either on the hardware domain or to nothing */ + if ( t && t != hardware_domain ) return -EPERM; if ( t == s ) @@ -1256,7 +1256,8 @@ static int arm_smmu_reassign_dt_dev(struct domain *s, struct domain *t, if ( ret ) return ret; - ret = arm_smmu_attach_dev(t, dev); + if ( t ) + ret = arm_smmu_attach_dev(t, dev); return ret; } diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthrough/device_tree.c index afb4dfc..8a4bc69 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -75,14 +75,12 @@ int iommu_deassign_dt_device(struct domain *d, struct dt_device_node *dev) spin_lock(&dtdevs_lock); - rc = hd->platform_ops->reassign_dt_device(d, hardware_domain, dev); + rc = hd->platform_ops->reassign_dt_device(d, NULL, dev); if ( rc ) goto fail; - list_del(&dev->domain_list); - - dt_device_set_used_by(dev, hardware_domain->domain_id); - list_add(&dev->domain_list, &domain_hvm_iommu(hardware_domain)->dt_devices); + list_del_init(&dev->domain_list); + dt_device_set_used_by(dev, DOMID_IO); fail: spin_unlock(&dtdevs_lock);