[Devel] [PATCH RH8 3/6] ipv6/sit: account and don't WARN on ip_tunnel_prl structs allocation

Vasily Averin vvs at virtuozzo.com
Mon Apr 12 13:26:36 MSK 2021


The size of the ip_tunnel_prl structs allocation is controllable from user-space,
thus it's better to avoid spam in dmesg if allocation failed.
Also add __GFP_ACCOUNT as this is a good candidate for per-memcg accounting.

khorenko@: allocation is temporary and limited to 4GB.

vz7: https://jira.sw.ru/browse/PSBM-58330
vz8: https://jira.sw.ru/browse/PSBM-120694

Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
(cherry-picked from vz7 commit)
Signed-off-by: Vasily Averin <vvs at virtuozzo.com>
---
 net/ipv6/sit.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
index 3fab62f21903..37b2463cf1df 100644
--- a/net/ipv6/sit.c
+++ b/net/ipv6/sit.c
@@ -319,7 +319,7 @@ static int ipip6_tunnel_get_prl(struct ip_tunnel *t,
 	 * we try harder to allocate.
 	 */
 	kp = (cmax <= 1 || ve_capable(CAP_NET_ADMIN)) ?
-		kcalloc(cmax, sizeof(*kp), GFP_KERNEL | __GFP_NOWARN) :
+		kcalloc(cmax, sizeof(*kp), GFP_KERNEL_ACCOUNT | __GFP_NOWARN) :
 		NULL;
 
 	rcu_read_lock();
@@ -332,7 +332,8 @@ static int ipip6_tunnel_get_prl(struct ip_tunnel *t,
 		 * For root users, retry allocating enough memory for
 		 * the answer.
 		 */
-		kp = kcalloc(ca, sizeof(*kp), GFP_ATOMIC);
+		kp = kcalloc(ca, sizeof(*kp), GFP_ATOMIC | __GFP_ACCOUNT |
+				__GFP_NOWARN);
 		if (!kp) {
 			ret = -ENOMEM;
 			goto out;
-- 
2.25.1



More information about the Devel mailing list