From patchwork Thu Feb 11 14:34:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 61770 Delivered-To: patches@linaro.org Received: by 10.112.43.199 with SMTP id y7csp228895lbl; Thu, 11 Feb 2016 06:35:35 -0800 (PST) X-Received: by 10.28.211.130 with SMTP id k124mr18608466wmg.7.1455201317236; Thu, 11 Feb 2016 06:35:17 -0800 (PST) Return-Path: Received: from mail-wm0-x22e.google.com (mail-wm0-x22e.google.com. [2a00:1450:400c:c09::22e]) by mx.google.com with ESMTPS id k9si12365351wjr.241.2016.02.11.06.35.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Feb 2016 06:35:17 -0800 (PST) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::22e as permitted sender) client-ip=2a00:1450:400c:c09::22e; Authentication-Results: mx.google.com; spf=pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::22e as permitted sender) smtp.mailfrom=eric.auger@linaro.org; dkim=pass header.i=@linaro.org Received: by mail-wm0-x22e.google.com with SMTP id g62so23910888wme.0 for ; Thu, 11 Feb 2016 06:35:17 -0800 (PST) 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=gUfGz16eJsEP9VqOTye+IeDVWz3FO1jjquln5mHcEbU=; b=AGvNIxAJ6teQbZAqBEREek16+9dO7vGQPKsDbZ0uipubRV7IM9KUAI9EyOAaXbDUi0 l79kIBJB3f6Q6M8INQWYECFND3w19mEUqfXtxzbVLuqP10hVShYG2DxOeVQ4IMkzZM4N 1hHhYjy3Aw7N2wUET+yK1iHqO9ZLGCQPJm6BM= 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=gUfGz16eJsEP9VqOTye+IeDVWz3FO1jjquln5mHcEbU=; b=A3dO0WFepSuXvpc/b1Qv6zFK6z6O2bEm1TeIHYK7pNeoXA7afYzvQHla3JPBUzIQHa USZojb5kBz6ui6/Wpclq9oiMdaJNQpQbXUhVLAuGj1ky9M//fHPX3lZbgmL0/PjzLGY2 Uy3c8OAjIPz7ZnuVijzdBeWqZmxtJuyj2iykYC/VE8OjQK7NbIBPUtGgEKkjvfP6EHhz 581iBfOmDrAG3H/rrqrQaurG3mTWGjKqNFH9Tj/fbU4RoXLntR7mHByYjRx1rHoKgYV+ ojJ3rU66TcyET1HR4C0uagBJd3Yf6xwfdMFkOTFsXBvIyNRIIg4zgfrdVPVqcsLSYuuY NVKg== X-Gm-Message-State: AG10YOR9vuJdLiPveyeeA5kBW7x6a2TAHF6el60P9uCj3yh23DM4lozWCAYVOOTAmAvR1TgNo8w= X-Received: by 10.194.203.99 with SMTP id kp3mr46959648wjc.3.1455201317031; Thu, 11 Feb 2016 06:35:17 -0800 (PST) Return-Path: Received: from new-host-12.home (LMontsouris-657-1-37-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id t205sm8290751wmt.23.2016.02.11.06.35.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 11 Feb 2016 06:35:15 -0800 (PST) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, alex.williamson@redhat.com, will.deacon@arm.com, joro@8bytes.org, tglx@linutronix.de, jason@lakedaemon.net, marc.zyngier@arm.com, christoffer.dall@linaro.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Cc: suravee.suthikulpanit@amd.com, patches@linaro.org, linux-kernel@vger.kernel.org, Manish.Jaggi@caviumnetworks.com, Bharat.Bhushan@freescale.com, pranav.sawargaonkar@gmail.com, p.fedin@samsung.com, iommu@lists.linux-foundation.org, sherry.hurwitz@amd.com, brijesh.singh@amd.com, leo.duran@amd.com, Thomas.Lendacky@amd.com Subject: [RFC v2 06/15] iommu/arm-smmu: add a reserved binding RB tree Date: Thu, 11 Feb 2016 14:34:13 +0000 Message-Id: <1455201262-5259-7-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1455201262-5259-1-git-send-email-eric.auger@linaro.org> References: <1455201262-5259-1-git-send-email-eric.auger@linaro.org> we will need to track which host physical addresses are mapped to reserved IOVA. In that prospect we introduce a new RB tree indexed by physical address. This RB tree only is used for reserved IOVA bindings. It is expected this RB tree will contain very few bindings. Those generally correspond to single page mapping one MSI frame (GICv2m frame or ITS GITS_TRANSLATER frame). Signed-off-by: Eric Auger --- drivers/iommu/arm-smmu.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) -- 1.9.1 diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c index f42341d..729a4c6 100644 --- a/drivers/iommu/arm-smmu.c +++ b/drivers/iommu/arm-smmu.c @@ -349,10 +349,21 @@ struct arm_smmu_domain { struct mutex init_mutex; /* Protects smmu pointer */ struct iommu_domain domain; struct iova_domain *reserved_iova_domain; - /* protects reserved domain manipulation */ + /* rb tree indexed by PA, for reserved bindings only */ + struct rb_root reserved_binding_list; + /* protects reserved domain and rbtree manipulation */ struct mutex reserved_mutex; }; +struct arm_smmu_reserved_binding { + struct kref kref; + struct rb_node node; + struct arm_smmu_domain *domain; + phys_addr_t addr; + dma_addr_t iova; + size_t size; +}; + static struct iommu_ops arm_smmu_ops; static DEFINE_SPINLOCK(arm_smmu_devices_lock); @@ -400,6 +411,57 @@ static struct device_node *dev_get_dev_node(struct device *dev) return dev->of_node; } +/* Reserved binding RB-tree manipulation */ + +static struct arm_smmu_reserved_binding *find_reserved_binding( + struct arm_smmu_domain *d, + phys_addr_t start, size_t size) +{ + struct rb_node *node = d->reserved_binding_list.rb_node; + + while (node) { + struct arm_smmu_reserved_binding *binding = + rb_entry(node, struct arm_smmu_reserved_binding, node); + + if (start + size <= binding->addr) + node = node->rb_left; + else if (start >= binding->addr + binding->size) + node = node->rb_right; + else + return binding; + } + + return NULL; +} + +static void link_reserved_binding(struct arm_smmu_domain *d, + struct arm_smmu_reserved_binding *new) +{ + struct rb_node **link = &d->reserved_binding_list.rb_node; + struct rb_node *parent = NULL; + struct arm_smmu_reserved_binding *binding; + + while (*link) { + parent = *link; + binding = rb_entry(parent, struct arm_smmu_reserved_binding, + node); + + if (new->addr + new->size <= binding->addr) + link = &(*link)->rb_left; + else + link = &(*link)->rb_right; + } + + rb_link_node(&new->node, parent, link); + rb_insert_color(&new->node, &d->reserved_binding_list); +} + +static void unlink_reserved_binding(struct arm_smmu_domain *d, + struct arm_smmu_reserved_binding *old) +{ + rb_erase(&old->node, &d->reserved_binding_list); +} + static struct arm_smmu_master *find_smmu_master(struct arm_smmu_device *smmu, struct device_node *dev_node) { @@ -981,6 +1043,7 @@ static struct iommu_domain *arm_smmu_domain_alloc(unsigned type) mutex_init(&smmu_domain->init_mutex); mutex_init(&smmu_domain->reserved_mutex); spin_lock_init(&smmu_domain->pgtbl_lock); + smmu_domain->reserved_binding_list = RB_ROOT; return &smmu_domain->domain; }