Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp3506376ioo; Wed, 25 May 2022 02:04:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZ87x1b1R2ENmrZU65078FAWydgsf1xvzZhh0GJpY5FYzdY0BJPTnANLK5nW+kBtW8SDEE X-Received: by 2002:a17:907:868c:b0:6fe:fd7a:e0d7 with SMTP id qa12-20020a170907868c00b006fefd7ae0d7mr8746761ejc.90.1653469459501; Wed, 25 May 2022 02:04:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653469459; cv=none; d=google.com; s=arc-20160816; b=Lca2gCtDee57V4z3+FrYgWn7XV6UV3Qx0RoDj4Be0XvuukjykWocEU9DRgz5MICvbc 1QTXXCw78XROd4/lZsuNUmr2h74GJC060hv4ydzM8smENWi3sDSXz7Wt0f5vMaIQL+JW 8rDaZLzWvs1T2bLAQs+mSA4HRm/YvW4KFsvvNxYvO9oZwo2I8YN1ig/XRowPUIPk0sLz BPD5V/1KpGguMzCuiusMkRFYxu84IWmaViOzgTIwI8ZXMMKX0OLbigx2wljTjEemFyOy 4x+YohaRAtTx9kAHKNDxxuIhGnLJpiL7L9S9T+Es4+6cDgfW8hRDOCRgBA8XFXWQ4YIt Yzag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:to:content-language:subject:cc:user-agent:mime-version :date:message-id:dkim-signature; bh=Gl8lhq6BfPG5L/7wig98CekpBFqWCskrBUyB41/VXQ4=; b=hw4BxLVzG4o1A26Xk7vmz13tNcUFbN8Xi5q6B9JTC9/NJZS1dCZj0bW4IhB6uEK2ge j6WTdPCzhWBoXaCNmCQIa6CbObZMWnSe8IdibqLXzZtt0hDGuO9nqFTDxwO55w2hShHr jbs189tIfam0+7H3/R5z8aQTrrTB4b9ZZUhSPuDdbaZ+MLwTNWawr+PV76Snl6wyXAHy /4MSi29y+tG5fACmFauu6rCnEl5Jt+O+zLXe4cOZsFPOAPzvRUbVx/6LZeceotn9taaf eBman8hwRzR0H21PWs3+5TJIZDoq/U3WZ2zeV3C5aYly7BkchJ8vxoaASTP3vJfEziJZ /evw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Bz07Cdun; 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 gn36-20020a1709070d2400b006f3976ed175si20388761ejc.938.2022.05.25.02.03.52; Wed, 25 May 2022 02:04:19 -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=Bz07Cdun; 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 S243060AbiEYEuP (ORCPT + 99 others); Wed, 25 May 2022 00:50:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229653AbiEYEuL (ORCPT ); Wed, 25 May 2022 00:50:11 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16F1771DA8 for ; Tue, 24 May 2022 21:50:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653454210; x=1684990210; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=pjZMmEANMCnklIA4vkBd2ENvVE8LwaQZspI3mdFXeHY=; b=Bz07Cdun7geUfgE5rloSint2MN1vCaXC2vhxMSOPIRkM/DudzNfMxO5d G96PK8kHTkR3DNkpoAhOk5B7vMKYLPkzm7Ebndrnb2N3VhbgAcCAamKPh 7mywDkNJq8wqUSAzfMzQZXl5XDqKPFy1BBk4/8BkhtPzYRLlR1Wdeetrg KYYmB7pRKHL+ev2oGBSiZ8WlJrpWy7UOeAWMz5w6NGfWTRBImOQyK2wQT mH9A1G8NZGrlU6pw2kOkDFSjyBabZQpnvOb1TZCXYrdj9Z9ctXahJwap7 Z/AS6IAe8PmPu/cIyX5MRNJRCFe+Czh94r3vwAoCfSaQjWu5FYM1hTFL+ g==; X-IronPort-AV: E=McAfee;i="6400,9594,10357"; a="336769629" X-IronPort-AV: E=Sophos;i="5.91,250,1647327600"; d="scan'208";a="336769629" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 May 2022 21:50:09 -0700 X-IronPort-AV: E=Sophos;i="5.91,250,1647327600"; d="scan'208";a="601652421" Received: from jwang96-mobl.ccr.corp.intel.com (HELO [10.255.29.139]) ([10.255.29.139]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 May 2022 21:50:06 -0700 Message-ID: Date: Wed, 25 May 2022 12:50:04 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Cc: baolu.lu@linux.intel.com, Eric Auger , "Liu, Yi L" , "Pan, Jacob jun" , "iommu@lists.linux-foundation.org" , "linux-kernel@vger.kernel.org" , Jean-Philippe Brucker Subject: Re: [PATCH v7 03/10] iommu/sva: Add iommu_sva_domain support Content-Language: en-US To: "Tian, Kevin" , Joerg Roedel , Jason Gunthorpe , Christoph Hellwig , "Raj, Ashok" , Will Deacon , Robin Murphy , Jean-Philippe Brucker , "Jiang, Dave" , Vinod Koul References: <20220519072047.2996983-1-baolu.lu@linux.intel.com> <20220519072047.2996983-4-baolu.lu@linux.intel.com> From: Baolu Lu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,NICE_REPLY_A,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 On 2022/5/24 17:39, Tian, Kevin wrote: >> From: Lu Baolu >> Sent: Thursday, May 19, 2022 3:21 PM >> >> The iommu_sva_domain represents a hardware pagetable that the IOMMU >> hardware could use for SVA translation. This adds some infrastructure >> to support SVA domain in the iommu common layer. It includes: >> >> - Add a new struct iommu_sva_domain and new IOMMU_DOMAIN_SVA >> domain >> type. >> - Add a new domain ops pointer in iommu_ops. The IOMMU drivers that >> support SVA should provide the callbacks. >> - Add helpers to allocate and free an SVA domain. >> - Add helpers to set an SVA domain to a device and the reverse >> operation. >> >> Some buses, like PCI, route packets without considering the PASID value. >> Thus a DMA target address with PASID might be treated as P2P if the >> address falls into the MMIO BAR of other devices in the group. To make >> things simple, the attach/detach interfaces only apply to devices >> belonging to the singleton groups, and the singleton is immutable in >> fabric i.e. not affected by hotplug. >> >> The iommu_set/block_device_pasid() can be used for other purposes, >> such as kernel DMA with pasid, mediation device, etc. Hence, it is put >> in the iommu.c. > > usually we have 'set/clear' pair or 'allow/block'. Having 'set' paired > with 'block' doesn't read very clearly. Yes. Let's still use the attach/detach semantics. > >> +static bool device_group_immutable_singleton(struct device *dev) >> +{ >> + struct iommu_group *group = iommu_group_get(dev); > > what about passing group as the parameter since the caller will > get the group again right after calling this function? In that case > the function could be renamed as: > > iommu_group_immutable_singleton() > > or be shorter: > > iommu_group_fixed_singleton() Fair enough. I will tune it as below: +static bool iommu_group_immutable_singleton(struct iommu_group *group) +{ + int count; + + mutex_lock(&group->mutex); + count = iommu_group_device_count(group); + mutex_unlock(&group->mutex); + + if (count != 1) + return false; + + /* + * The PCI device could be considered to be fully isolated if all + * devices on the path from the device to the host-PCI bridge are + * protected from peer-to-peer DMA by ACS. + */ + if (dev_is_pci(dev)) + return pci_acs_path_enabled(to_pci_dev(dev), NULL, + REQ_ACS_FLAGS); + + /* + * Otherwise, the device came from DT/ACPI, assume it is static and + * then singleton can know from the device count in the group. + */ + return true; +} > >> + int count; >> + >> + if (!group) >> + return false; >> + >> + mutex_lock(&group->mutex); >> + count = iommu_group_device_count(group); >> + mutex_unlock(&group->mutex); >> + iommu_group_put(group); >> + >> + if (count != 1) >> + return false; > > For non-pci devices above doesn't check anything against immutable. > Please add some comment to explain why doing so is correct. Yes, as above code shows. > >> + >> + /* >> + * The PCI device could be considered to be fully isolated if all >> + * devices on the path from the device to the host-PCI bridge are >> + * protected from peer-to-peer DMA by ACS. >> + */ >> + if (dev_is_pci(dev)) >> + return pci_acs_path_enabled(to_pci_dev(dev), NULL, >> + REQ_ACS_FLAGS); >> + >> + return true; >> +} >> + Best regards, baolu