From patchwork Fri May 31 01:17:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 165473 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp64496ili; Thu, 30 May 2019 18:18:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqzPr3pYgkRdiHnRMtJRnXr/UzNKiZYuT5KzEY2qXdRuklt8ajgXoiYpMlsBjuaDsi/ZWUX9 X-Received: by 2002:a63:e250:: with SMTP id y16mr6157552pgj.392.1559265500863; Thu, 30 May 2019 18:18:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559265500; cv=none; d=google.com; s=arc-20160816; b=pBIHu+u7JPCQwAsQv72DGxt6T5iAy2ZMlLfwOl+ZXmra5FpQOswyKD0QOXPt6f5h7f d3O81S9oQC/s6JTpZwkXza5Eed7siX/YX6e2ZJVm8o8DqpUecVBICTS42NtSXoIDRByF W0+5fw09+V9OHNd0fLnBndCShO82OempYsEshfHLtg3SkJ2RuX02v3quduw6J9JJB5HR vUJuIV8DWBsG0y5lu4xVStIoPV+8fLmDJAsTrA07y5W5NLEiaA0+5ZU2CAzbhh/0WB33 i5PB2fQrORjRct7xSfoFdh2JJ4uSG/gBe76qPwOkFmZWqqjghYByHcpJPYoI1jzbIXAZ 8rtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=uBw4EEYJCi6dX24BKwZjutyozmTL8aJL03Jek8XZUz0=; b=Ml4A5gjOmH9ng+on6FhL1KqiouvxIIKdLZhqZ3+NGsPwEE/Af3N6auwDVbBGJDp36l ClTASzf5OzFt/SV2OCXjKT05dhG2ERePaS3YYFYhQpyoyHllptLlP6WdrKTSYot3Tsu1 OTIqE1oEupmGmw2a51FRhNPypDcLV+LmFxYgtSpRG5f9ylRwScIj3Wn8rYGLmjMGs9yR jdqDaJuJtvA7dKpd0RVyQbWAvMpymuTqJRj6NhDjV7ULo37g4Yphw3zqGramOQcGm19a kinT9rimBT6+Zow4tebkxPKz1wyoHAt8kKqd4PvzPFQv0J4dImiLJvyhJ9CG78YMa7mN nvow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=p5yjRe95; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o5si4016743pjp.77.2019.05.30.18.18.20; Thu, 30 May 2019 18:18:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of netdev-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 header.s=google header.b=p5yjRe95; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-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 S1726952AbfEaBSU (ORCPT + 9 others); Thu, 30 May 2019 21:18:20 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:33425 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726879AbfEaBSC (ORCPT ); Thu, 30 May 2019 21:18:02 -0400 Received: by mail-pl1-f194.google.com with SMTP id g21so3289133plq.0 for ; Thu, 30 May 2019 18:18:01 -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=uBw4EEYJCi6dX24BKwZjutyozmTL8aJL03Jek8XZUz0=; b=p5yjRe95hE2L74zPVNLK1TX9rAuxSEKw3QPLcPDoNubJMlT8hW3msrbX9RYT1IzJor BBOcGMnIAgGxczRAO2tPepHxmRSrnAU8U/aNcQ2r3LN7L7jrsRn31ZBqQkRtm1o6Z+EK eyg0d09rveIz8M9od3xJfx4TrDnlkr8Nwd4dSJzeiMxLzpO+Ox8O994euhq7inpDmEuv 5rqiS/0xocH1ZN3jnv7Lp9hxF5gtqtZmWP6EGhOUPbR5GhoTTStf/YYDDvJstdN5jgU9 n9Xlr1D3Po6cuX+8T8k8d9p1hyMk2Au6MbIKt84oZRkslaQtKwvaRACbzYyi13FgM7c7 MKCA== 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=uBw4EEYJCi6dX24BKwZjutyozmTL8aJL03Jek8XZUz0=; b=KIV9qh8NZqNHF0/CoQHFRTN54is7af2plYQ8XpzMki8GmnMdhuKnSI7oNDNCwhikZ8 CM1ZB6zdrJjpLNGhRnw14QuHLF3Onh4kjbjNvdPjdTx66liBhIZJcxLz0QzkZUcCP2F9 i4sv21RCBWEgh8ASr0uoQfxEEwtwlN4ax5VDdkdgbOQVFhoiV5/J90wc0cQ3HAsgwRwr yeye3PGoUkiIEygumzFyaHLy04TShLvQUJpBHpQmwG+D72073WTmtOpVWCXssx6lBBxN MJQC5g0BW0/rKClZ6VwBvO77Tn9hXfc3saW2xfqXRwsMoIy7X6/siD8x1bQAj8YMGC8v rBhw== X-Gm-Message-State: APjAAAUhNZEeZWktrCmYb3QGnvXLoKntxeLm0YfOJkK064j7wwpPfa4H qVNEa8G/UNtjNhiaF7I9cKEiS7YZSTg= X-Received: by 2002:a17:902:8e8a:: with SMTP id bg10mr6206452plb.247.1559265481358; Thu, 30 May 2019 18:18:01 -0700 (PDT) Received: from localhost.localdomain (104-188-17-28.lightspeed.sndgca.sbcglobal.net. [104.188.17.28]) by smtp.gmail.com with ESMTPSA id j20sm1819042pff.183.2019.05.30.18.18.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 May 2019 18:18:00 -0700 (PDT) From: Bjorn Andersson To: "David S. Miller" Cc: Arun Kumar Neelakantam , Chris Lew , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: [PATCH v2 4/5] net: qrtr: Make qrtr_port_lookup() use RCU Date: Thu, 30 May 2019 18:17:52 -0700 Message-Id: <20190531011753.11840-5-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190531011753.11840-1-bjorn.andersson@linaro.org> References: <20190531011753.11840-1-bjorn.andersson@linaro.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The important part of qrtr_port_lookup() wrt synchronization is that the function returns a reference counted struct qrtr_sock, or fail. As such we need only to ensure that an decrement of the object's refcount happens inbetween the finding of the object in the idr and qrtr_port_lookup()'s own increment of the object. By using RCU and putting a synchronization point after we remove the mapping from the idr, but before it can be released we achieve this - with the benefit of not having to hold the mutex in qrtr_port_lookup(). Signed-off-by: Bjorn Andersson --- Changes since v1: - None net/qrtr/qrtr.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) -- 2.18.0 diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c index fdee32b979fe..7f048b9e02fb 100644 --- a/net/qrtr/qrtr.c +++ b/net/qrtr/qrtr.c @@ -645,11 +645,11 @@ static struct qrtr_sock *qrtr_port_lookup(int port) if (port == QRTR_PORT_CTRL) port = 0; - mutex_lock(&qrtr_port_lock); + rcu_read_lock(); ipc = idr_find(&qrtr_ports, port); if (ipc) sock_hold(&ipc->sk); - mutex_unlock(&qrtr_port_lock); + rcu_read_unlock(); return ipc; } @@ -691,6 +691,10 @@ static void qrtr_port_remove(struct qrtr_sock *ipc) mutex_lock(&qrtr_port_lock); idr_remove(&qrtr_ports, port); mutex_unlock(&qrtr_port_lock); + + /* Ensure that if qrtr_port_lookup() did enter the RCU read section we + * wait for it to up increment the refcount */ + synchronize_rcu(); } /* Assign port number to socket.