Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4584841pxj; Wed, 12 May 2021 08:41:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwgFUcPbNcmU6Gz+XW0YGFYbJiD07aFUqjAaWBd3CWYQ9I5hrqStKlNX+49lDJKGmazPq2Q X-Received: by 2002:a17:906:90cf:: with SMTP id v15mr38814097ejw.432.1620834116064; Wed, 12 May 2021 08:41:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620834116; cv=none; d=google.com; s=arc-20160816; b=Ctni60Lwm+1WWd2ya8whEi3Tn9Ti1CZRhvG22CIKfrPYkQLNRiUnsdub21qzeA5EDT PMphQy3sEB6dptya/9SdLFUT0fMLO8St9JtKCzrjyJ3Is5PjHjC0LgSjKjCJHKxBmLY5 hCgppkjv6inBXnJ6Gfh70eDUnc8WC6fMqNqQNtfPJqzgywVjPvmZ10ErvoTd/CUKnH3/ trGcpbBk7OiO3MxhPBIfdKNpAyVy5RoF8gTVdij9yCcKD1ZyQTMrq0qPR6sBz8xEx1HC htBhWkPsa3pN7K8/2IScNPSCIO6Yrp2rqTlmp19FflYMlRZp+Jk4/141eXpypUXZZvkL N5WA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=U+iA82YK5Ew9unfnej+BysAeYE4NHHZzLheT+wILl7c=; b=uu1C8wPCneKPRj39GA2+Ysbxfc3oN1fgth3+rRH1Bf5MVUFVwnXQxi6jkOV0Cdt7vy SLKhOE4mcqT2v1hTQaJKCNGvcdp337w99RDMgu9e5/Qr4ktkwdL1c2VgYPuBrfR13FMo 7o5Qcc1W7A01N/e8Y44VlL4uvl9DOr3XuxpGasrulwiZsSDMwpyifcR5C8IUJOanNdtv fdkwk91As4cULPfogq55rnxjWpLCEiAm50AUtSqzvhWLMPJSWf3Dt3lDk2AxkwkgKP56 A6vAiKhBF5MjUFMtrqQGaa87oAtrLVq9dW2WFrgnS0j4c+S+y1b3xKm8TL9MaQSGZV5S n62w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zuiiS2Yt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rs10si287334ejb.93.2021.05.12.08.41.30; Wed, 12 May 2021 08:41:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zuiiS2Yt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235594AbhELPf5 (ORCPT + 99 others); Wed, 12 May 2021 11:35:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:50550 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234244AbhELPQR (ORCPT ); Wed, 12 May 2021 11:16:17 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AA3C361975; Wed, 12 May 2021 15:05:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620831957; bh=D6rIF9Pl0TRvW5ls9/oMpGEPgLXfAPLzTQdV+1GkVlM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zuiiS2YtrLYaxQ1jnJRYUfzRUiQslhkZtBcZ7U+Kc9YzouNXQoGchiVSCc3yspuTW WT4iXbJq8HFpVoqC7HsLVJb9/l8gilQWmyc+RiR33fOw0YxEbbxV/Vv5lV2DEuQOHm xFSNrm5oZHvo4wpMpapAYaqrJtdK5mPtLwGu/q1Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Claudio Imbrenda , Janosch Frank , David Hildenbrand , Christian Borntraeger Subject: [PATCH 5.10 084/530] KVM: s390: VSIE: correctly handle MVPG when in VSIE Date: Wed, 12 May 2021 16:43:14 +0200 Message-Id: <20210512144822.537876805@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Claudio Imbrenda commit bdf7509bbefa20855d5f6bacdc5b62a8489477c9 upstream. Correctly handle the MVPG instruction when issued by a VSIE guest. Fixes: a3508fbe9dc6d ("KVM: s390: vsie: initial support for nested virtualization") Cc: stable@vger.kernel.org # f85f1baaa189: KVM: s390: split kvm_s390_logical_to_effective Signed-off-by: Claudio Imbrenda Acked-by: Janosch Frank Reviewed-by: David Hildenbrand Acked-by: Christian Borntraeger Link: https://lore.kernel.org/r/20210302174443.514363-4-imbrenda@linux.ibm.com [borntraeger@de.ibm.com: apply fixup from Claudio] Signed-off-by: Christian Borntraeger Signed-off-by: Greg Kroah-Hartman --- arch/s390/kvm/vsie.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 93 insertions(+), 5 deletions(-) --- a/arch/s390/kvm/vsie.c +++ b/arch/s390/kvm/vsie.c @@ -416,11 +416,6 @@ static void unshadow_scb(struct kvm_vcpu memcpy((void *)((u64)scb_o + 0xc0), (void *)((u64)scb_s + 0xc0), 0xf0 - 0xc0); break; - case ICPT_PARTEXEC: - /* MVPG only */ - memcpy((void *)((u64)scb_o + 0xc0), - (void *)((u64)scb_s + 0xc0), 0xd0 - 0xc0); - break; } if (scb_s->ihcpu != 0xffffU) @@ -983,6 +978,95 @@ static int handle_stfle(struct kvm_vcpu } /* + * Get a register for a nested guest. + * @vcpu the vcpu of the guest + * @vsie_page the vsie_page for the nested guest + * @reg the register number, the upper 4 bits are ignored. + * returns: the value of the register. + */ +static u64 vsie_get_register(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page, u8 reg) +{ + /* no need to validate the parameter and/or perform error handling */ + reg &= 0xf; + switch (reg) { + case 15: + return vsie_page->scb_s.gg15; + case 14: + return vsie_page->scb_s.gg14; + default: + return vcpu->run->s.regs.gprs[reg]; + } +} + +static int vsie_handle_mvpg(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) +{ + struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; + unsigned long pei_dest, pei_src, src, dest, mask; + u64 *pei_block = &vsie_page->scb_o->mcic; + int edat, rc_dest, rc_src; + union ctlreg0 cr0; + + cr0.val = vcpu->arch.sie_block->gcr[0]; + edat = cr0.edat && test_kvm_facility(vcpu->kvm, 8); + mask = _kvm_s390_logical_to_effective(&scb_s->gpsw, PAGE_MASK); + + dest = vsie_get_register(vcpu, vsie_page, scb_s->ipb >> 20) & mask; + src = vsie_get_register(vcpu, vsie_page, scb_s->ipb >> 16) & mask; + + rc_dest = kvm_s390_shadow_fault(vcpu, vsie_page->gmap, dest, &pei_dest); + rc_src = kvm_s390_shadow_fault(vcpu, vsie_page->gmap, src, &pei_src); + /* + * Either everything went well, or something non-critical went wrong + * e.g. because of a race. In either case, simply retry. + */ + if (rc_dest == -EAGAIN || rc_src == -EAGAIN || (!rc_dest && !rc_src)) { + retry_vsie_icpt(vsie_page); + return -EAGAIN; + } + /* Something more serious went wrong, propagate the error */ + if (rc_dest < 0) + return rc_dest; + if (rc_src < 0) + return rc_src; + + /* The only possible suppressing exception: just deliver it */ + if (rc_dest == PGM_TRANSLATION_SPEC || rc_src == PGM_TRANSLATION_SPEC) { + clear_vsie_icpt(vsie_page); + rc_dest = kvm_s390_inject_program_int(vcpu, PGM_TRANSLATION_SPEC); + WARN_ON_ONCE(rc_dest); + return 1; + } + + /* + * Forward the PEI intercept to the guest if it was a page fault, or + * also for segment and region table faults if EDAT applies. + */ + if (edat) { + rc_dest = rc_dest == PGM_ASCE_TYPE ? rc_dest : 0; + rc_src = rc_src == PGM_ASCE_TYPE ? rc_src : 0; + } else { + rc_dest = rc_dest != PGM_PAGE_TRANSLATION ? rc_dest : 0; + rc_src = rc_src != PGM_PAGE_TRANSLATION ? rc_src : 0; + } + if (!rc_dest && !rc_src) { + pei_block[0] = pei_dest; + pei_block[1] = pei_src; + return 1; + } + + retry_vsie_icpt(vsie_page); + + /* + * The host has edat, and the guest does not, or it was an ASCE type + * exception. The host needs to inject the appropriate DAT interrupts + * into the guest. + */ + if (rc_dest) + return inject_fault(vcpu, rc_dest, dest, 1); + return inject_fault(vcpu, rc_src, src, 0); +} + +/* * Run the vsie on a shadow scb and a shadow gmap, without any further * sanity checks, handling SIE faults. * @@ -1068,6 +1152,10 @@ static int do_vsie_run(struct kvm_vcpu * if ((scb_s->ipa & 0xf000) != 0xf000) scb_s->ipa += 0x1000; break; + case ICPT_PARTEXEC: + if (scb_s->ipa == 0xb254) + rc = vsie_handle_mvpg(vcpu, vsie_page); + break; } return rc; }