Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp1418396lqh; Mon, 6 May 2024 07:15:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVmAIUJReh4hhHT2AQomg5Rh78uE6KOdIR7Go1x0eD/ckuMTRqhd7vDsq9jBSZjEOw49KkesHjVtwXfaz5kzD0qXcOU8H1WjVObUhIJWg== X-Google-Smtp-Source: AGHT+IFkAkPh0KBMkHArf7hAPaVElz23F5aMQJ2nVEaicR/C4pYM+Rk8y/Nw7wYrhYptSqoayMEK X-Received: by 2002:a50:9b57:0:b0:56e:232b:95cd with SMTP id a23-20020a509b57000000b0056e232b95cdmr5873331edj.41.1715004918965; Mon, 06 May 2024 07:15:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715004918; cv=pass; d=google.com; s=arc-20160816; b=lSl2yIwiL0mpDLMJhaZ++O6jqd7D2mcde4u3KZ+1rEeV6U2RS0hnmp7f9SyK+yQqeL negfbuyFcBCymcLwZFvZ0SmHTX7SSISUJeQgQg9yimJVPPc4/7MU8Ay+pszY9eGab4y4 LYPs60UKydlJNz3AEgAuy0P3YoXQ6abrxcpVJFX820oJFuoxF5iwEVZ5yzKaTYad2ZkK SphWgDAbLqQ/B8ZVzrJcNfmyBVlHtgzfFlNxhehydL7kzI4Y63phpdbBK6jwIkwKaESO /7kfuUKE/mN3i3H3SwwiK6cmYuouIfvJ0mNU46IVnTL/QoqnPKETOT1nEtoHsCWWD3jg E21w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=ZyaYKGnkDPnTk6rgEgUZ2eoc97Zq0+zWClbbP5jrG5Y=; fh=WPZiuwQoP/+xu6BrYeD0VmNFNoGANTByzdduzQAySP0=; b=g6/MKqum78dFzTsKTC0Swmi3PL4fvDuSZZnl/lAJRm+nrUFDg6dQFEoJdZLIuLNk8S ACpYPsF/t2REjoSeeHfKktEsz72DVm5kHS4AM7DhdWWkQkBGj3kfGvoQuMDUcnMZf+7V ReLEDk7QxVYt8j94gGjTDcRf0MNRQcr4mTPpJk9zuLD92yd1u9kmTzAm9Pv8jttEf6LT GY1YrQHa5mYCrZx/5xqVO+oiVTAiaqQTMg5c3zp+s31IU/5WxdmQEAYdzo7nIezsH9Df gJuUN/Q+B7Ibeb5+g3xkcYdnGBkReQ+oixwn7/QLzmrzbfAPvtijlwZ7MERMrsJSDPBQ x1Wg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=phcptJ2Q; arc=pass (i=1 spf=pass spfdomain=canonical.com dkim=pass dkdomain=canonical.com dmarc=pass fromdomain=canonical.com); spf=pass (google.com: domain of linux-kernel+bounces-169955-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169955-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id y6-20020aa7ccc6000000b00572a223df70si4743926edt.280.2024.05.06.07.15.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 07:15:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-169955-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=phcptJ2Q; arc=pass (i=1 spf=pass spfdomain=canonical.com dkim=pass dkdomain=canonical.com dmarc=pass fromdomain=canonical.com); spf=pass (google.com: domain of linux-kernel+bounces-169955-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169955-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id AE5A81F21DF7 for ; Mon, 6 May 2024 14:15:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E048713CF95; Mon, 6 May 2024 14:15:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="phcptJ2Q" Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA53413BC04 for ; Mon, 6 May 2024 14:15:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.122 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715004904; cv=none; b=cYP3giym3o3XejDgqja6joyYBb2KG4DNQ6nYYMcYIgH0bggY4OlNGc1Fqx3uouJhGOdoS/ve0k5oNbgj/uMKLLzU6rQE0IfvFzvS2uZmPNOPhfqsog4rHGnlvq8CoFVGQqMcBhIo8Zzcq4f2tMkeABevFWZfGbCEvIW5a4jF/s8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715004904; c=relaxed/simple; bh=wcidanXZQTb3aE8biUO7m9uGWdjY9fC00+u5PTnfNfg=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=oXqLwEFg+LUAeOkbCtl5IS/bQRnZLJMqMJw1zcIMaI6qy/6LE9vGC2wkIvvcj+XV5ve0pC1cOcUjMG76I1TerILiPtwwQqDuwlDX/fAnadKGAVJkGOv+VtCQ9eSN1x24wMuNO82xqXN36vfcA0MRzbP0AU6ESHPp3sGPxOGT7Ew= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=phcptJ2Q; arc=none smtp.client-ip=185.125.188.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 7F5723F298 for ; Mon, 6 May 2024 14:14:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1715004894; bh=ZyaYKGnkDPnTk6rgEgUZ2eoc97Zq0+zWClbbP5jrG5Y=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=phcptJ2QVN0G8jM8cNMMBXZ5gNfWBLDEoemhGjO0tdU90Nb3ykM8qrXT3sAjsxcpr KREGP2NgUd6/12S7lw8jJCPz2dG2vx6r5sJdR4sr5UzGCFp7HCyzSNiPcSuWowiNiP NkAXKTkYpHInv2dEAo1VPpGQYblhUWHpQIs/SoU3gSebJOSBbigY0CPFItPAPdE/R4 eFtGOVo4zZYzW4u7xhq/hAba2J2TS3M3aBGduEP9kw4VZ94PnHbwPnt4L1AFo7BcOx RkIJ06U88vNhmFzum63uBDrQQrvJ6vlr9OuEoVsrqZqZdV0Q/FBULMxdJDiWtRqAfc 0DljOOaRMjI/A== Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a59a17f35c8so123115066b.0 for ; Mon, 06 May 2024 07:14:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715004894; x=1715609694; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ZyaYKGnkDPnTk6rgEgUZ2eoc97Zq0+zWClbbP5jrG5Y=; b=TP1Ah07zN3/1GhmtwaKKbAl2xRhU5r+rX+f2diZdOZUD3UvBKwaucdnMZDmctOQZ9s MlcIrdRZKwfuTD/xyJRWKDTWP8E/rNaE9mPp4GRVptb0lYVmrwnuUJUEidoH3nZezPZB Z3uW9nvTXnTV7aLWjmryxyk6wZeeYbgCreOaT6Dp6HAkMfSGH+DyEsTVBS+ycvSD8shE Eh6P1L7xkEgYcgxWqt9cpBsnYaVaggfGemOcQpVX7bhcVnlNp2SjcKF+6k88/N/Bm4mU uFw6JaeGJlMJ0E5RZhFyLEpvHXW1Sz2NdBaqPKmWXMYnGgELjyuwDvrIPsXAADabVUG+ Hl3A== X-Forwarded-Encrypted: i=1; AJvYcCV/u/9itigu8/d4GgjcexphRui2QwO1Qpoah7w2zAcdEnlWG1Lj9bWEU5XCbpY5KKCYhXS33CuY07sMhRh1iPcbMtTY/yu8AAqsN/iU X-Gm-Message-State: AOJu0YzNybEV8Igap4noqrMkJ/IiJOfPxBl1k2vjw4s6K3ttb/xjY3VQ 1halXnozrBvC1fzpruftA5IEb4XsvTjRY7s1hymkKIdawJRdHkBWYSF47cG3El0EnJFWilU5MAR 9FOlMVmIMy+I362PPTrUf/SqdZiWSfYXGVXSO2Mxy97monaYWPc5Adf3vzlqs5wTSLq0TjJ+zWB 0Pag== X-Received: by 2002:a17:906:4899:b0:a59:bfd3:2b27 with SMTP id v25-20020a170906489900b00a59bfd32b27mr2701618ejq.70.1715004894083; Mon, 06 May 2024 07:14:54 -0700 (PDT) X-Received: by 2002:a17:906:4899:b0:a59:bfd3:2b27 with SMTP id v25-20020a170906489900b00a59bfd32b27mr2701599ejq.70.1715004893754; Mon, 06 May 2024 07:14:53 -0700 (PDT) Received: from amikhalitsyn.lan ([2001:470:6d:781:4703:a034:4f89:f1de]) by smtp.gmail.com with ESMTPSA id xh9-20020a170906da8900b00a597ff2fc0dsm4663754ejb.69.2024.05.06.07.14.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 07:14:53 -0700 (PDT) From: Alexander Mikhalitsyn To: horms@verge.net.au Cc: netdev@vger.kernel.org, lvs-devel@vger.kernel.org, netfilter-devel@vger.kernel.org, linux-kernel@vger.kernel.org, Alexander Mikhalitsyn , Julian Anastasov , Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal Subject: [PATCH v4 1/2] ipvs: add READ_ONCE barrier for ipvs->sysctl_amemthresh Date: Mon, 6 May 2024 16:14:43 +0200 Message-Id: <20240506141444.145946-1-aleksandr.mikhalitsyn@canonical.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Cc: Julian Anastasov Cc: Simon Horman Cc: Pablo Neira Ayuso Cc: Jozsef Kadlecsik Cc: Florian Westphal Suggested-by: Julian Anastasov Signed-off-by: Alexander Mikhalitsyn --- net/netfilter/ipvs/ip_vs_ctl.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c index 50b5dbe40eb8..e122fa367b81 100644 --- a/net/netfilter/ipvs/ip_vs_ctl.c +++ b/net/netfilter/ipvs/ip_vs_ctl.c @@ -94,6 +94,7 @@ static void update_defense_level(struct netns_ipvs *ipvs) { struct sysinfo i; int availmem; + int amemthresh; int nomem; int to_change = -1; @@ -105,7 +106,8 @@ static void update_defense_level(struct netns_ipvs *ipvs) /* si_swapinfo(&i); */ /* availmem = availmem - (i.totalswap - i.freeswap); */ - nomem = (availmem < ipvs->sysctl_amemthresh); + amemthresh = max(READ_ONCE(ipvs->sysctl_amemthresh), 0); + nomem = (availmem < amemthresh); local_bh_disable(); @@ -145,9 +147,8 @@ static void update_defense_level(struct netns_ipvs *ipvs) break; case 1: if (nomem) { - ipvs->drop_rate = ipvs->drop_counter - = ipvs->sysctl_amemthresh / - (ipvs->sysctl_amemthresh-availmem); + ipvs->drop_counter = amemthresh / (amemthresh - availmem); + ipvs->drop_rate = ipvs->drop_counter; ipvs->sysctl_drop_packet = 2; } else { ipvs->drop_rate = 0; @@ -155,9 +156,8 @@ static void update_defense_level(struct netns_ipvs *ipvs) break; case 2: if (nomem) { - ipvs->drop_rate = ipvs->drop_counter - = ipvs->sysctl_amemthresh / - (ipvs->sysctl_amemthresh-availmem); + ipvs->drop_counter = amemthresh / (amemthresh - availmem); + ipvs->drop_rate = ipvs->drop_counter; } else { ipvs->drop_rate = 0; ipvs->sysctl_drop_packet = 1; -- 2.34.1