From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Fri, 1 Jul 2005 10:06:47 -0700 (PDT) From: Christoph Lameter Subject: [SUSPEND 1/2]Replace PF_FREEZE with TIF_FREEZE In-Reply-To: <20050628124750.GB11129@atrey.karlin.mff.cuni.cz> Message-ID: References: <20050626023053.GA2871@atrey.karlin.mff.cuni.cz> <20050626030925.GA4156@atrey.karlin.mff.cuni.cz> <20050627141320.GA4945@atrey.karlin.mff.cuni.cz> <42C0EBAB.8070709@sw.ru> <20050628124750.GB11129@atrey.karlin.mff.cuni.cz> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-linux-mm@kvack.org Return-Path: To: Pavel Machek Cc: Kirill Korotaev , Linus Torvalds , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Alexey Kuznetsov List-ID: The current suspend code modifies thread->flags from outside the context of the thread. This creates a SMP race. This patch fixes that by introducing a TIF_FREEZE flag in thread_info (This is not the end of the races in the suspend code since TIF_FREEZE is cleared when setting PF_FROZEN creating a window for freeze_processes()) Signed-off-by: Christoph Lameter Index: linux-2.6.12/include/linux/sched.h =================================================================== --- linux-2.6.12.orig/include/linux/sched.h 2005-06-30 23:26:07.000000000 +0000 +++ linux-2.6.12/include/linux/sched.h 2005-06-30 23:39:12.000000000 +0000 @@ -807,7 +807,6 @@ do { if (atomic_dec_and_test(&(tsk)->usa #define PF_MEMALLOC 0x00000800 /* Allocating memory */ #define PF_FLUSHER 0x00001000 /* responsible for disk writeback */ #define PF_USED_MATH 0x00002000 /* if unset the fpu must be initialized before use */ -#define PF_FREEZE 0x00004000 /* this task is being frozen for suspend now */ #define PF_NOFREEZE 0x00008000 /* this thread should not be frozen */ #define PF_FROZEN 0x00010000 /* frozen for system suspend */ #define PF_FSTRANS 0x00020000 /* inside a filesystem transaction */ @@ -1283,16 +1282,15 @@ static inline int frozen(struct task_str */ static inline int freezing(struct task_struct *p) { - return p->flags & PF_FREEZE; + return test_ti_thread_flag(p->thread_info, TIF_FREEZE); } /* * Request that a process be frozen - * FIXME: SMP problem. We may not modify other process' flags! */ static inline void freeze(struct task_struct *p) { - p->flags |= PF_FREEZE; + set_ti_thread_flag(p->thread_info, TIF_FREEZE); } /* @@ -1313,7 +1311,8 @@ static inline int thaw_process(struct ta */ static inline void frozen_process(struct task_struct *p) { - p->flags = (p->flags & ~PF_FREEZE) | PF_FROZEN; + p->flags |= PF_FROZEN; + clear_ti_thread_flag(p->thread_info, TIF_FREEZE); } extern void refrigerator(void); Index: linux-2.6.12/include/asm-x86_64/thread_info.h =================================================================== --- linux-2.6.12.orig/include/asm-x86_64/thread_info.h 2005-06-30 23:26:07.000000000 +0000 +++ linux-2.6.12/include/asm-x86_64/thread_info.h 2005-06-30 23:26:35.000000000 +0000 @@ -108,6 +108,7 @@ static inline struct thread_info *stack_ #define TIF_FORK 18 /* ret_from_fork */ #define TIF_ABI_PENDING 19 #define TIF_MEMDIE 20 +#define TIF_FREEZE 21 /* Freeze process */ #define _TIF_SYSCALL_TRACE (1< aart@kvack.org