From: Lu Baolu <baolu.lu@linux.intel.com>
To: Mathias Nyman <mathias.nyman@linux.intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v7 05/10] usb: dbc: add bulk out and bulk in interfaces
Date: Fri, 19 Feb 2016 15:09:13 +0800 [thread overview]
Message-ID: <56C6BF99.9010409@linux.intel.com> (raw)
In-Reply-To: <56C5C7EF.1020503@linux.intel.com>
On 02/18/2016 09:32 PM, Mathias Nyman wrote:
> On 26.01.2016 14:58, Lu Baolu wrote:
>> This patch adds interfaces for bulk out and bulk in ops. These
>> interfaces could be used to implement early printk bootconsole
>> or hook to various system debuggers.
>>
>> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
>> ---
>> drivers/usb/early/xhci-dbc.c | 373 +++++++++++++++++++++++++++++++++++++++++++
>> include/linux/usb/xhci-dbc.h | 30 ++++
>> 2 files changed, 403 insertions(+)
>>
>
> ...
>
>> +
>> +/*
>> + * Check and dispatch events in event ring. It also checks status
>> + * of hardware. This function will be called from multiple threads.
>> + * An atomic lock is applied to protect the access of event ring.
>> + */
>> +static int xdbc_check_event(void)
>> +{
>> + /* event ring is under checking by other thread? */
>> + if (!test_bit(XDBC_ATOMIC_EVENT, &xdbcp->atomic_flags) &&
>> + !test_and_set_bit(XDBC_ATOMIC_EVENT,
>> + &xdbcp->atomic_flags))
>> + return 0;
>
> homemade trylock, can't the real ones be used?
>
>> +
>> + xdbc_handle_events();
>> +
>> + test_and_clear_bit(XDBC_ATOMIC_EVENT, &xdbcp->atomic_flags);
>> +
>> + return 0;
>> +}
>> +
>> +#define BULK_IN_COMPLETED(p) ((xdbcp->in_pending == (p)) && \
>> + xdbcp->in_complete)
>> +#define BULK_OUT_COMPLETED(p) ((xdbcp->out_pending == (p)) && \
>> + xdbcp->out_complete)
>> +
>
> ...
>
>> +}
>> +
>> +int xdbc_bulk_read(void *data, int size, int loops)
>> +{
>> + int ret;
>> +
>> + do {
>> + if (!test_bit(XDBC_ATOMIC_BULKIN, &xdbcp->atomic_flags) &&
>> + !test_and_set_bit(XDBC_ATOMIC_BULKIN,
>> + &xdbcp->atomic_flags))
>> + break;
>> + } while (1);
>
> homemeade spin_lock, can't the real one be used?
>
> If the xdbc_bulk_write() can be accessed from interrupt context (handler, soft, timer) it
> may deadlock
>
>> +
>> + ret = xdbc_bulk_transfer(data, size, loops, true);
>> +
>> + test_and_clear_bit(XDBC_ATOMIC_BULKIN, &xdbcp->atomic_flags);
>> +
>> + return ret;
>> +}
>> +
>> +int xdbc_bulk_write(const char *bytes, int size)
>> +{
>> + int ret;
>> +
>> + do {
>> + if (!test_bit(XDBC_ATOMIC_BULKOUT, &xdbcp->atomic_flags) &&
>> + !test_and_set_bit(XDBC_ATOMIC_BULKOUT,
>> + &xdbcp->atomic_flags))
>> + break;
>> + } while (1);
>
> Another homemeade spin_lock, can't the real one be used?
>
> same issue here, deadlock if accessible from interrupt context.
I will try to rework this spin_lock with the real one and keep avoiding deadlock in mind.
>
>
> Would it make sense to have only one spinlock, and start one separate thread for
> reading the event ring. The thread would, lock, handle pending events, unlock,
> then call shedule, in a loop. ehci early debug code has some variant of this.
Let me try to find this part of code.
>
> So the lock would be taken while events are being handled.
>
> The same lock would be used for bulk_read and bulk_write. Yes this would prevent read and
> write at the same time, and the read and writes need to be modified to not block until
> the reansfer is finished, just to write the TRBs on the ring, update ring pointers,
> and ring the doorbell.
>
> Or is all this impossibe due to the earlyness of the code?
It's not only due to earlyness of the code. But also, these read/write ops were designed to
be used by a debugger (for example kgdb) as well. Using the kernel provided interface
might make things simple, but what should happen when the debugger is used
to debug the kernel subsystem itself?
So, it seems that I should implement read/write ops depends on the use case. For this
time being, let's focus on the boot console case.
Some transfers take place when the thread/lock subsystem is not initialized yet.
But after thread/lock subsystem is able to be used, we are able to use the real one.
Let me wrapper them in functions. For the transfers taken place before the subsystem
initialization (that's single thread context, no worry about deadlock), it will use the
current methods (it might be possible to drop lock due the single thread context),
and after the subsystem being initialized, it will use those provided by the kernel.
>
> -Mathias
>
Very appreciated for your time.
Regards,
-Baolu
next prev parent reply other threads:[~2016-02-19 7:09 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-26 12:58 [PATCH v7 00/10] usb: early: add support for early printk through USB3 debug port Lu Baolu
2016-01-26 12:58 ` [PATCH v7 01/10] x86: fixmap: add permanent fixmap for xhci " Lu Baolu
2016-01-26 12:58 ` [PATCH v7 02/10] usb: dbc: probe and setup xhci debug capability Lu Baolu
2016-02-16 14:19 ` Mathias Nyman
2016-02-17 8:45 ` Lu Baolu
2016-01-26 12:58 ` [PATCH v7 03/10] usb: dbc: add support for Intel xHCI dbc quirk Lu Baolu
2016-01-26 12:58 ` [PATCH v7 04/10] usb: dbc: add debug buffer Lu Baolu
2016-02-18 11:43 ` Mathias Nyman
2016-02-19 6:35 ` Lu Baolu
2016-01-26 12:58 ` [PATCH v7 05/10] usb: dbc: add bulk out and bulk in interfaces Lu Baolu
2016-02-18 13:32 ` Mathias Nyman
2016-02-19 7:09 ` Lu Baolu [this message]
2016-01-26 12:58 ` [PATCH v7 06/10] usb: dbc: handle dbc-configured exit Lu Baolu
2016-01-26 12:58 ` [PATCH v7 07/10] usb: dbc: handle endpoint stall Lu Baolu
2016-03-02 12:58 ` Mathias Nyman
2016-03-02 12:58 ` Felipe Balbi
2016-03-03 6:12 ` Lu Baolu
2016-03-03 6:00 ` Lu Baolu
2016-01-26 12:58 ` [PATCH v7 08/10] x86: early_printk: add USB3 debug port earlyprintk support Lu Baolu
2016-01-26 12:58 ` [PATCH v7 09/10] usb: dbc: add handshake between debug target and host Lu Baolu
2016-01-26 12:58 ` [PATCH v7 10/10] usb: doc: add document for xHCI DbC driver Lu Baolu
2016-02-02 14:34 ` [PATCH v7 00/10] usb: early: add support for early printk through USB3 debug port Lu Baolu
2016-02-03 21:43 ` Greg Kroah-Hartman
2016-02-03 23:52 ` Lu Baolu
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=56C6BF99.9010409@linux.intel.com \
--to=baolu.lu@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@linux.intel.com \
/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).