Skip to content

Commit 2c69c1a

Browse files
committed
Merge tag 'kvm-s390-next-20140910' of git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux into kvm-next
KVM: s390: Fixes and features for next (3.18) 1. Crypto/CPACF support: To enable the MSA4 instructions we have to provide a common control structure for each SIE control block 2. Two cleanups found by a static code checker: one redundant assignment and one useless if 3. Fix the page handling of the diag10 ballooning interface. If the guest freed the pages at absolute 0 some checks and frees were incorrect 4. Limit guests to 16TB 5. Add __must_check to interrupt injection code
2 parents 209cf19 + bfac1f5 commit 2c69c1a

File tree

6 files changed

+74
-20
lines changed

6 files changed

+74
-20
lines changed

arch/s390/include/asm/kvm_host.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ struct kvm_s390_sie_block {
157157
__u8 armid; /* 0x00e3 */
158158
__u8 reservede4[4]; /* 0x00e4 */
159159
__u64 tecmc; /* 0x00e8 */
160-
__u8 reservedf0[16]; /* 0x00f0 */
160+
__u8 reservedf0[12]; /* 0x00f0 */
161+
#define CRYCB_FORMAT1 0x00000001
162+
__u32 crycbd; /* 0x00fc */
161163
__u64 gcr[16]; /* 0x0100 */
162164
__u64 gbea; /* 0x0180 */
163165
__u8 reserved188[24]; /* 0x0188 */
@@ -410,6 +412,15 @@ struct s390_io_adapter {
410412
#define MAX_S390_IO_ADAPTERS ((MAX_ISC + 1) * 8)
411413
#define MAX_S390_ADAPTER_MAPS 256
412414

415+
struct kvm_s390_crypto {
416+
struct kvm_s390_crypto_cb *crycb;
417+
__u32 crycbd;
418+
};
419+
420+
struct kvm_s390_crypto_cb {
421+
__u8 reserved00[128]; /* 0x0000 */
422+
};
423+
413424
struct kvm_arch{
414425
struct sca_block *sca;
415426
debug_info_t *dbf;
@@ -423,6 +434,7 @@ struct kvm_arch{
423434
struct s390_io_adapter *adapters[MAX_S390_IO_ADAPTERS];
424435
wait_queue_head_t ipte_wq;
425436
spinlock_t start_stop_lock;
437+
struct kvm_s390_crypto crypto;
426438
};
427439

428440
#define KVM_HVA_ERR_BAD (-1UL)

arch/s390/kvm/diag.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,32 @@ static int diag_release_pages(struct kvm_vcpu *vcpu)
2828
start = vcpu->run->s.regs.gprs[(vcpu->arch.sie_block->ipa & 0xf0) >> 4];
2929
end = vcpu->run->s.regs.gprs[vcpu->arch.sie_block->ipa & 0xf] + 4096;
3030

31-
if (start & ~PAGE_MASK || end & ~PAGE_MASK || start > end
31+
if (start & ~PAGE_MASK || end & ~PAGE_MASK || start >= end
3232
|| start < 2 * PAGE_SIZE)
3333
return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
3434

3535
VCPU_EVENT(vcpu, 5, "diag release pages %lX %lX", start, end);
3636
vcpu->stat.diagnose_10++;
3737

38-
/* we checked for start > end above */
39-
if (end < prefix || start >= prefix + 2 * PAGE_SIZE) {
38+
/*
39+
* We checked for start >= end above, so lets check for the
40+
* fast path (no prefix swap page involved)
41+
*/
42+
if (end <= prefix || start >= prefix + 2 * PAGE_SIZE) {
4043
gmap_discard(vcpu->arch.gmap, start, end);
4144
} else {
42-
if (start < prefix)
43-
gmap_discard(vcpu->arch.gmap, start, prefix);
44-
if (end >= prefix)
45-
gmap_discard(vcpu->arch.gmap,
46-
prefix + 2 * PAGE_SIZE, end);
45+
/*
46+
* This is slow path. gmap_discard will check for start
47+
* so lets split this into before prefix, prefix, after
48+
* prefix and let gmap_discard make some of these calls
49+
* NOPs.
50+
*/
51+
gmap_discard(vcpu->arch.gmap, start, prefix);
52+
if (start <= prefix)
53+
gmap_discard(vcpu->arch.gmap, 0, 4096);
54+
if (end > prefix + 4096)
55+
gmap_discard(vcpu->arch.gmap, 4096, 8192);
56+
gmap_discard(vcpu->arch.gmap, prefix + 2 * PAGE_SIZE, end);
4757
}
4858
return 0;
4959
}

arch/s390/kvm/gaccess.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,7 @@ static void ipte_unlock_simple(struct kvm_vcpu *vcpu)
254254
new = old = ACCESS_ONCE(*ic);
255255
new.k = 0;
256256
} while (cmpxchg(&ic->val, old.val, new.val) != old.val);
257-
if (!ipte_lock_count)
258-
wake_up(&vcpu->kvm->arch.ipte_wq);
257+
wake_up(&vcpu->kvm->arch.ipte_wq);
259258
out:
260259
mutex_unlock(&ipte_mutex);
261260
}

arch/s390/kvm/interrupt.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#define IOINT_AI_MASK 0x04000000
2929
#define PFAULT_INIT 0x0600
3030

31-
static int deliver_ckc_interrupt(struct kvm_vcpu *vcpu);
31+
static int __must_check deliver_ckc_interrupt(struct kvm_vcpu *vcpu);
3232

3333
static int is_ioint(u64 type)
3434
{
@@ -77,7 +77,7 @@ static u64 int_word_to_isc_bits(u32 int_word)
7777
return (0x80 >> isc) << 24;
7878
}
7979

80-
static int __interrupt_is_deliverable(struct kvm_vcpu *vcpu,
80+
static int __must_check __interrupt_is_deliverable(struct kvm_vcpu *vcpu,
8181
struct kvm_s390_interrupt_info *inti)
8282
{
8383
switch (inti->type) {
@@ -86,6 +86,7 @@ static int __interrupt_is_deliverable(struct kvm_vcpu *vcpu,
8686
return 0;
8787
if (vcpu->arch.sie_block->gcr[0] & 0x2000ul)
8888
return 1;
89+
return 0;
8990
case KVM_S390_INT_EMERGENCY:
9091
if (psw_extint_disabled(vcpu))
9192
return 0;
@@ -225,7 +226,7 @@ static u16 get_ilc(struct kvm_vcpu *vcpu)
225226
}
226227
}
227228

228-
static int __deliver_prog_irq(struct kvm_vcpu *vcpu,
229+
static int __must_check __deliver_prog_irq(struct kvm_vcpu *vcpu,
229230
struct kvm_s390_pgm_info *pgm_info)
230231
{
231232
int rc = 0;
@@ -307,7 +308,7 @@ static int __deliver_prog_irq(struct kvm_vcpu *vcpu,
307308
return rc;
308309
}
309310

310-
static int __do_deliver_interrupt(struct kvm_vcpu *vcpu,
311+
static int __must_check __do_deliver_interrupt(struct kvm_vcpu *vcpu,
311312
struct kvm_s390_interrupt_info *inti)
312313
{
313314
const unsigned short table[] = { 2, 4, 4, 6 };
@@ -508,7 +509,7 @@ static int __do_deliver_interrupt(struct kvm_vcpu *vcpu,
508509
return rc;
509510
}
510511

511-
static int deliver_ckc_interrupt(struct kvm_vcpu *vcpu)
512+
static int __must_check deliver_ckc_interrupt(struct kvm_vcpu *vcpu)
512513
{
513514
int rc;
514515

@@ -657,7 +658,7 @@ void kvm_s390_clear_local_irqs(struct kvm_vcpu *vcpu)
657658
&vcpu->kvm->arch.sca->cpu[vcpu->vcpu_id].ctrl);
658659
}
659660

660-
int kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu)
661+
int __must_check kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu)
661662
{
662663
struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
663664
struct kvm_s390_float_interrupt *fi = vcpu->arch.local_int.float_int;
@@ -1351,7 +1352,6 @@ static int flic_set_attr(struct kvm_device *dev, struct kvm_device_attr *attr)
13511352
r = enqueue_floating_irq(dev, attr);
13521353
break;
13531354
case KVM_DEV_FLIC_CLEAR_IRQS:
1354-
r = 0;
13551355
kvm_s390_clear_float_irqs(dev->kvm);
13561356
break;
13571357
case KVM_DEV_FLIC_APF_ENABLE:

arch/s390/kvm/kvm-s390.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,22 @@ long kvm_arch_vm_ioctl(struct file *filp,
392392
return r;
393393
}
394394

395+
static int kvm_s390_crypto_init(struct kvm *kvm)
396+
{
397+
if (!test_vfacility(76))
398+
return 0;
399+
400+
kvm->arch.crypto.crycb = kzalloc(sizeof(*kvm->arch.crypto.crycb),
401+
GFP_KERNEL | GFP_DMA);
402+
if (!kvm->arch.crypto.crycb)
403+
return -ENOMEM;
404+
405+
kvm->arch.crypto.crycbd = (__u32) (unsigned long) kvm->arch.crypto.crycb |
406+
CRYCB_FORMAT1;
407+
408+
return 0;
409+
}
410+
395411
int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
396412
{
397413
int rc;
@@ -429,6 +445,9 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
429445
if (!kvm->arch.dbf)
430446
goto out_nodbf;
431447

448+
if (kvm_s390_crypto_init(kvm) < 0)
449+
goto out_crypto;
450+
432451
spin_lock_init(&kvm->arch.float_int.lock);
433452
INIT_LIST_HEAD(&kvm->arch.float_int.list);
434453
init_waitqueue_head(&kvm->arch.ipte_wq);
@@ -439,7 +458,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
439458
if (type & KVM_VM_S390_UCONTROL) {
440459
kvm->arch.gmap = NULL;
441460
} else {
442-
kvm->arch.gmap = gmap_alloc(current->mm, -1UL);
461+
kvm->arch.gmap = gmap_alloc(current->mm, (1UL << 44) - 1);
443462
if (!kvm->arch.gmap)
444463
goto out_nogmap;
445464
kvm->arch.gmap->private = kvm;
@@ -453,6 +472,8 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
453472

454473
return 0;
455474
out_nogmap:
475+
kfree(kvm->arch.crypto.crycb);
476+
out_crypto:
456477
debug_unregister(kvm->arch.dbf);
457478
out_nodbf:
458479
free_page((unsigned long)(kvm->arch.sca));
@@ -507,6 +528,7 @@ void kvm_arch_destroy_vm(struct kvm *kvm)
507528
kvm_free_vcpus(kvm);
508529
free_page((unsigned long)(kvm->arch.sca));
509530
debug_unregister(kvm->arch.dbf);
531+
kfree(kvm->arch.crypto.crycb);
510532
if (!kvm_is_ucontrol(kvm))
511533
gmap_free(kvm->arch.gmap);
512534
kvm_s390_destroy_adapters(kvm);
@@ -588,6 +610,14 @@ int kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
588610
return 0;
589611
}
590612

613+
static void kvm_s390_vcpu_crypto_setup(struct kvm_vcpu *vcpu)
614+
{
615+
if (!test_vfacility(76))
616+
return;
617+
618+
vcpu->arch.sie_block->crycbd = vcpu->kvm->arch.crypto.crycbd;
619+
}
620+
591621
void kvm_s390_vcpu_unsetup_cmma(struct kvm_vcpu *vcpu)
592622
{
593623
free_page(vcpu->arch.sie_block->cbrlo);
@@ -634,6 +664,9 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
634664
vcpu->arch.ckc_timer.function = kvm_s390_idle_wakeup;
635665
get_cpu_id(&vcpu->arch.cpu_id);
636666
vcpu->arch.cpu_id.version = 0xff;
667+
668+
kvm_s390_vcpu_crypto_setup(vcpu);
669+
637670
return rc;
638671
}
639672

arch/s390/kvm/kvm-s390.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static inline int kvm_s390_user_cpu_state_ctrl(struct kvm *kvm)
138138
int kvm_s390_handle_wait(struct kvm_vcpu *vcpu);
139139
void kvm_s390_vcpu_wakeup(struct kvm_vcpu *vcpu);
140140
enum hrtimer_restart kvm_s390_idle_wakeup(struct hrtimer *timer);
141-
int kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu);
141+
int __must_check kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu);
142142
void kvm_s390_clear_local_irqs(struct kvm_vcpu *vcpu);
143143
void kvm_s390_clear_float_irqs(struct kvm *kvm);
144144
int __must_check kvm_s390_inject_vm(struct kvm *kvm,

0 commit comments

Comments
 (0)