Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp60208ybg; Mon, 27 Jul 2020 23:25:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzyDjuQBc4JmtyWBnoZ/DfuUf355Dj06BmudY2g8jbz1nOiZU/E+9nJaLoyb8mGxWaNLA5L X-Received: by 2002:a17:906:1fd7:: with SMTP id e23mr11005298ejt.174.1595917527295; Mon, 27 Jul 2020 23:25:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595917527; cv=none; d=google.com; s=arc-20160816; b=I7iDS2u5/yTlNBv8cvB5JXNd/BCEH2iJpTi3Y9jG7QR9EzMy5UFQiI3LKnw+xXkmiG 60gYHyGFQQcp8mecvQoDkRGazDrsOh4rIBAXazRj1moiLG33gSRBcT1plVM25iw2YP3X jn6Lnq+LCHESMbdgWlX5EasHaM+RbwK5Zs88ty4w8yI7f+1E3qssI2Ro2QnGYkRKdEzx V7CHXgRneCA9Y6AYW8fUVTo1nXRhEMQ54uYm6XBZlBaQb/qD93ZAPil314B+hXFlLVgj HVQl+rVl6LhSmzSmqpmTG5UdQduonJ/2myiVeLJoMTAbzvqYOWzi/uoCHkZBCnQq5KLr EF4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:ironport-sdr:ironport-sdr; bh=hHNM6jY5Fmm5T+m5eSW9wRZvLH8s7B+BbXpih/f50ho=; b=T7UxmuQvCjsVs7RKKuPAnnPhHc8zPuTrbF87utxcAUAyzUzn2bxmZ4v9LzI6pF0HmL ezQpJIgk0ueHde9gQuS56zNfOKESGHzEFKiGLDBjAIr8zLc1l0iPmDnN46Tz+IokzvJh 6lzoWs53kybY0vlUGE9bn5BqwC9RAZ3E/e2cS6aNdc4/xbHn+gbvTSU1GHfVHQbSUvlP 2Mjtz8ZNul7uKoM7NKZCxuV9iGm/85Z0Ln2Ps3xTOwnfhaUpvQS063jbaHAzgW4zCwMG gqTNUKsgQDMDfwOH3SqShFQJKYPCY+864Gyyo9zceQhWjtLe1iTOAdTwaUITENk/XyzW ivVw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q3si6987166ejb.105.2020.07.27.23.25.04; Mon, 27 Jul 2020 23:25:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728099AbgG1GVw (ORCPT + 99 others); Tue, 28 Jul 2020 02:21:52 -0400 Received: from mga06.intel.com ([134.134.136.31]:26366 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727843AbgG1GVA (ORCPT ); Tue, 28 Jul 2020 02:21:00 -0400 IronPort-SDR: RsOp3H5EilCTJU/fzQlfQwGybB2yFTbpiV+kDSC6oBfjDW6aF0EFNjrt6KFlS1a6fRfjHZ/Zek MoNz4fBufX1g== X-IronPort-AV: E=McAfee;i="6000,8403,9695"; a="212681243" X-IronPort-AV: E=Sophos;i="5.75,405,1589266800"; d="scan'208";a="212681243" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jul 2020 23:20:56 -0700 IronPort-SDR: VyiBPr0vNrmCxDGcQ4QUdenaeG+1yPbpJCBMsRehXlNnm35WfPyqKxQLtiAyFNi/MAWs+5uP1I 7ICjs52dC6Iw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,405,1589266800"; d="scan'208";a="320274409" Received: from jacob-builder.jf.intel.com ([10.7.199.155]) by orsmga008.jf.intel.com with ESMTP; 27 Jul 2020 23:20:55 -0700 From: Liu Yi L To: alex.williamson@redhat.com, eric.auger@redhat.com, baolu.lu@linux.intel.com, joro@8bytes.org Cc: kevin.tian@intel.com, jacob.jun.pan@linux.intel.com, ashok.raj@intel.com, yi.l.liu@intel.com, jun.j.tian@intel.com, yi.y.sun@intel.com, jean-philippe@linaro.org, peterx@redhat.com, hao.wu@intel.com, stefanha@gmail.com, iommu@lists.linux-foundation.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 09/15] iommu/vt-d: Check ownership for PASIDs from user-space Date: Mon, 27 Jul 2020 23:27:38 -0700 Message-Id: <1595917664-33276-10-git-send-email-yi.l.liu@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1595917664-33276-1-git-send-email-yi.l.liu@intel.com> References: <1595917664-33276-1-git-send-email-yi.l.liu@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When an IOMMU domain with nesting attribute is used for guest SVA, a system-wide PASID is allocated for binding with the device and the domain. For security reason, we need to check the PASID passed from user-space. e.g. page table bind/unbind and PASID related cache invalidation. Cc: Kevin Tian CC: Jacob Pan Cc: Alex Williamson Cc: Eric Auger Cc: Jean-Philippe Brucker Cc: Joerg Roedel Cc: Lu Baolu Signed-off-by: Liu Yi L Signed-off-by: Jacob Pan --- drivers/iommu/intel/iommu.c | 10 ++++++++++ drivers/iommu/intel/svm.c | 7 +++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index b2fe54e..88f4647 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -5436,6 +5436,7 @@ intel_iommu_sva_invalidate(struct iommu_domain *domain, struct device *dev, int granu = 0; u64 pasid = 0; u64 addr = 0; + void *pdata; granu = to_vtd_granularity(cache_type, inv_info->granularity); if (granu == -EINVAL) { @@ -5456,6 +5457,15 @@ intel_iommu_sva_invalidate(struct iommu_domain *domain, struct device *dev, (inv_info->granu.addr_info.flags & IOMMU_INV_ADDR_FLAGS_PASID)) pasid = inv_info->granu.addr_info.pasid; + pdata = ioasid_find(dmar_domain->ioasid_sid, pasid, NULL); + if (!pdata) { + ret = -EINVAL; + goto out_unlock; + } else if (IS_ERR(pdata)) { + ret = PTR_ERR(pdata); + goto out_unlock; + } + switch (BIT(cache_type)) { case IOMMU_CACHE_INV_TYPE_IOTLB: /* HW will ignore LSB bits based on address mask */ diff --git a/drivers/iommu/intel/svm.c b/drivers/iommu/intel/svm.c index c85b8d5..b9b29ad 100644 --- a/drivers/iommu/intel/svm.c +++ b/drivers/iommu/intel/svm.c @@ -323,7 +323,7 @@ int intel_svm_bind_gpasid(struct iommu_domain *domain, struct device *dev, dmar_domain = to_dmar_domain(domain); mutex_lock(&pasid_mutex); - svm = ioasid_find(INVALID_IOASID_SET, data->hpasid, NULL); + svm = ioasid_find(dmar_domain->ioasid_sid, data->hpasid, NULL); if (IS_ERR(svm)) { ret = PTR_ERR(svm); goto out; @@ -440,6 +440,7 @@ int intel_svm_unbind_gpasid(struct iommu_domain *domain, struct device *dev, u32 pasid) { struct intel_iommu *iommu = intel_svm_device_to_iommu(dev); + struct dmar_domain *dmar_domain; struct intel_svm_dev *sdev; struct intel_svm *svm; int ret = -EINVAL; @@ -447,8 +448,10 @@ int intel_svm_unbind_gpasid(struct iommu_domain *domain, if (WARN_ON(!iommu)) return -EINVAL; + dmar_domain = to_dmar_domain(domain); + mutex_lock(&pasid_mutex); - svm = ioasid_find(INVALID_IOASID_SET, pasid, NULL); + svm = ioasid_find(dmar_domain->ioasid_sid, pasid, NULL); if (!svm) { ret = -EINVAL; goto out; -- 2.7.4