Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp854107pxk; Thu, 17 Sep 2020 19:10:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwfLY5ETcf5kZwMfC/oUL8lfzprI4ZUmRh+E0jUN+hPO1xpCpFp1xG9/aqq1BJZ3F6D13R X-Received: by 2002:aa7:ce97:: with SMTP id y23mr37242144edv.128.1600395006000; Thu, 17 Sep 2020 19:10:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600395005; cv=none; d=google.com; s=arc-20160816; b=jF+vJLFUMSOdE2mhdK/lRDpoZg4Dz+13dRowVtHlVwMDJOvC9GvJcuJ3bE1n0GQ1EM oxqN9+yZuEepEu2oh1YNIsQ6HMoYQRiJqfJgej5A49PWPB3PV4XBhfv8vkX/oCDeaKML AsOOvfRZnIp8LqHDUjhsiCBwtiGgh0crAFww59fuph+p3Dz0vJkEe2SYdOOfslf+XyZQ No3QV46920I6S2+XsuBAUOjACF5u5L/Y6ywJdaQRmZmmBpKxh6ZllQedE6epbZQjqVBU P+oi9JNg3fQUzXwmpaawrVzzn5LQSPdVeWD+Pp1AGXS2aWCCt4JkQxP+yUGMyLKOQ5dr br8A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=A3AN2PoHm0fpFrvdbiAC1iWA3bq3VxsLyLM1hGe6QMQ=; b=R2eXXC5LvFXAXuyMTqo+5KEHvdJl2bLdFTaE9Q6fjCZQDLAq8HLJ4xXL6YYkmk4S5l 2Blys9ppa/Xa5fbh27HplnIfI4h9AsNlqYSJU4pow7UO74kjFOfjrTS51/DR/waLHm0X OBUoWxESxOSRmnPNMxNd1A6r8YT+MK0ooK+ytAJhYsQTelI9MT+NtQoAj98N72lQ1Xg2 RkqYkmP99e63TqT2kPE41y7+EHIdDyUXnihJnPtnDqxzB7mewPSzVl484ryTTKVVm7kZ aE9zcKIzUI6GltDgyn4NCvxd64VMQJWJ370l9nvlJztws4aRCfV64WEcE8Fbl+NKF6oO WJsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="xn0/gFMl"; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g3si1061621edq.113.2020.09.17.19.09.42; Thu, 17 Sep 2020 19:10:05 -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=@kernel.org header.s=default header.b="xn0/gFMl"; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727331AbgIRCHt (ORCPT + 99 others); Thu, 17 Sep 2020 22:07:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:58126 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727966AbgIRCHi (ORCPT ); Thu, 17 Sep 2020 22:07:38 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4D49223770; Fri, 18 Sep 2020 02:07:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394858; bh=yGyQvtcrzzOsuLns5qoWHAXVBcKYt/j9EFNRVIfjoHU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xn0/gFMlDc1i4iHGMaZE8siBoKCz2jvRK9P8ls88uXW/9r4pjaqvFXOa8j/4lhq01 FXbwY+Sp7hQBNA+H1w32q1wLZGsGqNmAThB905VoB8HHznye3Kgy2i04ULTbaUG96g HW7DLewacFvml6D7bsvjlFo459A0Qbe+peyQx6lw= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Alex Williamson , Qian Cai , Daniel Wagner , Cornelia Huck , Sasha Levin , kvm@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 312/330] vfio/pci: Clear error and request eventfd ctx after releasing Date: Thu, 17 Sep 2020 22:00:52 -0400 Message-Id: <20200918020110.2063155-312-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alex Williamson [ Upstream commit 5c5866c593bbd444d0339ede6a8fb5f14ff66d72 ] 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 Reviewed-by: Cornelia Huck Tested-by: Daniel Wagner Signed-off-by: Alex Williamson Signed-off-by: Sasha Levin --- 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 12f7691e8b6ca..b669be5a20066 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -474,10 +474,14 @@ static void vfio_pci_release(void *device_data) if (!(--vdev->refcnt)) { 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); -- 2.25.1