net: mana: Clear RDMA teardown and suspend state in mana_rdma_probe()
Subsystems (5)
PATCH v2 1/1 net: mana: Clear RDMA teardown and suspend state in mana_rdma_probe()
mana_rdma_remove() sets gd->rdma_teardown to stop mana_rdma_service_handle() from acting on servicing events, but nothing ever clears it. A hardware service reset (GDMA_EQE_HWC_RESET_REQUEST) goes through mana_gd_suspend() -> mana_rdma_remove() and mana_gd_resume() -> mana_rdma_probe(), so from the first reset onwards every GDMA_EQE_HWC_SOC_SERVICE event returns early and RDMA suspend/resume servicing is silently dropped for the life of the device.
gd->is_suspended has the same problem: it is set when servicing removes the adev and is cleared only by a matching resume. A reset while RDMA is suspended re-adds the adev but leaves is_suspended set, so a later resume event calls add_adev() on top of a live gd->adev and leaks it. This is currently masked by the rdma_teardown bug.
Clear both in mana_rdma_probe(). is_suspended is otherwise only touched by mana_rdma_service_handle() on the ordered service workqueue, so clear it while rdma_teardown still gates that handler and re-open the gate with smp_store_release(), paired with smp_load_acquire() in the handler.
---
Changes in v2:
- No functional change; the diff is identical to v1, rebased on net/main.
- Target the net tree explicitly in the subject prefix; v1 omitted it and the netdev CI guessed net-next, where the Fixes: tag is not evaluated.
v1: https://lore.kernel.org/all/[email protected]/
--- drivers/net/ethernet/microsoft/mana/mana_en.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/net/ethernet/microsoft/mana/mana_en.c +13 -1
@@ -3983,7 +3983,8 @@ static void mana_rdma_service_handle(struct work_struct *work)struct device *dev = gd->gdma_context->dev;int ret; -if (READ_ONCE (gd->rdma_teardown)) +/* Pairs with the smp_store_release() in mana_rdma_probe(). */ +if (smp_load_acquire (&gd->rdma_teardown)) goto out;switch (serv_work->event) {
@@ -4279,6 +4280,17 @@ int mana_rdma_probe(struct gdma_dev *gd)if (err)return err; +/* Clear the state left by a previous mana_rdma_remove() so servicing +* events are handled again after a reset cycle. +*/ + gd->is_suspended = false; + +/* Publish is_suspended before re-opening the gate, so the handler +* cannot act on a stale value. Pairs with the smp_load_acquire() +* in mana_rdma_service_handle(). +*/ +smp_store_release (&gd->rdma_teardown, false); + err =add_adev (gd,"rdma" );if (err)mana_gd_deregister_device (gd);
Signature · 1 line
2.43.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Lockless gate reopening in `mana_rdma_probe()` exposes a race window that can silently drop…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Lockless gate reopening in mana_rdma_probe() exposes a race window that can silently drop hardware service events. --
commit 92507b04de784a341e9ea7d0275d9b3dbe00e839
Author: Long Li <[email protected]>
net: mana: Clear RDMA teardown and suspend state in mana_rdma_probe()
This commit clears the rdma_teardown and is_suspended flags during probe to ensure hardware service events are handled correctly after a reset cycle.
Quoted 4 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +0
-0
[ ... ]
Quoted 6 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +2
-0@@ -4279,6 +4280,17 @@ int mana_rdma_probe(struct gdma_dev *gd)if (err)return err; +/* Clear the state left by a previous mana_rdma_remove() so servicing +* events are handled again after a reset cycle.
drivers/net/ethernet/microsoft/mana/mana_en.c int mana_rdma_probe(struct gdma_dev *gd) · line 4294
Quoted 10 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +9
-0+*/ + gd->is_suspended = false; + +/* Publish is_suspended before re-opening the gate, so the handler +* cannot act on a stale value. Pairs with the smp_load_acquire() +* in mana_rdma_service_handle(). +*/ +smp_store_release (&gd->rdma_teardown, false); + err =add_adev (gd,"rdma" );
[Severity: High]
Does opening the rdma_teardown gate here create a race window where hardware service events can be silently dropped?
Because mana_gd_register_device(gd) was called earlier in this function, the hardware can now generate events. If an event like GDMA_SERVICE_TYPE_RDMA_SUSPEND fires immediately after smp_store_release() clears rdma_teardown, the ordered workqueue will run mana_rdma_service_handle().
The handler will pass the rdma_teardown check but evaluate !gd->adev as true because add_adev() hasn't completed yet:
drivers/net/ethernet/microsoft/mana/mana_en.c:mana_rdma_service_handle() {
...
case GDMA_SERVICE_TYPE_RDMA_SUSPEND:
if (!gd->adev || gd->is_suspended)
break;
...
}This causes the event to be dropped, which could create a permanent state inconsistency between the OS and the hardware. Should the gate be opened after add_adev() successfully assigns gd->adev?
Quoted 2 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +0
-0if (err)mana_gd_deregister_device (gd);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 79 lines
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Lockless gate reopening inmana_rdma_probe()exposes a race window that can silently drop hardware service events.
--commit
92507b04de784a341e9ea7d0275d9b3dbe00e839
Author: Long Li <[email protected]>net: mana: Clear RDMA teardown and suspend state in
mana_rdma_probe()This commit clears the
rdma_teardownandis_suspendedflags during probe to ensure hardware service events are handled correctly after a reset cycle.Link:
https://lore.ke/
rnel.org%2Fall%2F20260826235940.1869565-1- longli%40microsoft.com%2F&data=05%7C02%7Clongli%40microsoft.com%7Ce 4ad1794c21a42eae10608df0562428a%7C72f988bf86f141af91ab2d7cd011db4 7%7C1%7C0%7C639235591719595495%7CUnknown%7CTWFpbGZsb3d8eyJFb XB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWF pbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=DgiM6eURZJPqg1Kw%2F107 aSEqL3jkvp3JzFytQ6oXEJ4%3D&reserved=0Quoted 5 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +0
-0[ ... ]
drivers/net/ethernet/microsoft/mana/mana_en.c int mana_rdma_probe(struct gdma_dev *gd) · line 4283
Quoted 5 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +1
-0@@ -4279,6 +4280,17 @@ int mana_rdma_probe(struct gdma_dev *gd)if (err)return err; +/* Clear the state left by a previous mana_rdma_remove() so servicing
drivers/net/ethernet/microsoft/mana/mana_en.c int mana_rdma_probe(struct gdma_dev *gd) · line 4294
Quoted 11 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +10
-0+* events are handled again after a reset cycle. +*/ + gd->is_suspended = false; + +/* Publish is_suspended before re-opening the gate, so the handler +* cannot act on a stale value. Pairs with the smp_load_acquire() +* in mana_rdma_service_handle(). +*/ +smp_store_release (&gd->rdma_teardown, false); + err =add_adev (gd,"rdma" );[Severity: High]
Does opening therdma_teardowngate here create a race window where hardware service events can be silently dropped?Because
mana_gd_register_device(gd)was called earlier in this function, the hardware can now generate events. If an event likeGDMA_SERVICE_TYPE_RDMA_SUSPENDfires immediately aftersmp_store_release()clearsrdma_teardown, the ordered workqueue will runmana_rdma_service_handle().The handler will pass the
rdma_teardowncheck but evaluate !gd->adev as true becauseadd_adev()hasn't completed yet:drivers/net/ethernet/microsoft/mana/mana_en.c:mana_rdma_service_handl
e() { ... case GDMA_SERVICE_TYPE_RDMA_SUSPEND: if (!gd->adev || gd->is_suspended) break; ... }This causes the event to be dropped, which could create a permanent state inconsistency between the OS and the hardware. Should the gate be opened after
add_adev()successfully assignsgd->adev?drivers/net/ethernet/microsoft/mana/mana_en.c int mana_rdma_probe(struct gdma_dev *gd) · line 4296
Quoted 2 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +0
-0if (err)mana_gd_deregister_device (gd);
Quoted 10 lines
--
Sashiko AI
review * https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%25
2Fsashiko.dev%2F%23%2Fpatchset%2F20260828001202.2110938-1- longli%40microsoft.com%3Fpart%3D1&data=05%7C02%7Clongli%40microsoft. com%7Ce4ad1794c21a42eae10608df0562428a%7C72f988bf86f141af91ab2d7c d011db47%7C1%7C0%7C639235591719616083%7CUnknown%7CTWFpbGZsb 3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkF OIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=3TUhCla0LzwnJhxJ NJ5xptY5YUbnLeiax%2FT4HpHRpFA%3D&reserved=0
This is not an issue introduced by this patch.
Some background on what the patch fixes first, because it is the same code path.
There are two bugs, both in state that outlives a reset cycle.
gd is &gc->mana_ib, embedded in the gdma_context. A hardware service reset runs mana_serv_reset(), which calls mana_gd_suspend() and then mana_gd_resume() on the same pci_get_drvdata() pointer -- gc is not freed and reallocated, so everything in gd survives the cycle.
1) rdma_teardown is set by mana_rdma_remove() and never cleared.
mana_gd_suspend() -> mana_rdma_remove() sets rdma_teardown = true
mana_gd_resume() -> mana_rdma_probe() left it set
From the first reset onward, mana_rdma_service_handle() returns at
if (READ_ONCE(gd->rdma_teardown))
goto out; so every GDMA_EQE_HWC_SOC_SERVICE event is discarded for the remaining life of the device. RDMA suspend/resume servicing stops working entirely, and the host and hardware disagree permanently.
2) is_suspended has the same lifetime problem, and it is the only guard on the resume path -- note that the RDMA_RESUME case does not also test gd->adev:
case GDMA_SERVICE_TYPE_RDMA_RESUME:
if (!gd->is_suspended)
break;
ret = add_adev(gd, "rdma"); If a reset happens while RDMA is suspended, mana_rdma_remove() finds gd->adev already NULL and does not touch is_suspended, then mana_rdma_probe() re-adds the adev. is_suspended is still true, so a later resume event calls add_adev() on top of a live gd->adev. add_adev() assigns gd->adev last, so the pointer is overwritten and the previous auxiliary device stays registered but untracked. mana_rdma_remove() then only removes the tracked one.
Today this is masked by bug 1: the handler never gets that far. Clearing rdma_teardown alone would unmask it, which is why both flags are cleared together.
On the window you point at:
The !gd->adev check is not modified by this patch, and the race is not introduced by it. It already exists on the initial probe path in
mainline: gc is vzalloc()ed, so rdma_teardown starts clear, and mana_gd_setup() creates the service workqueue and enables the HWC interrupts (gdma_main.c) before mana_gd_probe() calls mana_rdma_probe() -> add_adev(). A SUSPEND arriving there passes the gate, sees gd->adev == NULL and is dropped, with no patch applied.
Before this patch the reset path did not reach that check, but only because the gate was shut forever and the event was already being dropped unconditionally -- along with every event after it. So there is no input for which this patch loses an event that mainline would have delivered; the set of dropped events strictly shrinks.
Closing the remaining add_adev() window needs probe to be serialized against the service workqueue, or the pending request to be latched and replayed once gd->adev is published. That is a behaviour change to the servicing protocol rather than part of this fix, so I would prefer to do it as a follow-up patch.
Thanks,
Long
Simon Horman
reviewerThis is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
Full review at: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/[email protected]?part=1
---
net: mana: Clear RDMA teardown and suspend state in mana_rdma_probe()
This clears gd->rdma_teardown and gd->is_suspended in mana_rdma_probe() so that RDMA servicing events are handled again after a hardware service reset cycle. The gate is re-opened with smp_store_release(), paired with a new smp_load_acquire() in mana_rdma_service_handle().
Quoted 14 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +2
-1@@ -3983,7 +3983,8 @@ static void mana_rdma_service_handle(struct work_struct *work)struct device *dev = gd->gdma_context->dev;int ret; -if (READ_ONCE (gd->rdma_teardown)) +/* Pairs with the smp_store_release() in mana_rdma_probe(). */ +if (smp_load_acquire (&gd->rdma_teardown)) goto out;switch (serv_work->event) {
[ ... ]
drivers/net/ethernet/microsoft/mana/mana_en.c int mana_rdma_probe(struct gdma_dev *gd) · line 4286
Quoted 8 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +4
-0@@ -4279,6 +4280,17 @@ int mana_rdma_probe(struct gdma_dev *gd)if (err)return err; +/* Clear the state left by a previous mana_rdma_remove() so servicing +* events are handled again after a reset cycle. +*/ + gd->is_suspended = false;
[Severity: Low]
Does the invariant described in the commit message hold on the initial probe path? The commit message says:
is_suspended is otherwise only touched by mana_rdma_service_handle() on the ordered service workqueue, so clear it while rdma_teardown still gates that handler
That is true for the reset path, where mana_rdma_remove() set rdma_teardown and flushed gc->service_wq first. On mana_gd_probe() -> mana_probe() -> mana_rdma_probe() the gate was never closed: gc comes from vzalloc(), so both gd->rdma_teardown and gd->is_suspended are already false, and mana_gd_setup() has already created gc->service_wq and brought up the HWC and EQs before mana_rdma_probe() runs.
So on that path the smp_store_release() is a false -> false store and the handler's smp_load_acquire() has no state change to order against, while the plain write of gd->is_suspended here (and add_adev()'s plain write of gd->adev) can run concurrently with the handler's plain accesses to the same two fields with no lock on either side.
The outcome looks benign today, since is_suspended is already false and the handler is a no-op in that window, but would it be worth wording the comment and commit message so they only claim the property that actually holds?
drivers/net/ethernet/microsoft/mana/mana_en.c int mana_rdma_probe(struct gdma_dev *gd) · line 4296
Quoted 10 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +7
-0+ +/* Publish is_suspended before re-opening the gate, so the handler +* cannot act on a stale value. Pairs with the smp_load_acquire() +* in mana_rdma_service_handle(). +*/ +smp_store_release (&gd->rdma_teardown, false); + err =add_adev (gd,"rdma" );if (err)mana_gd_deregister_device (gd);
[Severity: Medium]
Is the gate re-opened too early here, i.e. before add_adev() has published gd->adev? add_adev() stores it as its last step, after auxiliary_device_add() has already synchronously probed mana_ib:
drivers/net/ethernet/microsoft/mana/mana_en.c:add_adev() {
...
ret = auxiliary_device_add(adev);
if (ret)
goto add_fail;
gd->adev = adev;
...
}A GDMA_SERVICE_TYPE_RDMA_SUSPEND work item that runs inside that window passes the acquire load, but sees gd->adev == NULL because remove_adev() cleared it during the preceding mana_rdma_remove():
mana_rdma_service_handle() {
case GDMA_SERVICE_TYPE_RDMA_SUSPEND:
if (!gd->adev || gd->is_suspended)
break;
remove_adev(gd);
gd->is_suspended = true;
break;so the suspend event is consumed without setting gd->is_suspended, and the matching GDMA_SERVICE_TYPE_RDMA_RESUME then also breaks on !gd->is_suspended. Doesn't that leave the freshly created RDMA auxiliary device live across a servicing operation that explicitly asked for it to be quiesced, which is the same silently-dropped-servicing behaviour this change sets out to fix, now confined to the probe window?
Can the two contexts really overlap? mana_serv_reset() runs on the system workqueue via mana_schedule_serv_work()/schedule_work() (or from mana_recovery_delayed_func()) and calls mana_gd_suspend() -> mana_rdma_remove() then mana_gd_resume() -> mana_gd_setup() -> mana_rdma_probe(), while the handler runs on gc->service_wq, which mana_gd_setup() re-creates before mana_rdma_probe() is called:
mana_rdma_service_event() {
...
INIT_WORK(&serv_work->work, mana_rdma_service_handle);
queue_work(gc->service_wq, &serv_work->work);Different workqueues, and GC_IN_SERVICE only serializes further reset requests.
Related to the new comment: the handler's read of gd->adev is a plain read racing with add_adev()'s plain write, so "the handler cannot act on a stale value" holds for is_suspended but not for gd->adev.
mana_rdma_remove() uses the opposite ordering, closing the gate and draining the workqueue before touching gd->adev:
mana_rdma_remove() {
WRITE_ONCE(gd->rdma_teardown, true);
if (gc->service_wq)
flush_workqueue(gc->service_wq);
if (gd->adev)
remove_adev(gd);Would doing the mirror image in probe work here, i.e. keeping the gd->is_suspended = false store where it is but issuing smp_store_release(&gd->rdma_teardown, false) only after add_adev() has succeeded? Note that ordering alone still drops such an event, just via the gate instead; serializing mana_rdma_probe(), mana_rdma_remove() and the handler body with a mutex rather than extending the bool gate would close the window entirely.
Quoted 78 lines
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible. Full review at:
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fnetdev
- ai.bots.linux.dev%2Fsashiko%2F%23%2Fpatchset%2F20260828001202.211093 8-1- longli%40microsoft.com%3Fpart%3D1&data=05%7C02%7Clongli%40microsoft. com%7C588623f27cf64c19cb1008df0911b29d%7C72f988bf86f141af91ab2d7cd 011db47%7C1%7C0%7C639239643786367503%7CUnknown%7CTWFpbGZsb3 d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOI joiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=fPON6yyxZubRe8V9 4xCzc9ZMoSxXSR0cU2Zug1r8Lck%3D&reserved=0
---
net: mana: Clear RDMA teardown and suspend state inmana_rdma_probe()This clears
gd->rdma_teardownandgd->is_suspendedinmana_rdma_probe()so that RDMA servicing events are handled again after a hardware service reset cycle. The gate is re-opened withsmp_store_release(), paired with a newsmp_load_acquire()inmana_rdma_service_handle().drivers/net/ethernet/microsoft/mana/mana_en.c static void mana_rdma_service_handle(struct
Quoted 6 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +0
-0@@ -3983,7 +3983,8 @@ static void mana_rdma_service_handle(struct
work_struct*work)Quoted 9 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +2
-1struct device *dev = gd->gdma_context->dev;int ret; -if (READ_ONCE (gd->rdma_teardown)) +/* Pairs with the smp_store_release() in mana_rdma_probe(). */ +if (smp_load_acquire (&gd->rdma_teardown)) goto out;switch (serv_work->event) {[ ... ]
drivers/net/ethernet/microsoft/mana/mana_en.c int mana_rdma_probe(struct gdma_dev *gd) · line 4283
Quoted 5 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +1
-0@@ -4279,6 +4280,17 @@ int mana_rdma_probe(struct gdma_dev *gd)if (err)return err; +/* Clear the state left by a previous mana_rdma_remove() so servicing
drivers/net/ethernet/microsoft/mana/mana_en.c int mana_rdma_probe(struct gdma_dev *gd) · line 4286
Quoted 3 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +3
-0+* events are handled again after a reset cycle. +*/ + gd->is_suspended = false;[Severity: Low]
Does the invariant described in the commit message hold on the initial probe path? The commit message says:
is_suspendedis otherwise only touched bymana_rdma_service_handle()
on
the ordered service workqueue, so clear it whilerdma_teardownstill gates that handlerThat is true for the reset path, where
mana_rdma_remove()setrdma_teardownand flushedgc->service_wqfirst. Onmana_gd_probe()->mana_probe()->mana_rdma_probe()the gate was never closed: gc comes fromvzalloc(), so bothgd->rdma_teardownandgd->is_suspendedare already false, andgd->mana_gd_setup()
has already createdgc->service_wqand brought up the HWC and EQs beforemana_rdma_probe()runs.So on that path the
smp_store_release()is a false -> false store and the handler'ssmp_load_acquire()has no state change to order against, while the plain write ofgd->is_suspendedhere (and add_adev()'s plain write ofgd->adev) can run concurrently with the handler's plain accesses to thegd->same
two fields with no lock on either side.
Quoted 4 lines
The outcome looks benign today, since
is_suspendedis already false and the handler is a no-op in that window, but would it be worth wording the comment and commit message so they only claim the property that actually holds?
Thank you, Simon.
I will submit v3, with the commit message changed to be more accurate.
The following issue is pre-existing. The race window exists for all service events; this patch doesn't enlarge that race window or make it more visible. I'll explain more later in this email.
This patch only fixes the issue with the 2nd service event not reaching to RDMA probe.
Quoted 79 lines
drivers/net/ethernet/microsoft/mana/mana_en.c int mana_rdma_probe(struct gdma_dev *gd) · line 4296
Quoted 11 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +7
-0+ +/* Publish is_suspended before re-opening the gate, so the handler +* cannot act on a stale value. Pairs with the smp_load_acquire() +* in mana_rdma_service_handle(). +*/ +smp_store_release (&gd->rdma_teardown, false); + err =add_adev (gd,"rdma" );if (err)mana_gd_deregister_device (gd);[Severity: Medium]
Is the gate re-opened too early here, i.e. before
add_adev()has publishedgd->adev?add_adev()stores it as its last step, afterauxiliary_device_add()has already synchronously probedmana_ib:drivers/net/ethernet/microsoft/mana/mana_en.c:add_adev() { ... ret = auxiliary_device_add(adev); if (ret) goto add_fail; gd->adev = adev; ... }A
GDMA_SERVICE_TYPE_RDMA_SUSPENDwork item that runs inside that window passes the acquire load, but seesgd->adev== NULL becauseremove_adev()cleared it during the precedingmana_rdma_remove():mana_rdma_service_handle() { case GDMA_SERVICE_TYPE_RDMA_SUSPEND: if (!gd->adev || gd->is_suspended) break; remove_adev(gd); gd->is_suspended = true; break;so the suspend event is consumed without setting
gd->is_suspended, and the matchingGDMA_SERVICE_TYPE_RDMA_RESUMEthen also breaks on !gd-Quoted 1 line
is_suspended. Doesn't that leave the freshly created RDMA auxiliary devicelive across a servicing operation that explicitly asked for it to be quiesced, which is the same silently-dropped-servicing behaviour this change sets out to fix, now confined to the probe window?
Can the two contexts really overlap?
mana_serv_reset()runs on the system workqueue via mana_schedule_serv_work()/schedule_work() (or frommana_recovery_delayed_func()) and callsmana_gd_suspend()->mana_rdma_remove()thenmana_gd_resume()->mana_gd_setup()->mana_rdma_probe(), while the handler runs ongc->service_wq, whichmana_gd_setup()re-creates beforemana_rdma_probe()is called:mana_rdma_service_event() { ... INIT_WORK(&serv_work->work, mana_rdma_service_handle); queue_work(gc->service_wq, &serv_work->work);Different workqueues, and
GC_IN_SERVICEonly serializes further reset requests.Related to the new comment: the handler's read of
gd->adevis a plain read racing with add_adev()'s plain write, so "the handler cannot act on a stale value" holds foris_suspendedbut not forgd->adev.
mana_rdma_remove()uses the opposite ordering, closing the gate and draining the workqueue before touchinggd->adev:mana_rdma_remove() { WRITE_ONCE(gd->rdma_teardown, true); if (gc->service_wq) flush_workqueue(gc->service_wq); if (gd->adev) remove_adev(gd);
Quoted 4 lines
Would doing the mirror image in probe work here, i.e. keeping the
gd->is_suspended= false store where it is but issuingsmp_store_release(&gd->rdma_teardown, false)only afteradd_adev()has succeeded?
No, and I'd rather not make that change.
First, this window is pre-existing and this patch does not change it. The code that drops the event is:
case GDMA_SERVICE_TYPE_RDMA_SUSPEND:
if (!gd->adev || gd->is_suspended)
break;That test is untouched by this patch -- it does not appear in the diff. It is reachable in mainline today on the initial probe path:
gc = vzalloc() rdma_teardown = false, adev = NULL
mana_gd_setup()
alloc_ordered_workqueue() service_wq exists
mana_gd_setup_hwc_irqs() HWC events are flowing
mana_gd_detect_devices() mana_ib.dev_id.type is set
mana_rdma_probe()
add_adev() gd->adev published last
gc is zeroed, so the gate starts clear, and mana_rdma_service_event() already passes its dev_id.type test by then. A SUSPEND arriving while add_adev() is still running is dropped on a stock kernel, with or without this patch.
What this patch changes is only that the reset path now reaches that same pre-existing test. Before, it stopped earlier:
if (READ_ONCE(gd->rdma_teardown))
goto out;because mana_rdma_remove() set rdma_teardown and nothing ever cleared it, so that event and every event after it were dropped for the life of the device. There is no input where this patch loses an event that mainline would have delivered.
Second, on the reordering itself: the gate is a discard, not a defer. A work item that sees it closed falls through to "out: kfree(serv_work)" and is never re-queued, so moving the store just relocates the loss from !gd->adev to the gate, as you noted. It also leaves rdma_teardown set when add_adev() fails, reinstating the stuck gate this patch fixes.
Quoted 4 lines
Note that ordering alone still drops such an event, just via the gate instead; serializing
mana_rdma_probe(),mana_rdma_remove()and the handler body with a mutex rather than extending the bool gate would close the window entirely.
Agreed, because the handler would wait rather than discard. One trap for whoever writes it: mana_rdma_remove() closes the gate and then calls flush_workqueue(gc->service_wq). If that flush ends up inside the mutex while the handler body also takes it, it deadlocks. The mutex would also be held across auxiliary_device_add(), which probes mana_ib synchronously, so it needs a lockdep run.
Since the window predates this patch, I'd rather keep this one as the minimal fix for the stuck gate and the is_suspended leak, which is what the Fixes: tag refers to, and do the mutex separately against net-next.
Thanks,
Long