Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp878554imw; Mon, 4 Jul 2022 23:02:46 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vBxC1GWb3y2EsnQpP+s3Aj49x9aaFbSi1P4qJUBbTI/Al1pZaiW2sgaXKuTAypa4hoCR1N X-Received: by 2002:a63:9701:0:b0:40c:a588:b488 with SMTP id n1-20020a639701000000b0040ca588b488mr28144622pge.303.1657000966626; Mon, 04 Jul 2022 23:02:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657000966; cv=none; d=google.com; s=arc-20160816; b=pRACT/1iBLbLBrHj8umc4VdXTesn9rydTnDDfjk0lG0eH5YQy8seXKQ4TNOWEs9qgx uHOhDY7k2qvQw2FwoaMvBYQzCOQxdBTsuxElerOgca3eA1qWL33DJLCqu1zW6Q0V1t3M 4LiHfSCiIMDZ3emgoopXB+C0+SkVi7Ew/zvdjuY5SIkFuOf3MjDQpo3LN94aDjRGFG9u sgdlvpFICKzICI5zJ0ZQNkgldO2jne1ppVq73WXmP/KEdwKTn+/H8/DdOhJ03M0Tloye a9UvnnSCCSW6saj0tGn9JlManT7aRTdK0w+23P1vm5HBpxQ1SCHJoavNilGjgXEGexR3 AmmQ== 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=es573CVOK/ixJ9cpC79OFLHbiVERW6IIGADpV1bwsA4=; b=NDS0D3XMYwO2oLnDLLeiOMOngRXBJ4iIEwtuXHTsGDLK5DJ6+zY4On/JhqdkeMNXiF DMGDT3nmtcuFpaFq9dm8UJYsIKzX9ctgiHFHG0CDPt4yac9i2k6LlTmrrPcrdYQUASkl GB2IwIqEGrk0pCRfw9MyB2y9HDt/KNEcjKfhDJvA5Ha+ArBR1rxb8LW5bt0qWzfZsvil fNSFld9hd5SGesScAVWEV4UthTixFgmCPX1Hz1x9tbyreUUJWQWffwiysPGQ/nsKx23N vHYys44fLhvrcJlA/dm8PNLpKs/Yaz8+pAy25SVgf6wdzEF6WIGh6sHJ6aG7raaweK/2 PRqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fkBh1Kil; 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 f18-20020a63de12000000b003fe34775ab6si43885324pgg.286.2022.07.04.23.02.27; Mon, 04 Jul 2022 23:02:46 -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=fkBh1Kil; 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 S229881AbiGEFMd (ORCPT + 99 others); Tue, 5 Jul 2022 01:12:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229746AbiGEFMN (ORCPT ); Tue, 5 Jul 2022 01:12:13 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7289C13D43 for ; Mon, 4 Jul 2022 22:12:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656997928; x=1688533928; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uS+4zAhU3LsHFG2nNclNJmjXA6SLYohmWdVIExa9sM0=; b=fkBh1KilHr/D2Crj1UjNLuIEHiwbaI0UBrJYZ27GxGl1GSnjonzZOsTc 3Tx6Rr1VPhyePf0vLa+i1LrPSlAfSuGUwiTllKvUcUqUeJGdM8PO5BYkI su8dT22LGwozxjbNifMYUbCA4XZyhNxqrkrqEbNZEtlOAjnWYqFLpBPB+ QLnZEp7/9E9veSSn4THkKtzc0YUhU4T/WnvKFDoh+Mr6m0SPm7My4cQ/0 J/HDQ/SblWxRLIdIMojApSn+K7xJ0oS6l1S9s4UKxCuVNkVON0CmuBhXU n0rhekGGpJG6TZjha9lRYKPW/DJIg9Be6cDGwfmSGXtFaAi805X5W1KtD A==; X-IronPort-AV: E=McAfee;i="6400,9594,10398"; a="282011473" X-IronPort-AV: E=Sophos;i="5.92,245,1650956400"; d="scan'208";a="282011473" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jul 2022 22:12:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,245,1650956400"; d="scan'208";a="542807494" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga003.jf.intel.com with ESMTP; 04 Jul 2022 22:12:03 -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 , Zhangfei Gao , Zhu Tony , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v10 06/12] iommu/vt-d: Add SVA domain support Date: Tue, 5 Jul 2022 13:07:04 +0800 Message-Id: <20220705050710.2887204-7-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220705050710.2887204-1-baolu.lu@linux.intel.com> References: <20220705050710.2887204-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.0 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 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 Reviewed-by: Kevin Tian Tested-by: Tony Zhu --- include/linux/intel-iommu.h | 5 ++++ drivers/iommu/intel/iommu.c | 2 ++ drivers/iommu/intel/svm.c | 49 +++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h index 31e3edc0fc7e..9007428a68f1 100644 --- a/include/linux/intel-iommu.h +++ b/include/linux/intel-iommu.h @@ -743,6 +743,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; @@ -768,6 +769,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 44016594831d..993a1ce509a8 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4298,6 +4298,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 d04880a291c3..7d4f9d173013 100644 --- a/drivers/iommu/intel/svm.c +++ b/drivers/iommu/intel/svm.c @@ -931,3 +931,52 @@ int intel_svm_page_response(struct device *dev, mutex_unlock(&pasid_mutex); return ret; } + +static int intel_svm_set_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_block_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(to_dmar_domain(domain)); +} + +static const struct iommu_domain_ops intel_svm_domain_ops = { + .set_dev_pasid = intel_svm_set_dev_pasid, + .block_dev_pasid = intel_svm_block_dev_pasid, + .free = intel_svm_domain_free, +}; + +struct iommu_domain *intel_svm_domain_alloc(void) +{ + struct dmar_domain *domain; + + domain = kzalloc(sizeof(*domain), GFP_KERNEL); + if (!domain) + return NULL; + domain->domain.ops = &intel_svm_domain_ops; + + return &domain->domain; +} -- 2.25.1