Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1689700pxb; Thu, 16 Sep 2021 13:03:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvOgCweIss8wycnLFS92AX5H8uucdQsA+h3KdJ9lD79sDPsXN7HbYWbHPFI+dKPgCJe1w9 X-Received: by 2002:a05:6638:2104:: with SMTP id n4mr5778926jaj.111.1631822628808; Thu, 16 Sep 2021 13:03:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631822628; cv=none; d=google.com; s=arc-20160816; b=G8X0q/cUsKghM+uzIzlhMkpD25J7W6cuJY4M8X+ZMdE3sSoniOm6e9MnguQIyag9jN 2xvMBUyz9kJw21VW1e08Hf5QGhsZh+SGarsCPbU4ro9L9AZcHLWKJYR67mlSCwTXrcfp MRh8iHn7meuu6nP8joGKs477JgPL+RW8XlUYdh38SR3f6AqCKmvRy69H8qV/PTMteUou 6048S1w21pTMFWPt3UofRtm92fRkzP7Fb8CVsGEzL4U6OVHvpruo+VK4oQeJoqYiXT+z fZzQneYPnfltSbD1dzYVGskybbcHs9UgAiaeyrmbngQ4Frz52RwkjhnZ5+lRK2qzdgbz bQRg== 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=0VnZ/dD+hEkbUD84iN8zTt1TsLPe/052HqMdXpvmBP8=; b=dJtw1ftflcVio0HuuxHII928WPD4UYA8sAuNk7IGpG4uPJU6BfoK1nr1bZwe5d1sxa U/xshr8r0zHHiRnpSEt4N2RXgHQwCfUNZZ0AsIZJR2Y2wKL5d2YkxwoCzeQzfrRi3zRJ /xmja8srnbQ0EVbmKjjKz9Ya7hBzvcn9A+V8IC6i5iGKLQ100KOZ90v871HsJ7a1OF/Y hK9Is5ulYLY8D/wKRXtvYpcOXfdzCY9JdhMlx98bsQpYOPZPDB1wI2V/A1r6qJochS4x YZYssNsA52yAGkOTWogatsf/cwNzdYR5+so2vrcx0tTy5Htr4br8afqBU11vyKiAYPQU F9og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kU9IF+8t; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i9si3178574ilc.6.2021.09.16.13.03.33; Thu, 16 Sep 2021 13:03:48 -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=@linuxfoundation.org header.s=korg header.b=kU9IF+8t; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229958AbhIPQNA (ORCPT + 99 others); Thu, 16 Sep 2021 12:13:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:47724 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233356AbhIPQHr (ORCPT ); Thu, 16 Sep 2021 12:07:47 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id ADBBE6128B; Thu, 16 Sep 2021 16:06:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631808386; bh=Provur/kTKor3eJ8ubsXl60qaewRSFXzCPYiNMZd6NU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kU9IF+8ttm5PMK+QTkHXlYwpGuzswAP9jn/Bu5x407+U2lHcTz2KOKABQJH1PZcKG Q+f5ZVeb6Y4MGBz1E1JQPu9zy1eJqHkQAavjkJ22l1lNYhSf7WoJ9UQSLuiQOJxmG2 JjgRrpEIULKO8FlDRUy/cIXOmwcYI+tdHkXVe1TY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Julian Wiedmann , Benjamin Block , Heiko Carstens Subject: [PATCH 5.10 039/306] s390/qdio: fix roll-back after timeout on ESTABLISH ccw Date: Thu, 16 Sep 2021 17:56:24 +0200 Message-Id: <20210916155755.281231312@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155753.903069397@linuxfoundation.org> References: <20210916155753.903069397@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: Julian Wiedmann commit 2c197870e4701610ec3b1143808d4e31152caf30 upstream. When qdio_establish() times out while waiting for the ESTABLISH ccw to complete, it calls qdio_shutdown() to roll back all of its previous actions. But at this point the qdio_irq's state is still QDIO_IRQ_STATE_INACTIVE, so qdio_shutdown() will exit immediately without doing any actual work. Which means that eg. the qdio_irq's thinint-indicator stays registered, and cdev->handler isn't restored to its old value. And since commit 954d6235be41 ("s390/qdio: make thinint registration symmetric") the qdio_irq also stays on the tiq_list, so on the next qdio_establish() we might get a helpful BUG from the list-debugging code: ... [ 4633.512591] list_add double add: new=00000000005a4110, prev=00000001b357db78, next=00000000005a4110. [ 4633.512621] ------------[ cut here ]------------ [ 4633.512623] kernel BUG at lib/list_debug.c:29! ... [ 4633.512796] [<00000001b2c6ee9a>] __list_add_valid+0x82/0xa0 [ 4633.512798] ([<00000001b2c6ee96>] __list_add_valid+0x7e/0xa0) [ 4633.512800] [<00000001b2fcecce>] qdio_establish_thinint+0x116/0x190 [ 4633.512805] [<00000001b2fcbe58>] qdio_establish+0x128/0x498 ... Fix this by extracting a goto-chain from the existing error exits in qdio_establish(), and check the return value of the wait_event_...() to detect the timeout condition. Fixes: 779e6e1c724d ("[S390] qdio: new qdio driver.") Root-caused-by: Benjamin Block Signed-off-by: Julian Wiedmann Reviewed-by: Benjamin Block Cc: # 2.6.27 Signed-off-by: Heiko Carstens Signed-off-by: Greg Kroah-Hartman --- drivers/s390/cio/qdio_main.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) --- a/drivers/s390/cio/qdio_main.c +++ b/drivers/s390/cio/qdio_main.c @@ -1243,6 +1243,7 @@ int qdio_establish(struct ccw_device *cd { struct qdio_irq *irq_ptr = cdev->private->qdio_data; struct subchannel_id schid; + long timeout; int rc; ccw_device_get_schid(cdev, &schid); @@ -1268,11 +1269,8 @@ int qdio_establish(struct ccw_device *cd qdio_setup_irq(irq_ptr, init_data); rc = qdio_establish_thinint(irq_ptr); - if (rc) { - qdio_shutdown_irq(irq_ptr); - mutex_unlock(&irq_ptr->setup_mutex); - return rc; - } + if (rc) + goto err_thinint; /* establish q */ irq_ptr->ccw.cmd_code = irq_ptr->equeue.cmd; @@ -1288,15 +1286,16 @@ int qdio_establish(struct ccw_device *cd if (rc) { DBF_ERROR("%4x est IO ERR", irq_ptr->schid.sch_no); DBF_ERROR("rc:%4x", rc); - qdio_shutdown_thinint(irq_ptr); - qdio_shutdown_irq(irq_ptr); - mutex_unlock(&irq_ptr->setup_mutex); - return rc; + goto err_ccw_start; } - wait_event_interruptible_timeout(cdev->private->wait_q, - irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED || - irq_ptr->state == QDIO_IRQ_STATE_ERR, HZ); + timeout = wait_event_interruptible_timeout(cdev->private->wait_q, + irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED || + irq_ptr->state == QDIO_IRQ_STATE_ERR, HZ); + if (timeout <= 0) { + rc = (timeout == -ERESTARTSYS) ? -EINTR : -ETIME; + goto err_ccw_timeout; + } if (irq_ptr->state != QDIO_IRQ_STATE_ESTABLISHED) { mutex_unlock(&irq_ptr->setup_mutex); @@ -1315,6 +1314,14 @@ int qdio_establish(struct ccw_device *cd qdio_print_subchannel_info(irq_ptr); qdio_setup_debug_entries(irq_ptr); return 0; + +err_ccw_timeout: +err_ccw_start: + qdio_shutdown_thinint(irq_ptr); +err_thinint: + qdio_shutdown_irq(irq_ptr); + mutex_unlock(&irq_ptr->setup_mutex); + return rc; } EXPORT_SYMBOL_GPL(qdio_establish);