On Wed, 20 Jul 2022 at 12:30, Dr. David Alan Gilbert (git) <dgilb...@redhat.com> wrote: > > From: Hyman Huang(黄勇) <huang...@chinatelecom.cn> > > Setup a negative feedback system when vCPU thread > handling KVM_EXIT_DIRTY_RING_FULL exit by introducing > throttle_us_per_full field in struct CPUState. Sleep > throttle_us_per_full microseconds to throttle vCPU > if dirtylimit is in service. > > Signed-off-by: Hyman Huang(黄勇) <huang...@chinatelecom.cn> > Reviewed-by: Peter Xu <pet...@redhat.com> > Message-Id: > <977e808e03a1cef5151cae75984658b6821be618.1656177590.git.huang...@chinatelecom.cn> > Signed-off-by: Dr. David Alan Gilbert <dgilb...@redhat.com>
Hi; Coverity points out a problem with this code (CID 1490787): > +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; Because dirty_ring_size and TARGET_PAGE_SIZE are both 32 bits, this multiplication will be done as a 32-bit operation, which could overflow. You should cast one of the operands to uint64_t to ensure that the operation is done as a 64 bit multiplication. Side note: typo in the variable name: should be 'memory'. > + if (max_dirtyrate < dirtyrate) { > + max_dirtyrate = dirtyrate; > + } > + > + return dirty_ring_size_meory_MB * 1000000 / max_dirtyrate; > +} thanks -- PMM