~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/powerpc/kernel/eeh_event.c

Version: ~ [ linux-5.12-rc5 ] ~ [ linux-5.11.11 ] ~ [ linux-5.10.27 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.109 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.184 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.228 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.264 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.264 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 /*
  3  *
  4  * Copyright (c) 2005 Linas Vepstas <linas@linas.org>
  5  */
  6 
  7 #include <linux/delay.h>
  8 #include <linux/list.h>
  9 #include <linux/sched.h>
 10 #include <linux/semaphore.h>
 11 #include <linux/pci.h>
 12 #include <linux/slab.h>
 13 #include <linux/kthread.h>
 14 #include <asm/eeh_event.h>
 15 #include <asm/ppc-pci.h>
 16 
 17 /** Overview:
 18  *  EEH error states may be detected within exception handlers;
 19  *  however, the recovery processing needs to occur asynchronously
 20  *  in a normal kernel context and not an interrupt context.
 21  *  This pair of routines creates an event and queues it onto a
 22  *  work-queue, where a worker thread can drive recovery.
 23  */
 24 
 25 static DEFINE_SPINLOCK(eeh_eventlist_lock);
 26 static DECLARE_COMPLETION(eeh_eventlist_event);
 27 static LIST_HEAD(eeh_eventlist);
 28 
 29 /**
 30  * eeh_event_handler - Dispatch EEH events.
 31  * @dummy - unused
 32  *
 33  * The detection of a frozen slot can occur inside an interrupt,
 34  * where it can be hard to do anything about it.  The goal of this
 35  * routine is to pull these detection events out of the context
 36  * of the interrupt handler, and re-dispatch them for processing
 37  * at a later time in a normal context.
 38  */
 39 static int eeh_event_handler(void * dummy)
 40 {
 41         unsigned long flags;
 42         struct eeh_event *event;
 43         struct eeh_pe *pe;
 44 
 45         while (!kthread_should_stop()) {
 46                 if (wait_for_completion_interruptible(&eeh_eventlist_event))
 47                         break;
 48 
 49                 /* Fetch EEH event from the queue */
 50                 spin_lock_irqsave(&eeh_eventlist_lock, flags);
 51                 event = NULL;
 52                 if (!list_empty(&eeh_eventlist)) {
 53                         event = list_entry(eeh_eventlist.next,
 54                                            struct eeh_event, list);
 55                         list_del(&event->list);
 56                 }
 57                 spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
 58                 if (!event)
 59                         continue;
 60 
 61                 /* We might have event without binding PE */
 62                 pe = event->pe;
 63                 if (pe) {
 64                         if (pe->type & EEH_PE_PHB)
 65                                 pr_info("EEH: Detected error on PHB#%x\n",
 66                                          pe->phb->global_number);
 67                         else
 68                                 pr_info("EEH: Detected PCI bus error on "
 69                                         "PHB#%x-PE#%x\n",
 70                                         pe->phb->global_number, pe->addr);
 71                         eeh_handle_normal_event(pe);
 72                 } else {
 73                         eeh_handle_special_event();
 74                 }
 75 
 76                 kfree(event);
 77         }
 78 
 79         return 0;
 80 }
 81 
 82 /**
 83  * eeh_event_init - Start kernel thread to handle EEH events
 84  *
 85  * This routine is called to start the kernel thread for processing
 86  * EEH event.
 87  */
 88 int eeh_event_init(void)
 89 {
 90         struct task_struct *t;
 91         int ret = 0;
 92 
 93         t = kthread_run(eeh_event_handler, NULL, "eehd");
 94         if (IS_ERR(t)) {
 95                 ret = PTR_ERR(t);
 96                 pr_err("%s: Failed to start EEH daemon (%d)\n",
 97                         __func__, ret);
 98                 return ret;
 99         }
100 
101         return 0;
102 }
103 
104 /**
105  * eeh_send_failure_event - Generate a PCI error event
106  * @pe: EEH PE
107  *
108  * This routine can be called within an interrupt context;
109  * the actual event will be delivered in a normal context
110  * (from a workqueue).
111  */
112 int __eeh_send_failure_event(struct eeh_pe *pe)
113 {
114         unsigned long flags;
115         struct eeh_event *event;
116 
117         event = kzalloc(sizeof(*event), GFP_ATOMIC);
118         if (!event) {
119                 pr_err("EEH: out of memory, event not handled\n");
120                 return -ENOMEM;
121         }
122         event->pe = pe;
123 
124         /*
125          * Mark the PE as recovering before inserting it in the queue.
126          * This prevents the PE from being free()ed by a hotplug driver
127          * while the PE is sitting in the event queue.
128          */
129         if (pe)
130                 eeh_pe_state_mark(pe, EEH_PE_RECOVERING);
131 
132         /* We may or may not be called in an interrupt context */
133         spin_lock_irqsave(&eeh_eventlist_lock, flags);
134         list_add(&event->list, &eeh_eventlist);
135         spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
136 
137         /* For EEH deamon to knick in */
138         complete(&eeh_eventlist_event);
139 
140         return 0;
141 }
142 
143 int eeh_send_failure_event(struct eeh_pe *pe)
144 {
145         /*
146          * If we've manually supressed recovery events via debugfs
147          * then just drop it on the floor.
148          */
149         if (eeh_debugfs_no_recover) {
150                 pr_err("EEH: Event dropped due to no_recover setting\n");
151                 return 0;
152         }
153 
154         return __eeh_send_failure_event(pe);
155 }
156 
157 /**
158  * eeh_remove_event - Remove EEH event from the queue
159  * @pe: Event binding to the PE
160  * @force: Event will be removed unconditionally
161  *
162  * On PowerNV platform, we might have subsequent coming events
163  * is part of the former one. For that case, those subsequent
164  * coming events are totally duplicated and unnecessary, thus
165  * they should be removed.
166  */
167 void eeh_remove_event(struct eeh_pe *pe, bool force)
168 {
169         unsigned long flags;
170         struct eeh_event *event, *tmp;
171 
172         /*
173          * If we have NULL PE passed in, we have dead IOC
174          * or we're sure we can report all existing errors
175          * by the caller.
176          *
177          * With "force", the event with associated PE that
178          * have been isolated, the event won't be removed
179          * to avoid event lost.
180          */
181         spin_lock_irqsave(&eeh_eventlist_lock, flags);
182         list_for_each_entry_safe(event, tmp, &eeh_eventlist, list) {
183                 if (!force && event->pe &&
184                     (event->pe->state & EEH_PE_ISOLATED))
185                         continue;
186 
187                 if (!pe) {
188                         list_del(&event->list);
189                         kfree(event);
190                 } else if (pe->type & EEH_PE_PHB) {
191                         if (event->pe && event->pe->phb == pe->phb) {
192                                 list_del(&event->list);
193                                 kfree(event);
194                         }
195                 } else if (event->pe == pe) {
196                         list_del(&event->list);
197                         kfree(event);
198                 }
199         }
200         spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
201 }
202 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp