[01/11] libgomp: Release device lock on cbuf error path

Message ID ca035c65beec5c9b0c0fe30a61d4a792698580df.1633106212.git.julian@codesourcery.com
State Committed
Commit ccfcf08e66c741a1b24a7851a530cf47aa5e704f
Headers
Series OpenMP: Deep struct dereferences |

Commit Message

Julian Brown Oct. 1, 2021, 5:07 p.m. UTC
  This patch releases the device lock on a sanity-checking error path in
transfer combining (cbuf) handling in libgomp:target.c.  This shouldn't
happen when handling well-formed mapping clauses, but erroneous clauses
can currently cause a hang if the condition triggers.

Tested with offloading to NVPTX. OK?

2021-09-29  Julian Brown  <julian@codesourcery.com>

libgomp/
	* target.c (gomp_copy_host2dev): Release device lock on cbuf
	error path.
---
 libgomp/target.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
  

Comments

Jakub Jelinek Oct. 12, 2021, 9:23 a.m. UTC | #1
On Fri, Oct 01, 2021 at 10:07:48AM -0700, Julian Brown wrote:
> This patch releases the device lock on a sanity-checking error path in
> transfer combining (cbuf) handling in libgomp:target.c.  This shouldn't
> happen when handling well-formed mapping clauses, but erroneous clauses
> can currently cause a hang if the condition triggers.
> 
> Tested with offloading to NVPTX. OK?
> 
> 2021-09-29  Julian Brown  <julian@codesourcery.com>
> 
> libgomp/
> 	* target.c (gomp_copy_host2dev): Release device lock on cbuf
> 	error path.

Ok, thanks.  This doesn't seem to depend on anything else, so
can be committed separately right away.

> diff --git a/libgomp/target.c b/libgomp/target.c
> index 65bb40100e5..84c6fdf2c47 100644
> --- a/libgomp/target.c
> +++ b/libgomp/target.c
> @@ -385,7 +385,10 @@ gomp_copy_host2dev (struct gomp_device_descr *devicep,
>  	      else if (cbuf->chunks[middle].start <= doff)
>  		{
>  		  if (doff + sz > cbuf->chunks[middle].end)
> -		    gomp_fatal ("internal libgomp cbuf error");
> +		    {
> +		      gomp_mutex_unlock (&devicep->lock);
> +		      gomp_fatal ("internal libgomp cbuf error");
> +		    }
>  		  memcpy ((char *) cbuf->buf + (doff - cbuf->chunks[0].start),
>  			  h, sz);
>  		  return;
> -- 
> 2.29.2

	Jakub
  

Patch

diff --git a/libgomp/target.c b/libgomp/target.c
index 65bb40100e5..84c6fdf2c47 100644
--- a/libgomp/target.c
+++ b/libgomp/target.c
@@ -385,7 +385,10 @@  gomp_copy_host2dev (struct gomp_device_descr *devicep,
 	      else if (cbuf->chunks[middle].start <= doff)
 		{
 		  if (doff + sz > cbuf->chunks[middle].end)
-		    gomp_fatal ("internal libgomp cbuf error");
+		    {
+		      gomp_mutex_unlock (&devicep->lock);
+		      gomp_fatal ("internal libgomp cbuf error");
+		    }
 		  memcpy ((char *) cbuf->buf + (doff - cbuf->chunks[0].start),
 			  h, sz);
 		  return;