From owner-freebsd-current Sun Aug 25 10:23: 1 2002 Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 94B9637B401 for ; Sun, 25 Aug 2002 10:22:55 -0700 (PDT) Received: from tasogare.imasy.or.jp (tasogare.imasy.or.jp [202.227.24.5]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9886443E4A for ; Sun, 25 Aug 2002 10:22:53 -0700 (PDT) (envelope-from iwasaki@jp.FreeBSD.org) Received: from localhost (iwa@tasogare.imasy.or.jp [202.227.24.5]) by tasogare.imasy.or.jp (8.11.6+3.4W/8.11.6/tasogare) with ESMTP/inet id g7PHMoY26555 for ; Mon, 26 Aug 2002 02:22:50 +0900 (JST) (envelope-from iwasaki@jp.FreeBSD.org) Date: Mon, 26 Aug 2002 02:22:39 +0900 (JST) Message-Id: <20020826.022239.89228936.iwasaki@jp.FreeBSD.org> To: current@FreeBSD.ORG Subject: [PATCH]: resource manager (subr_rman.c) has a serious bug From: Mitsuru IWASAKI X-Mailer: Mew version 2.1 on Emacs 20.7 / Mule 4.0 (HANANOEN) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG [resent a few times, sorry if you receive the same messages] Hi, I've found that there is a serious bug in sys/kern/subr_rman.c about finding an acceptable region. I'm sure it's a obvious bug and going to commit it soon, but this is my first commit to resource manager code, so please review my patch. I'll commit this 2 or 3 days later. OK, when I trying to use wi PCCard with NEWCARD, sometimes wrong I/O port range was allocated and attaching the card was failed depending on the usage of I/O port resources. Here is the kernel message w/ RMAN_DEBUG option in subr_rman.c. ---- rman_reserve_resource: request: [0x100, 0xffffffff], length 0x40, flags 6144, device pccard1 considering [0x100, 0x107] region is allocated considering [0x108, 0x10d] truncated region: [0x140, 0x10d]; size 0xffffffce (requested 0x40) ^^^^^ ^^^^^ start > end, hmmm, very odd. ---- The resource manager is trying to find the I/O port resource range (length = 0x40) checking the range [0x108 - 0x10d]. Adjusted start address on boundary and alignment is [0x140], but this address already exceeds end address of the range. That's the problem. As the result, wrong address range [0x140 - 0x17f] was allocated. Here is my patch. very simple but correct I think. Index: subr_rman.c =================================================================== RCS file: /home/ncvs/src/sys/kern/subr_rman.c,v retrieving revision 1.24 diff -u -r1.24 subr_rman.c --- subr_rman.c 4 Apr 2002 21:03:26 -0000 1.24 +++ subr_rman.c 25 Aug 2002 14:49:20 -0000 @@ -232,6 +234,10 @@ } while ((rstart & amask) != 0 && rstart < end && rstart < s->r_end); rend = ulmin(s->r_end, ulmax(rstart + count, end)); + if (rstart > rend) { + DPRINTF(("adjusted start exceeds end\n")); + continue; + } DPRINTF(("truncated region: [%#lx, %#lx]; size %#lx (requested %#lx)\n", rstart, rend, (rend - rstart + 1), count)); The kernel message w/ my patch is: ---- rman_reserve_resource: request: [0x100, 0xffffffff], length 0x40, flags 6144, device pccard1 considering [0x100, 0x107] region is allocated considering [0x108, 0x10d] adjusted start exceeds end considering [0x10e, 0x10e] region is allocated considering [0x10f, 0x16f] truncated region: [0x140, 0x16f]; size 0x30 (requested 0x40) considering [0x170, 0x177] region is allocated considering [0x178, 0x1ef] truncated region: [0x180, 0x1ef]; size 0x70 (requested 0x40) ---- It seems that correct range is allocated, and wi PCCard is always working correctly now :-) Thanks To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message