Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp4123555ybe; Mon, 9 Sep 2019 04:43:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqy+xM5DeO8VMsgKJq+hMa6DbTH00uyRoL4Nb4FyMcZC0ppzZbcAY18QuqZKyw085UN5XKy+ X-Received: by 2002:a17:906:1317:: with SMTP id w23mr18728608ejb.312.1568029396433; Mon, 09 Sep 2019 04:43:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568029396; cv=none; d=google.com; s=arc-20160816; b=Gn5zujpSCS1W5Yqeuulp3I9XNOMCXo62KUhJEs+WuFTxsXRc0XPhB/l+Q09cL8XZJL HLbn6tksBVrui5Ky4ZImwQcQ7DJqe8Aqp5VYDA986Xr8t6yUI4Q6e/XbB78ozDrCnos2 zA5Hjp1IozPigZL/Ox0fU/7kpW/4mcl3QZlRI8AoNnMelrvsDlJvttziGMV81tmn0p+x J/T1U2rTRuRotMPbhhuTx3fchZZmoDayJYI5qYQDlPb7KxAKZz3/HWSnyAfNDfdfTaD0 GKiB9Ox1D1tzZKnlhM3esDkPBPFh41jGK6uyaprq+y+ihthbKbl4oK50qFBQpMFWCBLP s2tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8mT7/tA5vH6KzD8Qvl7r+I4qKjysYGMTJoYFqfzn+nI=; b=ZA56BI1x3MlmwwZUSzR5blsQLGcQRSEwZ+HPVUlQd94QdOt8cOvphwIaSP6KAvrbZA h4E4CVBGJ4AAszui6+3Xb//9T3wpChGdHIRt6Zs57uqZjvOCQMXFM7TQ2a235/+iwp+s R5zFLmLGM7WW2cmJEuXdgPf9u49UfKj8kIEwGVBSn3ef66oIfD+xPBI8pe3rP3gA9jKt YeJ/jH2azI2yTUTGlyDbPQY8RzDD/i+KtY+6+bZIarxXd/JXZ3zjSTi8LVaPWDViF1D1 PLqzxTlWbC1E55JFj+GDggIxfzE3paxXz/4oHFAKbHqCJ+KUlL03Zx66EloW+YxShW+6 YDCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=G0qXX3ut; 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 w27si8545310edd.84.2019.09.09.04.42.52; Mon, 09 Sep 2019 04:43:16 -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; dkim=pass header.i=@kernel.org header.s=default header.b=G0qXX3ut; 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 S1732338AbfIHMuv (ORCPT + 99 others); Sun, 8 Sep 2019 08:50:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:41832 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732280AbfIHMus (ORCPT ); Sun, 8 Sep 2019 08:50:48 -0400 Received: from localhost (unknown [62.28.240.114]) (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 1C29A2196F; Sun, 8 Sep 2019 12:50:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567947045; bh=gLSeBiYtRW05Fgp8Wur43XLorR7RRR+t7EZkK1UFHcI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G0qXX3utMDzh4t8i/4irVz0MjMor0o0S8OuT7GEp2MYHj0scQ8vTczPIzgBVfGtsI XY5NXO/sSZ0KLIb0MuWStXRP+vfI8cZxBOCNUPJhSxm/gA7U6T1qJihEC+5bm3SSCX deEcGwWz4oI0a7pLq7r+NPivJFZSZ+UNKb+ypDjM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Julian Wiedmann , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.2 39/94] s390/qeth: serialize cmd reply with concurrent timeout Date: Sun, 8 Sep 2019 13:41:35 +0100 Message-Id: <20190908121151.557585474@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190908121150.420989666@linuxfoundation.org> References: <20190908121150.420989666@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 072f79400032f74917726cf76f4248367ea2b5b8 ] Callbacks for a cmd reply run outside the protection of card->lock, to allow for additional cmds to be issued & enqueued in parallel. When qeth_send_control_data() bails out for a cmd without having received a reply (eg. due to timeout), its callback may concurrently be processing a reply that just arrived. In this case, the callback potentially accesses a stale reply->reply_param area that eg. was on-stack and has already been released. To avoid this race, add some locking so that qeth_send_control_data() can (1) wait for a concurrently running callback, and (2) zap any pending callback that still wants to run. Signed-off-by: Julian Wiedmann Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/s390/net/qeth_core.h | 1 + drivers/s390/net/qeth_core_main.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/drivers/s390/net/qeth_core.h b/drivers/s390/net/qeth_core.h index 784a2e76a1b04..c5f60f95e8db9 100644 --- a/drivers/s390/net/qeth_core.h +++ b/drivers/s390/net/qeth_core.h @@ -640,6 +640,7 @@ struct qeth_seqno { struct qeth_reply { struct list_head list; struct completion received; + spinlock_t lock; int (*callback)(struct qeth_card *, struct qeth_reply *, unsigned long); u32 seqno; diff --git a/drivers/s390/net/qeth_core_main.c b/drivers/s390/net/qeth_core_main.c index b1823d75dd35c..6b8f99e7d8a81 100644 --- a/drivers/s390/net/qeth_core_main.c +++ b/drivers/s390/net/qeth_core_main.c @@ -548,6 +548,7 @@ static struct qeth_reply *qeth_alloc_reply(struct qeth_card *card) if (reply) { refcount_set(&reply->refcnt, 1); init_completion(&reply->received); + spin_lock_init(&reply->lock); } return reply; } @@ -832,6 +833,13 @@ static void qeth_issue_next_read_cb(struct qeth_card *card, if (!reply->callback) { rc = 0; + goto no_callback; + } + + spin_lock_irqsave(&reply->lock, flags); + if (reply->rc) { + /* Bail out when the requestor has already left: */ + rc = reply->rc; } else { if (cmd) { reply->offset = (u16)((char *)cmd - (char *)iob->data); @@ -840,7 +848,9 @@ static void qeth_issue_next_read_cb(struct qeth_card *card, rc = reply->callback(card, reply, (unsigned long)iob); } } + spin_unlock_irqrestore(&reply->lock, flags); +no_callback: if (rc <= 0) qeth_notify_reply(reply, rc); qeth_put_reply(reply); @@ -1880,6 +1890,16 @@ static int qeth_send_control_data(struct qeth_card *card, int len, rc = (timeout == -ERESTARTSYS) ? -EINTR : -ETIME; qeth_dequeue_reply(card, reply); + + if (reply_cb) { + /* Wait until the callback for a late reply has completed: */ + spin_lock_irq(&reply->lock); + if (rc) + /* Zap any callback that's still pending: */ + reply->rc = rc; + spin_unlock_irq(&reply->lock); + } + if (!rc) rc = reply->rc; qeth_put_reply(reply); -- 2.20.1