Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp341703pxk; Fri, 11 Sep 2020 08:22:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwto2XSs32k0XjHmMjes/9cyo6jWroosFWsrGRrC7tNuvM+3TcQfEU1q8E6Rukp7XK773Pn X-Received: by 2002:a17:906:fb8f:: with SMTP id lr15mr2502135ejb.25.1599837728565; Fri, 11 Sep 2020 08:22:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599837728; cv=none; d=google.com; s=arc-20160816; b=iHpHus4CcFc8MWatBkBnGZdsWptTBxH7KIFoSMvCUk/+j7ghdW9FvD9Mp4m8Fu6y0M bUS2AEB/mOusmwGK3WyLDHCDYZegCDVj6Bt5zGgUBuBixUpYituMj318VUFeygN8Fp2b C1KU76RI9vWIn27H1fG7rSNrTaLFDZbiKzHlk3pyb7N/6kXxZCJC6+eqmQV5nYugsH1w k/2GvzZ7xVmdPJKodi4V6tknJ15+kDeUvCZ6GY2wKuWn5GkxsNpKMjaNaJG4+DwYCOMO 6ZycI31XKwE5wDOLxa3VbvcCckZ9/u7pnFqLkrqKjY2b/nBSS/PpRFZ4mQV2RlO8R2Qe o0kw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+h4OSyLQYppnpY0yWTsvgRKDst8q2OO6GUnt0J9oV/Y=; b=YuJ4Z42TSYMBLf20dDV66y27mt/eyER2+HxNzpnsrH1TtZzO9941887JePhYYvjsAo orRgwh2HMlXO39wY4tXZo3GS8/B48q20Y5QTXlVMPtweZReTj0UA/aVO0z2o9uuZZPsy HJnn/y0mYEtUnKRo8+uFYQxNsjLGVA1rQxKLkxpAgcmV7O++6TTuuXRzQDL9puiEASqO cRQbOE22MWu6OfXuFwuofz2mU6p86FSJCYcQxIDT1MzXyuvLt3kwiq4NW7mO5Ay/7X3a mAfWBwK4Iz4na27HU3auDhZk6ZiOzmPw8h12yn/JTuS/yC+Z3C3X7Haqid5CCADLYlIX +DIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=k9MdIB0o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id yd11si1442862ejb.184.2020.09.11.08.21.45; Fri, 11 Sep 2020 08:22:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=k9MdIB0o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726408AbgIKPUU (ORCPT + 99 others); Fri, 11 Sep 2020 11:20:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:52730 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726447AbgIKPPh (ORCPT ); Fri, 11 Sep 2020 11:15:37 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CFFB52224D; Fri, 11 Sep 2020 12:59:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599829173; bh=0WWgoPC3qSem1zGC5HZoGN0BJUzM5udXNx895gCMmkk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k9MdIB0odtRPpKoEqnPXrrD3H4UCt91tGL+l0zp+NCQ8yeFeqSnaemwPc7T9yNtPp oqNDG29ZqbwT/Fqvugo43f9O2X47ZX0E/Bgqky6OjletzSFsFHcGj+5EZui+iZHxZU NFWsucnpVYbgkNwsW7n32swJLp8kj/wY6UxenrgU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ying Xu , Xin Long , Marcelo Ricardo Leitner , "David S. Miller" Subject: [PATCH 5.8 11/16] sctp: not disable bh in the whole sctp_get_port_local() Date: Fri, 11 Sep 2020 14:47:28 +0200 Message-Id: <20200911122500.139722863@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200911122459.585735377@linuxfoundation.org> References: <20200911122459.585735377@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xin Long [ Upstream commit 3106ecb43a05dc3e009779764b9da245a5d082de ] With disabling bh in the whole sctp_get_port_local(), when snum == 0 and too many ports have been used, the do-while loop will take the cpu for a long time and cause cpu stuck: [ ] watchdog: BUG: soft lockup - CPU#11 stuck for 22s! [ ] RIP: 0010:native_queued_spin_lock_slowpath+0x4de/0x940 [ ] Call Trace: [ ] _raw_spin_lock+0xc1/0xd0 [ ] sctp_get_port_local+0x527/0x650 [sctp] [ ] sctp_do_bind+0x208/0x5e0 [sctp] [ ] sctp_autobind+0x165/0x1e0 [sctp] [ ] sctp_connect_new_asoc+0x355/0x480 [sctp] [ ] __sctp_connect+0x360/0xb10 [sctp] There's no need to disable bh in the whole function of sctp_get_port_local. So fix this cpu stuck by removing local_bh_disable() called at the beginning, and using spin_lock_bh() instead. The same thing was actually done for inet_csk_get_port() in Commit ea8add2b1903 ("tcp/dccp: better use of ephemeral ports in bind()"). Thanks to Marcelo for pointing the buggy code out. v1->v2: - use cond_resched() to yield cpu to other tasks if needed, as Eric noticed. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-by: Ying Xu Signed-off-by: Xin Long Acked-by: Marcelo Ricardo Leitner Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/sctp/socket.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -8297,8 +8297,6 @@ static int sctp_get_port_local(struct so pr_debug("%s: begins, snum:%d\n", __func__, snum); - local_bh_disable(); - if (snum == 0) { /* Search for an available port. */ int low, high, remaining, index; @@ -8316,20 +8314,21 @@ static int sctp_get_port_local(struct so continue; index = sctp_phashfn(net, rover); head = &sctp_port_hashtable[index]; - spin_lock(&head->lock); + spin_lock_bh(&head->lock); sctp_for_each_hentry(pp, &head->chain) if ((pp->port == rover) && net_eq(net, pp->net)) goto next; break; next: - spin_unlock(&head->lock); + spin_unlock_bh(&head->lock); + cond_resched(); } while (--remaining > 0); /* Exhausted local port range during search? */ ret = 1; if (remaining <= 0) - goto fail; + return ret; /* OK, here is the one we will use. HEAD (the port * hash table list entry) is non-NULL and we hold it's @@ -8344,7 +8343,7 @@ static int sctp_get_port_local(struct so * port iterator, pp being NULL. */ head = &sctp_port_hashtable[sctp_phashfn(net, snum)]; - spin_lock(&head->lock); + spin_lock_bh(&head->lock); sctp_for_each_hentry(pp, &head->chain) { if ((pp->port == snum) && net_eq(pp->net, net)) goto pp_found; @@ -8444,10 +8443,7 @@ success: ret = 0; fail_unlock: - spin_unlock(&head->lock); - -fail: - local_bh_enable(); + spin_unlock_bh(&head->lock); return ret; }