[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH RESEND v3 01/10] dirtylimit: Fix overflow when computing MB
From: |
huangy81 |
Subject: |
[PATCH RESEND v3 01/10] dirtylimit: Fix overflow when computing MB |
Date: |
Sun, 4 Dec 2022 01:09:04 +0800 |
From: Hyman Huang(黄勇) <huangy81@chinatelecom.cn>
Coverity points out a overflow problem when computing MB,
dirty_ring_size and TARGET_PAGE_SIZE are both 32 bits,
multiplication will be done as a 32-bit operation, which
could overflow. Simplify the formula.
Meanwhile, fix spelling mistake of variable name.
Reported-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Hyman Huang(黄勇) <huangy81@chinatelecom.cn>
Reviewed-by: Peter Xu <peterx@redhat.com>
---
softmmu/dirtylimit.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/softmmu/dirtylimit.c b/softmmu/dirtylimit.c
index 1266855..940d238 100644
--- a/softmmu/dirtylimit.c
+++ b/softmmu/dirtylimit.c
@@ -236,14 +236,14 @@ static inline int64_t
dirtylimit_dirty_ring_full_time(uint64_t dirtyrate)
{
static uint64_t max_dirtyrate;
uint32_t dirty_ring_size = kvm_dirty_ring_size();
- uint64_t dirty_ring_size_meory_MB =
- dirty_ring_size * TARGET_PAGE_SIZE >> 20;
+ uint32_t dirty_ring_size_memory_MB =
+ dirty_ring_size >> (20 - TARGET_PAGE_BITS);
if (max_dirtyrate < dirtyrate) {
max_dirtyrate = dirtyrate;
}
- return dirty_ring_size_meory_MB * 1000000 / max_dirtyrate;
+ return dirty_ring_size_memory_MB * 1000000ULL / max_dirtyrate;
}
static inline bool dirtylimit_done(uint64_t quota,
--
1.8.3.1
- [PATCH RESEND v3 00/10] migration: introduce dirtylimit capability, huangy81, 2022/12/03
- [PATCH RESEND v3 01/10] dirtylimit: Fix overflow when computing MB,
huangy81 <=
- [PATCH RESEND v3 02/10] softmmu/dirtylimit: Add parameter check for hmp "set_vcpu_dirty_limit", huangy81, 2022/12/03
- [PATCH RESEND v3 03/10] kvm: dirty-ring: Fix race with vcpu creation, huangy81, 2022/12/03
- [PATCH RESEND v3 04/10] qapi/migration: Introduce x-vcpu-dirty-limit-period parameter, huangy81, 2022/12/03
- [PATCH RESEND v3 05/10] qapi/migration: Introduce vcpu-dirty-limit parameters, huangy81, 2022/12/03
- [PATCH RESEND v3 06/10] migration: Introduce dirty-limit capability, huangy81, 2022/12/03
- [PATCH RESEND v3 07/10] migration: Refactor auto-converge capability logic, huangy81, 2022/12/03
- [PATCH RESEND v3 08/10] migration: Implement dirty-limit convergence algo, huangy81, 2022/12/03
- [PATCH RESEND v3 09/10] migration: Export dirty-limit time info for observation, huangy81, 2022/12/03
- [PATCH RESEND v3 10/10] tests: Add migration dirty-limit capability test, huangy81, 2022/12/03