From patchwork Sat Oct 31 00:37: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: 320044 Delivered-To: patches@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp1877238ilc; Fri, 30 Oct 2020 17:37:26 -0700 (PDT) X-Received: by 2002:a17:90a:3f8a:: with SMTP id m10mr5780229pjc.222.1604104646414; Fri, 30 Oct 2020 17:37:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604104646; cv=none; d=google.com; s=arc-20160816; b=YErE/+MCG3koNczrl427aUiRWE2F1l9Wl30Oc5TP9RNt28YfiuwdSQVIwJ4annMZ7v wsEfVypodyxLZB4mMxpUfAkjzr9pHnoUBT5r2nU+abUY1/Z+lIR98XR8P/Sf/paHCvb7 FWKvFQIlwI6FjjSkGZYgTOlhothgCMVJDrNuZ7KYz5TSOL46t8e7dsjgHVN1/EgkNncF rn10de5agcw9D7IpheEVg2inUqPQrGfrXMALUh3vTwPLHpeU3pvsJ/Y65bAEmMyKTxZU J0UF+Skn3bubVsMLoJCusDdsOBpKci96sjQVDmFf2G+k61w7SWNHI8DyS8ctivE6lsL+ ChOA== 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=ugPBqsnIl2V0jMcu70sNlPSiYLKtLk6y5vaC53EyWcElySUxXqBsb8cc0JZ5rmJXU9 roKqk2juNGDq7Ja2QrK+M92N9C44koSDwpQY8JTlvlLnfNFsZhL4TldycJYgHDZ3VgWY L9rdqDQmr7ubkNHOLWvywZXaP1NXTv7CW4FZ4OjoqxlvjR55D+e63Zazrp2sPWCcFoTg iCzIGknmB3qWUL03A0Mcv3fTfI1q8IbFo3wZwemGOY5aEEnvZ56Ql33ERF6iY2b7u1JQ SuDF6YE+094Ktd6G8to7qCQDI5e2O0gbvg/azlHGOfLVW6CLN83VcR5InhkzLqVBxSYO dGSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=d27j2ULI; 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 z26sor3524104pgc.2.2020.10.30.17.37.26 for (Google Transport Security); Fri, 30 Oct 2020 17:37:26 -0700 (PDT) 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=d27j2ULI; 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=d27j2ULI1adERw0Mu20sV02cDmRxBknyx87aj2jNGSy2/M7FhauOGGIYsa/Riauctg EOhOPIR2uCCmfhcS+oUvPpXBRSNFYtd276GaskBByCba6IEvNT5TTOtszcE7VyxsUFqx ewjkRK0mj/PtB5XBM1m+yM8aN89NMbuO1JbXqfeYY3Hs3Z1Qd+XVGP8yBPpNYqMh1Ul9 leNi9X8AFkNvi5HXNNUy3Ksrs78MufZo0B1tf25ZKzzOY8fD2bVQBhoaGaEGFm+hAoa1 2/2I5/iXDrHp+HsjqL5fP40bJ4ViVQ1fp34Av4TyhSI9D1Miysjhu8pknQVl2Rcs+wPx Id0g== 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=pr1ucoPOW7IUR4W58q671RJNDVwTaX47nYBUuWIBEVEKg1+dMniwpjYOGl7ys6eUr1 jRw6WHCiM50TrNGHZ6CqN+yrL5MEhwkYJsBXw6BT2J+dg3qegn+KNkdFn+/sEI/nUCv6 Mj3Pba1SluA2TKWDE+aSDt7sMKbLEx1Z5SfDyGpacQzkuPW9V8PFtW7buLOT97e/qOPr bdGq0eHQ62LtRvkknR32/UuiHtSqj5Yavw8XPaqlEdDHCp8afNGFK5eNMg4EUEg8GgiX HmATdmd7OfPisQ7USeZRdZCNJIepH9i74faaCGvswIpvlqLhDgrfmghQud7UGxKviMg4 b3lA== X-Gm-Message-State: AOAM533hAd13cWzyjiFnuvR9qaN+cmkd9ScN9o1VLAb8sONvAY7btDCE JJWekr/5iZXAUcd2TXeAjNutePps X-Google-Smtp-Source: ABdhPJwsAAj5WjEJppnE9Spzkm3zC39E6buD+bP6zorkZkq6ERJ/7NpLN//oW7RJhe6svibAhZLCsw== X-Received: by 2002:a63:3111:: with SMTP id x17mr4241208pgx.329.1604104645927; Fri, 30 Oct 2020 17:37:25 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id 3sm7011935pfv.92.2020.10.30.17.37.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 17:37:25 -0700 (PDT) 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: [RFC][PATCH 1/2] arm-smmu-qcom: Ensure the qcom_scm driver has finished probing Date: Sat, 31 Oct 2020 00:37:20 +0000 Message-Id: <20201031003721.40973-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);