re: sched, numa, mm: Implement constant, per task Working Set Sampling (WSS) rate
On Mon, 2012-10-22 at 14:55 +0300, Dan Carpenter wrote: > Hello Peter Zijlstra, > > The patch 3d049f8a5398: "sched, numa, mm: Implement constant, per > task Working Set Sampling (WSS) rate" from Oct 14, 2012, leads to the > following warning: > kernel/sched/fair.c:954 task_numa_work() >error: we previously assumed 'vma' could be null (see line 948) > >943 if (!vma) { >944 ACCESS_ONCE(mm->numa_scan_seq)++; >945 offset = 0; >946 vma = mm->mmap; >947 } >948 while (vma && !vma_migratable(vma)) { >^^^ > If this is NULL, >949 vma = vma->vm_next; >950 if (!vma) >951 goto again; >952 } >953 >954 offset = max(offset, vma->vm_start); > ^ > then it leads to a NULL dereference here. Ah.. indeed so. There's also what looks like an infinite loop in there if nothing is migratable or if length is stupid large. The below should avoid the reported NULL deref as well as break out when we've reached the end of the address space. --- kernel/sched/fair.c | 23 --- 1 files changed, 8 insertions(+), 15 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index c68b877..5a6d8f5 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -939,29 +939,22 @@ void task_numa_work(struct callback_head *work) down_read(>mmap_sem); vma = find_vma(mm, offset); -again: if (!vma) { ACCESS_ONCE(mm->numa_scan_seq)++; offset = 0; vma = mm->mmap; } - while (vma && !vma_migratable(vma)) { - vma = vma->vm_next; - if (!vma) - goto again; - } - - offset = max(offset, vma->vm_start); - end = min(ALIGN(offset + length, HPAGE_SIZE), vma->vm_end); - length -= end - offset; + for (; vma && length > 0; vma = vma->vm_next) { + if (!vma_migratable(vma)) + continue; - change_prot_none(vma, offset, end); + offset = max(offset, vma->vm_start); + end = min(ALIGN(offset + length, HPAGE_SIZE), vma->vm_end); + length -= end - offset; - offset = end; + change_prot_none(vma, offset, end); - if (length > 0) { - vma = vma->vm_next; - goto again; + offset = end; } mm->numa_scan_offset = offset; up_read(>mmap_sem); -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
re: sched, numa, mm: Implement constant, per task Working Set Sampling (WSS) rate
Hello Peter Zijlstra, The patch 3d049f8a5398: "sched, numa, mm: Implement constant, per task Working Set Sampling (WSS) rate" from Oct 14, 2012, leads to the following warning: kernel/sched/fair.c:954 task_numa_work() error: we previously assumed 'vma' could be null (see line 948) 943 if (!vma) { 944 ACCESS_ONCE(mm->numa_scan_seq)++; 945 offset = 0; 946 vma = mm->mmap; 947 } 948 while (vma && !vma_migratable(vma)) { ^^^ If this is NULL, 949 vma = vma->vm_next; 950 if (!vma) 951 goto again; 952 } 953 954 offset = max(offset, vma->vm_start); ^ then it leads to a NULL dereference here. regards, dan carpenter -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
re: sched, numa, mm: Implement constant, per task Working Set Sampling (WSS) rate
Hello Peter Zijlstra, The patch 3d049f8a5398: sched, numa, mm: Implement constant, per task Working Set Sampling (WSS) rate from Oct 14, 2012, leads to the following warning: kernel/sched/fair.c:954 task_numa_work() error: we previously assumed 'vma' could be null (see line 948) 943 if (!vma) { 944 ACCESS_ONCE(mm-numa_scan_seq)++; 945 offset = 0; 946 vma = mm-mmap; 947 } 948 while (vma !vma_migratable(vma)) { ^^^ If this is NULL, 949 vma = vma-vm_next; 950 if (!vma) 951 goto again; 952 } 953 954 offset = max(offset, vma-vm_start); ^ then it leads to a NULL dereference here. regards, dan carpenter -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
re: sched, numa, mm: Implement constant, per task Working Set Sampling (WSS) rate
On Mon, 2012-10-22 at 14:55 +0300, Dan Carpenter wrote: Hello Peter Zijlstra, The patch 3d049f8a5398: sched, numa, mm: Implement constant, per task Working Set Sampling (WSS) rate from Oct 14, 2012, leads to the following warning: kernel/sched/fair.c:954 task_numa_work() error: we previously assumed 'vma' could be null (see line 948) 943 if (!vma) { 944 ACCESS_ONCE(mm-numa_scan_seq)++; 945 offset = 0; 946 vma = mm-mmap; 947 } 948 while (vma !vma_migratable(vma)) { ^^^ If this is NULL, 949 vma = vma-vm_next; 950 if (!vma) 951 goto again; 952 } 953 954 offset = max(offset, vma-vm_start); ^ then it leads to a NULL dereference here. Ah.. indeed so. There's also what looks like an infinite loop in there if nothing is migratable or if length is stupid large. The below should avoid the reported NULL deref as well as break out when we've reached the end of the address space. --- kernel/sched/fair.c | 23 --- 1 files changed, 8 insertions(+), 15 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index c68b877..5a6d8f5 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -939,29 +939,22 @@ void task_numa_work(struct callback_head *work) down_read(mm-mmap_sem); vma = find_vma(mm, offset); -again: if (!vma) { ACCESS_ONCE(mm-numa_scan_seq)++; offset = 0; vma = mm-mmap; } - while (vma !vma_migratable(vma)) { - vma = vma-vm_next; - if (!vma) - goto again; - } - - offset = max(offset, vma-vm_start); - end = min(ALIGN(offset + length, HPAGE_SIZE), vma-vm_end); - length -= end - offset; + for (; vma length 0; vma = vma-vm_next) { + if (!vma_migratable(vma)) + continue; - change_prot_none(vma, offset, end); + offset = max(offset, vma-vm_start); + end = min(ALIGN(offset + length, HPAGE_SIZE), vma-vm_end); + length -= end - offset; - offset = end; + change_prot_none(vma, offset, end); - if (length 0) { - vma = vma-vm_next; - goto again; + offset = end; } mm-numa_scan_offset = offset; up_read(mm-mmap_sem); -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/