From: Nicolin Chen <nicolinc@nvidia.com>
To: Jason Gunthorpe <jgg@nvidia.com>
Cc: <will@kernel.org>, <robin.murphy@arm.com>, <joro@8bytes.org>,
<thierry.reding@gmail.com>, <vdumpa@nvidia.com>,
<jonathanh@nvidia.com>, <linux-kernel@vger.kernel.org>,
<iommu@lists.linux.dev>, <linux-arm-kernel@lists.infradead.org>,
<linux-tegra@vger.kernel.org>
Subject: Re: [PATCH v6 6/6] iommu/tegra241-cmdqv: Limit CMDs for guest owned VINTF
Date: Tue, 30 Apr 2024 11:58:44 -0700 [thread overview]
Message-ID: <ZjE/ZKX7okSkztpR@Asurada-Nvidia> (raw)
In-Reply-To: <20240430170655.GU941030@nvidia.com>
On Tue, Apr 30, 2024 at 02:06:55PM -0300, Jason Gunthorpe wrote:
> On Mon, Apr 29, 2024 at 09:43:49PM -0700, Nicolin Chen wrote:
> > -struct arm_smmu_cmdq *tegra241_cmdqv_get_cmdq(struct arm_smmu_device *smmu)
> > +static bool tegra241_vintf_support_cmds(struct tegra241_vintf *vintf,
> > + u64 *cmds, int n)
> > +{
> > + int i;
> > +
> > + /* VINTF owned by hypervisor can execute any command */
> > + if (vintf->hyp_own)
> > + return true;
> > +
> > + /* Guest-owned VINTF must Check against the list of supported CMDs */
> > + for (i = 0; i < n; i++) {
> > + switch (FIELD_GET(CMDQ_0_OP, cmds[i * CMDQ_ENT_DWORDS])) {
> > + case CMDQ_OP_TLBI_NH_ASID:
> > + case CMDQ_OP_TLBI_NH_VA:
> > + case CMDQ_OP_ATC_INV:
>
> So CMDQ only works if not ARM_SMMU_FEAT_E2H? Probably worth mentioning
> that too along with the discussion about HYP
Nod. EL2/EL3 commands aren't supported. And they aren't supposed
to be issued by a guess either, since ARM64_HAS_VIRT_HOST_EXTN is
the feature of "Virtualization Host Extensions"?
>
> > + continue;
> > + default:
> > + return false;
> > + }
> > + }
> > +
> > + return true;
> > +}
>
> For a performance path this looping seems disappointing.. The callers
> don't actually mix different command type. Is there something
> preventing adding a parameter at the callers?
The callers don't seem to mix at this moment. Yet we would have
to be extra careful against any future SMMU patch that may mix
commands?
> Actually looking at this more closely, isn't the command q selection
> in the wrong place?
>
> Ie this batch stuff:
>
> static void arm_smmu_cmdq_batch_add(struct arm_smmu_device *smmu,
> struct arm_smmu_cmdq_batch *cmds,
> struct arm_smmu_cmdq_ent *cmd)
> {
> int index;
>
> if (cmds->num == CMDQ_BATCH_ENTRIES - 1 &&
> (smmu->options & ARM_SMMU_OPT_CMDQ_FORCE_SYNC)) {
> arm_smmu_cmdq_issue_cmdlist(smmu, cmds->cmds, cmds->num, true);
> cmds->num = 0;
> }
>
> if (cmds->num == CMDQ_BATCH_ENTRIES) {
> arm_smmu_cmdq_issue_cmdlist(smmu, cmds->cmds, cmds->num, false);
> cmds->num = 0;
> }
>
> index = cmds->num * CMDQ_ENT_DWORDS;
> if (unlikely(arm_smmu_cmdq_build_cmd(&cmds->cmds[index], cmd))) {
> dev_warn(smmu->dev, "ignoring unknown CMDQ opcode 0x%x\n",
> cmd->opcode);
> return;
> }
>
> Has to push everything, across all the iterations of add/submut, onto
> the same CMDQ otherwise the SYNC won't be properly flushing?
ECMDQ seems to have such a limitation, but VCMDQs can get away
as HW can insert a SYNC to a queue that doesn't end with a SYNC.
> But each arm_smmu_cmdq_issue_cmdlist() calls its own get q
> function. Yes, they probably return the same Q since we are probably
> on the same CPU, but it seems logically wrong (and slower!) to
> organize it like this.
>
> I would expect the Q to be selected when the struct
> arm_smmu_cmdq_batch is allocated on the stack, and be the same for the
> entire batch operation. Not only do we spend less time trying to
> compute the Q to use we have a built in guarentee that every command
> will be on the same Q as the fenching SYNC.
This seems to be helpful to ECMDQ. The current version disables
the preempts, which feels costly to me.
> Something sort of like this as another patch?
>
> 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 268da20baa4e9c..d8c9597878315a 100644
> --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> @@ -357,11 +357,22 @@ static int arm_smmu_cmdq_build_cmd(u64 *cmd, struct arm_smmu_cmdq_ent *ent)
> return 0;
> }
>
> -static struct arm_smmu_cmdq *arm_smmu_get_cmdq(struct arm_smmu_device *smmu,
> - u64 *cmds, int n)
> +enum required_cmds {
> + CMDS_ALL,
> + /*
> + * Commands will be one of:
> + * CMDQ_OP_ATC_INV, CMDQ_OP_TLBI_EL2_VA, CMDQ_OP_TLBI_NH_VA,
> + * CMDQ_OP_TLBI_EL2_ASID, CMDQ_OP_TLBI_NH_ASID, CMDQ_OP_TLBI_S2_IPA,
> + * CMDQ_OP_TLBI_S12_VMALL, CMDQ_OP_SYNC
> + */
> + CMDS_INVALIDATION,
> +};
Hmm, guest-owned VCMDQs don't support EL2 commands. So, it feels
to be somehow complicated to decouple them further in the callers
of arm_smmu_cmdq_batch_add(). And I am not sure if there is a use
case of guest issuing CMDQ_OP_TLBI_S2_IPA/CMDQ_OP_TLBI_S12_VMALL
either, HW surprisingly supports these two though.
Perhaps we could just scan the first command in the batch, giving
a faith that no one will covertly sneak different commands in it?
Otherwise, there has to be a get_suported_cmdq callback so batch
or its callers can avoid adding unsupported commands at the first
place.
Thanks
Nicolin
WARNING: multiple messages have this Message-ID (diff)
From: Nicolin Chen <nicolinc@nvidia.com>
To: Jason Gunthorpe <jgg@nvidia.com>
Cc: <will@kernel.org>, <robin.murphy@arm.com>, <joro@8bytes.org>,
<thierry.reding@gmail.com>, <vdumpa@nvidia.com>,
<jonathanh@nvidia.com>, <linux-kernel@vger.kernel.org>,
<iommu@lists.linux.dev>, <linux-arm-kernel@lists.infradead.org>,
<linux-tegra@vger.kernel.org>
Subject: Re: [PATCH v6 6/6] iommu/tegra241-cmdqv: Limit CMDs for guest owned VINTF
Date: Tue, 30 Apr 2024 11:58:44 -0700 [thread overview]
Message-ID: <ZjE/ZKX7okSkztpR@Asurada-Nvidia> (raw)
In-Reply-To: <20240430170655.GU941030@nvidia.com>
On Tue, Apr 30, 2024 at 02:06:55PM -0300, Jason Gunthorpe wrote:
> On Mon, Apr 29, 2024 at 09:43:49PM -0700, Nicolin Chen wrote:
> > -struct arm_smmu_cmdq *tegra241_cmdqv_get_cmdq(struct arm_smmu_device *smmu)
> > +static bool tegra241_vintf_support_cmds(struct tegra241_vintf *vintf,
> > + u64 *cmds, int n)
> > +{
> > + int i;
> > +
> > + /* VINTF owned by hypervisor can execute any command */
> > + if (vintf->hyp_own)
> > + return true;
> > +
> > + /* Guest-owned VINTF must Check against the list of supported CMDs */
> > + for (i = 0; i < n; i++) {
> > + switch (FIELD_GET(CMDQ_0_OP, cmds[i * CMDQ_ENT_DWORDS])) {
> > + case CMDQ_OP_TLBI_NH_ASID:
> > + case CMDQ_OP_TLBI_NH_VA:
> > + case CMDQ_OP_ATC_INV:
>
> So CMDQ only works if not ARM_SMMU_FEAT_E2H? Probably worth mentioning
> that too along with the discussion about HYP
Nod. EL2/EL3 commands aren't supported. And they aren't supposed
to be issued by a guess either, since ARM64_HAS_VIRT_HOST_EXTN is
the feature of "Virtualization Host Extensions"?
>
> > + continue;
> > + default:
> > + return false;
> > + }
> > + }
> > +
> > + return true;
> > +}
>
> For a performance path this looping seems disappointing.. The callers
> don't actually mix different command type. Is there something
> preventing adding a parameter at the callers?
The callers don't seem to mix at this moment. Yet we would have
to be extra careful against any future SMMU patch that may mix
commands?
> Actually looking at this more closely, isn't the command q selection
> in the wrong place?
>
> Ie this batch stuff:
>
> static void arm_smmu_cmdq_batch_add(struct arm_smmu_device *smmu,
> struct arm_smmu_cmdq_batch *cmds,
> struct arm_smmu_cmdq_ent *cmd)
> {
> int index;
>
> if (cmds->num == CMDQ_BATCH_ENTRIES - 1 &&
> (smmu->options & ARM_SMMU_OPT_CMDQ_FORCE_SYNC)) {
> arm_smmu_cmdq_issue_cmdlist(smmu, cmds->cmds, cmds->num, true);
> cmds->num = 0;
> }
>
> if (cmds->num == CMDQ_BATCH_ENTRIES) {
> arm_smmu_cmdq_issue_cmdlist(smmu, cmds->cmds, cmds->num, false);
> cmds->num = 0;
> }
>
> index = cmds->num * CMDQ_ENT_DWORDS;
> if (unlikely(arm_smmu_cmdq_build_cmd(&cmds->cmds[index], cmd))) {
> dev_warn(smmu->dev, "ignoring unknown CMDQ opcode 0x%x\n",
> cmd->opcode);
> return;
> }
>
> Has to push everything, across all the iterations of add/submut, onto
> the same CMDQ otherwise the SYNC won't be properly flushing?
ECMDQ seems to have such a limitation, but VCMDQs can get away
as HW can insert a SYNC to a queue that doesn't end with a SYNC.
> But each arm_smmu_cmdq_issue_cmdlist() calls its own get q
> function. Yes, they probably return the same Q since we are probably
> on the same CPU, but it seems logically wrong (and slower!) to
> organize it like this.
>
> I would expect the Q to be selected when the struct
> arm_smmu_cmdq_batch is allocated on the stack, and be the same for the
> entire batch operation. Not only do we spend less time trying to
> compute the Q to use we have a built in guarentee that every command
> will be on the same Q as the fenching SYNC.
This seems to be helpful to ECMDQ. The current version disables
the preempts, which feels costly to me.
> Something sort of like this as another patch?
>
> 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 268da20baa4e9c..d8c9597878315a 100644
> --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> @@ -357,11 +357,22 @@ static int arm_smmu_cmdq_build_cmd(u64 *cmd, struct arm_smmu_cmdq_ent *ent)
> return 0;
> }
>
> -static struct arm_smmu_cmdq *arm_smmu_get_cmdq(struct arm_smmu_device *smmu,
> - u64 *cmds, int n)
> +enum required_cmds {
> + CMDS_ALL,
> + /*
> + * Commands will be one of:
> + * CMDQ_OP_ATC_INV, CMDQ_OP_TLBI_EL2_VA, CMDQ_OP_TLBI_NH_VA,
> + * CMDQ_OP_TLBI_EL2_ASID, CMDQ_OP_TLBI_NH_ASID, CMDQ_OP_TLBI_S2_IPA,
> + * CMDQ_OP_TLBI_S12_VMALL, CMDQ_OP_SYNC
> + */
> + CMDS_INVALIDATION,
> +};
Hmm, guest-owned VCMDQs don't support EL2 commands. So, it feels
to be somehow complicated to decouple them further in the callers
of arm_smmu_cmdq_batch_add(). And I am not sure if there is a use
case of guest issuing CMDQ_OP_TLBI_S2_IPA/CMDQ_OP_TLBI_S12_VMALL
either, HW surprisingly supports these two though.
Perhaps we could just scan the first command in the batch, giving
a faith that no one will covertly sneak different commands in it?
Otherwise, there has to be a get_suported_cmdq callback so batch
or its callers can avoid adding unsupported commands at the first
place.
Thanks
Nicolin
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2024-04-30 18:59 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-30 4:43 [PATCH v6 0/6] Add Tegra241 (Grace) CMDQV Support (part 1/2) Nicolin Chen
2024-04-30 4:43 ` Nicolin Chen
2024-04-30 4:43 ` [PATCH v6 1/6] iommu/arm-smmu-v3: Pass in cmdq pointer to arm_smmu_cmdq_issue_cmdlist() Nicolin Chen
2024-04-30 4:43 ` Nicolin Chen
2024-04-30 13:54 ` Jason Gunthorpe
2024-04-30 13:54 ` Jason Gunthorpe
2024-04-30 4:43 ` [PATCH v6 2/6] iommu/arm-smmu-v3: Add CS_NONE quirk Nicolin Chen
2024-04-30 4:43 ` Nicolin Chen
2024-04-30 14:22 ` Jason Gunthorpe
2024-04-30 14:22 ` Jason Gunthorpe
2024-04-30 16:30 ` Nicolin Chen
2024-04-30 16:30 ` Nicolin Chen
2024-04-30 16:37 ` Jason Gunthorpe
2024-04-30 16:37 ` Jason Gunthorpe
2024-04-30 16:43 ` Nicolin Chen
2024-04-30 16:43 ` Nicolin Chen
2024-04-30 4:43 ` [PATCH v6 3/6] iommu/arm-smmu-v3: Make arm_smmu_cmdq_init reusable Nicolin Chen
2024-04-30 4:43 ` Nicolin Chen
2024-04-30 14:24 ` Jason Gunthorpe
2024-04-30 14:24 ` Jason Gunthorpe
2024-04-30 15:50 ` Nicolin Chen
2024-04-30 15:50 ` Nicolin Chen
2024-04-30 4:43 ` [PATCH v6 4/6] iommu/arm-smmu-v3: Make __arm_smmu_cmdq_skip_err reusable Nicolin Chen
2024-04-30 4:43 ` Nicolin Chen
2024-04-30 14:06 ` Jason Gunthorpe
2024-04-30 14:06 ` Jason Gunthorpe
2024-04-30 15:48 ` Nicolin Chen
2024-04-30 15:48 ` Nicolin Chen
2024-04-30 4:43 ` [PATCH v6 5/6] iommu/arm-smmu-v3: Add in-kernel support for NVIDIA Tegra241 (Grace) CMDQV Nicolin Chen
2024-04-30 4:43 ` Nicolin Chen
2024-04-30 16:35 ` Jason Gunthorpe
2024-04-30 16:35 ` Jason Gunthorpe
2024-04-30 18:08 ` Nicolin Chen
2024-04-30 18:08 ` Nicolin Chen
2024-05-01 13:00 ` Jason Gunthorpe
2024-05-01 13:00 ` Jason Gunthorpe
2024-05-01 17:43 ` Nicolin Chen
2024-05-01 17:43 ` Nicolin Chen
2024-05-02 12:41 ` Jason Gunthorpe
2024-05-02 12:41 ` Jason Gunthorpe
2024-05-02 19:26 ` Nicolin Chen
2024-05-02 19:26 ` Nicolin Chen
2024-04-30 4:43 ` [PATCH v6 6/6] iommu/tegra241-cmdqv: Limit CMDs for guest owned VINTF Nicolin Chen
2024-04-30 4:43 ` Nicolin Chen
2024-04-30 17:06 ` Jason Gunthorpe
2024-04-30 17:06 ` Jason Gunthorpe
2024-04-30 18:58 ` Nicolin Chen [this message]
2024-04-30 18:58 ` Nicolin Chen
2024-05-01 0:17 ` Jason Gunthorpe
2024-05-01 0:17 ` Jason Gunthorpe
2024-05-01 16:32 ` Nicolin Chen
2024-05-01 16:32 ` Nicolin Chen
2024-05-06 3:52 ` Nicolin Chen
2024-05-06 3:52 ` Nicolin Chen
2024-05-06 13:00 ` Jason Gunthorpe
2024-05-06 13:00 ` Jason Gunthorpe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZjE/ZKX7okSkztpR@Asurada-Nvidia \
--to=nicolinc@nvidia.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=jonathanh@nvidia.com \
--cc=joro@8bytes.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=robin.murphy@arm.com \
--cc=thierry.reding@gmail.com \
--cc=vdumpa@nvidia.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.