Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp566811imm; Fri, 28 Sep 2018 03:16:19 -0700 (PDT) X-Google-Smtp-Source: ACcGV627tWp5OsfANJTnOMaaA5x48PlJ6oZAGXZH53kxNNjNRY8rUOYA0VY49p8N9O3ZfERwFepH X-Received: by 2002:a62:db46:: with SMTP id f67-v6mr16016526pfg.1.1538129779349; Fri, 28 Sep 2018 03:16:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538129779; cv=none; d=google.com; s=arc-20160816; b=1LsvGHXXFIrse6yn09J6E6pMtaHHnjIHlNGly8//8I/1jq8rC2I5lSniUMfbGJCks3 SnLfm1zb68lCMydOvSsgEETCKG8vxpYaxDZ0qxbgTbT3M0QAkQ8iZOEPZK1IcW+x2L7U KFuCRoy4PLUH4kLQRqElWSsWK2tb6/BlsU7GYzhct3wbXfRycA2V42c5HjMcdpXbYjzP YG9aiAEkvnpyDIihqPaaXt71PzahjIa96YarKcyoyuo00ccchF7WqsVNJ3TPAdnPIsgC OiGzU7FB8gtjkx9weaA0GmEEbUQZKW/2uQr6gojoNU7sF5pI9F5jTvTKW5LqiQ3Z16CW KCHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=G0daL/AxnOXPlk8gLqcREU2BiJidEMWMiMI7gRwc0fc=; b=OhCt4Mt9nLF/Je/lWI7ktY+Bcri4oMRAhM2jKpHWSC8Gah3ykkljAJjoCkd3HEQ+CD brP4DcmXfRKxBXeFxbhvRNNK8f5sxrMYHFV/nsJXxSduzavFPTDZjwQAA2WiY1kdgEIU UC5zqjqB3LZjVpMRVRJBUh/evc/cwOmMAKRA5SPrgQUOrH4WTM/8K/AHfxcNTg/fV0Ip usqu7tioqGWoY+K1uZ40NtTF2FKMrSH32Ss2FisLHmlUc5e/30XjGVn2Y1+HUVhRNBgr VgFG3ayVCyjYUNTfWDy+zU/m0sUaB+FZWKHIwGhFUQD52bDUbQVlh9MNe2HzS36DaHP6 p75A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 18-v6si4420584pgx.173.2018.09.28.03.16.01; Fri, 28 Sep 2018 03:16:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729241AbeI1Qhk (ORCPT + 99 others); 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