KVM: Dirty quota-based throttling
Subsystems (7)
v8 cover KVM: Dirty quota-based throttling
This is v8 of the dirty quota series, with the following changes over v7:
1. Removed pages_dirtied stat. Now, a single variable dirty_quota_bytes is being used for throttling.
2. IOCTL to enable/disable dirty quota throttling. Enabling/disabling can be done dynamically, e.g. we can enable dirty quota just before a live migration and disable it just after the live migration.
3. Decoupled dirty quota from dirty logging. Introduced a new function update_dirty_quota that decreases dirty_quota_bytes by by the appropriate architecture-specific granule or page size. It also raises a KVM request if dirty quota is exhausted.
4. Each arch that wants to use dirty quota throttling feature needs to call update_dirty_quota at each time a page is dirtied. Also, it needs to process the KVM request raised by update_dirty_quota and facilitate exit to userspace. Added support for x86 and arm64.
5. Code refactoring and minor nits.
v1:
https://lore.kernel.org/kvm/[email protected]/
v2: https://lore.kernel.org/kvm/[email protected]/T/
v3: https://lore.kernel.org/kvm/[email protected]/T/
v4:
https://lore.kernel.org/all/[email protected]/
v5: https://lore.kernel.org/all/[email protected]/T/
v6:
https://lore.kernel.org/all/[email protected]/
v7:
https://lore.kernel.org/all/[email protected]/t/
Thanks,
Shivam
Shivam Kumar (3):
KVM: Implement dirty quota-based throttling of vcpus
KVM: x86: Dirty quota-based throttling of vcpus
KVM: arm64: Dirty quota-based throttling of vcpus
Documentation/virt/kvm/api.rst | 17 +++++++++++++++++ arch/arm64/kvm/Kconfig | 1 + arch/arm64/kvm/arm.c | 7 +++++++ arch/arm64/kvm/mmu.c | 3 +++ arch/x86/kvm/Kconfig | 1 + arch/x86/kvm/mmu/mmu.c | 8 +++++++- arch/x86/kvm/mmu/spte.c | 3 +++ arch/x86/kvm/mmu/tdp_mmu.c | 3 +++ arch/x86/kvm/vmx/vmx.c | 5 +++++ arch/x86/kvm/x86.c | 16 ++++++++++++++++ arch/x86/kvm/xen.c | 12 +++++++++++- include/linux/kvm_host.h | 5 +++++ include/uapi/linux/kvm.h | 8 ++++++++ tools/include/uapi/linux/kvm.h | 1 + virt/kvm/Kconfig | 3 +++ virt/kvm/kvm_main.c | 31 +++++++++++++++++++++++++++++++ 16 files changed, 122 insertions(+), 2 deletions(-)
Signature · 1 line
2.22.3
PATCH v8 1/3 KVM: Implement dirty quota-based throttling of vcpus
Define dirty_quota_bytes variable to track and throttle memory dirtying for every vcpu. This variable stores the number of bytes the vcpu is allowed to dirty. To dirty more, the vcpu needs to request more quota by exiting to userspace.
Implement update_dirty_quota function which
i) Decreases dirty_quota_bytes by arch-specific page size whenever a page is dirtied.
ii) Raises a KVM request KVM_REQ_DIRTY_QUOTA_EXIT whenever the dirty quota is exhausted (i.e. dirty_quota_bytes <= 0).
--- Documentation/virt/kvm/api.rst | 17 +++++++++++++++++ include/linux/kvm_host.h | 5 +++++ include/uapi/linux/kvm.h | 8 ++++++++ tools/include/uapi/linux/kvm.h | 1 + virt/kvm/Kconfig | 3 +++ virt/kvm/kvm_main.c | 31 +++++++++++++++++++++++++++++++ 6 files changed, 65 insertions(+)
Documentation/virt/kvm/api.rst +17 -0
@@ -6688,6 +6688,23 @@ Please note that the kernel is allowed to use the kvm_run structure as the primary storage for certain register types. Therefore, the kernel may use the values in kvm_run even if the corresponding bit in kvm_dirty_regs is not set. +:: + + /* + * Number of bytes the vCPU is allowed to dirty if KVM_CAP_DIRTY_QUOTA is + * enabled. KVM_RUN exits with KVM_EXIT_DIRTY_QUOTA_EXHAUSTED if this quota + * is exhausted, i.e. dirty_quota_bytes <= 0. + */ + long dirty_quota_bytes; + +Please note that enforcing the quota is best effort. Dirty quota is reduced by +arch-specific page size when any guest page is dirtied. Also, the guest may dirty +multiple pages before KVM can recheck the quota. + +:: + }; + + 6. Capabilities that can be enabled on vCPUs ============================================
include/linux/kvm_host.h +5 -0
@@ -167,6 +167,7 @@ static inline bool is_error_page(struct page *page)#define KVM_REQ_VM_DEAD (1 | KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP)#define KVM_REQ_UNBLOCK 2#define KVM_REQ_DIRTY_RING_SOFT_FULL 3 +#define KVM_REQ_DIRTY_QUOTA_EXIT 4#define KVM_REQUEST_ARCH_BASE 8/*
@@ -800,6 +801,9 @@ struct kvm {bool dirty_ring_with_bitmap;bool vm_bugged;bool vm_dead; +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +bool dirty_quota_enabled; +#endif #ifdef CONFIG_HAVE_KVM_PM_NOTIFIER struct notifier_block pm_notifier;
@@ -1235,6 +1239,7 @@ struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn);bool kvm_is_visible_gfn (struct kvm *kvm,gfn_t gfn);bool kvm_vcpu_is_visible_gfn (struct kvm_vcpu *vcpu,gfn_t gfn);unsigned long kvm_host_page_size (struct kvm_vcpu *vcpu,gfn_t gfn); +void update_dirty_quota (struct kvm *kvm,unsigned long page_size_bytes);void mark_page_dirty_in_slot (struct kvm *kvm,const struct kvm_memory_slot *memslot,gfn_t gfn);void mark_page_dirty (struct kvm *kvm,gfn_t gfn);
include/uapi/linux/kvm.h +8 -0
@@ -264,6 +264,7 @@ struct kvm_xen_exit {#define KVM_EXIT_RISCV_SBI 35#define KVM_EXIT_RISCV_CSR 36#define KVM_EXIT_NOTIFY 37 +#define KVM_EXIT_DIRTY_QUOTA_EXHAUSTED 38/* For KVM_EXIT_INTERNAL_ERROR */ /* Emulate instruction failed. */
@@ -526,6 +527,12 @@ struct kvm_run {struct kvm_sync_regs regs;char padding[SYNC_REGS_SIZE_BYTES ]; } s; +/* +* Number of bytes the vCPU is allowed to dirty if KVM_CAP_DIRTY_QUOTA is +* enabled. KVM_RUN exits with KVM_EXIT_DIRTY_QUOTA_EXHAUSTED if this quota +* is exhausted, i.e. dirty_quota_bytes <= 0. +*/ +long dirty_quota_bytes; };/* for KVM_REGISTER_COALESCED_MMIO / KVM_UNREGISTER_COALESCED_MMIO */
@@ -1184,6 +1191,7 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_S390_PROTECTED_ASYNC_DISABLE 224#define KVM_CAP_DIRTY_LOG_RING_WITH_BITMAP 225#define KVM_CAP_PMU_EVENT_MASKED_EVENTS 226 +#define KVM_CAP_DIRTY_QUOTA 227#ifdef KVM_CAP_IRQ_ROUTING
tools/include/uapi/linux/kvm.h +1 -0
@@ -1175,6 +1175,7 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_DIRTY_LOG_RING_ACQ_REL 223#define KVM_CAP_S390_PROTECTED_ASYNC_DISABLE 224#define KVM_CAP_DIRTY_LOG_RING_WITH_BITMAP 225 +#define KVM_CAP_DIRTY_QUOTA 227#ifdef KVM_CAP_IRQ_ROUTING
virt/kvm/Kconfig +3 -0
@@ -19,6 +19,9 @@ config HAVE_KVM_IRQ_ROUTING config HAVE_KVM_DIRTY_RING bool +config HAVE_KVM_DIRTY_QUOTA + bool + # Only strongly ordered architectures can select this, as it doesn't # put any explicit constraint on userspace ordering. They can also # select the _ACQ_REL version.
virt/kvm/kvm_main.c +31 -0
@@ -3096,6 +3096,9 @@ static int __kvm_write_guest_page(struct kvm *kvm, r =__copy_to_user ((void __user *)addr + offset, data, len);if (r)return -EFAULT ; +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +update_dirty_quota (kvm,PAGE_SIZE ); +#endif mark_page_dirty_in_slot (kvm, memslot, gfn);return 0 ; }
@@ -3234,6 +3237,9 @@ int kvm_write_guest_offset_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc, r =__copy_to_user ((void __user *)ghc->hva + offset, data, len);if (r)return -EFAULT ; +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +update_dirty_quota (kvm,PAGE_SIZE ); +#endif mark_page_dirty_in_slot (kvm, ghc->memslot, gpa >>PAGE_SHIFT );return 0 ;
@@ -3304,6 +3310,18 @@ int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len) }EXPORT_SYMBOL_GPL (kvm_clear_guest); +void update_dirty_quota (struct kvm *kvm,unsigned long page_size_bytes) +{ +struct kvm_vcpu *vcpu =kvm_get_running_vcpu (); + +if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE (kvm->dirty_quota_enabled)) +return ; + + vcpu->run->dirty_quota_bytes -= page_size_bytes; +if (vcpu->run->dirty_quota_bytes <=0 ) +kvm_make_request (KVM_REQ_DIRTY_QUOTA_EXIT , vcpu); +} +void mark_page_dirty_in_slot (struct kvm *kvm,const struct kvm_memory_slot *memslot,gfn_t gfn)
@@ -3334,6 +3352,9 @@ void mark_page_dirty(struct kvm *kvm, gfn_t gfn)struct kvm_memory_slot *memslot; memslot =gfn_to_memslot (kvm, gfn); +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +update_dirty_quota (kvm,PAGE_SIZE ); +#endif mark_page_dirty_in_slot (kvm, memslot, gfn); }EXPORT_SYMBOL_GPL (mark_page_dirty);
@@ -3343,6 +3364,9 @@ void kvm_vcpu_mark_page_dirty(struct kvm_vcpu *vcpu, gfn_t gfn)struct kvm_memory_slot *memslot; memslot =kvm_vcpu_gfn_to_memslot (vcpu, gfn); +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +update_dirty_quota (vcpu->kvm,PAGE_SIZE ); +#endif mark_page_dirty_in_slot (vcpu->kvm, memslot, gfn); }EXPORT_SYMBOL_GPL (kvm_vcpu_mark_page_dirty);
@@ -4524,6 +4548,8 @@ static long kvm_vm_ioctl_check_extension_generic(struct kvm *kvm, long arg)case KVM_CAP_BINARY_STATS_FD :case KVM_CAP_SYSTEM_EVENT_DATA :return 1 ; +case KVM_CAP_DIRTY_QUOTA : +return !!IS_ENABLED (CONFIG_HAVE_KVM_DIRTY_QUOTA );default :break ; }
@@ -4673,6 +4699,11 @@ static int kvm_vm_ioctl_enable_cap_generic(struct kvm *kvm,return r; } +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +case KVM_CAP_DIRTY_QUOTA : +WRITE_ONCE (kvm->dirty_quota_enabled, cap->args[0 ]); +return 0 ; +#endif default :return kvm_vm_ioctl_enable_cap (kvm, cap); }
Signature · 1 line
2.22.3
kernel test robot
build botRe: [PATCH v8 1/3] KVM: Implement dirty quota-based throttling of vcpus
Thank you for the patch! Yet something to improve:
Hi Shivam,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on kvm/queue]
[also build test ERROR on linus/master next-20230225] [cannot apply to kvmarm/next mst-vhost/linux-next kvm/linux-next v6.2] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Shivam-Kumar/KVM-Implement-dirty-quota-based-throttling-of-vcpus/20230226-045019 base: https://git.kernel.org/pub/scm/virt/kvm/kvm.git queue patch link: https://lore.kernel.org/r/20230225204758.17726-2-shivam.kumar1%40nutanix.com patch subject: [PATCH v8 1/3] KVM: Implement dirty quota-based throttling of vcpus config: i386-debian-10.3 (https://download.01.org/0day-ci/archive/20230226/[email protected]/config) compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
# https://github.com/intel-lab-lkp/linux/commit/bdbf0891df39e87ef29d704ad4b9866ec34ea20c
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Shivam-Kumar/KVM-Implement-dirty-quota-based-throttling-of-vcpus/20230226-045019 git checkout bdbf0891df39e87ef29d704ad4b9866ec34ea20c
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=i386 olddefconfig
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from <command-line>:
arch/x86/kvm/../../../virt/kvm/kvm_main.c: In function 'update_dirty_quota':
>> arch/x86/kvm/../../../virt/kvm/kvm_main.c:3317:58: error: 'struct kvm' has no member named 'dirty_quota_enabled'
3317 | if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
| ^~
include/linux/compiler_types.h:338:23: note: in definition of macro '__compiletime_assert'
338 | if (!(condition)) \
| ^~~~~~~~~
include/linux/compiler_types.h:358:9: note: in expansion of macro '_compiletime_assert'
358 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:36:9: note: in expansion of macro 'compiletime_assert'
36 | compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
| ^~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:36:28: note: in expansion of macro '__native_word'
36 | compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
| ^~~~~~~~~~~~~
include/asm-generic/rwonce.h:49:9: note: in expansion of macro 'compiletime_assert_rwonce_type'
49 | compiletime_assert_rwonce_type(x); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/x86/kvm/../../../virt/kvm/kvm_main.c:3317:45: note: in expansion of macro 'READ_ONCE'
3317 | if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
| ^~~~~~~~~
>> arch/x86/kvm/../../../virt/kvm/kvm_main.c:3317:58: error: 'struct kvm' has no member named 'dirty_quota_enabled'
3317 | if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
| ^~
include/linux/compiler_types.h:338:23: note: in definition of macro '__compiletime_assert'
338 | if (!(condition)) \
| ^~~~~~~~~
include/linux/compiler_types.h:358:9: note: in expansion of macro '_compiletime_assert'
358 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:36:9: note: in expansion of macro 'compiletime_assert'
36 | compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
| ^~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:36:28: note: in expansion of macro '__native_word'
36 | compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
| ^~~~~~~~~~~~~
include/asm-generic/rwonce.h:49:9: note: in expansion of macro 'compiletime_assert_rwonce_type'
49 | compiletime_assert_rwonce_type(x); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/x86/kvm/../../../virt/kvm/kvm_main.c:3317:45: note: in expansion of macro 'READ_ONCE'
3317 | if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
| ^~~~~~~~~
>> arch/x86/kvm/../../../virt/kvm/kvm_main.c:3317:58: error: 'struct kvm' has no member named 'dirty_quota_enabled'
3317 | if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
| ^~
include/linux/compiler_types.h:338:23: note: in definition of macro '__compiletime_assert'
338 | if (!(condition)) \
| ^~~~~~~~~
include/linux/compiler_types.h:358:9: note: in expansion of macro '_compiletime_assert'
358 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:36:9: note: in expansion of macro 'compiletime_assert'
36 | compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
| ^~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:36:28: note: in expansion of macro '__native_word'
36 | compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
| ^~~~~~~~~~~~~
include/asm-generic/rwonce.h:49:9: note: in expansion of macro 'compiletime_assert_rwonce_type'
49 | compiletime_assert_rwonce_type(x); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/x86/kvm/../../../virt/kvm/kvm_main.c:3317:45: note: in expansion of macro 'READ_ONCE'
3317 | if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
| ^~~~~~~~~
>> arch/x86/kvm/../../../virt/kvm/kvm_main.c:3317:58: error: 'struct kvm' has no member named 'dirty_quota_enabled'
3317 | if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
| ^~
include/linux/compiler_types.h:338:23: note: in definition of macro '__compiletime_assert'
338 | if (!(condition)) \
| ^~~~~~~~~
include/linux/compiler_types.h:358:9: note: in expansion of macro '_compiletime_assert'
358 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:36:9: note: in expansion of macro 'compiletime_assert'
36 | compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
| ^~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:36:28: note: in expansion of macro '__native_word'
36 | compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
| ^~~~~~~~~~~~~
include/asm-generic/rwonce.h:49:9: note: in expansion of macro 'compiletime_assert_rwonce_type'
49 | compiletime_assert_rwonce_type(x); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/x86/kvm/../../../virt/kvm/kvm_main.c:3317:45: note: in expansion of macro 'READ_ONCE'
3317 | if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
| ^~~~~~~~~
>> arch/x86/kvm/../../../virt/kvm/kvm_main.c:3317:58: error: 'struct kvm' has no member named 'dirty_quota_enabled'
3317 | if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
| ^~
include/linux/compiler_types.h:338:23: note: in definition of macro '__compiletime_assert'
338 | if (!(condition)) \
| ^~~~~~~~~
include/linux/compiler_types.h:358:9: note: in expansion of macro '_compiletime_assert'
358 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:36:9: note: in expansion of macro 'compiletime_assert'
36 | compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
| ^~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:49:9: note: in expansion of macro 'compiletime_assert_rwonce_type'
49 | compiletime_assert_rwonce_type(x); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/x86/kvm/../../../virt/kvm/kvm_main.c:3317:45: note: in expansion of macro 'READ_ONCE'
3317 | if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
| ^~~~~~~~~
>> arch/x86/kvm/../../../virt/kvm/kvm_main.c:3317:58: error: 'struct kvm' has no member named 'dirty_quota_enabled'
3317 | if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
| ^~
include/linux/compiler_types.h:314:27: note: in definition of macro '__unqual_scalar_typeof'
314 | _Generic((x), \
| ^
include/asm-generic/rwonce.h:50:9: note: in expansion of macro '__READ_ONCE'
50 | __READ_ONCE(x); \
| ^~~~~~~~~~~
arch/x86/kvm/../../../virt/kvm/kvm_main.c:3317:45: note: in expansion of macro 'READ_ONCE'
3317 | if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
| ^~~~~~~~~
In file included from ./arch/x86/include/generated/asm/rwonce.h:1,
from include/linux/compiler.h:247,
from include/linux/build_bug.h:5,
from include/linux/bits.h:22,
from include/linux/kvm_types.h:21,
from include/kvm/iodev.h:6,
from arch/x86/kvm/../../../virt/kvm/kvm_main.c:16:
>> arch/x86/kvm/../../../virt/kvm/kvm_main.c:3317:58: error: 'struct kvm' has no member named 'dirty_quota_enabled'
3317 | if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
| ^~
include/asm-generic/rwonce.h:44:73: note: in definition of macro '__READ_ONCE'
44 | #define __READ_ONCE(x) (*(const volatile __unqual_scalar_typeof(x) *)&(x))
| ^
arch/x86/kvm/../../../virt/kvm/kvm_main.c:3317:45: note: in expansion of macro 'READ_ONCE'
3317 | if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
| ^~~~~~~~~vim +3317 arch/x86/kvm/../../../virt/kvm/kvm_main.c
3312
3313 void update_dirty_quota(struct kvm *kvm, unsigned long page_size_bytes)
3314 {
3315 struct kvm_vcpu *vcpu = kvm_get_running_vcpu();
3316
> 3317 if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
3318 return;
3319
3320 vcpu->run->dirty_quota_bytes -= page_size_bytes;
3321 if (vcpu->run->dirty_quota_bytes <= 0)
3322 kvm_make_request(KVM_REQ_DIRTY_QUOTA_EXIT, vcpu);
3323 }
3324
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
kernel test robot
build botRe: [PATCH v8 1/3] KVM: Implement dirty quota-based throttling of vcpus
In reply to Shivam KumarThank you for the patch! Yet something to improve:
Hi Shivam,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on kvm/queue]
[also build test ERROR on linus/master next-20230225] [cannot apply to kvmarm/next mst-vhost/linux-next kvm/linux-next v6.2] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Shivam-Kumar/KVM-Implement-dirty-quota-based-throttling-of-vcpus/20230226-045019 base: https://git.kernel.org/pub/scm/virt/kvm/kvm.git queue patch link: https://lore.kernel.org/r/20230225204758.17726-2-shivam.kumar1%40nutanix.com patch subject: [PATCH v8 1/3] KVM: Implement dirty quota-based throttling of vcpus config: riscv-randconfig-r025-20230226 (https://download.01.org/0day-ci/archive/20230226/[email protected]/config) compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project db89896bbbd2251fff457699635acbbedeead27f)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install riscv cross compiling tool for clang build
# apt-get install binutils-riscv-linux-gnu
# https://github.com/intel-lab-lkp/linux/commit/bdbf0891df39e87ef29d704ad4b9866ec34ea20c
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Shivam-Kumar/KVM-Implement-dirty-quota-based-throttling-of-vcpus/20230226-045019 git checkout bdbf0891df39e87ef29d704ad4b9866ec34ea20c
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=riscv olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> arch/riscv/kvm/../../../virt/kvm/kvm_main.c:3317:53: error: no member named 'dirty_quota_enabled' in 'struct kvm'
if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
~~~ ^
include/asm-generic/rwonce.h:49:33: note: expanded from macro 'READ_ONCE'
compiletime_assert_rwonce_type(x); \
^
include/asm-generic/rwonce.h:36:35: note: expanded from macro 'compiletime_assert_rwonce_type'
compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
^
include/linux/compiler_types.h:325:10: note: expanded from macro '__native_word'
(sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || \
^
note: (skipping 4 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/linux/compiler.h:58:52: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~
include/linux/compiler.h:56:47: note: expanded from macro 'if'
#define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
^~~~
include/linux/compiler.h:58:52: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~
>> arch/riscv/kvm/../../../virt/kvm/kvm_main.c:3317:53: error: no member named 'dirty_quota_enabled' in 'struct kvm'
if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
~~~ ^
include/asm-generic/rwonce.h:49:33: note: expanded from macro 'READ_ONCE'
compiletime_assert_rwonce_type(x); \
^
include/asm-generic/rwonce.h:36:35: note: expanded from macro 'compiletime_assert_rwonce_type'
compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
^
include/linux/compiler_types.h:325:39: note: expanded from macro '__native_word'
(sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || \
^
note: (skipping 4 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/linux/compiler.h:58:52: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~
include/linux/compiler.h:56:47: note: expanded from macro 'if'
#define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
^~~~
include/linux/compiler.h:58:52: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~
>> arch/riscv/kvm/../../../virt/kvm/kvm_main.c:3317:53: error: no member named 'dirty_quota_enabled' in 'struct kvm'
if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
~~~ ^
include/asm-generic/rwonce.h:49:33: note: expanded from macro 'READ_ONCE'
compiletime_assert_rwonce_type(x); \
^
include/asm-generic/rwonce.h:36:35: note: expanded from macro 'compiletime_assert_rwonce_type'
compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
^
include/linux/compiler_types.h:326:10: note: expanded from macro '__native_word'
sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long))
^
note: (skipping 4 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/linux/compiler.h:58:52: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~
include/linux/compiler.h:56:47: note: expanded from macro 'if'
#define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
^~~~
include/linux/compiler.h:58:52: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~
>> arch/riscv/kvm/../../../virt/kvm/kvm_main.c:3317:53: error: no member named 'dirty_quota_enabled' in 'struct kvm'
if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
~~~ ^
include/asm-generic/rwonce.h:49:33: note: expanded from macro 'READ_ONCE'
compiletime_assert_rwonce_type(x); \
^
include/asm-generic/rwonce.h:36:35: note: expanded from macro 'compiletime_assert_rwonce_type'
compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
^
include/linux/compiler_types.h:326:38: note: expanded from macro '__native_word'
sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long))
^
note: (skipping 4 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/linux/compiler.h:58:52: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~
include/linux/compiler.h:56:47: note: expanded from macro 'if'
#define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
^~~~
include/linux/compiler.h:58:52: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~
>> arch/riscv/kvm/../../../virt/kvm/kvm_main.c:3317:53: error: no member named 'dirty_quota_enabled' in 'struct kvm'
if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
~~~ ^
include/asm-generic/rwonce.h:49:33: note: expanded from macro 'READ_ONCE'
compiletime_assert_rwonce_type(x); \
^
include/asm-generic/rwonce.h:36:48: note: expanded from macro 'compiletime_assert_rwonce_type'
compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
^
include/linux/compiler_types.h:358:22: note: expanded from macro 'compiletime_assert'
_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
^~~~~~~~~
note: (skipping 3 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/linux/compiler.h:58:52: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~
include/linux/compiler.h:56:47: note: expanded from macro 'if'
#define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
^~~~
include/linux/compiler.h:58:52: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~
>> arch/riscv/kvm/../../../virt/kvm/kvm_main.c:3317:53: error: no member named 'dirty_quota_enabled' in 'struct kvm'
if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
~~~ ^
include/asm-generic/rwonce.h:49:33: note: expanded from macro 'READ_ONCE'
compiletime_assert_rwonce_type(x); \
^
include/asm-generic/rwonce.h:36:35: note: expanded from macro 'compiletime_assert_rwonce_type'
compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
^
include/linux/compiler_types.h:325:10: note: expanded from macro '__native_word'
(sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || \
^
note: (skipping 4 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/linux/compiler.h:58:61: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~
include/linux/compiler.h:56:47: note: expanded from macro 'if'
#define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
^~~~
include/linux/compiler.h:58:52: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~
>> arch/riscv/kvm/../../../virt/kvm/kvm_main.c:3317:53: error: no member named 'dirty_quota_enabled' in 'struct kvm'
if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
~~~ ^
include/asm-generic/rwonce.h:49:33: note: expanded from macro 'READ_ONCE'
compiletime_assert_rwonce_type(x); \
^
include/asm-generic/rwonce.h:36:35: note: expanded from macro 'compiletime_assert_rwonce_type'
compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
^
include/linux/compiler_types.h:325:39: note: expanded from macro '__native_word'
(sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || \
^
note: (skipping 4 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/linux/compiler.h:58:61: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~
include/linux/compiler.h:56:47: note: expanded from macro 'if'
#define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
^~~~
include/linux/compiler.h:58:52: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~
>> arch/riscv/kvm/../../../virt/kvm/kvm_main.c:3317:53: error: no member named 'dirty_quota_enabled' in 'struct kvm'
if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
~~~ ^
include/asm-generic/rwonce.h:49:33: note: expanded from macro 'READ_ONCE'
compiletime_assert_rwonce_type(x); \
^
include/asm-generic/rwonce.h:36:35: note: expanded from macro 'compiletime_assert_rwonce_type'
compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
^
include/linux/compiler_types.h:326:10: note: expanded from macro '__native_word'
sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long))
^
note: (skipping 4 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/linux/compiler.h:58:61: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~
include/linux/compiler.h:56:47: note: expanded from macro 'if'
#define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
^~~~
include/linux/compiler.h:58:52: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~
>> arch/riscv/kvm/../../../virt/kvm/kvm_main.c:3317:53: error: no member named 'dirty_quota_enabled' in 'struct kvm'
if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
~~~ ^
include/asm-generic/rwonce.h:49:33: note: expanded from macro 'READ_ONCE'
compiletime_assert_rwonce_type(x); \
^
include/asm-generic/rwonce.h:36:35: note: expanded from macro 'compiletime_assert_rwonce_type'
compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
^
include/linux/compiler_types.h:326:38: note: expanded from macro '__native_word'
sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long))
^
note: (skipping 4 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/linux/compiler.h:58:61: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~
include/linux/compiler.h:56:47: note: expanded from macro 'if'
#define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
^~~~
include/linux/compiler.h:58:52: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~
>> arch/riscv/kvm/../../../virt/kvm/kvm_main.c:3317:53: error: no member named 'dirty_quota_enabled' in 'struct kvm'
if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
~~~ ^
include/asm-generic/rwonce.h:49:33: note: expanded from macro 'READ_ONCE'
compiletime_assert_rwonce_type(x); \
^
include/asm-generic/rwonce.h:36:48: note: expanded from macro 'compiletime_assert_rwonce_type'
compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
^
include/linux/compiler_types.h:358:22: note: expanded from macro 'compiletime_assert'
_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
^~~~~~~~~
note: (skipping 3 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/linux/compiler.h:58:61: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~
include/linux/compiler.h:56:47: note: expanded from macro 'if'
#define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
^~~~
include/linux/compiler.h:58:52: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~
>> arch/riscv/kvm/../../../virt/kvm/kvm_main.c:3317:53: error: no member named 'dirty_quota_enabled' in 'struct kvm'
if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
~~~ ^
include/asm-generic/rwonce.h:49:33: note: expanded from macro 'READ_ONCE'
compiletime_assert_rwonce_type(x); \
^
include/asm-generic/rwonce.h:36:35: note: expanded from macro 'compiletime_assert_rwonce_type'
compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
^
include/linux/compiler_types.h:325:10: note: expanded from macro '__native_word'
(sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || \
^
note: (skipping 5 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/linux/compiler.h:69:3: note: expanded from macro '__trace_if_value'
(cond) ? \
^~~~
include/linux/compiler.h:56:47: note: expanded from macro 'if'
#define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
^~~~
include/linux/compiler.h:58:52: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~
>> arch/riscv/kvm/../../../virt/kvm/kvm_main.c:3317:53: error: no member named 'dirty_quota_enabled' in 'struct kvm'
if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
~~~ ^
include/asm-generic/rwonce.h:49:33: note: expanded from macro 'READ_ONCE'
compiletime_assert_rwonce_type(x); \
^
include/asm-generic/rwonce.h:36:35: note: expanded from macro 'compiletime_assert_rwonce_type'
compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
^
include/linux/compiler_types.h:325:39: note: expanded from macro '__native_word'
(sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || \
^
note: (skipping 5 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/linux/compiler.h:69:3: note: expanded from macro '__trace_if_value'
(cond) ? \
^~~~
include/linux/compiler.h:56:47: note: expanded from macro 'if'
#define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
^~~~
include/linux/compiler.h:58:52: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~
>> arch/riscv/kvm/../../../virt/kvm/kvm_main.c:3317:53: error: no member named 'dirty_quota_enabled' in 'struct kvm'
if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
~~~ ^
include/asm-generic/rwonce.h:49:33: note: expanded from macro 'READ_ONCE'
compiletime_assert_rwonce_type(x); \
^
include/asm-generic/rwonce.h:36:35: note: expanded from macro 'compiletime_assert_rwonce_type'
compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
^
include/linux/compiler_types.h:326:10: note: expanded from macro '__native_word'
sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long))
^
note: (skipping 5 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/linux/compiler.h:69:3: note: expanded from macro '__trace_if_value'
(cond) ? \
^~~~
include/linux/compiler.h:56:47: note: expanded from macro 'if'
#define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
^~~~
include/linux/compiler.h:58:52: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~
>> arch/riscv/kvm/../../../virt/kvm/kvm_main.c:3317:53: error: no member named 'dirty_quota_enabled' in 'struct kvm'
if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
~~~ ^
include/asm-generic/rwonce.h:49:33: note: expanded from macro 'READ_ONCE'
compiletime_assert_rwonce_type(x); \
^
include/asm-generic/rwonce.h:36:35: note: expanded from macro 'compiletime_assert_rwonce_type'
compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
^
include/linux/compiler_types.h:326:38: note: expanded from macro '__native_word'
sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long))
^
note: (skipping 5 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/linux/compiler.h:69:3: note: expanded from macro '__trace_if_value'
(cond) ? \
^~~~
include/linux/compiler.h:56:47: note: expanded from macro 'if'
#define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
^~~~
include/linux/compiler.h:58:52: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~
>> arch/riscv/kvm/../../../virt/kvm/kvm_main.c:3317:53: error: no member named 'dirty_quota_enabled' in 'struct kvm'
if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
~~~ ^
include/asm-generic/rwonce.h:49:33: note: expanded from macro 'READ_ONCE'
compiletime_assert_rwonce_type(x); \
^
include/asm-generic/rwonce.h:36:48: note: expanded from macro 'compiletime_assert_rwonce_type'
compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
^
include/linux/compiler_types.h:358:22: note: expanded from macro 'compiletime_assert'
_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
^~~~~~~~~
note: (skipping 4 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/linux/compiler.h:69:3: note: expanded from macro '__trace_if_value'
(cond) ? \
^~~~
include/linux/compiler.h:56:47: note: expanded from macro 'if'
#define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
^~~~
include/linux/compiler.h:58:52: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~
>> arch/riscv/kvm/../../../virt/kvm/kvm_main.c:3317:53: error: no member named 'dirty_quota_enabled' in 'struct kvm'
if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
~~~ ^
include/asm-generic/rwonce.h:50:14: note: expanded from macro 'READ_ONCE'
__READ_ONCE(x); \
^
include/asm-generic/rwonce.h:44:65: note: expanded from macro '__READ_ONCE'
#define __READ_ONCE(x) (*(const volatile __unqual_scalar_typeof(x) *)&(x))
^
include/linux/compiler_types.h:314:13: note: expanded from macro '__unqual_scalar_typeof'
_Generic((x), \
^
include/linux/compiler.h:56:47: note: expanded from macro 'if'
#define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
^~~~
include/linux/compiler.h:58:52: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~
>> arch/riscv/kvm/../../../virt/kvm/kvm_main.c:3317:53: error: no member named 'dirty_quota_enabled' in 'struct kvm'
if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
~~~ ^
include/asm-generic/rwonce.h:50:14: note: expanded from macro 'READ_ONCE'
__READ_ONCE(x); \
^
include/asm-generic/rwonce.h:44:65: note: expanded from macro '__READ_ONCE'
#define __READ_ONCE(x) (*(const volatile __unqual_scalar_typeof(x) *)&(x))
^
include/linux/compiler_types.h:321:15: note: expanded from macro '__unqual_scalar_typeof'
default: (x)))
^
include/linux/compiler.h:56:47: note: expanded from macro 'if'
#define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
^~~~
include/linux/compiler.h:58:52: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~
>> arch/riscv/kvm/../../../virt/kvm/kvm_main.c:3317:53: error: no member named 'dirty_quota_enabled' in 'struct kvm'
if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
~~~ ^
include/asm-generic/rwonce.h:50:14: note: expanded from macro 'READ_ONCE'
__READ_ONCE(x); \
^
include/asm-generic/rwonce.h:44:72: note: expanded from macro '__READ_ONCE'
#define __READ_ONCE(x) (*(const volatile __unqual_scalar_typeof(x) *)&(x))
^
include/linux/compiler.h:56:47: note: expanded from macro 'if'
#define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
^~~~
include/linux/compiler.h:58:52: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~
>> arch/riscv/kvm/../../../virt/kvm/kvm_main.c:3317:37: error: invalid argument type 'void' to unary expression
if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/compiler.h:56:47: note: expanded from macro 'if'
#define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
include/linux/compiler.h:58:52: note: expanded from macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~fatal error: too many errors emitted, stopping now [-ferror-limit=] 20 errors generated.
Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for IOMMU_IO_PGTABLE_LPAE
Depends on [n]: IOMMU_SUPPORT [=y] && (ARM || ARM64 || COMPILE_TEST [=y] && !GENERIC_ATOMIC64 [=y]) Selected by [y]:
- IPMMU_VMSA [=y] && IOMMU_SUPPORT [=y] && (ARCH_RENESAS [=y] || COMPILE_TEST [=y] && !GENERIC_ATOMIC64 [=y])
vim +3317 arch/riscv/kvm/../../../virt/kvm/kvm_main.c
3312
3313 void update_dirty_quota(struct kvm *kvm, unsigned long page_size_bytes)
3314 {
3315 struct kvm_vcpu *vcpu = kvm_get_running_vcpu();
3316
> 3317 if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
3318 return;
3319
3320 vcpu->run->dirty_quota_bytes -= page_size_bytes;
3321 if (vcpu->run->dirty_quota_bytes <= 0)
3322 kvm_make_request(KVM_REQ_DIRTY_QUOTA_EXIT, vcpu);
3323 }
3324
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
kernel test robot
build botRe: [PATCH v8 1/3] KVM: Implement dirty quota-based throttling of vcpus
In reply to Shivam KumarThank you for the patch! Yet something to improve:
Hi Shivam,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on kvm/queue]
[also build test ERROR on linus/master next-20230225] [cannot apply to kvmarm/next mst-vhost/linux-next kvm/linux-next v6.2] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Shivam-Kumar/KVM-Implement-dirty-quota-based-throttling-of-vcpus/20230226-045019 base: https://git.kernel.org/pub/scm/virt/kvm/kvm.git queue patch link: https://lore.kernel.org/r/20230225204758.17726-2-shivam.kumar1%40nutanix.com patch subject: [PATCH v8 1/3] KVM: Implement dirty quota-based throttling of vcpus config: riscv-rv32_defconfig (https://download.01.org/0day-ci/archive/20230226/[email protected]/config) compiler: riscv32-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/bdbf0891df39e87ef29d704ad4b9866ec34ea20c
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Shivam-Kumar/KVM-Implement-dirty-quota-based-throttling-of-vcpus/20230226-045019 git checkout bdbf0891df39e87ef29d704ad4b9866ec34ea20c
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=riscv olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from <command-line>:
arch/riscv/kvm/../../../virt/kvm/kvm_main.c: In function 'update_dirty_quota':
>> arch/riscv/kvm/../../../virt/kvm/kvm_main.c:3317:58: error: 'struct kvm' has no member named 'dirty_quota_enabled'
3317 | if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
| ^~
include/linux/compiler_types.h:338:23: note: in definition of macro '__compiletime_assert'
338 | if (!(condition)) \
| ^~~~~~~~~
include/linux/compiler_types.h:358:9: note: in expansion of macro '_compiletime_assert'
358 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:36:9: note: in expansion of macro 'compiletime_assert'
36 | compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
| ^~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:36:28: note: in expansion of macro '__native_word'
36 | compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
| ^~~~~~~~~~~~~
include/asm-generic/rwonce.h:49:9: note: in expansion of macro 'compiletime_assert_rwonce_type'
49 | compiletime_assert_rwonce_type(x); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/riscv/kvm/../../../virt/kvm/kvm_main.c:3317:45: note: in expansion of macro 'READ_ONCE'
3317 | if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
| ^~~~~~~~~
>> arch/riscv/kvm/../../../virt/kvm/kvm_main.c:3317:58: error: 'struct kvm' has no member named 'dirty_quota_enabled'
3317 | if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
| ^~
include/linux/compiler_types.h:338:23: note: in definition of macro '__compiletime_assert'
338 | if (!(condition)) \
| ^~~~~~~~~
include/linux/compiler_types.h:358:9: note: in expansion of macro '_compiletime_assert'
358 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:36:9: note: in expansion of macro 'compiletime_assert'
36 | compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
| ^~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:36:28: note: in expansion of macro '__native_word'
36 | compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
| ^~~~~~~~~~~~~
include/asm-generic/rwonce.h:49:9: note: in expansion of macro 'compiletime_assert_rwonce_type'
49 | compiletime_assert_rwonce_type(x); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/riscv/kvm/../../../virt/kvm/kvm_main.c:3317:45: note: in expansion of macro 'READ_ONCE'
3317 | if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
| ^~~~~~~~~
>> arch/riscv/kvm/../../../virt/kvm/kvm_main.c:3317:58: error: 'struct kvm' has no member named 'dirty_quota_enabled'
3317 | if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
| ^~
include/linux/compiler_types.h:338:23: note: in definition of macro '__compiletime_assert'
338 | if (!(condition)) \
| ^~~~~~~~~
include/linux/compiler_types.h:358:9: note: in expansion of macro '_compiletime_assert'
358 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:36:9: note: in expansion of macro 'compiletime_assert'
36 | compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
| ^~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:36:28: note: in expansion of macro '__native_word'
36 | compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
| ^~~~~~~~~~~~~
include/asm-generic/rwonce.h:49:9: note: in expansion of macro 'compiletime_assert_rwonce_type'
49 | compiletime_assert_rwonce_type(x); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/riscv/kvm/../../../virt/kvm/kvm_main.c:3317:45: note: in expansion of macro 'READ_ONCE'
3317 | if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
| ^~~~~~~~~
>> arch/riscv/kvm/../../../virt/kvm/kvm_main.c:3317:58: error: 'struct kvm' has no member named 'dirty_quota_enabled'
3317 | if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
| ^~
include/linux/compiler_types.h:338:23: note: in definition of macro '__compiletime_assert'
338 | if (!(condition)) \
| ^~~~~~~~~
include/linux/compiler_types.h:358:9: note: in expansion of macro '_compiletime_assert'
358 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:36:9: note: in expansion of macro 'compiletime_assert'
36 | compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
| ^~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:36:28: note: in expansion of macro '__native_word'
36 | compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
| ^~~~~~~~~~~~~
include/asm-generic/rwonce.h:49:9: note: in expansion of macro 'compiletime_assert_rwonce_type'
49 | compiletime_assert_rwonce_type(x); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/riscv/kvm/../../../virt/kvm/kvm_main.c:3317:45: note: in expansion of macro 'READ_ONCE'
3317 | if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
| ^~~~~~~~~
>> arch/riscv/kvm/../../../virt/kvm/kvm_main.c:3317:58: error: 'struct kvm' has no member named 'dirty_quota_enabled'
3317 | if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
| ^~
include/linux/compiler_types.h:338:23: note: in definition of macro '__compiletime_assert'
338 | if (!(condition)) \
| ^~~~~~~~~
include/linux/compiler_types.h:358:9: note: in expansion of macro '_compiletime_assert'
358 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:36:9: note: in expansion of macro 'compiletime_assert'
36 | compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
| ^~~~~~~~~~~~~~~~~~
include/asm-generic/rwonce.h:49:9: note: in expansion of macro 'compiletime_assert_rwonce_type'
49 | compiletime_assert_rwonce_type(x); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/riscv/kvm/../../../virt/kvm/kvm_main.c:3317:45: note: in expansion of macro 'READ_ONCE'
3317 | if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
| ^~~~~~~~~
>> arch/riscv/kvm/../../../virt/kvm/kvm_main.c:3317:58: error: 'struct kvm' has no member named 'dirty_quota_enabled'
3317 | if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
| ^~
include/linux/compiler_types.h:314:27: note: in definition of macro '__unqual_scalar_typeof'
314 | _Generic((x), \
| ^
include/asm-generic/rwonce.h:50:9: note: in expansion of macro '__READ_ONCE'
50 | __READ_ONCE(x); \
| ^~~~~~~~~~~
arch/riscv/kvm/../../../virt/kvm/kvm_main.c:3317:45: note: in expansion of macro 'READ_ONCE'
3317 | if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
| ^~~~~~~~~
In file included from ./arch/riscv/include/generated/asm/rwonce.h:1,
from include/linux/compiler.h:247,
from include/linux/build_bug.h:5,
from include/linux/bits.h:22,
from include/linux/kvm_types.h:21,
from include/kvm/iodev.h:6,
from arch/riscv/kvm/../../../virt/kvm/kvm_main.c:16:
>> arch/riscv/kvm/../../../virt/kvm/kvm_main.c:3317:58: error: 'struct kvm' has no member named 'dirty_quota_enabled'
3317 | if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
| ^~
include/asm-generic/rwonce.h:44:73: note: in definition of macro '__READ_ONCE'
44 | #define __READ_ONCE(x) (*(const volatile __unqual_scalar_typeof(x) *)&(x))
| ^
arch/riscv/kvm/../../../virt/kvm/kvm_main.c:3317:45: note: in expansion of macro 'READ_ONCE'
3317 | if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
| ^~~~~~~~~vim +3317 arch/riscv/kvm/../../../virt/kvm/kvm_main.c
3312
3313 void update_dirty_quota(struct kvm *kvm, unsigned long page_size_bytes)
3314 {
3315 struct kvm_vcpu *vcpu = kvm_get_running_vcpu();
3316
> 3317 if (!vcpu || (vcpu->kvm != kvm) || !READ_ONCE(kvm->dirty_quota_enabled))
3318 return;
3319
3320 vcpu->run->dirty_quota_bytes -= page_size_bytes;
3321 if (vcpu->run->dirty_quota_bytes <= 0)
3322 kvm_make_request(KVM_REQ_DIRTY_QUOTA_EXIT, vcpu);
3323 }
3324
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
Marc Zyngier
maintainerRe: [PATCH v8 1/3] KVM: Implement dirty quota-based throttling of vcpus
In reply to Shivam KumarQuoted 37 lines · Shivam Kumar
Define
dirty_quota_bytesvariable to track and throttle memory dirtying for every vcpu. This variable stores the number of bytes the vcpu is allowed to dirty. To dirty more, the vcpu needs to request more quota by exiting to userspace.Implement
update_dirty_quotafunction whichi) Decreases
dirty_quota_bytesby arch-specific page size whenever a page is dirtied.
ii) Raises a KVM requestKVM_REQ_DIRTY_QUOTA_EXITwhenever the dirty quota is exhausted (i.e.dirty_quota_bytes<= 0).Suggested-by Shaju Abraham <[email protected]>Suggested-by Manish Mishra <[email protected]>Co-developed-by Anurag Madnawat <[email protected]>Signed-off-by Anurag Madnawat <[email protected]>Signed-off-by Shivam Kumar <[email protected]>--- Documentation/virt/kvm/api.rst | 17 +++++++++++++++++ include/linux/kvm_host.h | 5 +++++ include/uapi/linux/kvm.h | 8 ++++++++ tools/include/uapi/linux/kvm.h | 1 + virt/kvm/Kconfig | 3 +++ virt/kvm/kvm_main.c | 31 +++++++++++++++++++++++++++++++ 6 files changed, 65 insertions(+)Documentation/virt/kvm/api.rst +2
-0@@ -6688,6 +6688,23 @@ Please note that the kernel is allowed to use the kvm_run structure as the primary storage for certain register types. Therefore, the kernel may use the values in kvm_run even if the corresponding bit in kvm_dirty_regs is not set. +:: +
Documentation/virt/kvm/api.rst Please note that the kernel is allowed to use the kvm_run structure as the · line 6702
Quoted 10 lines
Documentation/virt/kvm/api.rst +10
-0+ /* + * Number of bytes the vCPU is allowed to dirty if KVM_CAP_DIRTY_QUOTA is + * enabled. KVM_RUN exits with KVM_EXIT_DIRTY_QUOTA_EXHAUSTED if this quota + * is exhausted, i.e. dirty_quota_bytes <= 0. + */ + long dirty_quota_bytes; + +Please note that enforcing the quota is best effort. Dirty quota is reduced by +arch-specific page size when any guest page is dirtied. Also, the guest may dirty +multiple pages before KVM can recheck the quota.
What are the events that trigger such quota reduction?
Quoted 102 lines
Documentation/virt/kvm/api.rst +5
-0+ +:: + }; + + 6. Capabilities that can be enabled on vCPUs ============================================include/linux/kvm_host.h +5
-0@@ -167,6 +167,7 @@ static inline bool is_error_page(struct page *page)#define KVM_REQ_VM_DEAD (1 | KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP)#define KVM_REQ_UNBLOCK 2#define KVM_REQ_DIRTY_RING_SOFT_FULL 3 +#define KVM_REQ_DIRTY_QUOTA_EXIT 4#define KVM_REQUEST_ARCH_BASE 8/* @@ -800,6 +801,9 @@ struct kvm {bool dirty_ring_with_bitmap;bool vm_bugged;bool vm_dead; +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +bool dirty_quota_enabled; +#endif #ifdef CONFIG_HAVE_KVM_PM_NOTIFIER struct notifier_block pm_notifier;@@ -1235,6 +1239,7 @@ struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn);bool kvm_is_visible_gfn (struct kvm *kvm,gfn_t gfn);bool kvm_vcpu_is_visible_gfn (struct kvm_vcpu *vcpu,gfn_t gfn);unsigned long kvm_host_page_size (struct kvm_vcpu *vcpu,gfn_t gfn); +void update_dirty_quota (struct kvm *kvm,unsigned long page_size_bytes);void mark_page_dirty_in_slot (struct kvm *kvm,const struct kvm_memory_slot *memslot,gfn_t gfn);void mark_page_dirty (struct kvm *kvm,gfn_t gfn);include/uapi/linux/kvm.h +8
-0@@ -264,6 +264,7 @@ struct kvm_xen_exit {#define KVM_EXIT_RISCV_SBI 35#define KVM_EXIT_RISCV_CSR 36#define KVM_EXIT_NOTIFY 37 +#define KVM_EXIT_DIRTY_QUOTA_EXHAUSTED 38/* For KVM_EXIT_INTERNAL_ERROR */ /* Emulate instruction failed. */ @@ -526,6 +527,12 @@ struct kvm_run {struct kvm_sync_regs regs;char padding[SYNC_REGS_SIZE_BYTES ]; } s; +/* +* Number of bytes the vCPU is allowed to dirty if KVM_CAP_DIRTY_QUOTA is +* enabled. KVM_RUN exits with KVM_EXIT_DIRTY_QUOTA_EXHAUSTED if this quota +* is exhausted, i.e. dirty_quota_bytes <= 0. +*/ +long dirty_quota_bytes; };/* for KVM_REGISTER_COALESCED_MMIO / KVM_UNREGISTER_COALESCED_MMIO */ @@ -1184,6 +1191,7 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_S390_PROTECTED_ASYNC_DISABLE 224#define KVM_CAP_DIRTY_LOG_RING_WITH_BITMAP 225#define KVM_CAP_PMU_EVENT_MASKED_EVENTS 226 +#define KVM_CAP_DIRTY_QUOTA 227#ifdef KVM_CAP_IRQ_ROUTING tools/include/uapi/linux/kvm.h +1
-0@@ -1175,6 +1175,7 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_DIRTY_LOG_RING_ACQ_REL 223#define KVM_CAP_S390_PROTECTED_ASYNC_DISABLE 224#define KVM_CAP_DIRTY_LOG_RING_WITH_BITMAP 225 +#define KVM_CAP_DIRTY_QUOTA 227#ifdef KVM_CAP_IRQ_ROUTING virt/kvm/Kconfig +3
-0@@ -19,6 +19,9 @@ config HAVE_KVM_IRQ_ROUTING config HAVE_KVM_DIRTY_RING bool +config HAVE_KVM_DIRTY_QUOTA + bool + # Only strongly ordered architectures can select this, as it doesn't # put any explicit constraint on userspace ordering. They can also # select the _ACQ_REL version.virt/kvm/kvm_main.c +0
-0
virt/kvm/kvm_main.c static int __kvm_write_guest_page(struct kvm *kvm, · line 3101
Quoted 6 lines
virt/kvm/kvm_main.c +3
-0@@ -3096,6 +3096,9 @@ static int __kvm_write_guest_page(struct kvm *kvm, r =__copy_to_user ((void __user *)addr + offset, data, len);if (r)return -EFAULT ; +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +update_dirty_quota (kvm,PAGE_SIZE ); +#endif
Why PAGE_SIZE? Why not 'len'? Why if the page was already dirtied? Why should it be accounted for multiple times? In most cases, this is the *hypervisor* writing to the guest, not the vcpu. Why should this be accounted to the vcpu quota?
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Re: [PATCH v8 1/3] KVM: Implement dirty quota-based throttling of vcpus
Quoted 37 lines · Marc Zyngier
Quoted 35 lines · Shivam Kumar
Define
dirty_quota_bytesvariable to track and throttle memory dirtying for every vcpu. This variable stores the number of bytes the vcpu is allowed to dirty. To dirty more, the vcpu needs to request more quota by exiting to userspace.Implement
update_dirty_quotafunction whichi) Decreases
dirty_quota_bytesby arch-specific page size whenever a page is dirtied.
ii) Raises a KVM requestKVM_REQ_DIRTY_QUOTA_EXITwhenever the dirty quota is exhausted (i.e.dirty_quota_bytes<= 0).Suggested-by Shaju Abraham <[email protected]>Suggested-by Manish Mishra <[email protected]>Co-developed-by Anurag Madnawat <[email protected]>Signed-off-by Anurag Madnawat <[email protected]>Signed-off-by Shivam Kumar <[email protected]>--- Documentation/virt/kvm/api.rst | 17 +++++++++++++++++ include/linux/kvm_host.h | 5 +++++ include/uapi/linux/kvm.h | 8 ++++++++ tools/include/uapi/linux/kvm.h | 1 + virt/kvm/Kconfig | 3 +++ virt/kvm/kvm_main.c | 31 +++++++++++++++++++++++++++++++ 6 files changed, 65 insertions(+)Documentation/virt/kvm/api.rst +0
-0@@ -6688,6 +6688,23 @@ Please note that the kernel is allowed to use the kvm_run structure as the primary storage for certain register types. Therefore, the kernel may use the values in kvm_run even if the corresponding bit in kvm_dirty_regs is not set.
Quoted 14 lines
Documentation/virt/kvm/api.rst Please note that the kernel is allowed to use the kvm_run structure as the · line 6702
Quoted 12 lines
Documentation/virt/kvm/api.rst +12
-0+:: + + /* + * Number of bytes the vCPU is allowed to dirty if KVM_CAP_DIRTY_QUOTA is + * enabled. KVM_RUN exits with KVM_EXIT_DIRTY_QUOTA_EXHAUSTED if this quota + * is exhausted, i.e. dirty_quota_bytes <= 0. + */ + long dirty_quota_bytes; + +Please note that enforcing the quota is best effort. Dirty quota is reduced by +arch-specific page size when any guest page is dirtied. Also, the guest may dirty +multiple pages before KVM can recheck the quota.What are the events that trigger such quota reduction?
If PML is enabled or when functions like nested_mark_vmcs12_pages_dirty get called that can mark multiple pages dirtied in a single exit.
Thanks.
Quoted 106 lines
Quoted 106 lines
Documentation/virt/kvm/api.rst +5
-0+ +:: + }; + + 6. Capabilities that can be enabled on vCPUs ============================================include/linux/kvm_host.h +5
-0@@ -167,6 +167,7 @@ static inline bool is_error_page(struct page *page)#define KVM_REQ_VM_DEAD (1 | KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP)#define KVM_REQ_UNBLOCK 2#define KVM_REQ_DIRTY_RING_SOFT_FULL 3 +#define KVM_REQ_DIRTY_QUOTA_EXIT 4#define KVM_REQUEST_ARCH_BASE 8/* @@ -800,6 +801,9 @@ struct kvm {bool dirty_ring_with_bitmap;bool vm_bugged;bool vm_dead; +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +bool dirty_quota_enabled; +#endif #ifdef CONFIG_HAVE_KVM_PM_NOTIFIER struct notifier_block pm_notifier;@@ -1235,6 +1239,7 @@ struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn);bool kvm_is_visible_gfn (struct kvm *kvm,gfn_t gfn);bool kvm_vcpu_is_visible_gfn (struct kvm_vcpu *vcpu,gfn_t gfn);unsigned long kvm_host_page_size (struct kvm_vcpu *vcpu,gfn_t gfn); +void update_dirty_quota (struct kvm *kvm,unsigned long page_size_bytes);void mark_page_dirty_in_slot (struct kvm *kvm,const struct kvm_memory_slot *memslot,gfn_t gfn);void mark_page_dirty (struct kvm *kvm,gfn_t gfn);include/uapi/linux/kvm.h +8
-0@@ -264,6 +264,7 @@ struct kvm_xen_exit {#define KVM_EXIT_RISCV_SBI 35#define KVM_EXIT_RISCV_CSR 36#define KVM_EXIT_NOTIFY 37 +#define KVM_EXIT_DIRTY_QUOTA_EXHAUSTED 38/* For KVM_EXIT_INTERNAL_ERROR */ /* Emulate instruction failed. */ @@ -526,6 +527,12 @@ struct kvm_run {struct kvm_sync_regs regs;char padding[SYNC_REGS_SIZE_BYTES ]; } s; +/* +* Number of bytes the vCPU is allowed to dirty if KVM_CAP_DIRTY_QUOTA is +* enabled. KVM_RUN exits with KVM_EXIT_DIRTY_QUOTA_EXHAUSTED if this quota +* is exhausted, i.e. dirty_quota_bytes <= 0. +*/ +long dirty_quota_bytes; };/* for KVM_REGISTER_COALESCED_MMIO / KVM_UNREGISTER_COALESCED_MMIO */ @@ -1184,6 +1191,7 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_S390_PROTECTED_ASYNC_DISABLE 224#define KVM_CAP_DIRTY_LOG_RING_WITH_BITMAP 225#define KVM_CAP_PMU_EVENT_MASKED_EVENTS 226 +#define KVM_CAP_DIRTY_QUOTA 227#ifdef KVM_CAP_IRQ_ROUTING tools/include/uapi/linux/kvm.h +1
-0@@ -1175,6 +1175,7 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_DIRTY_LOG_RING_ACQ_REL 223#define KVM_CAP_S390_PROTECTED_ASYNC_DISABLE 224#define KVM_CAP_DIRTY_LOG_RING_WITH_BITMAP 225 +#define KVM_CAP_DIRTY_QUOTA 227#ifdef KVM_CAP_IRQ_ROUTING virt/kvm/Kconfig +3
-0@@ -19,6 +19,9 @@ config HAVE_KVM_IRQ_ROUTING config HAVE_KVM_DIRTY_RING bool +config HAVE_KVM_DIRTY_QUOTA + bool + # Only strongly ordered architectures can select this, as it doesn't # put any explicit constraint on userspace ordering. They can also # select the _ACQ_REL version.virt/kvm/kvm_main.c +0
-0@@ -3096,6 +3096,9 @@ static int __kvm_write_guest_page(struct kvm *kvm, r =__copy_to_user ((void __user *)addr + offset, data, len);if (r)return -EFAULT ;
Quoted 8 lines
virt/kvm/kvm_main.c static int __kvm_write_guest_page(struct kvm *kvm, · line 3101
Quoted 3 lines
virt/kvm/kvm_main.c +3
-0+#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +update_dirty_quota (kvm,PAGE_SIZE ); +#endif Why
PAGE_SIZE? Why not 'len'? Why if the page was already dirtied? Why should it be accounted for multiple times? In most cases, this is the *hypervisor* writing to the guest, not the vcpu. Why should this be accounted to the vcpu quota?
Agreed, update doesn't make much sense here. Thanks.
Thanks,
Shivam
PATCH v8 2/3 KVM: x86: Dirty quota-based throttling of vcpus
In reply to Shivam KumarCall update_dirty_quota whenever a page is marked dirty with appropriate arch-specific page size. Process the KVM request KVM_REQ_DIRTY_QUOTA_EXIT (raised by update_dirty_quota) to exit to userspace with exit reason KVM_EXIT_DIRTY_QUOTA_EXHAUSTED.
--- arch/x86/kvm/Kconfig | 1 + arch/x86/kvm/mmu/mmu.c | 8 +++++++- arch/x86/kvm/mmu/spte.c | 3 +++ arch/x86/kvm/mmu/tdp_mmu.c | 3 +++ arch/x86/kvm/vmx/vmx.c | 5 +++++ arch/x86/kvm/x86.c | 16 ++++++++++++++++ arch/x86/kvm/xen.c | 12 +++++++++++- 7 files changed, 46 insertions(+), 2 deletions(-)
arch/x86/kvm/Kconfig +1 -0
@@ -48,6 +48,7 @@ config KVM select KVM_VFIO select SRCU select INTERVAL_TREE + select HAVE_KVM_DIRTY_QUOTA select HAVE_KVM_PM_NOTIFIER if PM select KVM_GENERIC_HARDWARE_ENABLING help
arch/x86/kvm/mmu/mmu.c +7 -1
@@ -3323,8 +3323,14 @@ fast_pf_fix_direct_spte(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault,if (!try_cmpxchg64 (sptep, &old_spte, new_spte))return false; -if (is_writable_pte (new_spte) && !is_writable_pte (old_spte)) +if (is_writable_pte (new_spte) && !is_writable_pte (old_spte)) { +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +struct kvm_mmu_page *sp =sptep_to_sp (sptep); + +update_dirty_quota (vcpu->kvm, (1L <<SPTE_LEVEL_SHIFT (sp->role.level))); +#endif mark_page_dirty_in_slot (vcpu->kvm, fault->slot, fault->gfn); + }return true; }
arch/x86/kvm/mmu/spte.c +3 -0
@@ -243,6 +243,9 @@ bool make_spte(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,if ((spte &PT_WRITABLE_MASK ) &&kvm_slot_dirty_track_enabled (slot)) {/* Enforced by kvm_mmu_hugepage_adjust. */ WARN_ON (level >PG_LEVEL_4K ); +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +update_dirty_quota (vcpu->kvm, (1L <<SPTE_LEVEL_SHIFT (level))); +#endif mark_page_dirty_in_slot (vcpu->kvm, slot, gfn); }
arch/x86/kvm/mmu/tdp_mmu.c +3 -0
@@ -358,6 +358,9 @@ static void handle_changed_spte_dirty_log(struct kvm *kvm, int as_id, gfn_t gfn,if ((!is_writable_pte (old_spte) || pfn_changed) &&is_writable_pte (new_spte)) { +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +update_dirty_quota (kvm, (1L <<SPTE_LEVEL_SHIFT (level))); +#endif slot =__gfn_to_memslot (__kvm_memslots (kvm, as_id), gfn);mark_page_dirty_in_slot (kvm, slot, gfn); }
arch/x86/kvm/vmx/vmx.c +5 -0
@@ -5861,6 +5861,11 @@ static int handle_invalid_guest_state(struct kvm_vcpu *vcpu)*/ if (__xfer_to_guest_mode_work_pending ())return 1 ; + +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +if (kvm_test_request (KVM_REQ_DIRTY_QUOTA_EXIT , vcpu)) +return 1 ; +#endif }return 1 ;
arch/x86/kvm/x86.c +16 -0
@@ -3092,6 +3092,9 @@ static void kvm_setup_guest_pvclock(struct kvm_vcpu *v, guest_hv_clock->version = ++vcpu->hv_clock.version; +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +update_dirty_quota (v->kvm,PAGE_SIZE ); +#endif mark_page_dirty_in_slot (v->kvm, gpc->memslot, gpc->gpa >>PAGE_SHIFT );read_unlock_irqrestore (&gpc->lock, flags);
@@ -3566,6 +3569,9 @@ static void record_steal_time(struct kvm_vcpu *vcpu) out:user_access_end (); dirty: +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +update_dirty_quota (vcpu->kvm,PAGE_SIZE ); +#endif mark_page_dirty_in_slot (vcpu->kvm, ghc->memslot,gpa_to_gfn (ghc->gpa)); }
@@ -4815,6 +4821,9 @@ static void kvm_steal_time_set_preempted(struct kvm_vcpu *vcpu)if (!copy_to_user_nofault (&st->preempted, &preempted,sizeof (preempted))) vcpu->arch.st.preempted =KVM_VCPU_PREEMPTED ; +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +update_dirty_quota (vcpu->kvm,PAGE_SIZE ); +#endif mark_page_dirty_in_slot (vcpu->kvm, ghc->memslot,gpa_to_gfn (ghc->gpa)); }
@@ -10514,6 +10523,13 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) r =0 ; goto out; } +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +if (kvm_check_request (KVM_REQ_DIRTY_QUOTA_EXIT , vcpu)) { + vcpu->run->exit_reason =KVM_EXIT_DIRTY_QUOTA_EXHAUSTED ; + r =0 ; + goto out; + } +#endif /* * KVM_REQ_HV_STIMER has to be processed after
arch/x86/kvm/xen.c +11 -1
@@ -435,9 +435,16 @@ static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic)read_unlock_irqrestore (&gpc1->lock, flags); +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +update_dirty_quota (v->kvm,PAGE_SIZE ); +#endif mark_page_dirty_in_slot (v->kvm, gpc1->memslot, gpc1->gpa >>PAGE_SHIFT ); -if (user_len2) +if (user_len2) { +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +update_dirty_quota (v->kvm,PAGE_SIZE ); +#endif mark_page_dirty_in_slot (v->kvm, gpc2->memslot, gpc2->gpa >>PAGE_SHIFT ); + } }void kvm_xen_update_runstate (struct kvm_vcpu *v,int state)
@@ -549,6 +556,9 @@ void kvm_xen_inject_pending_events(struct kvm_vcpu *v)if (v->arch.xen.upcall_vector)kvm_xen_inject_vcpu_vector (v); +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +update_dirty_quota (v->kvm,PAGE_SIZE ); +#endif mark_page_dirty_in_slot (v->kvm, gpc->memslot, gpc->gpa >>PAGE_SHIFT ); }
Signature · 1 line
2.22.3
Re: [PATCH v8 2/3] KVM: x86: Dirty quota-based throttling of vcpus
Quoted 38 lines · Shivam Kumar
Call
update_dirty_quotawhenever a page is marked dirty with appropriate arch-specific page size. Process the KVM requestKVM_REQ_DIRTY_QUOTA_EXIT(raised byupdate_dirty_quota) to exit to userspace with exit reasonKVM_EXIT_DIRTY_QUOTA_EXHAUSTED.Suggested-by Shaju Abraham <[email protected]>Suggested-by Manish Mishra <[email protected]>Co-developed-by Anurag Madnawat <[email protected]>Signed-off-by Anurag Madnawat <[email protected]>Signed-off-by Shivam Kumar <[email protected]>--- arch/x86/kvm/Kconfig | 1 + arch/x86/kvm/mmu/mmu.c | 8 +++++++- arch/x86/kvm/mmu/spte.c | 3 +++ arch/x86/kvm/mmu/tdp_mmu.c | 3 +++ arch/x86/kvm/vmx/vmx.c | 5 +++++ arch/x86/kvm/x86.c | 16 ++++++++++++++++ arch/x86/kvm/xen.c | 12 +++++++++++- 7 files changed, 46 insertions(+), 2 deletions(-)arch/x86/kvm/Kconfig +1
-0@@ -48,6 +48,7 @@ config KVM select KVM_VFIO select SRCU select INTERVAL_TREE + select HAVE_KVM_DIRTY_QUOTA select HAVE_KVM_PM_NOTIFIER if PM select KVM_GENERIC_HARDWARE_ENABLING helparch/x86/kvm/mmu/mmu.c +0
-0@@ -3323,8 +3323,14 @@ fast_pf_fix_direct_spte(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault,if (!try_cmpxchg64 (sptep, &old_spte, new_spte))
arch/x86/kvm/mmu/mmu.c fast_pf_fix_direct_spte(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault, · line 3332
Quoted 10 lines
arch/x86/kvm/mmu/mmu.c +6
-1return false; -if (is_writable_pte (new_spte) && !is_writable_pte (old_spte)) +if (is_writable_pte (new_spte) && !is_writable_pte (old_spte)) { +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +struct kvm_mmu_page *sp =sptep_to_sp (sptep); + +update_dirty_quota (vcpu->kvm, (1L <<SPTE_LEVEL_SHIFT (sp->role.level))); +#endif mark_page_dirty_in_slot (vcpu->kvm, fault->slot, fault->gfn);
Possible to call update_dirty_quota() from mark_page_dirty_in_slot() ? Then other Architectures can be covered yet.
Quoted 131 lines
arch/x86/kvm/mmu/mmu.c +1
-0+ }return true; }arch/x86/kvm/mmu/spte.c +3
-0@@ -243,6 +243,9 @@ bool make_spte(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,if ((spte &PT_WRITABLE_MASK ) &&kvm_slot_dirty_track_enabled (slot)) {/* Enforced by kvm_mmu_hugepage_adjust. */ WARN_ON (level >PG_LEVEL_4K ); +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +update_dirty_quota (vcpu->kvm, (1L <<SPTE_LEVEL_SHIFT (level))); +#endif mark_page_dirty_in_slot (vcpu->kvm, slot, gfn); }arch/x86/kvm/mmu/tdp_mmu.c +3
-0@@ -358,6 +358,9 @@ static void handle_changed_spte_dirty_log(struct kvm *kvm, int as_id, gfn_t gfn,if ((!is_writable_pte (old_spte) || pfn_changed) &&is_writable_pte (new_spte)) { +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +update_dirty_quota (kvm, (1L <<SPTE_LEVEL_SHIFT (level))); +#endif slot =__gfn_to_memslot (__kvm_memslots (kvm, as_id), gfn);mark_page_dirty_in_slot (kvm, slot, gfn); }arch/x86/kvm/vmx/vmx.c +5
-0@@ -5861,6 +5861,11 @@ static int handle_invalid_guest_state(struct kvm_vcpu *vcpu)*/ if (__xfer_to_guest_mode_work_pending ())return 1 ; + +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +if (kvm_test_request (KVM_REQ_DIRTY_QUOTA_EXIT , vcpu)) +return 1 ; +#endif }return 1 ;arch/x86/kvm/x86.c +16
-0@@ -3092,6 +3092,9 @@ static void kvm_setup_guest_pvclock(struct kvm_vcpu *v, guest_hv_clock->version = ++vcpu->hv_clock.version; +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +update_dirty_quota (v->kvm,PAGE_SIZE ); +#endif mark_page_dirty_in_slot (v->kvm, gpc->memslot, gpc->gpa >>PAGE_SHIFT );read_unlock_irqrestore (&gpc->lock, flags);@@ -3566,6 +3569,9 @@ static void record_steal_time(struct kvm_vcpu *vcpu) out:user_access_end (); dirty: +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +update_dirty_quota (vcpu->kvm,PAGE_SIZE ); +#endif mark_page_dirty_in_slot (vcpu->kvm, ghc->memslot,gpa_to_gfn (ghc->gpa)); }@@ -4815,6 +4821,9 @@ static void kvm_steal_time_set_preempted(struct kvm_vcpu *vcpu)if (!copy_to_user_nofault (&st->preempted, &preempted,sizeof (preempted))) vcpu->arch.st.preempted =KVM_VCPU_PREEMPTED ; +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +update_dirty_quota (vcpu->kvm,PAGE_SIZE ); +#endif mark_page_dirty_in_slot (vcpu->kvm, ghc->memslot,gpa_to_gfn (ghc->gpa)); }@@ -10514,6 +10523,13 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) r =0 ; goto out; } +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +if (kvm_check_request (KVM_REQ_DIRTY_QUOTA_EXIT , vcpu)) { + vcpu->run->exit_reason =KVM_EXIT_DIRTY_QUOTA_EXHAUSTED ; + r =0 ; + goto out; + } +#endif /* * KVM_REQ_HV_STIMER has to be processed after arch/x86/kvm/xen.c +11
-2@@ -435,9 +435,16 @@ static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic)read_unlock_irqrestore (&gpc1->lock, flags); +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +update_dirty_quota (v->kvm,PAGE_SIZE ); +#endif mark_page_dirty_in_slot (v->kvm, gpc1->memslot, gpc1->gpa >>PAGE_SHIFT ); -if (user_len2) +if (user_len2) { +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +update_dirty_quota (v->kvm,PAGE_SIZE ); +#endif mark_page_dirty_in_slot (v->kvm, gpc2->memslot, gpc2->gpa >>PAGE_SHIFT ); + } }void kvm_xen_update_runstate (struct kvm_vcpu *v,int state)@@ -549,6 +556,9 @@ void kvm_xen_inject_pending_events(struct kvm_vcpu *v)if (v->arch.xen.upcall_vector)kvm_xen_inject_vcpu_vector (v); +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +update_dirty_quota (v->kvm,PAGE_SIZE ); +#endif mark_page_dirty_in_slot (v->kvm, gpc->memslot, gpc->gpa >>PAGE_SHIFT ); } --2.22.3
Re: [PATCH v8 2/3] KVM: x86: Dirty quota-based throttling of vcpus
Quoted 41 lines · Yuan Yao
Quoted 40 lines · Shivam Kumar
Call
update_dirty_quotawhenever a page is marked dirty with appropriate arch-specific page size. Process the KVM requestKVM_REQ_DIRTY_QUOTA_EXIT(raised byupdate_dirty_quota) to exit to userspace with exit reasonKVM_EXIT_DIRTY_QUOTA_EXHAUSTED.Suggested-by Shaju Abraham <[email protected]>Suggested-by Manish Mishra <[email protected]>Co-developed-by Anurag Madnawat <[email protected]>Signed-off-by Anurag Madnawat <[email protected]>Signed-off-by Shivam Kumar <[email protected]>--- arch/x86/kvm/Kconfig | 1 + arch/x86/kvm/mmu/mmu.c | 8 +++++++- arch/x86/kvm/mmu/spte.c | 3 +++ arch/x86/kvm/mmu/tdp_mmu.c | 3 +++ arch/x86/kvm/vmx/vmx.c | 5 +++++ arch/x86/kvm/x86.c | 16 ++++++++++++++++ arch/x86/kvm/xen.c | 12 +++++++++++- 7 files changed, 46 insertions(+), 2 deletions(-)arch/x86/kvm/Kconfig +1
-0@@ -48,6 +48,7 @@ config KVM select KVM_VFIO select SRCU select INTERVAL_TREE + select HAVE_KVM_DIRTY_QUOTA select HAVE_KVM_PM_NOTIFIER if PM select KVM_GENERIC_HARDWARE_ENABLING helparch/x86/kvm/mmu/mmu.c +0
-0@@ -3323,8 +3323,14 @@ fast_pf_fix_direct_spte(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault,if (!try_cmpxchg64 (sptep, &old_spte, new_spte))return false;
Quoted 11 lines
arch/x86/kvm/mmu/mmu.c fast_pf_fix_direct_spte(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault, · line 3332
Quoted 8 lines
arch/x86/kvm/mmu/mmu.c +6
-1-if (is_writable_pte (new_spte) && !is_writable_pte (old_spte)) +if (is_writable_pte (new_spte) && !is_writable_pte (old_spte)) { +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +struct kvm_mmu_page *sp =sptep_to_sp (sptep); + +update_dirty_quota (vcpu->kvm, (1L <<SPTE_LEVEL_SHIFT (sp->role.level))); +#endif mark_page_dirty_in_slot (vcpu->kvm, fault->slot, fault->gfn);Possible to call
update_dirty_quota()frommark_page_dirty_in_slot()? Then other Architectures can be covered yet.
As Marc commented on the first patch of this patchset, mark_page_dirty_in_slot can be called multiple times for the same page, e.g. in the case of PML for nested guests. If bitmap-based dirty tracking is not enabled, we might not be able to handle those cases without adding an extra param (which can tell us whether a dirty quota update is required or not) in mark_page_dirty_in_slot. Thanks.
Thanks,
Shivam
PATCH v8 3/3 KVM: arm64: Dirty quota-based throttling of vcpus
In reply to Shivam KumarCall update_dirty_quota whenever a page is marked dirty with appropriate arch-specific page size. Process the KVM request KVM_REQ_DIRTY_QUOTA_EXIT (raised by update_dirty_quota) to exit to userspace with exit reason KVM_EXIT_DIRTY_QUOTA_EXHAUSTED.
--- arch/arm64/kvm/Kconfig | 1 + arch/arm64/kvm/arm.c | 7 +++++++ arch/arm64/kvm/mmu.c | 3 +++ 3 files changed, 11 insertions(+)
arch/arm64/kvm/Kconfig +1 -0
@@ -44,6 +44,7 @@ menuconfig KVM select SCHED_INFO select GUEST_PERF_EVENTS if PERF_EVENTS select INTERVAL_TREE + select HAVE_KVM_DIRTY_QUOTA help Support hosting virtualized guest machines.
arch/arm64/kvm/arm.c +7 -0
@@ -757,6 +757,13 @@ static int check_vcpu_requests(struct kvm_vcpu *vcpu)if (kvm_dirty_ring_check_request (vcpu))return 0 ; + +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +if (kvm_check_request (KVM_REQ_DIRTY_QUOTA_EXIT , vcpu)) { + vcpu->run->exit_reason =KVM_EXIT_DIRTY_QUOTA_EXHAUSTED ; +return 0 ; + } +#endif }return 1 ;
arch/arm64/kvm/mmu.c +3 -0
@@ -1390,6 +1390,9 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,/* Mark the page dirty only if the fault is handled successfully */ if (writable && !ret) {kvm_set_pfn_dirty (pfn); +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +update_dirty_quota (kvm, fault_granule); +#endif mark_page_dirty_in_slot (kvm, memslot, gfn); }
Signature · 1 line
2.22.3
Marc Zyngier
maintainerRe: [PATCH v8 3/3] KVM: arm64: Dirty quota-based throttling of vcpus
Quoted 22 lines · Shivam Kumar
Call
update_dirty_quotawhenever a page is marked dirty with appropriate arch-specific page size. Process the KVM requestKVM_REQ_DIRTY_QUOTA_EXIT(raised byupdate_dirty_quota) to exit to userspace with exit reasonKVM_EXIT_DIRTY_QUOTA_EXHAUSTED.Suggested-by Shaju Abraham <[email protected]>Suggested-by Manish Mishra <[email protected]>Co-developed-by Anurag Madnawat <[email protected]>Signed-off-by Anurag Madnawat <[email protected]>Signed-off-by Shivam Kumar <[email protected]>--- arch/arm64/kvm/Kconfig | 1 + arch/arm64/kvm/arm.c | 7 +++++++ arch/arm64/kvm/mmu.c | 3 +++ 3 files changed, 11 insertions(+)arch/arm64/kvm/Kconfig +0
-0
arch/arm64/kvm/Kconfig menuconfig KVM · line 47
Quoted 4 lines
arch/arm64/kvm/Kconfig +1
-0@@ -44,6 +44,7 @@ menuconfig KVM select SCHED_INFO select GUEST_PERF_EVENTS if PERF_EVENTS select INTERVAL_TREE + select HAVE_KVM_DIRTY_QUOTA
So this is selected unconditionally...
arch/arm64/kvm/arm.c static int check_vcpu_requests(struct kvm_vcpu *vcpu) · line 761
Quoted 13 lines
arch/arm64/kvm/Kconfig +0
-0help Support hosting virtualized guest machines.arch/arm64/kvm/arm.c +2
-0@@ -757,6 +757,13 @@ static int check_vcpu_requests(struct kvm_vcpu *vcpu)if (kvm_dirty_ring_check_request (vcpu))return 0 ; + +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA
... and yet you litter the arch code with #ifdefs...
arch/arm64/kvm/arm.c static int check_vcpu_requests(struct kvm_vcpu *vcpu) · line 764
Quoted 3 lines
arch/arm64/kvm/arm.c +3
-0+if (kvm_check_request (KVM_REQ_DIRTY_QUOTA_EXIT , vcpu)) { + vcpu->run->exit_reason =KVM_EXIT_DIRTY_QUOTA_EXHAUSTED ; +return 0 ;
What rechecks the quota on entry?
Quoted 10 lines
arch/arm64/kvm/arm.c +2
-0+ } +#endif }return 1 ;arch/arm64/kvm/mmu.c +0
-0
arch/arm64/kvm/mmu.c static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, · line 1394
Quoted 5 lines
arch/arm64/kvm/mmu.c +2
-0@@ -1390,6 +1390,9 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,/* Mark the page dirty only if the fault is handled successfully */ if (writable && !ret) {kvm_set_pfn_dirty (pfn); +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +update_dirty_quota (kvm, fault_granule);
fault_granule isn't necessarily the amount that gets dirtied.
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Re: [PATCH v8 3/3] KVM: arm64: Dirty quota-based throttling of vcpus
Quoted 40 lines · Marc Zyngier
Quoted 22 lines · Shivam Kumar
Call
update_dirty_quotawhenever a page is marked dirty with appropriate arch-specific page size. Process the KVM requestKVM_REQ_DIRTY_QUOTA_EXIT(raised byupdate_dirty_quota) to exit to userspace with exit reasonKVM_EXIT_DIRTY_QUOTA_EXHAUSTED.Suggested-by Shaju Abraham <[email protected]>Suggested-by Manish Mishra <[email protected]>Co-developed-by Anurag Madnawat <[email protected]>Signed-off-by Anurag Madnawat <[email protected]>Signed-off-by Shivam Kumar <[email protected]>--- arch/arm64/kvm/Kconfig | 1 + arch/arm64/kvm/arm.c | 7 +++++++ arch/arm64/kvm/mmu.c | 3 +++ 3 files changed, 11 insertions(+)arch/arm64/kvm/Kconfig +0
-0arch/arm64/kvm/Kconfig menuconfig KVM · line 47
Quoted 4 lines
arch/arm64/kvm/Kconfig +1
-0@@ -44,6 +44,7 @@ menuconfig KVM select SCHED_INFO select GUEST_PERF_EVENTS if PERF_EVENTS select INTERVAL_TREE + select HAVE_KVM_DIRTY_QUOTASo this is selected unconditionally...
Quoted 9 lines
arch/arm64/kvm/Kconfig +0
-0help Support hosting virtualized guest machines.arch/arm64/kvm/arm.c +0
-0@@ -757,6 +757,13 @@ static int check_vcpu_requests(struct kvm_vcpu *vcpu)
Quoted 6 lines
arch/arm64/kvm/arm.c static int check_vcpu_requests(struct kvm_vcpu *vcpu) · line 761
Quoted 4 lines
arch/arm64/kvm/arm.c +2
-0if (kvm_dirty_ring_check_request (vcpu))return 0 ; + +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA ... and yet you litter the arch code with #ifdefs...
Sorry about that. #ifdefs are not required here.
Quoted 6 lines
arch/arm64/kvm/arm.c static int check_vcpu_requests(struct kvm_vcpu *vcpu) · line 764
Quoted 4 lines
arch/arm64/kvm/arm.c +3
-0+if (kvm_check_request (KVM_REQ_DIRTY_QUOTA_EXIT , vcpu)) { + vcpu->run->exit_reason =KVM_EXIT_DIRTY_QUOTA_EXHAUSTED ; +return 0 ;What rechecks the quota on entry?
Right now, we are not rechecking the quota after entry. So, if the userspace doesn't update the quota, then we let the vcpu run until it tries to dirty again.
I think it's a good idea to check the quota on entry and keep exiting to userspace until the quota is a positive value. Can add this in the next patchset.
Thanks.
Quoted 19 lines
Quoted 11 lines
arch/arm64/kvm/arm.c +2
-0+ } +#endif }return 1 ;arch/arm64/kvm/mmu.c +0
-0arch/arm64/kvm/mmu.c static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, · line 1394
Quoted 5 lines
arch/arm64/kvm/mmu.c +2
-0@@ -1390,6 +1390,9 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,/* Mark the page dirty only if the fault is handled successfully */ if (writable && !ret) {kvm_set_pfn_dirty (pfn); +#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA +update_dirty_quota (kvm, fault_granule);
fault_granuleisn't necessarily the amount that gets dirtied.
Quoted 2 lines
M.
For most of the paths where we are updating the quota, we cannot track (or precisely account for) dirtying at a granularity less than the minimum page size. Looking forward to your thoughts on what we can do better here. Thanks.
Thanks,
Shivam