From patchwork Fri Apr 22 15:57:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Vernet X-Patchwork-Id: 12823696 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9C8BC433EF for ; Fri, 22 Apr 2022 15:57:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C6FDD6B00A1; Fri, 22 Apr 2022 11:57:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C1C7E6B00A2; Fri, 22 Apr 2022 11:57:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A20416B00A3; Fri, 22 Apr 2022 11:57:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 8F01A6B00A1 for ; Fri, 22 Apr 2022 11:57:52 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 5F6C860CF2 for ; Fri, 22 Apr 2022 15:57:52 +0000 (UTC) X-FDA: 79384970784.01.5D8507E Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) by imf13.hostedemail.com (Postfix) with ESMTP id DE1D620031 for ; Fri, 22 Apr 2022 15:57:48 +0000 (UTC) Received: by mail-qt1-f170.google.com with SMTP id f14so5805378qtq.1 for ; Fri, 22 Apr 2022 08:57:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ybM2/MebbmHh9Uk+Civ8p2eG1e4lJfObLB1b9VYbOt0=; b=dURcLMDe6OjgAo56PrZgThUyPkdWnAzrGcsRDXkbuE+ZRSm/FqcX/pWOFdaL33osLw Vbjg6BtwnKMIUu6ru3u5sQXm7NzYOPSjDbO8idKD4WkCH6v7IvYm/GhD4x917LGlrTM6 ytGo91BWSt51AVTHVUzQA92F/DqFY33vmm8OkNtsfl/xSvmLuhUPAoeyVKSFL+QSnUAL X6OFcwq2sZOIOyRzczlgolIceT9uDDB/MWZpVnOq6c6JCzwqOp4PAA6sTR4/LSVZZLDS 5BtWbOoIL7rBOOrgf7QJxu//jUIyzEUJH+y5DhqO9f4fCJQW6hzx9I+mcHNbXxKcn8dj NGNg== X-Gm-Message-State: AOAM532uHx8dRpKNf7d0ORR2m5Y/Hyz4WcPzIn5uuSwJeOUzRUU/t/x3 FJ6Cu7NgAOa+g/1jTwA5BfU= X-Google-Smtp-Source: ABdhPJyMRR8Jr7rZxhR2OLWQ5M5A2n4MOa9OS2dQPPKnynJcD2a5ME2ySPAE1TYdGztolYD7YY14HQ== X-Received: by 2002:a05:622a:151:b0:2f1:fe9f:9177 with SMTP id v17-20020a05622a015100b002f1fe9f9177mr3762575qtw.628.1650643071259; Fri, 22 Apr 2022 08:57:51 -0700 (PDT) Received: from localhost (fwdproxy-ash-019.fbsv.net. [2a03:2880:20ff:13::face:b00c]) by smtp.gmail.com with ESMTPSA id c17-20020a05622a025100b002f34db6a3a2sm1543874qtx.4.2022.04.22.08.57.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 08:57:51 -0700 (PDT) From: David Vernet To: akpm@linux-foundation.org Cc: tj@kernel.org, roman.gushchin@linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org, hannes@cmpxchg.org, mhocko@kernel.org, shakeelb@google.com, kernel-team@fb.com, void@manifault.com Subject: [PATCH 5/5] cgroup: Fix racy check in alloc_pagecache_max_30M() helper function Date: Fri, 22 Apr 2022 08:57:29 -0700 Message-Id: <20220422155728.3055914-6-void@manifault.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220422155728.3055914-1-void@manifault.com> References: <20220422155728.3055914-1-void@manifault.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: DE1D620031 X-Rspam-User: Authentication-Results: imf13.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf13.hostedemail.com: domain of dcvernet@gmail.com designates 209.85.160.170 as permitted sender) smtp.mailfrom=dcvernet@gmail.com X-Stat-Signature: mz51bpim9fix5gb6bjk8ub471773nyb9 X-HE-Tag: 1650643068-84987 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000048, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: alloc_pagecache_max_30M() in the cgroup memcg tests performs a 50MB pagecache allocation, which it expects to be capped at 30MB due to the calling process having a memory.high setting of 30MB. After the allocation, the function contains a check that verifies that MB(29) < memory.current <= MB(30). This check can actually fail non-deterministically. The testcases that use this function are test_memcg_high() and test_memcg_max(), which set memory.min and memory.max to 30MB respectively for the cgroup under test. The allocation can slightly exceed this number in both cases, and for memory.max, the process performing the allocation will not have the OOM killer invoked as it's performing a pagecache allocation. This patchset therefore updates the above check to instead use the verify_close() helper function. Signed-off-by: David Vernet Acked-by: Roman Gushchin --- tools/testing/selftests/cgroup/test_memcontrol.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testing/selftests/cgroup/test_memcontrol.c index c4735fa36a3d..088850f01ae7 100644 --- a/tools/testing/selftests/cgroup/test_memcontrol.c +++ b/tools/testing/selftests/cgroup/test_memcontrol.c @@ -564,9 +564,14 @@ static int alloc_pagecache_max_30M(const char *cgroup, void *arg) { size_t size = MB(50); int ret = -1; - long current; + long current, high, max; int fd; + high = cg_read_long(cgroup, "memory.high"); + max = cg_read_long(cgroup, "memory.max"); + if (high != MB(30) && max != MB(30)) + goto cleanup; + fd = get_temp_fd(); if (fd < 0) return -1; @@ -575,7 +580,7 @@ static int alloc_pagecache_max_30M(const char *cgroup, void *arg) goto cleanup; current = cg_read_long(cgroup, "memory.current"); - if (current <= MB(29) || current > MB(30)) + if (!values_close(current, MB(30), 5)) goto cleanup; ret = 0;