We need to protect not only the dmm_map list, but the individual
map_obj's, otherwise, we might be building the scatter-gather list with
garbage. So, use the existing proc_lock for that.
I observed race conditions which caused kernel panics while running
stress tests, also, Tuomas Kulve found it happening quite often in
Gumstix Over. This patch fixes those.
Cc: Tuomas Kulve <[email protected]>
Signed-off-by: Felipe Contreras <[email protected]>
---
drivers/staging/tidspbridge/rmgr/proc.c | 18 ++++++++++++++----
1 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/drivers/staging/tidspbridge/rmgr/proc.c b/drivers/staging/tidspbridge/rmgr/proc.c
index b47d7aa..21052e3 100644
--- a/drivers/staging/tidspbridge/rmgr/proc.c
+++ b/drivers/staging/tidspbridge/rmgr/proc.c
@@ -781,12 +781,14 @@ int proc_begin_dma(void *hprocessor, void *pmpu_addr, u32 ul_size,
(u32)pmpu_addr,
ul_size, dir);
+ mutex_lock(&proc_lock);
+
/* find requested memory are in cached mapping information */
map_obj = find_containing_mapping(pr_ctxt, (u32) pmpu_addr, ul_size);
if (!map_obj) {
pr_err("%s: find_containing_mapping failed\n", __func__);
status = -EFAULT;
- goto err_out;
+ goto no_map;
}
if (memory_give_ownership(map_obj, (u32) pmpu_addr, ul_size, dir)) {
@@ -795,6 +797,8 @@ int proc_begin_dma(void *hprocessor, void *pmpu_addr, u32 ul_size,
status = -EFAULT;
}
+no_map:
+ mutex_unlock(&proc_lock);
err_out:
return status;
@@ -819,12 +823,14 @@ int proc_end_dma(void *hprocessor, void *pmpu_addr, u32 ul_size,
(u32)pmpu_addr,
ul_size, dir);
+ mutex_lock(&proc_lock);
+
/* find requested memory are in cached mapping information */
map_obj = find_containing_mapping(pr_ctxt, (u32) pmpu_addr, ul_size);
if (!map_obj) {
pr_err("%s: find_containing_mapping failed\n", __func__);
status = -EFAULT;
- goto err_out;
+ goto no_map;
}
if (memory_regain_ownership(map_obj, (u32) pmpu_addr, ul_size, dir)) {
@@ -834,6 +840,8 @@ int proc_end_dma(void *hprocessor, void *pmpu_addr, u32 ul_size,
goto err_out;
}
+no_map:
+ mutex_unlock(&proc_lock);
err_out:
return status;
}
@@ -1726,9 +1734,8 @@ int proc_un_map(void *hprocessor, void *map_addr,
(p_proc_object->hbridge_context, va_align, size_align);
}
- mutex_unlock(&proc_lock);
if (status)
- goto func_end;
+ goto unmap_failed;
/*
* A successful unmap should be followed by removal of map_obj
@@ -1737,6 +1744,9 @@ int proc_un_map(void *hprocessor, void *map_addr,
*/
remove_mapping_information(pr_ctxt, (u32) map_addr, size_align);
+unmap_failed:
+ mutex_unlock(&proc_lock);
+
func_end:
dev_dbg(bridge, "%s: hprocessor: 0x%p map_addr: 0x%p status: 0x%x\n",
__func__, hprocessor, map_addr, status);
--
1.7.4.1
On Fri, Mar 11, 2011 at 7:30 PM, Felipe Contreras
<[email protected]> wrote:
> We need to protect not only the dmm_map list, but the individual
> map_obj's, otherwise, we might be building the scatter-gather list with
> garbage. So, use the existing proc_lock for that.
>
> I observed race conditions which caused kernel panics while running
> stress tests, also, Tuomas Kulve found it happening quite often in
> Gumstix Over. This patch fixes those.
>
> Cc: Tuomas Kulve <[email protected]>
> Signed-off-by: Felipe Contreras <[email protected]>
Omar, 2.6.38 is imminent, if this patch has any chance of getting in,
I think you would need to push it soon.
Cheers.
--
Felipe Contreras
Hi Felipe,
On Fri, Mar 11, 2011 at 11:38 AM, Felipe Contreras
<[email protected]> wrote:
> On Fri, Mar 11, 2011 at 7:30 PM, Felipe Contreras
> <[email protected]> wrote:
>> We need to protect not only the dmm_map list, but the individual
>> map_obj's, otherwise, we might be building the scatter-gather list with
>> garbage. So, use the existing proc_lock for that.
>>
>> I observed race conditions which caused kernel panics while running
>> stress tests, also, Tuomas Kulve found it happening quite often in
>> Gumstix Over. This patch fixes those.
>>
>> Cc: Tuomas Kulve <[email protected]>
>> Signed-off-by: Felipe Contreras <[email protected]>
>
> Omar, 2.6.38 is imminent, if this patch has any chance of getting in,
> I think you would need to push it soon.
I'll push it to my queue, however I don't think this would be even
considered to make it before the official 2.6.38 which should happen
in the next few days, given that it should climb to staging tree first
and from there to mainline... we could attempt to shot directly to the
mainline kernel, but that would raise a few eyebrows and in the end be
rejected as well because this is a staging driver which is still in
process of cleanup.
OTOH, this patch was there long ago, since December, but I just lost
the track of it at the moment, along with the other proposed
solutions, so I take it as my fault for not picking it up then.
Regards,
Omar
On Fri, Mar 11, 2011 at 8:05 PM, Ramirez Luna, Omar <[email protected]> wrote:
> On Fri, Mar 11, 2011 at 11:38 AM, Felipe Contreras
> <[email protected]> wrote:
>> Omar, 2.6.38 is imminent, if this patch has any chance of getting in,
>> I think you would need to push it soon.
>
> I'll push it to my queue, however I don't think this would be even
> considered to make it before the official 2.6.38 which should happen
> in the next few days, given that it should climb to staging tree first
> and from there to mainline... we could attempt to shot directly to the
> mainline kernel, but that would raise a few eyebrows and in the end be
> rejected as well because this is a staging driver which is still in
> process of cleanup.
Well, not crashing is better than crashing, regardless of the status
of the driver. And there's no reason not to include the fix.
But if you send it to Greg, then it's Greg's call.
> OTOH, this patch was there long ago, since December, but I just lost
> the track of it at the moment, along with the other proposed
> solutions, so I take it as my fault for not picking it up then.
I don't think there was any consensus as which fix was supposed to go
forward or how, but now there is.
Cheers.
--
Felipe Contreras
Hi,
On Fri, Mar 11, 2011 at 12:31 PM, Felipe Contreras
<[email protected]> wrote:
> Well, not crashing is better than crashing, regardless of the status
> of the driver. And there's no reason not to include the fix.
No reason indeed.
> But if you send it to Greg, then it's Greg's call.
Ok then.
Regards,
Omar