Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp273055pxx; Wed, 28 Oct 2020 04:42:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwShvSBY0nAcx8VGa4GvvH+//uWrZ1ZAdwBP0nEj+RF5HPrAb6mB3VS+1OhoWTkVbQvJnv0 X-Received: by 2002:a50:d65c:: with SMTP id c28mr6988247edj.279.1603885336646; Wed, 28 Oct 2020 04:42:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603885336; cv=none; d=google.com; s=arc-20160816; b=IgNZ5sdRrTEyx+oRG62hbt+0mb4DC4mN9GufGLMwiy25uhGAMv+5CVQArHQUN3iYYw XyV3J33t/n2eIne9v9SE+6lF+KnfUtIH/4Um9chSljNLKxgucx3ATbhiiVlSbx4ve90H +Fux2Q4TjOl7EG0TyGv1Ip/0u4e3oj0Cv5RYfaJtE09KMZSVz32sQwbHx0L2PUT8d1L2 CHwzx7l/i0PVISr6UC8sGxeDAsfktpV/86bhYqbn6gHFPguBx9xL7GyCHDqxjQSb/Cq4 eyD3F7Qq0E6f6H3rCFhxFpJjysW8TIwAMjgvpa1+ZXJX2U88sL3qh+2gsKKioip3sXti QdKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=u5gN4i9WAqDCEpWgBM7oGoMVtrr4Du64QWAM2ZoaBEk=; b=Y2esRKHWEh9VCU8+cXA/x6L0ObCGAqyA8/6xK+zt5oGKb3tiNl6hLQSB1SjShFThMM bWGhmNqkvUs46PqoAwY4CquzS+4EOFq9Nm6KGKDpt2grC9/qJIHq9pMa6E0eOzszT/DI cg1DY+SmnPPKRB7m28r82m7/LpYfGAGyON231AMoQHoVzq/MbL52LYX3F/iBfJtc56V4 +gn8mhoEIPPo7PTJjXmhnEEVcRbqKA/S/segKva5V9S9jiU8YED9SoCG6n6nA/qot0Xp dazKGk08eAatEAQYFHPkogvuXSaNHpi8VqfHZoN6A36YJ10JEjlwlMqzq/Tw16fIxdsn ka8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=z32WtevV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x26si2664388eds.99.2020.10.28.04.41.54; Wed, 28 Oct 2020 04:42:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=z32WtevV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1794217AbgJ0PKg (ORCPT + 99 others); Tue, 27 Oct 2020 11:10:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:37202 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1789789AbgJ0PCx (ORCPT ); Tue, 27 Oct 2020 11:02:53 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 A81AC2071A; Tue, 27 Oct 2020 15:02:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603810973; bh=QZrPLNJpuWsmNkV0nyFp3PfJ1PGCgZCjAPJZR4EMZPU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=z32WtevVIoNkp2ApYwWlR0nJcrBV45g421+MnDeWl4/UGqW+RszUGMBwQRoweVZzJ YOLLbPhvdIzocaCdKhZGqgXGMpPUe0/+ZD0KI7mDFNfLZCkSt4mfeWj89aZv2/D3X3 QdRim7bDmrauPpur5ULVyxt2wET1iZ05aGCSJaaM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Leon Romanovsky , Jason Gunthorpe , Sasha Levin Subject: [PATCH 5.8 329/633] RDMA/ucma: Fix locking for ctx->events_reported Date: Tue, 27 Oct 2020 14:51:12 +0100 Message-Id: <20201027135538.113663554@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135522.655719020@linuxfoundation.org> References: <20201027135522.655719020@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jason Gunthorpe [ Upstream commit 98837c6c3d7285f6eca86480b6f7fac6880e27a8 ] This value is locked under the file->mut, ensure it is held whenever touching it. The case in ucma_migrate_id() is a race, while in ucma_free_uctx() it is already not possible for the write side to run, the movement is just for clarity. Fixes: 88314e4dda1e ("RDMA/cma: add support for rdma_migrate_id()") Link: https://lore.kernel.org/r/20200818120526.702120-10-leon@kernel.org Signed-off-by: Leon Romanovsky Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/core/ucma.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/infiniband/core/ucma.c b/drivers/infiniband/core/ucma.c index d03dacaef7880..cf283b70bf877 100644 --- a/drivers/infiniband/core/ucma.c +++ b/drivers/infiniband/core/ucma.c @@ -586,6 +586,7 @@ static int ucma_free_ctx(struct ucma_context *ctx) list_move_tail(&uevent->list, &list); } list_del(&ctx->list); + events_reported = ctx->events_reported; mutex_unlock(&ctx->file->mut); list_for_each_entry_safe(uevent, tmp, &list, list) { @@ -595,7 +596,6 @@ static int ucma_free_ctx(struct ucma_context *ctx) kfree(uevent); } - events_reported = ctx->events_reported; mutex_destroy(&ctx->mutex); kfree(ctx); return events_reported; @@ -1678,7 +1678,9 @@ static ssize_t ucma_migrate_id(struct ucma_file *new_file, cur_file = ctx->file; if (cur_file == new_file) { + mutex_lock(&cur_file->mut); resp.events_reported = ctx->events_reported; + mutex_unlock(&cur_file->mut); goto response; } -- 2.25.1