Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1121605ybh; Sun, 19 Jul 2020 09:09:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxo5JcrwaLifvWQfV1JXx63vc3Tqto5otHd0DozpqcDdno0kuGndt0LGAtYsR28deVoMkgx X-Received: by 2002:a17:906:c201:: with SMTP id d1mr17014931ejz.40.1595174995117; Sun, 19 Jul 2020 09:09:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595174995; cv=none; d=google.com; s=arc-20160816; b=u2LTK3LqCEnxQcg5Q8qdyBVz8QvihFFtlx7LY6UkVJWM0STk21qHaEFXb4PncMzIUy FqNtVt4Mv6RBX9FKygGKK+67DlfsFfvP9+uCodPvCTpcH2SADyraAo5wbkcJU6Neur6B MHetFK0jIAcb1yHJ9BIDJaD/rZMfkKXOfD25OhbfRZuIh+7zYFl02rUqgBCIou8PKOZr 2JgAQyrdtwGZB2y0ex+VgUiyWVAcJXK5ulW1K39iIyD+biz8vU1AXoJUu+XO6B4TNN3h nVv2b2sDAkDhcaIIGnxS1IS9UW4JkjJ6RKkFl3W44HwbgZoag2fDpJADGhy6szXRkZRy 5d9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=qvn7ah9yf4ty3GXyVniTDmRhC/pcWFvbVoRwSMY5+K0=; b=aY6kZEVTRccDVA4Nelc8fM050lfZ7EpAqbbjJHg65b6+O5RFyZkQdiyImW8Ggqfkxn ff2I9INPqCeX/BATT0ujiOt90u1Yyne6YFIhuAfE2k3ZGydMzCTEgdSTQ+4mHHLR+DQb G3sK4v0imZiGyK/4PtwaRBiu7CxJYjWDLsgYh7BvLIPpwzvZOaFQGRMj4qu7m+XOIUNS 7bfWNQR7U04AbUWdleRhWbv+2SS7n3HdLjjCBKq1okOGzOgcbkewJbLpC87Ot8cGhcUH R3ap2shiqV3lvmJxql1n8v9MLxerKPr2sWgNIqZ8G6A0HBAP+438NEcRRwpL9ilpDhd7 0reA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PxlSaHQg; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d19si9567413ejt.396.2020.07.19.09.09.32; Sun, 19 Jul 2020 09:09:55 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PxlSaHQg; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726255AbgGSQGR (ORCPT + 99 others); Sun, 19 Jul 2020 12:06:17 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:49326 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726135AbgGSQGR (ORCPT ); Sun, 19 Jul 2020 12:06:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595174775; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qvn7ah9yf4ty3GXyVniTDmRhC/pcWFvbVoRwSMY5+K0=; b=PxlSaHQgPaJZMhUhB/ERIK4y6pavVRlBcWYXtvKNtRNJ73sHhVv4nkos/F2zsBgtm+NcCE +5rsoOdvQQDjWiJn7a0KiKutg06yZzQwcMan5qsPBqr1mpmtE6Bdklny3asgUi+uZ9PDfM 0FFROadcd5wigd7FjDL+/X+dZWx16OM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-474-Oax_5lNPP8a5oDpzki4syg-1; Sun, 19 Jul 2020 12:06:13 -0400 X-MC-Unique: Oax_5lNPP8a5oDpzki4syg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5984A1005504; Sun, 19 Jul 2020 16:06:11 +0000 (UTC) Received: from [10.36.115.54] (ovpn-115-54.ams2.redhat.com [10.36.115.54]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 398A472E45; Sun, 19 Jul 2020 16:06:02 +0000 (UTC) Subject: Re: [PATCH v5 09/15] iommu/vt-d: Check ownership for PASIDs from user-space To: Liu Yi L , alex.williamson@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, 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 References: <1594552870-55687-1-git-send-email-yi.l.liu@intel.com> <1594552870-55687-10-git-send-email-yi.l.liu@intel.com> From: Auger Eric Message-ID: Date: Sun, 19 Jul 2020 18:06:00 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <1594552870-55687-10-git-send-email-yi.l.liu@intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Yi, On 7/12/20 1:21 PM, Liu Yi L wrote: > 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 passsed from user-space. passed > 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 4d54198..a9504cb 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 d2c0e1a..212dee0 100644 > --- a/drivers/iommu/intel/svm.c > +++ b/drivers/iommu/intel/svm.c > @@ -319,7 +319,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); I do not get what the call was supposed to do before that patch? > + svm = ioasid_find(dmar_domain->ioasid_sid, data->hpasid, NULL); > if (IS_ERR(svm)) { > ret = PTR_ERR(svm); > goto out; > @@ -436,6 +436,7 @@ int intel_svm_unbind_gpasid(struct iommu_domain *domain, > struct device *dev, ioasid_t 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; > @@ -443,8 +444,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); just to make sure, about the locking, can't domain->ioasid_sid change under the hood? Thanks Eric > if (!svm) { > ret = -EINVAL; > goto out; >