From nobody Tue Dec 2 02:59:05 2025 Received: from mail-ej1-f73.google.com (mail-ej1-f73.google.com [209.85.218.73]) (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 CB99533A01E for ; Mon, 17 Nov 2025 18:48:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763405327; cv=none; b=Af/vdOYZ7L6XpSfH6Up22vfK3+7Itewj70ZL9KnUSPdQRiSoHQvh3Xjj9Fi8BTxM7uzc0+IXf1HD7OesOeF1Ib3UytF7qbwYWcQ3Pr2IFdR//giioggYIcxxTX6IQRV7bUp7OMwUbUejZcTYiOuVgp6VzgpMZfsC+MaiF0Hk0sE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763405327; c=relaxed/simple; bh=WWfCCBvddxM5OBSZYoCRyfY75yEJKzutFES+Qny/bnk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=FTLLIG665bzABGKawP4/jek2fhK+RTKFFYpeHvjxiIBXnxO5rJN4Bi6AZFWuBmj6kHY+LQVVGgIQ8GoxBkyIG60iXuspCa4NeU+WcPqgkzLBWYPolWLmeQ36P4OHXJ0WaZfrpZF8ONfviKMmqhtf/kwX1zZrehqsUJkdlm5mE/k= 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=dYJ51Frk; arc=none smtp.client-ip=209.85.218.73 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="dYJ51Frk" Received: by mail-ej1-f73.google.com with SMTP id a640c23a62f3a-b73720562ceso257216466b.0 for ; Mon, 17 Nov 2025 10:48:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1763405323; x=1764010123; 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=NDHGRVWxr8tiMMJHgFkthzaCbmxDX2W8q2KLEFUMQ0M=; b=dYJ51FrkmdABQ2T0a9MIrK3CAjYwugwFz1YSMgEs+lt+Rlbgfry2WTdbtoqR0uatcr SZt+VDACKmiflSj+HMHXNjeIDyyDdfUpGG6PJZYYEfrEpIZwN2nmA+gqAnj63iIhnmv+ bwenB4f5FJHPAAt4WySlALUVMZHOesCD4LV0YDn8SZWKKHW7bEPZiNF8d7aME5urMNJ/ K94IP+cwnfFonunVzWdG5ciwHfunI2SFr9YX6tFPCl9QYwpsuVDrLdYxywbDZwsB0RhD gNTxlwhf0SmVJfqd/MMyxPKmu2WPD5NEbxyeAc4BX2R3FUGmenHs2CqP1u2NaRQxTrFj Pdbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763405323; x=1764010123; 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=NDHGRVWxr8tiMMJHgFkthzaCbmxDX2W8q2KLEFUMQ0M=; b=mXdHJs395Nhdvdl74TmpLpQoSI6dbOz4yE3ZphJI9WCko3JFv+bEufk880noW33LWO RfXnVRgabu/f1p5toY87uCXmrWMjOEmMO+Khb+q5IIA0PCz9alE1MM89MF7j/nKO8Sb7 jQzArsXKlVVxBwwEFgzQ3LYWw+CRTHYInF0xrhS8kMXfQcv2+Z1wZofHpx2wXe+5097j i2ZbxxtGKIySX3fSOrUqMO2E92uQLkyM2bAVVvzvnIXYkQBech5hEnwlUqkW8tJ/hKFH B1D84XtGhsXx65A+N/Qq7/u3r/v41eokLDUudqRl2eqKYMsCb3QtF3AFFMYsF/YpVjng Z5xw== X-Forwarded-Encrypted: i=1; AJvYcCUM6nimkS+WYuJKJgkU6JLG+htR3uIJKgVAk5+XKFY/JBv0WW0QcDjraYFjkHrR+ktYuuECYGwNy8nZi6Y=@vger.kernel.org X-Gm-Message-State: AOJu0YwkgDq12zAN630rFXdhPfwXDmiVAUzJxugzfwmUa7PIVT7dKvhJ dimMFfKZjDQBraXsk28T27mh+hLf1chx5bREIVR/Bc7VZDehZvVkb3oq6QFJXXFw6XN0E0P8ogG +KZEmY9kQpsVSnw== X-Google-Smtp-Source: AGHT+IG0TrsHTOFqlfcoz8fH0quPptO87OaYvkyHV4a6ntExQ0SYHVEwf58bnjdfGxOgO/BBPbDmIMTbefbdcw== X-Received: from ejclk13.prod.google.com ([2002:a17:907:178d:b0:b73:69d2:27b7]) (user=smostafa job=prod-delivery.src-stubby-dispatcher) by 2002:a17:907:97cc:b0:b73:7b5d:e76a with SMTP id a640c23a62f3a-b737b5dea0bmr1018806066b.27.1763405322837; Mon, 17 Nov 2025 10:48:42 -0800 (PST) Date: Mon, 17 Nov 2025 18:48:04 +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-18-smostafa@google.com> Subject: [PATCH v5 17/27] iommu/arm-smmu-v3-kvm: Probe SMMU HW 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" Probe SMMU features from the IDR register space, most of the logic is common with the kernel. Signed-off-by: Mostafa Saleh --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 1 + .../iommu/arm/arm-smmu-v3/pkvm/arm-smmu-v3.c | 57 ++++++++++++++++++- .../iommu/arm/arm-smmu-v3/pkvm/arm_smmu_v3.h | 8 +++ 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/ar= m/arm-smmu-v3/arm-smmu-v3.h index 309194ceebe7..1d552efdc4ae 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -49,6 +49,7 @@ struct arm_vsmmu; #define IDR0_S2P (1 << 0) =20 #define ARM_SMMU_IDR1 0x4 +#define IDR1_ECMDQ (1 << 31) #define IDR1_TABLES_PRESET (1 << 30) #define IDR1_QUEUES_PRESET (1 << 29) #define IDR1_REL (1 << 28) diff --git a/drivers/iommu/arm/arm-smmu-v3/pkvm/arm-smmu-v3.c b/drivers/iom= mu/arm/arm-smmu-v3/pkvm/arm-smmu-v3.c index b56feae81dda..e45b4e50b1e4 100644 --- a/drivers/iommu/arm/arm-smmu-v3/pkvm/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/pkvm/arm-smmu-v3.c @@ -10,6 +10,7 @@ #include =20 #include "arm_smmu_v3.h" +#include "../arm-smmu-v3.h" =20 size_t __ro_after_init kvm_hyp_arm_smmu_v3_count; struct hyp_arm_smmu_v3_device *kvm_hyp_arm_smmu_v3_smmus; @@ -45,9 +46,56 @@ static void smmu_deinit_device(struct hyp_arm_smmu_v3_de= vice *smmu) } } =20 +/* + * Mini-probe and validation for the hypervisor. + */ +static int smmu_probe(struct hyp_arm_smmu_v3_device *smmu) +{ + u32 reg; + + /* IDR0 */ + reg =3D readl_relaxed(smmu->base + ARM_SMMU_IDR0); + smmu->features =3D smmu_idr0_features(reg); + + /* + * Some MMU600 and MMU700 have errata that prevent them from using nestin= g, + * not sure how can we identify those, so it's recommended not to enable = this + * drivers on such systems. + * And preventing any of those will be too restrictive + */ + if (!(smmu->features & ARM_SMMU_FEAT_TRANS_S1) || + !(smmu->features & ARM_SMMU_FEAT_TRANS_S2)) + return -ENXIO; + + reg =3D readl_relaxed(smmu->base + ARM_SMMU_IDR1); + if (reg & (IDR1_TABLES_PRESET | IDR1_QUEUES_PRESET | IDR1_REL | IDR1_ECMD= Q)) + return -EINVAL; + + smmu->sid_bits =3D FIELD_GET(IDR1_SIDSIZE, reg); + /* Follows the kernel logic */ + if (smmu->sid_bits <=3D STRTAB_SPLIT) + smmu->features &=3D ~ARM_SMMU_FEAT_2_LVL_STRTAB; + + reg =3D readl_relaxed(smmu->base + ARM_SMMU_IDR3); + smmu->features |=3D smmu_idr3_features(reg); + + reg =3D readl_relaxed(smmu->base + ARM_SMMU_IDR5); + smmu->pgsize_bitmap =3D smmu_idr5_to_pgsize(reg); + + smmu->oas =3D smmu_idr5_to_oas(reg); + if (smmu->oas =3D=3D 52) + smmu->pgsize_bitmap |=3D 1ULL << 42; + else if (!smmu->oas) + smmu->oas =3D 48; + + smmu->ias =3D 64; + smmu->ias =3D min(smmu->ias, smmu->oas); + return 0; +} + static int smmu_init_device(struct hyp_arm_smmu_v3_device *smmu) { - int i; + int i, ret; size_t nr_pages; =20 if (!PAGE_ALIGNED(smmu->mmio_addr | smmu->mmio_size)) @@ -64,8 +112,13 @@ static int smmu_init_device(struct hyp_arm_smmu_v3_devi= ce *smmu) WARN_ON(__pkvm_host_donate_hyp_mmio(pfn)); } smmu->base =3D hyp_phys_to_virt(smmu->mmio_addr); - + ret =3D smmu_probe(smmu); + if (ret) + goto out_ret; return 0; +out_ret: + smmu_deinit_device(smmu); + return ret; } =20 static int smmu_init(void) diff --git a/drivers/iommu/arm/arm-smmu-v3/pkvm/arm_smmu_v3.h b/drivers/iom= mu/arm/arm-smmu-v3/pkvm/arm_smmu_v3.h index 744ee2b7f0b4..3550fa695539 100644 --- a/drivers/iommu/arm/arm-smmu-v3/pkvm/arm_smmu_v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/pkvm/arm_smmu_v3.h @@ -12,12 +12,20 @@ * * Other members are filled and used at runtime by the SMMU driver. * @base Virtual address of SMMU registers + * @ias IPA size + * @oas PA size + * @pgsize_bitmap Supported page sizes + * @sid_bits Max number of SID bits supported */ struct hyp_arm_smmu_v3_device { phys_addr_t mmio_addr; size_t mmio_size; void __iomem *base; u32 features; + unsigned long ias; + unsigned long oas; + unsigned long pgsize_bitmap; + unsigned int sid_bits; }; =20 extern size_t kvm_nvhe_sym(kvm_hyp_arm_smmu_v3_count); --=20 2.52.0.rc1.455.g30608eb744-goog