NetBSD Problem Report #36878
From dieter@bsdusr.net Sat Sep 1 13:49:10 2007
Return-Path: <dieter@bsdusr.net>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
by narn.NetBSD.org (Postfix) with ESMTP id 0BEA263B928
for <gnats-bugs@gnats.NetBSD.org>; Sat, 1 Sep 2007 13:49:10 +0000 (UTC)
Message-Id: <20070901134907.82B2055B4@mail.bsdusr.net>
Date: Sat, 1 Sep 2007 13:49:07 +0000 (UTC)
From: dieter.NetBSD@pandora.be
To: gnats-bugs@NetBSD.org
Subject: overflow in raidframe parity rebuild status
X-Send-Pr-Version: 3.95
>Number: 36878
>Category: kern
>Synopsis: overflow in raidframe parity rebuild status
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: oster
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat Sep 01 13:50:00 +0000 2007
>Closed-Date: Sun Sep 16 02:14:24 +0000 2007
>Last-Modified: Sun Sep 16 02:15:02 +0000 2007
>Originator: Dieter Roelants
>Release: NetBSD 4.0_BETA2
>Organization:
>Environment:
System: NetBSD bsdusr.net 4.0_BETA2 NetBSD 4.0_BETA2 (GENERIC) #0: Tue Aug 28 12:16:38 CEST 2007 dieter@simult.amelgem.be:/build/obj.amd64.4/sys/arch/amd64/compile/GENERIC amd64
Architecture: x86_64
Machine: amd64
>Description:
When rebuilding the parity of a RAID set, it can happen
that querying the status of this process returns a (large)
negative percentage.
>How-To-Repeat:
Build a RAID set which is either large enough or has a low
number of sectors per stripe unit. Check the status with
raidctl -s while the parity is being written.
>Fix:
I have 2 patches. The first one is only cosmetic, it wraps a long
line, and unnests some conditions. The second changes the way the
percentage is calculated when there is a possibility of overflowing
(but only then, because it's less precise for small numbers and
could maybe even divide by 0). Note that the patch changes copyback,
and reconstruction percentage calculations because I believe the
problem occurs there also. I should probably also mention that I
have only compile-tested this. :)
Index: rf_netbsdkintf.c
===================================================================
RCS file: /cvsroot/src/sys/dev/raidframe/rf_netbsdkintf.c,v
retrieving revision 1.224
diff -u -r1.224 rf_netbsdkintf.c
--- rf_netbsdkintf.c 30 Nov 2006 23:01:50 -0000 1.224
+++ rf_netbsdkintf.c 1 Sep 2007 13:26:23 -0000
@@ -1400,15 +1400,17 @@
*(int *) data = 100;
return(0);
}
- if (raidPtr->status != rf_rs_reconstructing)
+ if (raidPtr->status != rf_rs_reconstructing) {
*(int *) data = 100;
- else {
- if (raidPtr->reconControl->numRUsTotal > 0) {
- *(int *) data = (raidPtr->reconControl->numRUsComplete * 100 / raidPtr->reconControl->numRUsTotal);
- } else {
- *(int *) data = 0;
- }
+ return 0;
}
+ if (raidPtr->reconControl->numRUsTotal <= 0) {
+ *(int *) data = 0;
+ return 0;
+ }
+ *(int *) data = 100 *
+ raidPtr->reconControl->numRUsComplete /
+ raidPtr->reconControl->numRUsTotal;
return (0);
case RAIDFRAME_CHECK_RECON_STATUS_EXT:
progressInfoPtr = (RF_ProgressInfo_t **) data;
--- rf_netbsdkintf.c.cosm 2007-08-31 23:32:07.000000000 +0200
+++ rf_netbsdkintf.c 2007-08-31 23:32:07.000000000 +0200
@@ -1408,9 +1408,14 @@
*(int *) data = 0;
return 0;
}
- *(int *) data = 100 *
- raidPtr->reconControl->numRUsComplete /
- raidPtr->reconControl->numRUsTotal;
+ if (raidPtr->reconControl->numRUsComplete < (1 << 24)) {
+ *(int *) data = 100 *
+ raidPtr->reconControl->numRUsComplete /
+ raidPtr->reconControl->numRUsTotal;
+ } else {
+ *(int *) data = raidPtr->reconControl->numRUsComplete /
+ (raidPtr->reconControl->numRUsTotal / 100);
+ }
return (0);
case RAIDFRAME_CHECK_RECON_STATUS_EXT:
progressInfoPtr = (RF_ProgressInfo_t **) data;
@@ -1438,9 +1443,15 @@
return(0);
}
if (raidPtr->parity_rewrite_in_progress == 1) {
- *(int *) data = 100 *
- raidPtr->parity_rewrite_stripes_done /
- raidPtr->Layout.numStripe;
+ if (raidPtr->parity_rewrite_stripes_done < (1 << 24)) {
+ *(int *) data = 100 *
+ raidPtr->parity_rewrite_stripes_done /
+ raidPtr->Layout.numStripe;
+ } else {
+ *(int *) data =
+ raidPtr->parity_rewrite_stripes_done /
+ (raidPtr->Layout.numStripe / 100);
+ }
} else {
*(int *) data = 100;
}
@@ -1470,8 +1481,14 @@
return(0);
}
if (raidPtr->copyback_in_progress == 1) {
- *(int *) data = 100 * raidPtr->copyback_stripes_done /
- raidPtr->Layout.numStripe;
+ if (raidPtr->copyback_stripes_done < (1 << 24)) {
+ *(int *) data = 100 *
+ raidPtr->copyback_stripes_done /
+ raidPtr->Layout.numStripe;
+ } else {
+ *(int *) data = raidPtr->copyback_stripes_done /
+ (raidPtr->Layout.numStripe / 100);
+ }
} else {
*(int *) data = 100;
}
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: kern-bug-people->oster
Responsible-Changed-By: oster@netbsd.org
Responsible-Changed-When: Sat, 01 Sep 2007 22:14:36 +0000
Responsible-Changed-Why:
My area.
From: dieter roelants <dieter.NetBSD@pandora.be>
To: gnats-bugs@NetBSD.org
Cc:
Subject: Re: kern/36878: overflow in raidframe parity rebuild status
Date: Mon, 3 Sep 2007 16:15:00 +0200
Hi Greg,
On Sat, 1 Sep 2007 13:50:00 +0000 (UTC)
dieter.NetBSD@pandora.be wrote:
> I have only compile-tested this.
Well, this is no longer true now... (it works)
dieter
From: Greg Oster <oster@cs.usask.ca>
To: gnats-bugs@NetBSD.org
Cc:
Subject: Re: kern/36878: overflow in raidframe parity rebuild status
Date: Mon, 03 Sep 2007 11:30:52 -0600
dieter.NetBSD@pandora.be writes:
> >Number: 36878
> >Category: kern
> >Synopsis: overflow in raidframe parity rebuild status
> >Confidential: no
> >Severity: non-critical
> >Priority: medium
> >Responsible: kern-bug-people
> >State: open
> >Class: sw-bug
> >Submitter-Id: net
> >Arrival-Date: Sat Sep 01 13:50:00 +0000 2007
> >Originator: Dieter Roelants
> >Release: NetBSD 4.0_BETA2
> >Organization:
> >Environment:
> System: NetBSD bsdusr.net 4.0_BETA2 NetBSD 4.0_BETA2 (GENERIC) #0: Tue Aug 28
> 12:16:38 CEST 2007 dieter@simult.amelgem.be:/build/obj.amd64.4/sys/arch/amd6
> 4/compile/GENERIC amd64
> Architecture: x86_64
> Machine: amd64
> >Description:
> When rebuilding the parity of a RAID set, it can happen
> that querying the status of this process returns a (large)
> negative percentage.
>
> >How-To-Repeat:
> Build a RAID set which is either large enough or has a low
> number of sectors per stripe unit. Check the status with
> raidctl -s while the parity is being written.
I'm trying to figure out how this can happen.... all the variables
in use should be 64-bit quantities.... I know there used to be some
isuses with this, but I'm sure 4.0_BETA2 has those fixes in it...
> >Fix:
>
> I have 2 patches. The first one is only cosmetic, it wraps a long
> line, and unnests some conditions. The second changes the way the
> percentage is calculated when there is a possibility of overflowing
Does casting things to RF_uint64 fix the issue without having to do
the (1<<24) stuff? e.g. one shouldn't need to, but does:
*(int *) data = (RF_uint64) 100 *
raidPtr->reconControl->numRUsComplete /
raidPtr->reconControl->numRUsTotal;
behave any differently?
Later...
Greg Oster
From: dieter roelants <dieter.NetBSD@pandora.be>
To: gnats-bugs@NetBSD.org
Cc:
Subject: Re: kern/36878: overflow in raidframe parity rebuild status
Date: Wed, 5 Sep 2007 16:29:00 +0200
On Mon, 3 Sep 2007 17:35:02 +0000 (UTC)
Greg Oster <oster@cs.usask.ca> wrote:
> I'm trying to figure out how this can happen.... all the variables
> in use should be 64-bit quantities.... I know there used to be some
> isuses with this, but I'm sure 4.0_BETA2 has those fixes in it...
Hmm, you're right about the reconstruction, it would probably give the
right result (again, I had only witnessed this with parity rebuilding).
However parity_rewrite_stripes_done, recon_stripes_done (but it seems
unused), and also copyback_stripes_done in struct RF_Raid_s all have
type int. Changing those to RF_StripeCount_t fixes the issue too.
Thanks and kind regards,
dieter
State-Changed-From-To: open->closed
State-Changed-By: oster@netbsd.org
State-Changed-When: Sun, 16 Sep 2007 02:14:24 +0000
State-Changed-Why:
Bug addressed in a different way.
From: Greg Oster <oster@netbsd.org>
To: gnats-bugs@NetBSD.org
Cc:
Subject: PR/36878 CVS commit: src/sys/dev/raidframe
Date: Sun, 16 Sep 2007 02:13:35 +0000 (UTC)
Module Name: src
Committed By: oster
Date: Sun Sep 16 02:13:35 UTC 2007
Modified Files:
src/sys/dev/raidframe: rf_raid.h
Log Message:
Make a couple of variables 64-bit quantities to avoid overflow issues
when arrays have a large number of stripes. Remove unused variable
(recon_stripes_done). Thanks to Dieter Roelants for the report,
suggestions, and testing. Addresses PR#36878.
To generate a diff of this commit:
cvs rdiff -r1.36 -r1.37 src/sys/dev/raidframe/rf_raid.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.