* [PATCH] colo: fix return without releasing RCU
@ 2019-12-13 14:08 Paolo Bonzini
2019-12-13 15:03 ` Dr. David Alan Gilbert
0 siblings, 1 reply; 3+ messages in thread
From: Paolo Bonzini @ 2019-12-13 14:08 UTC (permalink / raw)
To: qemu-devel; +Cc: Dr. David Alan Gilbert
Use WITH_RCU_READ_LOCK_GUARD to avoid exiting colo_init_ram_cache
without releasing RCU.
Cc: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
migration/ram.c | 33 +++++++++++++++++----------------
1 file changed, 17 insertions(+), 16 deletions(-)
diff --git a/migration/ram.c b/migration/ram.c
index 7dd7f81..8d7c015 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -3891,26 +3891,27 @@ int colo_init_ram_cache(void)
{
RAMBlock *block;
- rcu_read_lock();
- RAMBLOCK_FOREACH_NOT_IGNORED(block) {
- block->colo_cache = qemu_anon_ram_alloc(block->used_length,
- NULL,
- false);
- if (!block->colo_cache) {
- error_report("%s: Can't alloc memory for COLO cache of block %s,"
- "size 0x" RAM_ADDR_FMT, __func__, block->idstr,
- block->used_length);
- RAMBLOCK_FOREACH_NOT_IGNORED(block) {
- if (block->colo_cache) {
- qemu_anon_ram_free(block->colo_cache, block->used_length);
- block->colo_cache = NULL;
+ WITH_RCU_READ_LOCK_GUARD() {
+ RAMBLOCK_FOREACH_NOT_IGNORED(block) {
+ block->colo_cache = qemu_anon_ram_alloc(block->used_length,
+ NULL,
+ false);
+ if (!block->colo_cache) {
+ error_report("%s: Can't alloc memory for COLO cache of block %s,"
+ "size 0x" RAM_ADDR_FMT, __func__, block->idstr,
+ block->used_length);
+ RAMBLOCK_FOREACH_NOT_IGNORED(block) {
+ if (block->colo_cache) {
+ qemu_anon_ram_free(block->colo_cache, block->used_length);
+ block->colo_cache = NULL;
+ }
}
+ return -errno;
}
- return -errno;
+ memcpy(block->colo_cache, block->host, block->used_length);
}
- memcpy(block->colo_cache, block->host, block->used_length);
}
- rcu_read_unlock();
+
/*
* Record the dirty pages that sent by PVM, we use this dirty bitmap together
* with to decide which page in cache should be flushed into SVM's RAM. Here
--
1.8.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] colo: fix return without releasing RCU
2019-12-13 14:08 [PATCH] colo: fix return without releasing RCU Paolo Bonzini
@ 2019-12-13 15:03 ` Dr. David Alan Gilbert
2019-12-14 17:47 ` Zhang, Chen
0 siblings, 1 reply; 3+ messages in thread
From: Dr. David Alan Gilbert @ 2019-12-13 15:03 UTC (permalink / raw)
To: Paolo Bonzini, quintela, chen.zhang; +Cc: qemu-devel
* Paolo Bonzini (pbonzini@redhat.com) wrote:
> Use WITH_RCU_READ_LOCK_GUARD to avoid exiting colo_init_ram_cache
> without releasing RCU.
>
> Cc: Dr. David Alan Gilbert <dgilbert@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> ---
> migration/ram.c | 33 +++++++++++++++++----------------
> 1 file changed, 17 insertions(+), 16 deletions(-)
>
> diff --git a/migration/ram.c b/migration/ram.c
> index 7dd7f81..8d7c015 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -3891,26 +3891,27 @@ int colo_init_ram_cache(void)
> {
> RAMBlock *block;
>
> - rcu_read_lock();
> - RAMBLOCK_FOREACH_NOT_IGNORED(block) {
> - block->colo_cache = qemu_anon_ram_alloc(block->used_length,
> - NULL,
> - false);
> - if (!block->colo_cache) {
> - error_report("%s: Can't alloc memory for COLO cache of block %s,"
> - "size 0x" RAM_ADDR_FMT, __func__, block->idstr,
> - block->used_length);
> - RAMBLOCK_FOREACH_NOT_IGNORED(block) {
> - if (block->colo_cache) {
> - qemu_anon_ram_free(block->colo_cache, block->used_length);
> - block->colo_cache = NULL;
> + WITH_RCU_READ_LOCK_GUARD() {
> + RAMBLOCK_FOREACH_NOT_IGNORED(block) {
> + block->colo_cache = qemu_anon_ram_alloc(block->used_length,
> + NULL,
> + false);
> + if (!block->colo_cache) {
> + error_report("%s: Can't alloc memory for COLO cache of block %s,"
> + "size 0x" RAM_ADDR_FMT, __func__, block->idstr,
> + block->used_length);
> + RAMBLOCK_FOREACH_NOT_IGNORED(block) {
> + if (block->colo_cache) {
> + qemu_anon_ram_free(block->colo_cache, block->used_length);
> + block->colo_cache = NULL;
> + }
> }
> + return -errno;
> }
> - return -errno;
> + memcpy(block->colo_cache, block->host, block->used_length);
> }
> - memcpy(block->colo_cache, block->host, block->used_length);
> }
> - rcu_read_unlock();
> +
> /*
> * Record the dirty pages that sent by PVM, we use this dirty bitmap together
> * with to decide which page in cache should be flushed into SVM's RAM. Here
> --
> 1.8.3.1
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] colo: fix return without releasing RCU
2019-12-13 15:03 ` Dr. David Alan Gilbert
@ 2019-12-14 17:47 ` Zhang, Chen
0 siblings, 0 replies; 3+ messages in thread
From: Zhang, Chen @ 2019-12-14 17:47 UTC (permalink / raw)
To: Dr. David Alan Gilbert, Paolo Bonzini, quintela; +Cc: qemu-devel
On 12/13/2019 11:03 PM, Dr. David Alan Gilbert wrote:
> * Paolo Bonzini (pbonzini@redhat.com) wrote:
>> Use WITH_RCU_READ_LOCK_GUARD to avoid exiting colo_init_ram_cache
>> without releasing RCU.
>>
>> Cc: Dr. David Alan Gilbert <dgilbert@redhat.com>
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Reviewed-by: Zhang Chen <chen.zhang@intel.com>
>
>> ---
>> migration/ram.c | 33 +++++++++++++++++----------------
>> 1 file changed, 17 insertions(+), 16 deletions(-)
>>
>> diff --git a/migration/ram.c b/migration/ram.c
>> index 7dd7f81..8d7c015 100644
>> --- a/migration/ram.c
>> +++ b/migration/ram.c
>> @@ -3891,26 +3891,27 @@ int colo_init_ram_cache(void)
>> {
>> RAMBlock *block;
>>
>> - rcu_read_lock();
>> - RAMBLOCK_FOREACH_NOT_IGNORED(block) {
>> - block->colo_cache = qemu_anon_ram_alloc(block->used_length,
>> - NULL,
>> - false);
>> - if (!block->colo_cache) {
>> - error_report("%s: Can't alloc memory for COLO cache of block %s,"
>> - "size 0x" RAM_ADDR_FMT, __func__, block->idstr,
>> - block->used_length);
>> - RAMBLOCK_FOREACH_NOT_IGNORED(block) {
>> - if (block->colo_cache) {
>> - qemu_anon_ram_free(block->colo_cache, block->used_length);
>> - block->colo_cache = NULL;
>> + WITH_RCU_READ_LOCK_GUARD() {
>> + RAMBLOCK_FOREACH_NOT_IGNORED(block) {
>> + block->colo_cache = qemu_anon_ram_alloc(block->used_length,
>> + NULL,
>> + false);
>> + if (!block->colo_cache) {
>> + error_report("%s: Can't alloc memory for COLO cache of block %s,"
>> + "size 0x" RAM_ADDR_FMT, __func__, block->idstr,
>> + block->used_length);
>> + RAMBLOCK_FOREACH_NOT_IGNORED(block) {
>> + if (block->colo_cache) {
>> + qemu_anon_ram_free(block->colo_cache, block->used_length);
>> + block->colo_cache = NULL;
>> + }
>> }
>> + return -errno;
>> }
>> - return -errno;
>> + memcpy(block->colo_cache, block->host, block->used_length);
>> }
>> - memcpy(block->colo_cache, block->host, block->used_length);
>> }
>> - rcu_read_unlock();
>> +
>> /*
>> * Record the dirty pages that sent by PVM, we use this dirty bitmap together
>> * with to decide which page in cache should be flushed into SVM's RAM. Here
>> --
>> 1.8.3.1
>>
> --
> Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-12-14 21:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-13 14:08 [PATCH] colo: fix return without releasing RCU Paolo Bonzini
2019-12-13 15:03 ` Dr. David Alan Gilbert
2019-12-14 17:47 ` Zhang, Chen
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.