Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2777588rdb; Fri, 22 Sep 2023 08:08:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFcY5GZf/euoluB73EhJltrfzXgFB+ucS1V6+l0HaCDXCDKGxFW2JHvbO222tzBH/8Dnlge X-Received: by 2002:a17:902:ec8a:b0:1c4:660d:3d19 with SMTP id x10-20020a170902ec8a00b001c4660d3d19mr10073713plg.26.1695395332456; Fri, 22 Sep 2023 08:08:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695395332; cv=none; d=google.com; s=arc-20160816; b=YKbkQ1zyXgUgVbDPLlrJalqqHBBYYqWSHqsvK3xKZFiQMmfhIJ47xkVkaBhjZ8N7/h u2/fTs4ZqczEYyxF6h8fBbSUg7PzTyXb6MbyIZq3ql+CtC0QrnVtHmxBFqJ78ufxiY/k SpIrtInwB3eZBR4CTSxO1qCfxbvqf1mlcRyBzFShFOJHeLOdN9z96Tmm1+e7ykhv4TiR 7GOi5w7uP8D2YtfFsHJdIAh9AZ25XQNbRFEi6NczxpY5G2w3ZR7eLDkcn6DTL9FIhTPL CyFqznUC1wWfR6VKRblfPA2etSFR2UiiUSmWDrRyFKHUxBR8A2m3NO19jvsnUCdqAxjQ Nt6A== 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=ZnFqnWCwcyqa0uxptZjUfiZurm7gKfTYACFMprkcSZc=; fh=GhyWDxOgQ7AIVkBH46MZBM5yaXEjx9AB27w/oyIbv6U=; b=pqEqQfpyrELMTk8UJ9X+ng9C51hg7SASKa5MOsu3HBY5neOP42TLBqK3D/6eV5AGZ/ 6Dq+KUZKBeQjp+9G08XapoW3F086jDYmpdByYvc8NbY0toPvS7UYi8LqlPBmUDXmcRGM 31y4pzZaJl7EsnvRXTyKcUccItX/CSnQMstWBHhA+zjGEdfdX46VPa+dfaGNfh6jyQEx tLMLsT/forDH0HHJ3kJe0ORvIMlTrNYlnNBNgtf+ue1h81gJkdXSie54TDWuEECAXxSx VRWAdpvExcECz8ipj8htTNdQfprQ6bn22Qvy0HlBWQ+3XwXk5aN6H1INh1LpIhOwMCfI S06w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=o9Nku1Hj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id u17-20020a170902e81100b001c3b5a1336esi4230582plg.329.2023.09.22.08.08.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 08:08:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=o9Nku1Hj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 61C2A81F88E8; Fri, 22 Sep 2023 00:57:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231925AbjIVH5X (ORCPT + 99 others); Fri, 22 Sep 2023 03:57:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229647AbjIVH5V (ORCPT ); Fri, 22 Sep 2023 03:57:21 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D82AFB for ; Fri, 22 Sep 2023 00:57:15 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-32001d16a14so1730138f8f.1 for ; Fri, 22 Sep 2023 00:57:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695369434; x=1695974234; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=ZnFqnWCwcyqa0uxptZjUfiZurm7gKfTYACFMprkcSZc=; b=o9Nku1Hj3ZkxrqqVc61TGuxGpxd/tMNhmAQYC5jmIZ5TKMv8jSXWDijWW7OAAauhIL MgYHnKrDtYQxr6FahrN65ex6uwMdeyz1xdoyjmdAGWmpVGsueawAwTrYz7/yHSOIZ/H8 3zZgEItO9gu8r99Vavlv8xlcz0SSEGIt/g01B/ZtaBf0jKg39RqTE+P6Z/9Ct2wen8Fw vj3ceau344xlImLtnLL1bk/yB5+DzUmBexz02R5Yr/scv0FItvwXFc/w+NPSuma84ZxY gvZoPvnXun092jkFbL3Sh6Vs4BIUkKzoyv2paZDa8L8DlWWtzsXMQqElPYujaEwAqiy/ 1k+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695369434; x=1695974234; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ZnFqnWCwcyqa0uxptZjUfiZurm7gKfTYACFMprkcSZc=; b=K2WM3PnMUe7MRHeZK61JMiteZ17IFYr1w3+l6aGkuLA+p3N+OosmDmq3HIv+cRDZvC t2G2lG5xkvhe2/vOpadf4JcPG9Ap5ZF0MujLGKkTjLKwvu+lxu/dtk+B+rdsiN59G9aN vCV+iggfs1sw3f+F2ysVw4/j2ymGtnvB6LMwjzTA39j1FPCKPQV3TsKtM30LJbOkEhfV zWWB7C6bp5nwsyznbgPTo8KmdeH0b/YU+SB9BxSv23PKGJicSo7R5Hk8rCr2t3+1g1NT MFJoPCqLLHomdBamWyNiLVvwhI/9WtMfF8eRnCViYrOOk8rdPyzDo4nBHI7rSNTCljSF BmJQ== X-Gm-Message-State: AOJu0YznbdQJHn0GOBWVARbca/7KXAC4xwyIRoFXBhMfKAMmnRp4eLQf a/y1WrkL2u9FOUXeqqJLrA6enQ== X-Received: by 2002:adf:f008:0:b0:31f:fab1:c3c3 with SMTP id j8-20020adff008000000b0031ffab1c3c3mr7029007wro.35.1695369433661; Fri, 22 Sep 2023 00:57:13 -0700 (PDT) Received: from myrica ([2a02:c7c:7290:b00:fd32:2b31:6755:400c]) by smtp.gmail.com with ESMTPSA id y12-20020adffa4c000000b0031f5f0d0be0sm3746610wrr.31.2023.09.22.00.57.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 00:57:13 -0700 (PDT) Date: Fri, 22 Sep 2023 08:57:19 +0100 From: Jean-Philippe Brucker To: Jason Gunthorpe Cc: Robin Murphy , Niklas Schnelle , Joerg Roedel , Will Deacon , virtualization@lists.linux-foundation.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/2] iommu/virtio: Make use of ops->iotlb_sync_map Message-ID: <20230922075719.GB1361815@myrica> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230919144649.GT13795@ziepe.ca> X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email 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 (agentk.vger.email [0.0.0.0]); Fri, 22 Sep 2023 00:57:25 -0700 (PDT) On Tue, Sep 19, 2023 at 11:46:49AM -0300, Jason Gunthorpe wrote: > On Tue, Sep 19, 2023 at 09:15:19AM +0100, Jean-Philippe Brucker wrote: > > On Mon, Sep 18, 2023 at 05:37:47PM +0100, Robin Murphy wrote: > > > > diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c > > > > index 17dcd826f5c2..3649586f0e5c 100644 > > > > --- a/drivers/iommu/virtio-iommu.c > > > > +++ b/drivers/iommu/virtio-iommu.c > > > > @@ -189,6 +189,12 @@ static int viommu_sync_req(struct viommu_dev *viommu) > > > > int ret; > > > > unsigned long flags; > > > > + /* > > > > + * .iotlb_sync_map and .flush_iotlb_all may be called before the viommu > > > > + * is initialized e.g. via iommu_create_device_direct_mappings() > > > > + */ > > > > + if (!viommu) > > > > + return 0; > > > > > > Minor nit: I'd be inclined to make that check explicitly in the places where > > > it definitely is expected, rather than allowing *any* sync to silently do > > > nothing if called incorrectly. Plus then they could use > > > vdomain->nr_endpoints for consistency with the equivalent checks elsewhere > > > (it did take me a moment to figure out how we could get to .iotlb_sync_map > > > with a NULL viommu without viommu_map_pages() blowing up first...) > > This makes more sense to me > > Ultimately this driver should reach a point where every iommu_domain > always has a non-null domain->viommu because it will be set during > alloc. > > But it can still have nr_endpoints == 0, doesn't it make sense to > avoid sync in this case? > > (btw this driver is missing locking around vdomain->nr_endpoints) Yes, that's on my list > > > 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; Thanks, Jean