s390x: css: pv: css test adaptation for PV
v4 cover s390x: css: pv: css test adaptation for PV
Hi all,
To adapt the CSS I/O tests to protected virtualisation we need utilities to:
1- allocate the I/O buffers in a private page using (patch 2)
It must be in a dedicated page to avoid exporting code or guest private data to the host.
We accept a size in byte and flags and allocate page integral memory to handle the Protected Virtualization.
2- share the I/O buffers with the host (patch 1)
This patch uses the page allocator reworked by Claudio.
The 2 first patches are the implementation of the tools, patch 3 is the modification of the css.c test for PV.
The checkpatch always asked me to modify MAINTAINERS, so I added me as reviewer to be in copy for CSS at least. May be we could create a finer grain MAINTAINERS in the future.
regards,
Pierre
Pierre Morel (3):
s390x: pv: implement routine to share/unshare memory
s390x: define UV compatible I/O allocation
s390x: css: pv: css test adaptation for PV
MAINTAINERS | 1 + lib/s390x/asm/uv.h | 38 +++++++++++++++++++++++ lib/s390x/css.h | 3 +- lib/s390x/css_lib.c | 28 +++++------------ lib/s390x/malloc_io.c | 70 +++++++++++++++++++++++++++++++++++++++++++ lib/s390x/malloc_io.h | 45 ++++++++++++++++++++++++++++ s390x/Makefile | 1 + s390x/css.c | 43 ++++++++++++++++++-------- 8 files changed, 195 insertions(+), 34 deletions(-) create mode 100644 lib/s390x/malloc_io.c create mode 100644 lib/s390x/malloc_io.h
Signature · 33 lines
2.17.1 changelog: from v3: - add failure report to the new allocations in css.c (Thomas) - rework alloc_io_page and free_io_page (Thomas, Claudio) - add SPDX licenses (Thomas) - add comment for the functions declaration. - add me as reviewer for the CSS from v2: - use the page allocator reworked by Claudio from v1: - add the kvm-unit-test header - correct checks for errors on Set/Remove Shared Access - Add report for uv Set/Remove Shared Access - zero the allocated I/O page before use - free the page on error.
PATCH v4 1/3 s390x: pv: implement routine to share/unshare memory
When communicating with the host we need to share part of the memory.
Let's implement the ultravisor calls for this.
--- lib/s390x/asm/uv.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
lib/s390x/asm/uv.h +38 -0
@@ -71,4 +71,42 @@ static inline int uv_call(unsigned long r1, unsigned long r2)return cc; } +static inline int share (unsigned long addr,u16 cmd) +{ +struct uv_cb_share uvcb = { + .header.cmd = cmd, + .header.len =sizeof (uvcb), + .paddr = addr + }; +int cc; + + cc =uv_call (0 , (u64)&uvcb); +if (!cc && uvcb.header.rc ==0x0001 ) +return 0 ; + +report_info ("cc %d response code: %04x" , cc, uvcb.header.rc); +return -1 ; +} + +/* +* Guest 2 request to the Ultravisor to make a page shared with the +* hypervisor for IO. +* +* @addr: Real or absolute address of the page to be shared +*/ +static inline int uv_set_shared (unsigned long addr) +{ +return share (addr,UVC_CMD_SET_SHARED_ACCESS ); +} + +/* +* Guest 2 request to the Ultravisor to make a page unshared. +* +* @addr: Real or absolute address of the page to be unshared +*/ +static inline int uv_remove_shared (unsigned long addr) +{ +return share (addr,UVC_CMD_REMOVE_SHARED_ACCESS ); +} +#endif
Signature · 1 line
2.17.1
Re: [kvm-unit-tests PATCH v4 1/3] s390x: pv: implement routine to share/unshare memory
Quoted 22 lines · Pierre Morel
When communicating with the host we need to share part of the memory.
Let's implement the ultravisor calls for this.
Signed-off-by Pierre Morel <[email protected]>Suggested-by Janosch Frank <[email protected]>Acked-by Cornelia Huck <[email protected]>Acked-by Thomas Huth <[email protected]>--- lib/s390x/asm/uv.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)lib/s390x/asm/uv.h +1
-0@@ -71,4 +71,42 @@ static inline int uv_call(unsigned long r1, unsigned long r2)return cc; } +static inline int share (unsigned long addr,u16 cmd)
lib/s390x/asm/uv.h static inline int uv_call(unsigned long r1, unsigned long r2) · line 84
Quoted 10 lines
lib/s390x/asm/uv.h +10
-0+{ +struct uv_cb_share uvcb = { + .header.cmd = cmd, + .header.len =sizeof (uvcb), + .paddr = addr + }; +int cc; + + cc =uv_call (0 , (u64)&uvcb); +if (!cc && uvcb.header.rc ==0x0001 )
s/0x0001/UVC_RC_EXECUTED/
lib/s390x/asm/uv.h static inline int uv_call(unsigned long r1, unsigned long r2) · line 87
Quoted 3 lines
lib/s390x/asm/uv.h +3
-0+return 0 ; + +report_info ("cc %d response code: %04x" , cc, uvcb.header.rc);
Will the print have the string UV in it or will I need to guess that a UV call failed?
I'm wondering if an assert would make more sense, if callers are interested in the uv rc they will need to write an own share function anyway.
Quoted 26 lines
lib/s390x/asm/uv.h +24
-0+ return -1; +} + +/* +* Guest 2 request to the Ultravisor to make a page shared with the +* hypervisor for IO. +* +* @addr: Real or absolute address of the page to be shared +*/ +static inline int uv_set_shared (unsigned long addr) +{ +return share (addr,UVC_CMD_SET_SHARED_ACCESS ); +} + +/* +* Guest 2 request to the Ultravisor to make a page unshared. +* +* @addr: Real or absolute address of the page to be unshared +*/ +static inline int uv_remove_shared (unsigned long addr) +{ +return share (addr,UVC_CMD_REMOVE_SHARED_ACCESS ); +} +#endif
Re: [kvm-unit-tests PATCH v4 1/3] s390x: pv: implement routine to share/unshare memory
Quoted 44 lines · Janosch Frank
Quoted 22 lines · Pierre Morel
When communicating with the host we need to share part of the memory.
Let's implement the ultravisor calls for this.
Signed-off-by Pierre Morel <[email protected]>Suggested-by Janosch Frank <[email protected]>Acked-by Cornelia Huck <[email protected]>Acked-by Thomas Huth <[email protected]>--- lib/s390x/asm/uv.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)lib/s390x/asm/uv.h +1
-0@@ -71,4 +71,42 @@ static inline int uv_call(unsigned long r1, unsigned long r2)return cc; } +static inline int share (unsigned long addr,u16 cmd)lib/s390x/asm/uv.h static inline int uv_call(unsigned long r1, unsigned long r2) · line 84
Quoted 10 lines
lib/s390x/asm/uv.h +10
-0+{ +struct uv_cb_share uvcb = { + .header.cmd = cmd, + .header.len =sizeof (uvcb), + .paddr = addr + }; +int cc; + + cc =uv_call (0 , (u64)&uvcb); +if (!cc && uvcb.header.rc ==0x0001 )s/0x0001/UVC_RC_EXECUTED/
lib/s390x/asm/uv.h static inline int uv_call(unsigned long r1, unsigned long r2) · line 87
Quoted 3 lines
lib/s390x/asm/uv.h +3
-0+return 0 ; + +report_info ("cc %d response code: %04x" , cc, uvcb.header.rc);Will the print have the string UV in it or will I need to guess that a UV call failed?
Quoted 3 lines
I'm wondering if an assert would make more sense, if callers are interested in the uv rc they will need to write an own share function anyway.
Ok, I'll take that back. In the following patches you return NULL if the share for an allocation fails and you check for NULL after every allocation so this is fine by me.
Quoted 28 lines
Quoted 27 lines
lib/s390x/asm/uv.h +24
-0+ return -1; +} + +/* +* Guest 2 request to the Ultravisor to make a page shared with the +* hypervisor for IO. +* +* @addr: Real or absolute address of the page to be shared +*/ +static inline int uv_set_shared (unsigned long addr) +{ +return share (addr,UVC_CMD_SET_SHARED_ACCESS ); +} + +/* +* Guest 2 request to the Ultravisor to make a page unshared. +* +* @addr: Real or absolute address of the page to be unshared +*/ +static inline int uv_remove_shared (unsigned long addr) +{ +return share (addr,UVC_CMD_REMOVE_SHARED_ACCESS ); +} +#endif
Re: [kvm-unit-tests PATCH v4 1/3] s390x: pv: implement routine to share/unshare memory
In reply to Janosch FrankQuoted 22 lines · Janosch Frank
Quoted 21 lines · Pierre Morel
When communicating with the host we need to share part of the memory.
Let's implement the ultravisor calls for this.
Signed-off-by Pierre Morel <[email protected]>Suggested-by Janosch Frank <[email protected]>Acked-by Cornelia Huck <[email protected]>Acked-by Thomas Huth <[email protected]>--- lib/s390x/asm/uv.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)lib/s390x/asm/uv.h +0
-0@@ -71,4 +71,42 @@ static inline int uv_call(unsigned long r1, unsigned long r2)return cc; }
Quoted 13 lines
lib/s390x/asm/uv.h static inline int uv_call(unsigned long r1, unsigned long r2) · line 84
Quoted 11 lines
lib/s390x/asm/uv.h +11
-0+static inline int share (unsigned long addr,u16 cmd) +{ +struct uv_cb_share uvcb = { + .header.cmd = cmd, + .header.len =sizeof (uvcb), + .paddr = addr + }; +int cc; + + cc =uv_call (0 , (u64)&uvcb); +if (!cc && uvcb.header.rc ==0x0001 )s/0x0001/UVC_RC_EXECUTED/
OK
Quoted 8 lines
lib/s390x/asm/uv.h static inline int uv_call(unsigned long r1, unsigned long r2) · line 87
Quoted 5 lines
lib/s390x/asm/uv.h +3
-0+return 0 ; + +report_info ("cc %d response code: %04x" , cc, uvcb.header.rc);Will the print have the string UV in it or will I need to guess that a UV call failed?
I will change for a more explicit
Quoted 4 lines
I'm wondering if an assert would make more sense, if callers are interested in the uv rc they will need to write an own share function anyway.
No need (reported OOB by Janosch)
Thanks,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
PATCH v4 2/3 s390x: define UV compatible I/O allocation
In reply to Pierre MorelTo centralize the memory allocation for I/O we define the alloc_io_page/free_io_page functions which share the I/O memory with the host in case the guest runs with protected virtualization.
--- MAINTAINERS | 1 + lib/s390x/malloc_io.c | 70 +++++++++++++++++++++++++++++++++++++++++++ lib/s390x/malloc_io.h | 45 ++++++++++++++++++++++++++++ s390x/Makefile | 1 + 4 files changed, 117 insertions(+) create mode 100644 lib/s390x/malloc_io.c create mode 100644 lib/s390x/malloc_io.h
MAINTAINERS +1 -0
@@ -82,6 +82,7 @@ M: Thomas Huth <[email protected]> M: David Hildenbrand <[email protected]> M: Janosch Frank <[email protected]> R: Cornelia Huck <[email protected]> +R: Pierre Morel <[email protected]> L: [email protected] L: [email protected] F: s390x/*
lib/s390x/malloc_io.c new file +70 -0
70 lines not on this page · raw message
lib/s390x/malloc_io.h new file +45 -0
45 lines not on this page · raw message
s390x/Makefile +1 -0
@@ -63,6 +63,7 @@ cflatobjs += lib/s390x/smp.o cflatobjs += lib/s390x/vm.o cflatobjs += lib/s390x/css_dump.o cflatobjs += lib/s390x/css_lib.o +cflatobjs += lib/s390x/malloc_io.o OBJDIRS += lib/s390x
Signature · 1 line
2.17.1
Re: [kvm-unit-tests PATCH v4 2/3] s390x: define UV compatible I/O allocation
Quoted 33 lines · Pierre Morel
To centralize the memory allocation for I/O we define the alloc_io_page/free_io_page functions which share the I/O memory with the host in case the guest runs with protected virtualization.
Signed-off-by Pierre Morel <[email protected]>--- MAINTAINERS | 1 + lib/s390x/malloc_io.c | 70 +++++++++++++++++++++++++++++++++++++++++++ lib/s390x/malloc_io.h | 45 ++++++++++++++++++++++++++++ s390x/Makefile | 1 + 4 files changed, 117 insertions(+)create mode 100644
lib/s390x/malloc_io.c
create mode 100644lib/s390x/malloc_io.hMAINTAINERS +1
-0@@ -82,6 +82,7 @@ M: Thomas Huth <[email protected]> M: David Hildenbrand <[email protected]> M: Janosch Frank <[email protected]> R: Cornelia Huck <[email protected]> +R: Pierre Morel <[email protected]> L: [email protected] L: [email protected] F: s390x/*lib/s390x/malloc_io.c new file +0
-0
lib/s390x/malloc_io.c line 1
Quoted 1 line
lib/s390x/malloc_io.c new file +1
-0@@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0
"GPL-2.0" is deprecated according to https://spdx.org/licenses/ ... please use "GPL-2.0-only" instead.
Quoted 17 lines
lib/s390x/malloc_io.c new file +17
-0+/* +* I/O page allocation +* +* Copyright (c) 2021 IBM Corp +* +* Authors: +* Pierre Morel <[email protected]> +* +* Using this interface provide host access to the allocated pages in +* case the guest is a secure guest. +* This is needed for I/O buffers. +* +*/ +#include <libcflat.h> +#include <asm/page.h> +#include <asm/uv.h> +#include <malloc_io.h>
lib/s390x/malloc_io.c line 28
Quoted 10 lines
lib/s390x/malloc_io.c new file +10
-0+#include <alloc_page.h> +#include <asm/facility.h> + +static int share_pages (void *p,int count) +{ +int i =0 ; + +for (i =0 ; i < count; i++, p +=PAGE_SIZE ) +if (uv_set_shared ((unsigned long )p)) +return i;
Just a matter of taste, but you could replace the "return i" here also with a "break" since you're returning i below anyway.
lib/s390x/malloc_io.c line 40
Quoted 12 lines
lib/s390x/malloc_io.c new file +12
-0+return i; +} + +static void unshare_pages (void *p,int count) +{ +int i; + +for (i = count; i >0 ; i--, p +=PAGE_SIZE ) +uv_remove_shared ((unsigned long )p); +} + +void *alloc_io_pages (int size,int flags)
I still think the naming or size parameter is confusing here. If I read something like alloc_io_pages(), I'd expect a "num_pages" parameter. So if you want to keep the "size" in bytes, I'd suggest to rename the function to "alloc_io_mem" instead.
lib/s390x/malloc_io.c line 42
Quoted 2 lines
lib/s390x/malloc_io.c new file +2
-0+{ +int order = (size >>PAGE_SHIFT );
I think this is wrong. According to the description of alloc_pages_flag, it allocates "1ull << order" pages. So you likely want to do this instead here:
int order = get_order(size >> PAGE_SHIFT);
Quoted 11 lines
lib/s390x/malloc_io.c new file +11
-0+void *p; +int n; + +assert (size); + + p =alloc_pages_flags (order,AREA_DMA31 | flags); +if (!p || !test_facility (158 )) +return p; + + n =share_pages (p,1 << order); +if (n ==1 << order)
lib/s390x/malloc_io.c line 63
Quoted 10 lines
lib/s390x/malloc_io.c new file +10
-0+return p; + +unshare_pages (p, n); +free_pages (p); +return NULL ; +} + +void free_io_pages (void *p,int size) +{ +int order = size >>PAGE_SHIFT ;
dito?
lib/s390x/malloc_io.h line 1
Quoted 13 lines
lib/s390x/malloc_io.c new file +6
-0+assert (IS_ALIGNED ((uintptr_t )p,PAGE_SIZE )); + +if (test_facility (158 )) +unshare_pages (p,1 << order); +free_pages (p); +}lib/s390x/malloc_io.h new file +1
-0@@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: GPL-2.0 */
GPL-2.0-only please.
Quoted 19 lines
lib/s390x/malloc_io.h new file +19
-0+/* +* I/O allocations +* +* Copyright (c) 2021 IBM Corp +* +* Authors: +* Pierre Morel <[email protected]> +* +*/ +#ifndef _S390X_MALLOC_IO_H_ +#define _S390X_MALLOC_IO_H_ + +/* +* Allocates a page aligned page bound range of contiguous real or +* absolute memory in the DMA31 region large enough to contain size +* bytes. +* If Protected Virtualization facility is present, shares the pages +* with the host. +* If all the pages for the specified size cannot be reserved,
lib/s390x/malloc_io.h line 30
Quoted 10 lines
lib/s390x/malloc_io.h new file +10
-0+* the function rewinds the partial allocation and a NULL pointer +* is returned. +* +* @size: the minimal size allocated in byte. +* @flags: the flags used for the underlying page allocator. +* +* Errors: +* The allocation will assert the size parameter, will fail if the +* underlying page allocator fail or in the case of protected +* virtualisation if the sharing of the pages fails.
I think "virtualization" (with an z) is more common than "virtualisation".
Quoted 20 lines
lib/s390x/malloc_io.h new file +15
-0+* +* Returns a pointer to the first page in case of success, NULL otherwise. +*/ +void *alloc_io_pages (int size,int flags); + +/* +* Frees a previously memory space allocated by alloc_io_pages. +* If Protected Virtualization facility is present, unshares the pages +* with the host. +* The address must be aligned on a page boundary otherwise an assertion +* breaks the program. +*/ +void free_io_pages (void *p,int size); + +#endif /* _S390X_MALLOC_IO_H_ */ s390x/Makefile +0
-0
s390x/Makefile cflatobjs += lib/s390x/smp.o · line 68
Quoted 6 lines
s390x/Makefile +1
-0@@ -63,6 +63,7 @@ cflatobjs += lib/s390x/smp.o cflatobjs += lib/s390x/vm.o cflatobjs += lib/s390x/css_dump.o cflatobjs += lib/s390x/css_lib.o +cflatobjs += lib/s390x/malloc_io.o OBJDIRS += lib/s390x
Thomas
Re: [kvm-unit-tests PATCH v4 2/3] s390x: define UV compatible I/O allocation
On 1/21/21 10:32 AM, Thomas Huth wrote:
...snip...
Quoted 11 lines
lib/s390x/malloc_io.c line 28
Quoted 9 lines
lib/s390x/malloc_io.c new file +9
-0+#include <asm/facility.h> + +static int share_pages (void *p,int count) +{ + int i = 0; + + for (i = 0; i < count; i++, p += PAGE_SIZE) + if (uv_set_shared((unsigned long)p)) + return i;Just a matter of taste, but you could replace the "return i" here also with a "break" since you're returning i below anyway.
right a single out point is always better.
Quoted 15 lines
lib/s390x/malloc_io.c line 40
Quoted 13 lines
+ return i;
lib/s390x/malloc_io.c new file +11
-0+} + +static void unshare_pages (void *p,int count) +{ + int i; + + for (i = count; i > 0; i--, p += PAGE_SIZE) + uv_remove_shared((unsigned long)p); +} + +void *alloc_io_pages (int size,int flags)I still think the naming or size parameter is confusing here. If I read something like
alloc_io_pages(), I'd expect a "num_pages" parameter. So if you want to keep the "size" in bytes, I'd suggest to rename the function to "alloc_io_mem" instead.
OK, I rename the function, allowing the user to keep a simple interface without having to calculate the page order.
Quoted 8 lines
Quoted 3 lines
+{
+ int order = (size >>PAGE_SHIFT);I think this is wrong. According to the description of
alloc_pages_flag, it allocates "1ull << order" pages. So you likely want to do this instead here:int order =
get_order(size >> PAGE_SHIFT);
you are absolutely right.
Quoted 16 lines
Quoted 16 lines
+ void *p;
+ int n;lib/s390x/malloc_io.c new file +13
-0+ + assert(size); + + p = alloc_pages_flags(order, AREA_DMA31 | flags); + if (!p || !test_facility(158)) + return p; + + n = share_pages(p, 1 << order); + if (n == 1 << order) + return p; + + unshare_pages(p, n); + free_pages(p);
Quoted 8 lines
lib/s390x/malloc_io.c line 63
Quoted 6 lines
+ return NULL;
lib/s390x/malloc_io.c new file +5
-0+} + +void free_io_pages (void *p,int size) +{ + int order = size >> PAGE_SHIFT;dito?
yes :(
Quoted 16 lines
Quoted 13 lines
+
assert(IS_ALIGNED((uintptr_t)p, PAGE_SIZE));lib/s390x/malloc_io.c new file +5
-0+ + if (test_facility(158)) + unshare_pages(p, 1 << order); + free_pages(p); +}lib/s390x/malloc_io.h new file +0
-0lib/s390x/malloc_io.h line 1
Quoted 1 line
lib/s390x/malloc_io.h new file +1
-0@@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: GPL-2.0 */ GPL-2.0-only please.
almmost... I use:
/* SPDX-License-Identifier: GPL-2.0-or-later */
as in other files updated by janosch if this is not a problem.
Quoted 24 lines
Quoted 24 lines
lib/s390x/malloc_io.h new file +23
-0+/* +* I/O allocations +* +* Copyright (c) 2021 IBM Corp +* +* Authors: +* Pierre Morel <[email protected]> +* +*/ +#ifndef _S390X_MALLOC_IO_H_ +#define _S390X_MALLOC_IO_H_ + +/* +* Allocates a page aligned page bound range of contiguous real or +* absolute memory in the DMA31 region large enough to contain size +* bytes. +* If Protected Virtualization facility is present, shares the pages +* with the host. +* If all the pages for the specified size cannot be reserved, +* the function rewinds the partial allocation and a NULL pointer +* is returned. +* +* @size: the minimal size allocated in byte.
Quoted 8 lines
lib/s390x/malloc_io.h line 30
Quoted 6 lines
lib/s390x/malloc_io.h new file +6
-0+* @flags: the flags used for the underlying page allocator. +* +* Errors: +* The allocation will assert the size parameter, will fail if the +* underlying page allocator fail or in the case of protected +* virtualisation if the sharing of the pages fails. I think "virtualization" (with an z) is more common than "virtualisation".
OK
Thanks,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [kvm-unit-tests PATCH v4 2/3] s390x: define UV compatible I/O allocation
In reply to Pierre MorelQuoted 20 lines · Pierre Morel
To centralize the memory allocation for I/O we define the alloc_io_page/free_io_page functions which share the I/O memory with the host in case the guest runs with protected virtualization.
Signed-off-by Pierre Morel <[email protected]>--- MAINTAINERS | 1 + lib/s390x/malloc_io.c | 70 +++++++++++++++++++++++++++++++++++++++++++ lib/s390x/malloc_io.h | 45 ++++++++++++++++++++++++++++ s390x/Makefile | 1 + 4 files changed, 117 insertions(+) create mode 100644 lib/s390x/malloc_io.c create mode 100644 lib/s390x/malloc_io.hMAINTAINERS +0
-0
MAINTAINERS M: Thomas Huth <[email protected]> · line 85
Quoted 4 lines
MAINTAINERS +1
-0@@ -82,6 +82,7 @@ M: Thomas Huth <[email protected]> M: David Hildenbrand <[email protected]> M: Janosch Frank <[email protected]> R: Cornelia Huck <[email protected]> +R: Pierre Morel <[email protected]>
If you're ok with the amount of mails you'll get then go ahead. But I think maintainer file changes should always be in a separate patch.
lib/s390x/malloc_io.c line 1
Quoted 10 lines
MAINTAINERS +0
-0L: [email protected] L: [email protected] F: s390x/*lib/s390x/malloc_io.c new file +1
-0@@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0
I think we wanted to use:
/* SPDX-License-Identifier: GPL-2.0-or-later */
Quoted 57 lines
lib/s390x/malloc_io.c new file +57
-0+/* +* I/O page allocation +* +* Copyright (c) 2021 IBM Corp +* +* Authors: +* Pierre Morel <[email protected]> +* +* Using this interface provide host access to the allocated pages in +* case the guest is a secure guest. +* This is needed for I/O buffers. +* +*/ +#include <libcflat.h> +#include <asm/page.h> +#include <asm/uv.h> +#include <malloc_io.h> +#include <alloc_page.h> +#include <asm/facility.h> + +static int share_pages (void *p,int count) +{ +int i =0 ; + +for (i =0 ; i < count; i++, p +=PAGE_SIZE ) +if (uv_set_shared ((unsigned long )p)) +return i; +return i; +} + +static void unshare_pages (void *p,int count) +{ +int i; + +for (i = count; i >0 ; i--, p +=PAGE_SIZE ) +uv_remove_shared ((unsigned long )p); +} + +void *alloc_io_pages (int size,int flags) +{ +int order = (size >>PAGE_SHIFT ); +void *p; +int n; + +assert (size); + + p =alloc_pages_flags (order,AREA_DMA31 | flags); +if (!p || !test_facility (158 )) +return p; + + n =share_pages (p,1 << order); +if (n ==1 << order) +return p; + +unshare_pages (p, n); +free_pages (p); +return NULL ;
lib/s390x/malloc_io.c line 68
Quoted 10 lines
lib/s390x/malloc_io.c new file +10
-0+} + +void free_io_pages (void *p,int size) +{ +int order = size >>PAGE_SHIFT ; + +assert (IS_ALIGNED ((uintptr_t )p,PAGE_SIZE )); + +if (test_facility (158 )) +unshare_pages (p,1 << order);
I have a lib file in the making that will let you check UV features like test_facility(). When that's ready I'm gonna check for unshare here.
Quoted 66 lines
lib/s390x/malloc_io.c new file +2
-0+free_pages (p); +}lib/s390x/malloc_io.h new file +45
-0@@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* I/O allocations +* +* Copyright (c) 2021 IBM Corp +* +* Authors: +* Pierre Morel <[email protected]> +* +*/ +#ifndef _S390X_MALLOC_IO_H_ +#define _S390X_MALLOC_IO_H_ + +/* +* Allocates a page aligned page bound range of contiguous real or +* absolute memory in the DMA31 region large enough to contain size +* bytes. +* If Protected Virtualization facility is present, shares the pages +* with the host. +* If all the pages for the specified size cannot be reserved, +* the function rewinds the partial allocation and a NULL pointer +* is returned. +* +* @size: the minimal size allocated in byte. +* @flags: the flags used for the underlying page allocator. +* +* Errors: +* The allocation will assert the size parameter, will fail if the +* underlying page allocator fail or in the case of protected +* virtualisation if the sharing of the pages fails. +* +* Returns a pointer to the first page in case of success, NULL otherwise. +*/ +void *alloc_io_pages (int size,int flags); + +/* +* Frees a previously memory space allocated by alloc_io_pages. +* If Protected Virtualization facility is present, unshares the pages +* with the host. +* The address must be aligned on a page boundary otherwise an assertion +* breaks the program. +*/ +void free_io_pages (void *p,int size); + +#endif /* _S390X_MALLOC_IO_H_ */ s390x/Makefile +1
-0@@ -63,6 +63,7 @@ cflatobjs += lib/s390x/smp.o cflatobjs += lib/s390x/vm.o cflatobjs += lib/s390x/css_dump.o cflatobjs += lib/s390x/css_lib.o +cflatobjs += lib/s390x/malloc_io.o OBJDIRS += lib/s390x
Re: [kvm-unit-tests PATCH v4 2/3] s390x: define UV compatible I/O allocation
Quoted 16 lines · Janosch Frank
Quoted 15 lines · Pierre Morel
To centralize the memory allocation for I/O we define the alloc_io_page/free_io_page functions which share the I/O memory with the host in case the guest runs with protected virtualization.
Signed-off-by Pierre Morel <[email protected]>--- MAINTAINERS | 1 + lib/s390x/malloc_io.c | 70 +++++++++++++++++++++++++++++++++++++++++++ lib/s390x/malloc_io.h | 45 ++++++++++++++++++++++++++++ s390x/Makefile | 1 + 4 files changed, 117 insertions(+)create mode 100644
lib/s390x/malloc_io.c
create mode 100644lib/s390x/malloc_io.h
Quoted 12 lines
MAINTAINERS M: Thomas Huth <[email protected]> · line 85
Quoted 9 lines
MAINTAINERS +1
-0@@ -82,6 +82,7 @@ M: Thomas Huth <[email protected]> M: David Hildenbrand <[email protected]> M: Janosch Frank <[email protected]> R: Cornelia Huck <[email protected]> +R: Pierre Morel <[email protected]>If you're ok with the amount of mails you'll get then go ahead. But I think maintainer file changes should always be in a separate patch.
You are right it was more an attempts to bring the Linux checkpatch to be quiet but this would need more changes so.. we can discuss this in a separate patch.
Quoted 14 lines
lib/s390x/malloc_io.c line 1
Quoted 11 lines
MAINTAINERS +0
-0L: [email protected] L: [email protected] F: s390x/*lib/s390x/malloc_io.c new file +1
-0@@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0 I think we wanted to use:
/* SPDX-License-Identifier: GPL-2.0-or-later */
yes
...snip...
Quoted 4 lines
Quoted 4 lines
lib/s390x/malloc_io.c new file +4
-0+ +void free_io_pages (void *p,int size) +{ +int order = size >>PAGE_SHIFT ;
Quoted 8 lines
lib/s390x/malloc_io.c line 68
Quoted 5 lines
lib/s390x/malloc_io.c new file +5
-0+ +assert (IS_ALIGNED ((uintptr_t )p,PAGE_SIZE )); + +if (test_facility (158 )) +unshare_pages (p,1 << order);I have a lib file in the making that will let you check UV features like
test_facility(). When that's ready I'm gonna check for unshare here.
OK
Thanks,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [kvm-unit-tests PATCH v4 2/3] s390x: define UV compatible I/O allocation
In reply to Janosch FrankQuoted 29 lines · Janosch Frank
Quoted 20 lines · Pierre Morel
To centralize the memory allocation for I/O we define the alloc_io_page/free_io_page functions which share the I/O memory with the host in case the guest runs with protected virtualization.
Signed-off-by Pierre Morel <[email protected]>--- MAINTAINERS | 1 + lib/s390x/malloc_io.c | 70 +++++++++++++++++++++++++++++++++++++++++++ lib/s390x/malloc_io.h | 45 ++++++++++++++++++++++++++++ s390x/Makefile | 1 + 4 files changed, 117 insertions(+)create mode 100644
lib/s390x/malloc_io.c
create mode 100644lib/s390x/malloc_io.hMAINTAINERS +0
-0MAINTAINERS M: Thomas Huth <[email protected]> · line 85
Quoted 4 lines
MAINTAINERS +1
-0@@ -82,6 +82,7 @@ M: Thomas Huth <[email protected]> M: David Hildenbrand <[email protected]> M: Janosch Frank <[email protected]> R: Cornelia Huck <[email protected]> +R: Pierre Morel <[email protected]>If you're ok with the amount of mails you'll get then go ahead. But I think maintainer file changes should always be in a separate patch.
Quoted 12 lines
lib/s390x/malloc_io.c line 1
Quoted 10 lines
MAINTAINERS +0
-0L: [email protected] L: [email protected] F: s390x/*lib/s390x/malloc_io.c new file +1
-0@@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0 I think we wanted to use:
@Janosch , @Thomas
Quoted 1 line
/* SPDX-License-Identifier: GPL-2.0-or-later */
or
// SPDX-License-Identifier: GPL-2.0-only
later or only ?
/* or // ?
If both are OK, I will take the Janosch proposition which is in use in vm.[ch] and ignore the Linux checkpatch warning.
Just to : Why are you people not using the Linux style code completely instead of making new exceptions.
i.e. SPDX license and MAINTAINERS
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [kvm-unit-tests PATCH v4 2/3] s390x: define UV compatible I/O allocation
Quoted 47 lines · Pierre Morel
Quoted 29 lines · Janosch Frank
Quoted 20 lines · Pierre Morel
To centralize the memory allocation for I/O we define the alloc_io_page/free_io_page functions which share the I/O memory with the host in case the guest runs with protected virtualization.
Signed-off-by Pierre Morel <[email protected]>---
MAINTAINERS | 1 +
lib/s390x/malloc_io.c| 70 +++++++++++++++++++++++++++++++++++++++++++lib/s390x/malloc_io.h| 45 ++++++++++++++++++++++++++++ s390x/Makefile | 1 +4 files changed, 117 insertions(+)create mode 100644
lib/s390x/malloc_io.c
create mode 100644lib/s390x/malloc_io.hMAINTAINERS +0
-0@@ -82,6 +82,7 @@ M: Thomas Huth <[email protected]>Quoted 4 lines
M: David Hildenbrand <[email protected]>
M: Janosch Frank <[email protected]>
R: Cornelia Huck <[email protected]>
+R: Pierre Morel <[email protected]>If you're ok with the amount of mails you'll get then go ahead. But I think maintainer file changes should always be in a separate patch.
Quoted 12 lines
lib/s390x/malloc_io.c line 1
Quoted 10 lines
L: [email protected]
L: [email protected]
F: s390x/*lib/s390x/malloc_io.c new file +1
-0@@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0 I think we wanted to use:
@Janosch , @Thomas
Quoted 7 lines
Quoted 1 line
/* SPDX-License-Identifier: GPL-2.0-or-later */
or
// SPDX-License-Identifier: GPL-2.0-only
later or only ?
If it's a new file, it's up to the author. I personally prefer -later, but I think IBM's preference is normally -only instead. Please check with your colleagues. Most s390x-related files in the kvm-unit-tests currently use "GPL-2.0-only", so that should be ok anyway.
Quoted 1 line
/* or // ?
I don't mind. // seems to be kernel style for .c files, but so far we've only used /* with SPDX in the kvm-unit-tests, so both should be fine, I think.
Quoted 3 lines
Just to : Why are you people not using the Linux style code completely instead of making new exceptions.
i.e. SPDX license and
MAINTAINERS
Actually, I wonder why the Linux documentation still recommends the identifiers that are marked as deprecated on the SPDX website. The deprecated "GPL-2.0" can be rather confusing, since it IMHO can easily be mistaken as "GPL-2.0+", so the newer identifiers are better, indeed.
Not sure what you mean with MAINTAINERS, though.
Thomas
Re: [kvm-unit-tests PATCH v4 2/3] s390x: define UV compatible I/O allocation
Quoted 64 lines · Thomas Huth
Quoted 48 lines · Pierre Morel
Quoted 30 lines · Janosch Frank
Quoted 21 lines · Pierre Morel
To centralize the memory allocation for I/O we define the alloc_io_page/free_io_page functions which share the I/O memory with the host in case the guest runs with protected virtualization.
Signed-off-by Pierre Morel <[email protected]>---
MAINTAINERS | 1 +lib/s390x/malloc_io.c| 70
+++++++++++++++++++++++++++++++++++++++++++
lib/s390x/malloc_io.h| 45 ++++++++++++++++++++++++++++ s390x/Makefile | 1 +4 files changed, 117 insertions(+)create mode 100644
lib/s390x/malloc_io.c
create mode 100644lib/s390x/malloc_io.hMAINTAINERS +0
-0@@ -82,6 +82,7 @@ M: Thomas Huth <[email protected]>Quoted 4 lines
M: David Hildenbrand <[email protected]>
M: Janosch Frank <[email protected]>
R: Cornelia Huck <[email protected]>
+R: Pierre Morel <[email protected]>If you're ok with the amount of mails you'll get then go ahead. But I think maintainer file changes should always be in a separate patch.
Quoted 12 lines
lib/s390x/malloc_io.c line 1
Quoted 10 lines
L: [email protected]
L: [email protected]
F: s390x/*lib/s390x/malloc_io.c new file +1
-0@@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0 I think we wanted to use:
@Janosch , @Thomas
Quoted 7 lines
Quoted 1 line
/* SPDX-License-Identifier: GPL-2.0-or-later */
or
// SPDX-License-Identifier: GPL-2.0-only
later or only ?
If it's a new file, it's up to the author. I personally prefer -later, but I think IBM's preference is normally -only instead. Please check with your colleagues. Most s390x-related files in the kvm-unit-tests currently use "GPL-2.0-only", so that should be ok anyway.
Quoted 1 line
/* or // ?
I don't mind. // seems to be kernel style for .c files, but so far we've only used /* with SPDX in the kvm-unit-tests, so both should be fine, I think.
Quoted 7 lines
Quoted 3 lines
Just to : Why are you people not using the Linux style code completely instead of making new exceptions.
i.e. SPDX license and
MAINTAINERSActually, I wonder why the Linux documentation still recommends the identifiers that are marked as deprecated on the SPDX website. The deprecated "GPL-2.0" can be rather confusing, since it IMHO can easily be mistaken as "GPL-2.0+", so the newer identifiers are better, indeed.
Not sure what you mean with
MAINTAINERS, though.
Thanks for the explanations :)
For MAINTAINERS, the Linux kernel checkpatch warns that we should use TABS instead of SPACES between item and names.
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [kvm-unit-tests PATCH v4 2/3] s390x: define UV compatible I/O allocation
On 21/01/2021 14.47, Pierre Morel wrote:
[...]
Quoted 2 lines
For
MAINTAINERS, the Linux kernel checkpatch warns that we should use TABS instead of SPACES between item and names.
Interesting, I wasn't aware of that. I guess it's simply because the MAINTAINERS file in kvm-unit-tests is older than the patch that changed the checkpatch script in the kernel, and updates to the MAINTAINRS file in k-u-t are so seldom that nobody really noticed afterwards.
If it bothers you, feel free to send a patch to fix k-u-t's MAINTAINERS file, it might be nice indeed to be aligned with the kernel here again.
Thomas
Re: [kvm-unit-tests PATCH v4 2/3] s390x: define UV compatible I/O allocation
Quoted 12 lines · Thomas Huth
On 21/01/2021 14.47, Pierre Morel wrote:
[...]Quoted 2 lines
For
MAINTAINERS, the Linux kernel checkpatch warns that we should use TABS instead of SPACES between item and names.Interesting, I wasn't aware of that. I guess it's simply because the
MAINTAINERSfile in kvm-unit-tests is older than the patch that changed the checkpatch script in the kernel, and updates to the MAINTAINRS file in k-u-t are so seldom that nobody really noticed afterwards.If it bothers you, feel free to send a patch to fix k-u-t's
MAINTAINERSfile, it might be nice indeed to be aligned with the kernel here again.Thomas
OK, I will do,
Thanks,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [kvm-unit-tests PATCH v4 2/3] s390x: define UV compatible I/O allocation
In reply to Pierre MorelQuoted 58 lines · Pierre Morel
Quoted 29 lines · Janosch Frank
Quoted 20 lines · Pierre Morel
To centralize the memory allocation for I/O we define the alloc_io_page/free_io_page functions which share the I/O memory with the host in case the guest runs with protected virtualization.
Signed-off-by Pierre Morel <[email protected]>--- MAINTAINERS | 1 + lib/s390x/malloc_io.c | 70 +++++++++++++++++++++++++++++++++++++++++++ lib/s390x/malloc_io.h | 45 ++++++++++++++++++++++++++++ s390x/Makefile | 1 + 4 files changed, 117 insertions(+)create mode 100644
lib/s390x/malloc_io.c
create mode 100644lib/s390x/malloc_io.hMAINTAINERS +0
-0MAINTAINERS M: Thomas Huth <[email protected]> · line 85
Quoted 4 lines
MAINTAINERS +1
-0@@ -82,6 +82,7 @@ M: Thomas Huth <[email protected]> M: David Hildenbrand <[email protected]> M: Janosch Frank <[email protected]> R: Cornelia Huck <[email protected]> +R: Pierre Morel <[email protected]>If you're ok with the amount of mails you'll get then go ahead. But I think maintainer file changes should always be in a separate patch.
Quoted 12 lines
lib/s390x/malloc_io.c line 1
Quoted 10 lines
MAINTAINERS +0
-0L: [email protected] L: [email protected] F: s390x/*lib/s390x/malloc_io.c new file +1
-0@@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0 I think we wanted to use:
@Janosch , @Thomas
Quoted 1 line
/* SPDX-License-Identifier: GPL-2.0-or-later */
or
// SPDX-License-Identifier: GPL-2.0-only
later or only ?
/* or // ?
Quoted 8 lines
If both are OK, I will take the Janosch proposition which is in use in vm.[ch] and ignore the Linux checkpatch warning.
Just to : Why are you people not using the Linux style code completely instead of making new exceptions.
i.e. SPDX license and
MAINTAINERS
s390 also has /* */ style SPDX and GPL2.0+ statements in the kernel...
Since KUT has way less developers the style rules aren't as strict and currently I see that as an advantage. Following checkpatch down the cliff is a bad idea in the kernel and for unit tests. It's most often correct, but not always.
Re: [kvm-unit-tests PATCH v4 2/3] s390x: define UV compatible I/O allocation
Quoted 68 lines · Janosch Frank
Quoted 58 lines · Pierre Morel
Quoted 29 lines · Janosch Frank
Quoted 20 lines · Pierre Morel
To centralize the memory allocation for I/O we define the alloc_io_page/free_io_page functions which share the I/O memory with the host in case the guest runs with protected virtualization.
Signed-off-by Pierre Morel <[email protected]>--- MAINTAINERS | 1 + lib/s390x/malloc_io.c | 70 +++++++++++++++++++++++++++++++++++++++++++ lib/s390x/malloc_io.h | 45 ++++++++++++++++++++++++++++ s390x/Makefile | 1 + 4 files changed, 117 insertions(+)create mode 100644
lib/s390x/malloc_io.c
create mode 100644lib/s390x/malloc_io.hMAINTAINERS +0
-0MAINTAINERS M: Thomas Huth <[email protected]> · line 85
Quoted 4 lines
MAINTAINERS +1
-0@@ -82,6 +82,7 @@ M: Thomas Huth <[email protected]> M: David Hildenbrand <[email protected]> M: Janosch Frank <[email protected]> R: Cornelia Huck <[email protected]> +R: Pierre Morel <[email protected]>If you're ok with the amount of mails you'll get then go ahead. But I think maintainer file changes should always be in a separate patch.
Quoted 12 lines
lib/s390x/malloc_io.c line 1
Quoted 10 lines
MAINTAINERS +0
-0L: [email protected] L: [email protected] F: s390x/*lib/s390x/malloc_io.c new file +1
-0@@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0 I think we wanted to use:
@Janosch , @Thomas
Quoted 1 line
/* SPDX-License-Identifier: GPL-2.0-or-later */
or
// SPDX-License-Identifier: GPL-2.0-only
later or only ?
/* or // ?
Quoted 8 lines
If both are OK, I will take the Janosch proposition which is in use in vm.[ch] and ignore the Linux checkpatch warning.
Just to : Why are you people not using the Linux style code completely instead of making new exceptions.
i.e. SPDX license and
MAINTAINERS
Quoted 7 lines
s390 also has /* */ style SPDX and GPL2.0+ statements in the kernel...
Since KUT has way less developers the style rules aren't as strict and currently I see that as an advantage. Following checkpatch down the cliff is a bad idea in the kernel and for unit tests. It's most often correct, but not always.
Oh OK,
thanks for the explanation,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [kvm-unit-tests PATCH v4 2/3] s390x: define UV compatible I/O allocation
In reply to Janosch FrankQuoted 105 lines · Janosch Frank
Quoted 20 lines · Pierre Morel
To centralize the memory allocation for I/O we define the alloc_io_page/free_io_page functions which share the I/O memory with the host in case the guest runs with protected virtualization.
Signed-off-by Pierre Morel <[email protected]>--- MAINTAINERS | 1 + lib/s390x/malloc_io.c | 70 +++++++++++++++++++++++++++++++++++++++++++ lib/s390x/malloc_io.h | 45 ++++++++++++++++++++++++++++ s390x/Makefile | 1 + 4 files changed, 117 insertions(+)create mode 100644
lib/s390x/malloc_io.c
create mode 100644lib/s390x/malloc_io.hMAINTAINERS +0
-0MAINTAINERS M: Thomas Huth <[email protected]> · line 85
Quoted 4 lines
MAINTAINERS +1
-0@@ -82,6 +82,7 @@ M: Thomas Huth <[email protected]> M: David Hildenbrand <[email protected]> M: Janosch Frank <[email protected]> R: Cornelia Huck <[email protected]> +R: Pierre Morel <[email protected]>If you're ok with the amount of mails you'll get then go ahead. But I think maintainer file changes should always be in a separate patch.
lib/s390x/malloc_io.c line 1
Quoted 10 lines
MAINTAINERS +0
-0L: [email protected] L: [email protected] F: s390x/*lib/s390x/malloc_io.c new file +1
-0@@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0 I think we wanted to use:
/* SPDX-License-Identifier: GPL-2.0-or-later */Quoted 62 lines
lib/s390x/malloc_io.c new file +62
-0+/* +* I/O page allocation +* +* Copyright (c) 2021 IBM Corp +* +* Authors: +* Pierre Morel <[email protected]> +* +* Using this interface provide host access to the allocated pages in +* case the guest is a secure guest. +* This is needed for I/O buffers. +* +*/ +#include <libcflat.h> +#include <asm/page.h> +#include <asm/uv.h> +#include <malloc_io.h> +#include <alloc_page.h> +#include <asm/facility.h> + +static int share_pages (void *p,int count) +{ +int i =0 ; + +for (i =0 ; i < count; i++, p +=PAGE_SIZE ) +if (uv_set_shared ((unsigned long )p)) +return i; +return i; +} + +static void unshare_pages (void *p,int count) +{ +int i; + +for (i = count; i >0 ; i--, p +=PAGE_SIZE ) +uv_remove_shared ((unsigned long )p); +} + +void *alloc_io_pages (int size,int flags) +{ +int order = (size >>PAGE_SHIFT ); +void *p; +int n; + +assert (size); + + p =alloc_pages_flags (order,AREA_DMA31 | flags); +if (!p || !test_facility (158 )) +return p; + + n =share_pages (p,1 << order); +if (n ==1 << order) +return p; + +unshare_pages (p, n); +free_pages (p); +return NULL ; +} + +void free_io_pages (void *p,int size) +{ +int order = size >>PAGE_SHIFT ;
Quoted 8 lines
lib/s390x/malloc_io.c line 68
Quoted 5 lines
lib/s390x/malloc_io.c new file +5
-0+ +assert (IS_ALIGNED ((uintptr_t )p,PAGE_SIZE )); + +if (test_facility (158 )) +unshare_pages (p,1 << order);I have a lib file in the making that will let you check UV features like
test_facility(). When that's ready I'm gonna check for unshare here.
OK.
On share_pages the rc is enough I suppose.
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
PATCH v4 3/3 s390x: css: pv: css test adaptation for PV
In reply to Pierre MorelWe want the tests to automatically work with or without protected virtualisation.
To do this we need to share the I/O memory with the host.
Let's replace all static allocations with dynamic allocations to clearly separate shared and private memory.
--- lib/s390x/css.h | 3 +-- lib/s390x/css_lib.c | 28 ++++++++-------------------- s390x/css.c | 43 +++++++++++++++++++++++++++++++------------ 3 files changed, 40 insertions(+), 34 deletions(-)
lib/s390x/css.h +1 -2
@@ -283,8 +283,7 @@ int css_enable(int schid, int isc);/* Library functions */ int start_ccw1_chain (unsigned int sid,struct ccw1 *ccw); -int start_single_ccw (unsigned int sid,int code,void *data,int count, -unsigned char flags); +struct ccw1 *ccw_alloc (int code,void *data,int count,unsigned char flags);void css_irq_io (void );int css_residual_count (unsigned int schid);
lib/s390x/css_lib.c +8 -20
@@ -18,6 +18,7 @@#include <asm/time.h> #include <asm/arch_def.h> +#include <malloc_io.h> #include <css.h> static struct schib schib;
@@ -202,33 +203,20 @@ int start_ccw1_chain(unsigned int sid, struct ccw1 *ccw)return ssch (sid, &orb); } -/* -* In the future, we want to implement support for CCW chains; -* for that, we will need to work with ccw1 pointers. -*/ -static struct ccw1 unique_ccw; - -int start_single_ccw (unsigned int sid,int code,void *data,int count, -unsigned char flags) +struct ccw1 *ccw_alloc (int code,void *data,int count,unsigned char flags) { -int cc; -struct ccw1 *ccw = &unique_ccw; +struct ccw1 *ccw; + + ccw =alloc_io_pages (sizeof (*ccw),0 ); +if (!ccw) +return NULL ; -report_prefix_push ("start_subchannel" ); -/* Build the CCW chain with a single CCW */ ccw->code = code; ccw->flags = flags; ccw->count = count; ccw->data_address = (int )(unsigned long )data; - cc =start_ccw1_chain (sid, ccw); -if (cc) { -report (0 ,"cc = %d" , cc); -report_prefix_pop (); -return cc; - } -report_prefix_pop (); -return 0 ; +return ccw; }/* wait_and_check_io_completion:
s390x/css.c +31 -12
89 lines not on this page · raw message
Signature · 1 line
2.17.1
Quoted 7 lines · Pierre Morel
We want the tests to automatically work with or without protected virtualisation.
To do this we need to share the I/O memory with the host.Let's replace all static allocations with dynamic allocations to clearly separate shared and private memory.
Quoted 6 lines
Signed-off-by Pierre Morel <[email protected]>--- lib/s390x/css.h | 3 +-- lib/s390x/css_lib.c | 28 ++++++++-------------------- s390x/css.c | 43 +++++++++++++++++++++++++++++++------------ 3 files changed, 40 insertions(+), 34 deletions(-)
Quoted 8 lines · Thomas Huth
Quoted 7 lines · Pierre Morel
We want the tests to automatically work with or without protected virtualisation.
To do this we need to share the I/O memory with the host.Let's replace all static allocations with dynamic allocations to clearly separate shared and private memory.
Quoted 9 lines
Quoted 6 lines
Signed-off-by Pierre Morel <[email protected]>---
lib/s390x/css.h | 3 +--
lib/s390x/css_lib.c| 28 ++++++++-------------------- s390x/css.c | 43 +++++++++++++++++++++++++++++++------------3 files changed, 40 insertions(+), 34 deletions(-)Reviewed-by Thomas Huth <[email protected]>
Thanks,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Quoted 8 lines · Pierre Morel
We want the tests to automatically work with or without protected virtualisation.
To do this we need to share the I/O memory with the host.Let's replace all static allocations with dynamic allocations to clearly separate shared and private memory.
Signed-off-by Pierre Morel <[email protected]>
Quoted 172 lines
--- lib/s390x/css.h | 3 +-- lib/s390x/css_lib.c | 28 ++++++++-------------------- s390x/css.c | 43 +++++++++++++++++++++++++++++++------------ 3 files changed, 40 insertions(+), 34 deletions(-)lib/s390x/css.h +1
-2@@ -283,8 +283,7 @@ int css_enable(int schid, int isc);/* Library functions */ int start_ccw1_chain (unsigned int sid,struct ccw1 *ccw); -int start_single_ccw (unsigned int sid,int code,void *data,int count, -unsigned char flags); +struct ccw1 *ccw_alloc (int code,void *data,int count,unsigned char flags);void css_irq_io (void );int css_residual_count (unsigned int schid);lib/s390x/css_lib.c +8
-20@@ -18,6 +18,7 @@#include <asm/time.h> #include <asm/arch_def.h> +#include <malloc_io.h> #include <css.h> static struct schib schib;@@ -202,33 +203,20 @@ int start_ccw1_chain(unsigned int sid, struct ccw1 *ccw)return ssch (sid, &orb); } -/* -* In the future, we want to implement support for CCW chains; -* for that, we will need to work with ccw1 pointers. -*/ -static struct ccw1 unique_ccw; - -int start_single_ccw (unsigned int sid,int code,void *data,int count, -unsigned char flags) +struct ccw1 *ccw_alloc (int code,void *data,int count,unsigned char flags) { -int cc; -struct ccw1 *ccw = &unique_ccw; +struct ccw1 *ccw; + + ccw =alloc_io_pages (sizeof (*ccw),0 ); +if (!ccw) +return NULL ; -report_prefix_push ("start_subchannel" ); -/* Build the CCW chain with a single CCW */ ccw->code = code; ccw->flags = flags; ccw->count = count; ccw->data_address = (int )(unsigned long )data; - cc =start_ccw1_chain (sid, ccw); -if (cc) { -report (0 ,"cc = %d" , cc); -report_prefix_pop (); -return cc; - } -report_prefix_pop (); -return 0 ; +return ccw; }/* wait_and_check_io_completion: s390x/css.c +31
-12@@ -17,13 +17,15 @@#include <interrupt.h> #include <asm/arch_def.h> +#include <malloc_io.h> #include <css.h> +#include <asm/barrier.h> #define DEFAULT_CU_TYPE 0x3832/* virtio-ccw */ static unsigned long cu_type =DEFAULT_CU_TYPE ;static int test_device_sid; -static struct senseid senseid; +static struct senseid *senseid;static void test_enumerate (void ) {@@ -57,6 +59,7 @@ static void test_enable(void)*/ static void test_sense (void ) { +struct ccw1 *ccw;int ret;int len;@@ -80,11 +83,23 @@ static void test_sense(void) lowcore_ptr->io_int_param =0 ; -memset (&senseid,0 ,sizeof (senseid)); - ret =start_single_ccw (test_device_sid,CCW_CMD_SENSE_ID , - &senseid,sizeof (senseid),CCW_F_SLI ); -if (ret) + senseid =alloc_io_pages (sizeof (*senseid),0 ); +if (!senseid) { +report (0 ,"Allocation of senseid" ); + goto error_senseid; + } + + ccw =ccw_alloc (CCW_CMD_SENSE_ID , senseid,sizeof (*senseid),CCW_F_SLI ); +if (!ccw) { +report (0 ,"Allocation of CCW" ); + goto error_ccw; + } + + ret =start_ccw1_chain (test_device_sid, ccw); +if (ret) { +report (0 ,"Starting CCW chain" ); goto error; + }if (wait_and_check_io_completion (test_device_sid) <0 ) goto error;@@ -97,7 +112,7 @@ static void test_sense(void)if (ret <0 ) {report_info ("no valid residual count" ); }else if (ret !=0 ) { - len =sizeof (senseid) - ret; + len =sizeof (*senseid) - ret;if (ret && len <CSS_SENSEID_COMMON_LEN ) {report (0 ,"transferred a too short length: %d" , ret); goto error;@@ -105,21 +120,25 @@ static void test_sense(void)report_info ("transferred a shorter length: %d" , len); } -if (senseid.reserved !=0xff ) { -report (0 ,"transferred garbage: 0x%02x" , senseid.reserved); +if (senseid->reserved !=0xff ) { +report (0 ,"transferred garbage: 0x%02x" , senseid->reserved); goto error; }report_prefix_pop ();report_info ("reserved 0x%02x cu_type 0x%04x cu_model 0x%02x dev_type 0x%04x dev_model 0x%02x" , - senseid.reserved, senseid.cu_type, senseid.cu_model, - senseid.dev_type, senseid.dev_model); + senseid->reserved, senseid->cu_type, senseid->cu_model, + senseid->dev_type, senseid->dev_model); -report (senseid.cu_type == cu_type,"cu_type expected 0x%04x got 0x%04x" , - (uint16_t ) cu_type, senseid.cu_type); +report (senseid->cu_type == cu_type,"cu_type expected 0x%04x got 0x%04x" , + (uint16_t )cu_type, senseid->cu_type); error: +free_io_pages (ccw,sizeof (*ccw)); +error_ccw: +free_io_pages (senseid,sizeof (*senseid)); +error_senseid:unregister_io_int_func (css_irq_io); }
Quoted 11 lines · Janosch Frank
Quoted 8 lines · Pierre Morel
We want the tests to automatically work with or without protected virtualisation.
To do this we need to share the I/O memory with the host.Let's replace all static allocations with dynamic allocations to clearly separate shared and private memory.
Signed-off-by Pierre Morel <[email protected]>Acked-by Janosch Frank <[email protected]>
Thanks,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Quoted 7 lines · On Thu, 21 Jan 2021 10:13:12 +0100 Pierre Morel <[email protected]> wrote:
We want the tests to automatically work with or without protected virtualisation.
To do this we need to share the I/O memory with the host.Let's replace all static allocations with dynamic allocations to clearly separate shared and private memory.
Quoted 7 lines
Signed-off-by Pierre Morel <[email protected]>--- lib/s390x/css.h | 3 +-- lib/s390x/css_lib.c | 28 ++++++++-------------------- s390x/css.c | 43 +++++++++++++++++++++++++++++++------------ 3 files changed, 40 insertions(+), 34 deletions(-)
Quoted 18 lines · Cornelia Huck
Quoted 7 lines · On Thu, 21 Jan 2021 10:13:12 +0100 Pierre Morel <[email protected]> wrote:
We want the tests to automatically work with or without protected virtualisation.
To do this we need to share the I/O memory with the host.Let's replace all static allocations with dynamic allocations to clearly separate shared and private memory.
Quoted 7 lines
Signed-off-by Pierre Morel <[email protected]>--- lib/s390x/css.h | 3 +-- lib/s390x/css_lib.c | 28 ++++++++-------------------- s390x/css.c | 43 +++++++++++++++++++++++++++++++------------ 3 files changed, 40 insertions(+), 34 deletions(-)
Quoted 2 lines
Reviewed-by Cornelia Huck <[email protected]>
Thanks,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen