LVS
lvs-devel
Google
 
Web LinuxVirtualServer.org

[PATCH net-next v3 1/2] ipvs: add READ_ONCE barrier for ipvs->sysctl_ame

To: horms@xxxxxxxxxxxx
Subject: [PATCH net-next v3 1/2] ipvs: add READ_ONCE barrier for ipvs->sysctl_amemthresh
Cc: netdev@xxxxxxxxxxxxxxx, lvs-devel@xxxxxxxxxxxxxxx, netfilter-devel@xxxxxxxxxxxxxxx, linux-kernel@xxxxxxxxxxxxxxx, Alexander Mikhalitsyn <aleksandr.mikhalitsyn@xxxxxxxxxxxxx>, Julian Anastasov <ja@xxxxxx>, Pablo Neira Ayuso <pablo@xxxxxxxxxxxxx>, Jozsef Kadlecsik <kadlec@xxxxxxxxxxxxx>, Florian Westphal <fw@xxxxxxxxx>
From: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@xxxxxxxxxxxxx>
Date: Thu, 18 Apr 2024 16:57:42 +0200
Cc: Julian Anastasov <ja@xxxxxx>
Cc: Simon Horman <horms@xxxxxxxxxxxx>
Cc: Pablo Neira Ayuso <pablo@xxxxxxxxxxxxx>
Cc: Jozsef Kadlecsik <kadlec@xxxxxxxxxxxxx>
Cc: Florian Westphal <fw@xxxxxxxxx>
Suggested-by: Julian Anastasov <ja@xxxxxx>
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@xxxxxxxxxxxxx>
---
 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 143a341bbc0a..32be24f0d4e4 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



<Prev in Thread] Current Thread [Next in Thread>