From: Laurent Vivier <laurent@vivier.eu>
To: "Cortland Tölva" <cst@tolva.net>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v3 3/3] linux-user: Implement special usbfs ioctls.
Date: Thu, 18 Oct 2018 20:48:24 +0200 [thread overview]
Message-ID: <ab7987e7-0cf9-7bde-12d3-52dba3b16713@vivier.eu> (raw)
In-Reply-To: <20181008163521.17341-4-cst@tolva.net>
Le 08/10/2018 à 18:35, Cortland Tölva a écrit :
> Userspace submits a USB Request Buffer to the kernel, optionally
> discards it, and finally reaps the URB. Thunk buffers from target
> to host and back.
>
> Tested by running an i386 scanner driver on ARMv7 and by running
> the PowerPC lsusb utility on x86_64. The discardurb ioctl is
> not exercised in these tests.
>
> Signed-off-by: Cortland Tölva <cst@tolva.net>
> ---
> There are two alternatives for the strategy of holding lock_user on
> memory from submit until reap. v3 of this series tries to determine
> the access permissions for user memory from endpoint direction, but
> the logic for this is complex. The first alternative is to request
> write access. If that fails, request read access. If that fails, try
> to submit the ioctl with no buffer - perhaps the user code filled in
> fields the kernel will ignore. The second alternative is to read user
> memory into an allocated buffer, pass it to the kernel, and write back
> to target memory only if the kernel indicates that writes occurred.
>
> Changes from v1:
> improve pointer cast to int compatibility
> remove unimplemented types for usb streams
> struct definitions moved to this patch where possible
>
> Changes from v2:
> organize urb thunk metadata in a struct
> hold lock_user from submit until discard
> fixes for 64-bit hosts
>
> linux-user/ioctls.h | 8 ++
> linux-user/syscall.c | 177 +++++++++++++++++++++++++++++++++++++++++++++
> linux-user/syscall_defs.h | 4 +
> linux-user/syscall_types.h | 20 +++++
> 4 files changed, 209 insertions(+)
>
> diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
> index 92f6177f1d..ae8951625f 100644
...
> index 2641260186..9b7ea96cfb 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -96,6 +96,7 @@
> #include <linux/fb.h>
> #if defined(CONFIG_USBFS)
> #include <linux/usbdevice_fs.h>
> +#include <linux/usb/ch9.h>
> #endif
> #include <linux/vt.h>
> #include <linux/dm-ioctl.h>
> @@ -4199,6 +4200,182 @@ static abi_long do_ioctl_ifconf(const IOCTLEntry *ie, uint8_t *buf_temp,
> return ret;
> }
>
> +#if defined(CONFIG_USBFS)
> +#if HOST_LONG_BITS > 64
> +#error USBDEVFS thunks do not support >64 bit hosts yet.
> +#endif
> +struct live_urb {
> + uint64_t target_urb_adr;
> + uint64_t target_buf_adr;
> + char *target_buf_ptr;
> + struct usbdevfs_urb host_urb;
> +};
> +
> +static GHashTable *usbdevfs_urb_hashtable(void)
> +{
> + static GHashTable *urb_hashtable;
> +
> + if (!urb_hashtable) {
> + urb_hashtable = g_hash_table_new(g_int64_hash, g_int64_equal);
> + }
> + return urb_hashtable;
> +}
> +
> +static void urb_hashtable_insert(struct live_urb *urb)
> +{
> + GHashTable *urb_hashtable = usbdevfs_urb_hashtable();
> + g_hash_table_insert(urb_hashtable, urb, urb);
Here the key of the hashtable seems to be the pointer to the host live_urb.
> +}
> +
> +static struct live_urb *urb_hashtable_lookup(uint64_t target_urb_adr)
> +{
> + GHashTable *urb_hashtable = usbdevfs_urb_hashtable();
> + return g_hash_table_lookup(urb_hashtable, &target_urb_adr);
And here the key is the pointer to the target_urb_adr
So I think urb_hashtable_insert() should be:
g_hash_table_insert(urb_hashtable, urb->target_urb_adr, urb);
and urb_hashtable_lookup() should be:
return g_hash_table_lookup(urb_hashtable, target_urb_adr);
...
Did I miss something?
Thanks,
Laurent
next prev parent reply other threads:[~2018-10-18 18:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-08 16:35 [Qemu-devel] [PATCH v3 0/3] Linux usermode emulation user mode USB driver support Cortland Tölva
2018-10-08 16:35 ` [Qemu-devel] [PATCH v3 1/3] linux-user: Check for Linux USBFS in configure Cortland Tölva
2018-10-08 16:35 ` [Qemu-devel] [PATCH v3 2/3] linux-user: Define ordinary usbfs ioctls Cortland Tölva
2018-10-12 19:07 ` Laurent Vivier
2018-10-08 16:35 ` [Qemu-devel] [PATCH v3 3/3] linux-user: Implement special " Cortland Tölva
2018-10-18 16:42 ` Cortland Setlow Tölva
2018-10-18 18:15 ` Laurent Vivier
2018-10-18 18:48 ` Laurent Vivier [this message]
2018-10-19 2:16 ` Cortland Setlow Tölva
2018-10-19 7:13 ` Laurent Vivier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ab7987e7-0cf9-7bde-12d3-52dba3b16713@vivier.eu \
--to=laurent@vivier.eu \
--cc=cst@tolva.net \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).