From patchwork Wed May 8 06:06:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 163621 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:81:0:0:0:0 with SMTP id l1csp2259785ilm; Tue, 7 May 2019 23:06:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqyCRNuu8J1kN1pz4rO1+oAGv9V4XxCJ5VMl7GW8uHPsmvL4gz2QiOob7iOMsUKXWBzfJBGQ X-Received: by 2002:a17:902:822:: with SMTP id 31mr44526415plk.41.1557295614475; Tue, 07 May 2019 23:06:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557295614; cv=none; d=google.com; s=arc-20160816; b=h5w+/ex0b8vqbxFex6WUlY1x/zBZM9Ghnh4L42fxKscPwWISnGyARIYi8ryyg3zP2Y 8wkWb4qs+SVj8bUsK6bBYSWPixcAyD+/wbzK41dk4RY9kYfJ94LzPcHD1x28OPUN2XQ7 gYUzzSgSuFl5T4WTzSIcfXZHfQW1GdqltiMvJ4Fko36c+daP3cUFNqF9iwaByq5rU0i4 m4YvCDp0SYS228XYN8qrTZJHu569wYurxrn+okLG25vVF7ZxqFG04bj39RHG706Cp2Pe P0OnSP7hsqM3fRny1DPlucyOchg1WqIUThT2p9dgNwNN6fPW7/SXrkYq3awlXk5WSRYr 4Uyw== 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=p5HInBiuJL6RtWK4IaOfUZdmH8ZXG7yh2eAVGA9vg3M=; b=p1fSoe2oWP1ESJos19gn20N1stSErrakdwO+sR8/M5H8J7eaxbD8RMfihrN7d+jo3c s8vHvbAkCmgGdUgfjkD5+mlf1vC3nMlq3oKcMXwS87UUy0ynnW4mOY9392H3Idsy1hZY RuHw7jmFuYFvDHCpiB0me0Gh/cUVDwSQUUF+fYg/xMVrR8jNsDvnIKcWr92+GW1saz6S juxCR5WI2KmOU9CVskUA5gltMnX2D97ym1lnqJFW7A9r2clPhSGdfYSU6Y4D4ioz/SWq vWTDRkhClYEHqucQ+24HhCZSBQaMwlnzajqj6jFx3C1A0X4IVrxB+q0gGABfbVRmYoV2 tCqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=u7QI4igQ; 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 r127si22723448pfr.78.2019.05.07.23.06.54; Tue, 07 May 2019 23:06:54 -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=u7QI4igQ; 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 S1728623AbfEHGGx (ORCPT + 9 others); Wed, 8 May 2019 02:06:53 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:46984 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728645AbfEHGGw (ORCPT ); Wed, 8 May 2019 02:06:52 -0400 Received: by mail-pg1-f194.google.com with SMTP id t187so5427411pgb.13 for ; Tue, 07 May 2019 23:06:52 -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=p5HInBiuJL6RtWK4IaOfUZdmH8ZXG7yh2eAVGA9vg3M=; b=u7QI4igQ8i/7N4oUg2BhkdqF4FwTcLtpbk8aJ06RfsBXr1Nqqo6zNwzuUELwAs0ThG pIKDNsZyj8tVY97Oj35iK/nVDAk8qWoYKzEW42lkqcG1QdA+yNBYcMnvHfH3EW8NKSQP QAegi/Ac9yj34wHZqOByYLTGfz5LS3p286gLTrG8DCKb8OVVSKCl/pk7qSS+uSiUMB3z 7+wSTLY1v1nbeNGBzo9uO1V0YL94eDE66GfOvqYb2ZJ0HPGL8Jqq1AUa1WwyBE9KyAL6 iC1RBZPBNf11/N4BlrlX+xaR1NXs+B2oTFhWUPLS6Oc51NEVRoz4Q8XCTo9Jo76G1fuk nn5w== 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=p5HInBiuJL6RtWK4IaOfUZdmH8ZXG7yh2eAVGA9vg3M=; b=Hjw/xR/J0sS3T707OeNqXXDZICLzZm4h9Ps1yjPIhOqvCZBrnPUkQ0btDbs19yyAtV xjzRkbDviLTel6BY4g8gSxf8XRa85gCRGGlTEbZ8wtLpQNm8Y26M3Ss+0Q3y9ETljaef 4XzD18dWKhYqD0O/kZbcbhFqK2v95ZgS3iffu8ov4F4qpoyFcNdttbOZYQKDx0i6+dso QUuLjoZn9aDgEEWsF+RFebQ3+9ycqjS0CeOmwWbKz5Bcg5YRttSDzng3sOEdQpz++dbo 9jAjDkUnWSLVGfanqVtrVkNb9E2TaUv8HggU/Ty4xQDWZr6X+SPAn1q0QOt1XCi2xwDA GO5A== X-Gm-Message-State: APjAAAWWhGbfVwYxCQ2C75Ph2tj2ayF606sS8VmS29ivTp7ijZI2+dcf k0PT5eE4egxOXoX669JGYjmgHg== X-Received: by 2002:a62:6c43:: with SMTP id h64mr13973560pfc.5.1557295611749; Tue, 07 May 2019 23:06:51 -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 t5sm2756130pgn.80.2019.05.07.23.06.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 May 2019 23:06:51 -0700 (PDT) From: Bjorn Andersson To: "David S. Miller" , Arun Kumar Neelakantam , Chris Lew Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: [PATCH 4/5] net: qrtr: Make qrtr_port_lookup() use RCU Date: Tue, 7 May 2019 23:06:42 -0700 Message-Id: <20190508060643.30936-5-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190508060643.30936-1-bjorn.andersson@linaro.org> References: <20190508060643.30936-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 --- 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 9075751028a2..d2eef43a3124 100644 --- a/net/qrtr/qrtr.c +++ b/net/qrtr/qrtr.c @@ -602,11 +602,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; } @@ -648,6 +648,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.