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 DD660C636D4 for ; Wed, 15 Feb 2023 13:08:38 +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:In-Reply-To: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=/Vk0xYqf6Woun+447d+Fb1blkK22VtawJuLKinOC/p0=; b=4OMt2Q6Q5o764v lbLBODGm0UbYIgdJQmZiFwPTWXnunycvPtW5r1FyuIh+v1dKnojvHKDWoTB6FFuEiwG3zGHEH+HPr 4iMWWzv6f07WAImeeUAwYHz1Y/38TtSTIbymqwjFW4vRF93kGCnGdulsoaFlGGxzDHXZAsqJC7geJ iT3B0VT6mBZAUQAsl9qIlmd156VEmEacSP7KZIsN+JIQMyPW2NS6pnu8EtlvrvuSS7YQKUl/N9xan odHvg+sl6KnPCsw5IGyQ8o2vw2X0WSi73D4ftizdoK2nmPRDZ2wZI8QGpJ1V510RBVNzEAwq8WE59 3AzLmtVUZZ9oFyc8368Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pSHVW-005v10-9s; Wed, 15 Feb 2023 13:07:34 +0000 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pSHVS-005uyo-Fc for linux-arm-kernel@lists.infradead.org; Wed, 15 Feb 2023 13:07:32 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 02A8CCE24A2; Wed, 15 Feb 2023 13:07:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 25876C433EF; Wed, 15 Feb 2023 13:07:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676466443; bh=+hwO7JErfYD4tISTCHkKL1+A6053koS9PX7XC0ujeYE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=a3EhsgsZn0VTwpxr63gGNBnxf8CoaEmcUge3otJJ6MWz5zRz+LI3pc69Zbrxcg+te eo6dq34XdS7Ni/ySYttdumSi0fK2VlgBMm0pBqEBaVpbemjguqBpQ2UlWDhZFERr0z Syi5Kp2osRKtcJSwWEhS8UJTpzD1HJsrvzCrWL01Qd1cG7nW3y0iIXbgk5lVJcTrAN dqKgmn05rtTpvkjr6CZFFi77NSiSO3grK/dI0vP30bIJoyIejtmlfafTBwkAYBA8VA 5RlcF//1vvYgHZeHMGq7vWy7G0G7WvXd9HDblUY/U8MA7tH076/wQ68GKvpSWTwkTq 5unmPNdr8X9AQ== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1pSHWF-0002Ri-Q4; Wed, 15 Feb 2023 14:08:19 +0100 Date: Wed, 15 Feb 2023 14:08:19 +0100 From: Johan Hovold To: Manivannan Sadhasivam Cc: will@kernel.org, joro@8bytes.org, robin.murphy@arm.com, andersson@kernel.org, johan+linaro@kernel.org, steev@kali.org, linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH] iommu/arm-smmu-qcom: Rework the logic finding the bypass quirk Message-ID: References: <20230201082500.61656-1-manivannan.sadhasivam@linaro.org> <20230214075312.GB4981@thinkpad> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230215_050730_984529_6FC3A325 X-CRM114-Status: GOOD ( 50.18 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Feb 14, 2023 at 10:07:36AM +0100, Johan Hovold wrote: > On Tue, Feb 14, 2023 at 01:23:12PM +0530, Manivannan Sadhasivam wrote: > > On Mon, Feb 13, 2023 at 05:43:56PM +0100, Johan Hovold wrote: > > > On Wed, Feb 01, 2023 at 01:55:00PM +0530, Manivannan Sadhasivam wrote: > > > > The logic used to find the quirky firmware that intercepts the writes to > > > > S2CR register to replace bypass type streams with a fault, and ignore the > > > > fault type, is not working with the firmware on newer SoCs like SC8280XP. > > > > > > > > The current logic uses the last stream mapping group (num_mapping_groups > > > > - 1) as an index for finding quirky firmware. But on SC8280XP, this > > > > logic is not working as the number of stream mapping groups reported by > > > > the SMMU (163 as on the SC8280XP-CRD device) is not valid for some reason. > > > > > > NUMSMRG read back as 162 here, both on my CRD and X13s. Was '163' a typo > > > or a real difference? > > > > > > > Ah yes, it is 162 indeed. Sorry, typo! > > > > > > So the current logic that checks the (163-1) S2CR entry fails to detect > > > > the quirky firmware on these devices and triggers invalid context fault > > > > for bypass streams. > > > > > > > > To fix this issue, rework the logic to find the first non-valid (free) > > > > stream mapping register group (SMR) and use that index to access S2CR > > > > for detecting the bypass quirk. > > > > > > So while this works for the quirk detection, shouldn't we also do > > > something about that bogus NUMSMRG value? At least cap it at 128, which > > > appears to be the maximum according to the specification, for example, > > > by clearing bit 7 when any of the lower bits are set? > > > > > > That would give us 35 (or 36) groups and working quirk detection with > > > just the following smaller patch: > > > > > > > I'm not certain if the value is bogus or not. It is clear that the spec > > specifies 128 as the max but internal qcom document shows that they indeed > > set 162 on purpose in the hypervisor. > > > > So until we get a clear view on that, I'd not cap it. > > But if we fault as soon as we try to do something with those register > groups above 128 that also violate the spec, it doesn't seem right to > trust the fw value here. I realised that the fault is due to the quirk not being detected properly as writes to groups above index 127 apparently succeeds (including out-of-bounds index 162): qcom_smmu_cfg_probe - index = 127, reg = 200ff, type = 02 qcom_smmu_cfg_probe - index = 128, reg = 100ff, type = 01 qcom_smmu_cfg_probe - index = 161, reg = 100ff, type = 01 qcom_smmu_cfg_probe - index = 162, reg = 100ff, type = 01 So leaving smmu->num_mapping_groups unchanged for now and using the first available group for the detection indeed seems like the right thing to do here (alternatively, never use an index above 127). But perhaps you can update to commit message to reflect this finding (i.e. that the num groups value is probably bogus, and that you at least need to use an index < 128 for quirk detection). By the way, I noticed that the number of groups is reported as 162 on the sa8295p-adp as well. > > > > This also warrants a change in variable name from last_s2cr to free_s2cr. > > > > > > > > Signed-off-by: Manivannan Sadhasivam > > > > --- > > > > drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c | 24 +++++++++++++++++----- > > > > 1 file changed, 19 insertions(+), 5 deletions(-) > > > > > > > > diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c > > > > index 78fc0e1bf215..4104f81b8d8f 100644 > > > > --- a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c > > > > +++ b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c > > > > @@ -267,23 +267,37 @@ static int qcom_smmu_init_context(struct arm_smmu_domain *smmu_domain, > > > > > > > > static int qcom_smmu_cfg_probe(struct arm_smmu_device *smmu) > > > > { > > > > - unsigned int last_s2cr = ARM_SMMU_GR0_S2CR(smmu->num_mapping_groups - 1); > > > > struct qcom_smmu *qsmmu = to_qcom_smmu(smmu); > > > > + u32 free_s2cr; > > > > u32 reg; > > > > u32 smr; > > > > int i; > > > > > > > > + /* > > > > + * Find the first non-valid (free) stream mapping register group and > > > > + * use that index to access S2CR for detecting the bypass quirk. > > > > + */ > > > > + for (i = 0; i < smmu->num_mapping_groups; i++) { > > > > + smr = arm_smmu_gr0_read(smmu, ARM_SMMU_GR0_SMR(i)); > > > > + > > > > + if (!FIELD_GET(ARM_SMMU_SMR_VALID, smr)) > > > > + break; > > > > + } > > > > + > > > > + free_s2cr = ARM_SMMU_GR0_S2CR(i); > > > > > > In the unlikely event that there is no free group this would access an > > > invalid index. > > > > > > > Hmm, theoretically yes. But what would be the plan of action if that happens? > > Should we just bail out with error or skip the quirk detection? > > Yes, skipping quirk detection seems preferable to crashing systems that > don't need the quirk. Perhaps you can move the quirk handling to its own function and simply return early in case there is no free group. Johan _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel