From owner-freebsd-hackers@FreeBSD.ORG Mon Aug 11 05:07:40 2003 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id CA26037B401 for ; Mon, 11 Aug 2003 05:07:40 -0700 (PDT) Received: from ns.webtt.biz (ns.webtt.biz [64.239.29.225]) by mx1.FreeBSD.org (Postfix) with SMTP id E1AE143FBD for ; Mon, 11 Aug 2003 05:07:39 -0700 (PDT) (envelope-from rui@ruilopes.com) Received: (qmail 24421 invoked from network); 11 Aug 2003 12:09:51 -0000 Received: from unknown (HELO ?217.129.149.167?) (rui@ruilopes.com@217.129.149.167) by ns.webtt.biz with SMTP; 11 Aug 2003 12:09:51 -0000 From: Rui Lopes To: freebsd-hackers@freebsd.org Content-Type: multipart/mixed; boundary="=-yEYvogjQ9gwJbuBvo2E9" Message-Id: <1060603824.650.12.camel@localhost> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.3 Date: 11 Aug 2003 13:10:24 +0100 Subject: Possible patch for vm/vm_glue.c X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Aug 2003 12:07:41 -0000 --=-yEYvogjQ9gwJbuBvo2E9 Content-Type: text/plain Content-Transfer-Encoding: 7bit Hello, I've been reading vm_glue.c and I think I've found a bug regarding the lock of `proc.p_sflag' inside `scheduler' function. >From proc.h, "int p_sflag; /* (j) PS_* flags. */" and "(j) - locked by sched_lock mtx"; but the access is done without having the lock. Take a look at the attached patch and tell me if this is ok. Patch made against "$FreeBSD: src/sys/vm/vm_glue.c,v 1.172 2003/05/13 20:36:02 jhb Exp $", but this is also present in current 1.182. Regards, Rui Lopes --=-yEYvogjQ9gwJbuBvo2E9 Content-Disposition: attachment; filename=vm_glue.c.patch Content-Type: text/plain; name=vm_glue.c.patch; charset= Content-Transfer-Encoding: 7bit # we should only access `proc.p_sflag' when `sched_lock' is locked. # From proc.h: # int p_sflag; /* (j) PS_* flags. */ # and j means: "(j) - locked by sched_lock mtx" # -- Rui Lopes --- vm_glue.c.orig Mon Aug 11 12:41:33 2003 +++ vm_glue.c Mon Aug 11 12:45:58 2003 @@ -596,10 +596,11 @@ sx_slock(&allproc_lock); FOREACH_PROC_IN_SYSTEM(p) { struct ksegrp *kg; + mtx_lock_spin(&sched_lock); if (p->p_sflag & (PS_INMEM | PS_SWAPPINGOUT | PS_SWAPPINGIN)) { + mtx_unlock_spin(&sched_lock); continue; } - mtx_lock_spin(&sched_lock); FOREACH_THREAD_IN_PROC(p, td) { /* * An otherwise runnable thread of a process --=-yEYvogjQ9gwJbuBvo2E9--