Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1014275lqm; Thu, 2 May 2024 02:38:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXjmU1xE7HVJkA0880ZrOICkk0RF8j7+xg9jWSqsNIjkWbgwH9Hp+JPJIBTeZ3rqZAHqyVKHATJJ4Rzu5rqLsuzTAJDHna4exKjZDWX8g== X-Google-Smtp-Source: AGHT+IGEA3VedhTmWHcGDJGVwkTcNLTbB122sLmRN6NOkGHjawYiP/w/dyae6wdedhSDIRBKRgmf X-Received: by 2002:ac2:4e94:0:b0:51c:d1ac:c450 with SMTP id o20-20020ac24e94000000b0051cd1acc450mr4059112lfr.10.1714642720920; Thu, 02 May 2024 02:38:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714642720; cv=pass; d=google.com; s=arc-20160816; b=gS4St0qRLwNSr9hYmErs4zZfK6hE8YsfYcAeq3l5/DBeTSCuBpigRDOyQ+RP+0l3cS zfsI5mZ09LQ1gW1bAR+ULMxebaSPR5uMID+iJKtfTTznBL6fncB362ESWZmra4ObpyJz t6xUQl4ED8KfDcZ++R0QAcI6g5yMNYOIbtdMagqda2L7HjsOgZ5la+bh6wcbe07pCBJO oFPQZN5gifEoQbr8PFE3mrZPb3CEAdDLlGXOo81oeM/wapjU0ZwQwC8cPx3M3kWpt6R5 blHsfqI9PGyyB7A2CiVF/hsj7/yGBn5+cM3XmzFAKcH6eLKATB1jxGo643z7DehTm72D YBqw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=lr7MjWncQAtacaqAC7ZB08mQencwJ/PD7PnZuGUlCwI=; fh=7Wspu6L8/3kHBQS/B2lSkjGFqDkNCXESCpIPTr9yr64=; b=d5UeZFr6pGlOjT6K7iM4ZFETAApV8RXvSF8R9iv9KtSaZufevo2h54wpFKMTXDXfe/ FgpEx8vMH2hgOuTEJs7nRHNjyJYMpjSJ2z2sPj0zcIqt9ycLvpY2Ny5iUb4+yQ+idY0A KNeXUAWBjDom5zLPtOPJMG8c7cqxE4FumEvwKNuJEf6v2x2It4koFwTT8jYlGN5MitUh uGKIyCgw9WCyXB/BHKec91rAU0AYkQpvpzZGo7V92jL9rHZNfNHnWqfAGPmjgRz1iXwa XTVa6ju5lajY3CcJVU1c/dy7QorfVeO7X15NyKtfr3Iw5meCFwBtgLJ2hUMlKIow07FD BnvA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Fyfe5fbM; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-166235-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166235-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id o6-20020a170906358600b00a559bbed405si329030ejb.1039.2024.05.02.02.38.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 02:38:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-166235-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Fyfe5fbM; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-166235-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166235-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id A9A2E1F24652 for ; Thu, 2 May 2024 09:37:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8639955C3A; Thu, 2 May 2024 09:37:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Fyfe5fbM" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A8AEA171AA; Thu, 2 May 2024 09:37:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714642650; cv=none; b=QupKBFNN0BcH1vsOoq92Tkfg5y+xX9eF+BR2KSWqOTyOLQ0fjUYdiR8H9KCJzDpPy+oyeUzCASDa2XSt+x4xqkfhjvs1oxlxswXxXLwJn4dG83RtO9ZdCq2uiVxKME7b6pqRMWtjj68vhiKrpxSSUt2jrVvUL9E+BVVDVti2Wf0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714642650; c=relaxed/simple; bh=3zvGW/fNYeFraVxsq2aoI463CmBHv/uMIxo/dy6oEV8=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=oHMP6dIjeOnFtudOcBhw13Cy2hwXkfkMk96C/ItE22P+J7dWijKtubPkCfq2f+OudlsJoC+Ja9Gfo0KQtUicg6Jg1TXvEBP/FHbV8j+vZ6d3/AzPvnp8rmDszsmGw3qebtZFsqMV4zXCquneWGxpaty8Smkmx8HfdT12aUD+/A4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Fyfe5fbM; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F417C113CC; Thu, 2 May 2024 09:37:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714642650; bh=3zvGW/fNYeFraVxsq2aoI463CmBHv/uMIxo/dy6oEV8=; h=From:To:Cc:Subject:Date:From; b=Fyfe5fbM19OSri66B9sGMaAwpNh+ZUkWsWPakeoxNMlTW8c5X9T/sQj6De+JKfKTH 2+XzU2Erujkt0iMuR3IWRYF7gwRrnzXp/fsNumvzLglSuffCPvoBhgzjUv6z0QucXp 0y1bKrCIObrtHzJz5zIR3kdb8+hUHjSDhYZCORdzbZ8bf8cSgCFaMLV1eMZHle8Da6 9TFANNA9BRYTuU7N/Sx+6UmbIhc2i8+e7kNYjjacp/6QGfIr+g+621kAFR7tqm4JSB q+Bp2WP5NDi2x+5iGNfn8pzQkfX8RBNeAyYoqHOsASy7upUrubdgL9YmUJZhuuJ5Zb lZ0V4h8x9wQzg== From: Will Deacon To: linux-kernel@vger.kernel.org Cc: iommu@lists.linux.dev, Will Deacon , Christoph Hellwig , Marek Szyprowski , Robin Murphy , =?UTF-8?q?Petr=20Tesa=C5=99=C3=ADk?= , Michael Kelley , Nikita Ioffe Subject: [PATCH] swiotlb: Initialise restricted pool list_head when SWIOTLB_DYNAMIC=y Date: Thu, 2 May 2024 10:37:23 +0100 Message-Id: <20240502093723.16820-1-will@kernel.org> X-Mailer: git-send-email 2.20.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using restricted DMA pools (CONFIG_DMA_RESTRICTED_POOL=y) in conjunction with dynamic SWIOTLB (CONFIG_SWIOTLB_DYNAMIC=y) leads to the following crash when initialising the restricted pools at boot-time: | Unable to handle kernel NULL pointer dereference at virtual address 0000000000000008 | Internal error: Oops: 0000000096000005 [#1] PREEMPT SMP | pc : rmem_swiotlb_device_init+0xfc/0x1ec | lr : rmem_swiotlb_device_init+0xf0/0x1ec | Call trace: | rmem_swiotlb_device_init+0xfc/0x1ec | of_reserved_mem_device_init_by_idx+0x18c/0x238 | of_dma_configure_id+0x31c/0x33c | platform_dma_configure+0x34/0x80 faddr2line reveals that the crash is in the list validation code: include/linux/list.h:83 include/linux/rculist.h:79 include/linux/rculist.h:106 kernel/dma/swiotlb.c:306 kernel/dma/swiotlb.c:1695 because add_mem_pool() is trying to list_add_rcu() to a NULL 'mem->pools'. Fix the crash by initialising the 'mem->pools' list_head in rmem_swiotlb_device_init() before calling add_mem_pool(). Cc: Christoph Hellwig Cc: Marek Szyprowski Cc: Robin Murphy Cc: Petr Tesařík Cc: Michael Kelley Reported-by: Nikita Ioffe Tested-by: Nikita Ioffe Fixes: 1aaa736815eb ("swiotlb: allocate a new memory pool when existing pools are full") Signed-off-by: Will Deacon --- kernel/dma/swiotlb.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 86fe172b5958..87dd3301dde3 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -1773,6 +1773,7 @@ static int rmem_swiotlb_device_init(struct reserved_mem *rmem, mem->for_alloc = true; #ifdef CONFIG_SWIOTLB_DYNAMIC spin_lock_init(&mem->lock); + INIT_LIST_HEAD_RCU(&mem->pools); #endif add_mem_pool(mem, pool); -- 2.45.0.rc1.225.g2a3ae87e7f-goog