Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp890869imw; Fri, 8 Jul 2022 13:49:34 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tsKbvAju7MfvJhCdeK4wXDuwWhN2ICDyJ/3Usc+zZWg/2QtMtFTcRkDzZ0Cz7kK3+kIn4G X-Received: by 2002:a63:86c8:0:b0:415:366c:f287 with SMTP id x191-20020a6386c8000000b00415366cf287mr4826778pgd.309.1657313374012; Fri, 08 Jul 2022 13:49:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657313374; cv=none; d=google.com; s=arc-20160816; b=Vmp5Her2npOZzQyhGtSGhhPZpugvIwYtm/rpyCwOqu07CzXPO8Tc4qb3RRx6fzsT3a TVidpg9Nc7SRiYm4EnIx9uXBfvuJ+VuWvEZWhKr1daAC409LVOsJz0oXMmNOmKep5573 rTxxpRF7R0z+po62en1V7tdW8R1L6LLEFGZFh7EICNXvIqRPrV39CMbRyDg9FOs6Osu0 kEx6s85Ft2o3TbkuX8TlrslioOAsLYsujiL0XP2vbI42aAQEWMYZsLPy78QQwItjffOg wwRf1W00LAg4zofH7JZYt4Kdy7xgTZmvOch9rmt8zFjWel3UnVWGPhKAt4hAq5FMz2BK txFA== 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=zyhtVmg+FSGgwCSRjpYPV+Hvje9tIt7c5VxhAH4t9io=; b=YDYxNpCVtjkfvwkNhpDwxRBYLH7QZyNOZxuVgTU7M8tTc4sugIGYGAuE4vZCjp+Llr +y0adFOKj2N1RIuKrs3wFaEd5D6RUpJluEkfVyFphG7S/odZaDNDjiQJ5PFQUBpYz5tH mVmgNTcjHNwQbjtQbFBBWrw6lq/ncrIsHPZ4IFzGYVbPJGrvNTOHm62zxsacXzJxUoNW Lgau7jp8YfslI6cfPXPMIuZF0PpOMj7mReGE9BvvRGM1ZuC+biKfv8L2CNIyV+fUqp2c ai5JzHTLieqjFWBvGeMe98cEf0P5Xz9jTBYtXTUwsUJ4M3Nmb4UcCRON+H3vppg3WCyr hfcA== 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 x3-20020a170902ec8300b0016bea2a24casi14180020plg.3.2022.07.08.13.49.21; Fri, 08 Jul 2022 13:49:34 -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 S240157AbiGHUeQ (ORCPT + 99 others); Fri, 8 Jul 2022 16:34:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240273AbiGHUdu (ORCPT ); Fri, 8 Jul 2022 16:33:50 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3EE0F9CE17 for ; Fri, 8 Jul 2022 13:33:10 -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 EF3601063; Fri, 8 Jul 2022 13:33:09 -0700 (PDT) Received: from [10.57.86.102] (unknown [10.57.86.102]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9CF9F3F70D; Fri, 8 Jul 2022 13:33:08 -0700 (PDT) Message-ID: Date: Fri, 8 Jul 2022 21:32:46 +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 Cc: Sudip Mukherjee , Jude Onyenegecha References: <20220708170811.270589-1-ben.dooks@sifive.com> From: Robin Murphy In-Reply-To: <20220708170811.270589-1-ben.dooks@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-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. > Fix this by making the structure's lock initialised at build time. > > Avoids the following BUG trigger: > > [ 3.046401] BUG: spinlock bad magic on CPU#3, kworker/u8:0/7 > [ 3.046689] lock: io_tlb_default_mem+0x30/0x60, .magic: 00000000, .owner: /-1, .owner_cpu: 0 > [ 3.047217] CPU: 3 PID: 7 Comm: kworker/u8:0 Not tainted 5.17.0-00056-g1e9bac738084-dirty #310 > [ 3.048363] Workqueue: events_unbound deferred_probe_work_func > [ 3.048892] Call Trace: > [ 3.049224] [] dump_backtrace+0x1c/0x24 > [ 3.049576] [] show_stack+0x2c/0x38 > [ 3.049898] [] dump_stack_lvl+0x40/0x58 > [ 3.050216] [] dump_stack+0x14/0x1c > [ 3.050460] [] spin_dump+0x62/0x6e > [ 3.050681] [] do_raw_spin_lock+0xb0/0xd0 > [ 3.050934] [] _raw_spin_lock_irqsave+0x20/0x2c > [ 3.051157] [] swiotlb_tbl_map_single+0xce/0x3da > [ 3.051372] [] swiotlb_map+0x3a/0x15c > [ 3.051668] [] dma_map_page_attrs+0x76/0x162 > [ 3.051975] [] dw_pcie_host_init+0x326/0x3f2 > > Signed-off-by: Ben Dooks > --- > 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..a707a944c39a 100644 > --- a/kernel/dma/swiotlb.c > +++ b/kernel/dma/swiotlb.c > @@ -65,7 +65,7 @@ > static bool swiotlb_force_bounce; > static bool swiotlb_force_disable; > > -struct io_tlb_mem io_tlb_default_mem; > +struct io_tlb_mem io_tlb_default_mem = { .lock = __SPIN_LOCK_UNLOCKED(io_tlb_default_mem.lock) } ; > > phys_addr_t swiotlb_unencrypted_base; >