Received: by 10.213.65.68 with SMTP id h4csp1726953imn; Mon, 19 Mar 2018 11:33:45 -0700 (PDT) X-Google-Smtp-Source: AG47ELu9LPXVX8/TgTeV4IvUIQU1AvSGv27Ek9oMHt3kS5zwzN1yHDfNzeDqR39kYXc6eXTd/wHv X-Received: by 10.98.204.12 with SMTP id a12mr10409488pfg.3.1521484425593; Mon, 19 Mar 2018 11:33:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521484425; cv=none; d=google.com; s=arc-20160816; b=rWkXh2POXxyco2FzP+9bgpPfVnGIymMTH2oRcgATv4W0VdM/JgjB/xwsGjUDvDTivQ OGyozUHcgD8P30C5tDXq78a/12LSKjhTYmPUfWq2569GCd0aHxxBvsUR/SYvAIwkBQe7 hItABOsyejnVSpPeYlmYRokVZ9jDePJBJJ2/x2EHEErrN9IZDQ6u6Zij49HsmjxtLY32 EzyowjReIOannv/52BOcP7aqudeEDzLnRhEE2zfC4FAcW9Q8XRHqxIA0EwBJ83EO+Rgl of/jtp0DVn6gzOcxjnUdFHvF0z1PjpoTmhfxv/alHk8soTylvxUikOhaQA/FNywn/SKl +iCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=7aKn6AMJzX80FyHNG5nWTpVnWwkklnobAseqq6adDHc=; b=e87j+9g+xJsIb/kHDX7UiBFmZc2xRNME+wbLi3oDSPtyvK8g4HICL6z7ZvAmMUIGnh mGlddoW9PtF44AFCfRw6UhlHZuhbZg7EYtluyQ0YDnNNx9UStmFMMInT4ebCA4GLOyJc UALzaM+BihlNWp5roRUMlfHzUTn0sUpXwfAlRzimFoggQ1QXp5HV+PLI3EqWxN/yvVH0 SaD/T+BiiZkB65Seecr3yMDWRcYiyZETNN+AR8P2lzU9+Qx6rh17npc3KznOveBuWFxu o1nI9MzYHPS5qLMm2jDJGQtg3DUowyTgEl8I7cV5qzQ5WxLxoYK3veh+DDBp+TbztY5s U4vw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 80si311286pfj.22.2018.03.19.11.33.31; Mon, 19 Mar 2018 11:33:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; 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 S1032045AbeCSSbB (ORCPT + 99 others); Mon, 19 Mar 2018 14:31:01 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:53376 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032003AbeCSSa5 (ORCPT ); Mon, 19 Mar 2018 14:30:57 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 0034B1278; Mon, 19 Mar 2018 18:30:56 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tejun Heo , Dennis Dalessandro , Mike Marciniszyn , linux-rdma@vger.kernel.org, Linus Torvalds Subject: [PATCH 4.14 28/41] RDMAVT: Fix synchronization around percpu_ref Date: Mon, 19 Mar 2018 19:08:28 +0100 Message-Id: <20180319180734.083478211@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319180732.195217948@linuxfoundation.org> References: <20180319180732.195217948@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tejun Heo commit 74b44bbe80b4c62113ac1501482ea1ee40eb9d67 upstream. rvt_mregion uses percpu_ref for reference counting and RCU to protect accesses from lkey_table. When a rvt_mregion needs to be freed, it first gets unregistered from lkey_table and then rvt_check_refs() is called to wait for in-flight usages before the rvt_mregion is freed. rvt_check_refs() seems to have a couple issues. * It has a fast exit path which tests percpu_ref_is_zero(). However, a percpu_ref reading zero doesn't mean that the object can be released. In fact, the ->release() callback might not even have started executing yet. Proceeding with freeing can lead to use-after-free. * lkey_table is RCU protected but there is no RCU grace period in the free path. percpu_ref uses RCU internally but it's sched-RCU whose grace periods are different from regular RCU. Also, it generally isn't a good idea to depend on internal behaviors like this. To address the above issues, this patch removes the fast exit and adds an explicit synchronize_rcu(). Signed-off-by: Tejun Heo Acked-by: Dennis Dalessandro Cc: Mike Marciniszyn Cc: linux-rdma@vger.kernel.org Cc: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- drivers/infiniband/sw/rdmavt/mr.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) --- a/drivers/infiniband/sw/rdmavt/mr.c +++ b/drivers/infiniband/sw/rdmavt/mr.c @@ -489,11 +489,13 @@ static int rvt_check_refs(struct rvt_mre unsigned long timeout; struct rvt_dev_info *rdi = ib_to_rvt(mr->pd->device); - if (percpu_ref_is_zero(&mr->refcount)) - return 0; - /* avoid dma mr */ - if (mr->lkey) + if (mr->lkey) { + /* avoid dma mr */ rvt_dereg_clean_qps(mr); + /* @mr was indexed on rcu protected @lkey_table */ + synchronize_rcu(); + } + timeout = wait_for_completion_timeout(&mr->comp, 5 * HZ); if (!timeout) { rvt_pr_err(rdi,