Re: [PATCH] NOMMU: add support for Memory Protection Units (MPU)

From: Mike Frysinger
Date: Tue Jul 14 2009 - 12:48:25 EST


On Tue, Jul 14, 2009 at 12:14, Johannes Weiner wrote:
> On Tue, Jul 14, 2009 at 10:22:20AM -0400, Mike Frysinger wrote:
>> --- a/mm/nommu.c
>> +++ b/mm/nommu.c
>> @@ -640,11 +641,23 @@ static void add_vma_to_mm(struct mm_struct *mm, struct vm_area_struct *vma)
>> Â Â Â struct vm_area_struct *pvma, **pp;
>> Â Â Â struct address_space *mapping;
>> Â Â Â struct rb_node **p, *parent;
>> +#ifdef CONFIG_MPU
>> + Â Â long start;
>> +#endif
>>
>> Â Â Â kenter(",%p", vma);
>>
>> Â Â Â BUG_ON(!vma->vm_region);
>>
>> +#ifdef CONFIG_MPU
>> + Â Â start = vma->vm_start & PAGE_MASK;
>> + Â Â while (start < vma->vm_end) {
>> + Â Â Â Â Â Â protect_page(mm, start, vma->vm_flags);
>> + Â Â Â Â Â Â start += PAGE_SIZE;
>> + Â Â }
>> + Â Â update_protections(mm);
>> +#endif
>> +
>> Â Â Â mm->map_count++;
>> Â Â Â vma->vm_mm = mm;
>>
>> @@ -707,9 +720,21 @@ static void delete_vma_from_mm(struct vm_area_struct *vma)
>> Â Â Â struct vm_area_struct **pp;
>> Â Â Â struct address_space *mapping;
>> Â Â Â struct mm_struct *mm = vma->vm_mm;
>> +#ifdef CONFIG_MPU
>> + Â Â long start;
>> +#endif
>>
>> Â Â Â kenter("%p", vma);
>>
>> +#ifdef CONFIG_MPU
>> + Â Â start = vma->vm_start & PAGE_MASK;
>> + Â Â while (start < vma->vm_end) {
>> + Â Â Â Â Â Â protect_page(mm, start, 0);
>> + Â Â Â Â Â Â start += PAGE_SIZE;
>> + Â Â }
>> + Â Â update_protections(mm);
>> +#endif
>
> How about refactoring that into one function? ÂSaves all but one
> #ifdef.

makes sense to me, thanks
-mike
--
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/