Re: [PATCH v3 1/3] x86/ldt: Make modify_ldt synchronous

From: Andy Lutomirski
Date: Sat Jul 25 2015 - 00:53:10 EST


On Fri, Jul 24, 2015 at 8:29 AM, Borislav Petkov <bp@xxxxxxxxx> wrote:
> Let it stick out:
>
> if (!cpumask_equal(mm_cpumask(current_mm), cpumask_of(smp_processor_id())))
> smp_call_function(flush_ldt, current_mm, 1);

I see your wide terminal and raise you a complete rewrite of that
function. Sigh, why did I assume the old code was the right way to do
it?

>> #endif
>> - }
>> - if (oldsize) {
>> - paravirt_free_ldt(oldldt, oldsize);
>> - if (oldsize * LDT_ENTRY_SIZE > PAGE_SIZE)
>> - vfree(oldldt);
>> - else
>> - put_page(virt_to_page(oldldt));
>> - }
>> - return 0;
>> + preempt_enable();
>> }
>>
>> -static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
>> +static void free_ldt_struct(struct ldt_struct *ldt)
>> {
>> - int err = alloc_ldt(new, old->size, 0);
>> - int i;
>> -
>> - if (err < 0)
>> - return err;
>> -
>> - for (i = 0; i < old->size; i++)
>> - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
>> - return 0;
>> + if (unlikely(ldt)) {
>
> Save an indentation level:
>
> int alloc_size;
>
> if (!ldt)
> return;
>
> alloc_size = sizeof(struct ldt_struct) + ldt->size * LDT_ENTRY_SIZE;
>

Hah we both missed it. This is wrong. (Fix your backport!)

> ...
>
>> + paravirt_free_ldt(ldt->entries, ldt->size);
>> + if (alloc_size > PAGE_SIZE)
>> + vfree(ldt->entries);
>> + else
>> + put_page(virt_to_page(ldt->entries));

I'm not sure this is correct, so I changed it to something obviously
correct (kmalloc/kfree).

>>
>> - fill_ldt(&ldt, &ldt_info);
>> - if (oldmode)
>> - ldt.avl = 0;
>> + if (old_ldt) {
>> + memcpy(new_ldt->entries, old_ldt->entries,
>> + oldsize * LDT_ENTRY_SIZE);
>> + }
>
> Single if-statement doesn't need {} and you don't absolutely need to
> keep 80cols. Just let it stick out.

You read too many of Linus' comments about using wider terminals :)

--Andy
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/