From nobody Mon Mar 23 21:37:03 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 C0DB83CA492 for ; Mon, 23 Mar 2026 15:18:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774279132; cv=none; b=Z2kpwpeJcPbnonwbKeBMC8zgn7CcXgdWeNTYQN7woOBmlNZzuY2HHXKCH0RCqvXzf7ZUcjQ0ki6vmuxWdvGk2mqtZD8/jGvHKGwSrYCA4vQJ1Cc8Yr7d549mWW5qOp/2TTLVFI000UrOA2Pza2Mxewr30lzAZvmndEQV4M06/WA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774279132; c=relaxed/simple; bh=wx6Y7sRnKEyzY6fn9CM3dUYPnLIUW+JIF5G1xiF3Fmg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QVsumHzj8WB8ogj3BlbhiuT3Z2lbLYVsNznTeL0s4OwNChcHZ/4h2mwzSPLCl9c3vMuPDaTGPYtnoLXA2CFvMguOb//lJ+jJlmv15R50ooVC67vQswzmVY4x/Xa3CN5wsUU507uzqac5yvb4kif9Qs2o6lhVEB4pJQ/KKWj2DtI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=VHv6e6L6; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="VHv6e6L6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774279130; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K89HWSWpfVYqvEFD4x4gGS5mGEm/+AIxXEbbLx4GIvo=; b=VHv6e6L6nUoEOcDvBVjijX9Ua/ecJ9WpQH4TKONqFrupgaGHGSQp5g4YASFE9q1ubyPJpE G0tCCpw38Sg+C9JLLx3HOfaB99QX+ouE1owUZztRZxwRyP1Ucv7Czbqxg7El5h+eMwqS5o imSafKFEntzY+FIn8AepcZReSLUirDk= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-609-6G7Fq-g4MEyxsY17lVplLg-1; Mon, 23 Mar 2026 11:18:46 -0400 X-MC-Unique: 6G7Fq-g4MEyxsY17lVplLg-1 X-Mimecast-MFC-AGG-ID: 6G7Fq-g4MEyxsY17lVplLg_1774279122 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 749F518002D1; Mon, 23 Mar 2026 15:18:42 +0000 (UTC) Received: from dell-per7425-02.rhts.eng.pek2.redhat.com (dell-per7425-02.rhts.eng.pek2.redhat.com [10.73.116.18]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 885031955D71; Mon, 23 Mar 2026 15:18:34 +0000 (UTC) From: Chunyu Hu To: akpm@linux-foundation.org, david@kernel.org, shuah@kernel.org, linux-mm@kvack.org, ljs@kernel.org Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, vbabka@suse.cz, rppt@kernel.org, surenb@google.com, mhocko@suse.com, ziy@nvidia.com, baolin.wang@linux.alibaba.com, npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, chuhu@redhat.com Subject: [PATCH v5 4/6] selftests/mm/vm_util: robust write_file() Date: Mon, 23 Mar 2026 23:17:51 +0800 Message-ID: <20260323151753.2576137-5-chuhu@redhat.com> In-Reply-To: <20260323151753.2576137-1-chuhu@redhat.com> References: <20260323151753.2576137-1-chuhu@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Content-Type: text/plain; charset="utf-8" Add two more checks for buflen and numwritten. The buflen should be at least one, otherwise the 'buflen - 1' could underflow and cause trouble. The numwritten should be equal to 'buflen - 1'. The test will exit if any of these conditions aren't met. Additionally, add more print information when a write failure occurs or a truncated write happens, providing clearer diagnostics. Signed-off-by: Chunyu Hu --- Chagnes in v5: - new patch for making improve on write_file. Add more safety checks and diagnostics info in log --- tools/testing/selftests/mm/vm_util.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests= /mm/vm_util.c index ad96d19d1b85..02db3caad646 100644 --- a/tools/testing/selftests/mm/vm_util.c +++ b/tools/testing/selftests/mm/vm_util.c @@ -769,6 +769,8 @@ void write_file(const char *path, const char *buf, size= _t buflen) { int fd; ssize_t numwritten; + if (buflen < 1) + ksft_exit_fail_msg("Incorrect buffer len: %zu\n", buflen); =20 fd =3D open(path, O_WRONLY); if (fd =3D=3D -1) @@ -777,5 +779,9 @@ void write_file(const char *path, const char *buf, size= _t buflen) numwritten =3D write(fd, buf, buflen - 1); close(fd); if (numwritten < 1) - ksft_exit_fail_msg("Write failed\n"); + ksft_exit_fail_msg("%s write(%s) failed: %s\n", path, buf, + strerror(errno)); + if (numwritten !=3D buflen - 1) + ksft_exit_fail_msg("%s write(%s) is truncated, expected %zu bytes, got %= zd bytes\n", + path, buf, buflen - 1, numwritten); } --=20 2.53.0