Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp5923024iob; Tue, 10 May 2022 06:48:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKDutWDKw6Gx7dpAoLw411h3/+jSd3i7bYkzepFefXFcGBBkzO2kUgxalttvGy+V2Z4c0E X-Received: by 2002:aa7:cb1a:0:b0:41c:dd9c:2eaa with SMTP id s26-20020aa7cb1a000000b0041cdd9c2eaamr23156565edt.119.1652190535692; Tue, 10 May 2022 06:48:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652190535; cv=none; d=google.com; s=arc-20160816; b=dutgusV5OSITn+DHHM7Wkh+rvARlZaBQ8ebePUPt0sXDxKsOhhfqhaw5LFnw65vd5u S7AwQrLxZ4yf/s0qKPLQwPRWw+0Ep0wo5YyKRcFi4kT8ulqUAsGzYqzHX6WhfPQX8Usn xMYeghbHtHaDsi3sO40ueVGiQg7ISbeorpdLvDsCseOckXVoBOSYJysrvNGWxgKo1KJA DhIJ7Lt6vnpDT/6NjtzdiMVXyGL31I9o0/YADlvd9u/x1SRcoPZGPPB/Q4Sjkqs5Tbd5 TW2X7SHoOwv0K9DvvFYDzodUDcpK76ytf2b6L2DLV4J0rxy3asWRFyubVSdGDqpJcXkm fs/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0IX+Br8KZx3WceDIRs+w+U9lxY91VFDHNMcbSoLm68E=; b=AImCNGJkV9qBq9s8LDoLimoOdPOiJ54TqV928rwzQxfA0owkw3oY8Jcs1C4G2LJwlZ 8YfftnGR74VhIlyKSCFW3hpam86q87dkVMQdg/b7uYvAxBJERodEFXpw8ve0ffvKaN16 Jom3UPwrW7Leh6BovpJEMz3vNidoKel2O+UU4sL2v4mzH9CqwJLDvk2OS1WXoD750cYX HoWwzSuUjM9T8v5HUvbJg5VlDPNpt9KpsM0qbBiCEPXVGa5vi0ZhB75A4Gp04X8PS051 U0tYjGqJG/KE+hxPiB7/URDJ1vG25mHvcL1wyHIwmmiNIVEafzA1DHmnEivSwdotm4vB 3Jpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=D40f6HCY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z12-20020a50e68c000000b00425bc76ecddsi18835328edm.337.2022.05.10.06.48.29; Tue, 10 May 2022 06:48:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=D40f6HCY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237176AbiEJGZc (ORCPT + 99 others); Tue, 10 May 2022 02:25:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237106AbiEJGZL (ORCPT ); Tue, 10 May 2022 02:25:11 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B61631900 for ; Mon, 9 May 2022 23:21:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1652163672; x=1683699672; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2oif/KlXSEUCU88GJ6ATwpartNvHpX2RX3MjlkgL9ng=; b=D40f6HCY4Z/DA7L+DZQcREjTlcsXvO5bJLcyqeL/O+ipb6dU+d5RBDMl enO3IpliwW+WJKZ4WjeAtR0dCPjPS+OmULpN75sDcBHQrOGXW+bZN6tKt MBpRIabtUryqRozcFA4UPa69TF2blOskPrNmHthmcz1bKnzEP+huVqJVO yYnTVhiC4DnTdXJmrCaFn63IBXl8CO54iWj8FwxKVguZoQQZB+2S2QD0Z rBrpfJCOrM5KyIySyaEo6dnjtjxSGo4mCXdbXdHCo+eZx+r/b1Ym+LJE0 xaS0PInA/mln9wbw18HscRtgV2fsbFpJTvmy8nzrRP5gV8FPW+hRIcCsX Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10342"; a="332312960" X-IronPort-AV: E=Sophos;i="5.91,213,1647327600"; d="scan'208";a="332312960" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 May 2022 23:21:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,213,1647327600"; d="scan'208";a="552636499" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga002.jf.intel.com with ESMTP; 09 May 2022 23:21:08 -0700 From: Lu Baolu To: Joerg Roedel , Jason Gunthorpe , Christoph Hellwig , Kevin Tian , Ashok Raj , Will Deacon , Robin Murphy , Jean-Philippe Brucker , Dave Jiang , Vinod Koul Cc: Eric Auger , Liu Yi L , Jacob jun Pan , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v6 06/12] iommu/vt-d: Add SVA domain support Date: Tue, 10 May 2022 14:17:32 +0800 Message-Id: <20220510061738.2761430-7-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220510061738.2761430-1-baolu.lu@linux.intel.com> References: <20220510061738.2761430-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support for SVA domain allocation and provide an SVA-specific iommu_domain_ops. Signed-off-by: Lu Baolu --- include/linux/intel-iommu.h | 5 ++++ drivers/iommu/intel/iommu.c | 2 ++ drivers/iommu/intel/svm.c | 48 +++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h index 72e5d7900e71..2397c2007cda 100644 --- a/include/linux/intel-iommu.h +++ b/include/linux/intel-iommu.h @@ -744,6 +744,7 @@ void intel_svm_unbind(struct iommu_sva *handle); u32 intel_svm_get_pasid(struct iommu_sva *handle); int intel_svm_page_response(struct device *dev, struct iommu_fault_event *evt, struct iommu_page_response *msg); +struct iommu_domain *intel_svm_domain_alloc(void); struct intel_svm_dev { struct list_head list; @@ -769,6 +770,10 @@ struct intel_svm { }; #else static inline void intel_svm_check(struct intel_iommu *iommu) {} +static inline struct iommu_domain *intel_svm_domain_alloc(void) +{ + return NULL; +} #endif #ifdef CONFIG_INTEL_IOMMU_DEBUGFS diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 99643f897f26..10b1e9dcbd98 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4343,6 +4343,8 @@ static struct iommu_domain *intel_iommu_domain_alloc(unsigned type) return domain; case IOMMU_DOMAIN_IDENTITY: return &si_domain->domain; + case IOMMU_DOMAIN_SVA: + return intel_svm_domain_alloc(); default: return NULL; } diff --git a/drivers/iommu/intel/svm.c b/drivers/iommu/intel/svm.c index 574ddddaa33a..641ab0491ada 100644 --- a/drivers/iommu/intel/svm.c +++ b/drivers/iommu/intel/svm.c @@ -931,3 +931,51 @@ int intel_svm_page_response(struct device *dev, mutex_unlock(&pasid_mutex); return ret; } + +static int intel_svm_attach_dev_pasid(struct iommu_domain *domain, + struct device *dev, ioasid_t pasid) +{ + struct device_domain_info *info = dev_iommu_priv_get(dev); + struct intel_iommu *iommu = info->iommu; + struct mm_struct *mm = domain->mm; + struct iommu_sva *sva; + int ret = 0; + + mutex_lock(&pasid_mutex); + sva = intel_svm_bind_mm(iommu, dev, mm); + if (IS_ERR(sva)) + ret = PTR_ERR(sva); + mutex_unlock(&pasid_mutex); + + return ret; +} + +static void intel_svm_detach_dev_pasid(struct iommu_domain *domain, + struct device *dev, ioasid_t pasid) +{ + mutex_lock(&pasid_mutex); + intel_svm_unbind_mm(dev, pasid); + mutex_unlock(&pasid_mutex); +} + +static void intel_svm_domain_free(struct iommu_domain *domain) +{ + kfree(domain); +} + +static const struct iommu_domain_ops intel_svm_domain_ops = { + .attach_dev_pasid = intel_svm_attach_dev_pasid, + .detach_dev_pasid = intel_svm_detach_dev_pasid, + .free = intel_svm_domain_free, +}; + +struct iommu_domain *intel_svm_domain_alloc(void) +{ + struct iommu_domain *domain; + + domain = kzalloc(sizeof(*domain), GFP_KERNEL); + if (domain) + domain->ops = &intel_svm_domain_ops; + + return domain; +} -- 2.25.1