[haiku-commits] haiku: hrev52902 - in src: add-ons/kernel/busses/usb add-ons/kernel/bus_managers/usb system/kernel system/kernel/arch/x86

  • From: waddlesplash <waddlesplash@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 19 Feb 2019 21:42:11 -0500 (EST)

hrev52902 adds 5 changesets to branch 'master'
old head: 784aba8e2d2ac8d9ccd4115865c2601a442aa467
new head: 055d49b1fd44ba7c450ad40051a2f34f38508b5f
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=055d49b1fd44+%5E784aba8e2d2a

----------------------------------------------------------------------------

d6f3954f3963: XHCI: Tweak copyright header.
  
   * List authors in alphabetical order.
   * Add myself.
   * Make first copyright year the actual year the file was created.

a182f1936435: USB: Properly assign IDs to USB Bus Managers (HCI drivers).
  
  Previously they would just get -1, as the BusManager class
  would request their ID before they had been added to the Stack.
  Now we add them to the stack inside ::Start(), rather than letting
  the individual drivers do that just after ::Start(), and then assign
  the ID there directly.

a21f7b525b2c: XHCI: Move and reorder Stop/SetTRD/Reset during endpoint creation.
  
  Fixes a lot of "command failed: invalid context" errors on a variety
  of devices following previous commits. Does not seem to affect much,
  though.

58ed2965d036: kernel: Panic on attempts to block a pinned thread.
  
  Preventing "normal" context switches caused by a time interrupt
  is the primary reason for pinning threads. "thread_block" and friends,
  however, cause an explicit context switch and will not return until
  another thread unblocks us.
  
  Calling these while a thread is pinned is thus undefined behavior,
  and so we should just panic in the case anyone attempts to do so.

055d49b1fd44: kernel/x86: Pin the current thread before calling interrupt 
handlers.
  
  int_io_* functions do not touch the thread state, but we already have
  it here as we will modify its contents later, so it makes more sense
  to set this flag here.
  
  This is mostly only relevant following the previous commit, i.e.
  finding interrupt handlers that brokenly try to context-switch.

                              [ Augustin Cavalier <waddlesplash@xxxxxxxxx> ]

----------------------------------------------------------------------------

7 files changed, 34 insertions(+), 16 deletions(-)
.../kernel/bus_managers/usb/BusManager.cpp       |  4 +++-
src/add-ons/kernel/busses/usb/ehci.cpp           |  6 ++++--
src/add-ons/kernel/busses/usb/ohci.cpp           |  6 ++++--
src/add-ons/kernel/busses/usb/uhci.cpp           |  6 ++++--
src/add-ons/kernel/busses/usb/xhci.cpp           | 21 +++++++++++---------
src/system/kernel/arch/x86/arch_int.cpp          |  2 ++
src/system/kernel/thread.cpp                     |  5 +++++

############################################################################

Commit:      d6f3954f3963f81cf00d2da9930cf9d90a179d87
URL:         https://git.haiku-os.org/haiku/commit/?id=d6f3954f3963
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Tue Feb 19 21:41:47 2019 UTC

XHCI: Tweak copyright header.

 * List authors in alphabetical order.
 * Add myself.
 * Make first copyright year the actual year the file was created.

----------------------------------------------------------------------------

diff --git a/src/add-ons/kernel/busses/usb/xhci.cpp 
b/src/add-ons/kernel/busses/usb/xhci.cpp
index c0852959f0..b6cf4b13fd 100644
--- a/src/add-ons/kernel/busses/usb/xhci.cpp
+++ b/src/add-ons/kernel/busses/usb/xhci.cpp
@@ -1,12 +1,13 @@
 /*
- * Copyright 2006-2019, Haiku Inc. All rights reserved.
+ * Copyright 2011-2019, Haiku Inc. All rights reserved.
  * Distributed under the terms of the MIT License.
  *
  * Authors:
- *             Michael Lotz <mmlr@xxxxxxxx>
+ *             Augustin Cavalier <waddlesplash>
  *             Jian Chiang <j.jian.chiang@xxxxxxxxx>
  *             Jérôme Duval <jerome.duval@xxxxxxxxx>
  *             Akshay Jaggi <akshay1994.leo@xxxxxxxxx>
+ *             Michael Lotz <mmlr@xxxxxxxx>
  */
 
 

############################################################################

Commit:      a182f19364351a88c75aca671052c702c7c0eaf2
URL:         https://git.haiku-os.org/haiku/commit/?id=a182f1936435
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Tue Feb 19 22:14:54 2019 UTC

USB: Properly assign IDs to USB Bus Managers (HCI drivers).

Previously they would just get -1, as the BusManager class
would request their ID before they had been added to the Stack.
Now we add them to the stack inside ::Start(), rather than letting
the individual drivers do that just after ::Start(), and then assign
the ID there directly.

----------------------------------------------------------------------------

diff --git a/src/add-ons/kernel/bus_managers/usb/BusManager.cpp 
b/src/add-ons/kernel/bus_managers/usb/BusManager.cpp
index 99f7953866..f6305802c7 100644
--- a/src/add-ons/kernel/bus_managers/usb/BusManager.cpp
+++ b/src/add-ons/kernel/bus_managers/usb/BusManager.cpp
@@ -14,7 +14,7 @@ BusManager::BusManager(Stack *stack)
        :       fInitOK(false),
                fStack(stack),
                fRootHub(NULL),
-               fUSBID(fStack->IndexOfBusManager(this))
+               fUSBID((uint32)-1)
 {
        mutex_init(&fLock, "usb busmanager lock");
 
@@ -253,6 +253,8 @@ BusManager::FreeDevice(Device *device)
 status_t
 BusManager::Start()
 {
+       fStack->AddBusManager(this);
+       fUSBID = fStack->IndexOfBusManager(this);
        return B_OK;
 }
 
diff --git a/src/add-ons/kernel/busses/usb/ehci.cpp 
b/src/add-ons/kernel/busses/usb/ehci.cpp
index b45541ea46..9c6bd23a85 100644
--- a/src/add-ons/kernel/busses/usb/ehci.cpp
+++ b/src/add-ons/kernel/busses/usb/ehci.cpp
@@ -1216,8 +1216,10 @@ EHCI::AddTo(Stack *stack)
                        // the bus took it away
                        item = new(std::nothrow) pci_info;
 
-                       bus->Start();
-                       stack->AddBusManager(bus);
+                       if (bus->Start() != B_OK) {
+                               delete bus;
+                               continue;
+                       }
                        found = true;
                }
        }
diff --git a/src/add-ons/kernel/busses/usb/ohci.cpp 
b/src/add-ons/kernel/busses/usb/ohci.cpp
index 7bf1513b30..ded588e16a 100644
--- a/src/add-ons/kernel/busses/usb/ohci.cpp
+++ b/src/add-ons/kernel/busses/usb/ohci.cpp
@@ -647,8 +647,10 @@ OHCI::AddTo(Stack *stack)
                        // the bus took it away
                        item = new(std::nothrow) pci_info;
 
-                       bus->Start();
-                       stack->AddBusManager(bus);
+                       if (bus->Start() != B_OK) {
+                               delete bus;
+                               continue;
+                       }
                        found = true;
                }
        }
diff --git a/src/add-ons/kernel/busses/usb/uhci.cpp 
b/src/add-ons/kernel/busses/usb/uhci.cpp
index 8d6f4e361c..ade4ca7114 100644
--- a/src/add-ons/kernel/busses/usb/uhci.cpp
+++ b/src/add-ons/kernel/busses/usb/uhci.cpp
@@ -1923,8 +1923,10 @@ UHCI::AddTo(Stack *stack)
                        // the bus took it away
                        item = new(std::nothrow) pci_info;
 
-                       bus->Start();
-                       stack->AddBusManager(bus);
+                       if (bus->Start() != B_OK) {
+                               delete bus;
+                               continue;
+                       }
                        found = true;
                }
        }
diff --git a/src/add-ons/kernel/busses/usb/xhci.cpp 
b/src/add-ons/kernel/busses/usb/xhci.cpp
index b6cf4b13fd..07382ccc5f 100644
--- a/src/add-ons/kernel/busses/usb/xhci.cpp
+++ b/src/add-ons/kernel/busses/usb/xhci.cpp
@@ -864,8 +864,10 @@ XHCI::AddTo(Stack *stack)
                        // the bus took it away
                        item = new(std::nothrow) pci_info;
 
-                       bus->Start();
-                       stack->AddBusManager(bus);
+                       if (bus->Start() != B_OK) {
+                               delete bus;
+                               continue;
+                       }
                        found = true;
                }
        }

############################################################################

Commit:      a21f7b525b2c030a07592354bc51eb186206392b
URL:         https://git.haiku-os.org/haiku/commit/?id=a21f7b525b2c
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Wed Feb 20 02:33:54 2019 UTC

XHCI: Move and reorder Stop/SetTRD/Reset during endpoint creation.

Fixes a lot of "command failed: invalid context" errors on a variety
of devices following previous commits. Does not seem to affect much,
though.

----------------------------------------------------------------------------

diff --git a/src/add-ons/kernel/busses/usb/xhci.cpp 
b/src/add-ons/kernel/busses/usb/xhci.cpp
index 07382ccc5f..6ed2727799 100644
--- a/src/add-ons/kernel/busses/usb/xhci.cpp
+++ b/src/add-ons/kernel/busses/usb/xhci.cpp
@@ -1496,11 +1496,6 @@ XHCI::_InsertEndpointForPipe(Pipe *pipe)
                        return status;
                }
 
-               StopEndpoint(false, endpoint, device->slot);
-               ResetEndpoint(false, endpoint, device->slot);
-               SetTRDequeue(device->endpoints[id].trb_addr, 0, endpoint,
-                       device->slot);
-
                _WriteContext(&device->input_ctx->input.dropFlags, 0);
                _WriteContext(&device->input_ctx->input.addFlags,
                        (1 << endpoint) | (1 << 0));
@@ -1510,6 +1505,11 @@ XHCI::_InsertEndpointForPipe(Pipe *pipe)
                else
                        EvaluateContext(device->input_ctx_addr, device->slot);
 
+               StopEndpoint(false, endpoint, device->slot);
+               SetTRDequeue(device->endpoints[id].trb_addr, 0, endpoint,
+                       device->slot);
+               ResetEndpoint(false, endpoint, device->slot);
+
                TRACE("device: address 0x%x state 0x%08" B_PRIx32 "\n",
                        device->address, SLOT_3_SLOT_STATE_GET(_ReadContext(
                                &device->device_ctx->slot.dwslot3)));

############################################################################

Commit:      58ed2965d0362707ca043b365ac1f2e89ee8c789
URL:         https://git.haiku-os.org/haiku/commit/?id=58ed2965d036
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Wed Feb 20 02:35:39 2019 UTC

kernel: Panic on attempts to block a pinned thread.

Preventing "normal" context switches caused by a time interrupt
is the primary reason for pinning threads. "thread_block" and friends,
however, cause an explicit context switch and will not return until
another thread unblocks us.

Calling these while a thread is pinned is thus undefined behavior,
and so we should just panic in the case anyone attempts to do so.

----------------------------------------------------------------------------

diff --git a/src/system/kernel/thread.cpp b/src/system/kernel/thread.cpp
index 1315338f1c..b92bdec833 100644
--- a/src/system/kernel/thread.cpp
+++ b/src/system/kernel/thread.cpp
@@ -2847,6 +2847,11 @@ thread_block_timeout(timer* timer)
 static inline status_t
 thread_block_locked(Thread* thread)
 {
+       if (thread->pinned_to_cpu > 0) {
+               panic("attempting to block thread %" B_PRId32 ", which is 
pinned!",
+                       thread->id);
+       }
+
        if (thread->wait.status == 1) {
                // check for signals, if interruptible
                if (thread_is_interrupted(thread, thread->wait.flags)) {

############################################################################

Revision:    hrev52902
Commit:      055d49b1fd44ba7c450ad40051a2f34f38508b5f
URL:         https://git.haiku-os.org/haiku/commit/?id=055d49b1fd44
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Wed Feb 20 02:38:15 2019 UTC

kernel/x86: Pin the current thread before calling interrupt handlers.

int_io_* functions do not touch the thread state, but we already have
it here as we will modify its contents later, so it makes more sense
to set this flag here.

This is mostly only relevant following the previous commit, i.e.
finding interrupt handlers that brokenly try to context-switch.

----------------------------------------------------------------------------

diff --git a/src/system/kernel/arch/x86/arch_int.cpp 
b/src/system/kernel/arch/x86/arch_int.cpp
index 5588d5d181..b8213c6fcc 100644
--- a/src/system/kernel/arch/x86/arch_int.cpp
+++ b/src/system/kernel/arch/x86/arch_int.cpp
@@ -233,7 +233,9 @@ x86_hardware_interrupt(struct iframe* frame)
                        apic_end_of_interrupt();
        }
 
+       thread->pinned_to_cpu++;
        int_io_interrupt_handler(vector, levelTriggered);
+       thread->pinned_to_cpu--;
 
        if (levelTriggered) {
                if (!sCurrentPIC->end_of_interrupt(vector))


Other related posts: