Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp172310pxx; Wed, 28 Oct 2020 01:32:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRFB1lxRmjBkjqartaJsID5kSvdjc3hPUMPlb7DjrFlu6Sn7K7t2M2yGvuzV7eLVhsvDYa X-Received: by 2002:a05:6402:143a:: with SMTP id c26mr6775403edx.150.1603873954051; Wed, 28 Oct 2020 01:32:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603873954; cv=none; d=google.com; s=arc-20160816; b=ye30k12h2XzqhwVygu0I0F4aNUEKiznAHJfFOYro5OiC+oOBMWUKuG2ZNqlYoLrVX4 HwEE9L91KsfjBRxW5I4rACgK/TVCR5jq2rtQE111/F9Gc8k5365gzByu+gZ3HaZnsUrk joU04CvjRQC9rcjT0cSw2N6N0poYl9XpQsJffu/gvvlcLZjzWMIrOxwyhZHkSzp8CWha gA6IN0WSi8sH9UjTiNRWtQX9OIJe96wRVIgzT6531tJ+wMA6qvICZNeBxBmzagSYxos3 962nRAl6hFP5Rcw1t4dPeJbtdDKwa1P/aD/Syd3wF/mXbTksLhZOzqQg145znY+sfAZT cUTg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=D3y5Pvr/Axctm3JEAvKalONuxrO4+b7a3effjhQyxtU=; b=b0if7JcVHhBrMY/2qhxLRI+P21ROzFcV9YyakfZZ8M2l/XUlhJJNkinepmxF8FMbrA 52fp5l7YCpIEW03GSRDHDTMHJ/8ANEyyY0LLij65miZf/NVXriR1Aeg5jIOFK67Mcvr8 5mvMnwHRLAtgmr9MBo7XgHRDZ+PPSnQgWzQwEiHIWokT5oJXPdDHM1yqTfG+hHFulNUp tWi7YmWk8hyDeX1ksyiK+ttL3WSII2f+l97iIHvOV9Wtg2Xzqfg9KL2I+4ne2Vd4TWBO QrysY1nQ4qy2xeiurRJfrxQKYafpF7Rl1RThHXFm9JhcGv1v+N7WgEyPIScE23ejyb4C nJWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=c5dHFTLw; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p19si2741759edu.169.2020.10.28.01.32.12; Wed, 28 Oct 2020 01:32:34 -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=c5dHFTLw; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754437AbgJ0OF2 (ORCPT + 99 others); Tue, 27 Oct 2020 10:05:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:53506 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754362AbgJ0OFM (ORCPT ); Tue, 27 Oct 2020 10:05:12 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4A3D522264; Tue, 27 Oct 2020 14:05:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603807511; bh=0jkClK8mVRrdFdEr2nOJ0GaA3EDBxXgPqMe58Z54eY0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c5dHFTLwtjvSvw0DmZBMzEAUEK7JwZH3AfFLlhMIfWQqahZKVV4bX4/8STb0ZekJH uRg1RBKzPgh7p6RpBo8Q2Wvsmgvnv2XdiCY7PhXGwMdt24Y3mKeC7P8dz+dQv5t2xc WvLfWwoTMycysni8qGA6Lcs9/4yT0kUNXDhVwe4s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, guomin chen , Alex Williamson , Sasha Levin Subject: [PATCH 4.9 080/139] vfio/pci: Clear token on bypass registration failure Date: Tue, 27 Oct 2020 14:49:34 +0100 Message-Id: <20201027134905.927592778@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027134902.130312227@linuxfoundation.org> References: <20201027134902.130312227@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alex Williamson [ Upstream commit 852b1beecb6ff9326f7ca4bc0fe69ae860ebdb9e ] The eventfd context is used as our irqbypass token, therefore if an eventfd is re-used, our token is the same. The irqbypass code will return an -EBUSY in this case, but we'll still attempt to unregister the producer, where if that duplicate token still exists, results in removing the wrong object. Clear the token of failed producers so that they harmlessly fall out when unregistered. Fixes: 6d7425f109d2 ("vfio: Register/unregister irq_bypass_producer") Reported-by: guomin chen Tested-by: guomin chen Signed-off-by: Alex Williamson Signed-off-by: Sasha Levin --- drivers/vfio/pci/vfio_pci_intrs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c index bdfdd506bc588..c989f777bf771 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c @@ -355,11 +355,13 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_device *vdev, vdev->ctx[vector].producer.token = trigger; vdev->ctx[vector].producer.irq = irq; ret = irq_bypass_register_producer(&vdev->ctx[vector].producer); - if (unlikely(ret)) + if (unlikely(ret)) { dev_info(&pdev->dev, "irq bypass producer (token %p) registration fails: %d\n", vdev->ctx[vector].producer.token, ret); + vdev->ctx[vector].producer.token = NULL; + } vdev->ctx[vector].trigger = trigger; return 0; -- 2.25.1