From nobody Tue Dec 2 02:59:06 2025 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 94DAD33971E for ; Mon, 17 Nov 2025 18:48:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763405324; cv=none; b=rTv7x2kbNupd/iQ98F1FiINM1nOrokBvIdT1I5NkTgAK1fWwfx8hdjlCpmOHbUIaT8LWnZKvKyyRjmniXAeNMG9gLoPPzHY2rce53qpzWkpEihJjko7MQ7F/VX1uHAi+j++2XVSbRrnEbDlJyjRCzPDc8lT6M7NaNfDuFXzg9ws= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763405324; c=relaxed/simple; bh=Tcqv38/05N/B44jMwcSYWvtznjIegtRBbmE71X1CBgw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=BshQYIpf6/qyvpAcZYZ2GZO6fxjr7xJdV+X8X6yOQ3oGRszFe4ueuMTyw7+rXaPkpn2+D7zNEsrN0/g8z+LTFDzqiARCu67KAZdPR0ckxMfutYlZxm2b0Xwb3njH1MBQscmUvWLcA2t8gGMnVfB0bwy5sB0u6hf6rij4wbtPg2Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--smostafa.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=dIf8b61t; arc=none smtp.client-ip=209.85.221.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--smostafa.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="dIf8b61t" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-42b2ad29140so2137452f8f.0 for ; Mon, 17 Nov 2025 10:48:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1763405319; x=1764010119; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=C8whZ0pZrNIRwagAm0ORPy5mFVOpkEuU2Ow6ExYwaLg=; b=dIf8b61tU/FnUSqbKfFNZRXyTGYlml5jywrucIFzvMV99UJkQgMVobflMXaZqGWmF0 zplbGdQ6P6J1DkAhHsH6BXL3i/Id9yWaQxQtlEFLASNC0A01W+AK34Y0nj6waC0SMJew N4Y3sPt4teV3ve44VidZ3I8+5Hplwztk2+chOp7RlKQQv1PJbqhLhQFE4nlGCfmCvOAo P44NW7yxhnpv7cY8GfSO+sWI8qe0Mjwqf9skCzBz+xWcgHvCZ4vwXeR3f1ppOfoVB9Bg iITkTBch9wsnhYYebseVeITsPWnAqTXeTM67tUNn2AcpFhfWe5JTRmBEUdXYjnqRUsD8 nG/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763405319; x=1764010119; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=C8whZ0pZrNIRwagAm0ORPy5mFVOpkEuU2Ow6ExYwaLg=; b=LMT/rHYcSvaWNXAA6mImIMM4ZUz1xC3E1BNQUdUwk1phKJiWKNoICe1hAhcekuCgYc WdlG8qz9eF4FuONV/NKuhVB8nYOn5iIhSBroID05E9CYEy3ScvpW2/i7j5VJ/ZUWor60 4VKj6ruqsGHB9Btrqz3Yw+DyPMjBXpxvz63Apga0+m3N4uCQWFT3J6PgygBy7j0BKmtK wSDO5hbjpzspLrwy4VU7huTrJKm0d3cbLLM1ZHXRQZdSyT7+sDbRIz+z72BuFlW1dTYV Yj8A2VPRXlYftqQ+1n6/g09JFNfQNdFGBAPv2yu/0Kx+uwVJ7KiXMMOyAemH24RLaFS3 vH/Q== X-Forwarded-Encrypted: i=1; AJvYcCUa/V1YGdrJj7Dm8fEkvETeQhbi459WKEYUai7tR/raTiWwZP/L1A/k1bitIMAZjKCN2g5sSMB5Y5GeaBY=@vger.kernel.org X-Gm-Message-State: AOJu0YyA9aT/ij/7tGWrCNEie07XDdZoAjvVNkyn3Bq4U+COdUBb5Onz tASyudxcbAemzUGVNIzgYyuuuZdukvB7Mc6NHn0MICyrxqUQpYGAdtaTQO75/Zxz0alvjDG9QDd JL5TpU4xjOd8urQ== X-Google-Smtp-Source: AGHT+IGsLY0ihnfe+d9VivrIlxJpw79fEdNZ7d3k+PXAdZb1HiZsb1oiiqepnVn54b8AHulaH6k3LpFgrXdMyA== X-Received: from wrmf14.prod.google.com ([2002:adf:e90e:0:b0:42b:b28a:6748]) (user=smostafa job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:2c0c:b0:42b:3806:2bb4 with SMTP id ffacd0b85a97d-42b59342e50mr13284074f8f.27.1763405319568; Mon, 17 Nov 2025 10:48:39 -0800 (PST) Date: Mon, 17 Nov 2025 18:48:01 +0000 In-Reply-To: <20251117184815.1027271-1-smostafa@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251117184815.1027271-1-smostafa@google.com> X-Mailer: git-send-email 2.52.0.rc1.455.g30608eb744-goog Message-ID: <20251117184815.1027271-15-smostafa@google.com> Subject: [PATCH v5 14/27] iommu/arm-smmu-v3: Support probing KVM emulated devices From: Mostafa Saleh To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, iommu@lists.linux.dev Cc: catalin.marinas@arm.com, will@kernel.org, maz@kernel.org, oliver.upton@linux.dev, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, joro@8bytes.org, jean-philippe@linaro.org, jgg@ziepe.ca, praan@google.com, danielmentz@google.com, mark.rutland@arm.com, qperret@google.com, tabba@google.com, Mostafa Saleh Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When KVM runs in protected mode, and CONFIG_ARM_SMMU_V3_PKVM is enabled, it will manage the SMMUv3 HW using trap and emulate and present emulated SMMUs to the host kernel. In that case, those SMMUs will be on the aux bus, so make it possibly to the driver to probe those devices. Otherwise, everything else is the same as the KVM emulation complies with the architecutre, so the driver doesn't need to be modified. Suggested-by: Jason Gunthorpe Signed-off-by: Mostafa Saleh --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 58 +++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/ar= m/arm-smmu-v3/arm-smmu-v3.c index 7b1bd0658910..851d47bedae6 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -11,6 +11,7 @@ =20 #include #include +#include #include #include #include @@ -4604,6 +4605,63 @@ static struct platform_driver arm_smmu_driver =3D { module_driver(arm_smmu_driver, platform_driver_register, arm_smmu_driver_unregister); =20 +#ifdef CONFIG_ARM_SMMU_V3_PKVM +/* + * Now we have 2 devices, the aux device bound to this driver, and pdev + * which is the physical platform device. + * This part is a bit hairy but it works due to the fact that + * CONFIG_ARM_SMMU_V3_PKVM forces both drivers to be built in. + * The struct device for the SMMU is used in the following cases: + * 1) Printing using dev_*() + * 2) DMA memory alloc (dmam_alloc_coherent, devm_*) + * 3) Requesting resources (iomem, sysfs) + * 4) Probing firmware info (of_node, fwnode...) + * 5) Dealing with abstracted HW resources (irqs, MSIs, RPM) + * 6) Saving/reading driver data + * For point 4) and 5) we must use the platform device. + * For, 1) pdev is better for debuggability. + * For 2), 3), 6) it's better to use the bound device. + * However that doesn't really work: + * For 2) The DMA allocation using the aux device will fail, as + * we need to setup some device DMA attrs (mask), to match the + * platform. + * For 6) Some contexts from the pdev as MSI, it needs to use the + * drvdata. + * Based on the following: + * 1- Both drivers must be built-in to enable this (enforced by Kconfig), + * which means that none of them can be removed. + * 2- The KVM driver doesn't do anythng at runtime and doesn't use drvdata. + * We can keep the driver simple and to claim the platform device in all c= ases. + */ +static int arm_smmu_device_probe_emu(struct auxiliary_device *auxdev, + const struct auxiliary_device_id *id) +{ + struct device *parent =3D auxdev->dev.parent; + + dev_info(&auxdev->dev, "Probing from %s\n", dev_name(parent)); + return arm_smmu_device_probe(to_platform_device(parent)); +} + +static void arm_smmu_device_shutdown_emu(struct auxiliary_device *auxdev) +{ + arm_smmu_device_shutdown(to_platform_device(auxdev->dev.parent)); +} + +const struct auxiliary_device_id arm_smmu_aux_table[] =3D { + { .name =3D "protected_kvm.smmu_v3_emu" }, + { }, +}; + +struct auxiliary_driver arm_smmu_driver_emu =3D { + .name =3D "arm-smmu-v3-emu", + .id_table =3D arm_smmu_aux_table, + .probe =3D arm_smmu_device_probe_emu, + .shutdown =3D arm_smmu_device_shutdown_emu, +}; + +module_auxiliary_driver(arm_smmu_driver_emu); +#endif + MODULE_DESCRIPTION("IOMMU API for ARM architected SMMUv3 implementations"); MODULE_AUTHOR("Will Deacon "); MODULE_ALIAS("platform:arm-smmu-v3"); --=20 2.52.0.rc1.455.g30608eb744-goog