Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1883238

Summary: Kpatch unload issue under stress
Product: Red Hat Enterprise Linux 8 Reporter: Yulia Kopkova <ykopkova>
Component: kpatchAssignee: kpatch maintainers <kpatch-maint>
kpatch sub component: kpatch-utility QA Contact: Yulia Kopkova <ykopkova>
Status: CLOSED ERRATA Docs Contact:
Severity: unspecified    
Priority: unspecified CC: bhu, joe.lawrence, kpatch-maint, rhandlin
Version: 8.4Keywords: Triaged
Target Milestone: rcFlags: pm-rhel: mirror+
Target Release: 8.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: kpatch-0.9.2-2.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-05-18 15:07:29 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Comment 2 Joe Lawrence 2020-09-28 17:09:55 UTC
The problem is that the underlying livepatch module is disabled, but it's module reference has not cleared yet.  Every once in a while, "kpatch unload" gets to its "rmmod" step before that reference count is clear and you see this transient problem.

Running with the following patch, I was able to run ~ 50k iterations of the repro without see any instances of "kpatch unload" failing.  This is stolen from code that the upstream livepatching kselftests currently utilize to ensure that sysfs and module reference counters have settled.  It's probably time to renovate the kpatch-utility code with something similar.

--- /usr/sbin/kpatch	2019-10-25 11:58:00.000000000 -0400
+++ /root/kpatch	2020-09-27 14:24:15.814974863 -0400
@@ -392,15 +392,34 @@ disable_patch () {
 	fi
 }
 
+MAX_RETRIES=600
+RETRY_INTERVAL=".1"	# seconds
+
+# loop_until(cmd) - loop a command until it is successful or $MAX_RETRIES,
+#		    sleep $RETRY_INTERVAL between attempts
+#	cmd - command and its arguments to run
+function loop_until() {
+	local cmd="$*"
+	local i=0
+	while true; do
+		eval "$cmd" && return 0
+		[[ $((i++)) -eq $MAX_RETRIES ]] && return 1
+		sleep $RETRY_INTERVAL
+	done
+}
+
 unload_module () {
 	PATCH="${1//-/_}"
 	PATCH="${PATCH%.ko}"
 	disable_patch "$PATCH"
 
+	loop_until '[[ $(cat "/sys/module/$PATCH/refcnt") == "0" ]]' ||
+		die "failed to unload module $PATCH (refcnt)"
+
 	echo "unloading patch module: $PATCH"
 	# ignore any error here because rmmod can fail if the module used
 	# KPATCH_FORCE_UNSAFE.
-	rmmod "$PATCH" 2> /dev/null || return 0
+	rmmod "$PATCH" # 2> /dev/null || return 0
 }
 
 get_module_version() {

Comment 9 errata-xmlrpc 2021-05-18 15:07:29 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (kpatch bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2021:1688