Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp984169iob; Thu, 28 Apr 2022 15:40:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrGQ+KUghEkdP01Iwo9oCz6OfKb1bg3UbOsa5fQfEo6A0lF1S9MUv97N/uT2B3TOzb2/ll X-Received: by 2002:a2e:91c7:0:b0:24f:1114:86fd with SMTP id u7-20020a2e91c7000000b0024f111486fdmr14558378ljg.147.1651185601479; Thu, 28 Apr 2022 15:40:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651185601; cv=none; d=google.com; s=arc-20160816; b=FhErKfVwNiwaS8ko0UbfDxOTMKXwQXe+cf9IZ7RNSSfyfH+3io4hDDOkei0/l8Rx7c 7+z1uKK9rspSsZWaJnvjPDBVTsogGJJXbjTQkcG3T07CHZJ1RNxcPyDhyiHVFK44+mzX rXWJvwyKqIGPTEbg3KnuTzGqXzboBTdUF5IrkE/OetHPwVVPxtdTqSTx5S7GKSV2ouTq mFEOfgzbBKFCkTSfFmbKGHrrqMlcVCqV94XUpBPgdJrkaMB1inT/9n6K+Ll8XlAm1BJp IiDSPEgkhmDDcQBy45wbIYhROGd9k0x4UqxjqBfYi91xaRc4f6YwHimbjr+KBxY7YgDl dBKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=XB6h972j5Zc5Yul0kh9vlaIZfxycg9OQhkbmMJ/20t8=; b=TeR+CgJGq9JPuUYGUByIB8vrkHiwAREt4ndQGMMCBSdJZJayxRZmaB2OIpaLCGM45w iNjsBjcsYIPcKMlwUA0nYJKdJwmj63fb8xwhybkvaTm+fxf84elMj1gtcye3B6UWCIBY aetTOYdKqIovivH6y0nn9aYm/X7GERBW6NAlxXo0B9q7mYolf4ai6p8lZyoaxZPUw8OT rI+I8gyJ2uO0L3X+xiDCYSYVtO1DdCRMYpr0y39LDWCGLYGkre1URRb+leEOJ4S0gw1t ehZn3wW/CroSqgk2QlsrLojP0rIpHQ9ENf8mbwTaMCE8FSbAsAKrsbKloWMmzn4pohay /xNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="c/ri+iwJ"; 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=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p9-20020a2ea409000000b0024dd43af724si5167511ljn.317.2022.04.28.15.39.34; Thu, 28 Apr 2022 15:40:01 -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=@linaro.org header.s=google header.b="c/ri+iwJ"; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235883AbiD1O5T (ORCPT + 99 others); Thu, 28 Apr 2022 10:57:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235854AbiD1O5L (ORCPT ); Thu, 28 Apr 2022 10:57:11 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71539B1AB2 for ; Thu, 28 Apr 2022 07:53:56 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id j15so7157732wrb.2 for ; Thu, 28 Apr 2022 07:53:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=XB6h972j5Zc5Yul0kh9vlaIZfxycg9OQhkbmMJ/20t8=; b=c/ri+iwJu54XxDDUxjRAyyeZXQg/x1z/8UR7R7qAnFzlIKkGhpuZSRtt5g+hSLafJB eR7InkulNarobbYa+axDXjKwE4ictyyHFKt4f+/zQXhYz73cWLBD+LK8/ForutsXBl0C JIRRMq6/jfDigNP7R6bS5UJMUf19Ki2MAmxeFjC4GXvxZnEwK6up3bFvn56+fgj+jdGO mgwO+zZ7ZHpSYDD8pV8IY9EiC1X6v1FiDD49K/a/165zmInJQANi3nYO5NigmcbdZDpm 6RyZxKMGbEhh8JbJI+xkQAw3AJJrIdAFk98aq6I+qyEKnzT/TLU41K+KI2mPmdh8MvOc iDmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=XB6h972j5Zc5Yul0kh9vlaIZfxycg9OQhkbmMJ/20t8=; b=LN6pdE4Ls30s9vQih5PZnufHiVam7YWLccqBvuFwK9XNf6xZNjh0UKsZNHtxEMTQFc hkgsXag6iT/+awDJsUi0ONnImH5Y08kgiPgelqJvjkdZQniJlCBt+kAFmP4b6AP+nQQt HP/Svj5Nq9/Xfyy/JFE+AB7y+cSa3ntO5nYgBDykbtboaA1QM4+n6OkmxbtCqmYxBOLK 511CAIBpZCEBeAeSImJRvRBjvR0P0XeKfA9/VNfpFKm3FeGyNBI789m9tZOz3kNC1kLK hEgqHFAGkoglglpFe87toWivKGHXI4KGRBxkdF70iIrQTl7j+fNgg5aja4xXxo16/pcw NGuQ== X-Gm-Message-State: AOAM533rtxp+7Ci3Xcwz5VJ08h5tENA4NjMMVs2Q0NIvQL6m1W+sWLIS 4XtbDjncnU30IsBJ5hTc8iPVBQ== X-Received: by 2002:adf:d1ea:0:b0:20a:2823:9e22 with SMTP id g10-20020adfd1ea000000b0020a28239e22mr27163586wrd.332.1651157635031; Thu, 28 Apr 2022 07:53:55 -0700 (PDT) Received: from myrica (cpc92880-cmbg19-2-0-cust679.5-4.cable.virginm.net. [82.27.106.168]) by smtp.gmail.com with ESMTPSA id f10-20020adff98a000000b0020af37b8d62sm43481wrr.113.2022.04.28.07.53.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 07:53:54 -0700 (PDT) Date: Thu, 28 Apr 2022 15:53:29 +0100 From: Jean-Philippe Brucker To: Lu Baolu Cc: Joerg Roedel , Jason Gunthorpe , Christoph Hellwig , Kevin Tian , Ashok Raj , Will Deacon , Robin Murphy , Jean-Philippe Brucker , Eric Auger , Liu Yi L , Jacob jun Pan , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 03/12] iommu: Add attach/detach_dev_pasid domain ops Message-ID: References: <20220421052121.3464100-1-baolu.lu@linux.intel.com> <20220421052121.3464100-4-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220421052121.3464100-4-baolu.lu@linux.intel.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS 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 Thu, Apr 21, 2022 at 01:21:12PM +0800, Lu Baolu wrote: > Attaching an IOMMU domain to a PASID of a device is a generic operation > for modern IOMMU drivers which support PASID-granular DMA address > translation. Currently visible usage scenarios include (but not limited): > > - SVA (Shared Virtual Address) > - kernel DMA with PASID > - hardware-assist mediated device > > This adds a pair of common domain ops for this purpose and adds helpers > to attach/detach a domain to/from a {device, PASID}. 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, these > interfaces only apply to devices belonging to the singleton groups, and > the singleton is immutable in fabric i.e. not affected by hotplug. > > Signed-off-by: Lu Baolu [...] > +/* > + * Use standard PCI bus topology, isolation features, and DMA > + * alias quirks to check the immutable singleton attribute. If > + * the device came from DT, assume it is static and then > + * singleton can know from the device count in the group. > + */ > +static bool device_group_immutable_singleton(struct device *dev) > +{ > + struct iommu_group *group = iommu_group_get(dev); > + 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; > + > + if (dev_is_pci(dev)) { > + struct pci_dev *pdev = to_pci_dev(dev); > + > + /* > + * The 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 (!pci_acs_path_enabled(pdev, NULL, REQ_ACS_FLAGS)) > + return false; > + > + /* Filter out devices which has any alias device. */ > + if (pci_for_each_dma_alias(pdev, has_pci_alias, pdev)) > + return false; Aren't aliases already added to the group by pci_device_group()? If so it's part of the count check above > + > + return true; > + } > + > + /* > + * If the device came from DT, assume it is static and then > + * singleton can know from the device count in the group. > + */ > + return is_of_node(dev_fwnode(dev)); I don't think DT is relevant here because a platform device enumerated through ACPI will also have its own group. It should be safe to stick to what the IOMMU drivers declare with their device_group() callback. Except for PCI those groups should be immutable so we can return true here. Thanks, Jean