Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2759455ybt; Tue, 16 Jun 2020 14:31:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6k0kI+4C9qxdN+2TNYff/9T6i4jjDEoKyxxRbntpoEP34jiyfrSdTJ1p6BrZkSeSxYaOJ X-Received: by 2002:a17:906:254f:: with SMTP id j15mr4460622ejb.162.1592343082266; Tue, 16 Jun 2020 14:31:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592343082; cv=none; d=google.com; s=arc-20160816; b=rprSGKaFbw6WGctBUIa72sEmjlJw55G3F1FGUg7q6J4cyb8UX0PuLegEtsxawsv22D 8KEBduM4ZwZc7gXcW0HVT4dBjTwGDgIQwo1FH4erx9Lqs+PcltvavOd7bma3Jd7Jb8rQ f9sS8eurud3Dp38ekAAV8Gd7y1dHTcUdzIkVuOqojwTsxkOXISumtct2F5+t++jwj+JW OOoSRKJQr5aHcUBS7TSUvzgnrJM30gr7JXkOTQ4s8Clo5oAxtj5ely9ci2Vs80JQrq+M DhAqHGkOIR/tiQjVfspWyTWXkfcBkjk9zemJjLKfTdZTQdJLEGhR51KVxEQjetqVSq0e Ioew== 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 :user-agent:message-id:date:cc:to:from:subject:dkim-signature; bh=rfjyihg61U3ImXhyN/RZdOnqUBmVbpAphX1IIssGqq4=; b=Qude/G4cVg9duiC8TTifMXLE1q7qiOxnvvskfL0zm8JDmiKcO3JYf5LmadYM0Z+g96 xPO8vl+cRTfxqDWAdaYVmsvD0wqb2XesKcbCLoG19cHr8TGCB7slCMfbSUQp9uKHJ7JR cjaO64yXvibOlJ4Cj4ic1Uk2l4XYdhXWNUKrcUnpHjbe94ks7NRfk4r/b4/A6vMOXqIK rRVYa3z3yz9pl4UyUC5XvlmYFyRIQhvRQRE6Y/ZbYBSdfdrVzR9+X9UGHuPMdEm9IAzV h9CeAW3BOSH5uHBlPC/m2UcKB17BxOmvoNNXt6QYP+OAyOLgIwpPirZkM04qgQpn4+LZ 9PRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=jMOd9W8O; 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 ha25si11867344ejb.180.2020.06.16.14.31.00; Tue, 16 Jun 2020 14:31:22 -0700 (PDT) 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=jMOd9W8O; 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 S1726384AbgFPV0p (ORCPT + 99 others); Tue, 16 Jun 2020 17:26:45 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:56738 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725967AbgFPV0o (ORCPT ); Tue, 16 Jun 2020 17:26:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592342803; 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; bh=rfjyihg61U3ImXhyN/RZdOnqUBmVbpAphX1IIssGqq4=; b=jMOd9W8OZVUfbqdp/+zCeeWqPtazUN7tG6pOiknb4fD1/E5QRuM6T6f/m763lDxLnAxDBp I0QZlK0UcrEnLSPT/U2dHPs6mWSGwYBPIeTr562K43AzYylteLw5cZt4JusRdh9y3RnnW9 XQrbs5OMYc3KKDLlRlNESBi3y4jtUEg= 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-140-iB73ybuIMlKdSBblkDt8xw-1; Tue, 16 Jun 2020 17:26:41 -0400 X-MC-Unique: iB73ybuIMlKdSBblkDt8xw-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 853891512E0; Tue, 16 Jun 2020 21:26:40 +0000 (UTC) Received: from gimli.home (ovpn-112-195.phx2.redhat.com [10.3.112.195]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3C52A5D9D3; Tue, 16 Jun 2020 21:26:37 +0000 (UTC) Subject: [PATCH] vfio/pci: Clear error and request eventfd ctx after releasing From: Alex Williamson To: alex.williamson@redhat.com Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, cohuck@redhat.com, dwagner@suse.de, cai@lca.pw Date: Tue, 16 Jun 2020 15:26:36 -0600 Message-ID: <159234276956.31057.6902954364435481688.stgit@gimli.home> User-Agent: StGit/0.19-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The next use of the device will generate an underflow from the stale reference. Cc: Qian Cai Fixes: 1518ac272e78 ("vfio/pci: fix memory leaks of eventfd ctx") Reported-by: Daniel Wagner Signed-off-by: Alex Williamson --- drivers/vfio/pci/vfio_pci.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index 7c0779018b1b..f634c81998bb 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -521,10 +521,14 @@ static void vfio_pci_release(void *device_data) vfio_pci_vf_token_user_add(vdev, -1); vfio_spapr_pci_eeh_release(vdev->pdev); vfio_pci_disable(vdev); - if (vdev->err_trigger) + if (vdev->err_trigger) { eventfd_ctx_put(vdev->err_trigger); - if (vdev->req_trigger) + vdev->err_trigger = NULL; + } + if (vdev->req_trigger) { eventfd_ctx_put(vdev->req_trigger); + vdev->req_trigger = NULL; + } } mutex_unlock(&vdev->reflck->lock);