Re: [PATCH v3 4/6] ALSA: xen-front: Implement handling of shared buffers
On 05/21/2018 11:26 PM, Takashi Iwai wrote: On Thu, 17 May 2018 08:26:16 +0200, Takashi Iwai wrote: On Tue, 15 May 2018 08:02:08 +0200, Oleksandr Andrushchenko wrote: On 05/15/2018 09:01 AM, Takashi Iwai wrote: On Tue, 15 May 2018 07:46:38 +0200, Oleksandr Andrushchenko wrote: On 05/14/2018 11:28 PM, Takashi Iwai wrote: On Mon, 14 May 2018 08:27:40 +0200, Oleksandr Andrushchenko wrote: --- /dev/null +++ b/sound/xen/xen_snd_front_shbuf.c @@ -0,0 +1,193 @@ +// SPDX-License-Identifier: GPL-2.0 OR MIT + +/* + * Xen para-virtual sound device + * + * Copyright (C) 2016-2018 EPAM Systems Inc. + * + * Author: Oleksandr Andrushchenko + */ + +#include +#include + +#include "xen_snd_front_shbuf.h" Hm, with the local build test, I get the following error: CC [M] sound/xen/xen_snd_front_shbuf.o In file included from sound/xen/xen_snd_front_shbuf.c:11:0: ./include/xen/xen.h:18:8: error: unknown type name ‘bool’ extern bool xen_pvh; ^~~~ In file included from ./include/xen/interface/xen.h:30:0, from ./include/xen/xen.h:29, from sound/xen/xen_snd_front_shbuf.c:11: ./arch/x86/include/asm/xen/interface.h:92:21: error: unknown type name ‘uint64_t’ DEFINE_GUEST_HANDLE(uint64_t); ^ Adding #include fixed the issue. Did you really test your patches with the latest Linus tree? My bad, it does build for ARM (which is my target), but also does need "#include " for x86 which I didn't build this time. Sorry about that. Do you want me to resend this single patch or you can make the change while applying? Yes, it's fine. Thank you FWIW, the patches are in topic/xen branch in sound.git tree, and I'll keep boiling for a while to see if any issues are caught by 0day bot. ... and now the topic/xen branch got merged to for-next, targeted for 4.18. Thanks for your patient works! Takashi Great news, thank you, Oleksandr
Re: [PATCH v3 4/6] ALSA: xen-front: Implement handling of shared buffers
On Thu, 17 May 2018 08:26:16 +0200, Takashi Iwai wrote: > > On Tue, 15 May 2018 08:02:08 +0200, > Oleksandr Andrushchenko wrote: > > > > On 05/15/2018 09:01 AM, Takashi Iwai wrote: > > > On Tue, 15 May 2018 07:46:38 +0200, > > > Oleksandr Andrushchenko wrote: > > >> On 05/14/2018 11:28 PM, Takashi Iwai wrote: > > >>> On Mon, 14 May 2018 08:27:40 +0200, > > >>> Oleksandr Andrushchenko wrote: > > --- /dev/null > > +++ b/sound/xen/xen_snd_front_shbuf.c > > @@ -0,0 +1,193 @@ > > +// SPDX-License-Identifier: GPL-2.0 OR MIT > > + > > +/* > > + * Xen para-virtual sound device > > + * > > + * Copyright (C) 2016-2018 EPAM Systems Inc. > > + * > > + * Author: Oleksandr Andrushchenko > > + */ > > + > > +#include > > +#include > > + > > +#include "xen_snd_front_shbuf.h" > > >>> Hm, with the local build test, I get the following error: > > >>> > > >>> CC [M] sound/xen/xen_snd_front_shbuf.o > > >>> In file included from sound/xen/xen_snd_front_shbuf.c:11:0: > > >>> ./include/xen/xen.h:18:8: error: unknown type name ‘bool’ > > >>> extern bool xen_pvh; > > >>> ^~~~ > > >>> In file included from ./include/xen/interface/xen.h:30:0, > > >>> from ./include/xen/xen.h:29, > > >>> from sound/xen/xen_snd_front_shbuf.c:11: > > >>> ./arch/x86/include/asm/xen/interface.h:92:21: error: unknown type > > >>> name ‘uint64_t’ > > >>> DEFINE_GUEST_HANDLE(uint64_t); > > >>> ^ > > >>> > > >>> Adding #include fixed the issue. > > >>> > > >>> Did you really test your patches with the latest Linus tree? > > >> My bad, it does build for ARM (which is my target), but also does > > >> need "#include " for x86 which I didn't build this time. > > >> Sorry about that. > > >> > > >> Do you want me to resend this single patch or you can make the change > > >> while applying? > > > Yes, it's fine. > > Thank you > > FWIW, the patches are in topic/xen branch in sound.git tree, and I'll > keep boiling for a while to see if any issues are caught by 0day bot. ... and now the topic/xen branch got merged to for-next, targeted for 4.18. Thanks for your patient works! Takashi
Re: [PATCH v3 4/6] ALSA: xen-front: Implement handling of shared buffers
On 05/17/2018 09:26 AM, Takashi Iwai wrote: On Tue, 15 May 2018 08:02:08 +0200, Oleksandr Andrushchenko wrote: On 05/15/2018 09:01 AM, Takashi Iwai wrote: On Tue, 15 May 2018 07:46:38 +0200, Oleksandr Andrushchenko wrote: On 05/14/2018 11:28 PM, Takashi Iwai wrote: On Mon, 14 May 2018 08:27:40 +0200, Oleksandr Andrushchenko wrote: --- /dev/null +++ b/sound/xen/xen_snd_front_shbuf.c @@ -0,0 +1,193 @@ +// SPDX-License-Identifier: GPL-2.0 OR MIT + +/* + * Xen para-virtual sound device + * + * Copyright (C) 2016-2018 EPAM Systems Inc. + * + * Author: Oleksandr Andrushchenko + */ + +#include +#include + +#include "xen_snd_front_shbuf.h" Hm, with the local build test, I get the following error: CC [M] sound/xen/xen_snd_front_shbuf.o In file included from sound/xen/xen_snd_front_shbuf.c:11:0: ./include/xen/xen.h:18:8: error: unknown type name ‘bool’ extern bool xen_pvh; ^~~~ In file included from ./include/xen/interface/xen.h:30:0, from ./include/xen/xen.h:29, from sound/xen/xen_snd_front_shbuf.c:11: ./arch/x86/include/asm/xen/interface.h:92:21: error: unknown type name ‘uint64_t’ DEFINE_GUEST_HANDLE(uint64_t); ^ Adding #include fixed the issue. Did you really test your patches with the latest Linus tree? My bad, it does build for ARM (which is my target), but also does need "#include " for x86 which I didn't build this time. Sorry about that. Do you want me to resend this single patch or you can make the change while applying? Yes, it's fine. Thank you FWIW, the patches are in topic/xen branch in sound.git tree, and I'll keep boiling for a while to see if any issues are caught by 0day bot. Thank you, hope everything goes well Takashi Thank you, Oleksandr
Re: [PATCH v3 4/6] ALSA: xen-front: Implement handling of shared buffers
On Tue, 15 May 2018 08:02:08 +0200, Oleksandr Andrushchenko wrote: > > On 05/15/2018 09:01 AM, Takashi Iwai wrote: > > On Tue, 15 May 2018 07:46:38 +0200, > > Oleksandr Andrushchenko wrote: > >> On 05/14/2018 11:28 PM, Takashi Iwai wrote: > >>> On Mon, 14 May 2018 08:27:40 +0200, > >>> Oleksandr Andrushchenko wrote: > --- /dev/null > +++ b/sound/xen/xen_snd_front_shbuf.c > @@ -0,0 +1,193 @@ > +// SPDX-License-Identifier: GPL-2.0 OR MIT > + > +/* > + * Xen para-virtual sound device > + * > + * Copyright (C) 2016-2018 EPAM Systems Inc. > + * > + * Author: Oleksandr Andrushchenko > + */ > + > +#include > +#include > + > +#include "xen_snd_front_shbuf.h" > >>> Hm, with the local build test, I get the following error: > >>> > >>> CC [M] sound/xen/xen_snd_front_shbuf.o > >>> In file included from sound/xen/xen_snd_front_shbuf.c:11:0: > >>> ./include/xen/xen.h:18:8: error: unknown type name ‘bool’ > >>> extern bool xen_pvh; > >>> ^~~~ > >>> In file included from ./include/xen/interface/xen.h:30:0, > >>> from ./include/xen/xen.h:29, > >>> from sound/xen/xen_snd_front_shbuf.c:11: > >>> ./arch/x86/include/asm/xen/interface.h:92:21: error: unknown type > >>> name ‘uint64_t’ > >>> DEFINE_GUEST_HANDLE(uint64_t); > >>> ^ > >>> > >>> Adding #include fixed the issue. > >>> > >>> Did you really test your patches with the latest Linus tree? > >> My bad, it does build for ARM (which is my target), but also does > >> need "#include " for x86 which I didn't build this time. > >> Sorry about that. > >> > >> Do you want me to resend this single patch or you can make the change > >> while applying? > > Yes, it's fine. > Thank you FWIW, the patches are in topic/xen branch in sound.git tree, and I'll keep boiling for a while to see if any issues are caught by 0day bot. Takashi
Re: [PATCH v3 4/6] ALSA: xen-front: Implement handling of shared buffers
On 05/15/2018 09:01 AM, Takashi Iwai wrote: On Tue, 15 May 2018 07:46:38 +0200, Oleksandr Andrushchenko wrote: On 05/14/2018 11:28 PM, Takashi Iwai wrote: On Mon, 14 May 2018 08:27:40 +0200, Oleksandr Andrushchenko wrote: --- /dev/null +++ b/sound/xen/xen_snd_front_shbuf.c @@ -0,0 +1,193 @@ +// SPDX-License-Identifier: GPL-2.0 OR MIT + +/* + * Xen para-virtual sound device + * + * Copyright (C) 2016-2018 EPAM Systems Inc. + * + * Author: Oleksandr Andrushchenko + */ + +#include +#include + +#include "xen_snd_front_shbuf.h" Hm, with the local build test, I get the following error: CC [M] sound/xen/xen_snd_front_shbuf.o In file included from sound/xen/xen_snd_front_shbuf.c:11:0: ./include/xen/xen.h:18:8: error: unknown type name ‘bool’ extern bool xen_pvh; ^~~~ In file included from ./include/xen/interface/xen.h:30:0, from ./include/xen/xen.h:29, from sound/xen/xen_snd_front_shbuf.c:11: ./arch/x86/include/asm/xen/interface.h:92:21: error: unknown type name ‘uint64_t’ DEFINE_GUEST_HANDLE(uint64_t); ^ Adding #include fixed the issue. Did you really test your patches with the latest Linus tree? My bad, it does build for ARM (which is my target), but also does need "#include " for x86 which I didn't build this time. Sorry about that. Do you want me to resend this single patch or you can make the change while applying? Yes, it's fine. Thank you thanks, Takashi
Re: [PATCH v3 4/6] ALSA: xen-front: Implement handling of shared buffers
On Tue, 15 May 2018 07:46:38 +0200, Oleksandr Andrushchenko wrote: > > On 05/14/2018 11:28 PM, Takashi Iwai wrote: > > On Mon, 14 May 2018 08:27:40 +0200, > > Oleksandr Andrushchenko wrote: > >> --- /dev/null > >> +++ b/sound/xen/xen_snd_front_shbuf.c > >> @@ -0,0 +1,193 @@ > >> +// SPDX-License-Identifier: GPL-2.0 OR MIT > >> + > >> +/* > >> + * Xen para-virtual sound device > >> + * > >> + * Copyright (C) 2016-2018 EPAM Systems Inc. > >> + * > >> + * Author: Oleksandr Andrushchenko > >> + */ > >> + > >> +#include > >> +#include > >> + > >> +#include "xen_snd_front_shbuf.h" > > Hm, with the local build test, I get the following error: > > > >CC [M] sound/xen/xen_snd_front_shbuf.o > >In file included from sound/xen/xen_snd_front_shbuf.c:11:0: > >./include/xen/xen.h:18:8: error: unknown type name ‘bool’ > > extern bool xen_pvh; > > ^~~~ > > In file included from ./include/xen/interface/xen.h:30:0, > > from ./include/xen/xen.h:29, > > from sound/xen/xen_snd_front_shbuf.c:11: > >./arch/x86/include/asm/xen/interface.h:92:21: error: unknown type name > > ‘uint64_t’ > > DEFINE_GUEST_HANDLE(uint64_t); > > ^ > > > > Adding #include fixed the issue. > > > > Did you really test your patches with the latest Linus tree? > My bad, it does build for ARM (which is my target), but also does > need "#include " for x86 which I didn't build this time. > Sorry about that. > > Do you want me to resend this single patch or you can make the change > while applying? Yes, it's fine. thanks, Takashi
Re: [PATCH v3 4/6] ALSA: xen-front: Implement handling of shared buffers
On 05/14/2018 11:28 PM, Takashi Iwai wrote: On Mon, 14 May 2018 08:27:40 +0200, Oleksandr Andrushchenko wrote: --- /dev/null +++ b/sound/xen/xen_snd_front_shbuf.c @@ -0,0 +1,193 @@ +// SPDX-License-Identifier: GPL-2.0 OR MIT + +/* + * Xen para-virtual sound device + * + * Copyright (C) 2016-2018 EPAM Systems Inc. + * + * Author: Oleksandr Andrushchenko + */ + +#include +#include + +#include "xen_snd_front_shbuf.h" Hm, with the local build test, I get the following error: CC [M] sound/xen/xen_snd_front_shbuf.o In file included from sound/xen/xen_snd_front_shbuf.c:11:0: ./include/xen/xen.h:18:8: error: unknown type name ‘bool’ extern bool xen_pvh; ^~~~ In file included from ./include/xen/interface/xen.h:30:0, from ./include/xen/xen.h:29, from sound/xen/xen_snd_front_shbuf.c:11: ./arch/x86/include/asm/xen/interface.h:92:21: error: unknown type name ‘uint64_t’ DEFINE_GUEST_HANDLE(uint64_t); ^ Adding #include fixed the issue. Did you really test your patches with the latest Linus tree? My bad, it does build for ARM (which is my target), but also does need "#include " for x86 which I didn't build this time. Sorry about that. Do you want me to resend this single patch or you can make the change while applying? thanks, Takashi Thank you, Oleksandr
Re: [PATCH v3 4/6] ALSA: xen-front: Implement handling of shared buffers
On Mon, 14 May 2018 08:27:40 +0200, Oleksandr Andrushchenko wrote: > --- /dev/null > +++ b/sound/xen/xen_snd_front_shbuf.c > @@ -0,0 +1,193 @@ > +// SPDX-License-Identifier: GPL-2.0 OR MIT > + > +/* > + * Xen para-virtual sound device > + * > + * Copyright (C) 2016-2018 EPAM Systems Inc. > + * > + * Author: Oleksandr Andrushchenko > + */ > + > +#include > +#include > + > +#include "xen_snd_front_shbuf.h" Hm, with the local build test, I get the following error: CC [M] sound/xen/xen_snd_front_shbuf.o In file included from sound/xen/xen_snd_front_shbuf.c:11:0: ./include/xen/xen.h:18:8: error: unknown type name ‘bool’ extern bool xen_pvh; ^~~~ In file included from ./include/xen/interface/xen.h:30:0, from ./include/xen/xen.h:29, from sound/xen/xen_snd_front_shbuf.c:11: ./arch/x86/include/asm/xen/interface.h:92:21: error: unknown type name ‘uint64_t’ DEFINE_GUEST_HANDLE(uint64_t); ^ Adding #include fixed the issue. Did you really test your patches with the latest Linus tree? thanks, Takashi
[PATCH v3 4/6] ALSA: xen-front: Implement handling of shared buffers
From: Oleksandr Andrushchenko Implement shared buffer handling according to the para-virtualized sound device protocol at xen/interface/io/sndif.h: - manage buffer memory - handle granted references - handle page directories Signed-off-by: Oleksandr Andrushchenko --- sound/xen/Makefile | 3 +- sound/xen/xen_snd_front.c | 8 ++ sound/xen/xen_snd_front_shbuf.c | 193 sound/xen/xen_snd_front_shbuf.h | 36 ++ 4 files changed, 239 insertions(+), 1 deletion(-) create mode 100644 sound/xen/xen_snd_front_shbuf.c create mode 100644 sound/xen/xen_snd_front_shbuf.h diff --git a/sound/xen/Makefile b/sound/xen/Makefile index 03c669984000..f028bc30af5d 100644 --- a/sound/xen/Makefile +++ b/sound/xen/Makefile @@ -2,6 +2,7 @@ snd_xen_front-objs := xen_snd_front.o \ xen_snd_front_cfg.o \ - xen_snd_front_evtchnl.o + xen_snd_front_evtchnl.o \ + xen_snd_front_shbuf.o obj-$(CONFIG_SND_XEN_FRONTEND) += snd_xen_front.o diff --git a/sound/xen/xen_snd_front.c b/sound/xen/xen_snd_front.c index 277214d4fd0a..cdf66ea516c4 100644 --- a/sound/xen/xen_snd_front.c +++ b/sound/xen/xen_snd_front.c @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -191,6 +192,13 @@ static int __init xen_drv_init(void) if (!xen_has_pv_devices()) return -ENODEV; + /* At the moment we only support case with XEN_PAGE_SIZE == PAGE_SIZE */ + if (XEN_PAGE_SIZE != PAGE_SIZE) { + pr_err(XENSND_DRIVER_NAME ": different kernel and Xen page sizes are not supported: XEN_PAGE_SIZE (%lu) != PAGE_SIZE (%lu)\n", + XEN_PAGE_SIZE, PAGE_SIZE); + return -ENODEV; + } + pr_info("Initialising Xen " XENSND_DRIVER_NAME " frontend driver\n"); return xenbus_register_frontend(&xen_driver); } diff --git a/sound/xen/xen_snd_front_shbuf.c b/sound/xen/xen_snd_front_shbuf.c new file mode 100644 index ..6845dbc7fdf5 --- /dev/null +++ b/sound/xen/xen_snd_front_shbuf.c @@ -0,0 +1,193 @@ +// SPDX-License-Identifier: GPL-2.0 OR MIT + +/* + * Xen para-virtual sound device + * + * Copyright (C) 2016-2018 EPAM Systems Inc. + * + * Author: Oleksandr Andrushchenko + */ + +#include +#include + +#include "xen_snd_front_shbuf.h" + +grant_ref_t xen_snd_front_shbuf_get_dir_start(struct xen_snd_front_shbuf *buf) +{ + if (!buf->grefs) + return GRANT_INVALID_REF; + + return buf->grefs[0]; +} + +void xen_snd_front_shbuf_clear(struct xen_snd_front_shbuf *buf) +{ + memset(buf, 0, sizeof(*buf)); +} + +void xen_snd_front_shbuf_free(struct xen_snd_front_shbuf *buf) +{ + int i; + + if (buf->grefs) { + for (i = 0; i < buf->num_grefs; i++) + if (buf->grefs[i] != GRANT_INVALID_REF) + gnttab_end_foreign_access(buf->grefs[i], + 0, 0UL); + kfree(buf->grefs); + } + kfree(buf->directory); + free_pages_exact(buf->buffer, buf->buffer_sz); + xen_snd_front_shbuf_clear(buf); +} + +/* + * number of grant references a page can hold with respect to the + * xensnd_page_directory header + */ +#define XENSND_NUM_GREFS_PER_PAGE ((XEN_PAGE_SIZE - \ + offsetof(struct xensnd_page_directory, gref)) / \ + sizeof(grant_ref_t)) + +static void fill_page_dir(struct xen_snd_front_shbuf *buf, + int num_pages_dir) +{ + struct xensnd_page_directory *page_dir; + unsigned char *ptr; + int i, cur_gref, grefs_left, to_copy; + + ptr = buf->directory; + grefs_left = buf->num_grefs - num_pages_dir; + /* +* skip grant references at the beginning, they are for pages granted +* for the page directory itself +*/ + cur_gref = num_pages_dir; + for (i = 0; i < num_pages_dir; i++) { + page_dir = (struct xensnd_page_directory *)ptr; + if (grefs_left <= XENSND_NUM_GREFS_PER_PAGE) { + to_copy = grefs_left; + page_dir->gref_dir_next_page = GRANT_INVALID_REF; + } else { + to_copy = XENSND_NUM_GREFS_PER_PAGE; + page_dir->gref_dir_next_page = buf->grefs[i + 1]; + } + + memcpy(&page_dir->gref, &buf->grefs[cur_gref], + to_copy * sizeof(grant_ref_t)); + + ptr += XEN_PAGE_SIZE; + grefs_left -= to_copy; + cur_gref += to_copy; + } +} + +static int grant_references(struct xenbus_device *xb_dev, + struct xen_snd_front_shbuf *buf, + int num_pages_dir, int num_pages_buffer, + int num_grefs) +{ + grant_ref_t priv_gref_head; +