From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 BC9332744F for ; Fri, 12 Dec 2025 15:53:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765554800; cv=none; b=rRvaCHUduS9COD2hlvGcYozpZGj2q2ttu0wS20lH+UaUWLwRBRjMR+wVglLntQafNF4zYmnmfmGh8LlljJ2YS1DVEQ0NymYrbOVgbQY2n4rBygy1hLRvNcIl3p4ziL+GlSjtiPpY/hIAVUiMwNkhC/bWhevasGXVKepg91evcW4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765554800; c=relaxed/simple; bh=zBoGh7Qottv/rPDdH62OofJFkNYMMNwpVKElG2S2exg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=aNJsIVxVgyGOKdstA7e5s9hLAVjDwiIlllkw6+Xu9mLPxWl4Vo7bkHaRq8t9uh13gClH03BtpHTznb6CpM7rhhlIdQfuanyJoUnfMM9x5K6vmjyZPRVn0FU5qm4ULKmYWvzr77KcBROqmMh3MSmY4UOqNbKiFaByiE7SkYBFWjE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=1OKB2iLE; arc=none smtp.client-ip=209.85.128.53 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=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="1OKB2iLE" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4779a4fb9bfso129585e9.0 for ; Fri, 12 Dec 2025 07:53:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765554797; x=1766159597; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=AoTM5VqqBSE/slfl8I1wW/rbVxxaz8QvUYFV+G2U2Oc=; b=1OKB2iLE561gNwFoPoTLoQASLPk946NmPukTvmxdsCb6R7pWihC+I+2I/H8N1qy4wI hhqloF7Fl0YFk5k/9l/ShSodGHwSWCQ2wJ351wPs/egQ6hpQDm6y89vWww1njsSwsYfL SU4OTgt6M/Zgoni2KZHpExF8woV+FKlTXIFm+cNLieqDFdlMERYW1ohMHtnu1LuGAk9f /k3bpF+wSfy7PibvR7QbTPI8+YaQPly41bECCRGGsFix8Ioskp1OVLhNPIlR2cjcfYNV gmsvM+dJvMcuzl89MvVhv6NXllBeFsxbvt1xnkpRNmH37JrCCvyqVO8qlJc7O5dGLX32 q7fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765554797; x=1766159597; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=AoTM5VqqBSE/slfl8I1wW/rbVxxaz8QvUYFV+G2U2Oc=; b=F3rNJhyqFXnUFG5cIwVzR7fXqh89zVxs0DCypMnrmh7bYKuI51ie4pDbJi1wQZjbcW zQThfTVm4trKQ2oBr6jjtULZFYV7SfN7hDKTCYSrF5ldkhgkcuFqe2qWOjlGoVO/d5AA BtQ8hrqZM9DJtRleM+SwH8rgNUEpFDaCCLs4FrXHa1dv9R+9z7wdVhCcVrszNjw9DLn/ VWfxjUHpl38+U3XxZ8buZJgVeVyIrIGz1d/QqLsDL5r3aJMEztbR9EB7F23Zscl4jEue l0gj6vO6HoRu4gjVPEponihqFFtDjSP4+YCLz1ffPFvjEkfYvUXZO/Odhi7NXE7+XA8L G0QQ== X-Forwarded-Encrypted: i=1; AJvYcCXlAgWtXFx+5vst4/nlAkZMnKHXMavpYTH50tB+/DUJvSJpCkkpbekZ9iGqqWH3BbQqHVdgUlEaiMFkC+w=@vger.kernel.org X-Gm-Message-State: AOJu0YzQiM64UzeLBW1v7LZVLabBymAqqO7QTvKVKDxLpXqvNr+M5lS6 iwMD68pbatmOvLyGUIkVCknVNkqYowT0URBUFfxnkHphb9rUVPSlUzbO4mfBpoSM+A== X-Gm-Gg: AY/fxX7E178uiq2DWP/3cZmSkcIprBXLrF6i5PdNZySb0HEb1DgQ3yzLehkmsMQSuab /TjZhlyNn5UUo5LgLTQMxzZcNOeWGSIwuDod7qvES8DCgME07VfpRCgoAqycle65G6yDosmoXHe KnnbAm2YLQLZbGqWq0wR2Mfv9CcRyelPkExXgORIqHojsb4MDXyCxoWOLE6EhJKjK1nOxz5o5k5 yFKPnLbgMaGU04GXWzVq6Io6aMFsPv8ZJLxafJe3oxEoKIXmM9joJuRAMfEzXZvQf3PAyLGAGxj x1mDvq7NLxgO+lGrrusOKttqryXuQY5ABRGF+ew+gBTtD7dIFhPSYwL89oTpbqZHG4NVZCaiklH SDYubfY4X2Eb1nGdnCX3j3DY5+9j+nbZ+p4M8ctYtmoomF6wB9+mthnHpSQ64lw06k7cSDyYGcs Qwi1HdlIVIhxtWGRurep23bd00cVMEu2CouQYN5bwe8FXNU4b/RLeRkZGCpXzy X-Google-Smtp-Source: AGHT+IHmfLLjUS7AcR5ly1Ud2Cl5iPQrQoNP3+3/YuFuH/EESCUT2zan2BZpMVjz/bWfM1lUWrZeUg== X-Received: by 2002:a05:600c:8885:b0:477:2f6f:44db with SMTP id 5b1f17b1804b1-47a8980f38emr1019575e9.5.1765554797030; Fri, 12 Dec 2025 07:53:17 -0800 (PST) Received: from google.com (54.140.140.34.bc.googleusercontent.com. [34.140.140.54]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47a8f4b516bsm15647455e9.2.2025.12.12.07.53.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Dec 2025 07:53:16 -0800 (PST) Date: Fri, 12 Dec 2025 15:53:13 +0000 From: Mostafa Saleh To: Jason Gunthorpe Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, iommu@lists.linux.dev, 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, praan@google.com, danielmentz@google.com, mark.rutland@arm.com, qperret@google.com, tabba@google.com Subject: Re: [PATCH v5 14/27] iommu/arm-smmu-v3: Support probing KVM emulated devices Message-ID: References: <20251117184815.1027271-1-smostafa@google.com> <20251117184815.1027271-15-smostafa@google.com> <20251128165616.GD812105@ziepe.ca> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20251128165616.GD812105@ziepe.ca> On Fri, Nov 28, 2025 at 12:56:16PM -0400, Jason Gunthorpe wrote: > On Mon, Nov 17, 2025 at 06:48:01PM +0000, Mostafa Saleh wrote: > > 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/arm/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 @@ > > > > #include > > #include > > +#include > > #include > > #include > > #include > > @@ -4604,6 +4605,63 @@ static struct platform_driver arm_smmu_driver = { > > module_driver(arm_smmu_driver, platform_driver_register, > > arm_smmu_driver_unregister); > > > > +#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 cases. > > + */ > > It is OK I guess, I wouldn't insist you change it, but I think it is > kind of gross. Registering the iommu driver against the platform > device instead of the aux is pretty ugly and denies userspace the > ability to see that the hypervisor is sitting in there through the > sysfs topology. Yes, that’s why I was wondering if it’s better to keep this as a platform driver and create the aux devices for the parent(KVM) but that was really complicated to handle the probe ordering. I will give this another though before v6. > > Not sure why the commentary about built-in though, what does that have > to do with anything? If the aux driver is not built in then it will > just module load later and everything should be fine? As at the moment the KVM driver doesn’t use drvdata(nor any device resources) and the main driver(aux) does, but if that was a module, we can’t know which version does what (if that changes in the future, although unlikely). Thanks, Mostafa > > Jason