Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1695873rwb; Wed, 5 Oct 2022 03:31:40 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7HIT0RKdwciID5TYiaczvOTALS+sZK1Pyq0f4E3kRdVdhbqkiUvElUvuqFrKVqiObKKtyw X-Received: by 2002:a17:907:72c1:b0:783:34ce:87b9 with SMTP id du1-20020a17090772c100b0078334ce87b9mr23181919ejc.115.1664965900503; Wed, 05 Oct 2022 03:31:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664965900; cv=none; d=google.com; s=arc-20160816; b=xMX01UMuxhUa2PFEDv2ztTFdQLqbC82YGV6FEmidgxHRyIGRQpnogl2uIXGxPmHVqu C0SRB6biuBIAdCrycNsMgSCQageWT7wQDQ02mnoClL6qDcps+M6kKzJXjhiAD7A4QfUr Sw2Kf3jNDawVcWI8lFL/0BODMhMr8gMYXfJVz65/J0d/CkydfCRiyxEBeMcZYuu8HbdD 4CS+Uh1RZSxcnbam4nEd/kP7Sk+ElCweYGMEIohW8tVeJMbVIAfr3kHtX25WVn8l/g/p AVlFojvGRLqaUXnBLnfi9gjNIlp6bUWbzJFLTfc2Cqcf2ZHjLU1rWI3Qc502vyEgvsTr 6FLw== 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=bChk26pV0mEMi00kvzZ5CKT3ZkSosJkErB+pygd7+ms=; b=OKaN9GqJhrHj2c88/soGEvYlS//cdagRqiLZIMks2xEbJNRa3Bw0RXwKXhj2nTwxwb Wch74LBsqXK8C59/ia6UrHQgXR9iMEZZnvH5MoojekYURLMb1SPjYGhEn2EzgulBrGlg MAXZeILUF5X3qa9k5c/IrCk4USngxdRencbAfCC0y9Tp/1sXIrIT1uhf0zRaCymNgRPo wELz2dcIVCuwWHzUC9DFebJPHlvsHlo2YQEBycFYn87Zr8rHjrtUoB6i+Tb2mLt1vswM /m6sObB3IJQAMzen9p+ZYIRB3Iy+WnEG6JsJFHsHoNdPMXW422FW32zXTwYxU0UGi46P qmLA== 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:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bk7-20020a170906b0c700b0077f7781816fsi12342570ejb.655.2022.10.05.03.31.12; Wed, 05 Oct 2022 03:31:40 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229790AbiJEJyC (ORCPT + 99 others); Wed, 5 Oct 2022 05:54:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229534AbiJEJx7 (ORCPT ); Wed, 5 Oct 2022 05:53:59 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9D70D33A3C; Wed, 5 Oct 2022 02:53:58 -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 2D764113E; Wed, 5 Oct 2022 02:54:05 -0700 (PDT) Received: from [10.57.65.170] (unknown [10.57.65.170]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 79CBD3F67D; Wed, 5 Oct 2022 02:53:55 -0700 (PDT) Message-ID: Date: Wed, 5 Oct 2022 10:53:50 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:102.0) Gecko/20100101 Thunderbird/102.3.1 Subject: Re: [PATCH v4 5/5] iommu/s390: Fix incorrect pgsize_bitmap Content-Language: en-GB To: Niklas Schnelle , Matthew Rosato , Pierre Morel , iommu@lists.linux.dev Cc: linux-s390@vger.kernel.org, borntraeger@linux.ibm.com, hca@linux.ibm.com, gor@linux.ibm.com, gerald.schaefer@linux.ibm.com, agordeev@linux.ibm.com, svens@linux.ibm.com, joro@8bytes.org, will@kernel.org, jgg@nvidia.com, linux-kernel@vger.kernel.org References: <20221004120706.2957492-1-schnelle@linux.ibm.com> <20221004120706.2957492-6-schnelle@linux.ibm.com> <0da03411190c004e85cc856965b0aca901fd78fb.camel@linux.ibm.com> From: Robin Murphy In-Reply-To: <0da03411190c004e85cc856965b0aca901fd78fb.camel@linux.ibm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_LOW,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 2022-10-04 17:13, Niklas Schnelle wrote: > On Tue, 2022-10-04 at 16:31 +0100, Robin Murphy wrote: >> On 2022-10-04 16:12, Matthew Rosato wrote: >>> On 10/4/22 11:02 AM, Robin Murphy wrote: >>>> On 2022-10-04 13:07, Niklas Schnelle wrote: >>>>> The .pgsize_bitmap property of struct iommu_ops is not a page mask but >>>>> rather has a bit set for each size of pages the IOMMU supports. As the >>>>> comment correctly pointed out at this moment the code only support 4K >>>>> pages so simply use SZ_4K here. >>>> >>>> Unless it's already been done somewhere else, you'll want to switch over to the {map,unmap}_pages() interfaces as well to avoid taking a hit on efficiency here. The "page mask" thing was an old hack to trick the core API into making fewer map/unmap calls where the driver could map arbitrary numbers of pages at once anyway. The multi-page interfaces now do that more honestly and generally better (since they work for non-power-of-two sizes as well). >>> >>> Thanks for the heads up -- Niklas has some additional series coming soon as described here: >>> >>> https://lore.kernel.org/linux-iommu/a10424adbe01a0fd40372cbd0736d11e517951a1.camel@linux.ibm.com/ >>> >>> So implementing the _pages() interfaces is soon up on the roadmap. But given what you say I wonder if this patch should just wait until the series that implements {map,unmap}_pages(). >> >> Perhaps, although the full change should be trivial enough that there's >> probably just as much argument for doing the whole thing in its own >> right for the sake of this cleanup. The main point is that >> S390_IOMMU_PGSIZES is not incorrect as such, it's just not spelling out >> the deliberate trick that it's achieving - everyone copied it from >> intel-iommu, but since that got converted to the new interfaces the >> original explanation is now gone. The only effect of "fixing" it in >> isolation right now will be to make large VFIO mappings slower. >> >> Robin. > > The patch changing to map_pages()/unmap_pages() is currently part of a > larger series of improvements, some of which are less trivial. So I'm > planning to send those as RFC first. Those include changing the > spin_lock protected list to RCU so the map/unmap can paralellize > better. Another one is atomic updates to the IOMMU tables to do away > with locks in map/unmap. So I think pulling that whole > series into this one isn't ideal. I could pull just the > map_pages()/unmap_pages() change though. Yeah, literally just updating the s390_iommu_{map,unmap} function prototypes and replacing "size" with "pgsize * count" within is all that's needed to clean up this hack properly. That can (and probably should) be completely independent of other improvements deeper down. Thanks, Robin. > >> >>>>> Reviewed-by: Jason Gunthorpe >>>>> Signed-off-by: Niklas Schnelle >>>>> --- >>>>> drivers/iommu/s390-iommu.c | 9 +-------- >>>>> 1 file changed, 1 insertion(+), 8 deletions(-) >>>>> >>>>> diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c >>>>> index 94c444b909bd..6bf23e7830a2 100644 >>>>> --- a/drivers/iommu/s390-iommu.c >>>>> +++ b/drivers/iommu/s390-iommu.c >>>>> @@ -12,13 +12,6 @@ >>>>> #include >>>>> #include >>>>> -/* >>>>> - * Physically contiguous memory regions can be mapped with 4 KiB alignment, >>>>> - * we allow all page sizes that are an order of 4KiB (no special large page >>>>> - * support so far). >>>>> - */ >>>>> -#define S390_IOMMU_PGSIZES (~0xFFFUL) >>>>> - >>>>> static const struct iommu_ops s390_iommu_ops; >>>>> struct s390_domain { >>>>> @@ -350,7 +343,7 @@ static const struct iommu_ops s390_iommu_ops = { >>>>> .probe_device = s390_iommu_probe_device, >>>>> .release_device = s390_iommu_release_device, >>>>> .device_group = generic_device_group, >>>>> - .pgsize_bitmap = S390_IOMMU_PGSIZES, >>>>> + .pgsize_bitmap = SZ_4K, >>>>> .get_resv_regions = s390_iommu_get_resv_regions, >>>>> .default_domain_ops = &(const struct iommu_domain_ops) { >>>>> .attach_dev = s390_iommu_attach_device, > >