From patchwork Tue Jan 14 07:56:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 190674 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C337C33CB1 for ; Tue, 14 Jan 2020 07:58:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0181A207FF for ; Tue, 14 Jan 2020 07:58:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="pdUjFjV0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729085AbgANH5z (ORCPT ); Tue, 14 Jan 2020 02:57:55 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:37511 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729083AbgANH5y (ORCPT ); Tue, 14 Jan 2020 02:57:54 -0500 Received: by mail-pg1-f193.google.com with SMTP id q127so6020491pga.4 for ; Mon, 13 Jan 2020 23:57:53 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=Px4G0+J+cRapXW5QpczEFWv3zS6gD7SLN1HuC+fZi3c=; b=pdUjFjV0LD/LgGKAxgvkoSltMrFIKqyzCbpjTWbRu6o0CtVu7FT0LLs9WL0NIK/TJA b3L/feFnoWjzMym/dGmzj/S7r8Py7Jg+I+pFDp4YjeHPzPESZ5kPcq9czEh9Y5pmrHNO qodrA41O2sWKy5vefORIyYBMesZekvVHGF7kw76NLwaRnkEjUKUxJgTMN+2jVug9qgz3 NQhWV1EfisvgISh6YuynLM/VZ7WaJGnWax06CCf3UIFFEI54KGfhvkw7TKCz1U7H8gxP A/pM0GFCwOzzNneNSEvW2e3yogFBGbmlZljaaNSYys2aXS1PCc+Slpy4YD0UIMRUciEc W9pA== 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:mime-version:content-transfer-encoding; bh=Px4G0+J+cRapXW5QpczEFWv3zS6gD7SLN1HuC+fZi3c=; b=kXMRmjDPVrDPSJh+VapMm7I7tO+GCEkem13kb3NJIUlcs2zeqAXxrC1CCbZ/DxwLga n7xhr61qYx1kYXbszKlKUgqGgC+QfYgPHX1ft5UCbNDAZL324rKeJm8DoNjCf/yrba5n 4y7EvWiGwXFfunEPl3GVy9oO/Wlq3jCcF+wiJ+n96H/LCb5ucOXRmMuhzAahjjQyU2Rx v12BkGeVf2/OEL6RKySzXko7vH9G4fktI6aB7wO8Tkhxn+qL+jRGKa2yqaF0Z0Zqg+VN r3B0JiBlG8uKokdq87X35MRjOdVculJf2cJSEtmto02xOvUpC0tFG56Ge5rFz192gSpZ T+Zg== X-Gm-Message-State: APjAAAWqOpWIRyD7EQRmF7OOkjmhKGbCgJyJ9io0qrgtMcRNFs9GfHJe EnGSL8MFMBZwKMORG9gxOYGLDA== X-Google-Smtp-Source: APXvYqzFnrDpXcxKDZkH0vJ11Mu/bGatj5joJUYZafTV4dTQTzqRsXeanCTjo2s7F4Dyxop5Eyai7w== X-Received: by 2002:a63:da4d:: with SMTP id l13mr26725803pgj.106.1578988673197; Mon, 13 Jan 2020 23:57:53 -0800 (PST) Received: from localhost.localdomain (104-188-17-28.lightspeed.sndgca.sbcglobal.net. [104.188.17.28]) by smtp.gmail.com with ESMTPSA id q63sm17349352pfb.149.2020.01.13.23.57.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2020 23:57:52 -0800 (PST) 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 v4 1/5] net: qrtr: Move resume-tx transmission to recvmsg Date: Mon, 13 Jan 2020 23:56:59 -0800 Message-Id: <20200114075703.2145718-2-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200114075703.2145718-1-bjorn.andersson@linaro.org> References: <20200114075703.2145718-1-bjorn.andersson@linaro.org> MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The confirm-rx bit is used to implement a per port flow control, in order to make sure that no messages are dropped due to resource exhaustion. Move the resume-tx transmission to recvmsg to only confirm messages as they are consumed by the application. Signed-off-by: Bjorn Andersson --- Changes since v3: - None net/qrtr/qrtr.c | 60 +++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c index 88f98f27ad88..6c56a8ce83ef 100644 --- a/net/qrtr/qrtr.c +++ b/net/qrtr/qrtr.c @@ -362,22 +362,11 @@ static void qrtr_port_put(struct qrtr_sock *ipc); static void qrtr_node_rx_work(struct work_struct *work) { struct qrtr_node *node = container_of(work, struct qrtr_node, work); - struct qrtr_ctrl_pkt *pkt; - struct sockaddr_qrtr dst; - struct sockaddr_qrtr src; struct sk_buff *skb; while ((skb = skb_dequeue(&node->rx_queue)) != NULL) { struct qrtr_sock *ipc; - struct qrtr_cb *cb; - int confirm; - - cb = (struct qrtr_cb *)skb->cb; - src.sq_node = cb->src_node; - src.sq_port = cb->src_port; - dst.sq_node = cb->dst_node; - dst.sq_port = cb->dst_port; - confirm = !!cb->confirm_rx; + struct qrtr_cb *cb = (struct qrtr_cb *)skb->cb; qrtr_node_assign(node, cb->src_node); @@ -390,20 +379,6 @@ static void qrtr_node_rx_work(struct work_struct *work) qrtr_port_put(ipc); } - - if (confirm) { - skb = qrtr_alloc_ctrl_packet(&pkt); - if (!skb) - break; - - pkt->cmd = cpu_to_le32(QRTR_TYPE_RESUME_TX); - pkt->client.node = cpu_to_le32(dst.sq_node); - pkt->client.port = cpu_to_le32(dst.sq_port); - - if (qrtr_node_enqueue(node, skb, QRTR_TYPE_RESUME_TX, - &dst, &src)) - break; - } } } @@ -816,6 +791,34 @@ static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) return rc; } +static int qrtr_send_resume_tx(struct qrtr_cb *cb) +{ + struct sockaddr_qrtr remote = { AF_QIPCRTR, cb->src_node, cb->src_port }; + struct sockaddr_qrtr local = { AF_QIPCRTR, cb->dst_node, cb->dst_port }; + struct qrtr_ctrl_pkt *pkt; + struct qrtr_node *node; + struct sk_buff *skb; + int ret; + + node = qrtr_node_lookup(remote.sq_node); + if (!node) + return -EINVAL; + + skb = qrtr_alloc_ctrl_packet(&pkt); + if (!skb) + return -ENOMEM; + + pkt->cmd = cpu_to_le32(QRTR_TYPE_RESUME_TX); + pkt->client.node = cpu_to_le32(cb->dst_node); + pkt->client.port = cpu_to_le32(cb->dst_port); + + ret = qrtr_node_enqueue(node, skb, QRTR_TYPE_RESUME_TX, &local, &remote); + + qrtr_node_release(node); + + return ret; +} + static int qrtr_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, int flags) { @@ -838,6 +841,7 @@ static int qrtr_recvmsg(struct socket *sock, struct msghdr *msg, release_sock(sk); return rc; } + cb = (struct qrtr_cb *)skb->cb; copied = skb->len; if (copied > size) { @@ -851,7 +855,6 @@ static int qrtr_recvmsg(struct socket *sock, struct msghdr *msg, rc = copied; if (addr) { - cb = (struct qrtr_cb *)skb->cb; addr->sq_family = AF_QIPCRTR; addr->sq_node = cb->src_node; addr->sq_port = cb->src_port; @@ -859,6 +862,9 @@ static int qrtr_recvmsg(struct socket *sock, struct msghdr *msg, } out: + if (cb->confirm_rx) + qrtr_send_resume_tx(cb); + skb_free_datagram(sk, skb); release_sock(sk); From patchwork Tue Jan 14 07:57:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 190676 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNWANTED_LANGUAGE_BODY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 15F04C33CB1 for ; Tue, 14 Jan 2020 07:57:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DDE0D207FF for ; Tue, 14 Jan 2020 07:57:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="hXEgZMMf" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729179AbgANH55 (ORCPT ); Tue, 14 Jan 2020 02:57:57 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:46012 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729157AbgANH54 (ORCPT ); Tue, 14 Jan 2020 02:57:56 -0500 Received: by mail-pg1-f194.google.com with SMTP id b9so5994784pgk.12 for ; Mon, 13 Jan 2020 23:57:56 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=FdqD8NRNphouo9P3H8kSDAOVyLnUT6AjcPDXOI9PAiQ=; b=hXEgZMMfgZiKB0EiZMA8jnwtGVY5x7TFCicAgnVuoKVm/oL3b1I9rT4nQxEKh2Aduc eBf+3WgpTPpbe2XLWgBqBtMnr3mKL3ULYAd0CBWTnJfF3jikFm8ZJjIPUXHd3EYu8xCW fROeetq+ibhA623110viLke2EtOw1Ne/dMR+wB67s1Xo1kGPMGJ6lkOe+NBWBzUXXSlI tajOZDcrlDV00sqYDQHsLVyeCw/pnUojUaDdzuJxFFIbSuxTmWND8IwQgetc4u957+Kb 8oH4RSxVb/aUQec1MZpft5UDzNNp8dPrJR3fq5UAtOhefO+8ITVeLPEwMrRUlTW8EwNT DkSQ== 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:mime-version:content-transfer-encoding; bh=FdqD8NRNphouo9P3H8kSDAOVyLnUT6AjcPDXOI9PAiQ=; b=gVpTTwpmVjVud+9H3r1lgv1oES55Sg+fjiARHjwub0w2nltHvxR0Ih3vlUhHwrtN8N ClQJUJPZuCJIRGIPtvMPh08gUtaZFg5jEjweq1nWzPfUIA0mbTRgkmwxqmSHOQjvoOmV NH9RA9YDJJ8P/O38FtcC7KSE56bJZrpoYWcOAv4vY1eN+OMvIpS8k7vt88N6oLgxXHZE 3AshT6YYGKcYo3Fv3uPyEcNczOUimheNys3vB78hiLf6u/eWPGqmHTe0k9lSNxEPJufc h7YSnPNXN+TtjbvjNuCvOMpvqJv+R+h99aIYtahyssM2zrcDFDbIy/FKJ1i8RBemMJik KCoQ== X-Gm-Message-State: APjAAAXMIOfju192kZR2E1jFFaOh0ZG6kGOf4deR17lbMkgWMCclMn3F aFZL6wVdQFv3Dx6tiQLAnIGyeBU4a3g= X-Google-Smtp-Source: APXvYqxYrG4IWc5BNa9rUaA7OJZ1AJ0p5PIQfRuXTlRa6Zk9yaCMkVK4RZYw1LGxEK8Z7NmG88+LNw== X-Received: by 2002:a62:2cc1:: with SMTP id s184mr24788042pfs.111.1578988675810; Mon, 13 Jan 2020 23:57:55 -0800 (PST) Received: from localhost.localdomain (104-188-17-28.lightspeed.sndgca.sbcglobal.net. [104.188.17.28]) by smtp.gmail.com with ESMTPSA id q63sm17349352pfb.149.2020.01.13.23.57.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2020 23:57:55 -0800 (PST) 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 v4 3/5] net: qrtr: Migrate node lookup tree to spinlock Date: Mon, 13 Jan 2020 23:57:01 -0800 Message-Id: <20200114075703.2145718-4-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200114075703.2145718-1-bjorn.andersson@linaro.org> References: <20200114075703.2145718-1-bjorn.andersson@linaro.org> MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Move operations on the qrtr_nodes radix tree under a separate spinlock and make the qrtr_nodes tree GFP_ATOMIC, to allow operation from atomic context in a subsequent patch. Signed-off-by: Bjorn Andersson --- Changes since v3: - None net/qrtr/qrtr.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c index 304d536c7353..52816d44fb26 100644 --- a/net/qrtr/qrtr.c +++ b/net/qrtr/qrtr.c @@ -8,6 +8,7 @@ #include #include /* For TIOCINQ/OUTQ */ #include +#include #include #include @@ -98,10 +99,11 @@ static inline struct qrtr_sock *qrtr_sk(struct sock *sk) static unsigned int qrtr_local_nid = NUMA_NO_NODE; /* for node ids */ -static RADIX_TREE(qrtr_nodes, GFP_KERNEL); +static RADIX_TREE(qrtr_nodes, GFP_ATOMIC); +static DEFINE_SPINLOCK(qrtr_nodes_lock); /* broadcast list */ static LIST_HEAD(qrtr_all_nodes); -/* lock for qrtr_nodes, qrtr_all_nodes and node reference */ +/* lock for qrtr_all_nodes and node reference */ static DEFINE_MUTEX(qrtr_node_lock); /* local port allocation management */ @@ -165,10 +167,13 @@ static void __qrtr_node_release(struct kref *kref) { struct qrtr_node *node = container_of(kref, struct qrtr_node, ref); struct radix_tree_iter iter; + unsigned long flags; void __rcu **slot; + spin_lock_irqsave(&qrtr_nodes_lock, flags); if (node->nid != QRTR_EP_NID_AUTO) radix_tree_delete(&qrtr_nodes, node->nid); + spin_unlock_irqrestore(&qrtr_nodes_lock, flags); list_del(&node->item); mutex_unlock(&qrtr_node_lock); @@ -376,11 +381,12 @@ static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb, static struct qrtr_node *qrtr_node_lookup(unsigned int nid) { struct qrtr_node *node; + unsigned long flags; - mutex_lock(&qrtr_node_lock); + spin_lock_irqsave(&qrtr_nodes_lock, flags); node = radix_tree_lookup(&qrtr_nodes, nid); node = qrtr_node_acquire(node); - mutex_unlock(&qrtr_node_lock); + spin_unlock_irqrestore(&qrtr_nodes_lock, flags); return node; } @@ -392,13 +398,15 @@ static struct qrtr_node *qrtr_node_lookup(unsigned int nid) */ static void qrtr_node_assign(struct qrtr_node *node, unsigned int nid) { + unsigned long flags; + if (node->nid != QRTR_EP_NID_AUTO || nid == QRTR_EP_NID_AUTO) return; - mutex_lock(&qrtr_node_lock); + spin_lock_irqsave(&qrtr_nodes_lock, flags); radix_tree_insert(&qrtr_nodes, nid, node); node->nid = nid; - mutex_unlock(&qrtr_node_lock); + spin_unlock_irqrestore(&qrtr_nodes_lock, flags); } /** From patchwork Tue Jan 14 07:57:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 190675 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42961C33CB1 for ; Tue, 14 Jan 2020 07:58:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0F6B3207FF for ; Tue, 14 Jan 2020 07:58:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="HWJ1FrKZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729080AbgANH56 (ORCPT ); Tue, 14 Jan 2020 02:57:58 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:45264 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729169AbgANH55 (ORCPT ); Tue, 14 Jan 2020 02:57:57 -0500 Received: by mail-pf1-f194.google.com with SMTP id 2so6177502pfg.12 for ; Mon, 13 Jan 2020 23:57:57 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=cT6CIKbYE+ZaFFcNOOsxSrYLOhAgjqy8hJjakcWsraw=; b=HWJ1FrKZivAC77Q6ewttmSwMoUhC4h8f56+T4yQkYs25/XqVt1ThC3IC6EIkcHoLVG Y2dYcFEqMihzuuTAPZAm1+7UqRpMk5pYxniaU+29kPfB+8LfcZdqTBakVYTfdnANH3PP 7+mK1m0XlZawRAeIqF2Owtzv8kZbkk0jPGX4STZEQUySpNfqfiEeeR+JoJaD/qi+ZSWB BraJSp7wL9eRt7pusrlG48nShyFwNDz4uqSEEtRRYZrexuBcShVJaAk25O66oIUw8APO FRBI0GvoQCE0Uxu/OeTAMbDVUOtpBRsi8LgxGZUFs1lRq0Ok2CvcFBYSLTufUgLaep5l Oi8Q== 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:mime-version:content-transfer-encoding; bh=cT6CIKbYE+ZaFFcNOOsxSrYLOhAgjqy8hJjakcWsraw=; b=FjCwtcPTKJSI0aMmNl/JS58SNutAJESQi8AdGDwT8hCesqSG2vyEbctVXktiiGDXpC vPC8ByzzKKCkL1lrD7ULUF9M6reyrCUATGu6X8eb4AJFMa+3sNfmSS2ygsL1AkIGv23u 0jmNb3fvlAsGzAeMi8e3SOQlG7CRgHDbqDzDp8jRWaYj8tmPBtq1qomydnQJrGQ4YK6c FIfMAdJ1Ao4/Rk6Nla/aqsX0k1d9UiW33j//BdNw1GsKzxozw2AO6zDu8n+QbgHl5b9Z Qqa4BB3rzYdIE2b+k7eYQLMT0xBy0dfAA5b6Esk/5ZIPeGeU/3ljMIkeBPmNcAovIX6E 830g== X-Gm-Message-State: APjAAAUvk7XIAkwzw1Td6lYswL8ji6fUR507Bnh7Rlol8m08KgyqJdUn TBmjosOYqmy4xJelGDEwVd9mGw== X-Google-Smtp-Source: APXvYqxa0sjqaAqTU3VpbArJAMp7cdEEAKNxoK+7V8ScX+GgBOrVf0psQGSLOw/kjBSkfLKnRweY0w== X-Received: by 2002:aa7:979a:: with SMTP id o26mr24139687pfp.0.1578988677055; Mon, 13 Jan 2020 23:57:57 -0800 (PST) Received: from localhost.localdomain (104-188-17-28.lightspeed.sndgca.sbcglobal.net. [104.188.17.28]) by smtp.gmail.com with ESMTPSA id q63sm17349352pfb.149.2020.01.13.23.57.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2020 23:57:56 -0800 (PST) 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 v4 4/5] net: qrtr: Make qrtr_port_lookup() use RCU Date: Mon, 13 Jan 2020 23:57:02 -0800 Message-Id: <20200114075703.2145718-5-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200114075703.2145718-1-bjorn.andersson@linaro.org> References: <20200114075703.2145718-1-bjorn.andersson@linaro.org> MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@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 v3: - None net/qrtr/qrtr.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c index 52816d44fb26..8ae301132a54 100644 --- a/net/qrtr/qrtr.c +++ b/net/qrtr/qrtr.c @@ -646,11 +646,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; } @@ -692,6 +692,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.