Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp8111542rwi; Tue, 25 Oct 2022 02:37:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4KE4eVDSuXS1dzy4Q4OuWpUdZ2GwkmPjrNrxudZ5X9l10PyxyOeCOkS0aiLxNSrkiWyL4t X-Received: by 2002:aa7:cd92:0:b0:456:cbb5:2027 with SMTP id x18-20020aa7cd92000000b00456cbb52027mr34517731edv.384.1666690653253; Tue, 25 Oct 2022 02:37:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666690653; cv=none; d=google.com; s=arc-20160816; b=ZbSvYXa6y3968nCuGs0sUszmM7YaS7/oNkzCwo3Z637q+abPaREYOAOsfojBEm814Q 3OotOWU8KVrd14tEuRciNitbNI404/03PFTT15uQirD29w0ISAsfZKrWXDftli3daP0G XSTP7HcwlwR3mPjGPuLXakgC8iH2ynpagcuIZbnbtiulExWmz+he9mMJKfFca9Kf9Ocp nuLhGwWOeyxK9lCnSef34mFLrvihtRkniyreJ0Ym46K52/TQXBNaSAA3yf/5BsjN5Wvj 94PoizKj8lH6S9JuzygkRobzoUwE7g9lWGVZvD5yZRl3uFFqFKszZM5ckhbkf+GUWMQN xXHw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=C0968ZWBFOazVrjsAN8FV+ygdlEqrbRRvFakZwWPuxQ=; b=su2FteBsTT5dyAMV0AnfpKsNK7OoUGQi3K7W6HzOnfkrhnRuQ4CHITUMM7IB1TYENY 5tUtYAUVDgPYwDJ9GrU8v285WjhMBoav31Ch9fR9bbrl8k+oy0z3rPE3u9vxHqcnUXRy T9UDFJN6kv8ae57hE4/SmN+lfc1WhmPYhkPVlgU4wlzVkGLkBl5K4HZfbFN3xOZaZ8M8 3J9jG7cblXZWQRCYfsoczg57XWMbMg9MkpIEtTMdkUyOHCFal7x+m46qxw5VkGiZov7c fG2WUv6xnMOwyRhx11OfmlzOdx5NWQDMGpBvZFuuI05ag4BrIBTePitxuRRRq7y1dVhQ huoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=QQkJ+mWh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id du21-20020a17090772d500b0078dcddc1b8csi2460750ejc.788.2022.10.25.02.37.08; Tue, 25 Oct 2022 02:37:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=QQkJ+mWh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231989AbiJYJUO (ORCPT + 99 others); Tue, 25 Oct 2022 05:20:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229629AbiJYJTQ (ORCPT ); Tue, 25 Oct 2022 05:19:16 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 546DD16D895; Tue, 25 Oct 2022 02:13:30 -0700 (PDT) Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29P8jQm1011200; Tue, 25 Oct 2022 09:13:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=C0968ZWBFOazVrjsAN8FV+ygdlEqrbRRvFakZwWPuxQ=; b=QQkJ+mWh0KB8c6FPuFg+IMZj2WKtEAXzGBPHH83avUBcwclFhfH4XuST5Z6S4psoQDtR +R6fElzaN0cFixqFdgxObIqZpBx/q2pwBymLEscQdkpSj96+QaV7APm84lbk1JTFHfb8 QihaUsks6XrZ6IgqQdgGO7d6oZCsw1jRkKi0fU1eo4BDBZWmyYFM3aMo/3vGxOikMBQy DcUV7rl8uU9VtfNy77qPrZvje7xRgoi86vxsQHNs1IX5ymVei1wOUOodcQCrBM5wHnaI eZLdvHywyhkVUkSVDdD53pJgaxCxpPe9TJRUhNK+7whr6RF+DR7pJQoXmUBzOPQ02zC+ JQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3keaxbvha8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Oct 2022 09:13:29 +0000 Received: from m0098399.ppops.net (m0098399.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 29P8s67M001398; Tue, 25 Oct 2022 09:13:29 GMT Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3keaxbvh98-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Oct 2022 09:13:29 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 29P96ZYr030525; Tue, 25 Oct 2022 09:13:26 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma03ams.nl.ibm.com with ESMTP id 3kdugasxtn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Oct 2022 09:13:26 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 29P9DwMQ39453098 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 Oct 2022 09:13:58 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B20A0A405C; Tue, 25 Oct 2022 09:13:23 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1E0E6A405F; Tue, 25 Oct 2022 09:13:23 +0000 (GMT) Received: from li-c6ac47cc-293c-11b2-a85c-d421c8e4747b.ibm.com.com (unknown [9.171.30.119]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 25 Oct 2022 09:13:23 +0000 (GMT) From: Pierre Morel To: kvm@vger.kernel.org Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, borntraeger@de.ibm.com, frankja@linux.ibm.com, cohuck@redhat.com, david@redhat.com, thuth@redhat.com, imbrenda@linux.ibm.com, hca@linux.ibm.com, gor@linux.ibm.com, svens@linux.ibm.com Subject: [PATCH v2 1/1] KVM: s390: vsie: clarifications on setting the APCB Date: Tue, 25 Oct 2022 11:13:19 +0200 Message-Id: <20221025091319.37110-2-pmorel@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221025091319.37110-1-pmorel@linux.ibm.com> References: <20221025091319.37110-1-pmorel@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: aOgpyQooVVThW98wDdjjs3QBYBYX4XBi X-Proofpoint-ORIG-GUID: qq6We6T3Yp6DnOux9guixK9lK1g_kdML X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-25_03,2022-10-25_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 adultscore=0 mlxscore=0 mlxlogscore=878 bulkscore=0 suspectscore=0 clxscore=1015 lowpriorityscore=0 priorityscore=1501 phishscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2210250052 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The APCB is part of the CRYCB. The calculation of the APCB origin can be done by adding the APCB offset to the CRYCB origin. Current code makes confusing transformations, converting the CRYCB origin to a pointer to calculate the APCB origin. Let's make things simpler and keep the CRYCB origin to make these calculations. Signed-off-by: Pierre Morel --- arch/s390/kvm/vsie.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/vsie.c index 94138f8f0c1c..f37851c9b1ab 100644 --- a/arch/s390/kvm/vsie.c +++ b/arch/s390/kvm/vsie.c @@ -138,9 +138,12 @@ static int prepare_cpuflags(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) } /* Copy to APCB FORMAT1 from APCB FORMAT0 */ static int setup_apcb10(struct kvm_vcpu *vcpu, struct kvm_s390_apcb1 *apcb_s, - unsigned long apcb_o, struct kvm_s390_apcb1 *apcb_h) + unsigned long crycb_o, struct kvm_s390_apcb1 *apcb_h) { struct kvm_s390_apcb0 tmp; + unsigned long apcb_o; + + apcb_o = crycb_o + offsetof(struct kvm_s390_crypto_cb, apcb0); if (read_guest_real(vcpu, apcb_o, &tmp, sizeof(struct kvm_s390_apcb0))) return -EFAULT; @@ -157,14 +160,18 @@ static int setup_apcb10(struct kvm_vcpu *vcpu, struct kvm_s390_apcb1 *apcb_s, * setup_apcb00 - Copy to APCB FORMAT0 from APCB FORMAT0 * @vcpu: pointer to the virtual CPU * @apcb_s: pointer to start of apcb in the shadow crycb - * @apcb_o: pointer to start of original apcb in the guest2 + * @crycb_o: real guest address to start of original guest crycb * @apcb_h: pointer to start of apcb in the guest1 * * Returns 0 and -EFAULT on error reading guest apcb */ static int setup_apcb00(struct kvm_vcpu *vcpu, unsigned long *apcb_s, - unsigned long apcb_o, unsigned long *apcb_h) + unsigned long crycb_o, unsigned long *apcb_h) { + unsigned long apcb_o; + + apcb_o = crycb_o + offsetof(struct kvm_s390_crypto_cb, apcb0); + if (read_guest_real(vcpu, apcb_o, apcb_s, sizeof(struct kvm_s390_apcb0))) return -EFAULT; @@ -178,15 +185,19 @@ static int setup_apcb00(struct kvm_vcpu *vcpu, unsigned long *apcb_s, * setup_apcb11 - Copy the FORMAT1 APCB from the guest to the shadow CRYCB * @vcpu: pointer to the virtual CPU * @apcb_s: pointer to start of apcb in the shadow crycb - * @apcb_o: pointer to start of original guest apcb + * @crycb_o: real guest address to start of original guest crycb * @apcb_h: pointer to start of apcb in the host * * Returns 0 and -EFAULT on error reading guest apcb */ static int setup_apcb11(struct kvm_vcpu *vcpu, unsigned long *apcb_s, - unsigned long apcb_o, + unsigned long crycb_o, unsigned long *apcb_h) { + unsigned long apcb_o; + + apcb_o = crycb_o + offsetof(struct kvm_s390_crypto_cb, apcb1); + if (read_guest_real(vcpu, apcb_o, apcb_s, sizeof(struct kvm_s390_apcb1))) return -EFAULT; @@ -200,7 +211,7 @@ static int setup_apcb11(struct kvm_vcpu *vcpu, unsigned long *apcb_s, * setup_apcb - Create a shadow copy of the apcb. * @vcpu: pointer to the virtual CPU * @crycb_s: pointer to shadow crycb - * @crycb_o: pointer to original guest crycb + * @crycb_o: real address of original guest crycb * @crycb_h: pointer to the host crycb * @fmt_o: format of the original guest crycb. * @fmt_h: format of the host crycb. @@ -215,10 +226,6 @@ static int setup_apcb(struct kvm_vcpu *vcpu, struct kvm_s390_crypto_cb *crycb_s, struct kvm_s390_crypto_cb *crycb_h, int fmt_o, int fmt_h) { - struct kvm_s390_crypto_cb *crycb; - - crycb = (struct kvm_s390_crypto_cb *) (unsigned long)crycb_o; - switch (fmt_o) { case CRYCB_FORMAT2: if ((crycb_o & PAGE_MASK) != ((crycb_o + 256) & PAGE_MASK)) @@ -226,18 +233,18 @@ static int setup_apcb(struct kvm_vcpu *vcpu, struct kvm_s390_crypto_cb *crycb_s, if (fmt_h != CRYCB_FORMAT2) return -EINVAL; return setup_apcb11(vcpu, (unsigned long *)&crycb_s->apcb1, - (unsigned long) &crycb->apcb1, + crycb_o, (unsigned long *)&crycb_h->apcb1); case CRYCB_FORMAT1: switch (fmt_h) { case CRYCB_FORMAT2: return setup_apcb10(vcpu, &crycb_s->apcb1, - (unsigned long) &crycb->apcb0, + crycb_o, &crycb_h->apcb1); case CRYCB_FORMAT1: return setup_apcb00(vcpu, (unsigned long *) &crycb_s->apcb0, - (unsigned long) &crycb->apcb0, + crycb_o, (unsigned long *) &crycb_h->apcb0); } break; @@ -248,13 +255,13 @@ static int setup_apcb(struct kvm_vcpu *vcpu, struct kvm_s390_crypto_cb *crycb_s, switch (fmt_h) { case CRYCB_FORMAT2: return setup_apcb10(vcpu, &crycb_s->apcb1, - (unsigned long) &crycb->apcb0, + crycb_o, &crycb_h->apcb1); case CRYCB_FORMAT1: case CRYCB_FORMAT0: return setup_apcb00(vcpu, (unsigned long *) &crycb_s->apcb0, - (unsigned long) &crycb->apcb0, + crycb_o, (unsigned long *) &crycb_h->apcb0); } } -- 2.31.1