From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69E18C43382 for ; Fri, 28 Sep 2018 10:14:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 229652172C for ; Fri, 28 Sep 2018 10:14:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 229652172C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729251AbeI1Qhk (ORCPT ); Fri, 28 Sep 2018 12:37:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45222 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728936AbeI1Qhk (ORCPT ); Fri, 28 Sep 2018 12:37:40 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 89985308FF30; Fri, 28 Sep 2018 10:14:37 +0000 (UTC) Received: from gondolin (dhcp-192-215.str.redhat.com [10.33.192.215]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7D6A62532; Fri, 28 Sep 2018 10:14:31 +0000 (UTC) Date: Fri, 28 Sep 2018 12:14:29 +0200 From: Cornelia Huck To: Tony Krowiak Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, freude@de.ibm.com, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, borntraeger@de.ibm.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, berrange@redhat.com, fiuczy@linux.vnet.ibm.com, buendgen@de.ibm.com, frankja@linux.ibm.com, Tony Krowiak Subject: Re: [PATCH v11 11/26] s390: vfio-ap: implement mediated device open callback Message-ID: <20180928121429.7323d78b.cohuck@redhat.com> In-Reply-To: <20180925231641.4954-12-akrowiak@linux.vnet.ibm.com> References: <20180925231641.4954-1-akrowiak@linux.vnet.ibm.com> <20180925231641.4954-12-akrowiak@linux.vnet.ibm.com> Organization: Red Hat GmbH MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Fri, 28 Sep 2018 10:14:37 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 25 Sep 2018 19:16:26 -0400 Tony Krowiak wrote: > From: Tony Krowiak > > Implements the open callback on the mediated matrix device. > The function registers a group notifier to receive notification > of the VFIO_GROUP_NOTIFY_SET_KVM event. When notified, > the vfio_ap device driver will get access to the guest's > kvm structure. The open callback must ensure that only one > mediated device shall be opened per guest. > > Signed-off-by: Tony Krowiak > Acked-by: Halil Pasic > Tested-by: Michael Mueller > Tested-by: Farhan Ali > Tested-by: Pierre Morel > Acked-by: Pierre Morel > --- > arch/s390/include/asm/kvm_host.h | 1 + > drivers/s390/crypto/vfio_ap_ops.c | 159 ++++++++++++++++++++++++++ > drivers/s390/crypto/vfio_ap_private.h | 5 + > 3 files changed, 165 insertions(+) > > +static void vfio_ap_mdev_copy_masks(struct ap_matrix_mdev *matrix_mdev) > +{ > + int nbytes; > + unsigned long *apm, *aqm, *adm; > + struct kvm_s390_crypto_cb *crycb = matrix_mdev->kvm->arch.crypto.crycb; > + > + switch (matrix_mdev->kvm->arch.crypto.crycbd & CRYCB_FORMAT_MASK) { > + case CRYCB_FORMAT2: > + apm = (unsigned long *)crycb->apcb1.apm; > + aqm = (unsigned long *)crycb->apcb1.aqm; > + adm = (unsigned long *)crycb->apcb1.adm; > + break; > + case CRYCB_FORMAT1: > + case CRYCB_FORMAT0: > + default: That one looks a tad odd: the masking above should guarantee that we hit either the format 2, 1, or 0 cases, so the default case should never hit. Moreover, if the mask above will ever be changed, we don't know where we should look for the correct masks (what will a FORMAT use: apcb1, apcb0, or something else?) Would it be better to moan in the default case and copy nothing? > + apm = (unsigned long *)crycb->apcb0.apm; > + aqm = (unsigned long *)crycb->apcb0.aqm; > + adm = (unsigned long *)crycb->apcb0.adm; > + break; > + } > + > + nbytes = DIV_ROUND_UP(matrix_mdev->matrix.apm_max + 1, BITS_PER_BYTE); > + memcpy(apm, matrix_mdev->matrix.apm, nbytes); > + nbytes = DIV_ROUND_UP(matrix_mdev->matrix.aqm_max + 1, BITS_PER_BYTE); > + memcpy(aqm, matrix_mdev->matrix.aqm, nbytes); > + nbytes = DIV_ROUND_UP(matrix_mdev->matrix.adm_max + 1, BITS_PER_BYTE); > + memcpy(adm, matrix_mdev->matrix.adm, nbytes); > +} Anyway, that can be easily changed later on; in general, Reviewed-by: Cornelia Huck