From patchwork Tue Nov 15 10:11:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AngeloGioacchino Del Regno X-Patchwork-Id: 20284 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2626681wru; Tue, 15 Nov 2022 02:12:51 -0800 (PST) X-Google-Smtp-Source: AA0mqf4NtbTB6wNXFpT5JM12vWD0ShXfk38ZkNyA1UDMMKcsuRin0c6C74Hi1RUpQiWwy7w7fZQR X-Received: by 2002:a17:907:962a:b0:7ae:39b4:7208 with SMTP id gb42-20020a170907962a00b007ae39b47208mr13177923ejc.766.1668507171331; Tue, 15 Nov 2022 02:12:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668507171; cv=none; d=google.com; s=arc-20160816; b=Rxqt0il/729TW046iUdqvszaBQUjOsq33s6GGWLN8TnaBeHjssGc5PlAAe8PrJS2Y5 G5TVKkAQcCdX8CeipXXhVSH3bSMFivW7YToFL9mctXWOcoqMA3H2Va5ibdI1ON2OJxOv i5RDJFW14B/DIZu5lcKpZnGCmznK1DBr0ep47AaNmGa7lPqig+QPdDUG/xtbQZFJL+2X RWQ3fC3TsnOd/cM0K7+VYf8rIwHRazjJecU+Ig4ZECWBeUGMlwtpv+TSIU8pxObgdYT/ zurNH6sUpsZ2NvCmAC2l/LdoSj8UhS8SxRafTIGvKnjcYxd1enpAod1cp/gm/qiq+kd+ aVog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BVydm18JEnXeiIzGhYMUwcTaqbenVEG4bSWLJV40ssg=; b=ucSnRfWLhPkgJ94NcrTDPLtWswxdm8bYgaJyh6B6f+pOnuXtoFHyL0vRMV5vblKmW/ A2HOfXdsf3ilNkdOvN7VJvzZ3oYnYlo0FZdYZDT/Q3JlTDn0ZSrM6QCFzMrfMGXv83ZQ rBMmU8J1NrwALjVxJIIhNrPfZzltEULXNnlqCLn/8oTC/gElJwNlG078JlrKagftcg4m PIv2uyOp3kZGIx+WfRgyCQaB6frMko8cvHZQc8b1LX1iT+Cy4A2YeEbCZA0sXjfFvnG3 zUrEPzMdtLMz8pnmXWKUTENdbQV156uuQogpOLTONxAAwvcLu0TuY0fsH+3m3USqWLn2 Ei0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=lY8ogjAK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id go38-20020a1709070da600b007ae4f8de35esi11544041ejc.860.2022.11.15.02.12.28; Tue, 15 Nov 2022 02:12:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=lY8ogjAK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238303AbiKOKLr (ORCPT + 99 others); Tue, 15 Nov 2022 05:11:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238275AbiKOKLi (ORCPT ); Tue, 15 Nov 2022 05:11:38 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 263E66416; Tue, 15 Nov 2022 02:11:38 -0800 (PST) Received: from IcarusMOD.eternityproject.eu (2-237-20-237.ip236.fastwebnet.it [2.237.20.237]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by madras.collabora.co.uk (Postfix) with ESMTPSA id D87C86602A13; Tue, 15 Nov 2022 10:11:35 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1668507096; bh=ZyyLPRrFzO2HVcobnI5VF8p7tvZDI9hyhowu+PLNJZE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lY8ogjAKhbMXwE1IRAzHKjBnY6w+MXTSWwTVh7rjLMewR2tg23pI25YQ6EInVA82+ mEgYyxW00ERGsqOPEzkNLDSmYro9H/F0/eFgbu+ofAWEy16MZEGhkMfy+KhAQ5pTDf tteDH5fQPAJEctL8pYfjdLrcOG/TS7V2YcAIzLLKFBsUTHCG/IBUr1MIiTuXP5dW/7 5MNZ7kvym5HwE7ttGh9JLHXdZHBLtRJPKV6fk20tBy73OFuqLseyrdJ4E6wUvLJIUi B21SXMdK1vnptUIUpcbcUiH8geGGEv8frgMRSC0VV3XbrvayK6SRdlOjH6vaTDSWoU 79cRZ3ZwXs3RA== From: AngeloGioacchino Del Regno To: agross@kernel.org Cc: andersson@kernel.org, konrad.dybcio@linaro.org, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, robdclark@gmail.com, linux-arm-msm@vger.kernel.org, iommu@lists.linux.dev, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, marijn.suijten@somainline.org, kernel@collabora.com, luca@z3ntu.xyz, a39.skl@gmail.com, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, AngeloGioacchino Del Regno Subject: [PATCH v3 3/6] iommu/qcom: Properly reset the IOMMU context Date: Tue, 15 Nov 2022 11:11:19 +0100 Message-Id: <20221115101122.155440-4-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221115101122.155440-1-angelogioacchino.delregno@collabora.com> References: <20221115101122.155440-1-angelogioacchino.delregno@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749556575411727766?= X-GMAIL-MSGID: =?utf-8?q?1749556575411727766?= Avoid context faults by resetting the context(s) entirely at detach_dev() time and also do the same before programming the context for domain initialization. Signed-off-by: Marijn Suijten [Marijn: Rebased over next-20221111] Signed-off-by: AngeloGioacchino Del Regno --- drivers/iommu/arm/arm-smmu/qcom_iommu.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c index 491a8093f3d6..49f4308f1bd2 100644 --- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c +++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c @@ -223,6 +223,20 @@ static irqreturn_t qcom_iommu_fault(int irq, void *dev) return IRQ_HANDLED; } +static void qcom_iommu_reset_ctx(struct qcom_iommu_ctx *ctx) +{ + iommu_writel(ctx, ARM_SMMU_CB_FAR, 0); + iommu_writel(ctx, ARM_SMMU_CB_FSR, ARM_SMMU_FSR_FAULT); + iommu_writel(ctx, ARM_SMMU_CB_S1_MAIR1, 0); + iommu_writel(ctx, ARM_SMMU_CB_PAR, 0); + iommu_writel(ctx, ARM_SMMU_CB_S1_MAIR0, 0); + iommu_writel(ctx, ARM_SMMU_CB_SCTLR, 0); + iommu_writel(ctx, ARM_SMMU_CB_TCR2, 0); + iommu_writel(ctx, ARM_SMMU_CB_TCR, 0); + iommu_writeq(ctx, ARM_SMMU_CB_TTBR0, 0); + iommu_writeq(ctx, ARM_SMMU_CB_TTBR1, 0); +} + static int qcom_iommu_init_domain(struct iommu_domain *domain, struct qcom_iommu_dev *qcom_iommu, struct device *dev) @@ -273,6 +287,8 @@ static int qcom_iommu_init_domain(struct iommu_domain *domain, ctx->secure_init = true; } + qcom_iommu_reset_ctx(ctx); + /* TTBRs */ iommu_writeq(ctx, ARM_SMMU_CB_TTBR0, pgtbl_cfg.arm_lpae_s1_cfg.ttbr | @@ -401,8 +417,8 @@ static void qcom_iommu_detach_dev(struct iommu_domain *domain, struct device *de for (i = 0; i < fwspec->num_ids; i++) { struct qcom_iommu_ctx *ctx = to_ctx(qcom_domain, fwspec->ids[i]); - /* Disable the context bank: */ - iommu_writel(ctx, ARM_SMMU_CB_SCTLR, 0); + /* Disable and reset the context bank */ + qcom_iommu_reset_ctx(ctx); ctx->domain = NULL; }