From: Izik Eidus <ieidus@redhat.com>
To: Hugh Dickins <hugh@veritas.com>
Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
aarcange@redhat.com, chrisw@redhat.com, alan@lxorguk.ukuu.org.uk,
device@lanana.org, linux-mm@kvack.org, nickpiggin@yahoo.com.au
Subject: Re: [PATCH 3/6] ksm: change the KSM_REMOVE_MEMORY_REGION ioctl.
Date: Mon, 04 May 2009 23:37:38 +0300 [thread overview]
Message-ID: <49FF5212.40208@redhat.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0905042024180.15009@blonde.anvils>
Hugh Dickins wrote:
> On Sun, 3 May 2009, Izik Eidus wrote:
>
>
>> This patch change the KSM_REMOVE_MEMORY_REGION ioctl to be specific per
>> memory region (instead of flushing all the registred memory regions inside
>> the file descriptor like it happen now)
>>
>> The previoes api was:
>> user register memory regions using KSM_REGISTER_MEMORY_REGION inside the fd,
>> and then when he wanted to remove just one memory region, he had to remove them
>> all using KSM_REMOVE_MEMORY_REGION.
>>
>> This patch change this beahivor by chaning the KSM_REMOVE_MEMORY_REGION
>> ioctl to recive another paramter that it is the begining of the virtual
>> address that is wanted to be removed.
>>
>> (user can still remove all the memory regions all at once, by just closing
>> the file descriptor)
>>
>> Signed-off-by: Izik Eidus <ieidus@redhat.com>
>>
>
> I realize that it's ridiculous to break my silence
Hello ! :)
> with a comment
> on this particular patch, when I've not yet commented on KSM as a
> whole. (In the last few days I have at last managed to set aside
> some time to give KSM the attention it deserves, but I'm still
> not yet through and ready to comment.)
>
> However, although this patch is on the right lines (certainly you
> should be allowing to remove individual regions rather than just
> all at once), I believe the patch is seriously broken and corrupting
> as is, so thought I'd better speak up now.
>
> remove_mm_from_hash_and_tree(slot->mm) is still doing its own
> silly loop through the slots:
> list_for_each_entry(slot, &slots, link)
> if (slot->mm == mm)
> break;
> So it will be operating on whatever it finds first
I just started to write big answer that go over the code path to show
why you are wrong, and then found the problem.
Thanks i will fix it and resend...
> , in general
> the wrong slot, and I expect havoc to follow once you kfree(slot).
>
> Easily fixed: replace remove_mm_from_hash_and_tree(mm)
> by remove_slot_from_hash_and_tree(slot).
>
Yea, remove_mm_from_hash_and_tree(mm) is surely something that we dont
need that was left from the old code base.
Thanks.
> Hugh
>
>
>> ---
>> mm/ksm.c | 31 +++++++++++++++++++++----------
>> 1 files changed, 21 insertions(+), 10 deletions(-)
>>
>> diff --git a/mm/ksm.c b/mm/ksm.c
>> index 982dfff..c14019f 100644
>> --- a/mm/ksm.c
>> +++ b/mm/ksm.c
>> @@ -561,17 +561,20 @@ static void remove_mm_from_hash_and_tree(struct mm_struct *mm)
>> list_del(&slot->link);
>> }
>>
>> -static int ksm_sma_ioctl_remove_memory_region(struct ksm_sma *ksm_sma)
>> +static int ksm_sma_ioctl_remove_memory_region(struct ksm_sma *ksm_sma,
>> + unsigned long addr)
>> {
>> struct ksm_mem_slot *slot, *node;
>>
>> down_write(&slots_lock);
>> list_for_each_entry_safe(slot, node, &ksm_sma->sma_slots, sma_link) {
>> - remove_mm_from_hash_and_tree(slot->mm);
>> - mmput(slot->mm);
>> - list_del(&slot->sma_link);
>> - kfree(slot);
>> - ksm_sma->nregions--;
>> + if (addr == slot->addr) {
>> + remove_mm_from_hash_and_tree(slot->mm);
>> + mmput(slot->mm);
>> + list_del(&slot->sma_link);
>> + kfree(slot);
>> + ksm_sma->nregions--;
>> + }
>> }
>> up_write(&slots_lock);
>> return 0;
>> @@ -579,12 +582,20 @@ static int ksm_sma_ioctl_remove_memory_region(struct ksm_sma *ksm_sma)
>>
>> static int ksm_sma_release(struct inode *inode, struct file *filp)
>> {
>> + struct ksm_mem_slot *slot, *node;
>> struct ksm_sma *ksm_sma = filp->private_data;
>> - int r;
>>
>> - r = ksm_sma_ioctl_remove_memory_region(ksm_sma);
>> + down_write(&slots_lock);
>> + list_for_each_entry_safe(slot, node, &ksm_sma->sma_slots, sma_link) {
>> + remove_mm_from_hash_and_tree(slot->mm);
>> + mmput(slot->mm);
>> + list_del(&slot->sma_link);
>> + kfree(slot);
>> + }
>> + up_write(&slots_lock);
>> +
>> kfree(ksm_sma);
>> - return r;
>> + return 0;
>> }
>>
>> static long ksm_sma_ioctl(struct file *filp,
>> @@ -607,7 +618,7 @@ static long ksm_sma_ioctl(struct file *filp,
>> break;
>> }
>> case KSM_REMOVE_MEMORY_REGION:
>> - r = ksm_sma_ioctl_remove_memory_region(sma);
>> + r = ksm_sma_ioctl_remove_memory_region(sma, arg);
>> break;
>> }
>>
>> --
>> 1.5.6.5
>>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2009-05-04 20:37 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-02 22:16 [PATCH 0/6] ksm changes Izik Eidus
2009-05-02 22:16 ` [PATCH 1/6] ksm: limiting the num of mem regions user can register per fd Izik Eidus
2009-05-02 22:16 ` [PATCH 2/6] ksm: dont allow overlap memory addresses registrations Izik Eidus
2009-05-02 22:16 ` [PATCH 3/6] ksm: change the KSM_REMOVE_MEMORY_REGION ioctl Izik Eidus
2009-05-02 22:16 ` [PATCH 4/6] ksm: change the prot handling to use the generic helper functions Izik Eidus
2009-05-02 22:16 ` [PATCH 5/6] ksm: build system make it compile for all archs Izik Eidus
2009-05-02 22:16 ` [PATCH 6/6] ksm: use another miscdevice minor number Izik Eidus
2009-05-04 19:43 ` [PATCH 3/6] ksm: change the KSM_REMOVE_MEMORY_REGION ioctl Hugh Dickins
2009-05-04 20:37 ` Izik Eidus [this message]
2009-05-03 2:08 ` [PATCH 1/6] ksm: limiting the num of mem regions user can register per fd Rik van Riel
2009-05-03 9:06 ` Izik Eidus
2009-05-03 2:08 ` Rik van Riel
-- strict thread matches above, loose matches on Subject: below --
2009-05-04 22:25 [PATCH 0/6] ksm changes (v2) Izik Eidus
2009-05-04 22:25 ` [PATCH 1/6] ksm: limiting the num of mem regions user can register per fd Izik Eidus
2009-05-04 22:25 ` [PATCH 2/6] ksm: dont allow overlap memory addresses registrations Izik Eidus
2009-05-04 22:25 ` [PATCH 3/6] ksm: change the KSM_REMOVE_MEMORY_REGION ioctl Izik Eidus
2009-05-06 0:53 ` Rik van Riel
2009-05-06 8:38 ` Izik Eidus
2009-05-06 11:16 ` Hugh Dickins
2009-05-06 13:34 ` Andrea Arcangeli
2009-05-06 13:56 ` Izik Eidus
2009-05-06 16:41 ` Hugh Dickins
2009-05-06 16:49 ` Chris Wright
2009-05-06 16:57 ` Hugh Dickins
2009-05-06 17:47 ` Andrea Arcangeli
2009-05-06 16:59 ` Izik Eidus
2009-05-07 11:31 ` Andrea Arcangeli
2009-05-07 13:13 ` Hugh Dickins
2009-05-07 13:23 ` Andrea Arcangeli
2009-05-06 14:25 ` Hugh Dickins
2009-05-06 14:45 ` Andrea Arcangeli
2009-05-06 15:36 ` Chris Wright
2009-05-06 15:27 ` Izik Eidus
2009-05-06 16:14 ` Chris Wright
2009-05-06 16:36 ` Hugh Dickins
2009-05-06 17:09 ` Chris Wright
2009-05-06 17:54 ` Hugh Dickins
2009-05-06 16:26 ` Hugh Dickins
2009-05-06 16:58 ` Izik Eidus
2009-05-06 23:59 ` Chris Wright
2009-05-07 2:41 ` Rik van Riel
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=49FF5212.40208@redhat.com \
--to=ieidus@redhat.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=chrisw@redhat.com \
--cc=device@lanana.org \
--cc=hugh@veritas.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nickpiggin@yahoo.com.au \
/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;
as well as URLs for NNTP newsgroup(s).