Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2900336rdb; Fri, 22 Sep 2023 11:22:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGSGF448WvIQNNPcxTr1o5OZjYBrfZA3W0gw8q5JKLJmBEtrHyDFi/x1ZpTIaNwSq2gQUH/ X-Received: by 2002:a05:6a00:23c6:b0:68f:b3ed:7d4d with SMTP id g6-20020a056a0023c600b0068fb3ed7d4dmr232409pfc.15.1695406975220; Fri, 22 Sep 2023 11:22:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695406975; cv=none; d=google.com; s=arc-20160816; b=KaAxDUkukkeyijNWL/mGoYtIrnI68Dfgc9qYDtymDcfarmcL0u/XY/Nk8z6mvVePK7 ZwzRHFQ5nTQ01Dpk0Auql6zIKY1cCDF65LBv50o/ENwCKOlc4JJmEQyOu87nI5kh3V1M 9YN8WfCyDbHSu+z+uh3c+qHKJ9KwbEiY5Ij17dNvfuSL4JkWnS7IPHLVoIjAu2xMQKfA I1XcZaXk1aB0jCB6CUqpwMbFSzyJhQ7hEO03Ft6LihqAvYq5HCw+JnM0gB/KOgSStWxC n+FtyjTwGOEOMFf9piKDBCG3f63DIgp474QPpoumsI1SS7gfJsC2xG/1jgxk5GSRJsQJ 5MMg== 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=+kSntrkok+oi2gqszm6k+8MbAVOEXJ/HX5Y2Vr4QFWU=; fh=6CnY0PDFv7SwsuLWtHYOQERiNjiEarqHOImF33gov24=; b=JajW/P3fbgcURZFAEk4YG2xyMJ7A3diZliIxz3rtKCQioLik4BGvfOZK3qdvFJfLn7 YHV8jx0/eUav+IVPGxegzZSOJxNt3Fk2pJotkjHRMvmF2LfKfwnvw3ZzgNMCZa6pg6Lj HRJzldFvu0ISIelTkRKaveq3hI00D06KvRRNdp3D1pzoXT1fn5QK3H2EQRHq6dlPAmCw H8skfj7Fo7K7CTqQkJUVUs7CPTqM60vClxHfJFdbrquMMjOlBoGSND9f7yMlejSK+tFV XmXZuY2bA0XvORnDptX3YSn3ib8e09b89jjkI25CJxA7ZzSZvov5LuI2HuIFoY9uTkHo 5TBA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id eg6-20020a056a00800600b00690d25b1988si4253395pfb.30.2023.09.22.11.22.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 11:22:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id D2D9584E9885; Fri, 22 Sep 2023 11:07:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230468AbjIVSH4 (ORCPT + 99 others); Fri, 22 Sep 2023 14:07:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230419AbjIVSHy (ORCPT ); Fri, 22 Sep 2023 14:07:54 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 13554102 for ; Fri, 22 Sep 2023 11:07:47 -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 876C7C15; Fri, 22 Sep 2023 11:08:23 -0700 (PDT) Received: from [10.1.196.40] (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 50FC03F59C; Fri, 22 Sep 2023 11:07:45 -0700 (PDT) Message-ID: <123c53c3-d259-9c20-9aa6-0c216d7eb3c0@arm.com> Date: Fri, 22 Sep 2023 19:07:40 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:102.0) Gecko/20100101 Thunderbird/102.15.0 Subject: Re: [PATCH v2 1/2] iommu/virtio: Make use of ops->iotlb_sync_map Content-Language: en-GB To: Jason Gunthorpe Cc: Jean-Philippe Brucker , Niklas Schnelle , Joerg Roedel , Will Deacon , virtualization@lists.linux-foundation.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org References: <20230918-viommu-sync-map-v2-0-f33767f6cf7a@linux.ibm.com> <20230918-viommu-sync-map-v2-1-f33767f6cf7a@linux.ibm.com> <20230919081519.GA3860249@myrica> <20230919144649.GT13795@ziepe.ca> <20230922075719.GB1361815@myrica> <20230922124130.GD13795@ziepe.ca> <900b644e-6e21-1038-2252-3dc86cbf0a32@arm.com> <20230922162714.GH13795@ziepe.ca> From: Robin Murphy In-Reply-To: <20230922162714.GH13795@ziepe.ca> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Fri, 22 Sep 2023 11:07:57 -0700 (PDT) On 22/09/2023 5:27 pm, Jason Gunthorpe wrote: > On Fri, Sep 22, 2023 at 02:13:18PM +0100, Robin Murphy wrote: >> On 22/09/2023 1:41 pm, Jason Gunthorpe wrote: >>> On Fri, Sep 22, 2023 at 08:57:19AM +0100, Jean-Philippe Brucker wrote: >>>>>> They're not strictly equivalent: this check works around a temporary issue >>>>>> with the IOMMU core, which calls map/unmap before the domain is >>>>>> finalized. >>>>> >>>>> Where? The above points to iommu_create_device_direct_mappings() but >>>>> it doesn't because the pgsize_bitmap == 0: >>>> >>>> __iommu_domain_alloc() sets pgsize_bitmap in this case: >>>> >>>> /* >>>> * If not already set, assume all sizes by default; the driver >>>> * may override this later >>>> */ >>>> if (!domain->pgsize_bitmap) >>>> domain->pgsize_bitmap = bus->iommu_ops->pgsize_bitmap; >>> >>> Dirver's shouldn't do that. >>> >>> The core code was fixed to try again with mapping reserved regions to >>> support these kinds of drivers. >> >> This is still the "normal" code path, really; I think it's only AMD that >> started initialising the domain bitmap "early" and warranted making it >> conditional. > > My main point was that iommu_create_device_direct_mappings() should > fail for unfinalized domains, setting pgsize_bitmap to allow it to > succeed is not a nice hack, and not necessary now. Sure, but it's the whole "unfinalised domains" and rewriting domain->pgsize_bitmap after attach thing that is itself the massive hack. AMD doesn't do that, and doesn't need to; it knows the appropriate format at allocation time and can quite happily return a fully working domain which allows map before attach, but the old ops->pgsize_bitmap mechanism fundamentally doesn't work for multiple formats with different page sizes. The only thing I'd accuse it of doing wrong is the weird half-and-half thing of having one format as a default via one mechanism, and the other as an override through the other, rather than setting both explicitly. virtio isn't setting ops->pgsize_bitmap for the sake of direct mappings either; it sets it once it's discovered any instance, since apparently it's assuming that all instances must support identical page sizes, and thus once it's seen one it can work "normally" per the core code's assumptions. It's also I think the only driver which has a "finalise" bodge but *can* still properly support map-before-attach, by virtue of having to replay mappings to every new endpoint anyway. > What do you think about something like this to replace > iommu_create_device_direct_mappings(), that does enforce things > properly? I fail to see how that would make any practical difference. Either the mappings can be correctly set up in a pagetable *before* the relevant device is attached to that pagetable, or they can't (if the driver doesn't have enough information to be able to do so) and we just have to really hope nothing blows up in the race window between attaching the device to an empty pagetable and having a second try at iommu_create_device_direct_mappings(). That's a driver-level issue and has nothing to do with pgsize_bitmap either way. Thanks, Robin.