Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp4274376rwb; Tue, 16 Aug 2022 18:40:47 -0700 (PDT) X-Google-Smtp-Source: AA6agR41sneXQyeIEBDj5OIMipiYOELlN1Mev7YbAHcPRCebtrnmq8YSgSKnFR05L3QruM0Xmel9 X-Received: by 2002:a05:6402:14e:b0:443:f58:17e9 with SMTP id s14-20020a056402014e00b004430f5817e9mr21221768edu.106.1660700447288; Tue, 16 Aug 2022 18:40:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660700447; cv=none; d=google.com; s=arc-20160816; b=cu4O+iZFxGNdOymckpSNGX3ndTeJmh8haQrE1/vZLlOz8jlfT/HhyQPpqbarzqynZP wZmdqeCVNsujOyw8CagL1laf9mqzLcQ7XCkoiAUCKYlIQ0DuiblgZWQ59MtLSGIJaLZC zawhJ9kTfHe1KpYvUTXz7UJnVR7zUZT/JYdId8+8MXqVF+Ocn96KLqO8YI8vP5ehHkWT REn35WW4N4x7cqXXoq2A99UW3yGIXAg5MPRpxBh8l/RbuTx+metmMqzuuLrvFKFFI03n xuoLYHo3Rmury8HNIg5Q6p0uIn1je7UzgelaqoMc2cQFnb9R050I3bRbDh4tcxdxJUoq nRtw== 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=53Zk4FW5QnmB9d2Sxb3M/sTCzvv2gjzkwoS8r9k5e2c=; b=rM9EC2TXNUMtEgdr7ZKN6sEhMn/9+zz5j2aPCz8WfgMapPGPV1uQKLO2fhqOHEXuiX vIpmuo3yvggTurq/Bc/AQ6otAIPLMvAL95UHkVhHrDb6sYx2+S1dupPW8JZeajH6jrJS 5CFEOQ+jwxUXeoribc1syXP8VF8AhPh1kfTjaBqg9gzngKKAB+5Wp35bXMH1+pmuDzsx rVGm9tepGqQSjin7J8B9x41oC1XrSFg6HqidLzBkFgjF+naTVCSegobnARzJpQrHtWtx WkA+hyGSr1OJFbCChU2mvLKsHnH24PjnMAoJ6rKSaJhdeN6YZsRVrFp2Db6gudDAz5pM mu8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gWschs1b; 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 r26-20020a056402019a00b0043d54ba0a4dsi10128828edv.327.2022.08.16.18.40.20; Tue, 16 Aug 2022 18:40:47 -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=gWschs1b; 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 S238181AbiHQB0u (ORCPT + 99 others); Tue, 16 Aug 2022 21:26:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238176AbiHQB0c (ORCPT ); Tue, 16 Aug 2022 21:26:32 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0BBA93517; Tue, 16 Aug 2022 18:26:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660699587; x=1692235587; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8BCQ4kwr1wi2UO2jjixrLUtiYCgHqXE7Y9gzTIR+eQ4=; b=gWschs1bdGXZadi0n9aIYSiWRVftPN7YOiG4wOZhOOeZVgIJLWBG2Kcv VQfiThyHM7WjKhDbBEcyI2sQiVA6MQscXYtYonaG5wXny2XrczYOoHw6E 2loPq8N7u0tN7Eyr2XTbQCYwebE/5k/pKiCc10N6P9RbnnY5P7L9MStVT aWyabpmxiSfFywhB3XBoha98JyykPPQw0TNHdHuanmLoJYfQmpY2RWpi8 GrBPGFhq9rrdeVd3CWLoOXrdPcyEc8sYvVALWoEXKP+DeTVJuKVG/fGj5 6kJI5m57aDx8ZGXmTImMWlmi9/LTk579E91PL9t6qM7oFc9wFgvaMIWcn g==; X-IronPort-AV: E=McAfee;i="6400,9594,10441"; a="293649235" X-IronPort-AV: E=Sophos;i="5.93,242,1654585200"; d="scan'208";a="293649235" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2022 18:26:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,242,1654585200"; d="scan'208";a="696587930" Received: from allen-box.sh.intel.com ([10.239.159.48]) by FMSMGA003.fm.intel.com with ESMTP; 16 Aug 2022 18:26:17 -0700 From: Lu Baolu To: Joerg Roedel , Jason Gunthorpe , Christoph Hellwig , Bjorn Helgaas , 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-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v11 07/13] iommu/vt-d: Add SVA domain support Date: Wed, 17 Aug 2022 09:20:18 +0800 Message-Id: <20220817012024.3251276-8-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220817012024.3251276-1-baolu.lu@linux.intel.com> References: <20220817012024.3251276-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 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. This implementation is based on the existing SVA code. Possible cleanup and refactoring are left for incremental changes later. Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian Reviewed-by: Jason Gunthorpe Reviewed-by: Yi Liu --- drivers/iommu/intel/iommu.h | 5 ++++ drivers/iommu/intel/iommu.c | 2 ++ drivers/iommu/intel/svm.c | 50 +++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index a9b8367c9361..4875c9974abd 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -747,6 +747,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; @@ -772,6 +773,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 7cca030a508e..27c9fd6139a8 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4149,6 +4149,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 2420fa5c2360..16a4d413fce4 100644 --- a/drivers/iommu/intel/svm.c +++ b/drivers/iommu/intel/svm.c @@ -928,3 +928,53 @@ 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 iommu_sva *sva; + int ret = 0; + + mutex_lock(&pasid_mutex); + /* + * Detach the domain if a blocking domain is set. Check the + * right domain type once the IOMMU driver supports a real + * blocking domain. + */ + if (!domain || domain->type == IOMMU_DOMAIN_UNMANAGED) { + intel_svm_unbind_mm(dev, pasid); + } else { + struct mm_struct *mm = domain->mm; + + 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_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, + .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