Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3212386imw; Mon, 11 Jul 2022 04:25:25 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vVGkYrLMvJvUnevYIZUHYzrPM1skmlwuyqffhMKoPzhQQiq73krFvFlNCrvBrwaVU7Qv7v X-Received: by 2002:a17:902:e80a:b0:16c:3340:aba5 with SMTP id u10-20020a170902e80a00b0016c3340aba5mr11967270plg.102.1657538724848; Mon, 11 Jul 2022 04:25:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657538724; cv=none; d=google.com; s=arc-20160816; b=sDKHnSSf32P31wDUJoKLGhYTJYyR0B6HntMai9+aHujYjeNrYM0p6wRapPOBGVyt+X DOIJWr5w6L0S6QtoziDNrAHrg68MImPHhHhv6KOWfph0jRgWePdSBsRTxPAkGrQ8a+/k maTwP8D0jhMQyHawWzUuD8qbRS+Fp6AjYSlolkOfqIFAadZdFswHqK0Uc+u0M4XvbjKn IcpECdz8DJ2+3bBMf5DFNL8rEqlSd47cgxwkcOAZj1QZzoIASdnbNE1hl8bPpkvOqUD1 7N6tw1xDyE91XJCXXZ+096HKXUWzjVnAXEKciLd6egRbAADv3/OWmC5qP7MjoZU3JMJZ rORA== 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=VcXwGD3u6QEQlbVgucuqzByNrTs7tzHam3khKN+gBg0=; b=LxBxE2cGLikYIUh6Yb8eRwISIzGxQ25nOiNnx11/GO8x5Khp3/g2O5OZPwmyR0lx6s vKGUiktR6uDHvOTcPiMd04CRfbVjDnRMUylXWl1wCmRX9xjPvXRFcnpWn3yxARhMVgRE Es4AcCRWixH1Yj0RhoAs5Pxla/ij9yjqQEUsz4ZxCx2xRfPG8cHq9pLvTgGhnzdZV/q3 2H1lnpAeHSIwTCAVqYuapZslFD2SWYySyXS7bBNyQB+GKPrf8gD+NHgDYLOH1cY79nEL aCQDe+nbSuFFdUJQm85vN3sv2ghYuQtGDp5rq/RPLXGk8+vrkS3pS+giRaZONoz3Alhy ottA== 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 r71-20020a632b4a000000b00415d5906454si9547338pgr.412.2022.07.11.04.25.12; Mon, 11 Jul 2022 04:25:24 -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 S230056AbiGKLCj (ORCPT + 99 others); Mon, 11 Jul 2022 07:02:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbiGKLCY (ORCPT ); Mon, 11 Jul 2022 07:02:24 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 534CB3DF00 for ; Mon, 11 Jul 2022 03:07:23 -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 7CCC316A3; Mon, 11 Jul 2022 03:07:23 -0700 (PDT) Received: from [10.57.85.194] (unknown [10.57.85.194]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D04B13F73D; Mon, 11 Jul 2022 03:07:21 -0700 (PDT) Message-ID: Date: Mon, 11 Jul 2022 11:07:17 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH] swiotlb: ensure io_tlb_default_mem spinlock always initialised Content-Language: en-GB To: Ben Dooks , linux-kernel@vger.kernel.org, iommu@lists.linux.dev, iommu@lists.linux-foundation.org, Christoph Hellwig Cc: Sudip Mukherjee , Jude Onyenegecha , Marek Szyprowski References: <20220708170811.270589-1-ben.dooks@sifive.com> <683344bd-dc9b-0bb5-9377-b3e9ab410a74@sifive.com> From: Robin Murphy In-Reply-To: <683344bd-dc9b-0bb5-9377-b3e9ab410a74@sifive.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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-07-11 08:26, Ben Dooks wrote: > On 08/07/2022 21:32, Robin Murphy wrote: >> On 2022-07-08 18:08, Ben Dooks wrote: >>> If the io_tlb_default_mem is used by a device that then gets used >>> by the swiotlb code, the spinlock warning is triggered causing a >>> lot of stack-trace. >> >> Hang on, how have we got as far as trying to allocate out of an >> uninitialised SWIOTLB at all? That seems like either something's gone >> more fundamentally wrong or we're missing a proper check somewhere. I >> don't think papering over it like this is right. >> >> Thanks, >> Robin > We have a system where we have no DMA capable memory in the 32bit > window, which means even if we initialise swiotlb we don't have > any dma capable memory. The code says go use an IOMMU but we don't > have one of those either (and all peripherals are capable of DMA > from any of the memory, so there shouldn't be the need for one) > > Is there any other way of fixing this DMA allocation issue? If none of your peripherals should need SWIOTLB, then the fact that you're ending up in swiotlb_map() at all is a clear sign that something's wrong. Most likely someone's forgotten to set their DMA masks correctly. However, by inspection it seems we do have a bug here as well, for which the correct fix should be as below. The fireworks you're *supposed* to get in that situation are considerably louder and more obvious than a DEBUG_SPINLOCK complaint ;) Thanks, Robin. ----->8----- Subject: [PATCH] swiotlb: Fail map correctly with failed io_tlb_default_mem In the failure case of trying to use a buffer which we'd previously failed to allocate, the "!mem" condition is no longer sufficient since io_tlb_default_mem became static and assigned by default. Update the condition to work as intended per the rest of that conversion. Fixes: 463e862ac63e ("swiotlb: Convert io_default_tlb_mem to static allocation") Signed-off-by: Robin Murphy --- kernel/dma/swiotlb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index cb50f8d38360..5830dce6081b 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -580,7 +580,7 @@ phys_addr_t swiotlb_tbl_map_single(struct device *dev, phys_addr_t orig_addr, int index; phys_addr_t tlb_addr; - if (!mem) + if (!mem || !mem->nslabs) panic("Can not allocate SWIOTLB buffer earlier and can't now provide you with the DMA bounce buffer"); if (cc_platform_has(CC_ATTR_MEM_ENCRYPT)) -- 2.36.1.dirty