* [PATCH] stm class: increase pos if no free channels found
@ 2018-09-06 7:22 Zhi Jin
2018-10-12 5:36 ` Jin, Zhi
2018-10-15 7:42 ` Alexander Shishkin
0 siblings, 2 replies; 4+ messages in thread
From: Zhi Jin @ 2018-09-06 7:22 UTC (permalink / raw)
To: alexander.shishkin; +Cc: linux-kernel, Zhi Jin
Considering this case in find_free_channels():
bitmap:
+------------------+-+-+-+-+-+-+-+-+-+-+
| ...... |0|0|0|0|0|0|0|1|0|0|
+------------------+-+-+-+-+-+-+-+-+-+-+
1. Channel #2 has been occupied, so bit #2 is 1, and the others
are all 0.
2. Another thread tries to find 4 free channels from #0.
3. In the 1st loop, pos starts from 0, and then it checks if the
following 4 bits are all 0, but fails, as bit#2 is 1.
4. In the 2st loop, pos is not updated, and still starts from 0,
so nothing changes against loop #1.
5. Dead loop ...
This patch is to update the pos in step #3 to avoid the issue.
Fixes: 7bd1d4093c2f ("stm class: Introduce an abstraction for System Trace Module devices")
Signed-off-by: Zhi Jin <zhi.jin@intel.com>
---
drivers/hwtracing/stm/core.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c
index 10bcb5d73f90..c86a979b9bd7 100644
--- a/drivers/hwtracing/stm/core.c
+++ b/drivers/hwtracing/stm/core.c
@@ -244,6 +244,8 @@ static int find_free_channels(unsigned long *bitmap, unsigned int start,
;
if (i == width)
return pos;
+
+ pos += i;
}
return -1;
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* RE: [PATCH] stm class: increase pos if no free channels found
2018-09-06 7:22 [PATCH] stm class: increase pos if no free channels found Zhi Jin
@ 2018-10-12 5:36 ` Jin, Zhi
2018-10-15 7:42 ` Alexander Shishkin
1 sibling, 0 replies; 4+ messages in thread
From: Jin, Zhi @ 2018-10-12 5:36 UTC (permalink / raw)
To: alexander.shishkin; +Cc: linux-kernel, Jin, Zhi
Hi Alexander,
Any comments about this patch?
BRs
Zhi Jin
> -----Original Message-----
> From: Jin, Zhi
> Sent: Thursday, September 06, 2018 3:22 PM
> To: alexander.shishkin@linux.intel.com
> Cc: linux-kernel@vger.kernel.org; Jin, Zhi <zhi.jin@intel.com>
> Subject: [PATCH] stm class: increase pos if no free channels found
>
> Considering this case in find_free_channels():
>
> bitmap:
> +------------------+-+-+-+-+-+-+-+-+-+-+
> | ...... |0|0|0|0|0|0|0|1|0|0|
> +------------------+-+-+-+-+-+-+-+-+-+-+
>
> 1. Channel #2 has been occupied, so bit #2 is 1, and the others
> are all 0.
> 2. Another thread tries to find 4 free channels from #0.
> 3. In the 1st loop, pos starts from 0, and then it checks if the
> following 4 bits are all 0, but fails, as bit#2 is 1.
> 4. In the 2st loop, pos is not updated, and still starts from 0,
> so nothing changes against loop #1.
> 5. Dead loop ...
>
> This patch is to update the pos in step #3 to avoid the issue.
>
> Fixes: 7bd1d4093c2f ("stm class: Introduce an abstraction for System
> Trace Module devices")
> Signed-off-by: Zhi Jin <zhi.jin@intel.com>
> ---
> drivers/hwtracing/stm/core.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c
> index 10bcb5d73f90..c86a979b9bd7 100644
> --- a/drivers/hwtracing/stm/core.c
> +++ b/drivers/hwtracing/stm/core.c
> @@ -244,6 +244,8 @@ static int find_free_channels(unsigned long *bitmap,
> unsigned int start,
> ;
> if (i == width)
> return pos;
> +
> + pos += i;
> }
>
> return -1;
> --
> 2.7.4
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] stm class: increase pos if no free channels found
2018-09-06 7:22 [PATCH] stm class: increase pos if no free channels found Zhi Jin
2018-10-12 5:36 ` Jin, Zhi
@ 2018-10-15 7:42 ` Alexander Shishkin
2018-10-15 8:16 ` Jin, Zhi
1 sibling, 1 reply; 4+ messages in thread
From: Alexander Shishkin @ 2018-10-15 7:42 UTC (permalink / raw)
To: Zhi Jin; +Cc: linux-kernel, Zhi Jin
Zhi Jin <zhi.jin@intel.com> writes:
> Considering this case in find_free_channels():
>
> bitmap:
> +------------------+-+-+-+-+-+-+-+-+-+-+
> | ...... |0|0|0|0|0|0|0|1|0|0|
> +------------------+-+-+-+-+-+-+-+-+-+-+
>
> 1. Channel #2 has been occupied, so bit #2 is 1, and the others
> are all 0.
> 2. Another thread tries to find 4 free channels from #0.
> 3. In the 1st loop, pos starts from 0, and then it checks if the
> following 4 bits are all 0, but fails, as bit#2 is 1.
> 4. In the 2st loop, pos is not updated, and still starts from 0,
> so nothing changes against loop #1.
> 5. Dead loop ...
>
> This patch is to update the pos in step #3 to avoid the issue.
The description is slightly confusing, but the patch looks correct and
the original code is clearly wrong. Thank you for finding this!
Basically, if you request 1 channel 3 times, release the first two and
then request 4 channels, you'll be stuck, right?
Thanks,
--
Alex
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [PATCH] stm class: increase pos if no free channels found
2018-10-15 7:42 ` Alexander Shishkin
@ 2018-10-15 8:16 ` Jin, Zhi
0 siblings, 0 replies; 4+ messages in thread
From: Jin, Zhi @ 2018-10-15 8:16 UTC (permalink / raw)
To: Alexander Shishkin; +Cc: linux-kernel
> -----Original Message-----
> From: Alexander Shishkin [mailto:alexander.shishkin@linux.intel.com]
> Sent: Monday, October 15, 2018 3:43 PM
> To: Jin, Zhi <zhi.jin@intel.com>
> Cc: linux-kernel@vger.kernel.org; Jin, Zhi <zhi.jin@intel.com>
> Subject: Re: [PATCH] stm class: increase pos if no free channels found
>
> Zhi Jin <zhi.jin@intel.com> writes:
>
> > Considering this case in find_free_channels():
> >
> > bitmap:
> > +------------------+-+-+-+-+-+-+-+-+-+-+
> > | ...... |0|0|0|0|0|0|0|1|0|0|
> > +------------------+-+-+-+-+-+-+-+-+-+-+
> >
> > 1. Channel #2 has been occupied, so bit #2 is 1, and the others
> > are all 0.
> > 2. Another thread tries to find 4 free channels from #0.
> > 3. In the 1st loop, pos starts from 0, and then it checks if the
> > following 4 bits are all 0, but fails, as bit#2 is 1.
> > 4. In the 2st loop, pos is not updated, and still starts from 0,
> > so nothing changes against loop #1.
> > 5. Dead loop ...
> >
> > This patch is to update the pos in step #3 to avoid the issue.
>
> The description is slightly confusing, but the patch looks correct and
> the original code is clearly wrong. Thank you for finding this!
>
> Basically, if you request 1 channel 3 times, release the first two and
> then request 4 channels, you'll be stuck, right?
Yes, you are right.
But the real case that I reproduced the issue is a little different:
I have 2 stp-policy:
"console": masters "256 259" channels "7 10"
"user" : masters "256 1024" channels "0 127"
I understand the policies should not be overlapped, which is caused by some
other issues.
So if someone uses "console" to request a channel (who will get Channel #7)
and then another uses "user" to request more than 8 channels, it will be stuck.
The commit message is what I trying to abstract the above case, sorry for the
confusion.
>
> Thanks,
> --
> Alex
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-10-15 8:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-06 7:22 [PATCH] stm class: increase pos if no free channels found Zhi Jin
2018-10-12 5:36 ` Jin, Zhi
2018-10-15 7:42 ` Alexander Shishkin
2018-10-15 8:16 ` Jin, Zhi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).