From patchwork Wed Feb 1 12:53:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 13124399 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 55ECDC636CD for ; Wed, 1 Feb 2023 14:17:05 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=uKrU2W7tXzmHXaZSQtBL4B26PcdS7Dp7M51t+BcXbHU=; b=QeaDS/VRFEq+/5 3tGTq/UF9exvy5STL5vcDjh6HSaNkQDXVqAxaep30cOY/aLHfhTSB7LGgwEy9JnGEne5OcR6bc2M0 29nTNxQ6XyLOjCzmmmo6FRU7B3GeJ4VvkMqOk/DCX4xQ9t3Tm5/vY+jRH5HYFsVDXnQvF9XEe0K6+ LzgCfzYghCiaAn8GcC4g/EFv6GLHT/JVEbj3wiUGOlxt3daDW5ShZ82ys9WcNCsJcF0aWvv3f7Aed LGmHxgZyF8anQBDKhtiZUscpjPesB0D95x9ma1Ju8fTe8KcOC5qS96XlF3SwXk/KLVqFDCwtSHkwT FPK9pprZwh9Ha7Ys6HuA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNDu9-00CH6L-5m; Wed, 01 Feb 2023 14:16:06 +0000 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNCiK-00BnFc-BJ for linux-arm-kernel@lists.infradead.org; Wed, 01 Feb 2023 12:59:49 +0000 Received: by mail-wr1-x42c.google.com with SMTP id q10so17233701wrm.4 for ; Wed, 01 Feb 2023 04:59:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=T1XbjFRROGqTsKVaKlJ9OMpS1XHI6QRbg+Uxdf993wI=; b=vGASOMbylysHRfrGLv6YhTO7WEjv6c1RwzKjV7XsdcywE+jEFIsdsb5w+2OghxLS9/ qXlv60FR7L4TDsiNTkGc7CFP9sOBBSMgFZJP6RehQWKk+xblpDCkv+NdoiRZJc4lo+MB OHZI/Ska0NQGQp6sf6XYaGIC4f/Sqp2c09J4jQvzaOnijt2sBekilaucOj/jUKSNd/AX 5pRusIs+/gQ0kDODgdeueanv2yN6KNe+s7ycRNU9ypbQUkV21yxob/1nlBgVHMhIfud/ OgRirqcvdAhkcPaU2A0Q77RWKieLbANDuuIfIpzi/IVRF8f+n9FVapUusjVNOE82ZS44 c4Sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=T1XbjFRROGqTsKVaKlJ9OMpS1XHI6QRbg+Uxdf993wI=; b=M1Dv+4mffRgkLcWqSG5DgcOCkrylR6/sucYAGyZi/6zIGmt3SXJOF6gKC3tbGjhfNQ EzgoHZckE085GaCwuMRR/SZI8+Svifsq6cgMR608TediqQjHpg/xnRZmfukkjC15NmIW idPw5dVBHlqFhbfruXmzShm+N+BppdbzzfCF1aJ8Aq0xHKTwrgLVrwWKHHknitLU7VJ4 WTQYH7K6vNufV6UB0i8xx14YKc/fIO1eog0FBLZGrQACbiS37QREjbhSGK33FDC0yj5u L5gvJ9d6LACWMjtfT/Mmbkc3v2/7E5maEo4OTidM5/b7dJSsS5K827Szs6JnRQ9TVvl4 /ufQ== X-Gm-Message-State: AO0yUKXi8y5atG5Pmoz0nKSMXHsMG3a874Y05wBvq96r53U0Vfrl4mrP TnDzGXZiMHNA6mTVSo5oPCpfFA== X-Google-Smtp-Source: AK7set/A9Wvge/x9I0c0N1VcVRmzSfGiz2QGPnhn/EemCOX5Ccigvrx/7k9pg7r6kMkCHM3qkXEWvg== X-Received: by 2002:a5d:6b48:0:b0:2bf:963a:f266 with SMTP id x8-20020a5d6b48000000b002bf963af266mr1586152wrw.27.1675256387822; Wed, 01 Feb 2023 04:59:47 -0800 (PST) Received: from localhost.localdomain (054592b0.skybroadband.com. [5.69.146.176]) by smtp.gmail.com with ESMTPSA id m15-20020a056000024f00b002bfae16ee2fsm17972811wrz.111.2023.02.01.04.59.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 04:59:47 -0800 (PST) From: Jean-Philippe Brucker To: maz@kernel.org, catalin.marinas@arm.com, will@kernel.org, joro@8bytes.org Cc: robin.murphy@arm.com, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, smostafa@google.com, dbrazdil@google.com, ryan.roberts@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, iommu@lists.linux.dev, Jean-Philippe Brucker Subject: [RFC PATCH 36/45] iommu/arm-smmu-v3-kvm: Validate device features Date: Wed, 1 Feb 2023 12:53:20 +0000 Message-Id: <20230201125328.2186498-37-jean-philippe@linaro.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230201125328.2186498-1-jean-philippe@linaro.org> References: <20230201125328.2186498-1-jean-philippe@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230201_045948_414485_3322CDCC X-CRM114-Status: GOOD ( 14.04 ) 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 The KVM hypervisor driver supports a small subset of features. Ensure the implementation is compatible, and disable some unused features. Signed-off-by: Jean-Philippe Brucker --- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-kvm.c | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-kvm.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-kvm.c index 1e0daf9ea4ac..2cc632f6b256 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-kvm.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-kvm.c @@ -23,6 +23,59 @@ static size_t kvm_arm_smmu_cur; static size_t kvm_arm_smmu_count; static struct hyp_arm_smmu_v3_device *kvm_arm_smmu_array; +static bool kvm_arm_smmu_validate_features(struct arm_smmu_device *smmu) +{ + unsigned long oas; + unsigned int required_features = + ARM_SMMU_FEAT_TRANS_S2 | + ARM_SMMU_FEAT_TT_LE; + unsigned int forbidden_features = + ARM_SMMU_FEAT_STALL_FORCE; + unsigned int keep_features = + ARM_SMMU_FEAT_2_LVL_STRTAB | + ARM_SMMU_FEAT_2_LVL_CDTAB | + ARM_SMMU_FEAT_TT_LE | + ARM_SMMU_FEAT_SEV | + ARM_SMMU_FEAT_COHERENCY | + ARM_SMMU_FEAT_TRANS_S1 | + ARM_SMMU_FEAT_TRANS_S2 | + ARM_SMMU_FEAT_VAX | + ARM_SMMU_FEAT_RANGE_INV; + + if (smmu->options & ARM_SMMU_OPT_PAGE0_REGS_ONLY) { + dev_err(smmu->dev, "unsupported layout\n"); + return false; + } + + if ((smmu->features & required_features) != required_features) { + dev_err(smmu->dev, "missing features 0x%x\n", + required_features & ~smmu->features); + return false; + } + + if (smmu->features & forbidden_features) { + dev_err(smmu->dev, "features 0x%x forbidden\n", + smmu->features & forbidden_features); + return false; + } + + smmu->features &= keep_features; + + /* + * This can be relaxed (although the spec says that OAS "must match + * the system physical address size."), but requires some changes. All + * table and queue allocations must use GFP_DMA* to ensure the SMMU can + * access them. + */ + oas = get_kvm_ipa_limit(); + if (smmu->oas < oas) { + dev_err(smmu->dev, "incompatible address size\n"); + return false; + } + + return true; +} + static int kvm_arm_smmu_probe(struct platform_device *pdev) { int ret; @@ -68,11 +121,15 @@ static int kvm_arm_smmu_probe(struct platform_device *pdev) if (ret) return ret; + if (!kvm_arm_smmu_validate_features(smmu)) + return -ENODEV; + platform_set_drvdata(pdev, host_smmu); /* Hypervisor parameters */ hyp_smmu->mmio_addr = ioaddr; hyp_smmu->mmio_size = size; + hyp_smmu->features = smmu->features; kvm_arm_smmu_cur++; return 0;