From patchwork Wed Jul 3 14:46:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varad Gautam X-Patchwork-Id: 11029695 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D9A1113BD for ; Wed, 3 Jul 2019 14:48:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C9069285AA for ; Wed, 3 Jul 2019 14:48:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BA95B287A6; Wed, 3 Jul 2019 14:48:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_ADSP_ALL, DKIM_INVALID,DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 53CF628756 for ; Wed, 3 Jul 2019 14:48:25 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1higWs-0005ku-Kj; Wed, 03 Jul 2019 14:46:38 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1higWr-0005kp-D2 for xen-devel@lists.xenproject.org; Wed, 03 Jul 2019 14:46:37 +0000 X-Inumbo-ID: 5b32ffac-9da1-11e9-97f4-5f158e500e76 Received: from smtp-fw-9102.amazon.com (unknown [207.171.184.29]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5b32ffac-9da1-11e9-97f4-5f158e500e76; Wed, 03 Jul 2019 14:46:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1562165196; x=1593701196; h=from:to:cc:subject:date:message-id:mime-version; bh=Ln69/s8NSRPhwQRZBcMhq/68rXIZpwIKGbrRxJCQ65Q=; b=Lr825ynFohx1X5BVKj4ypynSH0pBMVrRN1uu+VBhXfrihB2zviY+Tblp FwE0us6/bB4Xp05hIQibALsLY6kSPmF4cPVtz5lp3Pu9/8BJuHPRGuyRC w35tbvGMpHMED4RuxJWMqDxqnUYD0rKkvAfaWY47e20ouulQFQO/AJXjw g=; X-IronPort-AV: E=Sophos;i="5.62,446,1554768000"; d="scan'208";a="683543398" Received: from sea3-co-svc-lb6-vlan2.sea.amazon.com (HELO email-inbound-relay-1a-715bee71.us-east-1.amazon.com) ([10.47.22.34]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 03 Jul 2019 14:46:33 +0000 Received: from EX13MTAUEA001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1a-715bee71.us-east-1.amazon.com (Postfix) with ESMTPS id 44F28A23CA; Wed, 3 Jul 2019 14:46:31 +0000 (UTC) Received: from EX13D08UEE004.ant.amazon.com (10.43.62.182) by EX13MTAUEA001.ant.amazon.com (10.43.61.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 3 Jul 2019 14:46:31 +0000 Received: from EX13MTAUWC001.ant.amazon.com (10.43.162.135) by EX13D08UEE004.ant.amazon.com (10.43.62.182) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 3 Jul 2019 14:46:31 +0000 Received: from u908889d5e8f057.ant.amazon.com (10.28.86.21) by mail-relay.amazon.com (10.43.162.232) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Wed, 3 Jul 2019 14:46:28 +0000 From: Varad Gautam To: Date: Wed, 3 Jul 2019 16:46:13 +0200 Message-ID: <1562165173-31383-1-git-send-email-vrd@amazon.de> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH] x86: irq: Do not BUG_ON multiple unbind calls for shared pirqs X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Andrew Cooper , Varad Gautam , Jan Beulich , Amit Shah , David Woodhouse , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP It is possible to receive multiple __pirq_guest_unbind calls for the same pirq if the pirq has not yet been removed from the domain's pirq_tree. For a shared pirq (nr_guests > 1), the first call zaps the current domain from the pirq's guests[] list, but the action handler is never freed as there are other guests using this pirq. As a result, on the second call, __pirq_guest_unbind tries search for the current domain which has been removed from the guests[] list, and hits a BUG_ON. Allow xen to continue if a shared pirq has already been unbound from this guest. It will be cleaned up from the domain's pirq_tree during the destruction in complete_domain_destroy. Signed-off-by: Varad Gautam --- To apply stable-4.11 onwards. xen/arch/x86/irq.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/irq.c b/xen/arch/x86/irq.c index 094c3c5..256f503 100644 --- a/xen/arch/x86/irq.c +++ b/xen/arch/x86/irq.c @@ -1711,7 +1711,15 @@ static irq_guest_action_t *__pirq_guest_unbind( for ( i = 0; (i < action->nr_guests) && (action->guest[i] != d); i++ ) continue; - BUG_ON(i == action->nr_guests); + if ( i == action->nr_guests ) { + /* In case the pirq was shared, unbound for this domain in an earlier call, but still + * existed on the domain's pirq_tree, we still reach here if there are any later + * unbind calls on the same pirq. Return if such an unbind happens. */ + if ( action->nr_guests > 0 && action->shareable ) + return NULL; + BUG(); + } + memmove(&action->guest[i], &action->guest[i+1], (action->nr_guests-i-1) * sizeof(action->guest[0])); action->nr_guests--;