public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/13] Provide udata helpers and use them in bnxt_re
@ 2026-02-27  1:11 Jason Gunthorpe
  2026-02-27  1:11 ` [PATCH v2 01/13] RDMA: Use copy_struct_from_user() instead of open coding Jason Gunthorpe
                   ` (13 more replies)
  0 siblings, 14 replies; 20+ messages in thread
From: Jason Gunthorpe @ 2026-02-27  1:11 UTC (permalink / raw)
  To: Kalesh AP, Leon Romanovsky, linux-rdma, Selvin Xavier,
	Sriharsha Basavapatna
  Cc: patches

Add new helpers that entirely execute the expected common patterns for
driver data uAPI forward and backwards compatibility so that drivers don't
have to open code these.

The helpers were developed by looking at the entire tree and moving every
driver to use them, but this series only converts bnxt_re as it has a
pending series to extend the driver data uAPI and the lack of correct
compatibility handling will be problematic.

This handles both the request and response side of the udata using the
following general rules:

1) The userspace can provide a longer request so long as the trailing
   part the kernel doesn't understand is all zeros.

   This provides a degree of safety if the userspace wrongly tries to use
   a new feature the kernel does not understand with some non-zero value.

   It allows a simpler rdma-core implementation because the library can
   simply always use the latest structs for the request, even if they are
   bigger. It simply has to avoid using the new members if they are not
   supported/required.

2) The userspace can provide a shorter request, the kernel will 0 pad it
   out to fill the storage. The newer kernel should understand that older
   userspace will provide 0 to new fields. The kernel has three options
   to enable new request fields:
     - Input comp_mask that says the field is supported
     - Look for non-zero values
     - Check if the udata->inlen size covers the field

   This also corrects any bugs related to not filling in request
   structures as the new helper always fully writes to the struct.

 3) The userspace can provide a shorter or longer response struct.
    If shorter the kernel reply is truncated. The kernel should be
    designed to not write to new reply field unless the userspace has
    affirmatively requested them.

    If the user buffer is longer then the kernel will zero fill it.

    Userspace has three options to enable new response fields:
      - Output comp_mask that says the field is supported
      - Look for non-zero values
      - Infer the output must be valid because the request contents demand
        it and old kernels will fail the request

Since bnxt_re has never implemented these rules correctly and now does,
provide a UCTX flag to tell userspace about it. If
BNXT_RE_UCNTX_CMASK_UAPI_COMPAT_SUPPORTED is not set then userspace must
not use any request or response fields beyond the current kernel uAPI.

Using any new fields is only possible on kernels with the flag.

A series converting all drivers to these new helpers is on github, I will
send it later:

https://github.com/jgunthorpe/linux/commits/rdma_uapi/

v2:
 - Revise the core function implementations completely to use
   EXPORT_SYMBOLs and integrate debug logging
 - Have ib_is_udata_in_empty() return errno so it can propogate the right
   code in all cases
 - Remove debug prints
 - Rebase on linus's tree
v1: https://patch.msgid.link/r/0-v1-89ea7d615ba4+636-bnxt_re_uapi_jgg@nvidia.com

Jason Gunthorpe (13):
  RDMA: Use copy_struct_from_user() instead of open coding
  RDMA/core: Add rdma_udata_to_dev()
  RDMA: Add ib_copy_validate_udata_in()
  RDMA: Add ib_copy_validate_udata_in_cm()
  RDMA: Add ib_respond_udata()
  RDMA: Add ib_is_udata_in_empty()
  RDMA: Provide documentation about the uABI compatibility rules
  RDMA/bnxt_re: Add compatibility checks to the uapi path
  RDMA/bnxt_re: Add compatibility checks to the uapi path for no data
  RDMA/bnxt_re: Add missing comp_mask validation
  RDMA/bnxt_re: Use ib_respond_udata()
  RDMA/bnxt_re: Use ib_respond_empty_udata()
  RDMA/bnxt_re: Add BNXT_RE_UCNTX_CMASK_UAPI_COMPAT_SUPPORTED

 drivers/infiniband/core/ib_core_uverbs.c |  27 +++++
 drivers/infiniband/core/rdma_core.h      |   3 +
 drivers/infiniband/core/uverbs_cmd.c     |  24 +---
 drivers/infiniband/core/uverbs_ioctl.c   |  87 +++++++++++++
 drivers/infiniband/hw/bnxt_re/ib_verbs.c | 148 ++++++++++++++++-------
 include/rdma/ib_verbs.h                  |  87 +++++++++++++
 include/rdma/uverbs_ioctl.h              | 101 ++++++++++++++++
 include/uapi/rdma/bnxt_re-abi.h          |   1 +
 8 files changed, 414 insertions(+), 64 deletions(-)


base-commit: 3f4a08e64442340f4807de63e30aef22cc308830
-- 
2.43.0


^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2026-03-02 19:36 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-27  1:11 [PATCH v2 00/13] Provide udata helpers and use them in bnxt_re Jason Gunthorpe
2026-02-27  1:11 ` [PATCH v2 01/13] RDMA: Use copy_struct_from_user() instead of open coding Jason Gunthorpe
2026-02-27  1:11 ` [PATCH v2 02/13] RDMA/core: Add rdma_udata_to_dev() Jason Gunthorpe
2026-03-02 19:30   ` Leon Romanovsky
2026-03-02 19:36     ` Jason Gunthorpe
2026-02-27  1:11 ` [PATCH v2 03/13] RDMA: Add ib_copy_validate_udata_in() Jason Gunthorpe
2026-02-27  7:50   ` kernel test robot
2026-02-28 10:24   ` kernel test robot
2026-02-27  1:11 ` [PATCH v2 04/13] RDMA: Add ib_copy_validate_udata_in_cm() Jason Gunthorpe
2026-02-27  1:11 ` [PATCH v2 05/13] RDMA: Add ib_respond_udata() Jason Gunthorpe
2026-02-27  1:11 ` [PATCH v2 06/13] RDMA: Add ib_is_udata_in_empty() Jason Gunthorpe
2026-02-27  1:11 ` [PATCH v2 07/13] RDMA: Provide documentation about the uABI compatibility rules Jason Gunthorpe
2026-02-27  1:11 ` [PATCH v2 08/13] RDMA/bnxt_re: Add compatibility checks to the uapi path Jason Gunthorpe
2026-02-27  1:11 ` [PATCH v2 09/13] RDMA/bnxt_re: Add compatibility checks to the uapi path for no data Jason Gunthorpe
2026-02-27  1:11 ` [PATCH v2 10/13] RDMA/bnxt_re: Add missing comp_mask validation Jason Gunthorpe
2026-02-27  1:11 ` [PATCH v2 11/13] RDMA/bnxt_re: Use ib_respond_udata() Jason Gunthorpe
2026-02-27  1:11 ` [PATCH v2 12/13] RDMA/bnxt_re: Use ib_respond_empty_udata() Jason Gunthorpe
2026-02-27  1:11 ` [PATCH v2 13/13] RDMA/bnxt_re: Add BNXT_RE_UCNTX_CMASK_UAPI_COMPAT_SUPPORTED Jason Gunthorpe
2026-03-02 19:24 ` [PATCH v2 00/13] Provide udata helpers and use them in bnxt_re Leon Romanovsky
2026-03-02 19:33   ` Jason Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox