Commit 602ef894 authored by David Hildenbrand's avatar David Hildenbrand Committed by Michael S. Tsirkin

virito-mem: existing (un)plug functions are specific to Sub Block Mode (SBM)

Let's rename them accordingly. virtio_mem_plug_request() and
virtio_mem_unplug_request() will be handled separately.
Reviewed-by: default avatarWei Yang <richard.weiyang@linux.alibaba.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Jason Wang <jasowang@redhat.com>
Cc: Pankaj Gupta <pankaj.gupta.linux@gmail.com>
Signed-off-by: default avatarDavid Hildenbrand <david@redhat.com>
Link: https://lore.kernel.org/r/20201112133815.13332-23-david@redhat.comSigned-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
parent 8a6f082b
...@@ -1099,8 +1099,8 @@ static int virtio_mem_send_unplug_all_request(struct virtio_mem *vm) ...@@ -1099,8 +1099,8 @@ static int virtio_mem_send_unplug_all_request(struct virtio_mem *vm)
* Plug selected subblocks. Updates the plugged state, but not the state * Plug selected subblocks. Updates the plugged state, but not the state
* of the memory block. * of the memory block.
*/ */
static int virtio_mem_mb_plug_sb(struct virtio_mem *vm, unsigned long mb_id, static int virtio_mem_sbm_plug_sb(struct virtio_mem *vm, unsigned long mb_id,
int sb_id, int count) int sb_id, int count)
{ {
const uint64_t addr = virtio_mem_mb_id_to_phys(mb_id) + const uint64_t addr = virtio_mem_mb_id_to_phys(mb_id) +
sb_id * vm->sbm.sb_size; sb_id * vm->sbm.sb_size;
...@@ -1117,8 +1117,8 @@ static int virtio_mem_mb_plug_sb(struct virtio_mem *vm, unsigned long mb_id, ...@@ -1117,8 +1117,8 @@ static int virtio_mem_mb_plug_sb(struct virtio_mem *vm, unsigned long mb_id,
* Unplug selected subblocks. Updates the plugged state, but not the state * Unplug selected subblocks. Updates the plugged state, but not the state
* of the memory block. * of the memory block.
*/ */
static int virtio_mem_mb_unplug_sb(struct virtio_mem *vm, unsigned long mb_id, static int virtio_mem_sbm_unplug_sb(struct virtio_mem *vm, unsigned long mb_id,
int sb_id, int count) int sb_id, int count)
{ {
const uint64_t addr = virtio_mem_mb_id_to_phys(mb_id) + const uint64_t addr = virtio_mem_mb_id_to_phys(mb_id) +
sb_id * vm->sbm.sb_size; sb_id * vm->sbm.sb_size;
...@@ -1140,8 +1140,8 @@ static int virtio_mem_mb_unplug_sb(struct virtio_mem *vm, unsigned long mb_id, ...@@ -1140,8 +1140,8 @@ static int virtio_mem_mb_unplug_sb(struct virtio_mem *vm, unsigned long mb_id,
* *
* Note: can fail after some subblocks were unplugged. * Note: can fail after some subblocks were unplugged.
*/ */
static int virtio_mem_mb_unplug_any_sb(struct virtio_mem *vm, static int virtio_mem_sbm_unplug_any_sb(struct virtio_mem *vm,
unsigned long mb_id, uint64_t *nb_sb) unsigned long mb_id, uint64_t *nb_sb)
{ {
int sb_id, count; int sb_id, count;
int rc; int rc;
...@@ -1162,7 +1162,7 @@ static int virtio_mem_mb_unplug_any_sb(struct virtio_mem *vm, ...@@ -1162,7 +1162,7 @@ static int virtio_mem_mb_unplug_any_sb(struct virtio_mem *vm,
sb_id--; sb_id--;
} }
rc = virtio_mem_mb_unplug_sb(vm, mb_id, sb_id, count); rc = virtio_mem_sbm_unplug_sb(vm, mb_id, sb_id, count);
if (rc) if (rc)
return rc; return rc;
*nb_sb -= count; *nb_sb -= count;
...@@ -1179,18 +1179,18 @@ static int virtio_mem_mb_unplug_any_sb(struct virtio_mem *vm, ...@@ -1179,18 +1179,18 @@ static int virtio_mem_mb_unplug_any_sb(struct virtio_mem *vm,
* *
* Note: can fail after some subblocks were unplugged. * Note: can fail after some subblocks were unplugged.
*/ */
static int virtio_mem_mb_unplug(struct virtio_mem *vm, unsigned long mb_id) static int virtio_mem_sbm_unplug_mb(struct virtio_mem *vm, unsigned long mb_id)
{ {
uint64_t nb_sb = vm->sbm.sbs_per_mb; uint64_t nb_sb = vm->sbm.sbs_per_mb;
return virtio_mem_mb_unplug_any_sb(vm, mb_id, &nb_sb); return virtio_mem_sbm_unplug_any_sb(vm, mb_id, &nb_sb);
} }
/* /*
* Prepare tracking data for the next memory block. * Prepare tracking data for the next memory block.
*/ */
static int virtio_mem_prepare_next_mb(struct virtio_mem *vm, static int virtio_mem_sbm_prepare_next_mb(struct virtio_mem *vm,
unsigned long *mb_id) unsigned long *mb_id)
{ {
int rc; int rc;
...@@ -1218,9 +1218,8 @@ static int virtio_mem_prepare_next_mb(struct virtio_mem *vm, ...@@ -1218,9 +1218,8 @@ static int virtio_mem_prepare_next_mb(struct virtio_mem *vm,
* *
* Will modify the state of the memory block. * Will modify the state of the memory block.
*/ */
static int virtio_mem_mb_plug_and_add(struct virtio_mem *vm, static int virtio_mem_sbm_plug_and_add_mb(struct virtio_mem *vm,
unsigned long mb_id, unsigned long mb_id, uint64_t *nb_sb)
uint64_t *nb_sb)
{ {
const int count = min_t(int, *nb_sb, vm->sbm.sbs_per_mb); const int count = min_t(int, *nb_sb, vm->sbm.sbs_per_mb);
int rc; int rc;
...@@ -1232,7 +1231,7 @@ static int virtio_mem_mb_plug_and_add(struct virtio_mem *vm, ...@@ -1232,7 +1231,7 @@ static int virtio_mem_mb_plug_and_add(struct virtio_mem *vm,
* Plug the requested number of subblocks before adding it to linux, * Plug the requested number of subblocks before adding it to linux,
* so that onlining will directly online all plugged subblocks. * so that onlining will directly online all plugged subblocks.
*/ */
rc = virtio_mem_mb_plug_sb(vm, mb_id, 0, count); rc = virtio_mem_sbm_plug_sb(vm, mb_id, 0, count);
if (rc) if (rc)
return rc; return rc;
...@@ -1259,7 +1258,7 @@ static int virtio_mem_mb_plug_and_add(struct virtio_mem *vm, ...@@ -1259,7 +1258,7 @@ static int virtio_mem_mb_plug_and_add(struct virtio_mem *vm,
* TODO: Linux MM does not properly clean up yet in all cases * TODO: Linux MM does not properly clean up yet in all cases
* where adding of memory failed - especially on -ENOMEM. * where adding of memory failed - especially on -ENOMEM.
*/ */
if (virtio_mem_mb_unplug_sb(vm, mb_id, 0, count)) if (virtio_mem_sbm_unplug_sb(vm, mb_id, 0, count))
new_state = VIRTIO_MEM_SBM_MB_PLUGGED; new_state = VIRTIO_MEM_SBM_MB_PLUGGED;
virtio_mem_sbm_set_mb_state(vm, mb_id, new_state); virtio_mem_sbm_set_mb_state(vm, mb_id, new_state);
return rc; return rc;
...@@ -1277,8 +1276,9 @@ static int virtio_mem_mb_plug_and_add(struct virtio_mem *vm, ...@@ -1277,8 +1276,9 @@ static int virtio_mem_mb_plug_and_add(struct virtio_mem *vm,
* *
* Note: Can fail after some subblocks were successfully plugged. * Note: Can fail after some subblocks were successfully plugged.
*/ */
static int virtio_mem_mb_plug_any_sb(struct virtio_mem *vm, unsigned long mb_id, static int virtio_mem_sbm_plug_any_sb(struct virtio_mem *vm,
uint64_t *nb_sb, bool online) unsigned long mb_id, uint64_t *nb_sb,
bool online)
{ {
unsigned long pfn, nr_pages; unsigned long pfn, nr_pages;
int sb_id, count; int sb_id, count;
...@@ -1297,7 +1297,7 @@ static int virtio_mem_mb_plug_any_sb(struct virtio_mem *vm, unsigned long mb_id, ...@@ -1297,7 +1297,7 @@ static int virtio_mem_mb_plug_any_sb(struct virtio_mem *vm, unsigned long mb_id,
!virtio_mem_sbm_test_sb_plugged(vm, mb_id, sb_id + count, 1)) !virtio_mem_sbm_test_sb_plugged(vm, mb_id, sb_id + count, 1))
count++; count++;
rc = virtio_mem_mb_plug_sb(vm, mb_id, sb_id, count); rc = virtio_mem_sbm_plug_sb(vm, mb_id, sb_id, count);
if (rc) if (rc)
return rc; return rc;
*nb_sb -= count; *nb_sb -= count;
...@@ -1341,7 +1341,7 @@ static int virtio_mem_plug_request(struct virtio_mem *vm, uint64_t diff) ...@@ -1341,7 +1341,7 @@ static int virtio_mem_plug_request(struct virtio_mem *vm, uint64_t diff)
/* Try to plug subblocks of partially plugged online blocks. */ /* Try to plug subblocks of partially plugged online blocks. */
virtio_mem_sbm_for_each_mb(vm, mb_id, virtio_mem_sbm_for_each_mb(vm, mb_id,
VIRTIO_MEM_SBM_MB_ONLINE_PARTIAL) { VIRTIO_MEM_SBM_MB_ONLINE_PARTIAL) {
rc = virtio_mem_mb_plug_any_sb(vm, mb_id, &nb_sb, true); rc = virtio_mem_sbm_plug_any_sb(vm, mb_id, &nb_sb, true);
if (rc || !nb_sb) if (rc || !nb_sb)
goto out_unlock; goto out_unlock;
cond_resched(); cond_resched();
...@@ -1350,7 +1350,7 @@ static int virtio_mem_plug_request(struct virtio_mem *vm, uint64_t diff) ...@@ -1350,7 +1350,7 @@ static int virtio_mem_plug_request(struct virtio_mem *vm, uint64_t diff)
/* Try to plug subblocks of partially plugged offline blocks. */ /* Try to plug subblocks of partially plugged offline blocks. */
virtio_mem_sbm_for_each_mb(vm, mb_id, virtio_mem_sbm_for_each_mb(vm, mb_id,
VIRTIO_MEM_SBM_MB_OFFLINE_PARTIAL) { VIRTIO_MEM_SBM_MB_OFFLINE_PARTIAL) {
rc = virtio_mem_mb_plug_any_sb(vm, mb_id, &nb_sb, false); rc = virtio_mem_sbm_plug_any_sb(vm, mb_id, &nb_sb, false);
if (rc || !nb_sb) if (rc || !nb_sb)
goto out_unlock; goto out_unlock;
cond_resched(); cond_resched();
...@@ -1367,7 +1367,7 @@ static int virtio_mem_plug_request(struct virtio_mem *vm, uint64_t diff) ...@@ -1367,7 +1367,7 @@ static int virtio_mem_plug_request(struct virtio_mem *vm, uint64_t diff)
if (!virtio_mem_could_add_memory(vm, memory_block_size_bytes())) if (!virtio_mem_could_add_memory(vm, memory_block_size_bytes()))
return -ENOSPC; return -ENOSPC;
rc = virtio_mem_mb_plug_and_add(vm, mb_id, &nb_sb); rc = virtio_mem_sbm_plug_and_add_mb(vm, mb_id, &nb_sb);
if (rc || !nb_sb) if (rc || !nb_sb)
return rc; return rc;
cond_resched(); cond_resched();
...@@ -1378,10 +1378,10 @@ static int virtio_mem_plug_request(struct virtio_mem *vm, uint64_t diff) ...@@ -1378,10 +1378,10 @@ static int virtio_mem_plug_request(struct virtio_mem *vm, uint64_t diff)
if (!virtio_mem_could_add_memory(vm, memory_block_size_bytes())) if (!virtio_mem_could_add_memory(vm, memory_block_size_bytes()))
return -ENOSPC; return -ENOSPC;
rc = virtio_mem_prepare_next_mb(vm, &mb_id); rc = virtio_mem_sbm_prepare_next_mb(vm, &mb_id);
if (rc) if (rc)
return rc; return rc;
rc = virtio_mem_mb_plug_and_add(vm, mb_id, &nb_sb); rc = virtio_mem_sbm_plug_and_add_mb(vm, mb_id, &nb_sb);
if (rc) if (rc)
return rc; return rc;
cond_resched(); cond_resched();
...@@ -1402,13 +1402,13 @@ static int virtio_mem_plug_request(struct virtio_mem *vm, uint64_t diff) ...@@ -1402,13 +1402,13 @@ static int virtio_mem_plug_request(struct virtio_mem *vm, uint64_t diff)
* *
* Note: Can fail after some subblocks were successfully unplugged. * Note: Can fail after some subblocks were successfully unplugged.
*/ */
static int virtio_mem_mb_unplug_any_sb_offline(struct virtio_mem *vm, static int virtio_mem_sbm_unplug_any_sb_offline(struct virtio_mem *vm,
unsigned long mb_id, unsigned long mb_id,
uint64_t *nb_sb) uint64_t *nb_sb)
{ {
int rc; int rc;
rc = virtio_mem_mb_unplug_any_sb(vm, mb_id, nb_sb); rc = virtio_mem_sbm_unplug_any_sb(vm, mb_id, nb_sb);
/* some subblocks might have been unplugged even on failure */ /* some subblocks might have been unplugged even on failure */
if (!virtio_mem_sbm_test_sb_plugged(vm, mb_id, 0, vm->sbm.sbs_per_mb)) if (!virtio_mem_sbm_test_sb_plugged(vm, mb_id, 0, vm->sbm.sbs_per_mb))
...@@ -1440,9 +1440,9 @@ static int virtio_mem_mb_unplug_any_sb_offline(struct virtio_mem *vm, ...@@ -1440,9 +1440,9 @@ static int virtio_mem_mb_unplug_any_sb_offline(struct virtio_mem *vm,
* *
* Will modify the state of the memory block. * Will modify the state of the memory block.
*/ */
static int virtio_mem_mb_unplug_sb_online(struct virtio_mem *vm, static int virtio_mem_sbm_unplug_sb_online(struct virtio_mem *vm,
unsigned long mb_id, int sb_id, unsigned long mb_id, int sb_id,
int count) int count)
{ {
const unsigned long nr_pages = PFN_DOWN(vm->sbm.sb_size) * count; const unsigned long nr_pages = PFN_DOWN(vm->sbm.sb_size) * count;
unsigned long start_pfn; unsigned long start_pfn;
...@@ -1456,7 +1456,7 @@ static int virtio_mem_mb_unplug_sb_online(struct virtio_mem *vm, ...@@ -1456,7 +1456,7 @@ static int virtio_mem_mb_unplug_sb_online(struct virtio_mem *vm,
return rc; return rc;
/* Try to unplug the allocated memory */ /* Try to unplug the allocated memory */
rc = virtio_mem_mb_unplug_sb(vm, mb_id, sb_id, count); rc = virtio_mem_sbm_unplug_sb(vm, mb_id, sb_id, count);
if (rc) { if (rc) {
/* Return the memory to the buddy. */ /* Return the memory to the buddy. */
virtio_mem_fake_online(start_pfn, nr_pages); virtio_mem_fake_online(start_pfn, nr_pages);
...@@ -1478,17 +1478,17 @@ static int virtio_mem_mb_unplug_sb_online(struct virtio_mem *vm, ...@@ -1478,17 +1478,17 @@ static int virtio_mem_mb_unplug_sb_online(struct virtio_mem *vm,
* Note: Can fail after some subblocks were successfully unplugged. Can * Note: Can fail after some subblocks were successfully unplugged. Can
* return 0 even if subblocks were busy and could not get unplugged. * return 0 even if subblocks were busy and could not get unplugged.
*/ */
static int virtio_mem_mb_unplug_any_sb_online(struct virtio_mem *vm, static int virtio_mem_sbm_unplug_any_sb_online(struct virtio_mem *vm,
unsigned long mb_id, unsigned long mb_id,
uint64_t *nb_sb) uint64_t *nb_sb)
{ {
int rc, sb_id; int rc, sb_id;
/* If possible, try to unplug the complete block in one shot. */ /* If possible, try to unplug the complete block in one shot. */
if (*nb_sb >= vm->sbm.sbs_per_mb && if (*nb_sb >= vm->sbm.sbs_per_mb &&
virtio_mem_sbm_test_sb_plugged(vm, mb_id, 0, vm->sbm.sbs_per_mb)) { virtio_mem_sbm_test_sb_plugged(vm, mb_id, 0, vm->sbm.sbs_per_mb)) {
rc = virtio_mem_mb_unplug_sb_online(vm, mb_id, 0, rc = virtio_mem_sbm_unplug_sb_online(vm, mb_id, 0,
vm->sbm.sbs_per_mb); vm->sbm.sbs_per_mb);
if (!rc) { if (!rc) {
*nb_sb -= vm->sbm.sbs_per_mb; *nb_sb -= vm->sbm.sbs_per_mb;
goto unplugged; goto unplugged;
...@@ -1505,7 +1505,7 @@ static int virtio_mem_mb_unplug_any_sb_online(struct virtio_mem *vm, ...@@ -1505,7 +1505,7 @@ static int virtio_mem_mb_unplug_any_sb_online(struct virtio_mem *vm,
if (sb_id < 0) if (sb_id < 0)
break; break;
rc = virtio_mem_mb_unplug_sb_online(vm, mb_id, sb_id, 1); rc = virtio_mem_sbm_unplug_sb_online(vm, mb_id, sb_id, 1);
if (rc == -EBUSY) if (rc == -EBUSY)
continue; continue;
else if (rc) else if (rc)
...@@ -1553,8 +1553,7 @@ static int virtio_mem_unplug_request(struct virtio_mem *vm, uint64_t diff) ...@@ -1553,8 +1553,7 @@ static int virtio_mem_unplug_request(struct virtio_mem *vm, uint64_t diff)
/* Try to unplug subblocks of partially plugged offline blocks. */ /* Try to unplug subblocks of partially plugged offline blocks. */
virtio_mem_sbm_for_each_mb_rev(vm, mb_id, virtio_mem_sbm_for_each_mb_rev(vm, mb_id,
VIRTIO_MEM_SBM_MB_OFFLINE_PARTIAL) { VIRTIO_MEM_SBM_MB_OFFLINE_PARTIAL) {
rc = virtio_mem_mb_unplug_any_sb_offline(vm, mb_id, rc = virtio_mem_sbm_unplug_any_sb_offline(vm, mb_id, &nb_sb);
&nb_sb);
if (rc || !nb_sb) if (rc || !nb_sb)
goto out_unlock; goto out_unlock;
cond_resched(); cond_resched();
...@@ -1562,8 +1561,7 @@ static int virtio_mem_unplug_request(struct virtio_mem *vm, uint64_t diff) ...@@ -1562,8 +1561,7 @@ static int virtio_mem_unplug_request(struct virtio_mem *vm, uint64_t diff)
/* Try to unplug subblocks of plugged offline blocks. */ /* Try to unplug subblocks of plugged offline blocks. */
virtio_mem_sbm_for_each_mb_rev(vm, mb_id, VIRTIO_MEM_SBM_MB_OFFLINE) { virtio_mem_sbm_for_each_mb_rev(vm, mb_id, VIRTIO_MEM_SBM_MB_OFFLINE) {
rc = virtio_mem_mb_unplug_any_sb_offline(vm, mb_id, rc = virtio_mem_sbm_unplug_any_sb_offline(vm, mb_id, &nb_sb);
&nb_sb);
if (rc || !nb_sb) if (rc || !nb_sb)
goto out_unlock; goto out_unlock;
cond_resched(); cond_resched();
...@@ -1577,8 +1575,7 @@ static int virtio_mem_unplug_request(struct virtio_mem *vm, uint64_t diff) ...@@ -1577,8 +1575,7 @@ static int virtio_mem_unplug_request(struct virtio_mem *vm, uint64_t diff)
/* Try to unplug subblocks of partially plugged online blocks. */ /* Try to unplug subblocks of partially plugged online blocks. */
virtio_mem_sbm_for_each_mb_rev(vm, mb_id, virtio_mem_sbm_for_each_mb_rev(vm, mb_id,
VIRTIO_MEM_SBM_MB_ONLINE_PARTIAL) { VIRTIO_MEM_SBM_MB_ONLINE_PARTIAL) {
rc = virtio_mem_mb_unplug_any_sb_online(vm, mb_id, rc = virtio_mem_sbm_unplug_any_sb_online(vm, mb_id, &nb_sb);
&nb_sb);
if (rc || !nb_sb) if (rc || !nb_sb)
goto out_unlock; goto out_unlock;
mutex_unlock(&vm->hotplug_mutex); mutex_unlock(&vm->hotplug_mutex);
...@@ -1588,8 +1585,7 @@ static int virtio_mem_unplug_request(struct virtio_mem *vm, uint64_t diff) ...@@ -1588,8 +1585,7 @@ static int virtio_mem_unplug_request(struct virtio_mem *vm, uint64_t diff)
/* Try to unplug subblocks of plugged online blocks. */ /* Try to unplug subblocks of plugged online blocks. */
virtio_mem_sbm_for_each_mb_rev(vm, mb_id, VIRTIO_MEM_SBM_MB_ONLINE) { virtio_mem_sbm_for_each_mb_rev(vm, mb_id, VIRTIO_MEM_SBM_MB_ONLINE) {
rc = virtio_mem_mb_unplug_any_sb_online(vm, mb_id, rc = virtio_mem_sbm_unplug_any_sb_online(vm, mb_id, &nb_sb);
&nb_sb);
if (rc || !nb_sb) if (rc || !nb_sb)
goto out_unlock; goto out_unlock;
mutex_unlock(&vm->hotplug_mutex); mutex_unlock(&vm->hotplug_mutex);
...@@ -1614,7 +1610,7 @@ static int virtio_mem_unplug_pending_mb(struct virtio_mem *vm) ...@@ -1614,7 +1610,7 @@ static int virtio_mem_unplug_pending_mb(struct virtio_mem *vm)
int rc; int rc;
virtio_mem_sbm_for_each_mb(vm, mb_id, VIRTIO_MEM_SBM_MB_PLUGGED) { virtio_mem_sbm_for_each_mb(vm, mb_id, VIRTIO_MEM_SBM_MB_PLUGGED) {
rc = virtio_mem_mb_unplug(vm, mb_id); rc = virtio_mem_sbm_unplug_mb(vm, mb_id);
if (rc) if (rc)
return rc; return rc;
virtio_mem_sbm_set_mb_state(vm, mb_id, virtio_mem_sbm_set_mb_state(vm, mb_id,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment