Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3162527imw; Mon, 11 Jul 2022 03:15:45 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vCdE+bvj3SxW2h7yV2hXwXoZs1kPXaCF5Y3FlluEoUkVaMhzBDodVHw2RAuFUHr1Jtiq61 X-Received: by 2002:aa7:c0c4:0:b0:43a:20cf:3c68 with SMTP id j4-20020aa7c0c4000000b0043a20cf3c68mr23864765edp.172.1657534545677; Mon, 11 Jul 2022 03:15:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657534545; cv=none; d=google.com; s=arc-20160816; b=Zp9Sh9xItugNtI1YHuPPCfel2GHhbF/A7W1HQQDjlKFk/oRu+4vSX31CjszCAt/PGj BjQi3gmIUHds7pq9PSGoJJSMDXYtA3Ay7y0zrF0tEzH07zunUcS8IXKHRpOCrtYS/rcw rauOmAay64gAo33Vx4CbtKRjeZJa4KlWZlJDJAabrvNcw8c5UNflpU242/NEH7a+MPN8 ZqF3slQNZ2GSRsMtsGUZxNg4XljufpXY/CFNKa8peAVijPYDCKGDbeiLOXUKLUl2zPp/ 3QEXZRgp4GP1fHBlPUlxOOhLKwjKV7DbxGJkG31FlFreTzFHvQ2IzjlWPOV7F/8sO6bR 1ZQA== 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=I3r3KiTLEPKrNJoTcwmAwkyFAfbzM4SjfgOZL/X1jH4=; b=sN+Th1YKXlp9WqxnAg3lUHPOVRBon/cxWKuXDPbWGiswgASkHT7F5YKCEpmYC5H0XB okvCRIEWab4WiILuiPL/cKhen7uYRkA2YounlK+zCpDOuk5bjyHpPYUchwkClTO7GCe8 5k9I3Yl6+R8uzndZxr24wddC4/32/ubpHdgsfj79zhhRkUtn4kLTXytGtCGNvTLJb+Zy TnXCWMREVICZS9IOZkXQd2WHj22Sib0uiISo5ZzCeDBlSnNXgBPHXtSq7jr6QsTk6EHk 7dcOIby/OiAFEtQowbzg3Hjq6ioLAKEDngedLS/3LOzwEzFZ7SYvQME0RAw5a0bAkyEr fP+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Vp32p/5c"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m22-20020aa7c2d6000000b004396bf4d279si9238147edp.593.2022.07.11.03.15.20; Mon, 11 Jul 2022 03:15:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Vp32p/5c"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231221AbiGKJTj (ORCPT + 99 others); Mon, 11 Jul 2022 05:19:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231770AbiGKJSz (ORCPT ); Mon, 11 Jul 2022 05:18:55 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFBD31209C; Mon, 11 Jul 2022 02:12:00 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 4BE9DB80E76; Mon, 11 Jul 2022 09:11:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B40A3C341CD; Mon, 11 Jul 2022 09:11:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657530718; bh=02Gr89cUsMTj9nZTGgI/higKfc2ahKfCiNE3RXAa/4Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Vp32p/5c7v+RwFoL8JnxatomfESlU6/QHuUSWkGty4hXf2pm0aET0dmK+tCG9q/iL uws2fLNIUDC54d0PMcqAGxwsNKV//g5Xy9rQp8TD+GWR4mDnnbev4idpxjNF/QlO+f QWH1vOPHq+X7Q0jTG41ieh8H8QD2e2/WJm+u5dTw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , Norbert Slusarek , Thadeu Lima de Souza Cascardo , Oliver Hartkopp , Marc Kleine-Budde Subject: [PATCH 5.10 03/55] can: bcm: use call_rcu() instead of costly synchronize_rcu() Date: Mon, 11 Jul 2022 11:06:51 +0200 Message-Id: <20220711090541.865548757@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220711090541.764895984@linuxfoundation.org> References: <20220711090541.764895984@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Oliver Hartkopp commit f1b4e32aca0811aa011c76e5d6cf2fa19224b386 upstream. In commit d5f9023fa61e ("can: bcm: delay release of struct bcm_op after synchronize_rcu()") Thadeu Lima de Souza Cascardo introduced two synchronize_rcu() calls in bcm_release() (only once at socket close) and in bcm_delete_rx_op() (called on removal of each single bcm_op). Unfortunately this slow removal of the bcm_op's affects user space applications like cansniffer where the modification of a filter removes 2048 bcm_op's which blocks the cansniffer application for 40(!) seconds. In commit 181d4447905d ("can: gw: use call_rcu() instead of costly synchronize_rcu()") Eric Dumazet replaced the synchronize_rcu() calls with several call_rcu()'s to safely remove the data structures after the removal of CAN ID subscriptions with can_rx_unregister() calls. This patch adopts Erics approach for the can-bcm which should be applicable since the removal of tasklet_kill() in bcm_remove_op() and the introduction of the HRTIMER_MODE_SOFT timer handling in Linux 5.4. Fixes: d5f9023fa61e ("can: bcm: delay release of struct bcm_op after synchronize_rcu()") # >= 5.4 Link: https://lore.kernel.org/all/20220520183239.19111-1-socketcan@hartkopp.net Cc: stable@vger.kernel.org Cc: Eric Dumazet Cc: Norbert Slusarek Cc: Thadeu Lima de Souza Cascardo Signed-off-by: Oliver Hartkopp Signed-off-by: Marc Kleine-Budde Signed-off-by: Greg Kroah-Hartman --- net/can/bcm.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) --- a/net/can/bcm.c +++ b/net/can/bcm.c @@ -100,6 +100,7 @@ static inline u64 get_u64(const struct c struct bcm_op { struct list_head list; + struct rcu_head rcu; int ifindex; canid_t can_id; u32 flags; @@ -718,10 +719,9 @@ static struct bcm_op *bcm_find_op(struct return NULL; } -static void bcm_remove_op(struct bcm_op *op) +static void bcm_free_op_rcu(struct rcu_head *rcu_head) { - hrtimer_cancel(&op->timer); - hrtimer_cancel(&op->thrtimer); + struct bcm_op *op = container_of(rcu_head, struct bcm_op, rcu); if ((op->frames) && (op->frames != &op->sframe)) kfree(op->frames); @@ -732,6 +732,14 @@ static void bcm_remove_op(struct bcm_op kfree(op); } +static void bcm_remove_op(struct bcm_op *op) +{ + hrtimer_cancel(&op->timer); + hrtimer_cancel(&op->thrtimer); + + call_rcu(&op->rcu, bcm_free_op_rcu); +} + static void bcm_rx_unreg(struct net_device *dev, struct bcm_op *op) { if (op->rx_reg_dev == dev) { @@ -757,6 +765,9 @@ static int bcm_delete_rx_op(struct list_ if ((op->can_id == mh->can_id) && (op->ifindex == ifindex) && (op->flags & CAN_FD_FRAME) == (mh->flags & CAN_FD_FRAME)) { + /* disable automatic timer on frame reception */ + op->flags |= RX_NO_AUTOTIMER; + /* * Don't care if we're bound or not (due to netdev * problems) can_rx_unregister() is always a save @@ -785,7 +796,6 @@ static int bcm_delete_rx_op(struct list_ bcm_rx_handler, op); list_del(&op->list); - synchronize_rcu(); bcm_remove_op(op); return 1; /* done */ }