Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3561857pxu; Tue, 15 Dec 2020 09:47:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJy4bNfGrMdgfhYRic5+x+NqqoKvArIVDB/a8DSMpYxJIxYpr8TAfLlfiub1d5xi4a8/ihC+ X-Received: by 2002:a17:906:a115:: with SMTP id t21mr27565276ejy.549.1608054433737; Tue, 15 Dec 2020 09:47:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608054433; cv=none; d=google.com; s=arc-20160816; b=b1InkviBFtrQC4zOVefVwlfAPLrg1CS877NiqwheLmZ5/6XcWr42Ef9d4MbHbh70tA z/OLKK6kn6pHvLCoRuUqf2H1OyIrenEbiTZcM34CLBfT0gnaCPEtpWdWxbWz9HWGCnzL aMrqqJh7iEXH7CjlJchr9dQRsqUJ7aOY1cEd6FPuKrRgQs+0hFfuBhGLt1kgF3QsUqs7 bON/bLhAtNIGoAQ+HNSJWuEmCPo7QbdYk394rRevYTDtigltYHNQDVE6bfv5kY1aaj/A B+6hcn84qjI7xvoq0VE6xwvtpNFOg++I3RLn9VE8LB9OradVEtoMwfNDt5nIU3fPgRg5 BSog== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=zn2O0Yhhu1DgJxagbxrqvVu4xN/sjNU7imuSGqsiR7U=; b=bMkINpF0dA9kZnhfXXe0Jgz3IYWr7V9k2cTp1DCP2BKtWcBnpk4ov6wh5N8mDIDwst VVHOW/H8XqR0sbShSH0CnTWrxSclTD1BZ2uBB7UNBC7RcnZo7qiATlRlNdwzIA41uE8a gZE+wSp4f/eNrMXccqmDO5tmXcT7eIP3AVCGYwMN3lAGIG4Wod5VlMs/verJuLg41dyl bQsnvYAQ/DJb7LaWAUIi/wce8bU+p+SwuhsZ8y8JGSfDdKasZ48eo7UXj4fybPN8jZwg ly7CxEapP7kxVCchWe/12BlMjcdghecexvPMAaweLYOn3WKl4+Ve/g7p9uVuwD5WlJ79 j/Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dMcUcor0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ca24si1241310edb.492.2020.12.15.09.46.49; Tue, 15 Dec 2020 09:47:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dMcUcor0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731224AbgLORoY (ORCPT + 99 others); Tue, 15 Dec 2020 12:44:24 -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