From patchwork Thu Nov 12 22:05:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 324251 Delivered-To: patches@linaro.org Received: by 2002:a05:6e02:5ce:0:0:0:0 with SMTP id l14csp706004ils; Thu, 12 Nov 2020 14:05:24 -0800 (PST) X-Received: by 2002:a17:90a:ca0b:: with SMTP id x11mr1290480pjt.155.1605218724312; Thu, 12 Nov 2020 14:05:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605218724; cv=none; d=google.com; s=arc-20160816; b=W2kjYkzQQ2K1W3LJt8XAHNOTIJrEyBYSYJkgON6QfTXIuXUxrvuRi4jWL9vnPKJZu1 SC+ghfr5aytB49xfXPOsXQdWzyjImAvi42RHc+AtMikQDiHuM1egVcFi2DjbYiYJf+gV 4nlAK9V86eidlRfo/Vz79N07j31ezquzdxDklOzeuIru4sE6Pe3ORXXb74FzecWscZFt Mf7kkYIGDNMJu/gSaFBAHxzF+8VAVHqMkOJG+hkFllKmcEX/EiYBCHKIxlrZemuiiKrj wnHj0LHAW0pp2nSdRcst+LNB/FUca6V2Oa149yQjMmT8nyS5etCbzV7c6xYAmAIgKuc2 739w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature; bh=slkfJzLThfnq7dp6T3hHJaR873aqxgp2bKc6BsX9aV0=; b=C9HIabeHJnYNvbZBMw1SGy7va20mS7pwsVItL+KOzHhQwe3+TfB1ICfpvmiVQfBuqO vDchEKpxmGIJuoJB3L33DqHVwKl/lScIorwqKERgPlkzR6md3mCZj7mfr+ORrKni7bkT 1xHYFTqqKwfi+lCUDkfM0Hh6cPXgJu2Az1D50EJ5Mq4vzwpSsqJJY+CO3KrEE6bfpS6A eGH6ZdMuLwdeOfnq0Bs5rvH6yISfAorsYcAaWE6sUj7rf4Fh2LaFZbXtPzMt5AvaReid wtZorJ0pqvyujQNK6S2NKMEQ+DTG/7BicT3e0L0PNS9dK/9yM3HDV9PZfPDxCYH0XbI2 LiUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pinvfDrD; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id o198sor3415590pfd.60.2020.11.12.14.05.24 for (Google Transport Security); Thu, 12 Nov 2020 14:05:24 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pinvfDrD; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=slkfJzLThfnq7dp6T3hHJaR873aqxgp2bKc6BsX9aV0=; b=pinvfDrDrB6ctJHlCeWOYTxu5y04SDYjFnGR3GwyyCDGTbeCvS4VYROYFBfSi2WhCz KW8hlBAR3YFiOuLUNYTwBi+g9xr/VGgaTV2vWsnITUq9ZQfhas5xNg3/Wvr7gQtYykWF C3B5YcxnleGCEfOn0Zfx+3JoXDzz31JRxEVdZGfFXjiWK2kPeZShiRBZNDNR2dkccIHZ 09dI+FJpIwdTrg4w417/w3FRyR1QxjvsUHtxlGdjbN5GPCV2rGhtJCEskGqnB02OcG1R rmfQpkDGFfpQI0yg5p5VTLNbwQf16YFY5P5b+a5jjZmN8Lo4xmNb2kaSEa4ytkn2SBwv Nuzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=slkfJzLThfnq7dp6T3hHJaR873aqxgp2bKc6BsX9aV0=; b=P1sdklKqgbcZKkH+kK4Eh4DpOEwOD6sOPt6zOC/8qZ4IkosScMD+KQkbg2DaALmG9a gKj3RiebhECq9nkwCIeBMpJSndTrvuLSCwvEm7il23c0YgWbpEfZjxLQbRMgjXOvZ4L5 KTrr1ck89PJVB/hF4ak4vHJMon24Ati6x1VXXhkvjcM9hAxcVUxF7sXb7v5GF87UuazM uYRwyqQ4UwDp467Z7Cd2ZQ5UB6vQ+TvvYZ2/wmH1JtD/K3kLHa9Fb6xmT6DJC0IM6t0Y 8spvDOYEG+xaYWLKm4wGs0aRGK2P379rP3+VIsm0d3KKpVdsEBoOAw5L4R80qjG5frRf fRLw== X-Gm-Message-State: AOAM533m26oiiONXWuC7ixGudGMgaPs9hYrfr6nEfizW0rDziMjTVXFP W0zC9lfTJHtO7PmKnMDJb9I/pkIq X-Google-Smtp-Source: ABdhPJxfhZH/q5hThNOBnnLYhFe96bQakZ1Aix4ClMUJBa7gSEj5LlM3tIe7QGLlxguFwIACTomUHQ== X-Received: by 2002:aa7:9888:0:b029:18b:a9e2:dc7a with SMTP id r8-20020aa798880000b029018ba9e2dc7amr1335896pfl.67.1605218723741; Thu, 12 Nov 2020 14:05:23 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id mv5sm7638976pjb.42.2020.11.12.14.05.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2020 14:05:22 -0800 (PST) From: John Stultz To: lkml Cc: John Stultz , Robin Murphy , Will Deacon , Andy Gross , Maulik Shah , Bjorn Andersson , Saravana Kannan , Marc Zyngier , Lina Iyer , iommu@lists.linux-foundation.org, linux-arm-msm Subject: [RESEND][PATCH 1/2] arm-smmu-qcom: Ensure the qcom_scm driver has finished probing Date: Thu, 12 Nov 2020 22:05:19 +0000 Message-Id: <20201112220520.48159-1-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 Robin Murphy pointed out that if the arm-smmu driver probes before the qcom_scm driver, we may call qcom_scm_qsmmu500_wait_safe_toggle() before the __scm is initialized. Now, getting this to happen is a bit contrived, as in my efforts it required enabling asynchronous probing for both drivers, moving the firmware dts node to the end of the dtsi file, as well as forcing a long delay in the qcom_scm_probe function. With those tweaks we ran into the following crash: [ 2.631040] arm-smmu 15000000.iommu: Stage-1: 48-bit VA -> 48-bit IPA [ 2.633372] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 ... [ 2.633402] [0000000000000000] user address but active_mm is swapper [ 2.633409] Internal error: Oops: 96000005 [#1] PREEMPT SMP [ 2.633415] Modules linked in: [ 2.633427] CPU: 5 PID: 117 Comm: kworker/u16:2 Tainted: G W 5.10.0-rc1-mainline-00025-g272a618fc36-dirty #3971 [ 2.633430] Hardware name: Thundercomm Dragonboard 845c (DT) [ 2.633448] Workqueue: events_unbound async_run_entry_fn [ 2.633456] pstate: 80c00005 (Nzcv daif +PAN +UAO -TCO BTYPE=--) [ 2.633465] pc : qcom_scm_qsmmu500_wait_safe_toggle+0x78/0xb0 [ 2.633473] lr : qcom_smmu500_reset+0x58/0x78 [ 2.633476] sp : ffffffc0105a3b60 ... [ 2.633567] Call trace: [ 2.633572] qcom_scm_qsmmu500_wait_safe_toggle+0x78/0xb0 [ 2.633576] qcom_smmu500_reset+0x58/0x78 [ 2.633581] arm_smmu_device_reset+0x194/0x270 [ 2.633585] arm_smmu_device_probe+0xc94/0xeb8 [ 2.633592] platform_drv_probe+0x58/0xa8 [ 2.633597] really_probe+0xec/0x398 [ 2.633601] driver_probe_device+0x5c/0xb8 [ 2.633606] __driver_attach_async_helper+0x64/0x88 [ 2.633610] async_run_entry_fn+0x4c/0x118 [ 2.633617] process_one_work+0x20c/0x4b0 [ 2.633621] worker_thread+0x48/0x460 [ 2.633628] kthread+0x14c/0x158 [ 2.633634] ret_from_fork+0x10/0x18 [ 2.633642] Code: a9034fa0 d0007f73 29107fa0 91342273 (f9400020) To avoid this, this patch adds a check on qcom_scm_is_available() in the qcom_smmu_impl_init() function, returning -EPROBE_DEFER if its not ready. This allows the driver to try to probe again later after qcom_scm has finished probing. Cc: Robin Murphy Cc: Will Deacon Cc: Andy Gross Cc: Maulik Shah Cc: Bjorn Andersson Cc: Saravana Kannan Cc: Marc Zyngier Cc: Lina Iyer Cc: iommu@lists.linux-foundation.org Cc: linux-arm-msm Reported-by: Robin Murphy Signed-off-by: John Stultz --- drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c | 4 ++++ 1 file changed, 4 insertions(+) -- 2.17.1 diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c index 66ba4870659f4..ef37ccfa82562 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c @@ -159,6 +159,10 @@ struct arm_smmu_device *qcom_smmu_impl_init(struct arm_smmu_device *smmu) { struct qcom_smmu *qsmmu; + /* Check to make sure qcom_scm has finished probing */ + if (!qcom_scm_is_available()) + return ERR_PTR(-EPROBE_DEFER); + qsmmu = devm_kzalloc(smmu->dev, sizeof(*qsmmu), GFP_KERNEL); if (!qsmmu) return ERR_PTR(-ENOMEM); From patchwork Thu Nov 12 22:05:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 324252 Delivered-To: patches@linaro.org Received: by 2002:a05:6e02:5ce:0:0:0:0 with SMTP id l14csp706013ils; Thu, 12 Nov 2020 14:05:25 -0800 (PST) X-Received: by 2002:a63:5421:: with SMTP id i33mr1288301pgb.316.1605218725524; Thu, 12 Nov 2020 14:05:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605218725; cv=none; d=google.com; s=arc-20160816; b=ZjVEjJRJ1DBm1GGsxGzkPzRilsaVO3oXaeVBGLjEQeFui00G6w536rVtHVaVNjfV62 k4SVvsIl8WmfxadLkQcd1bedEA003kUmXWzHzo/5gv/WIAqk9JHfYzJ3h96UtSzJDCL2 oZdK8BK8ppbA7LuUzqRtCfSLIh3bkiQ/PsyFrnVWwVoVNzJeta73u8KoY7yP4QrNIBrh fz4e8hF8qYOtyz2W6mFHZ5eCh3fiv7xcAWP9uDen5+jWmPILfhUf6hXNlzKERUh9ub6u CY0oT+WLddwqz8YjibRph6oBYUqjd4zJOdZOWxGFZ28vEEROvKDdcMtTSHeByRGYWf4Q sABQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+LawQ4KJDTzVq+QOpbpG8odPiP4w40hrHWLf6v+3rmE=; b=EyHKFNuHxmydaL01ehq+Ne1Vwh9ToaBEGlMXD2BsGz1SM+AUl4js1L5yR6zOD9RZhu gyR9VrN2+y6zuUnwkUXLsOh3q/6mIY7ybl5XpK3BkfoeIk28a8VWJ/BLnukBspUqCtg3 KykgRwXFclDGbeV6igSf+N7/rdx6DZffCPKUEb2QqXBs7uTSYkJxBgdwII4lJ3KyfUh1 lTp9NrIKY/wiWyD8rK33LGzZzf+46wwe3Du6VPrk+KCyy8p21IMdOw22RMPchPB0UicE HFhvg+1fVUrGnXPzBdxNsz2+7nj+hW0ONi8qXZtyVhNLoJTaQc6BtnogwmirihK7Av5T Z6+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=htWCDbEm; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id n196sor3426942pfd.98.2020.11.12.14.05.25 for (Google Transport Security); Thu, 12 Nov 2020 14:05:25 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=htWCDbEm; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+LawQ4KJDTzVq+QOpbpG8odPiP4w40hrHWLf6v+3rmE=; b=htWCDbEmACJ9y+gah7nI9tft5RVJ1CtHVOlcXXga1UkmUIpP9KRR5X9vpAxLidVOJ+ sdq/Xg+NeKMAvmba9Gtv6CViADwOh7abi/n1hb4BkHkhcwW1EiPvt/XYcOA4mAFy22Do mltLfXPtS/WR61qc7e1YXL/nmxRzktg/JXPxJGU8sZLF6Dt+ZGk+4w1PoRbPUP8fSlB7 5A1/dgpbToPP4R4JXa4X3wZ0rG9+zYR+pR9EBWnVi+HD4lDfgJcZDcO2jmQ/6xTM/k8G +ODdG/qgThRGrXEqzbhbvVX0RAhfKg3sPxwXCos9bmxxNWNUgQd/qoyafic/F1MCBDIm zSlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+LawQ4KJDTzVq+QOpbpG8odPiP4w40hrHWLf6v+3rmE=; b=aBBHY/wVpscsLt0P55NeEA8aAN98gPxtJA/CJKoZzlkjXzlwhlRif7FLvsKaFyemfo zZ6WXBbWeoy9Ss5m3aLimImSecRKrPyd6yJ1PJTFov0PQRn/ECRNjJyuO5BtIMKduM1O f19T/csYcnGRDOflcFxDwAIUIICrBj4BBn2qiL0DyZo9zF9SVYG54Hd60cYmac2xbqyb jZbWecHxWv5gtIByuiDvj5JcqkcPyDrE1mV9lBqnu3J6orAoap4cwFs+KBrYnjtlLbt/ s7YPOjlz0Pw1jD7s13kLkrTLuJC+2duvOp57rIlF0nxT8qxNggmAi6wdRtQ7sOU1vqZi r7IQ== X-Gm-Message-State: AOAM53006ujd1O0Fzg5YnMNUnC9K32jZ+AV8UCQYu+at4Le69mkCnDRG OzAn6x31XeZjjMZ3KVpuEOikHqdi1g2yDj5o X-Google-Smtp-Source: ABdhPJzGwfTtv0eKnetksxwmqcLkLuFLyfkWvoLi4homYAQ4vpAhKHsccreAGTDL0qxC/sv1A2nKeQ== X-Received: by 2002:aa7:80c9:0:b029:164:4ca1:fff with SMTP id a9-20020aa780c90000b02901644ca10fffmr1432340pfn.11.1605218725223; Thu, 12 Nov 2020 14:05:25 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id mv5sm7638976pjb.42.2020.11.12.14.05.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2020 14:05:24 -0800 (PST) From: John Stultz To: lkml Cc: John Stultz , Robin Murphy , Will Deacon , Andy Gross , Maulik Shah , Bjorn Andersson , Saravana Kannan , Marc Zyngier , Lina Iyer , iommu@lists.linux-foundation.org, linux-arm-msm Subject: [RESEND][PATCH 2/2] iommu: Avoid crash if iommu_group is null Date: Thu, 12 Nov 2020 22:05:20 +0000 Message-Id: <20201112220520.48159-2-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201112220520.48159-1-john.stultz@linaro.org> References: <20201112220520.48159-1-john.stultz@linaro.org> In trying to handle a possible driver probe ordering issue brought up by Robin Murphy, I ran across a separate null pointer crash in the iommu core in iommu_group_remove_device(): [ 2.732803] dwc3-qcom a6f8800.usb: failed to get usb-ddr path: -517 [ 2.739281] Unable to handle kernel NULL pointer dereference at virtual address 00000000000000c0 ... [ 2.775619] [00000000000000c0] user address but active_mm is swapper [ 2.782039] Internal error: Oops: 96000005 [#1] PREEMPT SMP [ 2.787670] Modules linked in: [ 2.790769] CPU: 6 PID: 1 Comm: swapper/0 Tainted: G W 5.10.0-rc1-mainline-00025-g272a618fc36-dirty #3973 [ 2.801719] Hardware name: Thundercomm Dragonboard 845c (DT) [ 2.807431] pstate: 00c00005 (nzcv daif +PAN +UAO -TCO BTYPE=--) [ 2.813508] pc : iommu_group_remove_device+0x30/0x1b0 [ 2.818611] lr : iommu_release_device+0x4c/0x78 [ 2.823189] sp : ffffffc01005b950 ... [ 2.907082] Call trace: [ 2.909566] iommu_group_remove_device+0x30/0x1b0 [ 2.914323] iommu_release_device+0x4c/0x78 [ 2.918559] iommu_bus_notifier+0xe8/0x108 [ 2.922708] blocking_notifier_call_chain+0x78/0xb8 [ 2.927641] device_del+0x2ac/0x3d0 [ 2.931177] platform_device_del.part.9+0x20/0x98 [ 2.935933] platform_device_unregister+0x2c/0x40 [ 2.940694] of_platform_device_destroy+0xd8/0xe0 [ 2.945450] device_for_each_child_reverse+0x58/0xb0 [ 2.950471] of_platform_depopulate+0x4c/0x78 [ 2.954886] dwc3_qcom_probe+0x93c/0xcb8 [ 2.958858] platform_drv_probe+0x58/0xa8 [ 2.962917] really_probe+0xec/0x398 [ 2.966531] driver_probe_device+0x5c/0xb8 [ 2.970677] device_driver_attach+0x74/0x98 [ 2.974911] __driver_attach+0x60/0xe8 [ 2.978700] bus_for_each_dev+0x84/0xd8 [ 2.982581] driver_attach+0x30/0x40 [ 2.986194] bus_add_driver+0x160/0x208 [ 2.990076] driver_register+0x64/0x110 [ 2.993957] __platform_driver_register+0x58/0x68 [ 2.998716] dwc3_qcom_driver_init+0x20/0x28 [ 3.003041] do_one_initcall+0x6c/0x2d0 [ 3.006925] kernel_init_freeable+0x214/0x268 [ 3.011339] kernel_init+0x18/0x118 [ 3.014876] ret_from_fork+0x10/0x18 [ 3.018495] Code: d0006a21 f9417295 91130021 910162b6 (b940c2a2) In the case above, the arm-smmu driver fails to probe with EPROBE_DEFER, and I'm guessing I'm guessing that causes iommu_group_add_device() to fail and sets the dev->iommu_group = NULL, then somehow we hit iommu_group_remove_device() and trip over the null value? I'm not really sure... Anyway, adding the null check seems to avoid the issue and the system boots fine after the arm-smmu driver later reprobed. Feedback or better ideas for a solution would be appreciated! Cc: Robin Murphy Cc: Will Deacon Cc: Andy Gross Cc: Maulik Shah Cc: Bjorn Andersson Cc: Saravana Kannan Cc: Marc Zyngier Cc: Lina Iyer Cc: iommu@lists.linux-foundation.org Cc: linux-arm-msm Signed-off-by: John Stultz --- drivers/iommu/iommu.c | 4 ++++ 1 file changed, 4 insertions(+) -- 2.17.1 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index b53446bb8c6b4..28229f7ef7d5a 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -877,6 +877,10 @@ void iommu_group_remove_device(struct device *dev) struct iommu_group *group = dev->iommu_group; struct group_device *tmp_device, *device = NULL; + /* Avoid crash if iommu_group value is null */ + if (!group) + return; + dev_info(dev, "Removing from iommu group %d\n", group->id); /* Pre-notify listeners that a device is being removed. */