linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Wei Yang <richard.weiyang@gmail.com>
To: David Hildenbrand <david@redhat.com>
Cc: Wei Yang <richard.weiyang@gmail.com>,
	akpm@linux-foundation.org, linux-mm@kvack.org,
	Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	Rik van Riel <riel@surriel.com>,
	"Liam R . Howlett" <Liam.Howlett@oracle.com>,
	Vlastimil Babka <vbabka@suse.cz>,
	Harry Yoo <harry.yoo@oracle.com>
Subject: Re: [PATCH 1/3] selftests/mm: check a valid fd with negative value
Date: Thu, 17 Jul 2025 01:18:29 +0000	[thread overview]
Message-ID: <20250717011829.yhzeq32f4pgzrfmj@master> (raw)
In-Reply-To: <f109b782-5081-4c5a-b11c-0c5244301c09@redhat.com>

On Wed, Jul 16, 2025 at 10:52:21AM +0200, David Hildenbrand wrote:
>On 16.07.25 10:27, Wei Yang wrote:
>> fd 0 is usually occupied by stdin, which is not expected to be returned
>> by open(). But 0 is still a valid fd.
>> 
>> Check the valid fd with negative value like other places.
>> 
>> Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
>> Cc: David Hildenbrand <david@redhat.com>
>> Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
>> Cc: Rik van Riel <riel@surriel.com>
>> Cc: Liam R. Howlett <Liam.Howlett@oracle.com>
>> Cc: Vlastimil Babka <vbabka@suse.cz>
>> Cc: Harry Yoo <harry.yoo@oracle.com>
>> ---
>>   tools/testing/selftests/mm/ksm_functional_tests.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/tools/testing/selftests/mm/ksm_functional_tests.c b/tools/testing/selftests/mm/ksm_functional_tests.c
>> index d8bd1911dfc0..6da5c3340e10 100644
>> --- a/tools/testing/selftests/mm/ksm_functional_tests.c
>> +++ b/tools/testing/selftests/mm/ksm_functional_tests.c
>> @@ -81,7 +81,7 @@ static long get_my_ksm_zero_pages(void)
>>   	ssize_t read_size;
>>   	unsigned long my_ksm_zero_pages;
>> -	if (!proc_self_ksm_stat_fd)
>> +	if (proc_self_ksm_stat_fd < 0)
>>   		return 0;
>
>Only test_unmerge_zero_pages() calls get_my_ksm_zero_pages(). And there, we
>have
>
>if (proc_self_ksm_stat_fd < 0) {
>	ksft_test_result_skip("open(\"/proc/self/ksm_stat\") failed\n");
>	return;
>}
>
>As the fd is opened after others, we should never get fd=0.
>

You are right.

>So probably, this should just be handled as part of factoring it out, no need
>for this change upfront AFAIKS.
>

My intention of this change is, we plan to move get_my_ksm_zero_pages() into a
standalone helper and will open and check the fd there. To make following
change consistent, I split it out.

If you think it is not necessary, will drop this.

>-- 
>Cheers,
>
>David / dhildenb

-- 
Wei Yang
Help you, Help me


  reply	other threads:[~2025-07-17  1:18 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-16  8:27 [PATCH 0/3] selftests/mm: assert rmap behave as expected Wei Yang
2025-07-16  8:27 ` [PATCH 1/3] selftests/mm: check a valid fd with negative value Wei Yang
2025-07-16  8:52   ` David Hildenbrand
2025-07-17  1:18     ` Wei Yang [this message]
2025-07-17  8:27       ` David Hildenbrand
2025-07-16  8:27 ` [PATCH 2/3] selftests/mm: put general ksm operation into vm_util Wei Yang
2025-07-16  9:20   ` David Hildenbrand
2025-07-17  2:45     ` Wei Yang
2025-07-17  3:30       ` Wei Yang
2025-07-17 11:57         ` David Hildenbrand
2025-07-17 11:56       ` David Hildenbrand
2025-07-16  8:27 ` [PATCH 3/3] selftests/mm: assert rmap behave as expected Wei Yang
2025-07-16 13:34   ` David Hildenbrand
2025-07-17  3:17     ` Wei Yang
2025-07-25  2:16       ` Wei Yang
2025-07-25 13:34         ` David Hildenbrand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250717011829.yhzeq32f4pgzrfmj@master \
    --to=richard.weiyang@gmail.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=harry.yoo@oracle.com \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=riel@surriel.com \
    --cc=vbabka@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox