git: 3c872a70b883 - main - hwpmc: on process exit, ensure that the owned log is closed

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Mon, 21 Aug 2023 13:33:20 UTC
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=3c872a70b883e4e2b38135bd6bd114ac9d2ea579

commit 3c872a70b883e4e2b38135bd6bd114ac9d2ea579
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2023-08-13 13:42:49 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2023-08-21 13:33:13 +0000

    hwpmc: on process exit, ensure that the owned log is closed
    
    Tested by:      pho (previous version)
    Reviewed by:    markj
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D41521
---
 sys/dev/hwpmc/hwpmc_mod.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/sys/dev/hwpmc/hwpmc_mod.c b/sys/dev/hwpmc/hwpmc_mod.c
index b429f713b09c..de012b74d558 100644
--- a/sys/dev/hwpmc/hwpmc_mod.c
+++ b/sys/dev/hwpmc/hwpmc_mod.c
@@ -4989,13 +4989,13 @@ pmc_process_exit(void *arg __unused, struct proc *p)
 	}
 	PMC_EPOCH_EXIT();
 
-	if (!is_using_hwpmcs)
-		return;
-
 	PMC_GET_SX_XLOCK();
 	PMCDBG3(PRC,EXT,1,"process-exit proc=%p (%d, %s)", p, p->p_pid,
 	    p->p_comm);
 
+	if (!is_using_hwpmcs)
+		goto out;
+
 	/*
 	 * Since this code is invoked by the last thread in an exiting process,
 	 * we would have context switched IN at some prior point. However, with
@@ -5116,6 +5116,8 @@ out:
 	 * If the process owned PMCs, free them up and free up memory.
 	 */
 	if ((po = pmc_find_owner_descriptor(p)) != NULL) {
+		if ((po->po_flags & PMC_PO_OWNS_LOGFILE) != 0)
+			pmclog_close(po);
 		pmc_remove_owner(po);
 		pmc_destroy_owner_descriptor(po);
 	}