From patchwork Mon Jun 11 13:46:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejaswi Tanikella X-Patchwork-Id: 927673 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=codeaurora.org header.i=@codeaurora.org header.b="TSbHKJ/M"; dkim=pass (1024-bit key) header.d=codeaurora.org header.i=@codeaurora.org header.b="VR8BKXlZ"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 414Dnr6yFBz9rxs for ; Mon, 11 Jun 2018 23:46:40 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933076AbeFKNqi (ORCPT ); Mon, 11 Jun 2018 09:46:38 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:50558 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932904AbeFKNqh (ORCPT ); Mon, 11 Jun 2018 09:46:37 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 041F460791; Mon, 11 Jun 2018 13:46:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1528724797; bh=W5MAzpN0fOqWk5pD4TO4sMzUD92cx8k5+uO6t1Nl3ag=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=TSbHKJ/MROshmMykTtvVbVzhRaPVcC0TtW3UqLEKGIbIfjcHuvg8/P14AxkoIdC6v IXwdTbFsW91JKwpnB68ZW7r7izySVNnhFugRYN2GICDSlzTgUo1KYt0Vavb/nWGeX6 RvJKTEEcg6eWQlwlBUwjUSEi4+Mh7zkK+jkq98Rc= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED, T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from tejaswit-linux.qualcomm.com (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: tejaswit@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id BC7816074D; Mon, 11 Jun 2018 13:46:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1528724796; bh=W5MAzpN0fOqWk5pD4TO4sMzUD92cx8k5+uO6t1Nl3ag=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=VR8BKXlZuFsD2iwX+lUhwbKu2TVTGePJgoRET0nlvrQPrN5gN215kKnI2YXJBbmnN AwOAFDDwbjrB7eOkNZy645aQlvn9+HOz457/mjNtGL3JFsGACQK2cZqHG2BiXy9IMn DZ9XU/TO9LDviBR1oL3Ptaq7OCLUFY+Za8WX1uNk= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org BC7816074D Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=tejaswit@codeaurora.org Date: Mon, 11 Jun 2018 19:16:27 +0530 From: Tejaswi Tanikella To: netdev@vger.kernel.org, f.fainelli@gmail.com Cc: andrew@lunn.ch, davem@davemloft.net Subject: [PATCH net v3 2/2] ipv4: igmp: use alarmtimer to prevent delayed reports Message-ID: <20180611134619.GA28666@tejaswit-linux.qualcomm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180611134405.GA28495@tejaswit-linux.qualcomm.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On receiving a IGMPv2/v3 query, based on max_delay set in the header a timer is started to send out a response after a random time within max_delay. If the system then moves into suspend state, Report is delayed until system wakes up. Use a alarmtimer instead of using a timer. Alarmtimer will wake the system up from suspend to send out the IGMP report. Signed-off-by: Tejaswi Tanikella --- v2: use alarmtimer instead of wakelock. v3: add patches in the right order. --- If these changes are fine, I'll share similar patches for MLD and ARP. --- include/linux/igmp.h | 7 ++++++- net/ipv4/igmp.c | 27 ++++++++++++++++----------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/include/linux/igmp.h b/include/linux/igmp.h index f823185..45852eb 100644 --- a/include/linux/igmp.h +++ b/include/linux/igmp.h @@ -20,6 +20,9 @@ #include #include #include +#ifdef CONFIG_IP_MULTICAST +#include +#endif static inline struct igmphdr *igmp_hdr(const struct sk_buff *skb) { @@ -83,7 +86,9 @@ struct ip_mc_list { struct ip_mc_list __rcu *next_rcu; }; struct ip_mc_list __rcu *next_hash; - struct timer_list timer; +#ifdef CONFIG_IP_MULTICAST + struct alarm alarm; +#endif int users; refcount_t refcnt; spinlock_t lock; diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c index 85b617b..c30b5c4 100644 --- a/net/ipv4/igmp.c +++ b/net/ipv4/igmp.c @@ -199,7 +199,7 @@ static void ip_ma_put(struct ip_mc_list *im) static void igmp_stop_timer(struct ip_mc_list *im) { spin_lock_bh(&im->lock); - if (del_timer(&im->timer)) + if (alarm_cancel(&im->alarm)) refcount_dec(&im->refcnt); im->tm_running = 0; im->reporter = 0; @@ -210,11 +210,11 @@ static void igmp_stop_timer(struct ip_mc_list *im) /* It must be called with locked im->lock */ static void igmp_start_timer(struct ip_mc_list *im, int max_delay) { - int tv = prandom_u32() % max_delay; + ktime_t expiry = jiffies_to_ktime(prandom_u32() % max_delay + 2); im->tm_running = 1; - if (!mod_timer(&im->timer, jiffies+tv+2)) - refcount_inc(&im->refcnt); + alarm_start_relative(&im->alarm, expiry); + refcount_inc(&im->refcnt); } static void igmp_gq_start_timer(struct in_device *in_dev) @@ -241,11 +241,14 @@ static void igmp_ifc_start_timer(struct in_device *in_dev, int delay) static void igmp_mod_timer(struct ip_mc_list *im, int max_delay) { + ktime_t expiry; + spin_lock_bh(&im->lock); im->unsolicit_count = 0; - if (del_timer(&im->timer)) { - if ((long)(im->timer.expires-jiffies) < max_delay) { - add_timer(&im->timer); + expiry = alarm_expires_remaining(&im->alarm); + if (alarm_cancel(&im->alarm)) { + if (ktime_to_jiffies(expiry) < max_delay) { + alarm_start_relative(&im->alarm, expiry); im->tm_running = 1; spin_unlock_bh(&im->lock); return; @@ -812,9 +815,9 @@ static void igmp_ifc_event(struct in_device *in_dev) } -static void igmp_timer_expire(struct timer_list *t) +enum alarmtimer_restart igmp_timer_expire(struct alarm *alarm, ktime_t now) { - struct ip_mc_list *im = from_timer(im, t, timer); + struct ip_mc_list *im = container_of(alarm, struct ip_mc_list, alarm); struct in_device *in_dev = im->interface; spin_lock(&im->lock); @@ -835,6 +838,8 @@ static void igmp_timer_expire(struct timer_list *t) igmp_send_report(in_dev, im, IGMPV3_HOST_MEMBERSHIP_REPORT); ip_ma_put(im); + + return ALARMTIMER_NORESTART; } /* mark EXCLUDE-mode sources */ @@ -1413,7 +1418,7 @@ void ip_mc_inc_group(struct in_device *in_dev, __be32 addr) refcount_set(&im->refcnt, 1); spin_lock_init(&im->lock); #ifdef CONFIG_IP_MULTICAST - timer_setup(&im->timer, igmp_timer_expire, 0); + alarm_init(&im->alarm, ALARM_BOOTTIME, igmp_timer_expire); im->unsolicit_count = net->ipv4.sysctl_igmp_qrv; #endif @@ -2811,7 +2816,7 @@ static int igmp_mc_seq_show(struct seq_file *seq, void *v) state->dev->ifindex, state->dev->name, state->in_dev->mc_count, querier); } - delta = im->timer.expires - jiffies; + delta = ktime_to_jiffies(alarm_expires_remaining(&im->alarm)); seq_printf(seq, "\t\t\t\t%08X %5d %d:%08lX\t\t%d\n", im->multiaddr, im->users,