Skip to contentSkip to conversation

tools/libs: Make xenforeignmemory_unmap_resource() idempotent

PATCH In review Andrew Cooper 3 participants 7 messages Nov 23, 2018 – Nov 27, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/libs: Make xenforeignmemory_unmap_resource() idempotent

Most other close/unmap functions are.

---
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Paul Durrant <[email protected]>

This ideally wants backporting to 4.11 to hit 4.11.1

I got an unexpected shock while trying to diagnose why GVT-g is still broken (differently!) on staging.

---
 tools/libs/foreignmemory/core.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
tools/libs/foreignmemory/core.c +6 -1
index 63f12e2..2516fd4 100644
@@ -182,7 +182,12 @@ xenforeignmemory_resource_handle *xenforeignmemory_map_resource(
 int xenforeignmemory_unmap_resource(
     xenforeignmemory_handle *fmem, xenforeignmemory_resource_handle *fres)
 {
-    int rc = osdep_xenforeignmemory_unmap_resource(fmem, fres);
+    int rc;
+
+    if ( !fres )
+        return 0;
+
+    rc = osdep_xenforeignmemory_unmap_resource(fmem, fres);
 
     free(fres);
     return rc;
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw
Quoted 34 lines

-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: 23 November 2018 15:12
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Ian Jackson <[email protected]>; Wei Liu <[email protected]>; Paul Durrant <[email protected]>
Subject: [PATCH] tools/libs: Make xenforeignmemory_unmap_resource() idempotent

Most other close/unmap functions are.

---
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Paul Durrant <[email protected]>

This ideally wants backporting to 4.11 to hit 4.11.1

I got an unexpected shock while trying to diagnose why GVT-g is still broken (differently!) on staging.

---
 tools/libs/foreignmemory/core.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
tools/libs/foreignmemory/core.c +0 -0
index 63f12e2..2516fd4 100644
@@ -182,7 +182,12 @@ xenforeignmemory_resource_handle
 *xenforeignmemory_map_resource(
 int xenforeignmemory_unmap_resource(

tools/libs/foreignmemory/core.c xenforeignmemory_resource_handle · line 192

Quoted 10 lines
tools/libs/foreignmemory/core.c +6 -1
     xenforeignmemory_handle *fmem, xenforeignmemory_resource_handle
 *fres)
 {
-    int rc = osdep_xenforeignmemory_unmap_resource(fmem, fres);
+    int rc;
+
+    if ( !fres )
+        return 0;
+
+    rc = osdep_xenforeignmemory_unmap_resource(fmem, fres);

Freeing NULL should not be problem as this defined to do nothing so there is nothing about this function which is not idempotent. I assume, without looking yet, that it is the osdep function which needs fixing.

Paul

Quoted 5 lines
tools/libs/foreignmemory/core.c +0 -0
     free(fres);
     return rc;

--
2.1.4

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
Quoted 51 lines

-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Paul Durrant
Sent: 24 November 2018 15:06
To: Andrew Cooper <[email protected]>; Xen-devel <xen- [email protected]>
Cc: Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; Ian Jackson <[email protected]>
Subject: Re: [Xen-devel] [PATCH] tools/libs: Make xenforeignmemory_unmap_resource() idempotent

Quoted 40 lines

-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: 23 November 2018 15:12
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Ian Jackson <[email protected]>; Wei Liu <[email protected]>; Paul Durrant <[email protected]>
Subject: [PATCH] tools/libs: Make xenforeignmemory_unmap_resource() idempotent

Most other close/unmap functions are.

---
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Paul Durrant <[email protected]>

This ideally wants backporting to 4.11 to hit 4.11.1

I got an unexpected shock while trying to diagnose why GVT-g is still broken (differently!) on staging.

---
 tools/libs/foreignmemory/core.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
tools/libs/foreignmemory/core.c +2 -1
index 63f12e2..2516fd4 100644
@@ -182,7 +182,12 @@ xenforeignmemory_resource_handle
 *xenforeignmemory_map_resource(
 int xenforeignmemory_unmap_resource(
     xenforeignmemory_handle *fmem, xenforeignmemory_resource_handle
 *fres)
 {
-    int rc = osdep_xenforeignmemory_unmap_resource(fmem, fres);
+    int rc;
+
Quoted 9 lines

tools/libs/foreignmemory/core.c xenforeignmemory_resource_handle · line 192

Quoted 4 lines
tools/libs/foreignmemory/core.c +4 -0
+    if ( !fres )
+        return 0;
+
+    rc = osdep_xenforeignmemory_unmap_resource(fmem, fres);

Freeing NULL should not be problem as this defined to do nothing so there is nothing about this function which is not idempotent. I assume, without looking yet, that it is the osdep function which needs fixing.

...and indeed it does. I think this is patch you need...

tools/libs/foreignmemory/linux.c +1 -1
index 132875d..8daa582 100644
@@ -298,7 +298,7 @@ int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem,
 int osdep_xenforeignmemory_unmap_resource(
     xenforeignmemory_handle *fmem, xenforeignmemory_resource_handle *fres)
 {
-    return munmap(fres->addr, fres->nr_frames << PAGE_SHIFT);
+    return fres ? munmap(fres->addr, fres->nr_frames << PAGE_SHIFT) : 0;
 }
 
  Paul

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
Quoted 68 lines · Paul Durrant
Quoted 51 lines

-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Paul Durrant
Sent: 24 November 2018 15:06
To: Andrew Cooper <[email protected]>; Xen-devel <xen- [email protected]>
Cc: Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; Ian Jackson <[email protected]>
Subject: Re: [Xen-devel] [PATCH] tools/libs: Make xenforeignmemory_unmap_resource() idempotent

Quoted 40 lines

-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: 23 November 2018 15:12
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Ian Jackson <[email protected]>; Wei Liu <[email protected]>; Paul Durrant <[email protected]>
Subject: [PATCH] tools/libs: Make xenforeignmemory_unmap_resource() idempotent

Most other close/unmap functions are.

---
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Paul Durrant <[email protected]>

This ideally wants backporting to 4.11 to hit 4.11.1

I got an unexpected shock while trying to diagnose why GVT-g is still broken (differently!) on staging.

---
 tools/libs/foreignmemory/core.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
tools/libs/foreignmemory/core.c +2 -1
index 63f12e2..2516fd4 100644
@@ -182,7 +182,12 @@ xenforeignmemory_resource_handle
 *xenforeignmemory_map_resource(
 int xenforeignmemory_unmap_resource(
     xenforeignmemory_handle *fmem, xenforeignmemory_resource_handle
 *fres)
 {
-    int rc = osdep_xenforeignmemory_unmap_resource(fmem, fres);
+    int rc;
+
Quoted 9 lines

tools/libs/foreignmemory/core.c xenforeignmemory_resource_handle · line 192

Quoted 4 lines
tools/libs/foreignmemory/core.c +4 -0
+    if ( !fres )
+        return 0;
+
+    rc = osdep_xenforeignmemory_unmap_resource(fmem, fres);

Freeing NULL should not be problem as this defined to do nothing so there is nothing about this function which is not idempotent. I assume, without looking yet, that it is the osdep function which needs fixing.

...and indeed it does. I think this is patch you need...

tools/libs/foreignmemory/linux.c +0 -0
index 132875d..8daa582 100644

tools/libs/foreignmemory/linux.c int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem, · line 301

Quoted 5 lines
tools/libs/foreignmemory/linux.c +1 -1
@@ -298,7 +298,7 @@ int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem,
 int osdep_xenforeignmemory_unmap_resource(
     xenforeignmemory_handle *fmem, xenforeignmemory_resource_handle *fres)
 {
-    return munmap(fres->addr, fres->nr_frames << PAGE_SHIFT);
+    return fres ? munmap(fres->addr, fres->nr_frames << PAGE_SHIFT) : 0;

Can you submit a patch for this? And please do this for other osdep functions as well.

Wei.

tools/libs/foreignmemory/linux.c int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem, · line 304

Quoted 3 lines
tools/libs/foreignmemory/linux.c +0 -0
 }
 
  Paul

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw
Quoted 88 lines

-----Original Message-----
From: Wei Liu [mailto:[email protected]]
Sent: 27 November 2018 15:48
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; Xen-devel <xen- [email protected]>; Wei Liu <[email protected]>; Ian Jackson <[email protected]>
Subject: Re: [PATCH] tools/libs: Make xenforeignmemory_unmap_resource() idempotent

Quoted 2 lines · Paul Durrant
Quoted 2 lines

-----Original Message-----
From: Xen-devel [mailto:[email protected]] On

Behalf

Quoted 9 lines
Quoted 9 lines

Of Paul Durrant
Sent: 24 November 2018 15:06
To: Andrew Cooper <[email protected]>; Xen-devel <xen- [email protected]>
Cc: Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; Ian Jackson <[email protected]>
Subject: Re: [Xen-devel] [PATCH] tools/libs: Make xenforeignmemory_unmap_resource() idempotent

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: 23 November 2018 15:12
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Ian Jackson <[email protected]>; Wei Liu <[email protected]>; Paul

Durrant

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

<[email protected]>
Subject: [PATCH] tools/libs: Make xenforeignmemory_unmap_resource() idempotent

Most other close/unmap functions are.

---
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Paul Durrant <[email protected]>

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

This ideally wants backporting to 4.11 to hit 4.11.1

I got an unexpected shock while trying to diagnose why GVT-g is

still

Quoted 17 lines
Quoted 17 lines
Quoted 17 lines

broken (differently!) on staging.

---
 tools/libs/foreignmemory/core.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
tools/libs/foreignmemory/core.c +0 -1
index 63f12e2..2516fd4 100644
@@ -182,7 +182,12 @@ xenforeignmemory_resource_handle
 *xenforeignmemory_map_resource(
 int xenforeignmemory_unmap_resource(
     xenforeignmemory_handle *fmem, xenforeignmemory_resource_handle
 *fres)
 {
-    int rc = osdep_xenforeignmemory_unmap_resource(fmem, fres);
Quoted 8 lines
Quoted 8 lines

tools/libs/foreignmemory/core.c xenforeignmemory_resource_handle · line 192

Quoted 6 lines
tools/libs/foreignmemory/core.c +6 -0
+    int rc;
+
+    if ( !fres )
+        return 0;
+
+    rc = osdep_xenforeignmemory_unmap_resource(fmem, fres);

Freeing NULL should not be problem as this defined to do nothing so

there

Quoted 1 line
Quoted 1 line

is nothing about this function which is not idempotent. I assume,

without

Review

Quoted 6 lines
Quoted 2 lines

looking yet, that it is the osdep function which needs fixing.

...and indeed it does. I think this is patch you need...

(quoted diff) +0 -0

b/tools/libs/foreignmemory/linux.c

tools/libs/foreignmemory/linux.c int

Quoted 4 lines

index 132875d..8daa582 100644

tools/libs/foreignmemory/linux.c +0 -0
@@ -298,7 +298,7 @@ int

osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem,

tools/libs/foreignmemory/linux.c int · line 299

Quoted 2 lines
tools/libs/foreignmemory/linux.c +0 -0
 int osdep_xenforeignmemory_unmap_resource(
     xenforeignmemory_handle *fmem, xenforeignmemory_resource_handle
Quoted 9 lines

*fres)

tools/libs/foreignmemory/linux.c int osdep_xenforeignmemory_restrict(xenforeignmemory_handle *fmem,

Quoted 3 lines
tools/libs/foreignmemory/linux.c +1 -1
 {
-    return munmap(fres->addr, fres->nr_frames << PAGE_SHIFT);
+    return fres ? munmap(fres->addr, fres->nr_frames << PAGE_SHIFT) :

0;

Can you submit a patch for this? And please do this for other osdep functions as well.

Sure.

Paul

Quoted 5 lines

Wei.

Quoted 3 lines
tools/libs/foreignmemory/linux.c +0 -0
 }
 
  Paul

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#5 lore raw
In reply to Paul Durrant
Quoted 37 lines · Paul Durrant
Quoted 37 lines

-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: 23 November 2018 15:12
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Ian Jackson <[email protected]>; Wei Liu <[email protected]>; Paul Durrant <[email protected]>
Subject: [PATCH] tools/libs: Make xenforeignmemory_unmap_resource() idempotent

Most other close/unmap functions are.

---
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Paul Durrant <[email protected]>

This ideally wants backporting to 4.11 to hit 4.11.1

I got an unexpected shock while trying to diagnose why GVT-g is still broken (differently!) on staging.

---
 tools/libs/foreignmemory/core.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
tools/libs/foreignmemory/core.c +0 -0
index 63f12e2..2516fd4 100644
@@ -182,7 +182,12 @@ xenforeignmemory_resource_handle
 *xenforeignmemory_map_resource(
 int xenforeignmemory_unmap_resource(
     xenforeignmemory_handle *fmem, xenforeignmemory_resource_handle
 *fres)
 {
Quoted 8 lines

tools/libs/foreignmemory/core.c xenforeignmemory_resource_handle *xenforeignmemory_map_resource( · line 190

Quoted 7 lines
tools/libs/foreignmemory/core.c +6 -1
-    int rc = osdep_xenforeignmemory_unmap_resource(fmem, fres);
+    int rc;
+
+    if ( !fres )
+        return 0;
+
+    rc = osdep_xenforeignmemory_unmap_resource(fmem, fres);

Freeing NULL should not be problem as this defined to do nothing so there is nothing about this function which is not idempotent. I assume, without looking yet, that it is the osdep function which needs fixing.

Why?  You can fix it once for the entire library here, or once in every osdep flavour.

One of these is rather less code...

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#6 lore raw
Quoted 55 lines

-----Original Message-----
From: Andrew Cooper
Sent: 27 November 2018 16:10
To: Paul Durrant <[email protected]>; Xen-devel <xen- [email protected]>
Cc: Ian Jackson <[email protected]>; Wei Liu <[email protected]>
Subject: Re: [PATCH] tools/libs: Make xenforeignmemory_unmap_resource() idempotent

Quoted 37 lines · Paul Durrant
Quoted 37 lines

-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: 23 November 2018 15:12
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Ian Jackson <[email protected]>; Wei Liu <[email protected]>; Paul Durrant <[email protected]>
Subject: [PATCH] tools/libs: Make xenforeignmemory_unmap_resource() idempotent

Most other close/unmap functions are.

---
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Paul Durrant <[email protected]>

This ideally wants backporting to 4.11 to hit 4.11.1

I got an unexpected shock while trying to diagnose why GVT-g is still broken (differently!) on staging.

---
 tools/libs/foreignmemory/core.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
tools/libs/foreignmemory/core.c +0 -0
index 63f12e2..2516fd4 100644
@@ -182,7 +182,12 @@ xenforeignmemory_resource_handle
 *xenforeignmemory_map_resource(
 int xenforeignmemory_unmap_resource(
     xenforeignmemory_handle *fmem, xenforeignmemory_resource_handle
 *fres)
 {
Quoted 8 lines

tools/libs/foreignmemory/core.c xenforeignmemory_resource_handle *xenforeignmemory_map_resource( · line 190

Quoted 7 lines
tools/libs/foreignmemory/core.c +6 -1
-    int rc = osdep_xenforeignmemory_unmap_resource(fmem, fres);
+    int rc;
+
+    if ( !fres )
+        return 0;
+
+    rc = osdep_xenforeignmemory_unmap_resource(fmem, fres);

Freeing NULL should not be problem as this defined to do nothing so

Quoted 7 lines

there is nothing about this function which is not idempotent. I assume, without looking yet, that it is the osdep function which needs fixing.

Why?  You can fix it once for the entire library here, or once in every osdep flavour.

One of these is rather less code...

Actually I can argue my patch is both complete and smaller since there is a single non-idempotent osdep implementation at the moment :-) I'd also prefer that the osdep implementations are made (and kept) idempotent anyway.

Paul
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel