lkml.org 
[lkml]   [2010]   [Jul]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    SubjectRe: [PATCH 4/8] v3 Allow memory_block to span multiple memory sections
    From
    Date
    On Mon, 2010-07-19 at 22:55 -0500, Nathan Fontenot wrote:
    > +static int add_memory_section(int nid, struct mem_section *section,
    > + unsigned long state, enum mem_add_context context)
    > +{
    > + struct memory_block *mem;
    > + int ret = 0;
    > +
    > + mem = find_memory_block(section);
    > + if (mem) {
    > + atomic_inc(&mem->section_count);
    > + kobject_put(&mem->sysdev.kobj);
    > + } else
    > + ret = init_memory_block(&mem, section, state);
    > +
    > if (!ret) {
    > - if (context == HOTPLUG)
    > + if (context == HOTPLUG &&
    > + atomic_read(&mem->section_count) == sections_per_block)
    > ret = register_mem_sect_under_node(mem, nid);
    > }

    I think the atomic_inc() can race with the atomic_dec_and_test() in
    remove_memory_block().

    Thread 1 does:

    mem = find_memory_block(section);

    Thread 2 does

    atomic_dec_and_test(&mem->section_count);

    and destroys the memory block, Thread 1 runs again:

    if (mem) {
    atomic_inc(&mem->section_count);
    kobject_put(&mem->sysdev.kobj);
    } else

    but now mem got destroyed by Thread 2. You probably need to change
    find_memory_block() to itself take a reference, and to use
    atomic_inc_unless().

    -- Dave



    \
     
     \ /
      Last update: 2010-07-20 21:21    [W:0.020 / U:0.056 seconds]
    ©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site