clear-pkgs-linux-iot-lts2018/0764-Kernel-VHM-Use-the-bit...

134 lines
3.9 KiB
Diff
Raw Normal View History

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Zhao Yakui <yakui.zhao@intel.com>
Date: Thu, 29 Nov 2018 13:58:07 +0800
Subject: [PATCH] Kernel/VHM: Use the bit_op to remove the volatile definition
in ioreq_client
Now the ioreq_client use the volatile prefix to define the destroying/kthread_exit variable
so that it can't be optimized. As the volatile variable is not recommended, the bit_op
is used instead.
Tracked-On: PKT-1592
Tracked-On: https://github.com/projectacrn/acrn-hypervisor/issues/1957
Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
Reviewed-by: Eddie Dong <eddie.dong@intel.com>
Tested-by: Yin, FengWei <fengwei.yin@intel.com>
---
drivers/vhm/vhm_ioreq.c | 34 ++++++++++++++++------------------
1 file changed, 16 insertions(+), 18 deletions(-)
diff --git a/drivers/vhm/vhm_ioreq.c b/drivers/vhm/vhm_ioreq.c
2020-10-27 02:14:06 +08:00
index 7e067ac4923d..ac934fcd656f 100644
--- a/drivers/vhm/vhm_ioreq.c
+++ b/drivers/vhm/vhm_ioreq.c
@@ -51,6 +51,7 @@
*
*/
+#include <linux/bitops.h>
#include <linux/slab.h>
#include <linux/wait.h>
#include <linux/freezer.h>
@@ -72,6 +73,11 @@ struct ioreq_range {
long end;
};
+enum IOREQ_CLIENT_BITS {
+ IOREQ_CLIENT_DESTROYING = 0,
+ IOREQ_CLIENT_EXIT,
+};
+
struct ioreq_client {
/* client name */
char name[16];
@@ -91,8 +97,7 @@ struct ioreq_client {
*/
bool fallback;
- volatile bool destroying;
- volatile bool kthread_exit;
+ unsigned long flags;
/* client covered io ranges - N/A for fallback client */
struct list_head range_list;
@@ -157,7 +162,7 @@ static int alloc_client(void)
if (!client)
return -ENOMEM;
client->id = i;
- client->kthread_exit = true;
+ set_bit(IOREQ_CLIENT_EXIT, &client->flags);
clients[i] = client;
return i;
@@ -313,13 +318,10 @@ static void acrn_ioreq_destroy_client_pervm(struct ioreq_client *client,
struct list_head *pos, *tmp;
unsigned long flags;
- client->destroying = true;
+ set_bit(IOREQ_CLIENT_DESTROYING, &client->flags);
acrn_ioreq_notify_client(client);
- /* the client thread will mark kthread_exit flag as true before exit,
- * so wait for it exited.
- */
- while (client->vhm_create_kthread && !client->kthread_exit)
+ while (client->vhm_create_kthread && !test_bit(IOREQ_CLIENT_EXIT, &client->flags))
msleep(10);
spin_lock_irqsave(&client->range_lock, flags);
@@ -483,7 +485,7 @@ EXPORT_SYMBOL_GPL(acrn_ioreq_del_iorange);
static inline bool is_destroying(struct ioreq_client *client)
{
if (client)
- return client->destroying;
+ return test_bit(IOREQ_CLIENT_DESTROYING, &client->flags);
else
return true;
}
@@ -547,9 +549,7 @@ static int ioreq_client_thread(void *data)
is_destroying(client)));
}
- /* the client thread such as for hyper-dma will exit from here,
- * so mark kthread_exit as true before exit */
- client->kthread_exit = true;
+ set_bit(IOREQ_CLIENT_EXIT, &client->flags);
return 0;
}
@@ -583,9 +583,9 @@ int acrn_ioreq_attach_client(int client_id, bool check_kthread_stop)
"for client %s\n", client->name);
return -ENOMEM;
}
- client->kthread_exit = false;
+ clear_bit(IOREQ_CLIENT_EXIT, &client->flags);
} else {
- client->kthread_exit = false;
+ clear_bit(IOREQ_CLIENT_EXIT, &client->flags);
might_sleep();
if (check_kthread_stop) {
@@ -594,7 +594,7 @@ int acrn_ioreq_attach_client(int client_id, bool check_kthread_stop)
has_pending_request(client) ||
is_destroying(client)));
if (kthread_should_stop())
- client->kthread_exit = true;
+ set_bit(IOREQ_CLIENT_EXIT, &client->flags);
} else {
wait_event_freezable(client->wq,
(has_pending_request(client) ||
@@ -602,9 +602,7 @@ int acrn_ioreq_attach_client(int client_id, bool check_kthread_stop)
}
if (is_destroying(client)) {
- /* the client thread for vcpu will exit from here,
- * so mark kthread_exit as true before exit */
- client->kthread_exit = true;
+ set_bit(IOREQ_CLIENT_EXIT, &client->flags);
return 1;
}
}
--
https://clearlinux.org