Re: [PATCH v3 6/6] IB/mlx5: Use __iowrite64_copy() for write combining stores

Catalin Marinas
2025-07-18T18:10:15Z

On Tue, Jul 15, 2025 at 08:52:00AM -0300, Jason Gunthorpe wrote:
> On Tue, Jul 15, 2025 at 11:15:25AM +0100, Will Deacon wrote:
> > > Since STP was rejected alread we've only tested the Neon version. It
> > > does make a huge improvement, but it still somehow fails to combine
> > > rarely sometimes. The CPU is really bad at this :(
> >
> > I think the thread was from last year so I've forgotten most of the
> > details, but wasn't STP rejected because it wasn't virtualisable?
>
> Yes, that was the claim.
>
> > In which case, doesn't NEON suffer from exactly the same (or possibly
> > worse) problem?
>
> In general yes, in specific no.

For a generic iowrite function, I wouldn't use STP or Neon since it may
end up being used on emulated MMIO.

BTW, for Neon, don't you need kernel_neon_begin/end()? This may have its
own overhead and also BUG_ON for different contexts. Again, not suitable
for a generic function.

Unfortunately, there's no way to know what this function is called on.
We might try to infer that the kernel started at EL2 but even that is
not entirely correct with nested virt. Or the OS may start at EL1 but
have direct access to mlx5 where we'd want the faster option.

> mlx5 (and other RDMA devices) have long used Neon for MMIO in
> userspace, so any VMM assigning mlx5 devices simply must make this
> work - it is already not optional. So we know that all VMs out there
> with mlx5 support neon for mlx5, and it is safe for mlx5 to use.

I can't think of any generic solution here, it may have to be a hack
specific to mlx5. We can also add add support for ST64B and have some
condition on system_supports_st64b() for future systems.

Even if we could handle virtualisation, I wonder whether
__iowrite64_copy() is the right function to implement 128-bit stores or
the larger 64-byte atomic stores. At least the comment for the generic
function suggests that it writes in 64-bit quantities. Some MMIO may
only handle such writes. A function like memcpy_toio() is more generic,
it doesn't imply any restrictions on the size of the writes (though I
think it guarantees natural alignment for the stores).

--
Catalin