Received: by 2002:a05:7412:bc1a:b0:d7:7d3a:4fe2 with SMTP id ki26csp347695rdb; Sat, 19 Aug 2023 04:25:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGpB54WMoHQx+T2RFJ2cYZePwgN6qTITQ8aeoubHz5SGGy6s0hj8CciuY1+oy0MyvaQOvDK X-Received: by 2002:a92:d94e:0:b0:348:f47c:ac60 with SMTP id l14-20020a92d94e000000b00348f47cac60mr2334242ilq.1.1692444349362; Sat, 19 Aug 2023 04:25:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692444349; cv=none; d=google.com; s=arc-20160816; b=ZKm1hKRHm+i/LcGfk88BRNO3tMDH/cmH5nzNuMRdZudcwDyMCQWYcZ4kDUA5+U7GRR j9HXe6ySarHxOiC5H47aDAOcXcle2RWyc3bS/9NAU3itHH3N7Ki7/5Yp6aO6deWhioSl tP+op3PBZWtjWU3PCWoM/vtP40KIDlemfk+9zTQA8zSDYcW4BmPYT0fqjpHxg2WhCy/I kWgSw/km1xiowVfLy0FqCEGs+svmhGyXnxHMutKzPrcJrL4/DQDLEzhXbOmaATvbqUot QJDEQ5i3jJxLRZl+FB6bSBq0Cttn3++3CYELcC+7Rg/DRjK9ZzWPB8efcOGl133sE8FQ JDTA== 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:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=ksxzrf8FU3Cu3QIXCstakeUA88vQOsQlQZl4G4YIRNE=; fh=CGubzfu40/Fp4FTM6W8uZNncSKC7KOArXVFbDflSfsE=; b=RpmK4N0sLl34mA9ckrqdlDZVE6KiTNcULnTJyY1YRL5EVC4YSSMj2TxO+RGGy/Z/e5 pB+mjgCpKNtJ2HY4rQORXdJTP7TWVv/CbgXE3JhenY+XlX02FIkxNSQfJjy2gqbOJUqf d5qxqKIqlbj4DAxJltAh0tjegMK3FCcr/x/7roUJXV2zZ6Yek3Q2z63UWaR5kxJWeeaF 2uONJQtrfFu1f19FZLE3SzEhfPpp1sAwdY3KvyatK80S/1zvzMH8fKmsWRWWhuqLAW1i ZdFvdMu5X+u1rB+H7z//9c4mrmO9X51h0yP6ZKljbIntMbDJ9JwAdBTGHwZMxaRSK782 jNlA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id i2-20020a636d02000000b0055baed7e7e6si3193645pgc.251.2023.08.19.04.25.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Aug 2023 04:25:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 185686371F; Sat, 19 Aug 2023 01:34:02 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379574AbjHRTK6 (ORCPT + 99 others); Fri, 18 Aug 2023 15:10:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379586AbjHRTK3 (ORCPT ); Fri, 18 Aug 2023 15:10:29 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C70C0421B; Fri, 18 Aug 2023 12:10:27 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0405DD75; Fri, 18 Aug 2023 12:11:08 -0700 (PDT) Received: from [10.57.91.158] (unknown [10.57.91.158]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id AFD243F762; Fri, 18 Aug 2023 12:10:19 -0700 (PDT) Message-ID: Date: Fri, 18 Aug 2023 20:10:15 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Subject: Re: [PATCH v11 4/6] iommu/s390: Force ISM devices to use IOMMU_DOMAIN_DMA Content-Language: en-GB To: Niklas Schnelle , Joerg Roedel , Matthew Rosato , Will Deacon , Wenjia Zhang , Jason Gunthorpe Cc: Gerd Bayer , Julian Ruess , Pierre Morel , Alexandra Winter , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Suravee Suthikulpanit , Hector Martin , Sven Peter , Alyssa Rosenzweig , David Woodhouse , Lu Baolu , Andy Gross , Bjorn Andersson , Konrad Dybcio , Yong Wu , Matthias Brugger , AngeloGioacchino Del Regno , Gerald Schaefer , Orson Zhai , Baolin Wang , Chunyan Zhang , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Thierry Reding , Krishna Reddy , Jonathan Hunter , Jonathan Corbet , linux-s390@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, linux-doc@vger.kernel.org References: <20230717-dma_iommu-v11-0-a7a0b83c355c@linux.ibm.com> <20230717-dma_iommu-v11-4-a7a0b83c355c@linux.ibm.com> From: Robin Murphy In-Reply-To: <20230717-dma_iommu-v11-4-a7a0b83c355c@linux.ibm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE 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 2023-07-17 12:00, Niklas Schnelle wrote: > ISM devices are virtual PCI devices used for cross-LPAR communication. > Unlike real PCI devices ISM devices do not use the hardware IOMMU but > inspects IOMMU translation tables directly on IOTLB flush (s390 RPCIT > instruction). > > While ISM devices keep their DMA allocations static and only very rarely > DMA unmap at all, For each IOTLB flush that occurs after unmap the ISM > devices will inspect the area of the IOVA space indicated by the flush. > This means that for the global IOTLB flushes used by the flush queue > mechanism the entire IOVA space would be inspected. In principle this > would be fine, albeit potentially unnecessarily slow, it turns out > however that ISM devices are sensitive to seeing IOVA addresses that are > currently in use in the IOVA range being flushed. Seeing such in-use > IOVA addresses will cause the ISM device to enter an error state and > become unusable. > > Fix this by forcing IOMMU_DOMAIN_DMA to be used for ISM devices. This > makes sure IOTLB flushes only cover IOVAs that have been unmapped and > also restricts the range of the IOTLB flush potentially reducing latency > spikes. Would it not be simpler to return false for IOMMU_CAP_DEFERRED_FLUSH for these devices? Cheers, Robin. > Signed-off-by: Niklas Schnelle > --- > drivers/iommu/s390-iommu.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c > index f6d6c60e5634..020cc538e4c4 100644 > --- a/drivers/iommu/s390-iommu.c > +++ b/drivers/iommu/s390-iommu.c > @@ -710,6 +710,15 @@ struct zpci_iommu_ctrs *zpci_get_iommu_ctrs(struct zpci_dev *zdev) > return &zdev->s390_domain->ctrs; > } > > +static int s390_iommu_def_domain_type(struct device *dev) > +{ > + struct zpci_dev *zdev = to_zpci_dev(dev); > + > + if (zdev->pft == PCI_FUNC_TYPE_ISM) > + return IOMMU_DOMAIN_DMA; > + return 0; > +} > + > int zpci_init_iommu(struct zpci_dev *zdev) > { > u64 aperture_size; > @@ -789,6 +798,7 @@ static const struct iommu_ops s390_iommu_ops = { > .probe_device = s390_iommu_probe_device, > .probe_finalize = s390_iommu_probe_finalize, > .release_device = s390_iommu_release_device, > + .def_domain_type = s390_iommu_def_domain_type, > .device_group = generic_device_group, > .pgsize_bitmap = SZ_4K, > .get_resv_regions = s390_iommu_get_resv_regions, >