From patchwork Mon Apr 10 17:44:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 97196 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp1456342obc; Mon, 10 Apr 2017 10:45:27 -0700 (PDT) X-Received: by 10.98.33.218 with SMTP id o87mr42016765pfj.11.1491846327596; Mon, 10 Apr 2017 10:45:27 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n3si14186684pfk.174.2017.04.10.10.45.27; Mon, 10 Apr 2017 10:45:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=@linaro.org; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753825AbdDJRpV (ORCPT + 5 others); Mon, 10 Apr 2017 13:45:21 -0400 Received: from mail-pf0-f173.google.com ([209.85.192.173]:35234 "EHLO mail-pf0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753529AbdDJRpR (ORCPT ); Mon, 10 Apr 2017 13:45:17 -0400 Received: by mail-pf0-f173.google.com with SMTP id i5so36615352pfc.2 for ; Mon, 10 Apr 2017 10:45:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=O5ZMlkaIfvcEEig7wX/q6RQuKeBvS50/HXi5eEGbRRc=; b=baQUJl6mcVQEVWdFn4kz28qg1Vf7p7s7ViqVr/R5ZsPLCWBOgLkeaAmt//XlrPbx9E lsUMZdR3YUYhNah1vDWcEAxA2kjoxdcVSW4w0aPVw0Pv3CCGn4VfEh5KzTNjUXulR8Nb rrLnW1byQX/OgMxy83XIGktmJ4JPD8Wx8jO60= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=O5ZMlkaIfvcEEig7wX/q6RQuKeBvS50/HXi5eEGbRRc=; b=dnGsVQD/sTmnbk+ygp9HpwsgaA28ca8p8/P8Jb4zW4o+0DffDAajqGXIzTLTRtlrbo tKIyanzIUkWCJA4uB4m8d4rzEVuhcTgKR3R3sbN3xnWuquKibKtnm+KjsHyjWAGGTKlN w0Y8EVJjjo2EsXLiDSqQCQSfQTDfBn00y8XLQJHPEu3uXRGBipefMkPgglcEJcRWQktz lVL74DjKURPI9DnotDIlE3G9phY72yZWQhOqsOdcG8h9qFhuTbkDfOrExzpWT8FRbbHy /YXy0mzsKDvHjB06DYf/a+5Ap412+hGbB1ZP8y5NvbZaaTTQeFkkhc40PO4vNF3Jlrm8 Hnvw== X-Gm-Message-State: AFeK/H29F9REBoGXyZXFNySln1CkDa0Zy25OHHqpMAy9HeVlNoDfxBVO0CUOXYpGLLH8jSnz X-Received: by 10.98.141.67 with SMTP id z64mr52685486pfd.91.1491846311399; Mon, 10 Apr 2017 10:45:11 -0700 (PDT) Received: from phantom.lan ([106.51.225.38]) by smtp.gmail.com with ESMTPSA id y6sm768833pfa.83.2017.04.10.10.45.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Apr 2017 10:45:09 -0700 (PDT) From: Sumit Semwal To: stable@vger.kernel.org Cc: Jack Morgenstein , Tariq Toukan , "David S . Miller" , Sumit Semwal Subject: [PATCH for-4.4 01/16] net/mlx4_core: Fix when to save some qp context flags for dynamic VST to VGT transitions Date: Mon, 10 Apr 2017 23:14:17 +0530 Message-Id: <1491846272-14882-2-git-send-email-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1491846272-14882-1-git-send-email-sumit.semwal@linaro.org> References: <1491846272-14882-1-git-send-email-sumit.semwal@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Jack Morgenstein [Upstream commit 61a4577c9a4419b99e647744923517d47255da35] Save the qp context flags byte containing the flag disabling vlan stripping in the RESET to INIT qp transition, rather than in the INIT to RTR transition. Per the firmware spec, the flags in this byte are active in the RESET to INIT transition. As a result of saving the flags in the incorrect qp transition, when switching dynamically from VGT to VST and back to VGT, the vlan remained stripped (as is required for VST) and did not return to not-stripped (as is required for VGT). Fixes: f0f829bf42cd ("net/mlx4_core: Add immediate activate for VGT->VST->VGT") Signed-off-by: Jack Morgenstein Signed-off-by: Tariq Toukan Signed-off-by: David S. Miller Signed-off-by: Sumit Semwal [sumits: cherry picked for 4.4.y] --- drivers/net/ethernet/mellanox/mlx4/resource_tracker.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c b/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c index d314d96..d1fc7fa 100644 --- a/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c +++ b/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c @@ -2955,6 +2955,9 @@ int mlx4_RST2INIT_QP_wrapper(struct mlx4_dev *dev, int slave, put_res(dev, slave, srqn, RES_SRQ); qp->srq = srq; } + + /* Save param3 for dynamic changes from VST back to VGT */ + qp->param3 = qpc->param3; put_res(dev, slave, rcqn, RES_CQ); put_res(dev, slave, mtt_base, RES_MTT); res_end_move(dev, slave, RES_QP, qpn); @@ -3747,7 +3750,6 @@ int mlx4_INIT2RTR_QP_wrapper(struct mlx4_dev *dev, int slave, int qpn = vhcr->in_modifier & 0x7fffff; struct res_qp *qp; u8 orig_sched_queue; - __be32 orig_param3 = qpc->param3; u8 orig_vlan_control = qpc->pri_path.vlan_control; u8 orig_fvl_rx = qpc->pri_path.fvl_rx; u8 orig_pri_path_fl = qpc->pri_path.fl; @@ -3789,7 +3791,6 @@ out: */ if (!err) { qp->sched_queue = orig_sched_queue; - qp->param3 = orig_param3; qp->vlan_control = orig_vlan_control; qp->fvl_rx = orig_fvl_rx; qp->pri_path_fl = orig_pri_path_fl; From patchwork Mon Apr 10 17:44:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 97204 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp1456512obc; Mon, 10 Apr 2017 10:45:58 -0700 (PDT) X-Received: by 10.99.125.73 with SMTP id m9mr28468734pgn.234.1491846358225; Mon, 10 Apr 2017 10:45:58 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w21si14197944pgh.90.2017.04.10.10.45.58; Mon, 10 Apr 2017 10:45:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=@linaro.org; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752314AbdDJRpf (ORCPT + 5 others); Mon, 10 Apr 2017 13:45:35 -0400 Received: from mail-pf0-f174.google.com ([209.85.192.174]:32857 "EHLO mail-pf0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752498AbdDJRpP (ORCPT ); Mon, 10 Apr 2017 13:45:15 -0400 Received: by mail-pf0-f174.google.com with SMTP id s16so36624236pfs.0 for ; Mon, 10 Apr 2017 10:45:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CO8FrLSqiFxvilVf9YR8sleMNdKtd5xMIgKKFJD9HdQ=; b=Ca7lHGjacq7Nk2JV4QaySNea4fvcqvxNswfO2qexdVH+3ihjGO8mJlDtz+rkpcRUe+ I9w4aMp4BPhoirubDV0SiXwsMHnw77Uqu/OCEv3BROa9H63tQ1lisAKB0JTWUj/3ssZN Hx/aMxD6dH/E1k2nuF6dtuuBd5sZLDJsaJwKA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=CO8FrLSqiFxvilVf9YR8sleMNdKtd5xMIgKKFJD9HdQ=; b=Os32X0ZSjAvIztis3dSxq6wSk0hJC1ICZKjNLqA4Kx5i48qrDnr9QaPfeoLDSKelj2 IO5CTWODM48dBYIVckglOjhWakXxeslllbt8fo1jxaiqGCk4Jw0mdqKybEdnChW4+Yut 4MKIcmsa0Hu4xZAA84UJejSt6EZRkb+3qFxVe2LmWt67RzNVO9RES9WLVL6NYgGZ02nb qzT98C4fRom4bkhX/Em5UxqOEBXmc833CzzbGGSgLutNkbo2jVk1yaNmD5Rvb1AeFpA1 1Zkr7ehA7ws2pnm6Mb4AMA7madmaP7qod2vkSZmzwE8kARaU1lAiGXRjoe+0vw7eCgtc uvYg== X-Gm-Message-State: AFeK/H1OikSA3zdBueNP1Euj06P7eMDQe8XRdWsTHAET+X1kf2fN0c/VqGLueqgFeQR5b/RC X-Received: by 10.99.45.197 with SMTP id t188mr57875504pgt.209.1491846314520; Mon, 10 Apr 2017 10:45:14 -0700 (PDT) Received: from phantom.lan ([106.51.225.38]) by smtp.gmail.com with ESMTPSA id y6sm768833pfa.83.2017.04.10.10.45.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Apr 2017 10:45:13 -0700 (PDT) From: Sumit Semwal To: stable@vger.kernel.org Cc: Jack Morgenstein , Matan Barak , Tariq Toukan , "David S . Miller" , Sumit Semwal Subject: [PATCH for-4.4 02/16] net/mlx4_core: Fix racy CQ (Completion Queue) free Date: Mon, 10 Apr 2017 23:14:18 +0530 Message-Id: <1491846272-14882-3-git-send-email-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1491846272-14882-1-git-send-email-sumit.semwal@linaro.org> References: <1491846272-14882-1-git-send-email-sumit.semwal@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Jack Morgenstein [Upstream commit 291c566a28910614ce42d0ffe82196eddd6346f4] In function mlx4_cq_completion() and mlx4_cq_event(), the radix_tree_lookup requires a rcu_read_lock. This is mandatory: if another core frees the CQ, it could run the radix_tree_node_rcu_free() call_rcu() callback while its being used by the radix tree lookup function. Additionally, in function mlx4_cq_event(), since we are adding the rcu lock around the radix-tree lookup, we no longer need to take the spinlock. Also, the synchronize_irq() call for the async event eliminates the need for incrementing the cq reference count in mlx4_cq_event(). Other changes: 1. In function mlx4_cq_free(), replace spin_lock_irq with spin_lock: we no longer take this spinlock in the interrupt context. The spinlock here, therefore, simply protects against different threads simultaneously invoking mlx4_cq_free() for different cq's. 2. In function mlx4_cq_free(), we move the radix tree delete to before the synchronize_irq() calls. This guarantees that we will not access this cq during any subsequent interrupts, and therefore can safely free the CQ after the synchronize_irq calls. The rcu_read_lock in the interrupt handlers only needs to protect against corrupting the radix tree; the interrupt handlers may access the cq outside the rcu_read_lock due to the synchronize_irq calls which protect against premature freeing of the cq. 3. In function mlx4_cq_event(), we change the mlx_warn message to mlx4_dbg. 4. We leave the cq reference count mechanism in place, because it is still needed for the cq completion tasklet mechanism. Fixes: 6d90aa5cf17b ("net/mlx4_core: Make sure there are no pending async events when freeing CQ") Fixes: 225c7b1feef1 ("IB/mlx4: Add a driver Mellanox ConnectX InfiniBand adapters") Signed-off-by: Jack Morgenstein Signed-off-by: Matan Barak Signed-off-by: Tariq Toukan Signed-off-by: David S. Miller Signed-off-by: Sumit Semwal [sumits: cherry-picked for 4.4.y] --- drivers/net/ethernet/mellanox/mlx4/cq.c | 38 +++++++++++++++++---------------- 1 file changed, 20 insertions(+), 18 deletions(-) -- 2.7.4 diff --git a/drivers/net/ethernet/mellanox/mlx4/cq.c b/drivers/net/ethernet/mellanox/mlx4/cq.c index 3348e64..6eba580 100644 --- a/drivers/net/ethernet/mellanox/mlx4/cq.c +++ b/drivers/net/ethernet/mellanox/mlx4/cq.c @@ -101,13 +101,19 @@ void mlx4_cq_completion(struct mlx4_dev *dev, u32 cqn) { struct mlx4_cq *cq; + rcu_read_lock(); cq = radix_tree_lookup(&mlx4_priv(dev)->cq_table.tree, cqn & (dev->caps.num_cqs - 1)); + rcu_read_unlock(); + if (!cq) { mlx4_dbg(dev, "Completion event for bogus CQ %08x\n", cqn); return; } + /* Acessing the CQ outside of rcu_read_lock is safe, because + * the CQ is freed only after interrupt handling is completed. + */ ++cq->arm_sn; cq->comp(cq); @@ -118,23 +124,19 @@ void mlx4_cq_event(struct mlx4_dev *dev, u32 cqn, int event_type) struct mlx4_cq_table *cq_table = &mlx4_priv(dev)->cq_table; struct mlx4_cq *cq; - spin_lock(&cq_table->lock); - + rcu_read_lock(); cq = radix_tree_lookup(&cq_table->tree, cqn & (dev->caps.num_cqs - 1)); - if (cq) - atomic_inc(&cq->refcount); - - spin_unlock(&cq_table->lock); + rcu_read_unlock(); if (!cq) { - mlx4_warn(dev, "Async event for bogus CQ %08x\n", cqn); + mlx4_dbg(dev, "Async event for bogus CQ %08x\n", cqn); return; } + /* Acessing the CQ outside of rcu_read_lock is safe, because + * the CQ is freed only after interrupt handling is completed. + */ cq->event(cq, event_type); - - if (atomic_dec_and_test(&cq->refcount)) - complete(&cq->free); } static int mlx4_SW2HW_CQ(struct mlx4_dev *dev, struct mlx4_cmd_mailbox *mailbox, @@ -301,9 +303,9 @@ int mlx4_cq_alloc(struct mlx4_dev *dev, int nent, if (err) return err; - spin_lock_irq(&cq_table->lock); + spin_lock(&cq_table->lock); err = radix_tree_insert(&cq_table->tree, cq->cqn, cq); - spin_unlock_irq(&cq_table->lock); + spin_unlock(&cq_table->lock); if (err) goto err_icm; @@ -347,9 +349,9 @@ int mlx4_cq_alloc(struct mlx4_dev *dev, int nent, return 0; err_radix: - spin_lock_irq(&cq_table->lock); + spin_lock(&cq_table->lock); radix_tree_delete(&cq_table->tree, cq->cqn); - spin_unlock_irq(&cq_table->lock); + spin_unlock(&cq_table->lock); err_icm: mlx4_cq_free_icm(dev, cq->cqn); @@ -368,15 +370,15 @@ void mlx4_cq_free(struct mlx4_dev *dev, struct mlx4_cq *cq) if (err) mlx4_warn(dev, "HW2SW_CQ failed (%d) for CQN %06x\n", err, cq->cqn); + spin_lock(&cq_table->lock); + radix_tree_delete(&cq_table->tree, cq->cqn); + spin_unlock(&cq_table->lock); + synchronize_irq(priv->eq_table.eq[MLX4_CQ_TO_EQ_VECTOR(cq->vector)].irq); if (priv->eq_table.eq[MLX4_CQ_TO_EQ_VECTOR(cq->vector)].irq != priv->eq_table.eq[MLX4_EQ_ASYNC].irq) synchronize_irq(priv->eq_table.eq[MLX4_EQ_ASYNC].irq); - spin_lock_irq(&cq_table->lock); - radix_tree_delete(&cq_table->tree, cq->cqn); - spin_unlock_irq(&cq_table->lock); - if (atomic_dec_and_test(&cq->refcount)) complete(&cq->free); wait_for_completion(&cq->free); From patchwork Mon Apr 10 17:44:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 97197 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp1456343obc; Mon, 10 Apr 2017 10:45:27 -0700 (PDT) X-Received: by 10.99.149.16 with SMTP id p16mr56898575pgd.112.1491846327797; Mon, 10 Apr 2017 10:45:27 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n3si14186684pfk.174.2017.04.10.10.45.27; Mon, 10 Apr 2017 10:45:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=@linaro.org; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753953AbdDJRpU (ORCPT + 5 others); Mon, 10 Apr 2017 13:45:20 -0400 Received: from mail-pf0-f176.google.com ([209.85.192.176]:32868 "EHLO mail-pf0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753825AbdDJRpS (ORCPT ); Mon, 10 Apr 2017 13:45:18 -0400 Received: by mail-pf0-f176.google.com with SMTP id s16so36624726pfs.0 for ; Mon, 10 Apr 2017 10:45:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=A3wkWwk2XBOKz4a1YQ6ILb+VduwbK0ysFEMwUdeXyfg=; b=AVlWJfxVl8OijI5NzAW0Kw4NsX7cRCbYAAAKWb2VAS+BFbO+XD+mpOQ91t9gjW/lbS Nofv6pt+cEJGvSKb90Q6Aej/GqRuNwigpzP+Uj7pLH6v7RajYOUs9ftEIQAawdwIkvaz sgK8kAQF28x9GuU/YfIXi41z50uV3OK695Qac= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=A3wkWwk2XBOKz4a1YQ6ILb+VduwbK0ysFEMwUdeXyfg=; b=qveXPC3JlgzI2/5wYbzm4ksnzgvjf2pnbK8ZHWl9NYIkfnuscbBQ8pRoxyr++BATW8 L32Jvgybq8Iud42jLHRNiMAiWBohP0+lVAg/e31xp4gJuMjIwtrqvL7d66Q0PPxNNlb5 V1brd2iF/Osv6HVcnbXxkB4OLPO6O7ABbFZAKa1BF2SvXoCaqNSwZaWLkPzml79mLKRA VtNPLe4nRENE2PCvUIraMWtS+QNvDxZJ1rlBjsvv1Sf/28dreFWRCil5Fcx+EoMLU3lf AbfL1ZqO7zTfIULIfS5z35nDTzjknaCI4gQblbPsDZLGPnxAI7cPfAB+MVvZ6QRG9Xpl 3y2Q== X-Gm-Message-State: AFeK/H2sSOkaHGPmwQ0n9TK8sPlbAZmkUQuwddcjTYiY3yaunPkFspOGT/8cW3gRe7s9RSJ3 X-Received: by 10.98.222.70 with SMTP id h67mr55459537pfg.43.1491846317397; Mon, 10 Apr 2017 10:45:17 -0700 (PDT) Received: from phantom.lan ([106.51.225.38]) by smtp.gmail.com with ESMTPSA id y6sm768833pfa.83.2017.04.10.10.45.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Apr 2017 10:45:16 -0700 (PDT) From: Sumit Semwal To: stable@vger.kernel.org Cc: Eugenia Emantayev , Tariq Toukan , "David S . Miller" , Sumit Semwal Subject: [PATCH for-4.4 03/16] net/mlx4_en: Fix bad WQE issue Date: Mon, 10 Apr 2017 23:14:19 +0530 Message-Id: <1491846272-14882-4-git-send-email-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1491846272-14882-1-git-send-email-sumit.semwal@linaro.org> References: <1491846272-14882-1-git-send-email-sumit.semwal@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Eugenia Emantayev [Upstream commit 6496bbf0ec481966ef9ffe5b6660d8d1b55c60cc] Single send WQE in RX buffer should be stamped with software ownership in order to prevent the flow of QP in error in FW once UPDATE_QP is called. Fixes: 9f519f68cfff ('mlx4_en: Not using Shared Receive Queues') Signed-off-by: Eugenia Emantayev Signed-off-by: Tariq Toukan Signed-off-by: David S. Miller Signed-off-by: Sumit Semwal [sumits: cherry-picked for 4.4.y] --- drivers/net/ethernet/mellanox/mlx4/en_rx.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/drivers/net/ethernet/mellanox/mlx4/en_rx.c b/drivers/net/ethernet/mellanox/mlx4/en_rx.c index 28a4b34..82bf1b5 100644 --- a/drivers/net/ethernet/mellanox/mlx4/en_rx.c +++ b/drivers/net/ethernet/mellanox/mlx4/en_rx.c @@ -439,8 +439,14 @@ int mlx4_en_activate_rx_rings(struct mlx4_en_priv *priv) ring->cqn = priv->rx_cq[ring_ind]->mcq.cqn; ring->stride = stride; - if (ring->stride <= TXBB_SIZE) + if (ring->stride <= TXBB_SIZE) { + /* Stamp first unused send wqe */ + __be32 *ptr = (__be32 *)ring->buf; + __be32 stamp = cpu_to_be32(1 << STAMP_SHIFT); + *ptr = stamp; + /* Move pointer to start of rx section */ ring->buf += TXBB_SIZE; + } ring->log_stride = ffs(ring->stride) - 1; ring->buf_size = ring->size * ring->stride; From patchwork Mon Apr 10 17:44:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 97199 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp1456360obc; Mon, 10 Apr 2017 10:45:30 -0700 (PDT) X-Received: by 10.99.60.77 with SMTP id i13mr58386269pgn.185.1491846330383; Mon, 10 Apr 2017 10:45:30 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n3si14186684pfk.174.2017.04.10.10.45.30; Mon, 10 Apr 2017 10:45:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=@linaro.org; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750732AbdDJRp3 (ORCPT + 5 others); Mon, 10 Apr 2017 13:45:29 -0400 Received: from mail-pg0-f51.google.com ([74.125.83.51]:34917 "EHLO mail-pg0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752473AbdDJRp0 (ORCPT ); Mon, 10 Apr 2017 13:45:26 -0400 Received: by mail-pg0-f51.google.com with SMTP id 81so109365136pgh.2 for ; Mon, 10 Apr 2017 10:45:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=JxWeXbYeislg3eYSHyVLodJzOlp7kNaNuZ/2BqC6fqw=; b=SI9a47N4zlMTDmAWKQLScWAEtfKKTy/9zWNJJTOZD8UOXTLFLKcnBokscldIYMf5IB t/5zxeJGgNhNe8XeAgAtOAeqZ7/b6QKvhgVFzppYEmBhdetrJSyKMtKWHt6Gn5DQ5ECx GMHB1aIblXtn8RGjKx8lSmNTW0pPUERPPUZsA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=JxWeXbYeislg3eYSHyVLodJzOlp7kNaNuZ/2BqC6fqw=; b=sJNHIrRnnk4KNvO9fJueRQV4TvZ9QNydeKyuALHq0OfjL3QdPOfjN44YpnMsPLzpHE +/0heNdBP8Yi8mOxcTjp/2RolJXV+BTDE4wuzjL31DOn8IbcEkPoivBQR6G5tqhxk9XE p8ORtqDHFyHt24ciNMe247/dITpWRIoyECHG8/ThTINR2Auh9sp5hMBlY7Loc87r5hHf UYX/ntdBxHdd6IqExrx3M7taFm/w9VzOxXeTgfej1uou0XGASxpRcDQ5RGT7zqNDzN9e vcXI96BI2woWcupn64INuNQEOaZ+8szPoLtmskS+vRK0ABA+ex93I/nr5+R7SXMXqDVS LSXg== X-Gm-Message-State: AFeK/H3F3bRabiCLfByRoYpLAVmLRbCW5KD1PL5xR/SJtaOBWmsRnd7IZQSZMoZT/Pc6IsCi X-Received: by 10.99.123.75 with SMTP id k11mr56337953pgn.150.1491846320245; Mon, 10 Apr 2017 10:45:20 -0700 (PDT) Received: from phantom.lan ([106.51.225.38]) by smtp.gmail.com with ESMTPSA id y6sm768833pfa.83.2017.04.10.10.45.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Apr 2017 10:45:19 -0700 (PDT) From: Sumit Semwal To: stable@vger.kernel.org Cc: NeilBrown , Trond Myklebust , Sumit Semwal Subject: [PATCH for-4.4 04/16] SUNRPC: fix refcounting problems with auth_gss messages. Date: Mon, 10 Apr 2017 23:14:20 +0530 Message-Id: <1491846272-14882-5-git-send-email-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1491846272-14882-1-git-send-email-sumit.semwal@linaro.org> References: <1491846272-14882-1-git-send-email-sumit.semwal@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: NeilBrown [Upstream commit 1cded9d2974fe4fe339fc0ccd6638b80d465ab2c] There are two problems with refcounting of auth_gss messages. First, the reference on the pipe->pipe list (taken by a call to rpc_queue_upcall()) is not counted. It seems to be assumed that a message in pipe->pipe will always also be in pipe->in_downcall, where it is correctly reference counted. However there is no guaranty of this. I have a report of a NULL dereferences in rpc_pipe_read() which suggests a msg that has been freed is still on the pipe->pipe list. One way I imagine this might happen is: - message is queued for uid=U and auth->service=S1 - rpc.gssd reads this message and starts processing. This removes the message from pipe->pipe - message is queued for uid=U and auth->service=S2 - rpc.gssd replies to the first message. gss_pipe_downcall() calls __gss_find_upcall(pipe, U, NULL) and it finds the *second* message, as new messages are placed at the head of ->in_downcall, and the service type is not checked. - This second message is removed from ->in_downcall and freed by gss_release_msg() (even though it is still on pipe->pipe) - rpc.gssd tries to read another message, and dereferences a pointer to this message that has just been freed. I fix this by incrementing the reference count before calling rpc_queue_upcall(), and decrementing it if that fails, or normally in gss_pipe_destroy_msg(). It seems strange that the reply doesn't target the message more precisely, but I don't know all the details. In any case, I think the reference counting irregularity became a measureable bug when the extra arg was added to __gss_find_upcall(), hence the Fixes: line below. The second problem is that if rpc_queue_upcall() fails, the new message is not freed. gss_alloc_msg() set the ->count to 1, gss_add_msg() increments this to 2, gss_unhash_msg() decrements to 1, then the pointer is discarded so the memory never gets freed. Fixes: 9130b8dbc6ac ("SUNRPC: allow for upcalls for same uid but different gss service") Cc: stable@vger.kernel.org Link: https://bugzilla.opensuse.org/show_bug.cgi?id=1011250 Signed-off-by: NeilBrown Signed-off-by: Trond Myklebust Signed-off-by: Sumit Semwal --- net/sunrpc/auth_gss/auth_gss.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c index 06095cc..1f0687d 100644 --- a/net/sunrpc/auth_gss/auth_gss.c +++ b/net/sunrpc/auth_gss/auth_gss.c @@ -541,9 +541,13 @@ gss_setup_upcall(struct gss_auth *gss_auth, struct rpc_cred *cred) return gss_new; gss_msg = gss_add_msg(gss_new); if (gss_msg == gss_new) { - int res = rpc_queue_upcall(gss_new->pipe, &gss_new->msg); + int res; + atomic_inc(&gss_msg->count); + res = rpc_queue_upcall(gss_new->pipe, &gss_new->msg); if (res) { gss_unhash_msg(gss_new); + atomic_dec(&gss_msg->count); + gss_release_msg(gss_new); gss_msg = ERR_PTR(res); } } else @@ -836,6 +840,7 @@ gss_pipe_destroy_msg(struct rpc_pipe_msg *msg) warn_gssd(); gss_release_msg(gss_msg); } + gss_release_msg(gss_msg); } static void gss_pipe_dentry_destroy(struct dentry *dir, From patchwork Mon Apr 10 17:44:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 97198 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp1456354obc; Mon, 10 Apr 2017 10:45:29 -0700 (PDT) X-Received: by 10.84.128.4 with SMTP id 4mr39135790pla.37.1491846329934; Mon, 10 Apr 2017 10:45:29 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n3si14186684pfk.174.2017.04.10.10.45.29; Mon, 10 Apr 2017 10:45:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=@linaro.org; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752580AbdDJRp0 (ORCPT + 5 others); Mon, 10 Apr 2017 13:45:26 -0400 Received: from mail-pg0-f53.google.com ([74.125.83.53]:34930 "EHLO mail-pg0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753529AbdDJRpY (ORCPT ); Mon, 10 Apr 2017 13:45:24 -0400 Received: by mail-pg0-f53.google.com with SMTP id 81so109365687pgh.2 for ; Mon, 10 Apr 2017 10:45:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GFmRS1KYnPN34Jl5kex/NQAGd656bUVpDsdfrkkMgoE=; b=XWVP6J9CWmhqkXoxoFkob7KJeOXSNBZqWVwiJ37UD+v/lLlKbKg/GrxJH0el/UVv6f QqJ2HL8o4Q2XUOkP95stj+1YIhNJQ6yEi4+j7/5fhjB08ZpggYUHdUq1WpYDTJSGYs1o AcY+Q/Hy6C2QrolwvPPh669K8C9LEOIOOg4X0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GFmRS1KYnPN34Jl5kex/NQAGd656bUVpDsdfrkkMgoE=; b=qAgxYf4a7lIKeObH+/+FZ0k3XqhJfjz+vUJYTzbsMLmQqKz5eg9Es7QV+gV4zr4MPB TKeXtwBdL3Q6bWoQmJLa7SmxiPd+hezWJBahs3WzC3LUGGfqQNKC/tsLuJkUzGJOQQ6s 43o56+vyBwAozNAsFIeO/PS6U5RN/mHmAURHyxGaISbul5Vi1hMcS2fIzoTSK9Rvj386 YuFYLEP1lG50NqOJ0+jsryprI98XmwiNqZfdH5wxSp7lxJm3lxiZ3p5SomO3DtKj5OG+ /5RoH6XmBqbeRJgQ0gFMtR38olfkL4Jv455FYoyLH4AbOA3nQu/3WSrEqtiIwGTBdNh1 rojg== X-Gm-Message-State: AN3rC/7ahUQTipNcAFvvGCNRtqWdN501DckKYFCo9zAmu+yRXH0t4XYStZEGmlX/k7A4qOzX X-Received: by 10.84.222.139 with SMTP id x11mr16066668pls.112.1491846322982; Mon, 10 Apr 2017 10:45:22 -0700 (PDT) Received: from phantom.lan ([106.51.225.38]) by smtp.gmail.com with ESMTPSA id y6sm768833pfa.83.2017.04.10.10.45.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Apr 2017 10:45:21 -0700 (PDT) From: Sumit Semwal To: stable@vger.kernel.org Cc: Thomas Falcon , "David S . Miller" , Sumit Semwal Subject: [PATCH for-4.4 05/16] ibmveth: set correct gso_size and gso_type Date: Mon, 10 Apr 2017 23:14:21 +0530 Message-Id: <1491846272-14882-6-git-send-email-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1491846272-14882-1-git-send-email-sumit.semwal@linaro.org> References: <1491846272-14882-1-git-send-email-sumit.semwal@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Thomas Falcon [Upstream commit 7b5967389f5a8dfb9d32843830f5e2717e20995d] This patch is based on an earlier one submitted by Jon Maxwell with the following commit message: "We recently encountered a bug where a few customers using ibmveth on the same LPAR hit an issue where a TCP session hung when large receive was enabled. Closer analysis revealed that the session was stuck because the one side was advertising a zero window repeatedly. We narrowed this down to the fact the ibmveth driver did not set gso_size which is translated by TCP into the MSS later up the stack. The MSS is used to calculate the TCP window size and as that was abnormally large, it was calculating a zero window, even although the sockets receive buffer was completely empty." We rely on the Virtual I/O Server partition in a pseries environment to provide the MSS through the TCP header checksum field. The stipulation is that users should not disable checksum offloading if rx packet aggregation is enabled through VIOS. Some firmware offerings provide the MSS in the RX buffer. This is signalled by a bit in the RX queue descriptor. Reviewed-by: Brian King Reviewed-by: Pradeep Satyanarayana Reviewed-by: Marcelo Ricardo Leitner Reviewed-by: Jonathan Maxwell Reviewed-by: David Dai Signed-off-by: Thomas Falcon Signed-off-by: David S. Miller Signed-off-by: Sumit Semwal [sumits: cherry-picked for 4.4.y] --- drivers/net/ethernet/ibm/ibmveth.c | 65 ++++++++++++++++++++++++++++++++++++-- drivers/net/ethernet/ibm/ibmveth.h | 1 + 2 files changed, 64 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c index 7af870a..855c43d 100644 --- a/drivers/net/ethernet/ibm/ibmveth.c +++ b/drivers/net/ethernet/ibm/ibmveth.c @@ -58,7 +58,7 @@ static struct kobj_type ktype_veth_pool; static const char ibmveth_driver_name[] = "ibmveth"; static const char ibmveth_driver_string[] = "IBM Power Virtual Ethernet Driver"; -#define ibmveth_driver_version "1.05" +#define ibmveth_driver_version "1.06" MODULE_AUTHOR("Santiago Leon "); MODULE_DESCRIPTION("IBM Power Virtual Ethernet Driver"); @@ -137,6 +137,11 @@ static inline int ibmveth_rxq_frame_offset(struct ibmveth_adapter *adapter) return ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_OFF_MASK; } +static inline int ibmveth_rxq_large_packet(struct ibmveth_adapter *adapter) +{ + return ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_LRG_PKT; +} + static inline int ibmveth_rxq_frame_length(struct ibmveth_adapter *adapter) { return be32_to_cpu(adapter->rx_queue.queue_addr[adapter->rx_queue.index].length); @@ -1172,6 +1177,45 @@ map_failed: goto retry_bounce; } +static void ibmveth_rx_mss_helper(struct sk_buff *skb, u16 mss, int lrg_pkt) +{ + int offset = 0; + + /* only TCP packets will be aggregated */ + if (skb->protocol == htons(ETH_P_IP)) { + struct iphdr *iph = (struct iphdr *)skb->data; + + if (iph->protocol == IPPROTO_TCP) { + offset = iph->ihl * 4; + skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4; + } else { + return; + } + } else if (skb->protocol == htons(ETH_P_IPV6)) { + struct ipv6hdr *iph6 = (struct ipv6hdr *)skb->data; + + if (iph6->nexthdr == IPPROTO_TCP) { + offset = sizeof(struct ipv6hdr); + skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6; + } else { + return; + } + } else { + return; + } + /* if mss is not set through Large Packet bit/mss in rx buffer, + * expect that the mss will be written to the tcp header checksum. + */ + if (lrg_pkt) { + skb_shinfo(skb)->gso_size = mss; + } else if (offset) { + struct tcphdr *tcph = (struct tcphdr *)(skb->data + offset); + + skb_shinfo(skb)->gso_size = ntohs(tcph->check); + tcph->check = 0; + } +} + static int ibmveth_poll(struct napi_struct *napi, int budget) { struct ibmveth_adapter *adapter = @@ -1180,6 +1224,7 @@ static int ibmveth_poll(struct napi_struct *napi, int budget) int frames_processed = 0; unsigned long lpar_rc; struct iphdr *iph; + u16 mss = 0; restart_poll: while (frames_processed < budget) { @@ -1197,9 +1242,21 @@ restart_poll: int length = ibmveth_rxq_frame_length(adapter); int offset = ibmveth_rxq_frame_offset(adapter); int csum_good = ibmveth_rxq_csum_good(adapter); + int lrg_pkt = ibmveth_rxq_large_packet(adapter); skb = ibmveth_rxq_get_buffer(adapter); + /* if the large packet bit is set in the rx queue + * descriptor, the mss will be written by PHYP eight + * bytes from the start of the rx buffer, which is + * skb->data at this stage + */ + if (lrg_pkt) { + __be64 *rxmss = (__be64 *)(skb->data + 8); + + mss = (u16)be64_to_cpu(*rxmss); + } + new_skb = NULL; if (length < rx_copybreak) new_skb = netdev_alloc_skb(netdev, length); @@ -1233,11 +1290,15 @@ restart_poll: if (iph->check == 0xffff) { iph->check = 0; iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl); - adapter->rx_large_packets++; } } } + if (length > netdev->mtu + ETH_HLEN) { + ibmveth_rx_mss_helper(skb, mss, lrg_pkt); + adapter->rx_large_packets++; + } + napi_gro_receive(napi, skb); /* send it up */ netdev->stats.rx_packets++; diff --git a/drivers/net/ethernet/ibm/ibmveth.h b/drivers/net/ethernet/ibm/ibmveth.h index 4eade67..7acda04 100644 --- a/drivers/net/ethernet/ibm/ibmveth.h +++ b/drivers/net/ethernet/ibm/ibmveth.h @@ -209,6 +209,7 @@ struct ibmveth_rx_q_entry { #define IBMVETH_RXQ_TOGGLE 0x80000000 #define IBMVETH_RXQ_TOGGLE_SHIFT 31 #define IBMVETH_RXQ_VALID 0x40000000 +#define IBMVETH_RXQ_LRG_PKT 0x04000000 #define IBMVETH_RXQ_NO_CSUM 0x02000000 #define IBMVETH_RXQ_CSUM_GOOD 0x01000000 #define IBMVETH_RXQ_OFF_MASK 0x0000FFFF From patchwork Mon Apr 10 17:44:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 97202 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp1456498obc; Mon, 10 Apr 2017 10:45:56 -0700 (PDT) X-Received: by 10.84.171.129 with SMTP id l1mr33063459plb.5.1491846356564; Mon, 10 Apr 2017 10:45:56 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w21si14197944pgh.90.2017.04.10.10.45.56; Mon, 10 Apr 2017 10:45:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=@linaro.org; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753529AbdDJRpe (ORCPT + 5 others); Mon, 10 Apr 2017 13:45:34 -0400 Received: from mail-pf0-f181.google.com ([209.85.192.181]:36019 "EHLO mail-pf0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752314AbdDJRpb (ORCPT ); Mon, 10 Apr 2017 13:45:31 -0400 Received: by mail-pf0-f181.google.com with SMTP id o126so36634168pfb.3 for ; Mon, 10 Apr 2017 10:45:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ci+48rNPC3O4fb9iv9C0F/GoNwbg9ni8wQNpnXba7mo=; b=gENTgsjg53dVTXzIKhAb7zypcDZo457z2ojykRAkPfndUAs1Jq12pUhPsE3LXGa392 q/VP8LcTcWzhSWetbHfSJhuI8TtOwdfeACR3Z0yE13Hx587iIc/jcNpcxt+FHUMN5vtl VPANg0kBMloBGeJKCxEZByeMZSs8aptve0yxc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ci+48rNPC3O4fb9iv9C0F/GoNwbg9ni8wQNpnXba7mo=; b=mzWoMieEvc6xrKp0Kqa1ty1g4S7uBMbL/t0ToRt1cgjrBkdD1bMPcFdJZVLH+4cwxk MfXk1tpkIJbfo3XdF/lCCF6RZG0dPplx+u1pgpY3t5p4o29bl7nKCHR0miVx8G79OF03 85PDYv2u1/VDgZCgnzFJrhdn+Xt7mwxzkVeC0B6TFlAu3z6XWU9KbGQ7vPy3PaSNAJke ueFuTpDgE8S3xtu+mljo51NIKjvUj3uSPYNrUcyt7/Tv7j89hIjKs+KVdiPpnK5V3KlH 58VXbJTCEdQzNN2HSqrSFp5nLae32WCN4kHGpi/MvjSDFxgY+ZL0Hwiv4GKKTcUlD9UQ UAGw== X-Gm-Message-State: AN3rC/5RJBE9XIm73DO2bCaFQ24J9Ng4qacobG7gNuikTPyVK0om1gzRRj4F3/YywL/pxhM0 X-Received: by 10.84.233.136 with SMTP id l8mr19488371plk.49.1491846325899; Mon, 10 Apr 2017 10:45:25 -0700 (PDT) Received: from phantom.lan ([106.51.225.38]) by smtp.gmail.com with ESMTPSA id y6sm768833pfa.83.2017.04.10.10.45.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Apr 2017 10:45:24 -0700 (PDT) From: Sumit Semwal To: stable@vger.kernel.org Cc: Thomas Falcon , "David S . Miller" , Sumit Semwal Subject: [PATCH for-4.4 06/16] ibmveth: calculate gso_segs for large packets Date: Mon, 10 Apr 2017 23:14:22 +0530 Message-Id: <1491846272-14882-7-git-send-email-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1491846272-14882-1-git-send-email-sumit.semwal@linaro.org> References: <1491846272-14882-1-git-send-email-sumit.semwal@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Thomas Falcon [Upstream commit 94acf164dc8f1184e8d0737be7125134c2701dbe] Include calculations to compute the number of segments that comprise an aggregated large packet. Signed-off-by: Thomas Falcon Reviewed-by: Marcelo Ricardo Leitner Reviewed-by: Jonathan Maxwell Signed-off-by: David S. Miller Signed-off-by: Sumit Semwal [sumits: cherry-picked for 4.4.y] --- drivers/net/ethernet/ibm/ibmveth.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c index 855c43d..f9e4988 100644 --- a/drivers/net/ethernet/ibm/ibmveth.c +++ b/drivers/net/ethernet/ibm/ibmveth.c @@ -1179,7 +1179,9 @@ map_failed: static void ibmveth_rx_mss_helper(struct sk_buff *skb, u16 mss, int lrg_pkt) { + struct tcphdr *tcph; int offset = 0; + int hdr_len; /* only TCP packets will be aggregated */ if (skb->protocol == htons(ETH_P_IP)) { @@ -1206,14 +1208,20 @@ static void ibmveth_rx_mss_helper(struct sk_buff *skb, u16 mss, int lrg_pkt) /* if mss is not set through Large Packet bit/mss in rx buffer, * expect that the mss will be written to the tcp header checksum. */ + tcph = (struct tcphdr *)(skb->data + offset); if (lrg_pkt) { skb_shinfo(skb)->gso_size = mss; } else if (offset) { - struct tcphdr *tcph = (struct tcphdr *)(skb->data + offset); - skb_shinfo(skb)->gso_size = ntohs(tcph->check); tcph->check = 0; } + + if (skb_shinfo(skb)->gso_size) { + hdr_len = offset + tcph->doff * 4; + skb_shinfo(skb)->gso_segs = + DIV_ROUND_UP(skb->len - hdr_len, + skb_shinfo(skb)->gso_size); + } } static int ibmveth_poll(struct napi_struct *napi, int budget) From patchwork Mon Apr 10 17:44:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 97200 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp1456374obc; Mon, 10 Apr 2017 10:45:34 -0700 (PDT) X-Received: by 10.99.60.77 with SMTP id i13mr58386577pgn.185.1491846334409; Mon, 10 Apr 2017 10:45:34 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n3si14186684pfk.174.2017.04.10.10.45.34; Mon, 10 Apr 2017 10:45:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=@linaro.org; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752648AbdDJRpc (ORCPT + 5 others); Mon, 10 Apr 2017 13:45:32 -0400 Received: from mail-pg0-f46.google.com ([74.125.83.46]:36781 "EHLO mail-pg0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752473AbdDJRp3 (ORCPT ); Mon, 10 Apr 2017 13:45:29 -0400 Received: by mail-pg0-f46.google.com with SMTP id g2so107975356pge.3 for ; Mon, 10 Apr 2017 10:45:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7FD9eYeUC7RqCtVBVw4fTdZIa94y753MIJivS7QoN5w=; b=Dp9dhMXwiMEPSsqOpnS01Hiwa7AkuwlMUfqF7s10dJHwXWscYOi5gvq5KOq8De6bFF 8aHPkXYdxnkjpR/lNzpkwADFD2T9OfLyTiNT8CHZ3Mc2CjagziRsdS8G28VCRPxscL9O gGtlTeWNQZIV9QBWv7eE9BX7HSdCAbTLGOaNg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7FD9eYeUC7RqCtVBVw4fTdZIa94y753MIJivS7QoN5w=; b=mSrF7MmnGZIR7n66ReOsR/Ildn4ao3B+KTjoe4qascqnlUia+LM4dgjBWamrG++cTd rjWDu73reM+FVq4Enebd8I6JJ+7YKz58eJoF7K6WuXfUn8yp+x382ZGD/BXDo1RZJmO0 VQFzTh370OW025c+rkJUomunlCeunZN2GUj0UG7KHZ5GWb53juehg1TouwJ64+/dV2Wm zxlOa+p9Hnjy+NbAxjfCf3crApF94OX3NkeD4BzndXJs8B6euoan6ggTFja4JnbF9U7J 86RAaQQ7eiyHyACYAd+lAcLol/wejskKsOfS5O031nJAEI/40AFmbYWhU8rK0vILkjIH 2hPw== X-Gm-Message-State: AFeK/H1VvM0/yrhcda+/hDkXIrrOweaw82hOPO311JW3EcjAKDeWUXkX0iVnSWdweTQ/bajp X-Received: by 10.84.209.167 with SMTP id y36mr31615124plh.78.1491846328858; Mon, 10 Apr 2017 10:45:28 -0700 (PDT) Received: from phantom.lan ([106.51.225.38]) by smtp.gmail.com with ESMTPSA id y6sm768833pfa.83.2017.04.10.10.45.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Apr 2017 10:45:27 -0700 (PDT) From: Sumit Semwal To: stable@vger.kernel.org Cc: Vitaly Kuznetsov , "K . Y . Srinivasan" , Greg Kroah-Hartman , Sumit Semwal Subject: [PATCH for-4.4 07/16] Drivers: hv: get rid of redundant messagecount in create_gpadl_header() Date: Mon, 10 Apr 2017 23:14:23 +0530 Message-Id: <1491846272-14882-8-git-send-email-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1491846272-14882-1-git-send-email-sumit.semwal@linaro.org> References: <1491846272-14882-1-git-send-email-sumit.semwal@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Vitaly Kuznetsov [ Upstream commit 4d63763296ab7865a98bc29cc7d77145815ef89f ] We use messagecount only once in vmbus_establish_gpadl() to check if it is safe to iterate through the submsglist. We can just initialize the list header in all cases in create_gpadl_header() instead. Signed-off-by: Vitaly Kuznetsov Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sumit Semwal [sumits: cherry picked for 4.4.y] --- drivers/hv/channel.c | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) -- 2.7.4 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c index 1ef37c7..fb1e3df 100644 --- a/drivers/hv/channel.c +++ b/drivers/hv/channel.c @@ -223,8 +223,7 @@ EXPORT_SYMBOL_GPL(vmbus_open); * create_gpadl_header - Creates a gpadl for the specified buffer */ static int create_gpadl_header(void *kbuffer, u32 size, - struct vmbus_channel_msginfo **msginfo, - u32 *messagecount) + struct vmbus_channel_msginfo **msginfo) { int i; int pagecount; @@ -268,7 +267,6 @@ static int create_gpadl_header(void *kbuffer, u32 size, gpadl_header->range[0].pfn_array[i] = slow_virt_to_phys( kbuffer + PAGE_SIZE * i) >> PAGE_SHIFT; *msginfo = msgheader; - *messagecount = 1; pfnsum = pfncount; pfnleft = pagecount - pfncount; @@ -308,7 +306,6 @@ static int create_gpadl_header(void *kbuffer, u32 size, } msgbody->msgsize = msgsize; - (*messagecount)++; gpadl_body = (struct vmbus_channel_gpadl_body *)msgbody->msg; @@ -337,6 +334,8 @@ static int create_gpadl_header(void *kbuffer, u32 size, msgheader = kzalloc(msgsize, GFP_KERNEL); if (msgheader == NULL) goto nomem; + + INIT_LIST_HEAD(&msgheader->submsglist); msgheader->msgsize = msgsize; gpadl_header = (struct vmbus_channel_gpadl_header *) @@ -351,7 +350,6 @@ static int create_gpadl_header(void *kbuffer, u32 size, kbuffer + PAGE_SIZE * i) >> PAGE_SHIFT; *msginfo = msgheader; - *messagecount = 1; } return 0; @@ -376,7 +374,6 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer, struct vmbus_channel_gpadl_body *gpadl_body; struct vmbus_channel_msginfo *msginfo = NULL; struct vmbus_channel_msginfo *submsginfo; - u32 msgcount; struct list_head *curr; u32 next_gpadl_handle; unsigned long flags; @@ -385,7 +382,7 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer, next_gpadl_handle = (atomic_inc_return(&vmbus_connection.next_gpadl_handle) - 1); - ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount); + ret = create_gpadl_header(kbuffer, size, &msginfo); if (ret) return ret; @@ -408,24 +405,21 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer, if (ret != 0) goto cleanup; - if (msgcount > 1) { - list_for_each(curr, &msginfo->submsglist) { + list_for_each(curr, &msginfo->submsglist) { + submsginfo = (struct vmbus_channel_msginfo *)curr; + gpadl_body = + (struct vmbus_channel_gpadl_body *)submsginfo->msg; - submsginfo = (struct vmbus_channel_msginfo *)curr; - gpadl_body = - (struct vmbus_channel_gpadl_body *)submsginfo->msg; + gpadl_body->header.msgtype = + CHANNELMSG_GPADL_BODY; + gpadl_body->gpadl = next_gpadl_handle; - gpadl_body->header.msgtype = - CHANNELMSG_GPADL_BODY; - gpadl_body->gpadl = next_gpadl_handle; + ret = vmbus_post_msg(gpadl_body, + submsginfo->msgsize - + sizeof(*submsginfo)); + if (ret != 0) + goto cleanup; - ret = vmbus_post_msg(gpadl_body, - submsginfo->msgsize - - sizeof(*submsginfo)); - if (ret != 0) - goto cleanup; - - } } wait_for_completion(&msginfo->waitevent); From patchwork Mon Apr 10 17:44:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 97201 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp1456497obc; Mon, 10 Apr 2017 10:45:56 -0700 (PDT) X-Received: by 10.99.113.18 with SMTP id m18mr58034851pgc.235.1491846356355; Mon, 10 Apr 2017 10:45:56 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w21si14197944pgh.90.2017.04.10.10.45.56; Mon, 10 Apr 2017 10:45:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=@linaro.org; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753487AbdDJRpe (ORCPT + 5 others); Mon, 10 Apr 2017 13:45:34 -0400 Received: from mail-pg0-f48.google.com ([74.125.83.48]:34630 "EHLO mail-pg0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752473AbdDJRpc (ORCPT ); Mon, 10 Apr 2017 13:45:32 -0400 Received: by mail-pg0-f48.google.com with SMTP id 21so109454556pgg.1 for ; Mon, 10 Apr 2017 10:45:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VLHjgau/bHn36t9u38eVY9C1h0TFKG2NxVBdYg6dTE8=; b=M3IA9k6QUEYbH+B9MzvFdHJ8fl7vHx4ZeoydqRzl3KZJmEMoZnSrPRu06GA9g5ct/B Z98rLwa7EtDLg5yQtH2WZgiD6ox/y7P6hedM9gWybZ3A4FvKHkmMMKY3mwFZlyeG040Q V2cz1YvRD9EuTvs4NaTxr4AMvcdTMN/YpLSBM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=VLHjgau/bHn36t9u38eVY9C1h0TFKG2NxVBdYg6dTE8=; b=H1Bi2F7lvnfMjIxNIXopcdysqfAmcYB725lG3I3oAvDyRQOLAPhx1icsZmsepL0ooO 9o0ESxB4VV2RSK3Ctum5Rd1kswaYvn6388S55YTmpAaa3yxmK1/wXtlv8DiyzVK2eVkx N9k91sGdLe4DeRdFue3CgEVsNv72DCCKYs6/q2BmcnTyTYnOID4OLNw6GAEZAp5xseph rTpBgU3L3zFuD4Od+W3+P2+/JDdSrjftnHh0rLaGs/fYEZm41SviW3FpYFuSMe8FhuD4 Q0m3jQWSF6bWdpfhmH0fWHOW/gTr+PYCNTr77CKLnjvZRH66wOfGs35q8SsSDnif36GI ruUw== X-Gm-Message-State: AFeK/H3ta03E0PX+OM0b+7r+DoNFkuP8lHhW3cMQovh+JRs/jJp11N3E1ucmHJMHcLQc+Wb+ X-Received: by 10.99.178.6 with SMTP id x6mr57681698pge.80.1491846331763; Mon, 10 Apr 2017 10:45:31 -0700 (PDT) Received: from phantom.lan ([106.51.225.38]) by smtp.gmail.com with ESMTPSA id y6sm768833pfa.83.2017.04.10.10.45.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Apr 2017 10:45:30 -0700 (PDT) From: Sumit Semwal To: stable@vger.kernel.org Cc: Vitaly Kuznetsov , "K . Y . Srinivasan" , Greg Kroah-Hartman , Sumit Semwal Subject: [PATCH for-4.4 08/16] Drivers: hv: don't leak memory in vmbus_establish_gpadl() Date: Mon, 10 Apr 2017 23:14:24 +0530 Message-Id: <1491846272-14882-9-git-send-email-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1491846272-14882-1-git-send-email-sumit.semwal@linaro.org> References: <1491846272-14882-1-git-send-email-sumit.semwal@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Vitaly Kuznetsov [ Upstream commit 7cc80c98070ccc7940fc28811c92cca0a681015d ] In some cases create_gpadl_header() allocates submessages but we never free them. Signed-off-by: Vitaly Kuznetsov Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sumit Semwal --- drivers/hv/channel.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c index fb1e3df..ec61ad8 100644 --- a/drivers/hv/channel.c +++ b/drivers/hv/channel.c @@ -373,7 +373,7 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer, struct vmbus_channel_gpadl_header *gpadlmsg; struct vmbus_channel_gpadl_body *gpadl_body; struct vmbus_channel_msginfo *msginfo = NULL; - struct vmbus_channel_msginfo *submsginfo; + struct vmbus_channel_msginfo *submsginfo, *tmp; struct list_head *curr; u32 next_gpadl_handle; unsigned long flags; @@ -430,6 +430,10 @@ cleanup: spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); list_del(&msginfo->msglistentry); spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); + list_for_each_entry_safe(submsginfo, tmp, &msginfo->submsglist, + msglistentry) { + kfree(submsginfo); + } kfree(msginfo); return ret; From patchwork Mon Apr 10 17:44:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 97208 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp1456522obc; Mon, 10 Apr 2017 10:45:59 -0700 (PDT) X-Received: by 10.84.224.136 with SMTP id s8mr13940138plj.93.1491846359370; Mon, 10 Apr 2017 10:45:59 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w21si14197944pgh.90.2017.04.10.10.45.59; Mon, 10 Apr 2017 10:45:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=@linaro.org; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753997AbdDJRpw (ORCPT + 5 others); Mon, 10 Apr 2017 13:45:52 -0400 Received: from mail-pf0-f180.google.com ([209.85.192.180]:34100 "EHLO mail-pf0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753027AbdDJRpv (ORCPT ); Mon, 10 Apr 2017 13:45:51 -0400 Received: by mail-pf0-f180.google.com with SMTP id c198so25508337pfc.1 for ; Mon, 10 Apr 2017 10:45:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qIii9Fm+SvwEEzyBcxIH6F74YRHy/7vYFyXQT+CrHGE=; b=eLn+iWOoRuAbmPL1gN572bm2yrahECjqHD0nkaUI61wdLku8taG9m759i6ldjxwZqc hG4aLKW/yurFxhiHkzgVlqRCmMxhdqrtLYkxb2pHApzIfCvfKDo9R2H2OV7THZVPAiIi +pNYEdFaXJFvGmh4bApHt9N5TabSZa0iUpzC0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qIii9Fm+SvwEEzyBcxIH6F74YRHy/7vYFyXQT+CrHGE=; b=b7fGPvYBP49UotZClFgyl+xAwxjXZvOxHyw2VgjdUyU1y8y3D/bOecygpesSvmvTRP 2eNkqhpPg8oKmize5OqFuMEvEMgKEBZHPlBD6vRH9VUa4wssoe2HU0ATSAr92880/35+ 91QkVHqZn6Tfw60wk+BbfUuxBIxjcyW5UEyqBWmGGmAyBkEK3yc4qjWFV9ULt9NlhQrP KDGZkFhcW/IRXseHHOxLvA82o+1STklbiraIUHc1bYwU3C7W18ve1HQ4am740v0Gbc2f iBI3MXLAUNhwv9XV5x/SaQtKRs1QzRztjDnuPKaPG3dtYKUlJvd7GDucAFcZQt69VAmw NIBA== X-Gm-Message-State: AN3rC/4SYf6zVEAFYyaIhdorTX3en8jZgBxTvx1cMjviK9uwvBp6UUrMMTB3DinsFtwC5h7m X-Received: by 10.98.6.70 with SMTP id 67mr17239234pfg.156.1491846334752; Mon, 10 Apr 2017 10:45:34 -0700 (PDT) Received: from phantom.lan ([106.51.225.38]) by smtp.gmail.com with ESMTPSA id y6sm768833pfa.83.2017.04.10.10.45.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Apr 2017 10:45:33 -0700 (PDT) From: Sumit Semwal To: stable@vger.kernel.org Cc: Vitaly Kuznetsov , "K . Y . Srinivasan" , Greg Kroah-Hartman , Sumit Semwal Subject: [PATCH for-4.4 09/16] Drivers: hv: get rid of timeout in vmbus_open() Date: Mon, 10 Apr 2017 23:14:25 +0530 Message-Id: <1491846272-14882-10-git-send-email-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1491846272-14882-1-git-send-email-sumit.semwal@linaro.org> References: <1491846272-14882-1-git-send-email-sumit.semwal@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Vitaly Kuznetsov [ Upstream commit 396e287fa2ff46e83ae016cdcb300c3faa3b02f6 ] vmbus_teardown_gpadl() can result in infinite wait when it is called on 5 second timeout in vmbus_open(). The issue is caused by the fact that gpadl teardown operation won't ever succeed for an opened channel and the timeout isn't always enough. As a guest, we can always trust the host to respond to our request (and there is nothing we can do if it doesn't). Signed-off-by: Vitaly Kuznetsov Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sumit Semwal [sumits: cherry picked for 4.4.y] --- drivers/hv/channel.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) -- 2.7.4 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c index ec61ad8..800598c 100644 --- a/drivers/hv/channel.c +++ b/drivers/hv/channel.c @@ -73,7 +73,6 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, void *in, *out; unsigned long flags; int ret, err = 0; - unsigned long t; struct page *page; spin_lock_irqsave(&newchannel->lock, flags); @@ -183,11 +182,7 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, goto error1; } - t = wait_for_completion_timeout(&open_info->waitevent, 5*HZ); - if (t == 0) { - err = -ETIMEDOUT; - goto error1; - } + wait_for_completion(&open_info->waitevent); spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); list_del(&open_info->msglistentry); From patchwork Mon Apr 10 17:44:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 97205 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp1456513obc; Mon, 10 Apr 2017 10:45:58 -0700 (PDT) X-Received: by 10.99.125.12 with SMTP id y12mr7328125pgc.146.1491846358453; Mon, 10 Apr 2017 10:45:58 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w21si14197944pgh.90.2017.04.10.10.45.58; Mon, 10 Apr 2017 10:45:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=@linaro.org; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753101AbdDJRpo (ORCPT + 5 others); Mon, 10 Apr 2017 13:45:44 -0400 Received: from mail-pf0-f176.google.com ([209.85.192.176]:34110 "EHLO mail-pf0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752498AbdDJRpn (ORCPT ); Mon, 10 Apr 2017 13:45:43 -0400 Received: by mail-pf0-f176.google.com with SMTP id c198so25508793pfc.1 for ; Mon, 10 Apr 2017 10:45:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nvuryFGNPGCQ0OvrpADpfSou8jt4E6kEASBeHvbi9dE=; b=eKbq1yzrEMZclm0rFKGtqJCiIlYibuy+3+O+7YPN9jNAejRXZdISFmRuNso5QmDs8H ET13kSzVFtN4Ep162b53I+r3fhiVYo73skMrUzPAqJjUXOcKBXJF/w7p6TZcf8b5lEEg 2SRiyx/36D18QLu8vt/l5a24roh936ce44Tc8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=nvuryFGNPGCQ0OvrpADpfSou8jt4E6kEASBeHvbi9dE=; b=ulvYIPg4rXUYAG5svJSpHc8ZQKaQOIV5g3ReIsp90smO4WFwYnAF3spNXYa0N/ck8n NaZjODTNCR6rf/3ioqGZnZVTafZoPivE/0EUKQPwLQARYe3hxjP2Nvy/0ol/YOOaP41x sd2G0C20KLUYSuR/m9nXQ3AO0lUzPiC2FvQucAqNgpuXWubcyqntu2/H4SLSFacghpZJ toQ7duFvidR4bFeax4hA3w2I0AIFHGxLmpL4dgSBIOdcVAyd4jx7scEW/04uPLYUCcgB OM5Z4FM2Ee0opeHOFMauXX2yrSDD25ffOzkrwGhkmD7vqpvdhfVj7zOPqFvP+dHe2Fra ydAw== X-Gm-Message-State: AFeK/H0Tfu0av9s6uAWfldwaFW7S+DmrcpLS37u81ihzqJ8BsCzhMw3SfFKGzHSDp/1uEBuw X-Received: by 10.98.66.88 with SMTP id p85mr56601703pfa.146.1491846337501; Mon, 10 Apr 2017 10:45:37 -0700 (PDT) Received: from phantom.lan ([106.51.225.38]) by smtp.gmail.com with ESMTPSA id y6sm768833pfa.83.2017.04.10.10.45.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Apr 2017 10:45:36 -0700 (PDT) From: Sumit Semwal To: stable@vger.kernel.org Cc: "K. Y. Srinivasan" , Greg Kroah-Hartman , Sumit Semwal Subject: [PATCH for-4.4 10/16] Drivers: hv: vmbus: Reduce the delay between retries in vmbus_post_msg() Date: Mon, 10 Apr 2017 23:14:26 +0530 Message-Id: <1491846272-14882-11-git-send-email-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1491846272-14882-1-git-send-email-sumit.semwal@linaro.org> References: <1491846272-14882-1-git-send-email-sumit.semwal@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: "K. Y. Srinivasan" [ Upstream commit 8de0d7e951826d7592e0ba1da655b175c4aa0923 ] The current delay between retries is unnecessarily high and is negatively affecting the time it takes to boot the system. Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sumit Semwal --- drivers/hv/connection.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) -- 2.7.4 diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c index 4fc2e88..2bbc530 100644 --- a/drivers/hv/connection.c +++ b/drivers/hv/connection.c @@ -429,7 +429,7 @@ int vmbus_post_msg(void *buffer, size_t buflen) union hv_connection_id conn_id; int ret = 0; int retries = 0; - u32 msec = 1; + u32 usec = 1; conn_id.asu32 = 0; conn_id.u.id = VMBUS_MESSAGE_CONNECTION_ID; @@ -462,9 +462,9 @@ int vmbus_post_msg(void *buffer, size_t buflen) } retries++; - msleep(msec); - if (msec < 2048) - msec *= 2; + udelay(usec); + if (usec < 2048) + usec *= 2; } return ret; } From patchwork Mon Apr 10 17:44:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 97209 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp1456525obc; Mon, 10 Apr 2017 10:45:59 -0700 (PDT) X-Received: by 10.84.134.36 with SMTP id 33mr71305851plg.34.1491846359564; Mon, 10 Apr 2017 10:45:59 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w21si14197944pgh.90.2017.04.10.10.45.59; Mon, 10 Apr 2017 10:45:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=@linaro.org; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753027AbdDJRpx (ORCPT + 5 others); Mon, 10 Apr 2017 13:45:53 -0400 Received: from mail-pg0-f47.google.com ([74.125.83.47]:36829 "EHLO mail-pg0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753940AbdDJRpv (ORCPT ); Mon, 10 Apr 2017 13:45:51 -0400 Received: by mail-pg0-f47.google.com with SMTP id g2so107977625pge.3 for ; Mon, 10 Apr 2017 10:45:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=pJPpAxTCXAFWsJOMqb2N3RYGj35hZ9PAsgs24tOjD04=; b=XEUHbFhK/M65gm+auu64Nk3tB5pU5cLP0ZWpV0qlIpbxE/7qX8cJ1cX7uHq/fCMp2v JdF+yGKCM0Zc+wZ2zPLYteebHM/8+R3SauH2aaqPEP4wwL9kkyVTB0Ho+u6jurg6D92C P7FlPbXU69lHu08H7e6yYT1mkACszhbqhSAqU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=pJPpAxTCXAFWsJOMqb2N3RYGj35hZ9PAsgs24tOjD04=; b=S62nHhivNCjNq3WXWc7DeHjf47aJX1MR3eb3+O95WLX0PnHK6nruSQ1Db0aytV8ELp eE7NAO+LaPBVsvE+3kLQ3erT6irrvDp5qNJ3P8Pkg8nQjqk6CyA2HAw2HRpb8X5tMnvw /W2cwtQfjfcvQuag/S/Dr585jy1ibz69U0zevQZ6DCes+IH4hSoJSBnrMlZ11dJhxPhv y3xbxb+6/uaH/TL0AfJqTQmJrql8pE2X/p4kNORt8dfuBckxzdD4p3/c4gM4MlUg8efE Dfvd39sghZiwW54sc+Xnjj7j/AsyFHgNiMh6e5HMZVv3LsqXfcydBTeUisyJd1sukSQG QXEQ== X-Gm-Message-State: AFeK/H1cXHGBqyE42eE2P6e5C/feu4x7z++gbx8zuNnPrEstaZ3s376phkXpda93LrXsP5gh X-Received: by 10.98.141.67 with SMTP id z64mr52687776pfd.91.1491846340391; Mon, 10 Apr 2017 10:45:40 -0700 (PDT) Received: from phantom.lan ([106.51.225.38]) by smtp.gmail.com with ESMTPSA id y6sm768833pfa.83.2017.04.10.10.45.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Apr 2017 10:45:39 -0700 (PDT) From: Sumit Semwal To: stable@vger.kernel.org Cc: Vitaly Kuznetsov , "K . Y . Srinivasan" , Greg Kroah-Hartman , Sumit Semwal Subject: [PATCH for-4.4 11/16] Tools: hv: kvp: ensure kvp device fd is closed on exec Date: Mon, 10 Apr 2017 23:14:27 +0530 Message-Id: <1491846272-14882-12-git-send-email-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1491846272-14882-1-git-send-email-sumit.semwal@linaro.org> References: <1491846272-14882-1-git-send-email-sumit.semwal@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Vitaly Kuznetsov [ Upstream commit 26840437cbd6d3625ea6ab34e17cd34bb810c861 ] KVP daemon does fork()/exec() (with popen()) so we need to close our fds to avoid sharing them with child processes. The immediate implication of not doing so I see is SELinux complaining about 'ip' trying to access '/dev/vmbus/hv_kvp'. Signed-off-by: Vitaly Kuznetsov Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sumit Semwal --- tools/hv/hv_kvp_daemon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.7.4 diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c index 0d9f48e..bc7adb8 100644 --- a/tools/hv/hv_kvp_daemon.c +++ b/tools/hv/hv_kvp_daemon.c @@ -1433,7 +1433,7 @@ int main(int argc, char *argv[]) openlog("KVP", 0, LOG_USER); syslog(LOG_INFO, "KVP starting; pid is:%d", getpid()); - kvp_fd = open("/dev/vmbus/hv_kvp", O_RDWR); + kvp_fd = open("/dev/vmbus/hv_kvp", O_RDWR | O_CLOEXEC); if (kvp_fd < 0) { syslog(LOG_ERR, "open /dev/vmbus/hv_kvp failed; error: %d %s", From patchwork Mon Apr 10 17:44:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 97207 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp1456521obc; Mon, 10 Apr 2017 10:45:59 -0700 (PDT) X-Received: by 10.84.236.74 with SMTP id h10mr5418233pln.91.1491846359174; Mon, 10 Apr 2017 10:45:59 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w21si14197944pgh.90.2017.04.10.10.45.58; Mon, 10 Apr 2017 10:45:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=@linaro.org; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753963AbdDJRpu (ORCPT + 5 others); Mon, 10 Apr 2017 13:45:50 -0400 Received: from mail-pg0-f47.google.com ([74.125.83.47]:34682 "EHLO mail-pg0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753027AbdDJRpt (ORCPT ); Mon, 10 Apr 2017 13:45:49 -0400 Received: by mail-pg0-f47.google.com with SMTP id 21so109457014pgg.1 for ; Mon, 10 Apr 2017 10:45:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XvfGN4kuV2GaT9V0Hew0AdCq55FIICrp9Uuj/cDy4xQ=; b=cXcXPL9aqzZEYzYnXncRl9FPYDv/RIorBldW898soPbnAYkjCcKTtNqreyAxb7hFgm 1tVRC49ypq2qx1nCpByNB9J/KFPNU71wuzBnrRH9ZLXHIkKrdIb+o6ud+bGHiO+lwxAr wz9jFJwiVJJfSb79NnG38ggoqDwxh1UYi1DoM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XvfGN4kuV2GaT9V0Hew0AdCq55FIICrp9Uuj/cDy4xQ=; b=qW5gU1naRle6jVp4B0iqNBkGVTcI2LlkaLb3swFDyo5R1IVNmOLE44rCVAprndRAOo vNqYKU/Iv9d5yuRYaEj9EhOYwaiwdQQlg/fuiThjb9Bxvzqvn0JRTLxg25rKVgF8O2El HcH8c9yJuHDpX5CgHwuP/DDs29dieBfBKD5jYrmP2+KdSCVNpTgejgAhu6VHgoDGzoKq PB5MBYKThC/tH/un3BfT6HIuFi+HWkK7fD2Zt12MW8PrUNUpmf4fHF4A4c6zqNS8/9Rk KwFtn5VabGKMy8gebJunQTe22ZusivPNpcvPYb1rVhd7CGjKhscBPeuhFTl2puwBo8ne iLnA== X-Gm-Message-State: AFeK/H2t0OffxetJFs/zpqCN/GXU8HFKoQgudbrw5LoN8rM8xRtCWEwByTpJBaJAOlJxFUID X-Received: by 10.99.108.74 with SMTP id h71mr57686670pgc.18.1491846343388; Mon, 10 Apr 2017 10:45:43 -0700 (PDT) Received: from phantom.lan ([106.51.225.38]) by smtp.gmail.com with ESMTPSA id y6sm768833pfa.83.2017.04.10.10.45.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Apr 2017 10:45:42 -0700 (PDT) From: Sumit Semwal To: stable@vger.kernel.org Cc: Vitaly Kuznetsov , "K . Y . Srinivasan" , Greg Kroah-Hartman , Sumit Semwal Subject: [PATCH for-4.4 12/16] Drivers: hv: balloon: keep track of where ha_region starts Date: Mon, 10 Apr 2017 23:14:28 +0530 Message-Id: <1491846272-14882-13-git-send-email-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1491846272-14882-1-git-send-email-sumit.semwal@linaro.org> References: <1491846272-14882-1-git-send-email-sumit.semwal@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Vitaly Kuznetsov [ Upstream commit 7cf3b79ec85ee1a5bbaaf936bb1d050dc652983b ] Windows 2012 (non-R2) does not specify hot add region in hot add requests and the logic in hot_add_req() is trying to find a 128Mb-aligned region covering the request. It may also happen that host's requests are not 128Mb aligned and the created ha_region will start before the first specified PFN. We can't online these non-present pages but we don't remember the real start of the region. This is a regression introduced by the commit 5abbbb75d733 ("Drivers: hv: hv_balloon: don't lose memory when onlining order is not natural"). While the idea of keeping the 'moving window' was wrong (as there is no guarantee that hot add requests come ordered) we should still keep track of covered_start_pfn. This is not a revert, the logic is different. Signed-off-by: Vitaly Kuznetsov Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sumit Semwal --- drivers/hv/hv_balloon.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c index 43af913..1542d89 100644 --- a/drivers/hv/hv_balloon.c +++ b/drivers/hv/hv_balloon.c @@ -430,13 +430,14 @@ struct dm_info_msg { * currently hot added. We hot add in multiples of 128M * chunks; it is possible that we may not be able to bring * online all the pages in the region. The range - * covered_end_pfn defines the pages that can + * covered_start_pfn:covered_end_pfn defines the pages that can * be brough online. */ struct hv_hotadd_state { struct list_head list; unsigned long start_pfn; + unsigned long covered_start_pfn; unsigned long covered_end_pfn; unsigned long ha_end_pfn; unsigned long end_pfn; @@ -682,7 +683,8 @@ static void hv_online_page(struct page *pg) list_for_each(cur, &dm_device.ha_region_list) { has = list_entry(cur, struct hv_hotadd_state, list); - cur_start_pgp = (unsigned long)pfn_to_page(has->start_pfn); + cur_start_pgp = (unsigned long) + pfn_to_page(has->covered_start_pfn); cur_end_pgp = (unsigned long)pfn_to_page(has->covered_end_pfn); if (((unsigned long)pg >= cur_start_pgp) && @@ -854,6 +856,7 @@ static unsigned long process_hot_add(unsigned long pg_start, list_add_tail(&ha_region->list, &dm_device.ha_region_list); ha_region->start_pfn = rg_start; ha_region->ha_end_pfn = rg_start; + ha_region->covered_start_pfn = pg_start; ha_region->covered_end_pfn = pg_start; ha_region->end_pfn = rg_start + rg_size; } From patchwork Mon Apr 10 17:44:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 97206 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp1456519obc; Mon, 10 Apr 2017 10:45:58 -0700 (PDT) X-Received: by 10.98.9.156 with SMTP id 28mr55844907pfj.199.1491846358819; Mon, 10 Apr 2017 10:45:58 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w21si14197944pgh.90.2017.04.10.10.45.58; Mon, 10 Apr 2017 10:45:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=@linaro.org; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753952AbdDJRps (ORCPT + 5 others); Mon, 10 Apr 2017 13:45:48 -0400 Received: from mail-pg0-f47.google.com ([74.125.83.47]:36854 "EHLO mail-pg0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753027AbdDJRpr (ORCPT ); Mon, 10 Apr 2017 13:45:47 -0400 Received: by mail-pg0-f47.google.com with SMTP id g2so107978822pge.3 for ; Mon, 10 Apr 2017 10:45:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1TLPeZEc4Qi9B+BSa4nJ8Fzi3r7Z+n8PCSQza3IaqFU=; b=Y72eJnox79OcnFL3u501i7mzrK7gEExVoEUOQgMyif/aw+MMihM1U2BBLNZQit+E1V Sfle/3iHePi2j0ykd12ynC/7yb657ODW9rOcir4Yu+fvD4kkxmFfGnDcSdfkXj7EAX51 NwF90V7TwjDIx2ML8wJTIYrhH4KoKASN8knvA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=1TLPeZEc4Qi9B+BSa4nJ8Fzi3r7Z+n8PCSQza3IaqFU=; b=IGgbJ2tg1B2h0J+O+nuqBJmHiEI2YUYWRgoiLYLcj/iYHky5gj/h/QucgbsGU2PhzL DBmU3WAH5I3AWapi35YoSSnpcPyVvOA3EwmfyiBnfpX7vJBzjdT35R8jPu9ZE74gWW66 4gM/cIVsmvoMSHB0cUcs/j6jdx/1zpxYa0qGg2hoNEim09Xd3pqTeba+wEDa2+SBmpeb oQF+kGpFFGJerRPY10yi7X257BTd5ipkFl1cA72PrnNQei1kWoRb83Z06Ri2O7Of1F75 0DY5DY9bla9V6WQdnkK6cc0xi+kU5aSdJKAb1jqC2BwLaVmJRmNigiPZLkLXSGRfwtbL BWLQ== X-Gm-Message-State: AFeK/H3eeQFn5wyhXZZf4I+Zi5EW+KY1vRx2ymLtweVvE38/YKej9I6gtdSP/Qy1KJpIbBZQ X-Received: by 10.98.50.71 with SMTP id y68mr24745867pfy.220.1491846346311; Mon, 10 Apr 2017 10:45:46 -0700 (PDT) Received: from phantom.lan ([106.51.225.38]) by smtp.gmail.com with ESMTPSA id y6sm768833pfa.83.2017.04.10.10.45.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Apr 2017 10:45:45 -0700 (PDT) From: Sumit Semwal To: stable@vger.kernel.org Cc: Vitaly Kuznetsov , "K . Y . Srinivasan" , Greg Kroah-Hartman , Sumit Semwal Subject: [PATCH for-4.4 13/16] Drivers: hv: balloon: account for gaps in hot add regions Date: Mon, 10 Apr 2017 23:14:29 +0530 Message-Id: <1491846272-14882-14-git-send-email-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1491846272-14882-1-git-send-email-sumit.semwal@linaro.org> References: <1491846272-14882-1-git-send-email-sumit.semwal@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Vitaly Kuznetsov [ Upstream commit cb7a5724c7e1bfb5766ad1c3beba14cc715991cf ] I'm observing the following hot add requests from the WS2012 host: hot_add_req: start_pfn = 0x108200 count = 330752 hot_add_req: start_pfn = 0x158e00 count = 193536 hot_add_req: start_pfn = 0x188400 count = 239616 As the host doesn't specify hot add regions we're trying to create 128Mb-aligned region covering the first request, we create the 0x108000 - 0x160000 region and we add 0x108000 - 0x158e00 memory. The second request passes the pfn_covered() check, we enlarge the region to 0x108000 - 0x190000 and add 0x158e00 - 0x188200 memory. The problem emerges with the third request as it starts at 0x188400 so there is a 0x200 gap which is not covered. As the end of our region is 0x190000 now it again passes the pfn_covered() check were we just adjust the covered_end_pfn and make it 0x188400 instead of 0x188200 which means that we'll try to online 0x188200-0x188400 pages but these pages were never assigned to us and we crash. We can't react to such requests by creating new hot add regions as it may happen that the whole suggested range falls into the previously identified 128Mb-aligned area so we'll end up adding nothing or create intersecting regions and our current logic doesn't allow that. Instead, create a list of such 'gaps' and check for them in the page online callback. Signed-off-by: Vitaly Kuznetsov Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sumit Semwal [sumits: cherry picked for 4.4.y] --- drivers/hv/hv_balloon.c | 131 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 94 insertions(+), 37 deletions(-) -- 2.7.4 diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c index 1542d89..354da7f 100644 --- a/drivers/hv/hv_balloon.c +++ b/drivers/hv/hv_balloon.c @@ -441,6 +441,16 @@ struct hv_hotadd_state { unsigned long covered_end_pfn; unsigned long ha_end_pfn; unsigned long end_pfn; + /* + * A list of gaps. + */ + struct list_head gap_list; +}; + +struct hv_hotadd_gap { + struct list_head list; + unsigned long start_pfn; + unsigned long end_pfn; }; struct balloon_state { @@ -596,18 +606,46 @@ static struct notifier_block hv_memory_nb = { .priority = 0 }; +/* Check if the particular page is backed and can be onlined and online it. */ +static void hv_page_online_one(struct hv_hotadd_state *has, struct page *pg) +{ + unsigned long cur_start_pgp; + unsigned long cur_end_pgp; + struct hv_hotadd_gap *gap; + + cur_start_pgp = (unsigned long)pfn_to_page(has->covered_start_pfn); + cur_end_pgp = (unsigned long)pfn_to_page(has->covered_end_pfn); -static void hv_bring_pgs_online(unsigned long start_pfn, unsigned long size) + /* The page is not backed. */ + if (((unsigned long)pg < cur_start_pgp) || + ((unsigned long)pg >= cur_end_pgp)) + return; + + /* Check for gaps. */ + list_for_each_entry(gap, &has->gap_list, list) { + cur_start_pgp = (unsigned long) + pfn_to_page(gap->start_pfn); + cur_end_pgp = (unsigned long) + pfn_to_page(gap->end_pfn); + if (((unsigned long)pg >= cur_start_pgp) && + ((unsigned long)pg < cur_end_pgp)) { + return; + } + } + + /* This frame is currently backed; online the page. */ + __online_page_set_limits(pg); + __online_page_increment_counters(pg); + __online_page_free(pg); +} + +static void hv_bring_pgs_online(struct hv_hotadd_state *has, + unsigned long start_pfn, unsigned long size) { int i; - for (i = 0; i < size; i++) { - struct page *pg; - pg = pfn_to_page(start_pfn + i); - __online_page_set_limits(pg); - __online_page_increment_counters(pg); - __online_page_free(pg); - } + for (i = 0; i < size; i++) + hv_page_online_one(has, pfn_to_page(start_pfn + i)); } static void hv_mem_hot_add(unsigned long start, unsigned long size, @@ -684,26 +722,24 @@ static void hv_online_page(struct page *pg) list_for_each(cur, &dm_device.ha_region_list) { has = list_entry(cur, struct hv_hotadd_state, list); cur_start_pgp = (unsigned long) - pfn_to_page(has->covered_start_pfn); - cur_end_pgp = (unsigned long)pfn_to_page(has->covered_end_pfn); + pfn_to_page(has->start_pfn); + cur_end_pgp = (unsigned long)pfn_to_page(has->end_pfn); - if (((unsigned long)pg >= cur_start_pgp) && - ((unsigned long)pg < cur_end_pgp)) { - /* - * This frame is currently backed; online the - * page. - */ - __online_page_set_limits(pg); - __online_page_increment_counters(pg); - __online_page_free(pg); - } + /* The page belongs to a different HAS. */ + if (((unsigned long)pg < cur_start_pgp) || + ((unsigned long)pg >= cur_end_pgp)) + continue; + + hv_page_online_one(has, pg); + break; } } -static bool pfn_covered(unsigned long start_pfn, unsigned long pfn_cnt) +static int pfn_covered(unsigned long start_pfn, unsigned long pfn_cnt) { struct list_head *cur; struct hv_hotadd_state *has; + struct hv_hotadd_gap *gap; unsigned long residual, new_inc; if (list_empty(&dm_device.ha_region_list)) @@ -718,6 +754,24 @@ static bool pfn_covered(unsigned long start_pfn, unsigned long pfn_cnt) */ if (start_pfn < has->start_pfn || start_pfn >= has->end_pfn) continue; + + /* + * If the current start pfn is not where the covered_end + * is, create a gap and update covered_end_pfn. + */ + if (has->covered_end_pfn != start_pfn) { + gap = kzalloc(sizeof(struct hv_hotadd_gap), GFP_ATOMIC); + if (!gap) + return -ENOMEM; + + INIT_LIST_HEAD(&gap->list); + gap->start_pfn = has->covered_end_pfn; + gap->end_pfn = start_pfn; + list_add_tail(&gap->list, &has->gap_list); + + has->covered_end_pfn = start_pfn; + } + /* * If the current hot add-request extends beyond * our current limit; extend it. @@ -734,19 +788,10 @@ static bool pfn_covered(unsigned long start_pfn, unsigned long pfn_cnt) has->end_pfn += new_inc; } - /* - * If the current start pfn is not where the covered_end - * is, update it. - */ - - if (has->covered_end_pfn != start_pfn) - has->covered_end_pfn = start_pfn; - - return true; - + return 1; } - return false; + return 0; } static unsigned long handle_pg_range(unsigned long pg_start, @@ -785,6 +830,8 @@ static unsigned long handle_pg_range(unsigned long pg_start, if (pgs_ol > pfn_cnt) pgs_ol = pfn_cnt; + has->covered_end_pfn += pgs_ol; + pfn_cnt -= pgs_ol; /* * Check if the corresponding memory block is already * online by checking its last previously backed page. @@ -793,10 +840,8 @@ static unsigned long handle_pg_range(unsigned long pg_start, */ if (start_pfn > has->start_pfn && !PageReserved(pfn_to_page(start_pfn - 1))) - hv_bring_pgs_online(start_pfn, pgs_ol); + hv_bring_pgs_online(has, start_pfn, pgs_ol); - has->covered_end_pfn += pgs_ol; - pfn_cnt -= pgs_ol; } if ((has->ha_end_pfn < has->end_pfn) && (pfn_cnt > 0)) { @@ -834,13 +879,19 @@ static unsigned long process_hot_add(unsigned long pg_start, unsigned long rg_size) { struct hv_hotadd_state *ha_region = NULL; + int covered; if (pfn_cnt == 0) return 0; - if (!dm_device.host_specified_ha_region) - if (pfn_covered(pg_start, pfn_cnt)) + if (!dm_device.host_specified_ha_region) { + covered = pfn_covered(pg_start, pfn_cnt); + if (covered < 0) + return 0; + + if (covered) goto do_pg_range; + } /* * If the host has specified a hot-add range; deal with it first. @@ -852,6 +903,7 @@ static unsigned long process_hot_add(unsigned long pg_start, return 0; INIT_LIST_HEAD(&ha_region->list); + INIT_LIST_HEAD(&ha_region->gap_list); list_add_tail(&ha_region->list, &dm_device.ha_region_list); ha_region->start_pfn = rg_start; @@ -1584,6 +1636,7 @@ static int balloon_remove(struct hv_device *dev) struct hv_dynmem_device *dm = hv_get_drvdata(dev); struct list_head *cur, *tmp; struct hv_hotadd_state *has; + struct hv_hotadd_gap *gap, *tmp_gap; if (dm->num_pages_ballooned != 0) pr_warn("Ballooned pages: %d\n", dm->num_pages_ballooned); @@ -1600,6 +1653,10 @@ static int balloon_remove(struct hv_device *dev) #endif list_for_each_safe(cur, tmp, &dm->ha_region_list) { has = list_entry(cur, struct hv_hotadd_state, list); + list_for_each_entry_safe(gap, tmp_gap, &has->gap_list, list) { + list_del(&gap->list); + kfree(gap); + } list_del(&has->list); kfree(has); } From patchwork Mon Apr 10 17:44:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 97212 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp1456543obc; Mon, 10 Apr 2017 10:46:04 -0700 (PDT) X-Received: by 10.99.125.12 with SMTP id y12mr7328491pgc.146.1491846364045; Mon, 10 Apr 2017 10:46:04 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w21si14197944pgh.90.2017.04.10.10.46.03; Mon, 10 Apr 2017 10:46:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=@linaro.org; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754077AbdDJRqB (ORCPT + 5 others); Mon, 10 Apr 2017 13:46:01 -0400 Received: from mail-pg0-f51.google.com ([74.125.83.51]:35045 "EHLO mail-pg0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754010AbdDJRqA (ORCPT ); Mon, 10 Apr 2017 13:46:00 -0400 Received: by mail-pg0-f51.google.com with SMTP id 81so109370983pgh.2 for ; Mon, 10 Apr 2017 10:45:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=b/4EdhaVvM16veNbBlzw6pKOeSID24uDb6DOWoRvntM=; b=PheRkK8rDXK4a8si1Mhf3UFu/BfP3vqac3rk2CgaoFoj2aSOFjvmMVL/oSoe9qXqCW LU6G32+qQAorn3eaYQk9eBvYYPf1jabhNvysIXPLgcKmv5xrjy8JdXlNGqDyeC13T3Ze jAydDCl577OsgdNVeecECJpCSRybH1DqF6T7E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=b/4EdhaVvM16veNbBlzw6pKOeSID24uDb6DOWoRvntM=; b=lMT2a8b9x+lAveBFo6QBIQry6ul1dam3niZbtZOxKwph4rN1BAlotrYfOL724i9Jn9 XSsBqeSGHKqoZgGFSbYGjbyFv1jnprDGN7OWkKiIMTnBVwtOtQ+YoxSXxGEGHXktULxf s0NUozxR3fjuJhBWaUtq4vDycroOuZmZ63WacZdzWAGzH6wRNf2lT7rrwb6KZ1Ekm7TF vjojLf+N0FfvcWelojg+ef3N0Pm9j3uHs1Fxl7YEOq7DPx4JiXNv227ByGckiGqVoUbS PblO5C5pULTBDGiiS6PyFsRfY+h5Wgu/PCVmddWuEOd9k9r4bWYlIOVc4iJMyCv4zb7b wetA== X-Gm-Message-State: AFeK/H3GlQPBzoirNT/vi55PwOCYxHEHa2Arx6L3HoH1OLLzOg+PAS0epgUXBkmFbufkTWCi X-Received: by 10.98.219.3 with SMTP id f3mr54626223pfg.181.1491846349343; Mon, 10 Apr 2017 10:45:49 -0700 (PDT) Received: from phantom.lan ([106.51.225.38]) by smtp.gmail.com with ESMTPSA id y6sm768833pfa.83.2017.04.10.10.45.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Apr 2017 10:45:48 -0700 (PDT) From: Sumit Semwal To: stable@vger.kernel.org Cc: Vitaly Kuznetsov , "K . Y . Srinivasan" , Greg Kroah-Hartman , Sumit Semwal Subject: [PATCH for-4.4 14/16] hv: don't reset hv_context.tsc_page on crash Date: Mon, 10 Apr 2017 23:14:30 +0530 Message-Id: <1491846272-14882-15-git-send-email-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1491846272-14882-1-git-send-email-sumit.semwal@linaro.org> References: <1491846272-14882-1-git-send-email-sumit.semwal@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Vitaly Kuznetsov [ Upstream commit 56ef6718a1d8d77745033c5291e025ce18504159 ] It may happen that secondary CPUs are still alive and resetting hv_context.tsc_page will cause a consequent crash in read_hv_clock_tsc() as we don't check for it being not NULL there. It is safe as we're not freeing this page anyways. Signed-off-by: Vitaly Kuznetsov Signed-off-by: K. Y. Srinivasan Cc: Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sumit Semwal --- drivers/hv/hv.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index ddbf7e7..8ce1f2e 100644 --- a/drivers/hv/hv.c +++ b/drivers/hv/hv.c @@ -305,9 +305,10 @@ void hv_cleanup(bool crash) hypercall_msr.as_uint64 = 0; wrmsrl(HV_X64_MSR_REFERENCE_TSC, hypercall_msr.as_uint64); - if (!crash) + if (!crash) { vfree(hv_context.tsc_page); - hv_context.tsc_page = NULL; + hv_context.tsc_page = NULL; + } } #endif } From patchwork Mon Apr 10 17:44:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 97211 Delivered-To: patch@linaro.org Received: by 10.182.246.10 with SMTP id xs10csp1456528obc; Mon, 10 Apr 2017 10:45:59 -0700 (PDT) X-Received: by 10.84.217.153 with SMTP id p25mr31251390pli.188.1491846359901; Mon, 10 Apr 2017 10:45:59 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w21si14197944pgh.90.2017.04.10.10.45.59; Mon, 10 Apr 2017 10:45:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=@linaro.org; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754041AbdDJRp5 (ORCPT + 5 others); Mon, 10 Apr 2017 13:45:57 -0400 Received: from mail-pg0-f43.google.com ([74.125.83.43]:32899 "EHLO mail-pg0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754010AbdDJRp4 (ORCPT ); Mon, 10 Apr 2017 13:45:56 -0400 Received: by mail-pg0-f43.google.com with SMTP id x125so109394705pgb.0 for ; Mon, 10 Apr 2017 10:45:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4FgTjXrKB+1qieC2Ko4wiZ96yYb+24Bg8mgSFe1+KO4=; b=Pj/fO2DL4/XzF3P63Hu73qNDRsPXGU5eBAOsUTUKXoFaxG7aPHBf/IFgHmfuqdASGM g7AfcspscV//HW/ogOxw6Da2e47TZCjzq6p5LAjGuXOQKb7eLLIEWcuJjvGqGyVzsTUF fJwzSDsawI4kzmd9FGMru8tqEBmkNUws9zZlY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4FgTjXrKB+1qieC2Ko4wiZ96yYb+24Bg8mgSFe1+KO4=; b=f944xtjBzdMBKBAi3qfKSg0tVRdr4+GlS4oauRxiu7ZE8V2OIK/ZXnSr/AbcDdgVRd abjlGVEu8c1z+wCxSkQAXHIwBlCct9H5KYZ2NyvjSEdyx2eljAdQGASnW/3Fy7bOq0S7 qnD2SQQzD6+rAIINrzjHFImzQcCmkW5lrU4KTAXkF26Pufz5oMDM7uWualuTIc8p7hKz UcbKV4X3cHGYO6w3KjPRe1x0IUz5wSLg3OrGq8SBaB0Uw3AjIfHzqQXiFeIQNLRHR74I /tRx41viEVYLXXbjQdZNvjSBw/6zpYmUFd1Heaq9JcX+kYLAZiqyu5YE3xrZIuKL8LC6 4akA== X-Gm-Message-State: AFeK/H3TBO0Uovx3hIaMs/Vbr2NVLJe9nqQbuS89t395bcQMPhmOiSnNVm3fP/hNNQ/OCnxW X-Received: by 10.98.107.194 with SMTP id g185mr56907525pfc.22.1491846355644; Mon, 10 Apr 2017 10:45:55 -0700 (PDT) Received: from phantom.lan ([106.51.225.38]) by smtp.gmail.com with ESMTPSA id y6sm768833pfa.83.2017.04.10.10.45.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Apr 2017 10:45:54 -0700 (PDT) From: Sumit Semwal To: stable@vger.kernel.org Cc: Guenter Roeck , Douglas Anderson , Greg Kroah-Hartman , Sumit Semwal Subject: [PATCH for-4.4 16/16] usb: hub: Wait for connection to be reestablished after port reset Date: Mon, 10 Apr 2017 23:14:32 +0530 Message-Id: <1491846272-14882-17-git-send-email-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1491846272-14882-1-git-send-email-sumit.semwal@linaro.org> References: <1491846272-14882-1-git-send-email-sumit.semwal@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Guenter Roeck [ Upstream commit 22547c4cc4fe20698a6a85a55b8788859134b8e4 ] On a system with a defective USB device connected to an USB hub, an endless sequence of port connect events was observed. The sequence of events as observed is as follows: - Port reports connected event (port status=USB_PORT_STAT_CONNECTION). - Event handler debounces port and resets it by calling hub_port_reset(). - hub_port_reset() calls hub_port_wait_reset() to wait for the reset to complete. - The reset completes, but USB_PORT_STAT_CONNECTION is not immediately set in the port status register. - hub_port_wait_reset() returns -ENOTCONN. - Port initialization sequence is aborted. - A few milliseconds later, the port again reports a connected event, and the sequence repeats. This continues either forever or, randomly, stops if the connection is already re-established when the port status is read. It results in a high rate of udev events. This in turn destabilizes userspace since the above sequence holds the device mutex pretty much continuously and prevents userspace from actually reading the device status. To prevent the problem from happening, let's wait for the connection to be re-established after a port reset. If the device was actually disconnected, the code will still return an error, but it will do so only after the long reset timeout. Cc: Douglas Anderson Signed-off-by: Guenter Roeck Acked-by: Alan Stern Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sumit Semwal --- drivers/usb/core/hub.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 9e62c93..7c2d87b 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -2602,8 +2602,15 @@ static int hub_port_wait_reset(struct usb_hub *hub, int port1, if (ret < 0) return ret; - /* The port state is unknown until the reset completes. */ - if (!(portstatus & USB_PORT_STAT_RESET)) + /* + * The port state is unknown until the reset completes. + * + * On top of that, some chips may require additional time + * to re-establish a connection after the reset is complete, + * so also wait for the connection to be re-established. + */ + if (!(portstatus & USB_PORT_STAT_RESET) && + (portstatus & USB_PORT_STAT_CONNECTION)) break; /* switch to the long delay after two short delay failures */