Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 26 Aug 2002 02:22:39 +0900 (JST)
From:      Mitsuru IWASAKI <iwasaki@jp.FreeBSD.org>
To:        current@FreeBSD.ORG
Subject:   [PATCH]: resource manager (subr_rman.c) has a serious bug
Message-ID:  <20020826.022239.89228936.iwasaki@jp.FreeBSD.org>

next in thread | raw e-mail | index | archive | help
[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: <I/O ports> 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: <I/O ports> 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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020826.022239.89228936.iwasaki>