From mboxrd@z Thu Jan 1 00:00:00 1970 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 776E4C3DA4A for ; Thu, 22 Aug 2024 10:33:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To: Content-Transfer-Encoding:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=tUXipJTdapUuZZdhDEMNQWdCBYBL4+gU+qAyOZlKfmk=; b=BYVC2yvNW2PfEoHXg/xvaUV/uK NCpqHacVqMFM3y1HdjtvSxs5kA2KGa/BXnm2cshj01rZOZy6MYfD/ieYSrp8P8e23vcYurwaxy8K4 xZnaJaa8gB1+gQZWn71kE1cwKpLqycMk9lpbtdDerUjYUt2LqnXUbkblVTOWfhpttpvPmNLWzF3NJ TE/gqyWf/sEFH5p9O43Skv/jeUb+BKcfbGEJesK6pIVIU5yi5yPfYJuBIu2su/3PYDkqotqNpvFV4 ynHxXPk6I3jGSlS8uWLTKRqLrnlqGVnGgjqKsmUCLvYFTT3rEH/uq+B4YigkJ8onuwZcU6qO6TOTp unXplshw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sh589-0000000CReU-2avh; Thu, 22 Aug 2024 10:33:25 +0000 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sh56k-0000000CRTe-2cnh for linux-arm-kernel@lists.infradead.org; Thu, 22 Aug 2024 10:32:38 +0000 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-20353e5de9cso164255ad.0 for ; Thu, 22 Aug 2024 03:31:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1724322717; x=1724927517; darn=lists.infradead.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=tUXipJTdapUuZZdhDEMNQWdCBYBL4+gU+qAyOZlKfmk=; b=w4HarpkUU56e/MYNObuA4OAf/+8icjqTh6P1qetfs9+7Nt4k7MfQD4YkMv1RyWRyS+ OVZU72JbTXfNNYx2tGLTIlJD1UVrOCprXtM7RfZfM6a0h5AFGcHgRDBPq7N9MAP56+6K iON03Vcss8qQgAvoMna+3+oTeKFWERVQdqNsnM/A/Bj2D+jPoY8x6R7nEPS0DeBn1Ev2 ZWQ3nFoEN42WMH/hP0myeNv6GWmqM6mdcd355qAItTYRi0ZbCseC8f/8ROC2JMYhgtNw 8P2gbTMX3l7pRhb0TsbrooaYPuu8i8L0/sw7Snwd/K+QsRuwaObb8FlKtsFME/ZL20E2 APeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724322717; x=1724927517; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=tUXipJTdapUuZZdhDEMNQWdCBYBL4+gU+qAyOZlKfmk=; b=W8Naw67t/NnOmYzVk69OYhwcMLYAudojyR/W52YXEEnFlm9l4r7TGK9r7zye7B8lMD 5EI4KbwUkzHOB/W36GoJETjz9yMAAEkarYEJzL8UfONne/9Qrk/SApIYQOWj6zVqCLEl cBqEkvl8WbhGwTR7b6G9Hp+BmHbbJG4muTEaVeMsB6zQ83MOR/b2rUKTVmkfc6gTrJpf 1jb22VVtXTaYHpN9Et19MTchujxj7NtmIBLRYmV469Gvhb7J71n7thpwC+JitCkSaeUE imWKq7wr+TIDs/BU0DgNC3DcrxgrH+2ApCKZ9TILc7ougAsOCmgZPRTLskjdYfYtuuG0 4srQ== X-Forwarded-Encrypted: i=1; AJvYcCWMXzvPNjXzMMB3GuYQH35Fjc6XFwDBS5LRLpXtLdZoeaz8HimlxpKk8TPcKQGqRWh2L6W1y3OijrNcHx2IDJaV@lists.infradead.org X-Gm-Message-State: AOJu0Yz+AfILkQHjnJL2qrEUotN2ZWEm3n+YO14jZs75IyX3Xpx9CUra DJjUD7nevwn1/e5ktwfIPPJ7mZuWRs2Usa5Gjt3gR2XDM7sRbS4F2+L7rEKxWQ== X-Google-Smtp-Source: AGHT+IEH781ASflOBSZPkMIu7v/uf1ImBmbiSA+jZOLkQNWeidW1nwk8ZmripLpE58FpyKVExr8vpw== X-Received: by 2002:a17:903:32d1:b0:1f4:50b4:a50b with SMTP id d9443c01a7336-203824cefddmr2830035ad.18.1724322716320; Thu, 22 Aug 2024 03:31:56 -0700 (PDT) Received: from google.com (202.141.197.35.bc.googleusercontent.com. [35.197.141.202]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d613941e6esm1395309a91.26.2024.08.22.03.31.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 03:31:55 -0700 (PDT) Date: Thu, 22 Aug 2024 10:31:45 +0000 From: Pranjal Shrivastava To: Manivannan Sadhasivam Cc: Rob Clark , iommu@lists.linux.dev, linux-arm-msm@vger.kernel.org, Stephen Boyd , Robin Murphy , Rob Clark , Will Deacon , Joerg Roedel , Jason Gunthorpe , Jerry Snitselaar , Rob Herring , Krzysztof Kozlowski , Georgi Djakov , Dmitry Baryshkov , "moderated list:ARM SMMU DRIVERS" , open list Subject: Re: [PATCH v3 3/3] iommu/arm-smmu: Pretty-print context fault related regs Message-ID: References: <20240701162025.375134-1-robdclark@gmail.com> <20240701162025.375134-4-robdclark@gmail.com> <20240822100941.3tfqpjskzq43slfw@thinkpad> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240822100941.3tfqpjskzq43slfw@thinkpad> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240822_033158_697627_816E6BFE X-CRM114-Status: GOOD ( 28.15 ) 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 On Thu, Aug 22, 2024 at 03:39:41PM +0530, Manivannan Sadhasivam wrote: > On Mon, Jul 01, 2024 at 09:20:12AM -0700, Rob Clark wrote: > > From: Rob Clark > > > > Parse out the bitfields for easier-to-read fault messages. > > > > Signed-off-by: Rob Clark > > --- > > .../iommu/arm/arm-smmu/arm-smmu-qcom-debug.c | 52 +++++--------- > > drivers/iommu/arm/arm-smmu/arm-smmu.c | 70 +++++++++++++++---- > > drivers/iommu/arm/arm-smmu/arm-smmu.h | 21 ++++++ > > 3 files changed, 92 insertions(+), 51 deletions(-) > > > > [...] > > > diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-smmu/arm-smmu.c > > index 23cf91ac409b..79ec911ae151 100644 > > --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c > > +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c > > @@ -405,32 +405,72 @@ static const struct iommu_flush_ops arm_smmu_s2_tlb_ops_v1 = { > > .tlb_add_page = arm_smmu_tlb_add_page_s2_v1, > > }; > > > > + > > +void arm_smmu_read_context_fault_info(struct arm_smmu_device *smmu, int idx, > > + struct arm_smmu_context_fault_info *cfi) > > +{ > > + cfi->iova = arm_smmu_cb_readq(smmu, idx, ARM_SMMU_CB_FAR); > > + cfi->fsr = arm_smmu_cb_read(smmu, idx, ARM_SMMU_CB_FSR); > > + cfi->fsynr = arm_smmu_cb_read(smmu, idx, ARM_SMMU_CB_FSYNR0); > > + cfi->cbfrsynra = arm_smmu_gr1_read(smmu, ARM_SMMU_GR1_CBFRSYNRA(idx)); > > +} > > + > > +void arm_smmu_print_context_fault_info(struct arm_smmu_device *smmu, int idx, > > + const struct arm_smmu_context_fault_info *cfi) > > +{ > > + dev_dbg(smmu->dev, > > + "Unhandled context fault: fsr=0x%x, iova=0x%08lx, fsynr=0x%x, cbfrsynra=0x%x, cb=%d\n", > > + cfi->fsr, cfi->iova, cfi->fsynr, cfi->cbfrsynra, idx); > > + > > I just happen to hit an IOMMU fault in 6.11-rc4 and I did not see the 'Unhandled > context fault' log, but just the register dump in dmesg. Tracking that lead me > to this patch. > > May I know the reasoning behind making the actual error message _dbg()? It is > intentional first place? > > - Mani Hi Mani, That was a miss in this series, but it was fixed recently in [1]. I think it should land soon. [1] https://lore.kernel.org/linux-iommu/172381862229.1794487.17068761066364130246.b4-ty@kernel.org/ Thanks, Pranjal > > > + dev_err(smmu->dev, "FSR = %08x [%s%sFormat=%u%s%s%s%s%s%s%s%s], SID=0x%x\n", > > + cfi->fsr, > > + (cfi->fsr & ARM_SMMU_CB_FSR_MULTI) ? "MULTI " : "", > > + (cfi->fsr & ARM_SMMU_CB_FSR_SS) ? "SS " : "", > > + (u32)FIELD_GET(ARM_SMMU_CB_FSR_FORMAT, cfi->fsr), > > + (cfi->fsr & ARM_SMMU_CB_FSR_UUT) ? " UUT" : "", > > + (cfi->fsr & ARM_SMMU_CB_FSR_ASF) ? " ASF" : "", > > + (cfi->fsr & ARM_SMMU_CB_FSR_TLBLKF) ? " TLBLKF" : "", > > + (cfi->fsr & ARM_SMMU_CB_FSR_TLBMCF) ? " TLBMCF" : "", > > + (cfi->fsr & ARM_SMMU_CB_FSR_EF) ? " EF" : "", > > + (cfi->fsr & ARM_SMMU_CB_FSR_PF) ? " PF" : "", > > + (cfi->fsr & ARM_SMMU_CB_FSR_AFF) ? " AFF" : "", > > + (cfi->fsr & ARM_SMMU_CB_FSR_TF) ? " TF" : "", > > + cfi->cbfrsynra); > > + > > + dev_err(smmu->dev, "FSYNR0 = %08x [S1CBNDX=%u%s%s%s%s%s%s PLVL=%u]\n", > > + cfi->fsynr, > > + (u32)FIELD_GET(ARM_SMMU_CB_FSYNR0_S1CBNDX, cfi->fsynr), > > + (cfi->fsynr & ARM_SMMU_CB_FSYNR0_AFR) ? " AFR" : "", > > + (cfi->fsynr & ARM_SMMU_CB_FSYNR0_PTWF) ? " PTWF" : "", > > + (cfi->fsynr & ARM_SMMU_CB_FSYNR0_NSATTR) ? " NSATTR" : "", > > + (cfi->fsynr & ARM_SMMU_CB_FSYNR0_IND) ? " IND" : "", > > + (cfi->fsynr & ARM_SMMU_CB_FSYNR0_PNU) ? " PNU" : "", > > + (cfi->fsynr & ARM_SMMU_CB_FSYNR0_WNR) ? " WNR" : "", > > + (u32)FIELD_GET(ARM_SMMU_CB_FSYNR0_PLVL, cfi->fsynr)); > > +} > > + > > static irqreturn_t arm_smmu_context_fault(int irq, void *dev) > > { > > - u32 fsr, fsynr, cbfrsynra; > > - unsigned long iova; > > + struct arm_smmu_context_fault_info cfi; > > 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; > > > > - fsr = arm_smmu_cb_read(smmu, idx, ARM_SMMU_CB_FSR); > > - if (!(fsr & ARM_SMMU_CB_FSR_FAULT)) > > - return IRQ_NONE; > > + arm_smmu_read_context_fault_info(smmu, idx, &cfi); > > > > - fsynr = arm_smmu_cb_read(smmu, idx, ARM_SMMU_CB_FSYNR0); > > - iova = arm_smmu_cb_readq(smmu, idx, ARM_SMMU_CB_FAR); > > - cbfrsynra = arm_smmu_gr1_read(smmu, ARM_SMMU_GR1_CBFRSYNRA(idx)); > > + if (!(cfi.fsr & ARM_SMMU_CB_FSR_FAULT)) > > + return IRQ_NONE; > > > > - ret = report_iommu_fault(&smmu_domain->domain, NULL, iova, > > - fsynr & ARM_SMMU_CB_FSYNR0_WNR ? IOMMU_FAULT_WRITE : IOMMU_FAULT_READ); > > + ret = report_iommu_fault(&smmu_domain->domain, NULL, cfi.iova, > > + cfi.fsynr & ARM_SMMU_CB_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)) > > + arm_smmu_print_context_fault_info(smmu, idx, &cfi); > > > > - arm_smmu_cb_write(smmu, idx, ARM_SMMU_CB_FSR, fsr); > > + arm_smmu_cb_write(smmu, idx, ARM_SMMU_CB_FSR, cfi.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 b04a00126a12..e2aeb511ae90 100644 > > --- a/drivers/iommu/arm/arm-smmu/arm-smmu.h > > +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.h > > @@ -198,6 +198,7 @@ enum arm_smmu_cbar_type { > > #define ARM_SMMU_CB_FSR 0x58 > > #define ARM_SMMU_CB_FSR_MULTI BIT(31) > > #define ARM_SMMU_CB_FSR_SS BIT(30) > > +#define ARM_SMMU_CB_FSR_FORMAT GENMASK(10, 9) > > #define ARM_SMMU_CB_FSR_UUT BIT(8) > > #define ARM_SMMU_CB_FSR_ASF BIT(7) > > #define ARM_SMMU_CB_FSR_TLBLKF BIT(6) > > @@ -223,7 +224,14 @@ enum arm_smmu_cbar_type { > > #define ARM_SMMU_CB_FAR 0x60 > > > > #define ARM_SMMU_CB_FSYNR0 0x68 > > +#define ARM_SMMU_CB_FSYNR0_PLVL GENMASK(1, 0) > > #define ARM_SMMU_CB_FSYNR0_WNR BIT(4) > > +#define ARM_SMMU_CB_FSYNR0_PNU BIT(5) > > +#define ARM_SMMU_CB_FSYNR0_IND BIT(6) > > +#define ARM_SMMU_CB_FSYNR0_NSATTR BIT(8) > > +#define ARM_SMMU_CB_FSYNR0_PTWF BIT(10) > > +#define ARM_SMMU_CB_FSYNR0_AFR BIT(11) > > +#define ARM_SMMU_CB_FSYNR0_S1CBNDX GENMASK(23, 16) > > > > #define ARM_SMMU_CB_FSYNR1 0x6c > > > > @@ -533,4 +541,17 @@ struct arm_smmu_device *qcom_smmu_impl_init(struct arm_smmu_device *smmu); > > void arm_smmu_write_context_bank(struct arm_smmu_device *smmu, int idx); > > int arm_mmu500_reset(struct arm_smmu_device *smmu); > > > > +struct arm_smmu_context_fault_info { > > + unsigned long iova; > > + u32 fsr; > > + u32 fsynr; > > + u32 cbfrsynra; > > +}; > > + > > +void arm_smmu_read_context_fault_info(struct arm_smmu_device *smmu, int idx, > > + struct arm_smmu_context_fault_info *cfi); > > + > > +void arm_smmu_print_context_fault_info(struct arm_smmu_device *smmu, int idx, > > + const struct arm_smmu_context_fault_info *cfi); > > + > > #endif /* _ARM_SMMU_H */ > > -- > > 2.45.2 > > > > > > -- > மணிவண்ணன் சதாசிவம்