AIX: Free pinned_heap during shutdown to prevent kernel panic

During shutdown, the function shutdown_osisleep is called in
src/afs/afs_osi.c.  The body of this function is platform-
specific, and on AIX there is a call to xmfree:

                xmfree(tmp);

However, on AIX, xmfree actually takes two arguments:

int xmfree ( ptr,  heap)
caddr_t ptr;
caddr_t heap;

This is called elsewhere in the OpenAFS code correctly for
kernel_heap.  In src/afs/AIX/osi_sleep.c we start using the
pinned_heap, but never xmfree it.  Therefore, we need to do so here
during the shutdown.  Here we include a header file which defines
pinned_heap, and then supply it as an argument to xmfree.  This
prevents a kernel panic during OS shutdown.

The panic might go unnoticed in many environments, as during a
reboot, the system will normally dump and restart anyway.  However,
if kdb is loaded (bosboot -a -D), the system will break into the
debugger before the full shutdown procedure completes.  The stack
trace shows the following:

KDB(0)> stack
pvthread+01D200 STACK:
[00023900]abend_trap+000000 ()
[000EFF24]xmfree_frontend+0000A4 (??, ??, ??)
[F1000000C064CF1C]shutdown_osisleep@AF72_5+0000BC (??)
[F1000000C064CB7C]shutdown_osi+00001C ()
[F1000000C064A51C]afs_shutdown+0003BC (0000000100000001)
[F1000000C05A8DD4]afs_unmount+000094 (F1000A01501D4C10, 0000000000000000)
[F1000000C059FCE0]vfs_unmount+0000A0 (F1000A01501D4C10, 0000000000000000,
   F1000A015047B07C)
[00014D70].hkey_legacy_gate+00004C ()
[006A6AAC]vfs_unmount+00008C (??, ??, ??)
[006B4228]kunmount+000228 (??, ??, ??, ??)
[006B4944]uvmount+000204 (??, ??)
[00003954]syscall+00024C ()
[100084FC]helper_UMfunc+00027C (??, ??)
[10003D48]dounmount+0000C8 (??, ??, ??, ??)
[100044DC]umountmain+0001BC (??, ??)
[10000AD4]main+0000B4 (??, ??)
[10000168]__start+000068 ()

Reviewed-on: https://gerrit.openafs.org/15419
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
(cherry picked from commit 4810cca10bc32df7ba7809fc2bf095d20e2febd8)

Change-Id: I687caa6daae83fc7986e76d370b55f90f5ca53cc
Reviewed-on: https://gerrit.openafs.org/15425
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Ben Huntsman <ben@huntsmans.net>
Tested-by: Ben Huntsman <ben@huntsmans.net>
Reviewed-by: Mark Vitale <mvitale@sinenomine.net>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Stephan Wiesand <stephan.wiesand@desy.de>
This commit is contained in:
Ben Huntsman 2023-05-04 16:52:38 -07:00 committed by Stephan Wiesand
parent a2ab598bae
commit 332b5593d4

View File

@ -15,7 +15,8 @@
#include "afsincludes.h" /* Afs-based standard headers */
#include "afs/afs_stats.h" /* afs statistics */
#ifdef AFS_AIX_ENV
#include <sys/adspace.h> /* for vm_att(), vm_det() */
# include <sys/adspace.h> /* for vm_att(), vm_det() */
# include <sys/malloc.h> /* pinned_heap */
#endif
/* osi_Init -- do once per kernel installation initialization.
@ -241,7 +242,7 @@ shutdown_osisleep(void)
afs_warn("nonzero refcount in shutdown_osisleep()\n");
} else {
#if defined(AFS_AIX_ENV)
xmfree(tmp);
xmfree(tmp, pinned_heap);
#elif defined(AFS_FBSD_ENV)
afs_osi_Free(tmp, sizeof(*tmp));
#elif defined(AFS_SGI_ENV) || defined(AFS_XBSD_ENV) || defined(AFS_SUN5_ENV)