Re: [PATCH net-next v2 1/2] ipvs: add READ_ONCE barrier for ipvs->sysctl_amemthresh

Julian Anastasov <[email protected]>
Newsgroups org.kernel.vger.lvs-devel,org.kernel.vger.linux-kernel,org.kernel.vger.netdev,org.kernel.vger.netfilter-devel
Message-ID <[email protected]>
	Hello,

On Thu, 18 Apr 2024, Alexander Mikhalitsyn wrote:

> Cc: Julian Anastasov <[email protected]>
> Cc: Simon Horman <[email protected]>
> Cc: Pablo Neira Ayuso <[email protected]>
> Cc: Jozsef Kadlecsik <[email protected]>
> Cc: Florian Westphal <[email protected]>
> Suggested-by: Julian Anastasov <[email protected]>
> Signed-off-by: Alexander Mikhalitsyn <[email protected]>
> ---
>  net/netfilter/ipvs/ip_vs_ctl.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
> index 143a341bbc0a..daa62b8b2dd1 100644
> --- a/net/netfilter/ipvs/ip_vs_ctl.c
> +++ b/net/netfilter/ipvs/ip_vs_ctl.c

> @@ -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();
>  
> @@ -146,8 +148,8 @@ static void update_defense_level(struct netns_ipvs *ipvs)
>  	case 1:
>  		if (nomem) {
>  			ipvs->drop_rate = ipvs->drop_counter
> -				= ipvs->sysctl_amemthresh /
> -				(ipvs->sysctl_amemthresh-availmem);
> +				= amemthresh /
> +				(amemthresh-availmem);

	Thanks, both patches look ok except that the old styling
is showing warnings for this patch:

scripts/checkpatch.pl --strict /tmp/file1.patch

	It would be great if you silence them somehow in v3...

	BTW, est_cpulist is masked with current->cpus_mask of the
sysctl writer process, if that is of any help. That is why I skipped
it but lets keep it read-only for now...

>  			ipvs->sysctl_drop_packet = 2;
>  		} else {
>  			ipvs->drop_rate = 0;
> @@ -156,8 +158,8 @@ static void update_defense_level(struct netns_ipvs *ipvs)
>  	case 2:
>  		if (nomem) {
>  			ipvs->drop_rate = ipvs->drop_counter
> -				= ipvs->sysctl_amemthresh /
> -				(ipvs->sysctl_amemthresh-availmem);
> +				= amemthresh /
> +				(amemthresh-availmem);
>  		} else {
>  			ipvs->drop_rate = 0;
>  			ipvs->sysctl_drop_packet = 1;

Regards

--
Julian Anastasov <[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.