aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorMarkus Metzger <markus.t.metzger@intel.com>2009-04-24 03:51:43 -0400
committerIngo Molnar <mingo@elte.hu>2009-04-24 04:18:52 -0400
commit1cb81b143fa8f0e4629f10690862e2e52ca792ff (patch)
tree667b9677f8ad1211ca3d094bedabe47a3d4f5ba9 /arch
parent7e0bfad24d85de7cf2202a7b0ce51de11a077b21 (diff)
x86, bts, mm: clean up buffer allocation
The current mm interface is asymetric. One function allocates a locked buffer, another function only refunds the memory. Change this to have two functions for accounting and refunding locked memory, respectively; and do the actual buffer allocation in ptrace. [ Impact: refactor BTS buffer allocation code ] Signed-off-by: Markus Metzger <markus.t.metzger@intel.com> Acked-by: Andrew Morton <akpm@linux-foundation.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> LKML-Reference: <20090424095143.A30265@sedona.ch.intel.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'arch')
-rw-r--r--arch/x86/kernel/ptrace.c39
1 files changed, 26 insertions, 13 deletions
diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
index d5252ae6c520..09ecbde91c13 100644
--- a/arch/x86/kernel/ptrace.c
+++ b/arch/x86/kernel/ptrace.c
@@ -617,17 +617,28 @@ struct bts_context {
617 struct work_struct work; 617 struct work_struct work;
618}; 618};
619 619
620static inline void alloc_bts_buffer(struct bts_context *context, 620static int alloc_bts_buffer(struct bts_context *context, unsigned int size)
621 unsigned int size)
622{ 621{
623 void *buffer; 622 void *buffer = NULL;
623 int err = -ENOMEM;
624 624
625 buffer = alloc_locked_buffer(size); 625 err = account_locked_memory(current->mm, current->signal->rlim, size);
626 if (buffer) { 626 if (err < 0)
627 context->buffer = buffer; 627 return err;
628 context->size = size; 628
629 context->mm = get_task_mm(current); 629 buffer = kzalloc(size, GFP_KERNEL);
630 } 630 if (!buffer)
631 goto out_refund;
632
633 context->buffer = buffer;
634 context->size = size;
635 context->mm = get_task_mm(current);
636
637 return 0;
638
639 out_refund:
640 refund_locked_memory(current->mm, size);
641 return err;
631} 642}
632 643
633static inline void free_bts_buffer(struct bts_context *context) 644static inline void free_bts_buffer(struct bts_context *context)
@@ -638,7 +649,7 @@ static inline void free_bts_buffer(struct bts_context *context)
638 kfree(context->buffer); 649 kfree(context->buffer);
639 context->buffer = NULL; 650 context->buffer = NULL;
640 651
641 refund_locked_buffer_memory(context->mm, context->size); 652 refund_locked_memory(context->mm, context->size);
642 context->size = 0; 653 context->size = 0;
643 654
644 mmput(context->mm); 655 mmput(context->mm);
@@ -786,13 +797,15 @@ static int ptrace_bts_config(struct task_struct *child,
786 context->tracer = NULL; 797 context->tracer = NULL;
787 798
788 if ((cfg.flags & PTRACE_BTS_O_ALLOC) && (cfg.size != context->size)) { 799 if ((cfg.flags & PTRACE_BTS_O_ALLOC) && (cfg.size != context->size)) {
800 int err;
801
789 free_bts_buffer(context); 802 free_bts_buffer(context);
790 if (!cfg.size) 803 if (!cfg.size)
791 return 0; 804 return 0;
792 805
793 alloc_bts_buffer(context, cfg.size); 806 err = alloc_bts_buffer(context, cfg.size);
794 if (!context->buffer) 807 if (err < 0)
795 return -ENOMEM; 808 return err;
796 } 809 }
797 810
798 if (cfg.flags & PTRACE_BTS_O_TRACE) 811 if (cfg.flags & PTRACE_BTS_O_TRACE)