Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4492628ybx; Mon, 4 Nov 2019 14:19:17 -0800 (PST) X-Google-Smtp-Source: APXvYqxU36wvU7TpIAj0Hy57lZDn7WjwDSF7QP28U/mI1qOlWxbtIH5LFjBvpsUnfURaqsOvX5E2 X-Received: by 2002:a50:ac2c:: with SMTP id v41mr31535397edc.11.1572905957654; Mon, 04 Nov 2019 14:19:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572905957; cv=none; d=google.com; s=arc-20160816; b=ffofZhZHyRy/Wj21eKrzORD3USEVw8PZqmze/X8K8VbdaBlOKi1X07uPvCb5IkNbf2 QtZ4TRkjw1kO1eRpO+a2+T1H9YpF1yT5L36sHHLSAwPMD/rJ7hbVWMHZ0rDHNKLlRMee NaWReb5zxAch/hK5PsjSN2uSAibeUQ4qqfgFCpN/K+PAjne6X/PxsYWUV5hEA6dOnIXQ 6AEcrdY5zgTxtcnntjmWnj3EvwbUeK/5T5n2YK4FbPaZ9hWC5+cVu1gaow7h0ZFDWXIO W88NRPXlnMDnkp2wZCYRWicr2yzTcBVnb33Ok8It9MzKushSh9E3J9AnDO2uhS13rNKA dsFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=iEEEcv3vU26+ziXUjMXJ4VVBOMycEu1IBuNa5QH6XgE=; b=zGd17kNl3C5WRVyd4hpIvi2YyWpNsPJD8M7BW1lcc12bucU3qKMV5ZR+rN7R/Lbww4 lJRf4hl3tpzzawuipkT/eGm4rP0VLEzHeDJWyfFn1+KiN3tSnn8IB7JHkFdNo+XWlEtI gxvou5ZmV594QMhhI4p5kb7wXS6wJ/l1yzRiQRyftg8UXvVWrZ90jK6pvI3VURXQebz5 cTBH9mS8BcotKNeCifpNDSKNh/Ix2SncEtddukfZBt/rat/LiGg3KrmencTFWDP29rw+ bIVCW7SVSEV7QTf83jnKsH+BlbAPNeYeuD4npsXMtEyUonhfrzjVa1NmfUYOvUtuG6IZ JY5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fxnxZ83x; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gz10si1848604ejb.32.2019.11.04.14.18.42; Mon, 04 Nov 2019 14:19:17 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fxnxZ83x; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390328AbfKDWPm (ORCPT + 99 others); Mon, 4 Nov 2019 17:15:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:37162 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389861AbfKDWFl (ORCPT ); Mon, 4 Nov 2019 17:05:41 -0500 Received: from localhost (6.204-14-84.ripe.coltfrance.com [84.14.204.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 06D5E20650; Mon, 4 Nov 2019 22:05:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572905140; bh=ZN/G0DCHvmoMD9ezTpP+BUSAzatO5A2Gky/EnJq3BiM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fxnxZ83xgubDV/4D5rhhFjRdUoS7VnPZ0yvmEZ/ybuzEBsSiSqgxUeGZh8LPm8JUk 033jhslRSXAbdOc+kFPP8dc/q0oVQY+g5RR9C2yKwsqKlXqRKKy7vVbSErHIBr9cWN S0sQkEE7KZ6u2PE9EG18ORdbhBFUHKSnEEvNBACI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Artemy Kovalyov , Jason Gunthorpe , Sasha Levin Subject: [PATCH 5.3 041/163] RDMA/mlx5: Order num_pending_prefetch properly with synchronize_srcu Date: Mon, 4 Nov 2019 22:43:51 +0100 Message-Id: <20191104212143.254999850@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191104212140.046021995@linuxfoundation.org> References: <20191104212140.046021995@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jason Gunthorpe [ Upstream commit aa116b810ac9077a263ed8679fb4d595f180e0eb ] During destroy setting live = 0 and then synchronize_srcu() prevents num_pending_prefetch from incrementing, and also, ensures that all work holding that count is queued on the WQ. Testing before causes races of the form: CPU0 CPU1 dereg_mr() mlx5_ib_advise_mr_prefetch() srcu_read_lock() num_pending_prefetch_inc() if (!live) live = 0 atomic_read() == 0 // skip flush_workqueue() atomic_inc() queue_work(); srcu_read_unlock() WARN_ON(atomic_read()) // Fails Swap the order so that the synchronize_srcu() prevents this. Fixes: a6bc3875f176 ("IB/mlx5: Protect against prefetch of invalid MR") Link: https://lore.kernel.org/r/20191001153821.23621-5-jgg@ziepe.ca Reviewed-by: Artemy Kovalyov Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/hw/mlx5/mr.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/hw/mlx5/mr.c b/drivers/infiniband/hw/mlx5/mr.c index c4ba8838d2c46..96c8a6835592d 100644 --- a/drivers/infiniband/hw/mlx5/mr.c +++ b/drivers/infiniband/hw/mlx5/mr.c @@ -1591,13 +1591,14 @@ static void dereg_mr(struct mlx5_ib_dev *dev, struct mlx5_ib_mr *mr) */ mr->live = 0; + /* Wait for all running page-fault handlers to finish. */ + synchronize_srcu(&dev->mr_srcu); + /* dequeue pending prefetch requests for the mr */ if (atomic_read(&mr->num_pending_prefetch)) flush_workqueue(system_unbound_wq); WARN_ON(atomic_read(&mr->num_pending_prefetch)); - /* Wait for all running page-fault handlers to finish. */ - synchronize_srcu(&dev->mr_srcu); /* Destroy all page mappings */ if (umem_odp->page_list) mlx5_ib_invalidate_range(umem_odp, -- 2.20.1