Received: by 2002:ab2:687:0:b0:1f4:6588:b3a7 with SMTP id s7csp159186lqe; Tue, 9 Apr 2024 19:12:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWrB/D4O3zh/8Cboey5Qg5yfwOFK98OrJpgGF++ib5vxDN9MaBwCjidk3426PUpblcqUC+yzNyTGZ4DrG8JrdfPznLvmG1bA3QRcpPw8g== X-Google-Smtp-Source: AGHT+IFnoHS+oEBMSEXv3j3lRVaaro3a7opiw7N8D/OsiocHIH84BzUSCitymVOPwokWw6qQslSH X-Received: by 2002:a05:6a00:7006:b0:6ed:caf6:6e54 with SMTP id lf6-20020a056a00700600b006edcaf66e54mr76296pfb.28.1712715159283; Tue, 09 Apr 2024 19:12:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712715159; cv=pass; d=google.com; s=arc-20160816; b=CNKfYcl1mgz1LWn56ilu34/O+ygutb94DNXo2bMYlUpT6KaVlGGNdo93mzJ7mb41RA jwBvPDcwpS1VQBZvWKeOqhJ+dZc3kWLdwqm8sBFZw8w7+w2CCtOp6Z/bzF8YUDyXrrJ9 eMT1O0IPM1a4M9bib6gN6w66Qk6Ywsi58gEuwpDKj0/AjHkNgCUMTgHcAbzhfOJ7PCaJ GzQIinsTi2VZJKpmuRING1kak6Oe0v6DPRinkZf2iNoos5vCShIUWcJTIpu/yCG/3gGt Z68uo3iCKqqBJJnRwpuMK3143g0I9E/0g6882f6HoGkzSQovhHDu7a1qwamew03qPVFc P3PQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ScVvJ5nW4wA6ur5iWFXBo3BDIDleI34HYre6thztvC8=; fh=QV0B1XrLwvNUeUktDnagRy3Hsau+tAky7/nHKoqGuBQ=; b=Z1eipoWEEG7Xn9HjKB2rDeRP+MiTEBlc2tH9eopWLpbsMY2d2yEMYuiS8acFchHZeZ XkCiUCFAZDCnYLljALrPC/IJA/lx/jK//oc4JL4QfJmec1ZP9upAOs00AQc34ZUeYdYH /lHaguUFIyheFTrOc7amCmrNVfPPNbzT+dSl8P26ueRPuE6NlGtdYgd/OcEOPNKvN7kq sJhF3y57/r6K/iale9UXlIFRONFHCZndjvJC5GpQECPUGmK8TZII3qF7kPAdhPWOoRP7 DscsRbEYGmq8QWEUVhjUpvTdE0s9v+e8uSAgEAFNTu/zNugXdnQyEMzCCtlMnQiqoj01 OKOw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="N0DmI/LT"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-137827-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-137827-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id u11-20020a63df0b000000b005e468bd4cadsi9897354pgg.787.2024.04.09.19.12.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 19:12:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-137827-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="N0DmI/LT"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-137827-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-137827-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id F151C284EEA for ; Wed, 10 Apr 2024 02:12:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BF786BA31; Wed, 10 Apr 2024 02:10:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="N0DmI/LT" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B31B29D08 for ; Wed, 10 Apr 2024 02:10:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712715034; cv=none; b=jIbzZJrv3hrQP3+0UXhl3NaQoyEsNYOjwd1lgS0tx2WmnYufD+qCUUbqlAFArZqYn/LEk7iq1g7ivRii9UpFWc/mLVPSR5hW8sNGZDDIBWxsYABS81zwU9iLc0lceZJLmjZ/dTjcFwQbNzQi2wmjxxfJDaB8hAbfPcA2U5ZXW1g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712715034; c=relaxed/simple; bh=Z4N9WjZXB3Uq7GgVWrBbRtPl6f+yBep/k+sWPTppZwU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qEe3pFndf2GQR+hSuomDl7AhiF+T+pOmnLw5SSt+LPrjEg3oy2NU0C0fglCMnFj716WA++1M9rcmORndj5aJIhuQS5/4USRBReUOw6ZZnf6NYntSlQWTKbmpF6i8KOGQcXaHzs4d0vCESA7EmKxESnMJeKSGfBA3WRIIa8h3KBU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=N0DmI/LT; arc=none smtp.client-ip=198.175.65.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712715034; x=1744251034; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Z4N9WjZXB3Uq7GgVWrBbRtPl6f+yBep/k+sWPTppZwU=; b=N0DmI/LTx15oPeIC2ESylrk+w2fH6hYO5Jhj2F2DbD2ly2G7e9CqPdOW b4TYsXr7UtCxIrSmh/ANP+AKCoCIgxZpAS9mQv5YhYu9pA5TgveCCZC4z Cx8c5ozUP4/QcYxMzEB2H/1ph0W7uprt1W/Ddjc38dqC7JNmbZpmDXQrb PzCy7EPIoG0sun1vDuQ73FbLrZuv7HYNysp3CpeoK8Tw4P8WYciPi+p/r SQxTZaFx0b56qCCe1LaLi1MX/AL3KhIuE+RTUHFXORfQ9f5m1rh2q7BoE jl99ZuHv/lCLhW8qAdKZZ/hDStNc3ON+6BcxvMP5WobiV7gOg0l1H1XO9 A==; X-CSE-ConnectionGUID: FfT84J3YQDyia+aQxhXTGQ== X-CSE-MsgGUID: pWAmjWc/RbqT6JcEmJwZSA== X-IronPort-AV: E=McAfee;i="6600,9927,11039"; a="7918623" X-IronPort-AV: E=Sophos;i="6.07,190,1708416000"; d="scan'208";a="7918623" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Apr 2024 19:10:33 -0700 X-CSE-ConnectionGUID: WHam9GteSOefNDx1SxfR3Q== X-CSE-MsgGUID: 0FmamW2PRGChoDBl7nx6CQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,190,1708416000"; d="scan'208";a="20478942" Received: from unknown (HELO allen-box.sh.intel.com) ([10.239.159.127]) by fmviesa007.fm.intel.com with ESMTP; 09 Apr 2024 19:10:29 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Kevin Tian , Jason Gunthorpe Cc: Tina Zhang , Yi Liu , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Jason Gunthorpe , Vasant Hegde , Lu Baolu Subject: [PATCH v2 11/12] iommu: Add ops->domain_alloc_sva() Date: Wed, 10 Apr 2024 10:08:43 +0800 Message-Id: <20240410020844.253535-12-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240410020844.253535-1-baolu.lu@linux.intel.com> References: <20240410020844.253535-1-baolu.lu@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Jason Gunthorpe Make a new op that receives the device and the mm_struct that the SVA domain should be created for. Unlike domain_alloc_paging() the dev argument is never NULL here. This allows drivers to fully initialize the SVA domain and allocate the mmu_notifier during allocation. It allows the notifier lifetime to follow the lifetime of the iommu_domain. Since we have only one call site, upgrade the new op to return ERR_PTR instead of NULL. Signed-off-by: Jason Gunthorpe [Removed smmu3 related changes - Vasant] Signed-off-by: Vasant Hegde Reviewed-by: Tina Zhang Link: https://lore.kernel.org/r/20240311090843.133455-15-vasant.hegde@amd.com Signed-off-by: Lu Baolu --- include/linux/iommu.h | 3 +++ drivers/iommu/iommu-sva.c | 16 +++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 2e925b5eba53..8aabe83af8f2 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -518,6 +518,7 @@ static inline int __iommu_copy_struct_from_user_array( * Upon failure, ERR_PTR must be returned. * @domain_alloc_paging: Allocate an iommu_domain that can be used for * UNMANAGED, DMA, and DMA_FQ domain types. + * @domain_alloc_sva: Allocate an iommu_domain for Shared Virtual Addressing. * @probe_device: Add device to iommu driver handling * @release_device: Remove device from iommu driver handling * @probe_finalize: Do final setup work after the device is added to an IOMMU @@ -558,6 +559,8 @@ struct iommu_ops { struct device *dev, u32 flags, struct iommu_domain *parent, const struct iommu_user_data *user_data); struct iommu_domain *(*domain_alloc_paging)(struct device *dev); + struct iommu_domain *(*domain_alloc_sva)(struct device *dev, + struct mm_struct *mm); struct iommu_device *(*probe_device)(struct device *dev); void (*release_device)(struct device *dev); diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c index 640acc804e8c..18a35e798b72 100644 --- a/drivers/iommu/iommu-sva.c +++ b/drivers/iommu/iommu-sva.c @@ -108,8 +108,8 @@ struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct mm_struct *mm /* Allocate a new domain and set it on device pasid. */ domain = iommu_sva_domain_alloc(dev, mm); - if (!domain) { - ret = -ENOMEM; + if (IS_ERR(domain)) { + ret = PTR_ERR(domain); goto out_free_handle; } @@ -283,9 +283,15 @@ struct iommu_domain *iommu_sva_domain_alloc(struct device *dev, const struct iommu_ops *ops = dev_iommu_ops(dev); struct iommu_domain *domain; - domain = ops->domain_alloc(IOMMU_DOMAIN_SVA); - if (!domain) - return NULL; + if (ops->domain_alloc_sva) { + domain = ops->domain_alloc_sva(dev, mm); + if (IS_ERR(domain)) + return domain; + } else { + domain = ops->domain_alloc(IOMMU_DOMAIN_SVA); + if (!domain) + return ERR_PTR(-ENOMEM); + } domain->type = IOMMU_DOMAIN_SVA; mmgrab(mm); -- 2.34.1