Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp344693pxk; Fri, 11 Sep 2020 08:27:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwPUpay0VzV7WttKRP0t3Oy+OuaS7nBzXXo06RAT0L5CYC0lpEo92lxJGvkKMQsCLjZpZPx X-Received: by 2002:a05:6402:305a:: with SMTP id bu26mr2701340edb.262.1599838042792; Fri, 11 Sep 2020 08:27:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599838042; cv=none; d=google.com; s=arc-20160816; b=PgA8Dq3MEt4Nr5TwvQrn+E3A0zzk4FMqSvQXzpuWJ6oKaPs718q2gSOLsA4er7k2eS oWTsyixbDCchkGk9DrVm2KfKfLB0W7xW4OofKzw8DHMzj6opAhT61XSnvJu9W3ADZaK7 QPq3VsKH0Qx0ofW8bUPF/ny0GbVUVTOT7Sf9IR0sO2/sHK8YsHV9bXaXsm8Jz/m6y3k3 PgivWf2mldzpeL1penOws4+fR4fxmj7IM4xYqVUgUu8/YixS5AwZogAx61zMuP5lr9DS XkLOJudSMZg6M/V8nHa2qsPnewcQjLA25On1bjio4S7Soox/78YHABde6nw+o7Wn4sm4 Bcmg== 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=s/USL8CKsXU1i3b5yqS1DBcCJUzWDb0qaRk9UrfS7Zk=; b=UbBB0VSV1bWjweviExlIAFr5XU8HTfQISjypiTLF9uX5pvwnILIxdZuPFH2R1VxKyJ 7pHc9OFmCqpEHPS1oLeeE0yYsq6LvS8d6MbzO6JXiKbi2xxVSPyIttE9lPe2s2F3jIby SqEiGaKbko3jnWUn25YMN29UFXhSAJ0bP6O+3J+V2ddHg8wE9BiuK1FV1RfFi9fGUHew mw4u9qa0g+n4oHMykm3PKr9QGqu3A0tBgy1wPpBiJ4mVMsIpNnx576fb21ivpBklTTDV jbNwGMqZS5+fM6woJlM12e7PGEnlFmOgWWJQPpUKFqCo2UPBHaDoYbgTD+GW4rBgVJLI 1m/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lfc2RBeF; 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 j23si1462601ejm.736.2020.09.11.08.26.59; Fri, 11 Sep 2020 08:27:22 -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=lfc2RBeF; 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 S1725833AbgIKPXm (ORCPT + 99 others); Fri, 11 Sep 2020 11:23:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:53398 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726448AbgIKPRj (ORCPT ); Fri, 11 Sep 2020 11:17:39 -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 2DA5E223D6; Fri, 11 Sep 2020 12:58:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599829127; bh=pg8QoShE6RW4IjYx3j1/NruMNLMONbUk0DC6zHwCcpE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lfc2RBeFSHZoiTtMMl9kZAB/zPuS1EjRXdJN1Kn0DBDJaxQ45QYtIWM32cRUIOVtk vbOWdsCqwxeggkgOdluEU4U9QANef6PmwMZHynXaaPCsJV5HNuTfFLd3tz+HpnfE5W L/dnEInbFkYTErd4k7WE3VSFYHGp9Gh8KrdLhrbU= 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 4.9 70/71] sctp: not disable bh in the whole sctp_get_port_local() Date: Fri, 11 Sep 2020 14:46:54 +0200 Message-Id: <20200911122508.433447547@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200911122504.928931589@linuxfoundation.org> References: <20200911122504.928931589@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 @@ -6687,8 +6687,6 @@ static long sctp_get_port_local(struct s 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; @@ -6707,20 +6705,21 @@ static long sctp_get_port_local(struct s continue; index = sctp_phashfn(sock_net(sk), 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(sock_net(sk), 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 @@ -6735,7 +6734,7 @@ static long sctp_get_port_local(struct s * port iterator, pp being NULL. */ head = &sctp_port_hashtable[sctp_phashfn(sock_net(sk), 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, sock_net(sk))) goto pp_found; @@ -6819,10 +6818,7 @@ success: ret = 0; fail_unlock: - spin_unlock(&head->lock); - -fail: - local_bh_enable(); + spin_unlock_bh(&head->lock); return ret; }