From patchwork Wed Jun 26 16:38:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13713183 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 71C0DC27C4F for ; Wed, 26 Jun 2024 16:39:08 +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:Content-Transfer-Encoding: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=SWzieAW4a+lvny1okz+Epi3m5sR5cLacEd8KBGZql9g=; b=zVwFFLoNmh//LV2tF+CutpzFIV RyL9jd0MGtoBgeXMDsvGc9fg0x+2MdaAonIAqPu327uWCZramSQpuHCeMywmbeltwAELRXqmAAtT7 cDSeIEFxMWPyPuZi7Iu7Lbk7JULqk9uTmD8SI8D8IUSi5xMZHdCV1NO42XiD6N+FbOjB6NvZwzc6+ XvHpZUgs+v1Ie03xpnXuQEPQryT948gpdMHxK7Cq91W/Dw77PdmK+vUAOo9HUZKHOoN/K7AtIfR3F jMNbZT+nGPrgC7MXWdDU8l+y8XcMYMs1bCBZPoJoj4ZxeRLb3ucCq4sUnV8ZI3j6QOLatRr0TAnpe WaKRTDMQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sMVfb-00000007dC3-1wfC; Wed, 26 Jun 2024 16:38:55 +0000 Received: from mail-oo1-xc29.google.com ([2607:f8b0:4864:20::c29]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sMVfT-00000007dAB-45Oy for linux-arm-kernel@lists.infradead.org; Wed, 26 Jun 2024 16:38:49 +0000 Received: by mail-oo1-xc29.google.com with SMTP id 006d021491bc7-5b970a97e8eso3688830eaf.1 for ; Wed, 26 Jun 2024 09:38:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719419926; x=1720024726; 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=SWzieAW4a+lvny1okz+Epi3m5sR5cLacEd8KBGZql9g=; b=kDJ4cAW6o8yTWaaJwZPqFDnJ5fKFflAqM2ha7vWlYNx80Ggq+8D54m7j7B4Pc7wf3G yNzuPzoV0LXjHP85OlseNYX/QkucipDlprWC9N296muBc+XBUwEXVhPUevjbsvbZMFqQ l1jH5qTawwG5sxwMwOsrtqf84Gi03AJY0eo6cJAl2g9VWXRE2oERNFX7nV/RNX9qQBVm DkM6QRlQLojv3J7J6DzVVP+SbhWLyOnbeQ7nEgo0/JyP6Dpd1NpzplMHE+kFImlFL7CB wt7yjOJI8Z0SAyLRAyMFHFPPgyFISLpfuMeBKnj7jCeZBhaNaTnLic0pl069juG+RgAN V5Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719419926; x=1720024726; 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=SWzieAW4a+lvny1okz+Epi3m5sR5cLacEd8KBGZql9g=; b=nljaCD9ZIXaW0qnLc0UvsHuhKZZDIDLBLWOX/vytKOgrWR708wrPp4pjB2iNGl2czk LUm/TmZOXRbQgfaTFYO0sHyh1gn/O2axcyTX/NIjs5tdIu9nXjTh8cKb0UC1jhXJ/UxJ 2sV7CicUCWruA4QHKwlHGmhgxprBEJjZQOwtkLwlA0gm7Koz3d8vhjYp6TFxcZXptWln 3rX8vrwaqDZrLhyIyMYO1C5QMR/H9ru7zINpYu8in+1J11XT+W8KOvDErfB1nNQ6LyMP 2niH7JYm3Ik2HccXM0834chUstRSw1v47sNq0HJSphAG32WxZM2VzTHmVxrTFJmyHXIb EFSw== X-Forwarded-Encrypted: i=1; AJvYcCWs6wlIo+FC3Eb7cCAxirMpytQriOGCv2sdns06FtCJp4KUOZI+IkEROig9umWIOyoTqJwodQP2AnhqCIC52nldGM/4XafZmT+Ra0kP07oaAjjRyC0= X-Gm-Message-State: AOJu0YyT1tcovqhrO3xeYm49d/Lfb7EhNf0DJBaUHfbTqbTOHlthDLRf BDnHz2+0Y89WT+hlxBXdW+DKdjPYjS9+xEyMqE+F0D/zOQwtgq4s X-Google-Smtp-Source: AGHT+IF32yp5lqZIJHIVEYNwMPOPqn40IzoSCvEsTm7oJ/KwT63/UUbxgksu4RHOILX8ivphZ4mRHA== X-Received: by 2002:a05:6358:998d:b0:19f:38a0:f507 with SMTP id e5c5f4694b2df-1a23c02ab11mr1433148055d.5.1719419926096; Wed, 26 Jun 2024 09:38:46 -0700 (PDT) Received: from localhost ([2a00:79e1:2e00:1301:e1c5:6354:b45d:8ffc]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-716ba5b5f58sm8985778a12.73.2024.06.26.09.38.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jun 2024 09:38:44 -0700 (PDT) From: Rob Clark To: iommu@lists.linux.dev Cc: linux-arm-msm@vger.kernel.org, Stephen Boyd , Pranjal Shrivastava , Robin Murphy , Rob Clark , Rob Clark , Will Deacon , Joerg Roedel , Jason Gunthorpe , Jerry Snitselaar , Rob Herring , Dmitry Baryshkov , Georgi Djakov , linux-arm-kernel@lists.infradead.org (moderated list:ARM SMMU DRIVERS), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2] iommu/arm-smmu: Pretty-print context fault related regs Date: Wed, 26 Jun 2024 09:38:37 -0700 Message-ID: <20240626163842.205631-1-robdclark@gmail.com> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240626_093848_042648_1C78EE52 X-CRM114-Status: GOOD ( 16.64 ) 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 --- I kept with the dev_err, which matches qcom_smmu_context_fault. It is only adding two extra lines, and it is ratelimited. I also converted qcom_smmu_context_fault() to use the helpers to do the parsing, rather than more or less duplicating. .../iommu/arm/arm-smmu/arm-smmu-qcom-debug.c | 21 +++--- drivers/iommu/arm/arm-smmu/arm-smmu.c | 70 ++++++++++++++++++- drivers/iommu/arm/arm-smmu/arm-smmu.h | 58 +++++++++------ 3 files changed, 110 insertions(+), 39 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 552199cbd9e2..ee7eab273e1a 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom-debug.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom-debug.c @@ -429,22 +429,17 @@ irqreturn_t qcom_smmu_context_fault(int irq, void *dev) phys_addr_t phys_atos = qcom_smmu_verify_fault(smmu_domain, iova, fsr); if (__ratelimit(&_rs)) { + char buf[80]; + dev_err(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); - dev_err(smmu->dev, - "FSR = %08x [%s%s%s%s%s%s%s%s%s], SID=0x%x\n", - fsr, - (fsr & 0x02) ? "TF " : "", - (fsr & 0x04) ? "AFF " : "", - (fsr & 0x08) ? "PF " : "", - (fsr & 0x10) ? "EF " : "", - (fsr & 0x20) ? "TLBMCF " : "", - (fsr & 0x40) ? "TLBLKF " : "", - (fsr & 0x80) ? "MHF " : "", - (fsr & 0x40000000) ? "SS " : "", - (fsr & 0x80000000) ? "MULTI " : "", - cbfrsynra); + + arm_smmu_parse_fsr(buf, fsr); + dev_err(smmu->dev, "FSR: %s\n", buf); + + arm_smmu_parse_fsynr0(buf, fsynr); + dev_err(smmu->dev, "FSYNR0: %s\n", buf); dev_err(smmu->dev, "soft iova-to-phys=%pa\n", &phys_soft); diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-smmu/arm-smmu.c index 87c81f75cf84..7f5ca75d5ebe 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c @@ -405,12 +405,67 @@ 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_parse_fsr(char buf[80], u32 fsr) +{ + static const struct { + u32 mask; + const char *name; + } fsr_bits[] = { + { ARM_SMMU_CB_FSR_MULTI, "MULTI" }, + { ARM_SMMU_CB_FSR_SS, "SS" }, + { ARM_SMMU_CB_FSR_UUT, "UUT" }, + { ARM_SMMU_CB_FSR_ASF, "ASF" }, + { ARM_SMMU_CB_FSR_TLBLKF, "TLBLKF" }, + { ARM_SMMU_CB_FSR_TLBMCF, "TLBMCF" }, + { ARM_SMMU_CB_FSR_EF, "EF" }, + { ARM_SMMU_CB_FSR_PF, "PF" }, + { ARM_SMMU_CB_FSR_AFF, "AFF" }, + { ARM_SMMU_CB_FSR_TF, "TF" }, + }; + char *p = buf; + + p += sprintf(p, "FORMAT=%u", + (u32)FIELD_GET(ARM_SMMU_CB_FSR_FORMAT, fsr)); + + for (int i = 0; i < ARRAY_SIZE(fsr_bits); i++) + if (fsr & fsr_bits[i].mask) + p += sprintf(p, "|%s", fsr_bits[i].name); +} + +void arm_smmu_parse_fsynr0(char buf[80], u32 fsynr) +{ + static const struct { + u32 mask; + const char *name; + } fsynr0_bits[] = { + { ARM_SMMU_CB_FSYNR0_WNR, "WNR" }, + { ARM_SMMU_CB_FSYNR0_PNU, "PNU" }, + { ARM_SMMU_CB_FSYNR0_IND, "IND" }, + { ARM_SMMU_CB_FSYNR0_NSATTR, "NSATTR" }, + { ARM_SMMU_CB_FSYNR0_PTWF, "PTWF" }, + { ARM_SMMU_CB_FSYNR0_AFR, "AFR" }, + }; + char *p = buf; + + p += sprintf(p, "S1CBNDX=%u", + (u32)FIELD_GET(ARM_SMMU_CB_FSYNR0_S1CBNDX, fsynr)); + + for (int i = 0; i < ARRAY_SIZE(fsynr0_bits); i++) + if (fsynr & fsynr0_bits[i].mask) + p += sprintf(p, "|%s", fsynr0_bits[i].name); + + p += sprintf(p, "|PLVL=%u", + (u32)FIELD_GET(ARM_SMMU_CB_FSYNR0_PLVL, fsynr)); +} + static irqreturn_t arm_smmu_context_fault(int irq, void *dev) { u32 fsr, fsynr, cbfrsynra; 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; @@ -423,13 +478,22 @@ static irqreturn_t arm_smmu_context_fault(int irq, void *dev) cbfrsynra = arm_smmu_gr1_read(smmu, ARM_SMMU_GR1_CBFRSYNRA(idx)); ret = report_iommu_fault(&smmu_domain->domain, NULL, iova, - fsynr & ARM_SMMU_FSYNR0_WNR ? IOMMU_FAULT_WRITE : IOMMU_FAULT_READ); + fsynr & ARM_SMMU_CB_FSYNR0_WNR ? IOMMU_FAULT_WRITE : IOMMU_FAULT_READ); + + if (ret == -ENOSYS && __ratelimit(&rs)) { + char buf[80]; - if (ret == -ENOSYS) - dev_err_ratelimited(smmu->dev, + dev_err(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); + arm_smmu_parse_fsr(buf, fsr); + dev_err(smmu->dev, "FSR: %s\n", buf); + + arm_smmu_parse_fsynr0(buf, fsynr); + dev_err(smmu->dev, "FSYNR0: %s\n", buf); + } + 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 4765c6945c34..763ea52fca64 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.h +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.h @@ -196,34 +196,46 @@ enum arm_smmu_cbar_type { #define ARM_SMMU_CB_PAR_F BIT(0) #define ARM_SMMU_CB_FSR 0x58 -#define ARM_SMMU_FSR_MULTI BIT(31) -#define ARM_SMMU_FSR_SS BIT(30) -#define ARM_SMMU_FSR_UUT BIT(8) -#define ARM_SMMU_FSR_ASF BIT(7) -#define ARM_SMMU_FSR_TLBLKF BIT(6) -#define ARM_SMMU_FSR_TLBMCF BIT(5) -#define ARM_SMMU_FSR_EF BIT(4) -#define ARM_SMMU_FSR_PF BIT(3) -#define ARM_SMMU_FSR_AFF BIT(2) -#define ARM_SMMU_FSR_TF BIT(1) - -#define ARM_SMMU_FSR_IGN (ARM_SMMU_FSR_AFF | \ - ARM_SMMU_FSR_ASF | \ - ARM_SMMU_FSR_TLBMCF | \ - ARM_SMMU_FSR_TLBLKF) - -#define ARM_SMMU_FSR_FAULT (ARM_SMMU_FSR_MULTI | \ - ARM_SMMU_FSR_SS | \ - ARM_SMMU_FSR_UUT | \ - ARM_SMMU_FSR_EF | \ - ARM_SMMU_FSR_PF | \ - ARM_SMMU_FSR_TF | \ +#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) +#define ARM_SMMU_CB_FSR_TLBMCF BIT(5) +#define ARM_SMMU_CB_FSR_EF BIT(4) +#define ARM_SMMU_CB_FSR_PF BIT(3) +#define ARM_SMMU_CB_FSR_AFF BIT(2) +#define ARM_SMMU_CB_FSR_TF BIT(1) + +void arm_smmu_parse_fsr(char buf[80], u32 fsr); + +#define ARM_SMMU_FSR_IGN (ARM_SMMU_CB_FSR_AFF | \ + ARM_SMMU_CB_FSR_ASF | \ + ARM_SMMU_CB_FSR_TLBMCF | \ + ARM_SMMU_CB_FSR_TLBLKF) + +#define ARM_SMMU_FSR_FAULT (ARM_SMMU_CB_FSR_MULTI | \ + ARM_SMMU_CB_FSR_SS | \ + ARM_SMMU_CB_FSR_UUT | \ + ARM_SMMU_CB_FSR_EF | \ + ARM_SMMU_CB_FSR_PF | \ + ARM_SMMU_CB_FSR_TF | \ ARM_SMMU_FSR_IGN) #define ARM_SMMU_CB_FAR 0x60 #define ARM_SMMU_CB_FSYNR0 0x68 -#define ARM_SMMU_FSYNR0_WNR BIT(4) +#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) + +void arm_smmu_parse_fsynr0(char buf[80], u32 fsynr); #define ARM_SMMU_CB_FSYNR1 0x6c