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=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 3D5B1C2BB48 for ; Tue, 15 Dec 2020 17:44:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0005A22B3B for ; Tue, 15 Dec 2020 17:44:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731236AbgLORo3 (ORCPT ); Tue, 15 Dec 2020 12:44:29 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:55919 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731184AbgLORoQ (ORCPT ); Tue, 15 Dec 2020 12:44:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608054170; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zn2O0Yhhu1DgJxagbxrqvVu4xN/sjNU7imuSGqsiR7U=; b=dMcUcor0IkvDy3PUhFd1AKUEcgwy4VF8Ws5GsllTas9AWyUy8C6DT+lIkhjM2SAfACago6 86JSABG0ehAxhd9rNCLx20afvscoceZiqwqGwoOYkimv4S82cBqylmbaEbxq33zWHIe0En 47oeytJOpThZ7JvSG3EmnlD83JgNkZc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-596-z3d7gljTOCqguLxPk_neRg-1; Tue, 15 Dec 2020 12:42:46 -0500 X-MC-Unique: z3d7gljTOCqguLxPk_neRg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0C064801AC1; Tue, 15 Dec 2020 17:42:45 +0000 (UTC) Received: from gondolin (ovpn-114-220.ams2.redhat.com [10.36.114.220]) by smtp.corp.redhat.com (Postfix) with ESMTP id 29F905D9E8; Tue, 15 Dec 2020 17:42:36 +0000 (UTC) Date: Tue, 15 Dec 2020 18:42:34 +0100 From: Cornelia Huck To: Tony Krowiak Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, stable@vger.kernel.org, gregkh@linuxfoundation.org, sashal@kernel.org, borntraeger@de.ibm.com, kwankhede@nvidia.com, pbonzini@redhat.com, alex.williamson@redhat.com, pasic@linux.vnet.ibm.com Subject: Re: [PATCH v3] s390/vfio-ap: clean up vfio_ap resources when KVM pointer invalidated Message-ID: <20201215184234.186b2971.cohuck@redhat.com> In-Reply-To: <20201214165617.28685-1-akrowiak@linux.ibm.com> References: <20201214165617.28685-1-akrowiak@linux.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.14 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 14 Dec 2020 11:56:17 -0500 Tony Krowiak wrote: > The vfio_ap device driver registers a group notifier with VFIO when the > file descriptor for a VFIO mediated device for a KVM guest is opened to > receive notification that the KVM pointer is set (VFIO_GROUP_NOTIFY_SET_KVM > event). When the KVM pointer is set, the vfio_ap driver takes the > following actions: > 1. Stashes the KVM pointer in the vfio_ap_mdev struct that holds the state > of the mediated device. > 2. Calls the kvm_get_kvm() function to increment its reference counter. > 3. Sets the function pointer to the function that handles interception of > the instruction that enables/disables interrupt processing. > 4. Sets the masks in the KVM guest's CRYCB to pass AP resources through to > the guest. > > In order to avoid memory leaks, when the notifier is called to receive > notification that the KVM pointer has been set to NULL, the vfio_ap device > driver should reverse the actions taken when the KVM pointer was set. > > Fixes: 258287c994de ("s390: vfio-ap: implement mediated device open callback") > Signed-off-by: Tony Krowiak > --- > drivers/s390/crypto/vfio_ap_ops.c | 29 ++++++++++++++++++++--------- > 1 file changed, 20 insertions(+), 9 deletions(-) Reviewed-by: Cornelia Huck