Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1652265imm; Thu, 14 Jun 2018 01:22:53 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIW3h5MpeDBeDBApP7I9skGt91T4mvRvROSpuYgOegJ9QYPp3M6aJ7TAZaqiDPDCwtp2R9j X-Received: by 2002:a65:611a:: with SMTP id z26-v6mr1422224pgu.61.1528964573353; Thu, 14 Jun 2018 01:22:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528964573; cv=none; d=google.com; s=arc-20160816; b=R6xpiYlBsC6s3YPpp4JttP/nSl/CM3IohKL3CPLPUEL5dSiuqhVfRw9xJeVs+V74x8 7jdrhP8jq9AN70Yy2XVNgkMI0zwTE9MODDkHWJUhDB6R2Y135HLYwG+akXFxDsVU97vl xpLMAuqv660flndIiWJQbb61g9sCELtQu6Q1PeWAjX2dIic6an3CgyUjIiu5AnSSPg0u mQ9Fg4MZY2YlR+Q7/03A1zcQF5GIaKzoR0Ka4rstt/s+0JgfcqEBJfGtiwtaHQxmQi6Z 44yf0vPx52haZI/0NE+FQ5ncvetW+f+V0pTJAN3o3jpPPkhVHWYzWdfk+9PA0i9OtJ/H hhUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date :arc-authentication-results; bh=eqOHEoLDszciBUMh+I1ZdE7EwV5MGQN6Il+zL7syFB0=; b=lHHdaHtpmqvwy1th9QcHkiczbwvVrS3nrfjthGK6DGfKxDpjjw8Z3XZTSS+cMgDyqO uDAMHKUROArFpyYaCGyzT1gLB0mt9rUmbfHDhHiNUKLhp3pB2eSoLHCJl/Lvw6vPQKu5 2CjwlThq/KXfTe6naDkmvlR53jig3vEEl/Ft0Q/deASCXqKKfuef1RT+WWtn7qh+wsWa bjZ+L6cTaOYEqOt5FbrFmjM7WAq/rc+YoL9s0M9glGucA1d3znEye8+Hz8Yn81DdNalQ xjbDELKFB3rtNj/ONTX827xBdfJ4usfPTj7VEm1Fa8z4fggixkl4jk4XoGOQfj3GdZkt wYIg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e88-v6si5026165pfk.198.2018.06.14.01.22.39; Thu, 14 Jun 2018 01:22:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754817AbeFNIWE (ORCPT + 99 others); Thu, 14 Jun 2018 04:22:04 -0400 Received: from smtp.ctxuk.citrix.com ([185.25.65.24]:8068 "EHLO SMTP.EU.CITRIX.COM" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752876AbeFNIWC (ORCPT ); Thu, 14 Jun 2018 04:22:02 -0400 X-IronPort-AV: E=Sophos;i="5.51,222,1526342400"; d="scan'208";a="74640716" Date: Thu, 14 Jun 2018 10:21:54 +0200 From: Roger Pau =?utf-8?B?TW9ubsOp?= To: Ben Hutchings CC: Greg Kroah-Hartman , LKML , stable , Hooman Mirhadi , Amit Shah , Boris Ostrovsky , Juergen Gross , Sasha Levin Subject: Re: [PATCH 4.4 119/268] xen/pirq: fix error path cleanup when binding MSIs Message-ID: <20180614082154.froqupxpmory2f4i@mac.bytemobile.com> References: <1528914431.2289.163.camel@citrix.com> <1528915730.2289.166.camel@codethink.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1528915730.2289.166.camel@codethink.co.uk> User-Agent: NeoMutt/20180512 X-ClientProxiedBy: AMSPEX02CAS01.citrite.net (10.69.22.112) To AMSPEX02CL02.citrite.net (10.69.22.126) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 13, 2018 at 07:48:50PM +0100, Ben Hutchings wrote: > On Wed, 2018-02-28 at 09:19 +0000, Roger Pau Monne wrote: > > From: Roger Pau Monne > > > > [ Upstream commit 910f8befdf5bccf25287d9f1743e3e546bcb7ce0 ] > > > > Current cleanup in the error path of xen_bind_pirq_msi_to_irq is > > wrong. First of all there's an off-by-one in the cleanup loop, which > > can lead to unbinding wrong IRQs. > > > > Secondly IRQs not bound won't be freed, thus leaking IRQ numbers. > > > > Note that there's no need to differentiate between bound and unbound > > IRQs when freeing them, __unbind_from_irq will deal with both of them > > correctly. > > It appears to me that it is safe to call __unbind_from_irq() after > xen_irq_info_common_setup() fails, but *not* if the latter hasn't been > called at all. In that case the IRQ type will still be set to > IRQT_UNBOUND and this will trigger the BUG_ON() in __unbind_from_irq(). > > [...] > > --- a/drivers/xen/events/events_base.c > > +++ b/drivers/xen/events/events_base.c > > @@ -764,8 +764,8 @@ out: > > ? mutex_unlock(&irq_mapping_update_lock); > > ? return irq; > > ?error_irq: > > - for (; i >= 0; i--) > > - __unbind_from_irq(irq + i); > > + while (nvec--) > > + __unbind_from_irq(irq + nvec); > > If nvec > 1, and xen_irq_info_pirq_setup() fails for i != nvec - 1, > then we reach here without having called xen_irq_info_common_setup() > for all these IRQs. > > In that case, I think we will still want to call xen_free_irq() for all > IRQs. So maybe the fix would be to remove the BUG_ON() in > __unbind_from_irq()? I think your analysis is right, and I agree that removing the BUG_ON from __unbind_from_irq seems like the right solution. I can't see any issues from calling xen_free_irq with type == IRQT_UNBOUND, but I've already attempted to fix this once and failed, so I would like to get second opinions. Also I'm not sure of the reason behind that BUG_ON. Roger.