Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp5811190rwb; Tue, 1 Aug 2023 08:12:48 -0700 (PDT) X-Google-Smtp-Source: APBJJlHq8q0J7I/L29+pim66BHZqEEQdH2UJpWPj8UwyEICkw76KZyDCUcpO58rDS5HouRab3j9Y X-Received: by 2002:a17:902:b58b:b0:1b6:a99b:ceb1 with SMTP id a11-20020a170902b58b00b001b6a99bceb1mr10833009pls.50.1690902768550; Tue, 01 Aug 2023 08:12:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690902768; cv=none; d=google.com; s=arc-20160816; b=nPe6bpiiPvAltRCDNCVVoFskC53zPc1YatHvBRGKC0V4WITC9fj3Yvdtrj5uu0OZEb Nvud2KDy9Y9oDe7Y6/5bwEBpZU4QQBwrJteNu5ZBRLIEh8FgJMtps8gEbJvJM2p3sN8F i8wBErIWPbOmPv5n856jJy94AHwzkOmMfmqBBJFTyD6eaCKnuoy+IaPFE0A5x+fI0FsS 1PLMLbn2rTn/7ZzPZQmc6ie0sIZLpNWv9/gcvhg7PUfV5kGjcKO38C6Xs+PFsV8g+LU3 lJrJiCqGR0cH4caUan60yp82eV6pecJ+9nkX2D8LF1uLutjSKgVfMMLGDjdYNGmogog5 UkZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=7cokidr9vFx17ZKGgzlyAwX+onf4Lm9u9O/bTIh2Qd4=; fh=efF0n8wJ+ZfzJBh1vsMJyOpEJ6IYNxAgcm6Bx7Bg6uw=; b=dEpZGJq7ffFSOvMnf1Pt/c2TzTsgBrLX3YPMNfXvEmgt3Q3HzX/Yzoj2wtFbtFAm5N 5ygQ9NxCW1DdfDlgylV0CiXJyRXJPiLHkFeeGfdUSnn2WjLM3bjRK532m+3+0QBPLP5A AKXzbCJiz4aR53FRWXxNqQTHdcso6SOS0KS6vklgbmTBloWm7l+aof/nQNfYXQNRiQCh kY8n2pmEPp87z0R76v3TerePmUAoHXiaYQeYTUgnUTzjnVIgoLXX53agCr/w2O+yhSfS hkjpKfbxHBCv8KK5fljXLr3YStwIe/e/+HwiDS2a4ILsEOlET/r5x1xh3iycUjlxwynK scDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=eoHmMrCk; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k17-20020a170902c41100b001bb1a270d1asi9817241plk.276.2023.08.01.08.12.28; Tue, 01 Aug 2023 08:12:48 -0700 (PDT) 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=eoHmMrCk; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234444AbjHAOCp (ORCPT + 99 others); Tue, 1 Aug 2023 10:02:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232064AbjHAOCj (ORCPT ); Tue, 1 Aug 2023 10:02:39 -0400 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 20C44E5F; Tue, 1 Aug 2023 07:02:27 -0700 (PDT) Received: from [192.168.1.100] (2-237-20-237.ip236.fastwebnet.it [2.237.20.237]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 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 8D28F6607187; Tue, 1 Aug 2023 15:02:24 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1690898545; bh=O+sOqle7nRll28/FmxMTrTj8mlyOiIx2mIEKBCwzSGA=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=eoHmMrCkU2nYDXoxwl6GPyQUilti2nJ82i/ts2XxDBgQyKb4hPNwDuIUyLUSiSc8z R0A5XpQtIjU1Qxnm7npVqJ0L60HTMNovgl/DNSe7hLGBeKMbt4gi1Wn78S2rTaMFk2 /IycX6R5OfRR2F3ujH3Oi8fKrwtmvWTwbRD9P9BpbauTpIooMAXxcAlSujIK86w57X Ev/wQhrEPZYpwj1ohQlPVqzYHuQzmdef1CXDJGBnI4Q7U2OQA8eR53u3v5eHV7jR+P /fGTEAhrG1+RgBECZ+Zd7hAloPlBzsoPuxwRXoE8ouT1h7DXIAmVjW0ox3q3Yuvi4j oVssdzhph1nKQ== Message-ID: <9ae6616c-7799-8b0c-eff5-1a30d467fbda@collabora.com> Date: Tue, 1 Aug 2023 16:02:21 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH v5 2/6] iommu/qcom: Use the asid read from device-tree if specified Content-Language: en-US To: Will Deacon Cc: agross@kernel.org, andersson@kernel.org, luca@z3ntu.xyz, konrad.dybcio@linaro.org, dmitry.baryshkov@linaro.org, joro@8bytes.org, robin.murphy@arm.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.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, kernel@collabora.com, Marijn Suijten References: <20230622092742.74819-1-angelogioacchino.delregno@collabora.com> <20230622092742.74819-3-angelogioacchino.delregno@collabora.com> <20230801134953.GA26253@willie-the-truck> From: AngeloGioacchino Del Regno In-Reply-To: <20230801134953.GA26253@willie-the-truck> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 Il 01/08/23 15:49, Will Deacon ha scritto: > On Thu, Jun 22, 2023 at 11:27:38AM +0200, AngeloGioacchino Del Regno wrote: >> As specified in this driver, the context banks are 0x1000 apart but >> on some SoCs the context number does not necessarily match this >> logic, hence we end up using the wrong ASID: keeping in mind that >> this IOMMU implementation relies heavily on SCM (TZ) calls, it is >> mandatory that we communicate the right context number. >> >> Since this is all about how context banks are mapped in firmware, >> which may be board dependent (as a different firmware version may >> eventually change the expected context bank numbers), introduce a >> new property "qcom,ctx-asid": when found, the ASID will be forced >> as read from the devicetree. >> >> When "qcom,ctx-asid" is not found, this driver retains the previous >> behavior as to avoid breaking older devicetrees or systems that do >> not require forcing ASID numbers. >> >> Signed-off-by: Marijn Suijten >> [Marijn: Rebased over next-20221111] >> Signed-off-by: AngeloGioacchino Del Regno >> --- >> drivers/iommu/arm/arm-smmu/qcom_iommu.c | 18 +++++++++++++++--- >> 1 file changed, 15 insertions(+), 3 deletions(-) >> >> diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c >> index a503ed758ec3..8face57c4180 100644 >> --- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c >> +++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c >> @@ -531,7 +531,8 @@ static int qcom_iommu_of_xlate(struct device *dev, struct of_phandle_args *args) >> * index into qcom_iommu->ctxs: >> */ >> if (WARN_ON(asid < 1) || >> - WARN_ON(asid > qcom_iommu->num_ctxs)) { >> + WARN_ON(asid > qcom_iommu->num_ctxs) || >> + WARN_ON(qcom_iommu->ctxs[asid - 1] == NULL)) { >> put_device(&iommu_pdev->dev); >> return -EINVAL; >> } >> @@ -617,7 +618,8 @@ static int qcom_iommu_sec_ptbl_init(struct device *dev) >> >> static int get_asid(const struct device_node *np) >> { >> - u32 reg; >> + u32 reg, val; >> + int asid; >> >> /* read the "reg" property directly to get the relative address >> * of the context bank, and calculate the asid from that: >> @@ -625,7 +627,17 @@ static int get_asid(const struct device_node *np) >> if (of_property_read_u32_index(np, "reg", 0, ®)) >> return -ENODEV; >> >> - return reg / 0x1000; /* context banks are 0x1000 apart */ >> + /* >> + * Context banks are 0x1000 apart but, in some cases, the ASID >> + * number doesn't match to this logic and needs to be passed >> + * from the DT configuration explicitly. >> + */ >> + if (!of_property_read_u32(np, "qcom,ctx-asid", &val)) >> + asid = val; >> + else >> + asid = reg / 0x1000; >> + >> + return asid; > > Shouldn't we at least have some error checking here? For example, ensuring > that the ASIDs are within range, aren't duplicates etc? > The only check that we can perform here for ASID-in-range is if ((asid * 0x1000 > (mmio_start + mmio_size - 0x1000)) return -EINVAL; ...as for duplicates, a check can *probably* (surely) be done... but I'm not sure I have any more time to feed more code to this series from years ago... > Also, can you elaborate a little more on what sort of ASID-to-Context > mappings you actually see in practice? > I'm sorry, but not really. The first version of this (including the whole research that I had to perform to write those patches) is from year 2019, so 4 years ago... ...I don't really remember the full details anymore - if not that all of this was done because context banks are fixed (and setup by TZ), tz takes an asid number when trying to perform any operation on the context bank, and there's no way to reset mappings because everything is protected by the hypervisor (which will fault and reboot the AP instantly if you try). Cheers, Angelo