2022-05-09 07:16:50

by Jürgen Groß

[permalink] [raw]
Subject: [PATCH v3 00/21] xen: simplify frontend side ring setup

Many Xen PV frontends share similar code for setting up a ring page
(allocating and granting access for the backend) and for tearing it
down.

Create new service functions doing all needed steps in one go.

This requires all frontends to use a common value for an invalid
grant reference in order to make the functions idempotent.

Changes in V3:
- new patches 1 and 2, comments addressed

Changes in V2:
- new patch 9 and related changes in patches 10-18

Juergen Gross (21):
xen: update grant_table.h
xen/grant-table: never put a reserved grant on the free list
xen/blkfront: switch blkfront to use INVALID_GRANT_REF
xen/netfront: switch netfront to use INVALID_GRANT_REF
xen/scsifront: remove unused GRANT_INVALID_REF definition
xen/usb: switch xen-hcd to use INVALID_GRANT_REF
xen/drm: switch xen_drm_front to use INVALID_GRANT_REF
xen/sound: switch xen_snd_front to use INVALID_GRANT_REF
xen/dmabuf: switch gntdev-dmabuf to use INVALID_GRANT_REF
xen/shbuf: switch xen-front-pgdir-shbuf to use INVALID_GRANT_REF
xen: update ring.h
xen/xenbus: add xenbus_setup_ring() service function
xen/blkfront: use xenbus_setup_ring() and xenbus_teardown_ring()
xen/netfront: use xenbus_setup_ring() and xenbus_teardown_ring()
xen/tpmfront: use xenbus_setup_ring() and xenbus_teardown_ring()
xen/drmfront: use xenbus_setup_ring() and xenbus_teardown_ring()
xen/pcifront: use xenbus_setup_ring() and xenbus_teardown_ring()
xen/scsifront: use xenbus_setup_ring() and xenbus_teardown_ring()
xen/usbfront: use xenbus_setup_ring() and xenbus_teardown_ring()
xen/sndfront: use xenbus_setup_ring() and xenbus_teardown_ring()
xen/xenbus: eliminate xenbus_grant_ring()

drivers/block/xen-blkfront.c | 57 +++----
drivers/char/tpm/xen-tpmfront.c | 18 +--
drivers/gpu/drm/xen/xen_drm_front.h | 9 --
drivers/gpu/drm/xen/xen_drm_front_evtchnl.c | 43 ++----
drivers/net/xen-netfront.c | 85 ++++-------
drivers/pci/xen-pcifront.c | 19 +--
drivers/scsi/xen-scsifront.c | 31 +---
drivers/usb/host/xen-hcd.c | 65 ++------
drivers/xen/gntdev-dmabuf.c | 13 +-
drivers/xen/grant-table.c | 12 +-
drivers/xen/xen-front-pgdir-shbuf.c | 18 +--
drivers/xen/xenbus/xenbus_client.c | 82 +++++++---
include/xen/grant_table.h | 2 -
include/xen/interface/grant_table.h | 161 ++++++++++++--------
include/xen/interface/io/ring.h | 19 ++-
include/xen/xenbus.h | 4 +-
sound/xen/xen_snd_front_evtchnl.c | 44 ++----
sound/xen/xen_snd_front_evtchnl.h | 9 --
18 files changed, 287 insertions(+), 404 deletions(-)

--
2.35.3



2022-05-09 07:21:35

by Jürgen Groß

[permalink] [raw]
Subject: [PATCH v3 13/21] xen/blkfront: use xenbus_setup_ring() and xenbus_teardown_ring()

Simplify blkfront's ring creation and removal via xenbus_setup_ring()
and xenbus_teardown_ring().

Signed-off-by: Juergen Gross <[email protected]>
---
drivers/block/xen-blkfront.c | 37 ++++++++----------------------------
1 file changed, 8 insertions(+), 29 deletions(-)

diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index 7f35e30e626a..bd7b34f29193 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -1280,15 +1280,8 @@ static void blkif_free_ring(struct blkfront_ring_info *rinfo)
flush_work(&rinfo->work);

/* Free resources associated with old device channel. */
- for (i = 0; i < info->nr_ring_pages; i++) {
- if (rinfo->ring_ref[i] != INVALID_GRANT_REF) {
- gnttab_end_foreign_access(rinfo->ring_ref[i], 0);
- rinfo->ring_ref[i] = INVALID_GRANT_REF;
- }
- }
- free_pages_exact(rinfo->ring.sring,
- info->nr_ring_pages * XEN_PAGE_SIZE);
- rinfo->ring.sring = NULL;
+ xenbus_teardown_ring((void **)&rinfo->ring.sring, info->nr_ring_pages,
+ rinfo->ring_ref);

if (rinfo->irq)
unbind_from_irqhandler(rinfo->irq, rinfo);
@@ -1679,30 +1672,16 @@ static int setup_blkring(struct xenbus_device *dev,
struct blkfront_ring_info *rinfo)
{
struct blkif_sring *sring;
- int err, i;
+ int err;
struct blkfront_info *info = rinfo->dev_info;
unsigned long ring_size = info->nr_ring_pages * XEN_PAGE_SIZE;
- grant_ref_t gref[XENBUS_MAX_RING_GRANTS];
-
- for (i = 0; i < info->nr_ring_pages; i++)
- rinfo->ring_ref[i] = INVALID_GRANT_REF;

- sring = alloc_pages_exact(ring_size, GFP_NOIO);
- if (!sring) {
- xenbus_dev_fatal(dev, -ENOMEM, "allocating shared ring");
- return -ENOMEM;
- }
- SHARED_RING_INIT(sring);
- FRONT_RING_INIT(&rinfo->ring, sring, ring_size);
-
- err = xenbus_grant_ring(dev, rinfo->ring.sring, info->nr_ring_pages, gref);
- if (err < 0) {
- free_pages_exact(sring, ring_size);
- rinfo->ring.sring = NULL;
+ err = xenbus_setup_ring(dev, GFP_NOIO, (void **)&sring,
+ info->nr_ring_pages, rinfo->ring_ref);
+ if (err)
goto fail;
- }
- for (i = 0; i < info->nr_ring_pages; i++)
- rinfo->ring_ref[i] = gref[i];
+
+ XEN_FRONT_RING_INIT(&rinfo->ring, sring, ring_size);

err = xenbus_alloc_evtchn(dev, &rinfo->evtchn);
if (err)
--
2.35.3


2022-05-09 09:18:41

by Boris Ostrovsky

[permalink] [raw]
Subject: Re: [PATCH v3 00/21] xen: simplify frontend side ring setup


On 5/5/22 4:16 AM, Juergen Gross wrote:
> Many Xen PV frontends share similar code for setting up a ring page
> (allocating and granting access for the backend) and for tearing it
> down.
>
> Create new service functions doing all needed steps in one go.
>
> This requires all frontends to use a common value for an invalid
> grant reference in order to make the functions idempotent.
>
> Changes in V3:
> - new patches 1 and 2, comments addressed
>
> Changes in V2:
> - new patch 9 and related changes in patches 10-18


For the patches that I was explicitly copied on:


Reviewed-by: Boris Ostrovsky <[email protected]>


2022-05-09 09:41:56

by Jürgen Groß

[permalink] [raw]
Subject: [PATCH v3 05/21] xen/scsifront: remove unused GRANT_INVALID_REF definition

GRANT_INVALID_REF isn't used in scsifront, so remove it.

Signed-off-by: Juergen Gross <[email protected]>
---
drivers/scsi/xen-scsifront.c | 3 ---
1 file changed, 3 deletions(-)

diff --git a/drivers/scsi/xen-scsifront.c b/drivers/scsi/xen-scsifront.c
index 56173beecbc6..4c55e479fc36 100644
--- a/drivers/scsi/xen-scsifront.c
+++ b/drivers/scsi/xen-scsifront.c
@@ -58,9 +58,6 @@

#include <asm/xen/hypervisor.h>

-
-#define GRANT_INVALID_REF 0
-
#define VSCSIFRONT_OP_ADD_LUN 1
#define VSCSIFRONT_OP_DEL_LUN 2
#define VSCSIFRONT_OP_READD_LUN 3
--
2.35.3


2022-05-09 11:33:22

by Jürgen Groß

[permalink] [raw]
Subject: [PATCH v3 06/21] xen/usb: switch xen-hcd to use INVALID_GRANT_REF

Instead of using a private macro for an invalid grant reference use
the common one.

Signed-off-by: Juergen Gross <[email protected]>
Acked-by: Greg Kroah-Hartman <[email protected]>
---
drivers/usb/host/xen-hcd.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/host/xen-hcd.c b/drivers/usb/host/xen-hcd.c
index 3e487baf8422..9cbc7c2dab02 100644
--- a/drivers/usb/host/xen-hcd.c
+++ b/drivers/usb/host/xen-hcd.c
@@ -87,8 +87,6 @@ struct xenhcd_info {
bool error;
};

-#define GRANT_INVALID_REF 0
-
#define XENHCD_RING_JIFFIES (HZ/200)
#define XENHCD_SCAN_JIFFIES 1

@@ -1100,17 +1098,17 @@ static void xenhcd_destroy_rings(struct xenhcd_info *info)
unbind_from_irqhandler(info->irq, info);
info->irq = 0;

- if (info->urb_ring_ref != GRANT_INVALID_REF) {
+ if (info->urb_ring_ref != INVALID_GRANT_REF) {
gnttab_end_foreign_access(info->urb_ring_ref,
(unsigned long)info->urb_ring.sring);
- info->urb_ring_ref = GRANT_INVALID_REF;
+ info->urb_ring_ref = INVALID_GRANT_REF;
}
info->urb_ring.sring = NULL;

- if (info->conn_ring_ref != GRANT_INVALID_REF) {
+ if (info->conn_ring_ref != INVALID_GRANT_REF) {
gnttab_end_foreign_access(info->conn_ring_ref,
(unsigned long)info->conn_ring.sring);
- info->conn_ring_ref = GRANT_INVALID_REF;
+ info->conn_ring_ref = INVALID_GRANT_REF;
}
info->conn_ring.sring = NULL;
}
@@ -1123,8 +1121,8 @@ static int xenhcd_setup_rings(struct xenbus_device *dev,
grant_ref_t gref;
int err;

- info->urb_ring_ref = GRANT_INVALID_REF;
- info->conn_ring_ref = GRANT_INVALID_REF;
+ info->urb_ring_ref = INVALID_GRANT_REF;
+ info->conn_ring_ref = INVALID_GRANT_REF;

urb_sring = (struct xenusb_urb_sring *)get_zeroed_page(
GFP_NOIO | __GFP_HIGH);
--
2.35.3


2022-05-09 13:34:05

by Oleksandr Tyshchenko

[permalink] [raw]
Subject: Re: [PATCH v3 00/21] xen: simplify frontend side ring setup


On 05.05.22 11:16, Juergen Gross wrote:

Hello Juergen.



> Many Xen PV frontends share similar code for setting up a ring page
> (allocating and granting access for the backend) and for tearing it
> down.
>
> Create new service functions doing all needed steps in one go.
>
> This requires all frontends to use a common value for an invalid
> grant reference in order to make the functions idempotent.
>
> Changes in V3:
> - new patches 1 and 2, comments addressed
>
> Changes in V2:
> - new patch 9 and related changes in patches 10-18
>
> Juergen Gross (21):
> xen: update grant_table.h
> xen/grant-table: never put a reserved grant on the free list
> xen/blkfront: switch blkfront to use INVALID_GRANT_REF
> xen/netfront: switch netfront to use INVALID_GRANT_REF
> xen/scsifront: remove unused GRANT_INVALID_REF definition
> xen/usb: switch xen-hcd to use INVALID_GRANT_REF
> xen/drm: switch xen_drm_front to use INVALID_GRANT_REF
> xen/sound: switch xen_snd_front to use INVALID_GRANT_REF
> xen/dmabuf: switch gntdev-dmabuf to use INVALID_GRANT_REF
> xen/shbuf: switch xen-front-pgdir-shbuf to use INVALID_GRANT_REF
> xen: update ring.h
> xen/xenbus: add xenbus_setup_ring() service function
> xen/blkfront: use xenbus_setup_ring() and xenbus_teardown_ring()
> xen/netfront: use xenbus_setup_ring() and xenbus_teardown_ring()
> xen/tpmfront: use xenbus_setup_ring() and xenbus_teardown_ring()
> xen/drmfront: use xenbus_setup_ring() and xenbus_teardown_ring()
> xen/pcifront: use xenbus_setup_ring() and xenbus_teardown_ring()
> xen/scsifront: use xenbus_setup_ring() and xenbus_teardown_ring()
> xen/usbfront: use xenbus_setup_ring() and xenbus_teardown_ring()
> xen/sndfront: use xenbus_setup_ring() and xenbus_teardown_ring()
> xen/xenbus: eliminate xenbus_grant_ring()


For the patches that touch PV display (#07, #16), PV sound (#08, #20)
and shared buffer framework used by both frontends (#10):

Reviewed-by: Oleksandr Tyshchenko <[email protected]>


Also I didn't see any issues with these frontends while testing on Arm64
based board.
So, you can also add:

[Arm64 only]
Tested-by: Oleksandr Tyshchenko <[email protected]>


Thanks!


>
> drivers/block/xen-blkfront.c | 57 +++----
> drivers/char/tpm/xen-tpmfront.c | 18 +--
> drivers/gpu/drm/xen/xen_drm_front.h | 9 --
> drivers/gpu/drm/xen/xen_drm_front_evtchnl.c | 43 ++----
> drivers/net/xen-netfront.c | 85 ++++-------
> drivers/pci/xen-pcifront.c | 19 +--
> drivers/scsi/xen-scsifront.c | 31 +---
> drivers/usb/host/xen-hcd.c | 65 ++------
> drivers/xen/gntdev-dmabuf.c | 13 +-
> drivers/xen/grant-table.c | 12 +-
> drivers/xen/xen-front-pgdir-shbuf.c | 18 +--
> drivers/xen/xenbus/xenbus_client.c | 82 +++++++---
> include/xen/grant_table.h | 2 -
> include/xen/interface/grant_table.h | 161 ++++++++++++--------
> include/xen/interface/io/ring.h | 19 ++-
> include/xen/xenbus.h | 4 +-
> sound/xen/xen_snd_front_evtchnl.c | 44 ++----
> sound/xen/xen_snd_front_evtchnl.h | 9 --
> 18 files changed, 287 insertions(+), 404 deletions(-)
>
--
Regards,

Oleksandr Tyshchenko