From patchwork Thu May 23 21:34:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13672329 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 86140C25B79 for ; Thu, 23 May 2024 21:35:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=7+6WpupTUCg13sV+0stUd2a2vm1wXg9pHE/ciDKwRf8=; b=zs7R5fTkTc3ojh AysX1uxsHnjWTTP4byfhGqOa2U0M2g04zGjDwU7CXXtl/joPKHcDnIJm0PLFiTUWHVKejzH8HEslM mcs49jlkrQ1S5OIX1Ml/yW+ZRqDG9Eg4ZDn/qMTFRnmuXdDk56BMdrc35d4m6GksuGyD1G3fUsQhu Nz/jCnMem4zI/0v8/sLzW3vxve5U6I2pZuV2PZLVKvykZ6RNIJDjIQXqQZk4SgbukZHiO+dObMMhn 50+GvR8OfQV8avCGraF8zt8jj42prlqpEy421jCVNJBiVmCr4k3yKlDYlmrGRcqRee2s3aRADojFW SyzZtZTKqh18IFv5dUVQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sAG5W-00000007Nhd-0u7q; Thu, 23 May 2024 21:35:02 +0000 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sAG5T-00000007Ngr-0hj7 for linux-arm-kernel@lists.infradead.org; Thu, 23 May 2024 21:35:00 +0000 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1f32a3b9491so17273445ad.0 for ; Thu, 23 May 2024 14:34:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716500098; x=1717104898; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=T7a2uMVZssHO/XdZkFjaZx6Fve2Wj78fROEuqBTUEKo=; b=R5yknD4w5fT9J+4nrQBvNG5fR++MLRY+fDeUwBwBdpvn+lmBKruhuhB39gqvsbVwJ+ HLln9gzrh2t8J9e7fX48z7vDZdUVEiS7gU44ygTlWlsrC4HpWeCacb4MXyjpfW7HmKH3 AyckJ0wwN7ANTW6VOc3UDOmUqGxwYANqOmG8Ia4MmpujfNOcAx2KtTBwcPNFROJZb0RH x4OjRyU4UzAFJ++Mk5SLG7Tx33fUVHR+GAYZoNXhKU6eN6tmP9z/ZLN0lKGTuQAz+NiB Yj18DBxumVxjXFpLSrq6htbAf44i46+U+bd/JaLugl1NRp+Y9xWXRzCfc04Zy97Cz/LT Q9NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716500098; x=1717104898; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=T7a2uMVZssHO/XdZkFjaZx6Fve2Wj78fROEuqBTUEKo=; b=KpaqDmTDFJmM82DSxnMq2PbB59kLzjksLvFUiz3Vd5ocwWBRonfEvgfX3cZ9p+Nzqo judMUt67DrFkBfskuuGWkL+EJhaettNCaxMHXUq5GOSF2LsrkEXBwJ6Zx2AyW132hyoD 7ZgU+gC+LcnXVS6YeO+8v46w4Fe3c8njFYHI9EyXZdqFiDFzpDY0N2BGphQHgYb0WLZb 0Ftxzltx2oDI7iqBWAgnBonOE8KiDXEzohhekaKjr/rVQHKxBj/qdBDf33PL/KBKuWm7 +UqT6YileivSHCazR+2w8PAJtE5yrHLYO4PXobROlFFcZdWyejUvwbj3OrHbA1ArtARC 5wIg== X-Forwarded-Encrypted: i=1; AJvYcCV7t8kUN1WzgQkgtZWAqk/zA7LnMhUIJykyzwxocIyMHYQ8vOnF5EDJqK43zm0v2SanQHkrJRclDnECDnZeGGJrSjmTeFzAmMUZ/nuYdG2DWyjXLIo= X-Gm-Message-State: AOJu0YxLyrnTIR3Ceg7bWmlnYSplCIuGVcx+MqZVFD0b/3rscpdD1I+A EQplTSSAYALuRmUMTHkdov3ZYROLkf4zo1Ngt/mCylhITskQURvj X-Google-Smtp-Source: AGHT+IHg64GfV68qCaL9nLaV71GpQJxYCS/dHS/c9zQ8wKfbt4plO5szkSRDbRHEZbACBIBwzwC+Ng== X-Received: by 2002:a17:902:ea0a:b0:1f2:fd9a:dbf3 with SMTP id d9443c01a7336-1f4486d1fa4mr5743115ad.11.1716500097727; Thu, 23 May 2024 14:34:57 -0700 (PDT) Received: from localhost ([2a00:79e1:2e00:1301:e1c5:6354:b45d:8ffc]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f44c9dd519sm399235ad.298.2024.05.23.14.34.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 14:34:57 -0700 (PDT) From: Rob Clark To: iommu@lists.linux-foundation.org Cc: linux-arm-msm@vger.kernel.org, Stephen Boyd , Rob Clark , Will Deacon , Robin Murphy , Joerg Roedel , Jason Gunthorpe , Jerry Snitselaar , Krzysztof Kozlowski , Rob Herring , Dmitry Baryshkov , linux-arm-kernel@lists.infradead.org (moderated list:ARM SMMU DRIVERS), iommu@lists.linux.dev (open list:IOMMU SUBSYSTEM), linux-kernel@vger.kernel.org (open list) Subject: [PATCH] iommu/arm-smmu: Pretty-print context fault related regs Date: Thu, 23 May 2024 14:34:47 -0700 Message-ID: <20240523213452.144108-1-robdclark@gmail.com> X-Mailer: git-send-email 2.45.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240523_143459_240803_172447E3 X-CRM114-Status: GOOD ( 14.69 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Rob Clark Parse out the bitfields for easier-to-read fault messages. Signed-off-by: Rob Clark --- Stephen was wanting easier to read fault messages.. so I typed this up. drivers/iommu/arm/arm-smmu/arm-smmu.c | 53 +++++++++++++++++++++++++-- drivers/iommu/arm/arm-smmu/arm-smmu.h | 5 +++ 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-smmu/arm-smmu.c index c572d877b0e1..06712d73519c 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c @@ -411,6 +411,8 @@ static irqreturn_t arm_smmu_context_fault(int irq, void *dev) unsigned long iova; struct arm_smmu_domain *smmu_domain = dev; struct arm_smmu_device *smmu = smmu_domain->smmu; + static DEFINE_RATELIMIT_STATE(rs, DEFAULT_RATELIMIT_INTERVAL, + DEFAULT_RATELIMIT_BURST); int idx = smmu_domain->cfg.cbndx; int ret; @@ -425,10 +427,53 @@ static irqreturn_t arm_smmu_context_fault(int irq, void *dev) ret = report_iommu_fault(&smmu_domain->domain, NULL, iova, fsynr & ARM_SMMU_FSYNR0_WNR ? IOMMU_FAULT_WRITE : IOMMU_FAULT_READ); - if (ret == -ENOSYS) - dev_err_ratelimited(smmu->dev, - "Unhandled context fault: fsr=0x%x, iova=0x%08lx, fsynr=0x%x, cbfrsynra=0x%x, cb=%d\n", - fsr, iova, fsynr, cbfrsynra, idx); + if (ret == -ENOSYS && __ratelimit(&rs)) { + static const struct { + u32 mask; const char *name; + } fsr_bits[] = { + { ARM_SMMU_FSR_MULTI, "MULTI" }, + { ARM_SMMU_FSR_SS, "SS" }, + { ARM_SMMU_FSR_UUT, "UUT" }, + { ARM_SMMU_FSR_ASF, "ASF" }, + { ARM_SMMU_FSR_TLBLKF, "TLBLKF" }, + { ARM_SMMU_FSR_TLBMCF, "TLBMCF" }, + { ARM_SMMU_FSR_EF, "EF" }, + { ARM_SMMU_FSR_PF, "PF" }, + { ARM_SMMU_FSR_AFF, "AFF" }, + { ARM_SMMU_FSR_TF, "TF" }, + }, fsynr0_bits[] = { + { ARM_SMMU_FSYNR0_WNR, "WNR" }, + { ARM_SMMU_FSYNR0_PNU, "PNU" }, + { ARM_SMMU_FSYNR0_IND, "IND" }, + { ARM_SMMU_FSYNR0_NSATTR, "NSATTR" }, + { ARM_SMMU_FSYNR0_PTWF, "PTWF" }, + { ARM_SMMU_FSYNR0_AFR, "AFR" }, + }; + + pr_err("%s %s: Unhandled context fault: fsr=0x%x (", + dev_driver_string(smmu->dev), dev_name(smmu->dev), fsr); + + for (int i = 0, n = 0; i < ARRAY_SIZE(fsr_bits); i++) { + if (fsr & fsr_bits[i].mask) { + pr_cont("%s%s", (n > 0) ? "|" : "", fsr_bits[i].name); + n++; + } + } + + pr_cont("), iova=0x%08lx, fsynr=0x%x (S1CBNDX=%u", iova, fsynr, + (fsynr >> 16) & 0xff); + + for (int i = 0; i < ARRAY_SIZE(fsynr0_bits); i++) { + if (fsynr & fsynr0_bits[i].mask) { + pr_cont("|%s", fsynr0_bits[i].name); + } + } + + pr_cont("|PLVL=%u), cbfrsynra=0x%x, cb=%d\n", + fsynr & 0x3, /* FSYNR0.PLV */ + cbfrsynra, idx); + + } arm_smmu_cb_write(smmu, idx, ARM_SMMU_CB_FSR, fsr); return IRQ_HANDLED; diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.h b/drivers/iommu/arm/arm-smmu/arm-smmu.h index 836ed6799a80..3b051273718b 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.h +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.h @@ -223,6 +223,11 @@ enum arm_smmu_cbar_type { #define ARM_SMMU_CB_FSYNR0 0x68 #define ARM_SMMU_FSYNR0_WNR BIT(4) +#define ARM_SMMU_FSYNR0_PNU BIT(5) +#define ARM_SMMU_FSYNR0_IND BIT(6) +#define ARM_SMMU_FSYNR0_NSATTR BIT(8) +#define ARM_SMMU_FSYNR0_PTWF BIT(10) +#define ARM_SMMU_FSYNR0_AFR BIT(11) #define ARM_SMMU_CB_FSYNR1 0x6c