git: c6cf874c7de3 - main - LinuxKPI: Add comment describing proper use of the on_each_cpu() function.

From: Hans Petter Selasky <hselasky_at_FreeBSD.org>
Date: Wed, 16 Mar 2022 14:44:46 UTC
The branch main has been updated by hselasky:

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

commit c6cf874c7de3bcc092a58a932c732221b2933043
Author:     Hans Petter Selasky <hselasky@FreeBSD.org>
AuthorDate: 2022-03-16 14:40:09 +0000
Commit:     Hans Petter Selasky <hselasky@FreeBSD.org>
CommitDate: 2022-03-16 14:44:07 +0000

    LinuxKPI: Add comment describing proper use of the on_each_cpu() function.
    
    MFC after:              1 week
    Sponsored by:           NVIDIA Networking
---
 sys/compat/linuxkpi/common/include/linux/smp.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/linux/smp.h b/sys/compat/linuxkpi/common/include/linux/smp.h
index 290b91469b12..c6d011fceb5f 100644
--- a/sys/compat/linuxkpi/common/include/linux/smp.h
+++ b/sys/compat/linuxkpi/common/include/linux/smp.h
@@ -29,6 +29,18 @@
 #ifndef _LINUXKPI_LINUX_SMP_H_
 #define	_LINUXKPI_LINUX_SMP_H_
 
+/*
+ * Important note about the use of the function provided below:
+ *
+ * The callback function passed to on_each_cpu() is called from a
+ * so-called critical section, and if you need a mutex you will have
+ * to rewrite the code to use native FreeBSD mtx spinlocks instead of
+ * the spinlocks provided by the LinuxKPI! Be very careful to not call
+ * any LinuxKPI functions inside the on_each_cpu()'s callback
+ * function, because they may sleep, unlike in native Linux.
+ *
+ * Enabling witness(4) when testing, can catch such issues.
+ */
 #define	on_each_cpu(cb, data, wait) ({				\
 	CTASSERT(wait);						\
 	linux_on_each_cpu(cb, data);				\