Commit c4196218 authored by Christian Borntraeger's avatar Christian Borntraeger

KVM: s390: Add memcg accounting to KVM allocations

Almost all kvm allocations in the s390x KVM code can be attributed to
the process that triggers the allocation (in other words, no global
allocation for other guests). This will help the memcg controller to
make the right decisions.
Signed-off-by: default avatarChristian Borntraeger <borntraeger@de.ibm.com>
Acked-by: default avatarJanosch Frank <frankja@linux.ibm.com>
Acked-by: default avatarCornelia Huck <cohuck@redhat.com>
parent f8394f23
...@@ -184,7 +184,7 @@ static int __import_wp_info(struct kvm_vcpu *vcpu, ...@@ -184,7 +184,7 @@ static int __import_wp_info(struct kvm_vcpu *vcpu,
if (wp_info->len < 0 || wp_info->len > MAX_WP_SIZE) if (wp_info->len < 0 || wp_info->len > MAX_WP_SIZE)
return -EINVAL; return -EINVAL;
wp_info->old_data = kmalloc(bp_data->len, GFP_KERNEL); wp_info->old_data = kmalloc(bp_data->len, GFP_KERNEL_ACCOUNT);
if (!wp_info->old_data) if (!wp_info->old_data)
return -ENOMEM; return -ENOMEM;
/* try to backup the original value */ /* try to backup the original value */
...@@ -234,7 +234,7 @@ int kvm_s390_import_bp_data(struct kvm_vcpu *vcpu, ...@@ -234,7 +234,7 @@ int kvm_s390_import_bp_data(struct kvm_vcpu *vcpu,
if (nr_wp > 0) { if (nr_wp > 0) {
wp_info = kmalloc_array(nr_wp, wp_info = kmalloc_array(nr_wp,
sizeof(*wp_info), sizeof(*wp_info),
GFP_KERNEL); GFP_KERNEL_ACCOUNT);
if (!wp_info) { if (!wp_info) {
ret = -ENOMEM; ret = -ENOMEM;
goto error; goto error;
...@@ -243,7 +243,7 @@ int kvm_s390_import_bp_data(struct kvm_vcpu *vcpu, ...@@ -243,7 +243,7 @@ int kvm_s390_import_bp_data(struct kvm_vcpu *vcpu,
if (nr_bp > 0) { if (nr_bp > 0) {
bp_info = kmalloc_array(nr_bp, bp_info = kmalloc_array(nr_bp,
sizeof(*bp_info), sizeof(*bp_info),
GFP_KERNEL); GFP_KERNEL_ACCOUNT);
if (!bp_info) { if (!bp_info) {
ret = -ENOMEM; ret = -ENOMEM;
goto error; goto error;
...@@ -349,7 +349,7 @@ static struct kvm_hw_wp_info_arch *any_wp_changed(struct kvm_vcpu *vcpu) ...@@ -349,7 +349,7 @@ static struct kvm_hw_wp_info_arch *any_wp_changed(struct kvm_vcpu *vcpu)
if (!wp_info || !wp_info->old_data || wp_info->len <= 0) if (!wp_info || !wp_info->old_data || wp_info->len <= 0)
continue; continue;
temp = kmalloc(wp_info->len, GFP_KERNEL); temp = kmalloc(wp_info->len, GFP_KERNEL_ACCOUNT);
if (!temp) if (!temp)
continue; continue;
......
...@@ -398,7 +398,7 @@ int handle_sthyi(struct kvm_vcpu *vcpu) ...@@ -398,7 +398,7 @@ int handle_sthyi(struct kvm_vcpu *vcpu)
if (!kvm_s390_pv_cpu_is_protected(vcpu) && (addr & ~PAGE_MASK)) if (!kvm_s390_pv_cpu_is_protected(vcpu) && (addr & ~PAGE_MASK))
return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
sctns = (void *)get_zeroed_page(GFP_KERNEL); sctns = (void *)get_zeroed_page(GFP_KERNEL_ACCOUNT);
if (!sctns) if (!sctns)
return -ENOMEM; return -ENOMEM;
......
...@@ -1792,7 +1792,7 @@ struct kvm_s390_interrupt_info *kvm_s390_get_io_int(struct kvm *kvm, ...@@ -1792,7 +1792,7 @@ struct kvm_s390_interrupt_info *kvm_s390_get_io_int(struct kvm *kvm,
goto out; goto out;
} }
gisa_out: gisa_out:
tmp_inti = kzalloc(sizeof(*inti), GFP_KERNEL); tmp_inti = kzalloc(sizeof(*inti), GFP_KERNEL_ACCOUNT);
if (tmp_inti) { if (tmp_inti) {
tmp_inti->type = KVM_S390_INT_IO(1, 0, 0, 0); tmp_inti->type = KVM_S390_INT_IO(1, 0, 0, 0);
tmp_inti->io.io_int_word = isc_to_int_word(isc); tmp_inti->io.io_int_word = isc_to_int_word(isc);
...@@ -2015,7 +2015,7 @@ int kvm_s390_inject_vm(struct kvm *kvm, ...@@ -2015,7 +2015,7 @@ int kvm_s390_inject_vm(struct kvm *kvm,
struct kvm_s390_interrupt_info *inti; struct kvm_s390_interrupt_info *inti;
int rc; int rc;
inti = kzalloc(sizeof(*inti), GFP_KERNEL); inti = kzalloc(sizeof(*inti), GFP_KERNEL_ACCOUNT);
if (!inti) if (!inti)
return -ENOMEM; return -ENOMEM;
...@@ -2414,7 +2414,7 @@ static int enqueue_floating_irq(struct kvm_device *dev, ...@@ -2414,7 +2414,7 @@ static int enqueue_floating_irq(struct kvm_device *dev,
return -EINVAL; return -EINVAL;
while (len >= sizeof(struct kvm_s390_irq)) { while (len >= sizeof(struct kvm_s390_irq)) {
inti = kzalloc(sizeof(*inti), GFP_KERNEL); inti = kzalloc(sizeof(*inti), GFP_KERNEL_ACCOUNT);
if (!inti) if (!inti)
return -ENOMEM; return -ENOMEM;
...@@ -2462,7 +2462,7 @@ static int register_io_adapter(struct kvm_device *dev, ...@@ -2462,7 +2462,7 @@ static int register_io_adapter(struct kvm_device *dev,
if (dev->kvm->arch.adapters[adapter_info.id] != NULL) if (dev->kvm->arch.adapters[adapter_info.id] != NULL)
return -EINVAL; return -EINVAL;
adapter = kzalloc(sizeof(*adapter), GFP_KERNEL); adapter = kzalloc(sizeof(*adapter), GFP_KERNEL_ACCOUNT);
if (!adapter) if (!adapter)
return -ENOMEM; return -ENOMEM;
...@@ -3290,7 +3290,7 @@ int kvm_s390_gib_init(u8 nisc) ...@@ -3290,7 +3290,7 @@ int kvm_s390_gib_init(u8 nisc)
goto out; goto out;
} }
gib = (struct kvm_s390_gib *)get_zeroed_page(GFP_KERNEL | GFP_DMA); gib = (struct kvm_s390_gib *)get_zeroed_page(GFP_KERNEL_ACCOUNT | GFP_DMA);
if (!gib) { if (!gib) {
rc = -ENOMEM; rc = -ENOMEM;
goto out; goto out;
......
...@@ -1254,7 +1254,7 @@ static int kvm_s390_set_processor(struct kvm *kvm, struct kvm_device_attr *attr) ...@@ -1254,7 +1254,7 @@ static int kvm_s390_set_processor(struct kvm *kvm, struct kvm_device_attr *attr)
ret = -EBUSY; ret = -EBUSY;
goto out; goto out;
} }
proc = kzalloc(sizeof(*proc), GFP_KERNEL); proc = kzalloc(sizeof(*proc), GFP_KERNEL_ACCOUNT);
if (!proc) { if (!proc) {
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
...@@ -1416,7 +1416,7 @@ static int kvm_s390_get_processor(struct kvm *kvm, struct kvm_device_attr *attr) ...@@ -1416,7 +1416,7 @@ static int kvm_s390_get_processor(struct kvm *kvm, struct kvm_device_attr *attr)
struct kvm_s390_vm_cpu_processor *proc; struct kvm_s390_vm_cpu_processor *proc;
int ret = 0; int ret = 0;
proc = kzalloc(sizeof(*proc), GFP_KERNEL); proc = kzalloc(sizeof(*proc), GFP_KERNEL_ACCOUNT);
if (!proc) { if (!proc) {
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
...@@ -1444,7 +1444,7 @@ static int kvm_s390_get_machine(struct kvm *kvm, struct kvm_device_attr *attr) ...@@ -1444,7 +1444,7 @@ static int kvm_s390_get_machine(struct kvm *kvm, struct kvm_device_attr *attr)
struct kvm_s390_vm_cpu_machine *mach; struct kvm_s390_vm_cpu_machine *mach;
int ret = 0; int ret = 0;
mach = kzalloc(sizeof(*mach), GFP_KERNEL); mach = kzalloc(sizeof(*mach), GFP_KERNEL_ACCOUNT);
if (!mach) { if (!mach) {
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
...@@ -1812,7 +1812,7 @@ static long kvm_s390_get_skeys(struct kvm *kvm, struct kvm_s390_skeys *args) ...@@ -1812,7 +1812,7 @@ static long kvm_s390_get_skeys(struct kvm *kvm, struct kvm_s390_skeys *args)
if (args->count < 1 || args->count > KVM_S390_SKEYS_MAX) if (args->count < 1 || args->count > KVM_S390_SKEYS_MAX)
return -EINVAL; return -EINVAL;
keys = kvmalloc_array(args->count, sizeof(uint8_t), GFP_KERNEL); keys = kvmalloc_array(args->count, sizeof(uint8_t), GFP_KERNEL_ACCOUNT);
if (!keys) if (!keys)
return -ENOMEM; return -ENOMEM;
...@@ -1857,7 +1857,7 @@ static long kvm_s390_set_skeys(struct kvm *kvm, struct kvm_s390_skeys *args) ...@@ -1857,7 +1857,7 @@ static long kvm_s390_set_skeys(struct kvm *kvm, struct kvm_s390_skeys *args)
if (args->count < 1 || args->count > KVM_S390_SKEYS_MAX) if (args->count < 1 || args->count > KVM_S390_SKEYS_MAX)
return -EINVAL; return -EINVAL;
keys = kvmalloc_array(args->count, sizeof(uint8_t), GFP_KERNEL); keys = kvmalloc_array(args->count, sizeof(uint8_t), GFP_KERNEL_ACCOUNT);
if (!keys) if (!keys)
return -ENOMEM; return -ENOMEM;
...@@ -2625,7 +2625,7 @@ static void sca_dispose(struct kvm *kvm) ...@@ -2625,7 +2625,7 @@ static void sca_dispose(struct kvm *kvm)
int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
{ {
gfp_t alloc_flags = GFP_KERNEL; gfp_t alloc_flags = GFP_KERNEL_ACCOUNT;
int i, rc; int i, rc;
char debug_name[16]; char debug_name[16];
static unsigned long sca_offset; static unsigned long sca_offset;
...@@ -2670,7 +2670,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) ...@@ -2670,7 +2670,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
BUILD_BUG_ON(sizeof(struct sie_page2) != 4096); BUILD_BUG_ON(sizeof(struct sie_page2) != 4096);
kvm->arch.sie_page2 = kvm->arch.sie_page2 =
(struct sie_page2 *) get_zeroed_page(GFP_KERNEL | GFP_DMA); (struct sie_page2 *) get_zeroed_page(GFP_KERNEL_ACCOUNT | GFP_DMA);
if (!kvm->arch.sie_page2) if (!kvm->arch.sie_page2)
goto out_err; goto out_err;
...@@ -2900,7 +2900,7 @@ static int sca_switch_to_extended(struct kvm *kvm) ...@@ -2900,7 +2900,7 @@ static int sca_switch_to_extended(struct kvm *kvm)
if (kvm->arch.use_esca) if (kvm->arch.use_esca)
return 0; return 0;
new_sca = alloc_pages_exact(sizeof(*new_sca), GFP_KERNEL|__GFP_ZERO); new_sca = alloc_pages_exact(sizeof(*new_sca), GFP_KERNEL_ACCOUNT | __GFP_ZERO);
if (!new_sca) if (!new_sca)
return -ENOMEM; return -ENOMEM;
...@@ -3133,7 +3133,7 @@ void kvm_s390_vcpu_unsetup_cmma(struct kvm_vcpu *vcpu) ...@@ -3133,7 +3133,7 @@ void kvm_s390_vcpu_unsetup_cmma(struct kvm_vcpu *vcpu)
int kvm_s390_vcpu_setup_cmma(struct kvm_vcpu *vcpu) int kvm_s390_vcpu_setup_cmma(struct kvm_vcpu *vcpu)
{ {
vcpu->arch.sie_block->cbrlo = get_zeroed_page(GFP_KERNEL); vcpu->arch.sie_block->cbrlo = get_zeroed_page(GFP_KERNEL_ACCOUNT);
if (!vcpu->arch.sie_block->cbrlo) if (!vcpu->arch.sie_block->cbrlo)
return -ENOMEM; return -ENOMEM;
return 0; return 0;
...@@ -3243,7 +3243,7 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu) ...@@ -3243,7 +3243,7 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
int rc; int rc;
BUILD_BUG_ON(sizeof(struct sie_page) != 4096); BUILD_BUG_ON(sizeof(struct sie_page) != 4096);
sie_page = (struct sie_page *) get_zeroed_page(GFP_KERNEL); sie_page = (struct sie_page *) get_zeroed_page(GFP_KERNEL_ACCOUNT);
if (!sie_page) if (!sie_page)
return -ENOMEM; return -ENOMEM;
......
...@@ -879,7 +879,7 @@ static int handle_stsi(struct kvm_vcpu *vcpu) ...@@ -879,7 +879,7 @@ static int handle_stsi(struct kvm_vcpu *vcpu)
switch (fc) { switch (fc) {
case 1: /* same handling for 1 and 2 */ case 1: /* same handling for 1 and 2 */
case 2: case 2:
mem = get_zeroed_page(GFP_KERNEL); mem = get_zeroed_page(GFP_KERNEL_ACCOUNT);
if (!mem) if (!mem)
goto out_no_data; goto out_no_data;
if (stsi((void *) mem, fc, sel1, sel2)) if (stsi((void *) mem, fc, sel1, sel2))
...@@ -888,7 +888,7 @@ static int handle_stsi(struct kvm_vcpu *vcpu) ...@@ -888,7 +888,7 @@ static int handle_stsi(struct kvm_vcpu *vcpu)
case 3: case 3:
if (sel1 != 2 || sel2 != 2) if (sel1 != 2 || sel2 != 2)
goto out_no_data; goto out_no_data;
mem = get_zeroed_page(GFP_KERNEL); mem = get_zeroed_page(GFP_KERNEL_ACCOUNT);
if (!mem) if (!mem)
goto out_no_data; goto out_no_data;
handle_stsi_3_2_2(vcpu, (void *) mem); handle_stsi_3_2_2(vcpu, (void *) mem);
......
...@@ -60,7 +60,7 @@ int kvm_s390_pv_create_cpu(struct kvm_vcpu *vcpu, u16 *rc, u16 *rrc) ...@@ -60,7 +60,7 @@ int kvm_s390_pv_create_cpu(struct kvm_vcpu *vcpu, u16 *rc, u16 *rrc)
if (kvm_s390_pv_cpu_get_handle(vcpu)) if (kvm_s390_pv_cpu_get_handle(vcpu))
return -EINVAL; return -EINVAL;
vcpu->arch.pv.stor_base = __get_free_pages(GFP_KERNEL, vcpu->arch.pv.stor_base = __get_free_pages(GFP_KERNEL_ACCOUNT,
get_order(uv_info.guest_cpu_stor_len)); get_order(uv_info.guest_cpu_stor_len));
if (!vcpu->arch.pv.stor_base) if (!vcpu->arch.pv.stor_base)
return -ENOMEM; return -ENOMEM;
...@@ -72,7 +72,7 @@ int kvm_s390_pv_create_cpu(struct kvm_vcpu *vcpu, u16 *rc, u16 *rrc) ...@@ -72,7 +72,7 @@ int kvm_s390_pv_create_cpu(struct kvm_vcpu *vcpu, u16 *rc, u16 *rrc)
uvcb.stor_origin = (u64)vcpu->arch.pv.stor_base; uvcb.stor_origin = (u64)vcpu->arch.pv.stor_base;
/* Alloc Secure Instruction Data Area Designation */ /* Alloc Secure Instruction Data Area Designation */
vcpu->arch.sie_block->sidad = __get_free_page(GFP_KERNEL | __GFP_ZERO); vcpu->arch.sie_block->sidad = __get_free_page(GFP_KERNEL_ACCOUNT | __GFP_ZERO);
if (!vcpu->arch.sie_block->sidad) { if (!vcpu->arch.sie_block->sidad) {
free_pages(vcpu->arch.pv.stor_base, free_pages(vcpu->arch.pv.stor_base,
get_order(uv_info.guest_cpu_stor_len)); get_order(uv_info.guest_cpu_stor_len));
...@@ -120,7 +120,7 @@ static int kvm_s390_pv_alloc_vm(struct kvm *kvm) ...@@ -120,7 +120,7 @@ static int kvm_s390_pv_alloc_vm(struct kvm *kvm)
struct kvm_memory_slot *memslot; struct kvm_memory_slot *memslot;
kvm->arch.pv.stor_var = NULL; kvm->arch.pv.stor_var = NULL;
kvm->arch.pv.stor_base = __get_free_pages(GFP_KERNEL, get_order(base)); kvm->arch.pv.stor_base = __get_free_pages(GFP_KERNEL_ACCOUNT, get_order(base));
if (!kvm->arch.pv.stor_base) if (!kvm->arch.pv.stor_base)
return -ENOMEM; return -ENOMEM;
......
...@@ -1234,7 +1234,7 @@ static struct vsie_page *get_vsie_page(struct kvm *kvm, unsigned long addr) ...@@ -1234,7 +1234,7 @@ static struct vsie_page *get_vsie_page(struct kvm *kvm, unsigned long addr)
mutex_lock(&kvm->arch.vsie.mutex); mutex_lock(&kvm->arch.vsie.mutex);
if (kvm->arch.vsie.page_count < nr_vcpus) { if (kvm->arch.vsie.page_count < nr_vcpus) {
page = alloc_page(GFP_KERNEL | __GFP_ZERO | GFP_DMA); page = alloc_page(GFP_KERNEL_ACCOUNT | __GFP_ZERO | GFP_DMA);
if (!page) { if (!page) {
mutex_unlock(&kvm->arch.vsie.mutex); mutex_unlock(&kvm->arch.vsie.mutex);
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
...@@ -1336,7 +1336,7 @@ int kvm_s390_handle_vsie(struct kvm_vcpu *vcpu) ...@@ -1336,7 +1336,7 @@ int kvm_s390_handle_vsie(struct kvm_vcpu *vcpu)
void kvm_s390_vsie_init(struct kvm *kvm) void kvm_s390_vsie_init(struct kvm *kvm)
{ {
mutex_init(&kvm->arch.vsie.mutex); mutex_init(&kvm->arch.vsie.mutex);
INIT_RADIX_TREE(&kvm->arch.vsie.addr_to_page, GFP_KERNEL); INIT_RADIX_TREE(&kvm->arch.vsie.addr_to_page, GFP_KERNEL_ACCOUNT);
} }
/* Destroy the vsie data structures. To be called when a vm is destroyed. */ /* Destroy the vsie data structures. To be called when a vm is destroyed. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment