summaryrefslogtreecommitdiff
path: root/drivers/infiniband/hw/mlx4
AgeCommit message (Collapse)Author
20 hoursMerge branch 'for-next' of ↵Mark Brown
ssh://git@gitolite.kernel.org/pub/scm/linux/kernel/git/rdma/rdma.git
12 daysRDMA: fix typos in commentsHemanth Selam
Fix typos in comments, reported by scripts/checkpatch.pl using the misspelling list in scripts/spelling.txt. Only touches comments, no code changes. Assisted-by: Cursor:claude-opus-5 Signed-off-by: Hemanth Selam <hemanth.selam@gmail.com> Link: https://patch.msgid.link/20260907065047.26773-2-hemanth.selam@gmail.com Signed-off-by: Leon Romanovsky <leon@kernel.org>
2026-09-01IB/mlx4: Fix use-after-free on pkey sysfs registration failureShuangpeng Bai
register_pkey_tree() ignores errors from register_one_pkey_tree() and continues registering the remaining slaves. The per-slave error path has already released the pkey parent kobjects, but their pointers remain stored in the device. A later device cleanup therefore passes the stale pointers to kobject_put(), causing a use-after-free. Clear the parent pointers after releasing a failed slave tree and skip unregistered trees during device cleanup. This preserves the existing best-effort registration behavior while preventing a second cleanup of the failed tree. Fixes: c1e7e466120b ("IB/mlx4: Add iov directory in sysfs under the ib device") Cc: stable@vger.kernel.org Signed-off-by: Shuangpeng Bai <shuangpeng.kernel@gmail.com> Link: https://patch.msgid.link/20260816044510.3848996-1-shuangpeng.kernel@gmail.com Signed-off-by: Leon Romanovsky <leon@kernel.org>
2026-07-20RDMA/mlx4: use kzalloc() for the fast registration page listLeon Romanovsky
mlx4_alloc_priv_pages() allocates a zeroed, page-sized buffer for a DMA-to-device page list. kmalloc() provides the required physical contiguity, and a PAGE_SIZE allocation retains the alignment needed to keep the list within one page. Use kzalloc() for the buffer and kfree() on the error and teardown paths. Link: https://patch.msgid.link/20260715-get_pages-to-kmalloc-v1-2-b0b7fce288be@nvidia.com Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
2026-07-20IB/mlx4: Fix stale CM id_map entries when RTU is never receivedPraveen Kumar Kannoju
mlx4_ib_multiplex_cm_handler() allocates an id_map_entry for CM transactions, but the entry is normally released only on DREQ or REJ flows. In the duplicate REP handling scenario, cm_dup_rep_handler() may be invoked when the remote side receives a REP for which no matching cm_id_priv exists. In such cases the CM handshake never reaches RTU, and the sender side may never receive either DREQ or REJ cleanup events. As a result, the allocated id_map_entry remains indefinitely, resulting in a stale mapping leak. Fix this by arming an RTU-abandon cleanup timeout when the id_map_entry is allocated. The timeout uses the mlx4 CM workqueue and the existing schedule_delayed() path, so later DREQ/REJ cleanup can shorten the pending timeout with mod_delayed_work(). Track whether a pending cleanup timeout is still waiting for RTU. RTU cancels only that initial timeout; if DREQ/REJ has already converted it to normal teardown cleanup, a late or duplicate RTU does not cancel the teardown timer. If the RTU timeout callback has already started, leave the entry on the timeout path and make the RTU packet lose that race. Hold id_map_lock while looking up the entry, canceling the RTU timeout, scheduling teardown cleanup, and copying the id values needed by the CM handlers. The delayed-work callback rechecks scheduled_delete under the same lock before removing and freeing the entry, avoiding use-after-free when RTU races with timeout execution. Signed-off-by: Praveen Kumar Kannoju <praveen.kannoju@oracle.com> Link: https://patch.msgid.link/20260715080738.1357072-1-praveen.kannoju@oracle.com Signed-off-by: Leon Romanovsky <leon@kernel.org>
2026-07-14RDMA: Remove redundant memset() from query_device callbacksLeon Romanovsky
The core always hands the driver's query_device() callback a zeroed ib_device_attr. There are only two callers of the op and both clear the structure before invoking it: setup_device() memsets &device->attrs, and ib_uverbs_ex_query_device() passes an on-stack structure initialized to {}. The open-coded memset(props, 0, sizeof(*props)) at the top of the driver callbacks is therefore redundant. Remove it from all drivers. Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
2026-07-13IB/mlx4: delete allocated id_map_entry while sending REJPraveen Kumar Kannoju
The mlx4 CM paravirtualization layer rewrites a VF's local communication ID to a PF-visible ID when CM MADs are sent from the VF. For messages that start or advance a connection from the VF side, such as REQ, REP, MRA and SIDR_REQ, mlx4_ib_multiplex_cm_handler() allocates an id_map_entry when no existing mapping is found. A REJ is different because it is a terminal response to an already known exchange. It should either find an existing id_map_entry, rewrite the local communication ID, and schedule that entry for deletion, or it should pass through unchanged when no mapping exists. Some REJ messages, such as rejects for an inbound REQ before an MRA or REP was sent, do not have an id_map_entry because their local_comm_id is zero. Timeout REJ messages are handled in the initial lookup branch, but a lookup miss there must not fall through to id_map_alloc(); such a miss means there is no existing mapping to translate or delete for the REJ. Commit 227a0e142e37 ("IB/mlx4: Add support for REJ due to timeout") added the timeout REJ case to the initial branch so an outgoing timeout REJ could reuse the id_map_entry that was created when the VF's REQ was multiplexed. Reusing that entry is the useful part: it rewrites the timeout REJ local_comm_id to the same PF-visible ID that was sent in the REQ. If the lookup misses, allocating a new id_map_entry does not help because the peer has never seen that new PF-visible ID, and REJ is not starting a new exchange. Keep timeout REJ handling in the initial lookup branch, but return before allocation if no mapping is found. Handle the other REJ cases with the same lookup-only behavior. When a mapping is found, translate the local communication ID and schedule delayed deletion, as is already done for DREQ and for received REJ in the demux path. When no mapping is found, keep the existing pass-through behavior. Signed-off-by: Praveen Kumar Kannoju <praveen.kannoju@oracle.com> Link: https://patch.msgid.link/20260615171759.557425-1-praveen.kannoju@oracle.com Signed-off-by: Leon Romanovsky <leon@kernel.org>
2026-06-18Merge tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdmaLinus Torvalds
Pull rdma updates from Jason Gunthorpe: "Many AI driven bug fixes, and several big driver API cleanups - Driver bug fixes and minor cleanups in mlx5, hns, rxe, efa, siw, rtrs, mana, irdma, mlx4. Commonly error path flows, integer arithmetic overflows on unsafe data, out of bounds access, and use after free issues under races. - Second half of the new udata API for drivers focusing on uAPI response - bnxt_re supports more options for QP creation that will allow a dv path in rdma-core - Untangle the module dependencies so drivers don't link to ib_uverbs.ko as was originall intended - Provide a new way to handle umems with a consistent simplified uAPI and update several drivers to use it. This brings dmabuf support to more places and more drivers - Support for mlx5 rate limit and packet pacing for UD and UC - A batch of fixes for the new shared FRMR pools infrastructure" * tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma: (148 commits) RDMA/irdma: Replace waitqueue and flag with completion RDMA/hns: Fix memory leak of bonding resources RDMA/rtrs-srv: Bound RDMA-Write length to chunk size in rdma_write_sg docs: infiniband: correct name of option to enable the ib_uverbs module RDMA/bnxt_re: Reject GET_TOGGLE_MEM when toggle page was not allocated RDMA/bnxt_re: Fail DBR related page allocation UAPIs if the feature is disabled RDMA/bnxt_re: Avoid repeated requests to allocate WC pages RDMA/bnxt_re: Proper rollback if the ioremap fails RDMA/bnxt_re: Add a max slot check for SQ RDMA/bnxt_re: Avoid displaying the kernel pointer RDMA/bnxt_re: Free CQ toggle page after firmware teardown RDMA/bnxt_re: Free SRQ toggle page after firmware teardown RDMA/bnxt_re: Initialize dpi variable to zero ABI: sysfs-class-infiniband: minor cleanup RDMA/mlx5: Release the HW‑provided UAR index rather than the SW one RDMA/mlx5: Fix undefined shift of user RQ WQE size RDMA/mlx5: Remove raw RSS QP restrack tracking RDMA/mlx5: Remove DCT restrack tracking RDMA/mlx5: Drop FRMR pool handle on UMR revoke failure RDMA/core: Add ib_frmr_pool_drop for unrecoverable handles ...
2026-06-09IB/mlx4: Fill in the access_flags if IB_MR_REREG_ACCESS is not specifiedJason Gunthorpe
Sashiko noticed mlx4 was using whatever random access flags were provided when IB_MR_REREG_ACCESS is not used. Since IB_MR_REREG_TRANS needs access_flags it used the random ones which means it doesn't work sensibly if userspace provides only IB_MR_REREG_TRANS. Keep track of the current access_flag of the MR and use it if the user does not specify one. Also fixup a little confusion around mmr.access, it is the HW access flags so the convert_access() was missing. But nothing reads this by the time rereg_mr can happen. Fixes: 9376932d0c26 ("IB/mlx4_ib: Add support for user MR re-registration") Link: https://patch.msgid.link/r/0-v1-29ca7a402625+ddd6-mlx4_rereg_flags_jgg@nvidia.com Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2026-06-08RDMA: During rereg_mr ensure that REREG_ACCESS is compatibleJason Gunthorpe
If IB_MR_REREG_ACCESS changes from RO to RW then the umem has to be re-evaluated to ensure it is properly pinned as RW. Since the umem is hidden inside each driver's mr struct add a ib_umem_check_rereg() function that each driver has to call before processing IB_MR_REREG_ACCESS. mlx4 has to retain its duplicate ib_access_writable check because it implements IB_MR_REREG_ACCESS | IB_MR_REREG_TRANS by changing both items in place sequentially while the MR is live, so it will continue to not support this combination. Cc: stable@vger.kernel.org Fixes: b40656aa7d55 ("RDMA/umem: remove FOLL_FORCE usage") Link: https://patch.msgid.link/r/0-v1-06fb1a2d6cf5+107-rereg_access_jgg@nvidia.com Reported-by: Philip Tsukerman <philiptsukerman@gmail.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2026-06-03RDMA: Update the query_device() opJason Gunthorpe
This op hasn't followed the normal pattern of passing NULL for udata when invoked by the kernel. Instead the kernel caller creates a dummy ib_udata on the stack and passes that in. It does not seem to currently be a bug, but this flow should be modernized to use the new API flow and in the process accept NULL as well. Only mlx4 uses an input request structure, have every other driver call ib_is_udata_in_empty() to enforce the lack of request structs. Use ib_respond_empty_udata() in every driver that does not use a response struct. Ensure a check for NULL udata before calling ib_respond_udata() in bnxt_re, efa, and mlx5. Make mlx4 safe to be called with NULL. Link: https://patch.msgid.link/r/2-v1-922fa8e828ba+f7-ib_udata_stack_jgg@nvidia.com Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2026-05-29RDMA/mlx4: Use ib_umem_get_cq_buf() for user CQ bufferJiri Pirko
Pin the user CQ buffer with ib_umem_get_cq_buf() and take ownership of the umem in the driver; fall back to ib_umem_get_va() for the legacy UHW VA path. Apply the same ownership pattern to the resize path. Link: https://patch.msgid.link/r/20260529134312.2836341-11-jiri@resnulli.us Signed-off-by: Jiri Pirko <jiri@nvidia.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2026-05-29RDMA/umem: Rename ib_umem_get() to ib_umem_get_va()Jiri Pirko
The new umem getter family being introduced in follow-up patches need a fitting name for the central all-source helper that resolves attributes, legacy fillers and a UHW VA fallback. Rename the existing VA-pinning helper ib_umem_get() to ib_umem_get_va() so the name is freed up. The new name is consistent with names of rest of the helpers that are about to be introduced. Link: https://patch.msgid.link/r/20260529134312.2836341-2-jiri@resnulli.us Signed-off-by: Jiri Pirko <jiri@nvidia.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2026-05-25Merge tag 'v7.1-rc5' into rdma.git for-nextJason Gunthorpe
For dependencies in the following patches Resolve conflicts, use the goto labels from the rc tag. * tag 'v7.1-rc5': (1526 commits) Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2026-05-25IB/mlx4: Fix refcount leak in add_port() error pathGuangshuo Li
After kobject_init_and_add(), the lifetime of the embedded struct kobject is expected to be managed through the kobject core reference counting. In add_port(), failure paths after kobject_init_and_add() must not free struct mlx4_port directly, because the embedded kobject is then managed by the kobject core. Freeing it directly leaves the kobject reference counting unbalanced and can lead to incorrect lifetime handling. Allocate the pkey and gid attribute arrays before kobject_init_and_add(), so failures before kobject initialization can be handled by directly freeing the allocated memory. Once kobject_init_and_add() has been called, unwind later failures by removing any successfully created sysfs groups, calling kobject_del(), and then releasing the embedded kobject with kobject_put(). Fixes: c1e7e466120b ("IB/mlx4: Add iov directory in sysfs under the ib device") Link: https://patch.msgid.link/r/20260518021910.972900-1-lgs201920130244@gmail.com Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2026-05-18RDMA: Add missed = {} initialization to uresp structsJason Gunthorpe
All of these are fully initialized so no bugs are being fixed. Add the missing initializer as a precaution against future changes. Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Leon Romanovsky <leon@kernel.org>
2026-05-18RDMA: Use proper driver data response structs instead of open codingJason Gunthorpe
At some point the response structs were added and rdma-core is using them, but the kernel was not changed to use them as well. Replace the open-coded copy with the right struct and ib_respond_udata(). Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Leon Romanovsky <leon@kernel.org>
2026-05-18RDMA/mlx: Replace response_len with ib_respond_udata()Jason Gunthorpe
The Mellanox drivers have a pattern where they compute the response length they think they need based on what the user asked for, then blindly write that ignoring the provided size limit on the response structure. Drop this and just use ib_respond_udata() which caps the response struct to the user's memory, which is fine for what mlx5 is doing. Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Leon Romanovsky <leon@kernel.org>
2026-05-18RDMA: Convert drivers using sizeof() to ib_respond_udata()Jason Gunthorpe
Convert the pattern: ib_copy_to_udata(udata, &resp, sizeof(resp)); Using Coccinelle: @@ identifier resp; expression udata; @@ - ib_copy_to_udata(udata, &resp, sizeof(resp)) + ib_respond_udata(udata, resp) Run another pass with AI to propagate the return code correctly and remove redundant prints. Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Leon Romanovsky <leon@kernel.org>
2026-05-18RDMA: Use ib_is_udata_in_empty() for places calling ib_is_udata_cleared()Jason Gunthorpe
Convert the pattern: if (udata->inlen && !ib_is_udata_cleared(udata, 0, udata->inlen)) Using Coccinelle: virtual patch virtual context virtual report @@ expression udata; @@ ( - udata->inlen && !ib_is_udata_cleared(udata, 0, udata->inlen) + !ib_is_udata_in_empty(udata) | - udata->inlen > 0 && !ib_is_udata_cleared(udata, 0, udata->inlen) + !ib_is_udata_in_empty(udata) ) @@ expression udata; @@ - udata && udata->inlen && !ib_is_udata_cleared(udata, 0, udata->inlen) + !ib_is_udata_in_empty(udata) These cases are already checking for zeroed data that the kernel does not understand. Run another pass with AI to propagate the return code correctly and remove redundant prints. Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Leon Romanovsky <leon@kernel.org>
2026-05-18RDMA/mlx4: Use secs_to_jiffies() instead of open-codingRohit Chavan
The conversion from seconds to jiffies is currently performed by multiplying the value by 1000 and passing it to msecs_to_jiffies(). Use the more direct secs_to_jiffies() helper instead. This simplifies the code, improves readability, and avoids the manual multiplication step by using the dedicated kernel API. Signed-off-by: Rohit Chavan <roheetchavan@gmail.com> Link: https://patch.msgid.link/20260505075308.1754861-1-roheetchavan@gmail.com Signed-off-by: Leon Romanovsky <leon@kernel.org>
2026-05-02RDMA/mlx4: Fix resource leak on error in mlx4_ib_create_srq()Jason Gunthorpe
Sashiko points out that mlx4_srq_alloc() was not undone during error unwind, add the missing call to mlx4_srq_free(). Cc: stable@vger.kernel.org Fixes: 225c7b1feef1 ("IB/mlx4: Add a driver Mellanox ConnectX InfiniBand adapters") Link: https://sashiko.dev/#/patchset/0-v1-e911b76a94d1%2B65d95-rdma_udata_rep_jgg%40nvidia.com?part=8 Link: https://patch.msgid.link/r/11-v1-41f3135e5565+9d2-rdma_ai_fixes1_jgg@nvidia.com Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2026-03-31RDMA: Remove redundant = {} for udata req structsJason Gunthorpe
Now that all of the udata request structs are loaded with the helpers the callers should not pre-zero them. The helpers all guarantee that the entire struct is filled with something. Reviewed-by: Long Li <longli@microsoft.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
2026-03-31RDMA: Use ib_copy_validate_udata_in_cm() for zero comp_maskJason Gunthorpe
All of these cases require a 0 comp_mask. Consolidate these into using ib_copy_validate_udata_in_cm() and remove the open coded comp_mask test. Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
2026-03-31RDMA/mlx4: Use ib_copy_validate_udata_in() for QPJason Gunthorpe
Move the validation of the udata to the same function that copies it. Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
2026-03-31RDMA/mlx4: Use ib_copy_validate_udata_in()Jason Gunthorpe
Follow the last member of each struct at the point MLX4_IB_UVERBS_ABI_VERSION was set to 4. Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
2026-03-31RDMA: Consolidate patterns with sizeof() to ib_copy_validate_udata_in()Jason Gunthorpe
Similar to the prior patch, these patterns are open coding an offsetofend() using sizeof(), which targets the last member of the current struct. Reviewed-by: Long Li <longli@microsoft.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Bernard Metzler <bernard.metzler@linux.dev> Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
2026-03-31RDMA: Consolidate patterns with offsetofend() to ib_copy_validate_udata_in()Jason Gunthorpe
Go treewide and consolidate all existing patterns using: * offsetofend() and variations * ib_is_udata_cleared() * ib_copy_from_udata() into a direct call to the new ib_copy_validate_udata_in(). Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
2026-03-30RDMA/mlx4: Restrict external umem for CQ when copy_to_user() is usedLeon Romanovsky
When the mlx4 firmware reports the MLX4_DEV_CAP_FLAG2_SW_CQ_INIT capability, libmlx4 from the rdma-core package expects the driver to initialize memory at the address provided in the buf_addr parameter of ucmd. This behavior cannot be supported by any external umem implementation, so restrict it accordingly. Fixes: f45f195af521 ("RDMA/mlx4: Introduce a modern CQ creation interface") Reported-by: Jiri Pirko <jiri@nvidia.com> Link: https://patch.msgid.link/20260325-fix-mlx4-external-umem-v1-1-1c7c0e779329@nvidia.com Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
2026-03-30RDMA: Properly propagate the number of CQEs as unsigned intLeon Romanovsky
Instead of checking whether the number of CQEs is negative or zero, fix the .resize_user_cq() declaration to use unsigned int. This better reflects the expected value range. The sanity check is then handled correctly in ib_uvbers. Link: https://patch.msgid.link/20260319-resize_cq-cqe-v1-1-b78c6efc1def@nvidia.com Reviewed-by: Zhu Yanjun <yanjun.zhu@linux.dev> Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
2026-03-30RDMA: Clarify that CQ resize is a user‑space verbLeon Romanovsky
The CQ resize operation is used only by uverbs. Make this explicit. Link: https://patch.msgid.link/20260318-resize_cq-type-v1-2-b2846ed18846@nvidia.com Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
2026-03-02RDMA: Complete k[z|m|c]alloc-to-k[z|m]alloc_obj conversionLeon Romanovsky
Commits bf4afc53b77a ("Convert 'alloc_obj' family to use the new default GFP_KERNEL argument") and 69050f8d6d07 ("treewide: Replace kmalloc with kmalloc_obj for non-scalar types") updated various k[z|m|c]alloc calls to their k[z|m]alloc_obj counterparts. This commit finalizes that transition within the RDMA subsystem. Link: https://patch.msgid.link/20260226-complete-alloc-conversion-v1-1-ebf1df1c2518@nvidia.com Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
2026-02-25RDMA/mlx4: Remove unused create_flags field from CQ structureLeon Romanovsky
The CQ creation flags do not need to be cached, as they are used immediately at the point where they are stored. Remove the unused field and reclaim 4 bytes. Link: https://patch.msgid.link/20260213-refactor-umem-v1-14-f3be85847922@nvidia.com Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
2026-02-25RDMA/mlx4: Introduce a modern CQ creation interfaceLeon Romanovsky
The uverbs CQ creation UAPI allows users to supply their own umem when creating a CQ. Update mlx4 to support this model while preserving compatibility with the legacy interface that allocates umem internally. Link: https://patch.msgid.link/20260213-refactor-umem-v1-13-f3be85847922@nvidia.com Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
2026-02-25RDMA/mlx4: Inline mlx4_ib_get_cq_umem into callersLeon Romanovsky
Inline the mlx4_ib_get_cq_umem helper function into its two call sites (mlx4_ib_create_cq and mlx4_alloc_resize_umem) to prepare for the transition to modern CQ creation interface. Link: https://patch.msgid.link/20260213-refactor-umem-v1-12-f3be85847922@nvidia.com Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
2026-02-25RDMA: Move DMA block iterator logic into dedicated filesLeon Romanovsky
The DMA iterator logic was mixed into verbs and umem-specific code, forcing all users to include rdma/ib_umem.h. Move the block iterator logic into iter.c and rdma/iter.h so that rdma/ib_umem.h and rdma/ib_verbs.h can be separated in a follow-up patch. Link: https://patch.msgid.link/20260213-refactor-umem-v1-1-f3be85847922@nvidia.com Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
2026-02-22Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL usesKees Cook
Conversion performed via this Coccinelle script: // SPDX-License-Identifier: GPL-2.0-only // Options: --include-headers-for-types --all-includes --include-headers --keep-comments virtual patch @gfp depends on patch && !(file in "tools") && !(file in "samples")@ identifier ALLOC = {kmalloc_obj,kmalloc_objs,kmalloc_flex, kzalloc_obj,kzalloc_objs,kzalloc_flex, kvmalloc_obj,kvmalloc_objs,kvmalloc_flex, kvzalloc_obj,kvzalloc_objs,kvzalloc_flex}; @@ ALLOC(... - , GFP_KERNEL ) $ make coccicheck MODE=patch COCCI=gfp.cocci Build and boot tested x86_64 with Fedora 42's GCC and Clang: Linux version 6.19.0+ (user@host) (gcc (GCC) 15.2.1 20260123 (Red Hat 15.2.1-7), GNU ld version 2.44-12.fc42) #1 SMP PREEMPT_DYNAMIC 1970-01-01 Linux version 6.19.0+ (user@host) (clang version 20.1.8 (Fedora 20.1.8-4.fc42), LLD 20.1.8) #1 SMP PREEMPT_DYNAMIC 1970-01-01 Signed-off-by: Kees Cook <kees@kernel.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2026-02-21Convert more 'alloc_obj' cases to default GFP_KERNEL argumentsLinus Torvalds
This converts some of the visually simpler cases that have been split over multiple lines. I only did the ones that are easy to verify the resulting diff by having just that final GFP_KERNEL argument on the next line. Somebody should probably do a proper coccinelle script for this, but for me the trivial script actually resulted in an assertion failure in the middle of the script. I probably had made it a bit _too_ trivial. So after fighting that far a while I decided to just do some of the syntactically simpler cases with variations of the previous 'sed' scripts. The more syntactically complex multi-line cases would mostly really want whitespace cleanup anyway. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2026-02-21Convert 'alloc_obj' family to use the new default GFP_KERNEL argumentLinus Torvalds
This was done entirely with mindless brute force, using git grep -l '\<k[vmz]*alloc_objs*(.*, GFP_KERNEL)' | xargs sed -i 's/\(alloc_objs*(.*\), GFP_KERNEL)/\1)/' to convert the new alloc_obj() users that had a simple GFP_KERNEL argument to just drop that argument. Note that due to the extreme simplicity of the scripting, any slightly more complex cases spread over multiple lines would not be triggered: they definitely exist, but this covers the vast bulk of the cases, and the resulting diff is also then easier to check automatically. For the same reason the 'flex' versions will be done as a separate conversion. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2026-02-21treewide: Replace kmalloc with kmalloc_obj for non-scalar typesKees Cook
This is the result of running the Coccinelle script from scripts/coccinelle/api/kmalloc_objs.cocci. The script is designed to avoid scalar types (which need careful case-by-case checking), and instead replace kmalloc-family calls that allocate struct or union object instances: Single allocations: kmalloc(sizeof(TYPE), ...) are replaced with: kmalloc_obj(TYPE, ...) Array allocations: kmalloc_array(COUNT, sizeof(TYPE), ...) are replaced with: kmalloc_objs(TYPE, COUNT, ...) Flex array allocations: kmalloc(struct_size(PTR, FAM, COUNT), ...) are replaced with: kmalloc_flex(*PTR, FAM, COUNT, ...) (where TYPE may also be *VAR) The resulting allocations no longer return "void *", instead returning "TYPE *". Signed-off-by: Kees Cook <kees@kernel.org>
2025-11-06RDMA/mlx4: WQ_PERCPU added to alloc_workqueue usersMarco Crivellari
Currently if a user enqueue a work item using schedule_delayed_work() the used wq is "system_wq" (per-cpu wq) while queue_delayed_work() use WORK_CPU_UNBOUND (used when a cpu is not specified). The same applies to schedule_work() that is using system_wq and queue_work(), that makes use again of WORK_CPU_UNBOUND. This lack of consistentcy cannot be addressed without refactoring the API. alloc_workqueue() treats all queues as per-CPU by default, while unbound workqueues must opt-in via WQ_UNBOUND. This default is suboptimal: most workloads benefit from unbound queues, allowing the scheduler to place worker threads where they’re needed and reducing noise when CPUs are isolated. This change adds a new WQ_PERCPU flag to explicitly request alloc_workqueue() to be per-cpu when WQ_UNBOUND has not been specified. With the introduction of the WQ_PERCPU flag (equivalent to !WQ_UNBOUND), any alloc_workqueue() caller that doesn’t explicitly specify WQ_UNBOUND must now use WQ_PERCPU. Once migration is complete, WQ_UNBOUND can be removed and unbound will become the implicit default. CC: Yishai Hadas <yishaih@nvidia.com> Suggested-by: Tejun Heo <tj@kernel.org> Signed-off-by: Marco Crivellari <marco.crivellari@suse.com> Link: https://patch.msgid.link/20251101163121.78400-5-marco.crivellari@suse.com Signed-off-by: Leon Romanovsky <leon@kernel.org>
2025-09-21RDMA: Use %pe format specifier for error pointersLeon Romanovsky
Convert error logging throughout the RDMA subsystem to use the %pe format specifier instead of PTR_ERR() with integer format specifiers. Link: https://patch.msgid.link/e81ec02df1e474be20417fb62e779776e3f47a50.1758217936.git.leon@kernel.org Reviewed-by: Zhu Yanjun <yanjun.zhu@linux.dev> Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
2025-07-23IB: Extend UVERBS_METHOD_REG_MR to get DMAHYishai Hadas
Extend UVERBS_METHOD_REG_MR to get DMAH and pass it to all drivers. It will be used in mlx5 driver as part of the next patch from the series. Signed-off-by: Yishai Hadas <yishaih@nvidia.com> Reviewed-by: Edward Srouji <edwards@nvidia.com> Link: https://patch.msgid.link/2ae1e628c0675db81f092cc00d3ad6fbf6139405.1752752567.git.leon@kernel.org Signed-off-by: Leon Romanovsky <leon@kernel.org>
2025-04-07RDMA: Replace msecs_to_jiffies with secs_to_jiffies for timeoutPeng Jiang
In drivers/infiniband/hw/mlx4/mcg.c and drivers/infiniband/hw/mlx5/mr.c, `msecs_to_jiffies` is used to convert milliseconds to jiffies. For constant milliseconds, using `msecs_to_jiffies` introduces additional computational overhead. For example, it is unnecessary to check if m > jiffies_to_msecs(MAX_JIFFY_OFFSET) or (int)m < 0 for constants, while using `secs_to_jiffies` can avoid these extra calculations. Link: https://patch.msgid.link/r/20250326221955611qu6Ix3Pt5WgKvhL6sTySX@zte.com.cn Signed-off-by: Peng Jiang <jiang.peng9@zte.com.cn> Signed-off-by: Ye Xingchen <ye.xingchen@zte.com.cn> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2024-12-25RDMA/mlx4: Support report_port_event() opsYuyu Li
In addition to dispatching event, some private stuffs need to be done in this driver's link status event handler. Implement the new report_port_event() ops with the link status event codes. Signed-off-by: Yuyu Li <liyuyu6@huawei.com> Signed-off-by: Junxian Huang <huangjunxian6@hisilicon.com> Signed-off-by: Leon Romanovsky <leon@kernel.org>
2024-12-10RDMA/mlx4: Use DMA iterator to write MTTLeon Romanovsky
Replace an open coding of rdma_umem_for_each_dma_block() with the proper function. Link: https://patch.msgid.link/0bf595962c964fb8918743405acf9103a5a85983.1733233299.git.leonro@nvidia.com Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
2024-12-10RDMA/mlx4: Use ib_umem_find_best_pgsz() to calculate MTT sizeLeon Romanovsky
Convert mlx4 to use ib_umem_find_best_pgsz() instead of open-coded variant to calculate MTT size. Link: https://patch.msgid.link/c39ec6f5d4664c439a72f2961728ebb5895a9f07.1733233299.git.leonro@nvidia.com Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
2024-12-10RDMA/mlx4: Avoid false error about access to uninitialized gids arrayLeon Romanovsky
Smatch generates the following false error report: drivers/infiniband/hw/mlx4/main.c:393 mlx4_ib_del_gid() error: uninitialized symbol 'gids'. Traditionally, we are not changing kernel code and asking people to fix the tools. However in this case, the fix can be done by simply rearranging the code to be more clear. Fixes: e26be1bfef81 ("IB/mlx4: Implement ib_device callbacks") Link: https://patch.msgid.link/6a3a1577463da16962463fcf62883a87506e9b62.1733233426.git.leonro@nvidia.com Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
2024-08-23RDMA/mlx4: Simplify an alloc_ordered_workqueue() invocationJinjie Ruan
Let alloc_ordered_workqueue() format the workqueue name instead of calling snprintf() explicitly. Link: https://patch.msgid.link/r/20240823101840.515398-5-ruanjinjie@huawei.com Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2024-08-23RDMA/mlx4: Simplify an alloc_ordered_workqueue() invocationJinjie Ruan
Let alloc_ordered_workqueue() format the workqueue name instead of calling snprintf() explicitly. Link: https://patch.msgid.link/r/20240823101840.515398-4-ruanjinjie@huawei.com Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>