Re: [PATCH] sched/fair: Use 'unsigned long' for group_shares,group_runnable

From: chengjian (D)
Date: Mon Apr 15 2019 - 11:51:17 EST



On 2019/4/15 23:25, Peter Zijlstra wrote:
On Mon, Apr 15, 2019 at 11:20:31PM +0800, chengjian (D) wrote:
Hi, Peter


On 2019/4/15 20:46, Peter Zijlstra wrote:

I write a demo about this, which I described it as overflow.
I'm not saying there's no overflow, I'm saying there's nothing UB about
it.


Yeah. I got it.

This may not be an undefined behavior,

but rather a bug or logic error caused by overflow.


```cpp


static long calc_group_shares(struct cfs_rq *cfs_rq)
{

ÂÂÂ // ......

ÂÂÂ shares = (tg_shares * load);ÂÂ // 1048576 * 9144968455305Â = -8857549630719655936 (OVERFLOW)
ÂÂÂ if (tg_weight)ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ // assume tg_weight is 3
ÂÂÂ ÂÂÂ shares /= tg_weight;ÂÂÂÂÂÂÂÂ //Â 0xd7068dd8c2daaaab shoule be 0x2c5be32e18300000
}

```


It will cause `se->runnable_weight` to have an incorrect value in reweight_entity().


Thanks.

CHENG Jian