Received: by 10.223.185.111 with SMTP id b44csp906945wrg; Fri, 9 Mar 2018 16:32:40 -0800 (PST) X-Google-Smtp-Source: AG47ELtXPw0ISoUgaThmwhfw89IciznF83w+OkrpZ7tiIbEss0a2gKzbjEIfoJkABxe5AYV/6A9f X-Received: by 10.98.159.209 with SMTP id v78mr333592pfk.49.1520641960574; Fri, 09 Mar 2018 16:32:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520641960; cv=none; d=google.com; s=arc-20160816; b=KCjWP972GI94S3ERRk3Lg5Tp2Vo8EaeU+P3FDOb6t38AfZlHPPvjWNrErhPj+BCP0h n/MfQa+Ht0z2Pqf13r8xwLyOtlguDWeYXVVIABSipW8W6/UjVoYahoFbmFDn3joG2pkv 6vYeqE6eOf2pcu+nvCJi93QE2SCpzyIjV3iSksqVseEH1/5hAOxRaJo5GvXK3ZHBcEt9 d+5LhB150hE9Fh/bZjYMaP9nEdq5BbudBi31gdjn8nKyVvY/dcLgKKkoeu2XRNaG5bo6 zlCRbqQfrhqrqavuy2g5XlWs2jE+w5RWc2BO+XpukasVSN6AHl9cAZcbkfW8UR5X/X+J MkaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=1XbuzA4nOxTqL+XvVW/rEtn7zaVrXbSCeTim6MU5ouA=; b=i2QJycTYsjhquChCz0VQIRFKOsR+MTlVIt++2E2Q1u61OUlBwoqzRFfkn5e9YRwg+a 0JJA5/QPL0PCTQcr+5O4n1coQ4g1ALTrdJsx+riJkkZkH+DrS3GNfpt6ni5VYDJhO1ew /Vfpg3FARijt/BfXPXJWpkQvhIt0JuQgtAMO1n+tnKreD9MltGzR1wX6/hyFGvAVd8bH oJoH7mkToD/JuebnE590COeDzV4PcfyOCwzKUNrt0FTHFXNyGxMmYM7tStD6fCnuQLR1 xHu6ZZAShBuql1cK5geo7qXpFNFFiTVxCUstxl+unfL/gwtlyN6MsaESWh7vtceKFJTw d61g== 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 a5-v6si1714409pll.348.2018.03.09.16.32.26; Fri, 09 Mar 2018 16:32:40 -0800 (PST) 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 S1751996AbeCJAbf (ORCPT + 99 others); Fri, 9 Mar 2018 19:31:35 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:40084 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933911AbeCJAWi (ORCPT ); Fri, 9 Mar 2018 19:22:38 -0500 Received: from localhost (unknown [185.236.200.248]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id BFEB11149; Sat, 10 Mar 2018 00:22:37 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Julian Wiedmann , "David S. Miller" Subject: [PATCH 4.9 55/65] s390/qeth: fix IPA command submission race Date: Fri, 9 Mar 2018 16:18:55 -0800 Message-Id: <20180310001829.478393332@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180310001824.927996722@linuxfoundation.org> References: <20180310001824.927996722@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Julian Wiedmann [ Upstream commit d22ffb5a712f9211ffd104c38fc17cbfb1b5e2b0 ] If multiple IPA commands are build & sent out concurrently, fill_ipacmd_header() may assign a seqno value to a command that's different from what send_control_data() later assigns to this command's reply. This is due to other commands passing through send_control_data(), and incrementing card->seqno.ipa along the way. So one IPA command has no reply that's waiting for its seqno, while some other IPA command has multiple reply objects waiting for it. Only one of those waiting replies wins, and the other(s) times out and triggers a recovery via send_ipa_cmd(). Fix this by making sure that the same seqno value is assigned to a command and its reply object. Do so immediately before submitting the command & while holding the irq_pending "lock", to produce nicely ascending seqnos. As a side effect, *all* IPA commands now use a reply object that's waiting for its actual seqno. Previously, early IPA commands that were submitted while the card was still DOWN used the "catch-all" IDX seqno. Signed-off-by: Julian Wiedmann Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/s390/net/qeth_core_main.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) --- a/drivers/s390/net/qeth_core_main.c +++ b/drivers/s390/net/qeth_core_main.c @@ -2064,25 +2064,26 @@ int qeth_send_control_data(struct qeth_c } reply->callback = reply_cb; reply->param = reply_param; - if (card->state == CARD_STATE_DOWN) - reply->seqno = QETH_IDX_COMMAND_SEQNO; - else - reply->seqno = card->seqno.ipa++; + init_waitqueue_head(&reply->wait_q); - spin_lock_irqsave(&card->lock, flags); - list_add_tail(&reply->list, &card->cmd_waiter_list); - spin_unlock_irqrestore(&card->lock, flags); QETH_DBF_HEX(CTRL, 2, iob->data, QETH_DBF_CTRL_LEN); while (atomic_cmpxchg(&card->write.irq_pending, 0, 1)) ; - qeth_prepare_control_data(card, len, iob); if (IS_IPA(iob->data)) { cmd = __ipa_cmd(iob); + cmd->hdr.seqno = card->seqno.ipa++; + reply->seqno = cmd->hdr.seqno; event_timeout = QETH_IPA_TIMEOUT; } else { + reply->seqno = QETH_IDX_COMMAND_SEQNO; event_timeout = QETH_TIMEOUT; } + qeth_prepare_control_data(card, len, iob); + + spin_lock_irqsave(&card->lock, flags); + list_add_tail(&reply->list, &card->cmd_waiter_list); + spin_unlock_irqrestore(&card->lock, flags); timeout = jiffies + event_timeout; @@ -2873,7 +2874,7 @@ static void qeth_fill_ipacmd_header(stru memset(cmd, 0, sizeof(struct qeth_ipa_cmd)); cmd->hdr.command = command; cmd->hdr.initiator = IPA_CMD_INITIATOR_HOST; - cmd->hdr.seqno = card->seqno.ipa; + /* cmd->hdr.seqno is set by qeth_send_control_data() */ cmd->hdr.adapter_type = qeth_get_ipa_adp_type(card->info.link_type); cmd->hdr.rel_adapter_no = (__u8) card->info.portno; if (card->options.layer2)