Skip to content

Commit

Permalink
ehea: Fix memory hook reference counting crashes
Browse files Browse the repository at this point in the history
The recent commit to only register the EHEA memory hotplug hooks on
adapter probe has a few problems.

Firstly the reference counting is wrong for multiple adapters, in that
the hooks are registered multiple times. Secondly the check in the tear
down path is backward. Finally the error path doesn't decrement the
count.

The multiple registration of the hooks is the biggest problem, as it
leads to oopses when the system is rebooted, and/or errors during memory
hotplug, eg:

  $ ./mem-on-off-test.sh -r 2
  ...
  ehea: memory is going offline
  ehea: LPAR memory changed - re-initializing driver
  ehea: re-initializing driver complete
  ehea: memory is going offline
  ehea: LPAR memory changed - re-initializing driver
  ehea: opcode=26c ret=fffffffffffffffc arg1=8000000003000003 arg2=0 arg3=700000060000d600 arg4=3fded0000 arg5=200 arg6=0 arg7=0
  ehea: register_rpage_mr failed
  ehea: registering mr failed
  ehea: register MR failed - driver inoperable!
  ehea: memory is going offline

Fixes: aa18332 ("ehea: Register memory hotplug, reboot and crash hooks on adapter probe")
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
mpe authored and davem330 committed Apr 25, 2015
1 parent dfc8f37 commit 3051f39
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions drivers/net/ethernet/ibm/ehea/ehea_main.c
Expand Up @@ -3347,7 +3347,7 @@ static int ehea_register_memory_hooks(void)
{
int ret = 0;

if (atomic_inc_and_test(&ehea_memory_hooks_registered))
if (atomic_inc_return(&ehea_memory_hooks_registered) > 1)
return 0;

ret = ehea_create_busmap();
Expand Down Expand Up @@ -3381,12 +3381,14 @@ static int ehea_register_memory_hooks(void)
out2:
unregister_reboot_notifier(&ehea_reboot_nb);
out:
atomic_dec(&ehea_memory_hooks_registered);
return ret;
}

static void ehea_unregister_memory_hooks(void)
{
if (atomic_read(&ehea_memory_hooks_registered))
/* Only remove the hooks if we've registered them */
if (atomic_read(&ehea_memory_hooks_registered) == 0)
return;

unregister_reboot_notifier(&ehea_reboot_nb);
Expand Down

0 comments on commit 3051f39

Please sign in to comment.