From patchwork Tue May 20 17:44:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Connor Abbott X-Patchwork-Id: 891344 Received: from mail-qv1-f43.google.com (mail-qv1-f43.google.com [209.85.219.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1BF11AF4C1 for ; Tue, 20 May 2025 17:45:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747763105; cv=none; b=dyAmBnCVRxyfHesAA3poMEP04HSTMD113DT4gmbyXAFeDe81FkCZ8TFB5PH2PvU0asdzfC0UsC/pg7EJXbmvZVswbLKUBr+nAHgvfFd/gRS7j5wM7xMhQX+6MOOd/T4JaIhA8VtC0mouTy5a15QUftbur5uxuxxoq8YCH2lIvJ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747763105; c=relaxed/simple; bh=xmVtxKp7l1nH9HRMvlhp+AXA8iIyclW4FjVkhjfpiJg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QyJ4GFKOIbKWwpRsd6NAYEHWpik6IwroSpnHFCXCJZlkXrO0CzJ2cqbziPl6B3s50d7+mFu4JSBrvU6FUpPe73Ncsxjq6OkpNHXy7Up5e4zwU4Kd1l1ed4UEiOicLC7O5wGOASLkQ4Ix1Q6Hty5n8UwarNn3gDMFssJvnGPwuyk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=L/BHj9jB; arc=none smtp.client-ip=209.85.219.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="L/BHj9jB" Received: by mail-qv1-f43.google.com with SMTP id 6a1803df08f44-6f8adf56370so9292926d6.1 for ; Tue, 20 May 2025 10:45:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747763102; x=1748367902; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Ii8Ima0T9o2vsm/Kvny8YHfjV8PP21HFA5Cwpdauwc4=; b=L/BHj9jBo8h9Txl5FghjeP7bWpfLPCdi4+t9M+yOh4iacDKu9ReM0q5GBXPMfv/vBB UiUWI9XCXglwzcnLxofl32DtPeBohZbbcT/N9yagMKDS9OefEnNpE1da+mbH9klUjxg+ D1T81E5ThhSWvKnMU22S3UTGio3VEHIPbd35hFkO72lxzBkOpS3KeYAicSgYXvW6mVpo oe8BKzNU7VJahaD8ZeUIPU8knwH5EEG3i3Rqdx0d3FTIxffQQ6ql1YG+2j/en8R37cKY jtTuCUKFgHk4q89CKj/idAVzpHZkFbcIkmAfsI10P/SJHDN8W/gD73SY++ClsELF287u wPMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747763102; x=1748367902; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ii8Ima0T9o2vsm/Kvny8YHfjV8PP21HFA5Cwpdauwc4=; b=hGgMfSahSFYMQu2lA5zPvPIkqwh2gTcCC1bTy6r6/bzM/zGyAXAMl2er1/iA2sooIy BQD0QMjSxvGkqY7TjxF1u3DnVoWzZuiz5bIKgX5fRP3PsQhU2BJl795/vqdgsInd4KfB 3uzac6gboxKmsrEK0b+98ovsm2j26+x+3DW+nhhcR6Ypd96aQHL9oMZvBglVxFIsCKRl vZwaHY5HNJbJwlqE86523y8A7JiKEBarhDQqN1LT+8k8/MbHVaIk8Sb5R0BXq6k/YQhF m9tThSQxJdhslRo6IRPNSJNGgkAL4l++es9/g01mYSYu2qNwIEa+TTH3TGXy4cItUmpC 23BA== X-Forwarded-Encrypted: i=1; AJvYcCUPBaB2ZhE8A8IWpQtkG+a5dZu7TLWENFtgoZkNs/DSO4fdNIAkmTFvqIWW7i6icieBX9X4sjKXzoL1C40N@vger.kernel.org X-Gm-Message-State: AOJu0YzBHZifeKiOU+f7aw89IaDeIW0vwdCwpagryg/Um/JyjBxsfqMM /7Sj50IvC8bfvTWM67ZOVOsJ0EVoDiB+3yJhP0eVK2B+r0RYY4rz9Y8GxW/bTejb X-Gm-Gg: ASbGnct9pJQSqtMyI7kYcvJWFMebKbWp+RGXJjr2K7So6arP0Ji7Rx5GIRJlieAwK90 qPLAiqgI6BMYWde0SLv5IK36dJ9hcc9AxVxZwCPRCEU7iMzs/LWV3+40HuxBmh4oamiff6tCIqN NnePu60VUD5IgAcrOJyLgRwWC9kFuMLKSZoX/OynD9X9deCcs5v3OVkUKPBasHKywyp1tj/NhhV +QavRtXETmz592nOPjzEo0zVy3cJ8y6cQzlpjnIqLHBByvi6DLJW011dzEuCyKzYu75PPjr6BH4 ZBx62rK4EIwVVooAfIz6XktcoItsdloVFws5m6XPM9vqPNeK7htNkOVLrYj4Bu6Qcyjuiv6Vq+j s7EB5Qetj/2S3YJLuvsc= X-Google-Smtp-Source: AGHT+IGHjNqtL4ML4K6mgFG8Y9ysSdvcdDlvh9TXE8IuhX0uhbekGYa67m2VZbTWJPgCHebVjAgMOg== X-Received: by 2002:a05:6214:e66:b0:6f8:c773:367 with SMTP id 6a1803df08f44-6f8c773156emr75941506d6.10.1747763102259; Tue, 20 May 2025 10:45:02 -0700 (PDT) Received: from [192.168.124.1] (syn-067-243-142-039.res.spectrum.com. [67.243.142.39]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6f8b096ddb4sm74126586d6.78.2025.05.20.10.45.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 May 2025 10:45:01 -0700 (PDT) From: Connor Abbott Date: Tue, 20 May 2025 13:44:51 -0400 Subject: [PATCH v7 2/7] iommu/arm-smmu: Move handing of RESUME to the context fault handler Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250520-msm-gpu-fault-fixes-next-v7-2-96cd1cc9ae05@gmail.com> References: <20250520-msm-gpu-fault-fixes-next-v7-0-96cd1cc9ae05@gmail.com> In-Reply-To: <20250520-msm-gpu-fault-fixes-next-v7-0-96cd1cc9ae05@gmail.com> To: Rob Clark , Will Deacon , Robin Murphy , Joerg Roedel , Sean Paul , Konrad Dybcio , Abhinav Kumar , Dmitry Baryshkov , Marijn Suijten Cc: iommu@lists.linux.dev, linux-arm-msm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, freedreno@lists.freedesktop.org, Connor Abbott X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1747763098; l=5304; i=cwabbott0@gmail.com; s=20240426; h=from:subject:message-id; bh=xmVtxKp7l1nH9HRMvlhp+AXA8iIyclW4FjVkhjfpiJg=; b=PbqlKooG9WJYSUN66hnuD7Hs/WXVtPXW5O42qPXoWh9DeILsAkZl1dC2cj4pxrwKSl2Dy/a6j 6Xw2i7fjiClCzQcHWFkZHeFDoj6GJLgXfQwNHeoaudrBrkhd0nC7Eg+ X-Developer-Key: i=cwabbott0@gmail.com; a=ed25519; pk=dkpOeRSXLzVgqhy0Idr3nsBr4ranyERLMnoAgR4cHmY= The upper layer fault handler is now expected to handle everything required to retry the transaction or dump state related to it, since we enable threaded IRQs. This means that we can take charge of writing RESUME, making sure that we always write it after writing FSR as recommended by the specification. The iommu handler should write -EAGAIN if a transaction needs to be retried. This avoids tricky cross-tree changes in drm/msm, since it never wants to retry the transaction and it already returns 0 from its fault handler. Therefore it will continue to correctly terminate the transaction without any changes required. devcoredumps from drm/msm will temporarily be broken until it is fixed to collect devcoredumps inside its fault handler, but fixing that first would actually be worse because MMU-500 ignores writes to RESUME unless all fields of FSR (except SS of course) are clear and raises an interrupt when only SS is asserted. Right now, things happen to work most of the time if we collect a devcoredump, because RESUME is written asynchronously in the fault worker after the fault handler clears FSR and finishes, although there will be some spurious faults, but if this is changed before this commit fixes the FSR/RESUME write order then SS will never be cleared, the interrupt will never be cleared, and the whole system will hang every time a fault happens. It will therefore help bisectability if this commit goes first. I've changed the TBU path to also accept -EAGAIN and do the same thing, while keeping the old -EBUSY behavior. Although the old path was broken because you'd get a storm of interrupts due to returning IRQ_NONE that would eventually result in the interrupt being disabled, and I think it was dead code anyway, so it should eventually be deleted. Note that drm/msm never uses TBU so this is untested. Signed-off-by: Connor Abbott --- drivers/iommu/arm/arm-smmu/arm-smmu-qcom-debug.c | 9 +++++++++ drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c | 14 -------------- drivers/iommu/arm/arm-smmu/arm-smmu.c | 6 ++++++ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom-debug.c b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom-debug.c index d03b2239baad48680eb6c3201c85f924ec4a0e07..65e0ef6539fe70aabffa0c8fbe444c34c620d367 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom-debug.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom-debug.c @@ -406,6 +406,12 @@ irqreturn_t qcom_smmu_context_fault(int irq, void *dev) arm_smmu_print_context_fault_info(smmu, idx, &cfi); arm_smmu_cb_write(smmu, idx, ARM_SMMU_CB_FSR, cfi.fsr); + + if (cfi.fsr & ARM_SMMU_CB_FSR_SS) { + arm_smmu_cb_write(smmu, idx, ARM_SMMU_CB_RESUME, + ret == -EAGAIN ? 0 : ARM_SMMU_RESUME_TERMINATE); + } + return IRQ_HANDLED; } @@ -416,6 +422,9 @@ irqreturn_t qcom_smmu_context_fault(int irq, void *dev) if (!tmp || tmp == -EBUSY) { ret = IRQ_HANDLED; resume = ARM_SMMU_RESUME_TERMINATE; + } else if (tmp == -EAGAIN) { + ret = IRQ_HANDLED; + resume = 0; } else { phys_addr_t phys_atos = qcom_smmu_verify_fault(smmu_domain, cfi.iova, cfi.fsr); diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c index 4d3b99babd3584ec971bef30cd533c35904fe7f5..c84730d33a30c013a37e603d10319fb83203eaa5 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c @@ -120,19 +120,6 @@ static void qcom_adreno_smmu_set_stall(const void *cookie, bool enabled) qsmmu->stall_enabled &= ~BIT(cfg->cbndx); } -static void qcom_adreno_smmu_resume_translation(const void *cookie, bool terminate) -{ - struct arm_smmu_domain *smmu_domain = (void *)cookie; - struct arm_smmu_cfg *cfg = &smmu_domain->cfg; - struct arm_smmu_device *smmu = smmu_domain->smmu; - u32 reg = 0; - - if (terminate) - reg |= ARM_SMMU_RESUME_TERMINATE; - - arm_smmu_cb_write(smmu, cfg->cbndx, ARM_SMMU_CB_RESUME, reg); -} - static void qcom_adreno_smmu_set_prr_bit(const void *cookie, bool set) { struct arm_smmu_domain *smmu_domain = (void *)cookie; @@ -337,7 +324,6 @@ static int qcom_adreno_smmu_init_context(struct arm_smmu_domain *smmu_domain, priv->set_ttbr0_cfg = qcom_adreno_smmu_set_ttbr0_cfg; priv->get_fault_info = qcom_adreno_smmu_get_fault_info; priv->set_stall = qcom_adreno_smmu_set_stall; - priv->resume_translation = qcom_adreno_smmu_resume_translation; priv->set_prr_bit = NULL; priv->set_prr_addr = NULL; diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-smmu/arm-smmu.c index 8f439c265a23f16bd11801a93dae12fd476ddfb2..8d95b14c7d5a4040bb8add56475e297beb16b162 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c @@ -474,6 +474,12 @@ static irqreturn_t arm_smmu_context_fault(int irq, void *dev) arm_smmu_print_context_fault_info(smmu, idx, &cfi); arm_smmu_cb_write(smmu, idx, ARM_SMMU_CB_FSR, cfi.fsr); + + if (cfi.fsr & ARM_SMMU_CB_FSR_SS) { + arm_smmu_cb_write(smmu, idx, ARM_SMMU_CB_RESUME, + ret == -EAGAIN ? 0 : ARM_SMMU_RESUME_TERMINATE); + } + return IRQ_HANDLED; }