[Devel] [PATCH RHEL8 COMMIT] proc connector: protect from task cpu migration in send_msg_ve
Konstantin Khorenko
khorenko at virtuozzo.com
Fri Sep 10 19:49:44 MSK 2021
The commit is pushed to "branch-rh8-4.18.0-305.3.1.vz8.7.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-305.3.1.vz8.7.11
------>
commit b52c9d8a3f42108bd8a36abee89193b93a18facb
Author: Konstantin Khorenko <khorenko at virtuozzo.com>
Date: Thu Sep 9 23:18:47 2021 +0300
proc connector: protect from task cpu migration in send_msg_ve
this_cpu_ptr() should be used under local_lock() (or task migration
should be disabled instead), so switch the order.
Fixes: 0e60020d2a ("proc connector: take number of listeners and per-cpu
conters from VE")
Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
Signed-off-by: Alexander Mikhalitsyn <alexander.mikhalitsyn at virtuozzo.com>
---
drivers/connector/cn_proc.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/drivers/connector/cn_proc.c b/drivers/connector/cn_proc.c
index 9b63792f0dff..ce7b33345db5 100644
--- a/drivers/connector/cn_proc.c
+++ b/drivers/connector/cn_proc.c
@@ -63,9 +63,15 @@ static inline void send_msg_ve(struct ve_struct *ve, struct cn_msg *msg)
{
struct local_event *le_ptr;
- le_ptr = this_cpu_ptr(ve->cn->local_event);
- local_lock(&le_ptr->lock);
+ /*
+ * The following hack with local_event->lock address works only
+ * till the "lock" is the first field in the local_event struct,
+ * so be of the safe side.
+ */
+ BUILD_BUG_ON(offsetof(struct local_event, lock) != 0);
+ local_lock(&ve->cn->local_event->lock);
+ le_ptr = this_cpu_ptr(ve->cn->local_event);
msg->seq = le_ptr->count++;
((struct proc_event *)msg->data)->cpu = smp_processor_id();
@@ -77,7 +83,7 @@ static inline void send_msg_ve(struct ve_struct *ve, struct cn_msg *msg)
*/
cn_netlink_send_ve(ve, msg, 0, CN_IDX_PROC, GFP_NOWAIT);
- local_unlock(&le_ptr->lock);
+ local_unlock(&ve->cn->local_event->lock);
}
static struct cn_msg *cn_msg_fill(__u8 *buffer, struct ve_struct *ve,
More information about the Devel
mailing list