From: David Hildenbrand <david@redhat.com>
To: Tony Krowiak <akrowiak@linux.vnet.ibm.com>,
linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org,
kvm@vger.kernel.org
Cc: freude@de.ibm.com, schwidefsky@de.ibm.com,
heiko.carstens@de.ibm.com, borntraeger@de.ibm.com,
cohuck@redhat.com, kwankhede@nvidia.com,
bjsdjshi@linux.vnet.ibm.com, pbonzini@redhat.com,
alex.williamson@redhat.com, pmorel@linux.vnet.ibm.com,
alifm@linux.vnet.ibm.com, mjrosato@linux.vnet.ibm.com,
jjherne@linux.vnet.ibm.com, thuth@redhat.com,
pasic@linux.vnet.ibm.com, fiuczy@linux.vnet.ibm.com,
buendgen@de.ibm.com
Subject: Re: [PATCH v2 02/15] s390: vsie: implement AP support for second level guest
Date: Wed, 28 Feb 2018 10:39:51 +0100 [thread overview]
Message-ID: <0882e962-8ebb-2cea-0180-5cee9a0db1e4@redhat.com> (raw)
In-Reply-To: <1519741693-17440-3-git-send-email-akrowiak@linux.vnet.ibm.com>
On 27.02.2018 15:28, Tony Krowiak wrote:
> Set effective masks and CRYCB format in the shadow copy of the
> guest level 2 CRYCB.
>
> Signed-off-by: Tony Krowiak <akrowiak@linux.vnet.ibm.com>
> ---
> arch/s390/include/asm/kvm-ap.h | 2 +
> arch/s390/kvm/kvm-ap.c | 5 +++
> arch/s390/kvm/vsie.c | 71 +++++++++++++++++++++++++++++++++-------
> 3 files changed, 66 insertions(+), 12 deletions(-)
>
> diff --git a/arch/s390/include/asm/kvm-ap.h b/arch/s390/include/asm/kvm-ap.h
> index 4e43117..ef749e7 100644
> --- a/arch/s390/include/asm/kvm-ap.h
> +++ b/arch/s390/include/asm/kvm-ap.h
> @@ -13,4 +13,6 @@
>
> void kvm_ap_set_crycb_format(struct kvm *kvm, __u32 *crycbd);
>
> +int kvm_ap_get_crycb_format(struct kvm *kvm);
> +
> #endif /* _ASM_KVM_AP */
> diff --git a/arch/s390/kvm/kvm-ap.c b/arch/s390/kvm/kvm-ap.c
> index 5305f4c..bafe63b 100644
> --- a/arch/s390/kvm/kvm-ap.c
> +++ b/arch/s390/kvm/kvm-ap.c
> @@ -11,6 +11,11 @@
>
> #include "kvm-s390.h"
>
> +int kvm_ap_get_crycb_format(struct kvm *kvm)
> +{
> + return kvm->arch.crypto.crycbd & CRYCB_FORMAT_MASK;
> +}
Why exactly do we need this function? If there are no other users, just
do it directly in the code below.
> +
> static int kvm_ap_apxa_installed(void)
> {
> int ret;
> diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/vsie.c
> index 8961e39..93076ba 100644
> --- a/arch/s390/kvm/vsie.c
> +++ b/arch/s390/kvm/vsie.c
> @@ -18,6 +18,7 @@
> #include <asm/sclp.h>
> #include <asm/nmi.h>
> #include <asm/dis.h>
> +#include <asm/kvm-ap.h>
> #include "kvm-s390.h"
> #include "gaccess.h"
>
> @@ -137,12 +138,56 @@ static int prepare_cpuflags(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
> }
>
> /*
> + * Set up the effective masks for the shadow copy of the crycb. The effective
> + * masks for guest 3 are set by performing a logical bitwise AND of the guest 3
> + * masks with the guest 2 masks.
> + */
> +static void set_crycb_emasks(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
> +{
> + int fmt = kvm_ap_get_crycb_format(vcpu->kvm);
> + unsigned long *mask1, *mask2;
> +
> + switch (fmt) {
> + case CRYCB_FORMAT1:
> + case CRYCB_FORMAT2:
Assume L2 gave us FORMAT0 and we are using FORMAT2. You would copy wrong
bits. See below, maybe we need conversion.
> + mask1 = (unsigned long *)vsie_page->crycb.apcb1.apm;
> + mask2 = (unsigned long *)
> + vcpu->kvm->arch.crypto.crycb->apcb1.apm;
> + bitmap_and(mask1, mask1, mask2, APCB1_MASK_SIZE);
> +
> + mask1 = (unsigned long *)vsie_page->crycb.apcb1.aqm;
> + mask2 = (unsigned long *)
> + vcpu->kvm->arch.crypto.crycb->apcb1.aqm;
> + bitmap_and(mask1, mask1, mask2, APCB1_MASK_SIZE);
> +
> + mask1 = (unsigned long *)vsie_page->crycb.apcb1.adm;
> + mask2 = (unsigned long *)
> + vcpu->kvm->arch.crypto.crycb->apcb1.adm;
> + bitmap_and(mask1, mask1, mask2, APCB1_MASK_SIZE);
> + break;
> + default:
> + mask1 = (unsigned long *)vsie_page->crycb.apcb0.apm;
> + mask2 = (unsigned long *)
> + vcpu->kvm->arch.crypto.crycb->apcb1.apm;
> + bitmap_and(mask1, mask1, mask2, APCB0_MASK_SIZE);
> +
> + mask1 = (unsigned long *)vsie_page->crycb.apcb0.aqm;
> + mask2 = (unsigned long *)
> + vcpu->kvm->arch.crypto.crycb->apcb1.aqm;
> + bitmap_and(mask1, mask1, mask2, APCB0_MASK_SIZE);
> +
> + mask1 = (unsigned long *)vsie_page->crycb.apcb0.adm;
> + mask2 = (unsigned long *)
> + vcpu->kvm->arch.crypto.crycb->apcb1.adm;
> + bitmap_and(mask1, mask1, mask2, APCB0_MASK_SIZE);
> + break;
> + }
> +}
> +
> +/*
> * Create a shadow copy of the crycb block and setup key wrapping, if
> * requested for guest 3 and enabled for guest 2.
> *
> - * We only accept format-1 (no AP in g2), but convert it into format-2
> - * There is nothing to do for format-0.
> - *
> * Returns: - 0 if shadowed or nothing to do
> * - > 0 if control has to be given to guest 2
> */
> @@ -155,9 +200,17 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
> unsigned long *b1, *b2;
> u8 ecb3_flags;
>
> - scb_s->crycbd = 0;
> - if (!(crycbd_o & vcpu->arch.sie_block->crycbd & CRYCB_FORMAT1))
> - return 0;
> + scb_s->crycbd = ((__u32)(__u64) &vsie_page->crycb);
> + kvm_ap_set_crycb_format(vcpu->kvm, &scb_s->crycbd);
> +
> + /* copy the crycb */
> + if (read_guest_real(vcpu, crycb_addr, &vsie_page->crycb,
> + sizeof(vsie_page->crycb)))
> + return set_validity_icpt(scb_s, 0x0035U);
This looks wrong. You are always copying from L2, although L2 might not
even set up a crycb for L3. You removed the important crycbd_o check.
Don't we need the following?
a) Determine the _allowed_ crycb format for L2 -> L3. (How can we tell
which format L2 is allowed to use for L3)
b) Determine the target crycb format. This is basically
vm_ap_set_crycb_format afaics.
c) Convert the given crycb to the target crycb format.
So importantly, can you clarify (as I don't have access to documentation):
- When is L2 allowed to use format-0? So when will the format not be
ignored but is actually used?
- When is L2 allowed to use fortma-2? So when will the format not be
ignored but is actually used?
- When does the SIE start interpreting AP instructions? So how can we
hinder it from doing so? Empty masks? crycb format?
> +
> + /* set up the effective masks */
> + set_crycb_emasks(vcpu, vsie_page);
> +
> /* format-1 is supported with message-security-assist extension 3 */
> if (!test_kvm_facility(vcpu->kvm, 76))
> return 0;
You now already copied the wrapping keys. So they could be !0. Please
add a comment why we don't care.
/* wrapping keys are ignored without ECB3_AES / ECB3_DEA */
> @@ -172,13 +225,7 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
> else if (!crycb_addr)
> return set_validity_icpt(scb_s, 0x0039U);
>
> - /* copy only the wrapping keys */
> - if (read_guest_real(vcpu, crycb_addr + 72, &vsie_page->crycb, 56))
> - return set_validity_icpt(scb_s, 0x0035U);
> -
> scb_s->ecb3 |= ecb3_flags;
> - scb_s->crycbd = ((__u32)(__u64) &vsie_page->crycb) | CRYCB_FORMAT1 |
> - CRYCB_FORMAT2;
>
> /* xor both blocks in one run */
> b1 = (unsigned long *) vsie_page->crycb.dea_wrapping_key_mask;
>
--
Thanks,
David / dhildenb
next prev parent reply other threads:[~2018-02-28 9:39 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-27 14:27 [PATCH v2 00/15] s390: vfio-ap: guest dedicated crypto adapters Tony Krowiak
2018-02-27 14:27 ` [PATCH v2 01/15] KVM: s390: refactor crypto initialization Tony Krowiak
2018-02-28 17:37 ` Cornelia Huck
2018-02-28 21:23 ` Tony Krowiak
2018-03-01 9:59 ` Cornelia Huck
2018-03-14 16:02 ` Tony Krowiak
2018-02-27 14:28 ` [PATCH v2 02/15] s390: vsie: implement AP support for second level guest Tony Krowiak
2018-02-28 9:39 ` David Hildenbrand [this message]
2018-02-28 10:03 ` Pierre Morel
2018-02-27 14:28 ` [PATCH v2 03/15] s390: zcrypt: externalize AP instructions available function Tony Krowiak
2018-02-28 11:40 ` Harald Freudenberger
2018-02-28 17:41 ` Cornelia Huck
2018-03-01 8:38 ` Harald Freudenberger
2018-02-27 14:28 ` [PATCH v2 04/15] KVM: s390: CPU model support for AP virtualization Tony Krowiak
2018-02-28 9:48 ` David Hildenbrand
2018-02-28 11:40 ` Christian Borntraeger
2018-02-28 11:58 ` David Hildenbrand
2018-02-28 15:59 ` Tony Krowiak
2018-02-27 14:28 ` [PATCH v2 05/15] s390: vfio-ap: base implementation of VFIO AP device driver Tony Krowiak
2018-02-28 15:33 ` Pierre Morel
2018-02-28 16:43 ` Tony Krowiak
2018-02-28 18:10 ` Cornelia Huck
2018-02-28 20:34 ` Tony Krowiak
2018-02-27 14:28 ` [PATCH v2 06/15] s390: vfio-ap: register matrix device with VFIO mdev framework Tony Krowiak
2018-02-27 14:28 ` [PATCH v2 07/15] KVM: s390: Interfaces to configure/deconfigure guest's AP matrix Tony Krowiak
2018-02-28 16:15 ` Pierre Morel
2018-02-28 19:11 ` Tony Krowiak
2018-02-28 18:50 ` Tony Krowiak
2018-02-28 19:38 ` Tony Krowiak
2018-03-08 23:03 ` Tony Krowiak
2018-02-27 14:28 ` [PATCH v2 08/15] KVM: s390: interface to enable AP execution mode Tony Krowiak
2018-02-28 9:42 ` David Hildenbrand
2018-02-28 20:37 ` Tony Krowiak
2018-03-01 9:32 ` David Hildenbrand
2018-02-28 9:44 ` David Hildenbrand
2018-02-28 20:39 ` Tony Krowiak
2018-03-01 9:35 ` David Hildenbrand
2018-03-02 19:54 ` Tony Krowiak
2018-03-14 16:29 ` Tony Krowiak
2018-02-27 14:28 ` [PATCH v2 09/15] s390: vfio-ap: sysfs interfaces to configure adapters Tony Krowiak
2018-02-27 14:28 ` [PATCH v2 10/15] s390: vfio-ap: sysfs interfaces to configure domains Tony Krowiak
2018-02-27 14:28 ` [PATCH v2 11/15] s390: vfio-ap: sysfs interfaces to configure control domains Tony Krowiak
2018-02-27 14:28 ` [PATCH v2 12/15] s390: vfio-ap: sysfs interface to view matrix mdev matrix Tony Krowiak
2018-02-27 14:28 ` [PATCH v2 13/15] KVM: s390: Configure the guest's CRYCB Tony Krowiak
2018-02-28 9:49 ` David Hildenbrand
2018-02-28 20:45 ` Tony Krowiak
2018-03-01 9:37 ` David Hildenbrand
2018-03-01 20:42 ` Tony Krowiak
2018-03-02 10:08 ` David Hildenbrand
2018-03-02 19:48 ` Tony Krowiak
2018-02-27 14:28 ` [PATCH v2 14/15] s390: vfio-ap: implement VFIO_DEVICE_GET_INFO ioctl Tony Krowiak
2018-02-27 14:28 ` [PATCH v2 15/15] s390: doc: detailed specifications for AP virtualization Tony Krowiak
2018-02-27 15:57 ` Cornelia Huck
2018-02-27 18:12 ` Tony Krowiak
2018-02-27 14:58 ` [PATCH v2 00/15] s390: vfio-ap: guest dedicated crypto adapters Cornelia Huck
2018-02-27 15:57 ` Tony Krowiak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0882e962-8ebb-2cea-0180-5cee9a0db1e4@redhat.com \
--to=david@redhat.com \
--cc=akrowiak@linux.vnet.ibm.com \
--cc=alex.williamson@redhat.com \
--cc=alifm@linux.vnet.ibm.com \
--cc=bjsdjshi@linux.vnet.ibm.com \
--cc=borntraeger@de.ibm.com \
--cc=buendgen@de.ibm.com \
--cc=cohuck@redhat.com \
--cc=fiuczy@linux.vnet.ibm.com \
--cc=freude@de.ibm.com \
--cc=heiko.carstens@de.ibm.com \
--cc=jjherne@linux.vnet.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=kwankhede@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=mjrosato@linux.vnet.ibm.com \
--cc=pasic@linux.vnet.ibm.com \
--cc=pbonzini@redhat.com \
--cc=pmorel@linux.vnet.ibm.com \
--cc=schwidefsky@de.ibm.com \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).