Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4092825rdb; Thu, 14 Sep 2023 11:28:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHarYTDlvJxylDl3y6L32naube3Sw5aRzvp7NTucMmoKwNSbhmnXN0HjtNoL2HFjznnHEmd X-Received: by 2002:a17:902:b40a:b0:1c3:90c7:b99d with SMTP id x10-20020a170902b40a00b001c390c7b99dmr5306842plr.41.1694716106932; Thu, 14 Sep 2023 11:28:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694716106; cv=none; d=google.com; s=arc-20160816; b=aYaEa7wT4kBQci8ZH63e7ztl/fCaFeAzMgtXuFc5yODG8g1s991bfHjQlv/vDXKmcb 1aEo5Im7qLptEeEDmSArTsiiJpbuZAbbZhQvMBmr6Iueey49qNu9kmIlWVEoyxJ8gh1E vEih8hGIStd+aiudnZEgZq0RdmAuLJQrg2CSW6I2ba6EDaQbPrbttGqVP+/ajLBYWkqL xuISIOGXNKIKUO+WYnTqdJAQj+Nk1D9BEzK8OQbhQ4whshy8RFBK+wPFlOmR7xmpgoCr XtbKfaf2DeD0iK1s7zodoycOyDVAeS6byVlmKk4RWl8E0KFh1zrdvIucBhLdijB09oQE 8ZZw== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=ubu23TXduLS2HM5mqV7QWCGrkXJO/gD+LRJTkB/Qdmc=; fh=f3JYAadzaKkTjM/C/xopH45BiwSGFUeKzNsio6WoDEo=; b=nqFDorprfxvNBpYwOtt12rjQnTzkd5E3JsTYMZRXKVGjnpnF+iXEbnnrvUe2lyUQq3 sXidIJkr/iZOe2FcMOOQCfwUu6ZFURPM8xiDizEm3hwoBllrTjCPy9aBFz4N0k7UBGFv ETQ8Uc0Q/SdipQCYB3kCAqDrxhgL5z4ixfYQ0gAV5VGjuf5D4YsfhhOXOruTLJTmiZ2F OWdyP59z4XQ1rSJuikrs4hxzs1VdXC1X7ig1/bBN+8nggCW+fzg4/a470UgkVXJ9FnvZ 43QLHDFPGmbaDywhnmNxb7x+tJqYQ8A3xBtGvqBQ4+MUGINOR3l6wkUvmD/Swpj6mVn+ mAFA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id q15-20020a170902a3cf00b001c3fa95ca18si1476671plb.333.2023.09.14.11.28.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 11:28:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id D5838832BE5A; Thu, 14 Sep 2023 11:28:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240824AbjINS2L (ORCPT + 99 others); Thu, 14 Sep 2023 14:28:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239368AbjINS2K (ORCPT ); Thu, 14 Sep 2023 14:28:10 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 497FE1FE0 for ; Thu, 14 Sep 2023 11:28:06 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55E7CC433C7; Thu, 14 Sep 2023 18:28:04 +0000 (UTC) Date: Thu, 14 Sep 2023 19:28:01 +0100 From: Catalin Marinas To: Petr =?utf-8?B?VGVzYcWZw61r?= Cc: Christoph Hellwig , Marek Szyprowski , Robin Murphy , "open list:DMA MAPPING HELPERS" , open list , Roberto Sassu , Jonathan Corbet Subject: Re: [PATCH] swiotlb: fix the check whether a device has used software IO TLB Message-ID: References: <20230913114016.17752-1-petr@tesarici.cz> <20230913121403.GB4544@lst.de> <20230913142656.29e135d6@meshulam.tesarici.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230913142656.29e135d6@meshulam.tesarici.cz> 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 (groat.vger.email [0.0.0.0]); Thu, 14 Sep 2023 11:28:23 -0700 (PDT) X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email On Wed, Sep 13, 2023 at 02:26:56PM +0200, Petr Tesařík wrote: > On Wed, 13 Sep 2023 14:14:03 +0200 > Christoph Hellwig wrote: > > Thanks, I've applied this to get it into linux-next ASAP. I'd love > > to have reviews before sending it on to Linus, though. > > Fully understood, given my past record. ;-) > > @Catalin Marinas: I have added you to the list of recipient, because you > spotted some issues with memory barriers in one of my previous attempts. I seem to have forgotten everything about that thread (trying to remember what I meant in https://lore.kernel.org/all/ZGJdtmP13pv06xDH@arm.com/ ;)). What do the smp_wmb() barriers in swiotlb_find_slots() and swiotlb_dyn_alloc() order? The latter is even more unclear as it's at the end of the function and the "pairing" comment doesn't help. I found the "pairing" description in memory-barriers.txt not helping much and lots of code comments end up stating that some barrier is paired with another as if it is some magic synchronisation event. In general a wmb() barrier ends up paired with an rmb() one (or some other form of dependency, acquire semantics etc.) but they should be described in isolation first - what memory accesses on a CPU before and after the *mb() need ordering - and then how this pairing solves the accesses observability across multiple CPUs. The comments should also describe things like "ensure payload is visible before flag update" rather than "the wmb here pairs with the rmb over there". Presumably in swiotlb_find_slots(), the smp_wmb() needs to ensure the write to dev->dma_uses_io_tlb is visible before the *retpool write? For swiotlb_dyn_alloc(), I'm completely lost on what the smp_wmb() orders. You really need at least two memory accesses on a CPU for the barrier to make sense. -- Catalin