Page MenuHomeFreeBSD

kdb: set kdb_why when entered via reboot and panic
ClosedPublic

Authored by thj on Mar 14 2022, 5:05 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Mar 7, 2:56 PM
Unknown Object (File)
Jan 24 2024, 6:12 AM
Unknown Object (File)
Dec 22 2023, 9:55 PM
Unknown Object (File)
Nov 29 2023, 11:58 PM
Unknown Object (File)
Nov 23 2023, 8:38 PM
Unknown Object (File)
Oct 28 2023, 8:45 PM
Unknown Object (File)
Sep 11 2023, 7:53 PM
Unknown Object (File)
Aug 18 2023, 2:01 AM
Subscribers

Details

Summary

Set the kdb_why reason when we enter via the reboot and panic paths. Add a
reason for kdb_why in the reboot path.

The original downstream diff has this comment explaining why kdb_why has to be
set earlier. To me this move seems harmless for us and it helps then reduce
their diff. I am happy to add an explanation, but I am not really sure it is
needed in kdb_enter.

 void                                                                        
 kdb_enter(const char *why, const char *msg)                                 
 {                                                                           
                                                                             
        if (kdb_dbbe != NULL && kdb_active == 0) {                           
+               /* Needs to happen early because we added a KASSERT in cnputs
+                  which fails unless kdb_why is set. cnputs is called by    
+                  printf. */                                                
+               kdb_why = why;                                               
                if (msg != NULL)                                             
                        printf("KDB: enter: %s\n", msg);                     
-               kdb_why = why;                                               
                breakpoint();                                                
                kdb_why = KDB_WHY_UNSET;                                     
        }                                                                    
 }

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

thj requested review of this revision.Mar 14 2022, 5:05 PM
sys/kern/subr_kdb.c
306

I don't think shutdown_nice() actually enters kdb. Do we need this WHY?

sys/kern/subr_kdb.c
306

I suspect that downstream wants to check kdb_why in the cnputc() called from printf(). I don't know though of the value of checking kdb_why in cnputc() if kdb hasn't been entered yet? Understanding the reason for that KASSERT may help understand this change better.

sys/kern/subr_kdb.c
306

They allow cnputsn to print with interrupts enabled. To avoid deadlock that have special cased some subsystems which handle deadlock on their own. They assert that kdb_why is not KDB_WHY_UNSET when running with interrupts enabled in cnputsn.

This part of their change is very specific to their code base.

I guess this is fine. The changes for kdb_panic and kdb_reboot do indeed seem a bit gratuitous and non-obvious, so there is some risk they get broken in the future perhaps. OTOH, this file doesn't change much.

This revision is now accepted and ready to land.Mar 25 2022, 5:44 PM

Note that an alternative would be to have some other special variable that gets set in other places and have the KASSERT be something like KASSERT(new_var || kdb_why != KDB_WHY_UNSENT). That would be a downstream-only approach of course, but would avoid needing to move kdb_why around downstream.