Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3358493pxb; Mon, 25 Jan 2021 13:55:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJxeYrUuqnfNH9TB0vXIIZu4vBSg2y8UGj8dbZW+cWKytUEPKqm9eS8CFLGbNZD4VknjUObv X-Received: by 2002:aa7:cb8a:: with SMTP id r10mr2181685edt.152.1611611754476; Mon, 25 Jan 2021 13:55:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611611754; cv=none; d=google.com; s=arc-20160816; b=lP3TP29oCuwGtUMrLnHO39qnw29c1SOJhBxm/PDzYMg6QN4ovzp0yIrQdqtbJCA7EB /GinHypdkRRKcFgwp3tFgXv/IV0neLqWL9PyCZCPuN2eT9dXsg84cuL1Lsi6NPK8Beuf WVnmiTQTcoZgefK2CQNjWl1WiP1Bn8hL6yZD/bXXyhC4e1xts1hNxecwW+AxGRIMWIft hU/g9+DsTZIlOyWTBONc7G5Ug7g0I/PMPuMRJIIbXddtGEpk778UkQ8uTJqd3mZflVLr qS1hswRuz85sxtIr0zOGzAywhEcMR7+3aqmaw0hAsPFA3Y2UgQgukP0nGxCaHD+2lcl4 6Mng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from:dmarc-filter :sender:dkim-signature; bh=wjOwZ7hnkSut6Udf2hJQbonOlbKoFsbqZco5e9Oswzk=; b=JpSOPcBKNbqv9rTtPSZECgQ5/msVIlVzDobv48E/TI78f6PB+wKYv3Ol6KdDQLme3P iCQ/w4F0TkIyZ2005l+pnV4bO72vm7WmgrgjTr7K+W+Ctzt+nYbwOoD6t7f0uxbZwbbd 0rLqfP6YhkfH8HnTVBnaYXN/ouIx5kExLRL1bP44FGGDyGjQlBjehwryxx4G+IS6NXvA UbRfPXwnZzsV9jcV/GWB0zIpx+OiN1vu7tyS4i8HSpbEon2cUAyseGfRomv+amaRnjSU 2C6fcbHR0kbNpht4A4N3FmQK++Dlm0evv4tsuW2FuvlHuNGZJ/Mej6upSEEIFpXH9bxM 4vfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=fR2qsfRV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t15si5907654ejj.506.2021.01.25.13.55.30; Mon, 25 Jan 2021 13:55:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=fR2qsfRV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732472AbhAYVyN (ORCPT + 99 others); Mon, 25 Jan 2021 16:54:13 -0500 Received: from m42-8.mailgun.net ([69.72.42.8]:31783 "EHLO m42-8.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733092AbhAYVxc (ORCPT ); Mon, 25 Jan 2021 16:53:32 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1611611590; h=Message-Id: Date: Subject: Cc: To: From: Sender; bh=wjOwZ7hnkSut6Udf2hJQbonOlbKoFsbqZco5e9Oswzk=; b=fR2qsfRVUa1S9421tOeLI3rJqmaFSqDDRk06xBrDqbp4tQYjJCohacD7BfhiirWt8GNmaLFI iSw5ZF5hCLwoqXrzyiOcbLKosC/ogI+V1/NetCaIkj5BDV4KJZNUSNt4MuMBhMf4N7aZxcjn 2qQkmUUsvnPTnlzgjGvtalXVAZg= X-Mailgun-Sending-Ip: 69.72.42.8 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n07.prod.us-east-1.postgun.com with SMTP id 600f3da02c36b2106dd15036 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Mon, 25 Jan 2021 21:52:32 GMT Sender: isaacm=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id D2380C433C6; Mon, 25 Jan 2021 21:52:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=ALL_TRUSTED,BAYES_00,SPF_FAIL, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from isaacm-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: isaacm) by smtp.codeaurora.org (Postfix) with ESMTPSA id EB1D3C433CA; Mon, 25 Jan 2021 21:52:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org EB1D3C433CA Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=fail smtp.mailfrom=isaacm@codeaurora.org From: "Isaac J. Manjarres" To: will@kernel.org, robin.murphy@arm.com, joro@8bytes.org, bjorn.andersson@linaro.org Cc: "Isaac J. Manjarres" , linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH] iommu/arm-smmu-qcom: Fix mask extraction for bootloader programmed SMRs Date: Mon, 25 Jan 2021 13:52:25 -0800 Message-Id: <1611611545-19055-1-git-send-email-isaacm@codeaurora.org> X-Mailer: git-send-email 2.7.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When extracting the mask for a SMR that was programmed by the bootloader, the SMR's valid bit is also extracted and is treated as part of the mask, which is not correct. Consider the scenario where an SMMU master whose context is determined by a bootloader programmed SMR is removed (omitting parts of device/driver core): ->iommu_release_device() -> arm_smmu_release_device() -> arm_smmu_master_free_smes() -> arm_smmu_free_sme() /* Assume that the SME is now free */ -> arm_smmu_write_sme() -> arm_smmu_write_smr() /* Construct SMR value using mask and SID */ Since the valid bit was considered as part of the mask, the SMR will be programmed as valid. Fix the SMR mask extraction step for bootloader programmed SMRs by masking out the valid bit when we know that we're already working with a valid SMR. Fixes: 07a7f2caaa5a ("iommu/arm-smmu-qcom: Read back stream mappings") Signed-off-by: Isaac J. Manjarres Cc: stable@vger.kernel.org --- drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c index bcda170..abb1d2f 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c @@ -206,6 +206,8 @@ static int qcom_smmu_cfg_probe(struct arm_smmu_device *smmu) smr = arm_smmu_gr0_read(smmu, ARM_SMMU_GR0_SMR(i)); if (FIELD_GET(ARM_SMMU_SMR_VALID, smr)) { + /* Ignore valid bit for SMR mask extraction. */ + smr &= ~ARM_SMMU_SMR_VALID; smmu->smrs[i].id = FIELD_GET(ARM_SMMU_SMR_ID, smr); smmu->smrs[i].mask = FIELD_GET(ARM_SMMU_SMR_MASK, smr); smmu->smrs[i].valid = true; -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project