Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3904882iog; Tue, 21 Jun 2022 08:11:55 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vuy34D92rTbkGtBlKyQC95mDq51peciMvBkNXey+7s/wigXvOwvPQq4od2wWivJtvFb/X1 X-Received: by 2002:aa7:c846:0:b0:431:6c7b:26af with SMTP id g6-20020aa7c846000000b004316c7b26afmr35768875edt.123.1655824314965; Tue, 21 Jun 2022 08:11:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655824314; cv=none; d=google.com; s=arc-20160816; b=xKEomnlxXSx5E8T8955e+FJY64QuhiCkn307JQjyBsNDbltsYFjxL8upTf+NAtqI6S rO41w3O1EsejrgtQGj8UPJDUDNCoFWQT4KVuA7tA9QwWxZScTfzpYm5TLgrVnnEIwwMe VK0oXqGTcCsDVFtH0POz1jTaAesO9BIUbxpBnHnmiBq/T9l9na19sPvAt/lC266P9GZn 99if4X+cMDZcpg4c93l34hNfQFlvISe7JVxzH5jJUuFdaVzpOsDZYhXzolmczwJRgOy4 ZN4dpZP1W/uKhRydNvz73Fxk6wTPMZpQHPbyOw0Ln8BSRcwYi9z9lUl3vW5/7v+PCdoc E7Gg== 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=bmoyv07D7/rdE4jGMnJccg7oFjI1LTqvPasF44UbBt0=; b=T66Ph8nwHnXaKcXqh0EnMu1BHq0PghPJw72na/8KnsPy69djHpOFS94E9L+CDbmGio R9WZq1KRx6OabcYymrudUGDMBUB34lBzVr/wDI59t+24xitnLa80qQ3Z88q6Yqn98qFa gC/EjxG/fPvL0yWOeI2He9VKUEFm7BdEUQahS6e5M9vRk/B6/xGa8PsUz+E2bviDOcwD 0wYrlFgvRGSjWy0nmqw+gtKJu0HyjaKDnMochoWlj+mUx7G9uNIfsXAIwcvds9BNEfZe Mkm+cuNPE2WBkZDBBoJNPUMjcfe5CsnjwZ2uePRPlu/jgcCN1Xa3ed+D2J5dsyHbH/Tj nA8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Siv+oeM+; 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 30-20020a170906209e00b006ff03a0cdf6si13475128ejq.951.2022.06.21.08.11.26; Tue, 21 Jun 2022 08:11:54 -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=Siv+oeM+; 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 S1351921AbiFUOsv (ORCPT + 99 others); Tue, 21 Jun 2022 10:48:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351905AbiFUOs1 (ORCPT ); Tue, 21 Jun 2022 10:48:27 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C995101C6 for ; Tue, 21 Jun 2022 07:48:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1655822906; x=1687358906; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ycx1bkVXPrbmcJKHWTEOkCYhcIUfTBYC7pxFYcHJfLU=; b=Siv+oeM+DwIs/F+He4c4/9DEFVLkMNZh+ejVMvYfEijJ+PXwEi/PkEx1 oYrEPIDmAfe3vi4Pz8vyzL9wfOckOSEYHboDeiYxLX9kOnBdsFQDrMCXa Ac2f/NAC3ZOawiUjMvMzyO9mdcqpPnkMUB9KcLA0v9EfJxhUFe1FjqMl/ 9G1PbGLJV7xyvb3nqqPitFXBjC3SGDPjm70lwQUj/Z1poDYb0VYi0pZWi UaiPZy8FEjxrR9NqNlHjxFVMQPXqG1XQq6Ws0p9pXydfefyMXJN+DAkI2 lPzUd/dogQrat022Qu+bMytsdpumugUzfFFzl+BXfh7iTZTVzi8yrwKLQ Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10384"; a="260566674" X-IronPort-AV: E=Sophos;i="5.92,209,1650956400"; d="scan'208";a="260566674" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jun 2022 07:48:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,209,1650956400"; d="scan'208";a="643659292" Received: from allen-box.sh.intel.com ([10.239.159.48]) by fmsmga008.fm.intel.com with ESMTP; 21 Jun 2022 07:48:20 -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, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v9 05/11] iommu/vt-d: Add SVA domain support Date: Tue, 21 Jun 2022 22:43:47 +0800 Message-Id: <20220621144353.17547-6-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220621144353.17547-1-baolu.lu@linux.intel.com> References: <20220621144353.17547-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 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 | 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