Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp475978pxx; Wed, 28 Oct 2020 09:10:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz82ajmTYEaceVxwSoC7kS74mbojc6hcfE1wX6jQCpgoPV58zLdo726SMj4ODPYJUp88Tyg X-Received: by 2002:a17:906:f24b:: with SMTP id gy11mr8500705ejb.371.1603901452063; Wed, 28 Oct 2020 09:10:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603901452; cv=none; d=google.com; s=arc-20160816; b=S5WztvGFY6AJL5akQ2bVzlzp1nVeVGgE9mb53iVcoz34z/0L/LEeNGTInAMxUgMq8N woNYmm17VuUM7r7Dn/GPXTzMW/ZkNviKiUzW3tDhSqKqzwbddnuAMbsrWgoIpKHM6ors BviCR1tOU82dkIVeCtJjlIMp90ZmCVxWew4mowZXKGk+NqtW677LNkH32DsbJTLF36J7 T8Wh3B5puB42lC7UNW1mkJxScoHrHavjPbCBjWRft4Bd0KCAuGmWmbOzFKMq4Mp3k6ad HX4tXexwtHecad0LPhRdaBugqH2LUm3RgIGa72/HhtbgbPe09xUmg4gJOuNMM0qc1asg GJ0g== 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=qph0izQjGj7Ok6qbwksZCjJcZKUxo/wolicMqv9ULEU=; b=Exc8DKfLO62gmvYxb/oaq/nacX0E57oYFXAK0jNfExUfjT6/xyyDeqrY2k2e5qdsfs UHA3pBt5hFMi7W8kQk6N7Lj0og+vHMR8QlK4lcW99BkjHqf4nWoj4aqaM8KZQB3Fd5lq QNzh8Q6MxK6ODSmJYQkUNuFuC3UXzruYWTdGWajpCLQNF8k/2HacEKyEzbJOx5iIp2Wv dRhZLmvgGQ6QWDj2PSNO8ftmOL6GBLbNtPNF6E0etRcOVP1U1bCJhkVNc6m92ZqVWTBO nGe8tmbfFwsDPlXMT3bH9jWmeQv7NvCKMfe9IRvZiY0yRSV5hFhb1wf5/2WzM/73+V7h GbVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dpBk5a3m; 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 i26si3622017edq.25.2020.10.28.09.10.26; Wed, 28 Oct 2020 09:10:52 -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=dpBk5a3m; 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 S1814954AbgJ0RAs (ORCPT + 99 others); Tue, 27 Oct 2020 13:00:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:44546 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1793922AbgJ0PJH (ORCPT ); Tue, 27 Oct 2020 11:09:07 -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 E606420657; Tue, 27 Oct 2020 15:09:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603811346; bh=i9pwAcbMBFwVFvTsy6gwZlshudc99nSg7f/5QAsJM/4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dpBk5a3mN+3a1HHmpJbF9F5zpl2YVS8r5ZbOwm6tmHd3i34+LEd65DW8y0LzpKJQZ 1s3ZzUtkDf/0uyCjmsyH4bHZDUeKRzEeBDvCWNob9rUuFEB7aopsrBkrb1/2a2hlOx XltR63fLsMlhS5j3VA9Dm1AvkSX+JEk2vjwwptyo= 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 5.8 461/633] vfio/pci: Clear token on bypass registration failure Date: Tue, 27 Oct 2020 14:53:24 +0100 Message-Id: <20201027135544.350637604@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135522.655719020@linuxfoundation.org> References: <20201027135522.655719020@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 1d9fb25929459..869dce5f134dd 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c @@ -352,11 +352,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