Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (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 CC07353BB for ; Mon, 6 Feb 2023 19:45:11 +0000 (UTC) Received: by mail-wm1-f54.google.com with SMTP id l37-20020a05600c1d2500b003dfe46a9801so8282853wms.0 for ; Mon, 06 Feb 2023 11:45:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=APDyx3z4IV3rW3QxZlA7mfU0mjO7Ox32BtkbuWjdnhQ=; b=BA9E+Wxq5Z1bboYNGKdE7TzAScXqwKruYCCehgI70/13ingHOhZ6Y5lGoiIW56O4oD iPyb2vXEu6NdFnIsOqjcMM+aTduZbnWf9PLpnpM6swoMBvfb8WtbdsuCBWcMA67TrDDq Eg2djz5q+d9V14je6D2HYO8GqM6bxlcDxePdjqAk9G4NrYZ4wgFRJ8/Nav7JHwNxaABP 42QiftW1N6IgjvDmEqAWK2U/CB9OYPN0KhibLpI+IylVivMMA4ymm8RHisqUCezi9lMz J6BlkASoQUWyqBX+Q15WD5ygF0797iMyOHWin84BkroAw5L0qb6NZp+uIG7DXIZ8uBVd Mp9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=APDyx3z4IV3rW3QxZlA7mfU0mjO7Ox32BtkbuWjdnhQ=; b=NGmAlbms8JT2psSZSCZxmh6yckC7zT+WrMCY9UDKaah7RSpFfIsESFNZsAr21VFwkM zn5gdrnSSIe+KHd3/L1rrDbhyp0mHR3pke9ChJZKgnwEbu0iUzCtyDfKMY2LROCWkuA0 lY5iiZuXiOJdXVMO2NZ53YmeZ8IYIOis0nA+J9CK/fmZsHzlqjKD4qfNyDBHI8Dw6DVW P5loxVfSq4j5chQTIfEmVC72CevQCu5ptYtnETWFBlM5BnW0wfz3r8J0iNDIne7QqgaP ETpINQ/abBZJni23m0GiyN5IcG8iVCfxx3wTOduYHOBHs4sMRNm7PyGrLUHfE8/UYwPP 2hVA== X-Gm-Message-State: AO0yUKUKfdYZfRzG/W8MN3sT+r45/VWDsn4BdJl8xjUujpmQg1ueEdSB Resia6UPaXTMg0yegAJYvRrOsQ== X-Google-Smtp-Source: AK7set8XgVcldAJlafsoSXSh5Q33TEccODw28mHgBONK8/sMpsHldbDSv7P8EojCeImLsUHJJWeYsQ== X-Received: by 2002:a05:600c:43ca:b0:3d9:a145:4d1a with SMTP id f10-20020a05600c43ca00b003d9a1454d1amr764913wmn.34.1675712710077; Mon, 06 Feb 2023 11:45:10 -0800 (PST) Received: from myrica (054592b0.skybroadband.com. [5.69.146.176]) by smtp.gmail.com with ESMTPSA id ip20-20020a05600ca69400b003dd19baf45asm11232511wmb.40.2023.02.06.11.45.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Feb 2023 11:45:09 -0800 (PST) Date: Mon, 6 Feb 2023 19:45:05 +0000 From: Jean-Philippe Brucker To: Ganapatrao Kulkarni Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, robin.murphy@arm.com, will@kernel.org, joro@8bytes.org, darren@os.amperecomputing.com, scott@os.amperecomputing.com Subject: Re: [PATCH] iommu/arm-smmu-v3: Enable PCI ATS in passthrough mode as well Message-ID: References: <20230202124053.848792-1-gankulkarni@os.amperecomputing.com> <3a681b82-d840-6ef1-40dd-358f34c8be9c@os.amperecomputing.com> Precedence: bulk X-Mailing-List: iommu@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3a681b82-d840-6ef1-40dd-358f34c8be9c@os.amperecomputing.com> On Mon, Feb 06, 2023 at 10:50:00PM +0530, Ganapatrao Kulkarni wrote: > > > On 03-02-2023 05:30 pm, Jean-Philippe Brucker wrote: > > On Thu, Feb 02, 2023 at 04:40:53AM -0800, Ganapatrao Kulkarni wrote: > > > The current smmu-v3 driver does not enable PCI ATS for physical functions > > > of ATS capable End Points when booted in smmu bypass mode > > > (iommu.passthrough=1). This will not allow virtual functions to enable > > > ATS(even though EP supports it) while they are attached to a VM using > > > VFIO driver. > > > > > > This patch adds changes to enable ATS support for physical functions > > > in passthrough/bypass mode as well. > > [...] > > > @@ -2453,8 +2458,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) > > > master->domain = smmu_domain; > > > - if (smmu_domain->stage != ARM_SMMU_DOMAIN_BYPASS) > > > - master->ats_enabled = arm_smmu_ats_supported(master); > > > + master->ats_enabled = arm_smmu_ats_supported(master); > > > > I should have added a comment for this. Only found the reason in an old > > cover letter [1]: > > > > "When no translation stages are enabled (0b100), ATS Translation Requests > > (and Translated traffic, if SMMU_CR0.ATSCHK == 1) are denied as though > > EATS == 0b00; the actual value of the EATS field is IGNORED. Such a > > Translation Request causes F_BAD_ATS_TREQ and Translated traffic causes > > F_TRANSL_FORBIDDEN." > > > > (See 3.9.1.1 "Responses to ATS Translation Requests and Translated > > transactions" and 5.2 "Stream Table Entry") > > > > So I don't think we can enable ATS for bypass domains :/ The PF needs to > > be in translated mode in that case. > > Are you intending to say smmu-v3 driver/spec will not support ATS to a VF, > if it's PF is in bypass? What I meant was that if, in order to enable the VF ATS capability, the PCIe device requires to first enable the PF ATS capability, then given that the SMMU does not allow enabling ATS for streams in bypass, we need to enable translation on both PF and VF SMMU configurations. But reading the PCIe spec, it looks like the capabilities are not necessarily tied together: "The ATS Capabilities in VFs and their associated PFs are permitted to be enabled independently." 10.5.1 ATS Extended Capability That wording doesn't indicate that all implementations must allow enabling the caps independently, only that they are allowed to do so. If a device provides independent capabilities, then I don't think you need to enable ATS in the PF. Then the ATS Control Register seems to contradict this with the STU field: "For VFs, this field must be hardwired to Zero. The associated PF's value applies." 10.5.1.3 ATS Control Register (Offset 06h) So pci_enable_ats() requires that pdev->ats_stu is set in order to enable ATS on the VF: /* * Note that enabling ATS on a VF fails unless it's already enabled * with the same STU on the PF. */ ... if (dev->is_virtfn) { pdev = pci_physfn(dev); if (pdev->ats_stu != ps) return -EINVAL; But I suspect it's done this way only because it's easier to implement. The spec doesn't require the PF ATS capability to be enabled, it just says that the PF's STU value counts as the VF's one. It looks like we're allowed to enable ATS on the VF without enabling it on the PF, right? If you rework the PCI driver to only write the PF's STU without enabling the capability, then you could enable it in the VF. Thanks, Jean > > > > > I can send a patch adding the comment next cycle. > > I am more keen to know, how we enable ATS to a VF of ATS capable EP when > it's PF is in bypass? > or it is mandatory to have a PF also translated? then that should be > captured somewhere in documentation. > > > > > > Thanks, > > Jean > > > > [1] https://lore.kernel.org/linux-iommu/20190409165245.26500-1-jean-philippe.brucker@arm.com/ > > > > Thanks, > Ganapat