From patchwork Fri Jan 24 09:32:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 233121 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=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,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 EA5AEC2D0DB for ; Fri, 24 Jan 2020 10:06:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B6D142087E for ; Fri, 24 Jan 2020 10:06:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579860375; bh=LY2r0NJZN5XEzlmexeOZQTjHN1jzFqohm1sxyG5AAZs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=NqpOWZe13IdfphHIsL4pca7Q3AJTvUedEKk4dFy9Dtfp21X2xbyM1GesYR1N02kJH oFal89SNhrb/EyadwjtvXtXWuB2YTTG67iv2qEabCvIO9vi6xyzaRzEj2VKiAr7h1d ovyBs0eDbkv0qr6NtK7GhiYW1L1mp8uefgjXa82s= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388600AbgAXKGO (ORCPT ); Fri, 24 Jan 2020 05:06:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:42832 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389276AbgAXKGN (ORCPT ); Fri, 24 Jan 2020 05:06:13 -0500 Received: from localhost (unknown [145.15.244.15]) (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 00E1E20718; Fri, 24 Jan 2020 10:06:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579860372; bh=LY2r0NJZN5XEzlmexeOZQTjHN1jzFqohm1sxyG5AAZs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VJkeHfRNfqcoi2XxX96kCL1Wzqd+l6RyvVhJo7KvEIJT2WshYXNdKNIm123YFMUnN 1bgql0KIvy9gi2+wEgKufw3rKc9hnQU/O8nwCHInYZM71OHIHAEP2bS54rPcnTNdWg 3cdmbPGtpFYLFpUPw6oWEVkF1zbZnrzBu5+Pg4SM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , Jakub Kicinski , Sasha Levin Subject: [PATCH 4.14 324/343] tcp: annotate lockless access to tcp_memory_pressure Date: Fri, 24 Jan 2020 10:32:22 +0100 Message-Id: <20200124093002.398212922@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200124092919.490687572@linuxfoundation.org> References: <20200124092919.490687572@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Eric Dumazet [ Upstream commit 1f142c17d19a5618d5a633195a46f2c8be9bf232 ] tcp_memory_pressure is read without holding any lock, and its value could be changed on other cpus. Use READ_ONCE() to annotate these lockless reads. The write side is already using atomic ops. Fixes: b8da51ebb1aa ("tcp: introduce tcp_under_memory_pressure()") Signed-off-by: Eric Dumazet Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- include/net/tcp.h | 2 +- net/ipv4/tcp.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index 00d10f0e11949..c963023103149 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -289,7 +289,7 @@ static inline bool tcp_under_memory_pressure(const struct sock *sk) mem_cgroup_under_socket_pressure(sk->sk_memcg)) return true; - return tcp_memory_pressure; + return READ_ONCE(tcp_memory_pressure); } /* * The next routines deal with comparing 32 bit unsigned ints diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 8f07655718f34..db1eceda2359c 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -328,7 +328,7 @@ void tcp_enter_memory_pressure(struct sock *sk) { unsigned long val; - if (tcp_memory_pressure) + if (READ_ONCE(tcp_memory_pressure)) return; val = jiffies; @@ -343,7 +343,7 @@ void tcp_leave_memory_pressure(struct sock *sk) { unsigned long val; - if (!tcp_memory_pressure) + if (!READ_ONCE(tcp_memory_pressure)) return; val = xchg(&tcp_memory_pressure, 0); if (val)