lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <2ecdf349-779f-43d5-ae3d-55d973ea50e9@163.com>
Date: Mon, 17 Mar 2025 17:13:09 +0800
From: Liu Ye <liuyerd@....com>
To: David Hildenbrand <david@...hat.com>, akpm@...ux-foundation.org
Cc: willy@...radead.org, ran.xiaokai@....com.cn, dan.carpenter@...aro.org,
 linux-kernel@...r.kernel.org, linux-fsdevel@...r.kernel.org,
 Liu Ye <liuye@...inos.cn>
Subject: Re: [PATCH] fs/proc/page: Refactoring to reduce code duplication.


在 2025/3/17 16:56, David Hildenbrand 写道:
> On 17.03.25 09:01, Liu Ye wrote:
>> From: Liu Ye <liuye@...inos.cn>
>>
>> The function kpageflags_read and kpagecgroup_read is quite similar
>> to kpagecount_read. Consider refactoring common code into a helper
>> function to reduce code duplication.
>>
>> Signed-off-by: Liu Ye <liuye@...inos.cn>
>> ---
>>   fs/proc/page.c | 158 ++++++++++++++++---------------------------------
>>   1 file changed, 50 insertions(+), 108 deletions(-)
>>
>> diff --git a/fs/proc/page.c b/fs/proc/page.c
>> index a55f5acefa97..f413016ebe67 100644
>> --- a/fs/proc/page.c
>> +++ b/fs/proc/page.c
>> @@ -37,19 +37,17 @@ static inline unsigned long get_max_dump_pfn(void)
>>   #endif
>>   }
>>   -/* /proc/kpagecount - an array exposing page mapcounts
>> - *
>> - * Each entry is a u64 representing the corresponding
>> - * physical page mapcount.
>> - */
>> -static ssize_t kpagecount_read(struct file *file, char __user *buf,
>> -                 size_t count, loff_t *ppos)
>> +static ssize_t kpage_read(struct file *file, char __user *buf,
>> +        size_t count, loff_t *ppos,
>> +        u64 (*get_page_info)(struct page *))
>
> Can we just indicate using an enum which operation to perform, so we can avoid having+passing these functions?
>
Like this? Good idea, I'll send a new patch later.

enum kpage_operation {
    KPAGE_FLAGS,
    KPAGE_COUNT,
    KPAGE_CGROUP,
};

static u64 get_page_info(struct page *page, enum kpage_operation op)
{
    switch (op) {
    case KPAGE_FLAGS:
        return stable_page_flags(page);
    case KPAGE_COUNT:
        return page_count(page);
    case KPAGE_CGROUP:
        return page_cgroup_ino(page);
    default:
        return 0;
    }
}

static ssize_t kpageflags_read(struct file *file, char __user *buf,
                               size_t count, loff_t *ppos)
{
    return kpage_read(file, buf, count, ppos, KPAGE_FLAGS);
}

static ssize_t kpagecount_read(struct file *file, char __user *buf,
                               size_t count, loff_t *ppos)
{
    return kpage_read(file, buf, count, ppos, KPAGE_COUNT);
}

static ssize_t kpagecgroup_read(struct file *file, char __user *buf,
                                size_t count, loff_t *ppos)
{
    return kpage_read(file, buf, count, ppos, KPAGE_CGROUP);
}

static ssize_t kpage_read(struct file *file, char __user *buf,
                          size_t count, loff_t *ppos,
                          enum kpage_operation op)
{
        ...
        info = get_page_info(ppage, op);
        ...
}





Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ