rv.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2019-2022 Red Hat, Inc. Daniel Bristot de Oliveira <bristot@kernel.org>
  4. *
  5. * This is the online Runtime Verification (RV) interface.
  6. *
  7. * RV is a lightweight (yet rigorous) method that complements classical
  8. * exhaustive verification techniques (such as model checking and
  9. * theorem proving) with a more practical approach to complex systems.
  10. *
  11. * RV works by analyzing the trace of the system's actual execution,
  12. * comparing it against a formal specification of the system behavior.
  13. * RV can give precise information on the runtime behavior of the
  14. * monitored system while enabling the reaction for unexpected
  15. * events, avoiding, for example, the propagation of a failure on
  16. * safety-critical systems.
  17. *
  18. * The development of this interface roots in the development of the
  19. * paper:
  20. *
  21. * De Oliveira, Daniel Bristot; Cucinotta, Tommaso; De Oliveira, Romulo
  22. * Silva. Efficient formal verification for the Linux kernel. In:
  23. * International Conference on Software Engineering and Formal Methods.
  24. * Springer, Cham, 2019. p. 315-332.
  25. *
  26. * And:
  27. *
  28. * De Oliveira, Daniel Bristot, et al. Automata-based formal analysis
  29. * and verification of the real-time Linux kernel. PhD Thesis, 2020.
  30. *
  31. * == Runtime monitor interface ==
  32. *
  33. * A monitor is the central part of the runtime verification of a system.
  34. *
  35. * The monitor stands in between the formal specification of the desired
  36. * (or undesired) behavior, and the trace of the actual system.
  37. *
  38. * In Linux terms, the runtime verification monitors are encapsulated
  39. * inside the "RV monitor" abstraction. A RV monitor includes a reference
  40. * model of the system, a set of instances of the monitor (per-cpu monitor,
  41. * per-task monitor, and so on), and the helper functions that glue the
  42. * monitor to the system via trace. Generally, a monitor includes some form
  43. * of trace output as a reaction for event parsing and exceptions,
  44. * as depicted bellow:
  45. *
  46. * Linux +----- RV Monitor ----------------------------------+ Formal
  47. * Realm | | Realm
  48. * +-------------------+ +----------------+ +-----------------+
  49. * | Linux kernel | | Monitor | | Reference |
  50. * | Tracing | -> | Instance(s) | <- | Model |
  51. * | (instrumentation) | | (verification) | | (specification) |
  52. * +-------------------+ +----------------+ +-----------------+
  53. * | | |
  54. * | V |
  55. * | +----------+ |
  56. * | | Reaction | |
  57. * | +--+--+--+-+ |
  58. * | | | | |
  59. * | | | +-> trace output ? |
  60. * +------------------------|--|----------------------+
  61. * | +----> panic ?
  62. * +-------> <user-specified>
  63. *
  64. * This file implements the interface for loading RV monitors, and
  65. * to control the verification session.
  66. *
  67. * == Registering monitors ==
  68. *
  69. * The struct rv_monitor defines a set of callback functions to control
  70. * a verification session. For instance, when a given monitor is enabled,
  71. * the "enable" callback function is called to hook the instrumentation
  72. * functions to the kernel trace events. The "disable" function is called
  73. * when disabling the verification session.
  74. *
  75. * A RV monitor is registered via:
  76. * int rv_register_monitor(struct rv_monitor *monitor);
  77. * And unregistered via:
  78. * int rv_unregister_monitor(struct rv_monitor *monitor);
  79. *
  80. * == User interface ==
  81. *
  82. * The user interface resembles kernel tracing interface. It presents
  83. * these files:
  84. *
  85. * "available_monitors"
  86. * - List the available monitors, one per line.
  87. *
  88. * For example:
  89. * # cat available_monitors
  90. * wip
  91. * wwnr
  92. *
  93. * "enabled_monitors"
  94. * - Lists the enabled monitors, one per line;
  95. * - Writing to it enables a given monitor;
  96. * - Writing a monitor name with a '!' prefix disables it;
  97. * - Truncating the file disables all enabled monitors.
  98. *
  99. * For example:
  100. * # cat enabled_monitors
  101. * # echo wip > enabled_monitors
  102. * # echo wwnr >> enabled_monitors
  103. * # cat enabled_monitors
  104. * wip
  105. * wwnr
  106. * # echo '!wip' >> enabled_monitors
  107. * # cat enabled_monitors
  108. * wwnr
  109. * # echo > enabled_monitors
  110. * # cat enabled_monitors
  111. * #
  112. *
  113. * Note that more than one monitor can be enabled concurrently.
  114. *
  115. * "monitoring_on"
  116. * - It is an on/off general switcher for monitoring. Note
  117. * that it does not disable enabled monitors or detach events,
  118. * but stops the per-entity monitors from monitoring the events
  119. * received from the instrumentation. It resembles the "tracing_on"
  120. * switcher.
  121. *
  122. * "monitors/"
  123. * Each monitor will have its own directory inside "monitors/". There
  124. * the monitor specific files will be presented.
  125. * The "monitors/" directory resembles the "events" directory on
  126. * tracefs.
  127. *
  128. * For example:
  129. * # cd monitors/wip/
  130. * # ls
  131. * desc enable
  132. * # cat desc
  133. * auto-generated wakeup in preemptive monitor.
  134. * # cat enable
  135. * 0
  136. *
  137. * For further information, see:
  138. * Documentation/trace/rv/runtime-verification.rst
  139. */
  140. #include <linux/kernel.h>
  141. #include <linux/module.h>
  142. #include <linux/init.h>
  143. #include <linux/slab.h>
  144. #ifdef CONFIG_DA_MON_EVENTS
  145. #define CREATE_TRACE_POINTS
  146. #include <trace/events/rv.h>
  147. #endif
  148. #include "rv.h"
  149. DEFINE_MUTEX(rv_interface_lock);
  150. static struct rv_interface rv_root;
  151. struct dentry *get_monitors_root(void)
  152. {
  153. return rv_root.monitors_dir;
  154. }
  155. /*
  156. * Interface for the monitor register.
  157. */
  158. static LIST_HEAD(rv_monitors_list);
  159. static int task_monitor_count;
  160. static bool task_monitor_slots[RV_PER_TASK_MONITORS];
  161. int rv_get_task_monitor_slot(void)
  162. {
  163. int i;
  164. lockdep_assert_held(&rv_interface_lock);
  165. if (task_monitor_count == RV_PER_TASK_MONITORS)
  166. return -EBUSY;
  167. task_monitor_count++;
  168. for (i = 0; i < RV_PER_TASK_MONITORS; i++) {
  169. if (task_monitor_slots[i] == false) {
  170. task_monitor_slots[i] = true;
  171. return i;
  172. }
  173. }
  174. WARN_ONCE(1, "RV task_monitor_count and slots are out of sync\n");
  175. return -EINVAL;
  176. }
  177. void rv_put_task_monitor_slot(int slot)
  178. {
  179. lockdep_assert_held(&rv_interface_lock);
  180. if (slot < 0 || slot >= RV_PER_TASK_MONITORS) {
  181. WARN_ONCE(1, "RV releasing an invalid slot!: %d\n", slot);
  182. return;
  183. }
  184. WARN_ONCE(!task_monitor_slots[slot], "RV releasing unused task_monitor_slots: %d\n",
  185. slot);
  186. task_monitor_count--;
  187. task_monitor_slots[slot] = false;
  188. }
  189. /*
  190. * This section collects the monitor/ files and folders.
  191. */
  192. static ssize_t monitor_enable_read_data(struct file *filp, char __user *user_buf, size_t count,
  193. loff_t *ppos)
  194. {
  195. struct rv_monitor_def *mdef = filp->private_data;
  196. const char *buff;
  197. buff = mdef->monitor->enabled ? "1\n" : "0\n";
  198. return simple_read_from_buffer(user_buf, count, ppos, buff, strlen(buff)+1);
  199. }
  200. /*
  201. * __rv_disable_monitor - disabled an enabled monitor
  202. */
  203. static int __rv_disable_monitor(struct rv_monitor_def *mdef, bool sync)
  204. {
  205. lockdep_assert_held(&rv_interface_lock);
  206. if (mdef->monitor->enabled) {
  207. mdef->monitor->enabled = 0;
  208. mdef->monitor->disable();
  209. /*
  210. * Wait for the execution of all events to finish.
  211. * Otherwise, the data used by the monitor could
  212. * be inconsistent. i.e., if the monitor is re-enabled.
  213. */
  214. if (sync)
  215. tracepoint_synchronize_unregister();
  216. return 1;
  217. }
  218. return 0;
  219. }
  220. /**
  221. * rv_disable_monitor - disable a given runtime monitor
  222. * @mdef: Pointer to the monitor definition structure.
  223. *
  224. * Returns 0 on success.
  225. */
  226. int rv_disable_monitor(struct rv_monitor_def *mdef)
  227. {
  228. __rv_disable_monitor(mdef, true);
  229. return 0;
  230. }
  231. /**
  232. * rv_enable_monitor - enable a given runtime monitor
  233. * @mdef: Pointer to the monitor definition structure.
  234. *
  235. * Returns 0 on success, error otherwise.
  236. */
  237. int rv_enable_monitor(struct rv_monitor_def *mdef)
  238. {
  239. int retval;
  240. lockdep_assert_held(&rv_interface_lock);
  241. if (mdef->monitor->enabled)
  242. return 0;
  243. retval = mdef->monitor->enable();
  244. if (!retval)
  245. mdef->monitor->enabled = 1;
  246. return retval;
  247. }
  248. /*
  249. * interface for enabling/disabling a monitor.
  250. */
  251. static ssize_t monitor_enable_write_data(struct file *filp, const char __user *user_buf,
  252. size_t count, loff_t *ppos)
  253. {
  254. struct rv_monitor_def *mdef = filp->private_data;
  255. int retval;
  256. bool val;
  257. retval = kstrtobool_from_user(user_buf, count, &val);
  258. if (retval)
  259. return retval;
  260. mutex_lock(&rv_interface_lock);
  261. if (val)
  262. retval = rv_enable_monitor(mdef);
  263. else
  264. retval = rv_disable_monitor(mdef);
  265. mutex_unlock(&rv_interface_lock);
  266. return retval ? : count;
  267. }
  268. static const struct file_operations interface_enable_fops = {
  269. .open = simple_open,
  270. .write = monitor_enable_write_data,
  271. .read = monitor_enable_read_data,
  272. };
  273. /*
  274. * Interface to read monitors description.
  275. */
  276. static ssize_t monitor_desc_read_data(struct file *filp, char __user *user_buf, size_t count,
  277. loff_t *ppos)
  278. {
  279. struct rv_monitor_def *mdef = filp->private_data;
  280. char buff[256];
  281. memset(buff, 0, sizeof(buff));
  282. snprintf(buff, sizeof(buff), "%s\n", mdef->monitor->description);
  283. return simple_read_from_buffer(user_buf, count, ppos, buff, strlen(buff) + 1);
  284. }
  285. static const struct file_operations interface_desc_fops = {
  286. .open = simple_open,
  287. .read = monitor_desc_read_data,
  288. };
  289. /*
  290. * During the registration of a monitor, this function creates
  291. * the monitor dir, where the specific options of the monitor
  292. * are exposed.
  293. */
  294. static int create_monitor_dir(struct rv_monitor_def *mdef)
  295. {
  296. struct dentry *root = get_monitors_root();
  297. const char *name = mdef->monitor->name;
  298. struct dentry *tmp;
  299. int retval;
  300. mdef->root_d = rv_create_dir(name, root);
  301. if (!mdef->root_d)
  302. return -ENOMEM;
  303. tmp = rv_create_file("enable", RV_MODE_WRITE, mdef->root_d, mdef, &interface_enable_fops);
  304. if (!tmp) {
  305. retval = -ENOMEM;
  306. goto out_remove_root;
  307. }
  308. tmp = rv_create_file("desc", RV_MODE_READ, mdef->root_d, mdef, &interface_desc_fops);
  309. if (!tmp) {
  310. retval = -ENOMEM;
  311. goto out_remove_root;
  312. }
  313. retval = reactor_populate_monitor(mdef);
  314. if (retval)
  315. goto out_remove_root;
  316. return 0;
  317. out_remove_root:
  318. rv_remove(mdef->root_d);
  319. return retval;
  320. }
  321. /*
  322. * Available/Enable monitor shared seq functions.
  323. */
  324. static int monitors_show(struct seq_file *m, void *p)
  325. {
  326. struct rv_monitor_def *mon_def = p;
  327. seq_printf(m, "%s\n", mon_def->monitor->name);
  328. return 0;
  329. }
  330. /*
  331. * Used by the seq file operations at the end of a read
  332. * operation.
  333. */
  334. static void monitors_stop(struct seq_file *m, void *p)
  335. {
  336. mutex_unlock(&rv_interface_lock);
  337. }
  338. /*
  339. * Available monitor seq functions.
  340. */
  341. static void *available_monitors_start(struct seq_file *m, loff_t *pos)
  342. {
  343. mutex_lock(&rv_interface_lock);
  344. return seq_list_start(&rv_monitors_list, *pos);
  345. }
  346. static void *available_monitors_next(struct seq_file *m, void *p, loff_t *pos)
  347. {
  348. return seq_list_next(p, &rv_monitors_list, pos);
  349. }
  350. /*
  351. * Enable monitor seq functions.
  352. */
  353. static void *enabled_monitors_next(struct seq_file *m, void *p, loff_t *pos)
  354. {
  355. struct rv_monitor_def *m_def = p;
  356. (*pos)++;
  357. list_for_each_entry_continue(m_def, &rv_monitors_list, list) {
  358. if (m_def->monitor->enabled)
  359. return m_def;
  360. }
  361. return NULL;
  362. }
  363. static void *enabled_monitors_start(struct seq_file *m, loff_t *pos)
  364. {
  365. struct rv_monitor_def *m_def;
  366. loff_t l;
  367. mutex_lock(&rv_interface_lock);
  368. if (list_empty(&rv_monitors_list))
  369. return NULL;
  370. m_def = list_entry(&rv_monitors_list, struct rv_monitor_def, list);
  371. for (l = 0; l <= *pos; ) {
  372. m_def = enabled_monitors_next(m, m_def, &l);
  373. if (!m_def)
  374. break;
  375. }
  376. return m_def;
  377. }
  378. /*
  379. * available/enabled monitors seq definition.
  380. */
  381. static const struct seq_operations available_monitors_seq_ops = {
  382. .start = available_monitors_start,
  383. .next = available_monitors_next,
  384. .stop = monitors_stop,
  385. .show = monitors_show
  386. };
  387. static const struct seq_operations enabled_monitors_seq_ops = {
  388. .start = enabled_monitors_start,
  389. .next = enabled_monitors_next,
  390. .stop = monitors_stop,
  391. .show = monitors_show
  392. };
  393. /*
  394. * available_monitors interface.
  395. */
  396. static int available_monitors_open(struct inode *inode, struct file *file)
  397. {
  398. return seq_open(file, &available_monitors_seq_ops);
  399. };
  400. static const struct file_operations available_monitors_ops = {
  401. .open = available_monitors_open,
  402. .read = seq_read,
  403. .llseek = seq_lseek,
  404. .release = seq_release
  405. };
  406. /*
  407. * enabled_monitors interface.
  408. */
  409. static void disable_all_monitors(void)
  410. {
  411. struct rv_monitor_def *mdef;
  412. int enabled = 0;
  413. mutex_lock(&rv_interface_lock);
  414. list_for_each_entry(mdef, &rv_monitors_list, list)
  415. enabled += __rv_disable_monitor(mdef, false);
  416. if (enabled) {
  417. /*
  418. * Wait for the execution of all events to finish.
  419. * Otherwise, the data used by the monitor could
  420. * be inconsistent. i.e., if the monitor is re-enabled.
  421. */
  422. tracepoint_synchronize_unregister();
  423. }
  424. mutex_unlock(&rv_interface_lock);
  425. }
  426. static int enabled_monitors_open(struct inode *inode, struct file *file)
  427. {
  428. if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_TRUNC))
  429. disable_all_monitors();
  430. return seq_open(file, &enabled_monitors_seq_ops);
  431. };
  432. static ssize_t enabled_monitors_write(struct file *filp, const char __user *user_buf,
  433. size_t count, loff_t *ppos)
  434. {
  435. char buff[MAX_RV_MONITOR_NAME_SIZE + 2];
  436. struct rv_monitor_def *mdef;
  437. int retval = -EINVAL;
  438. bool enable = true;
  439. char *ptr;
  440. int len;
  441. if (count < 1 || count > MAX_RV_MONITOR_NAME_SIZE + 1)
  442. return -EINVAL;
  443. memset(buff, 0, sizeof(buff));
  444. retval = simple_write_to_buffer(buff, sizeof(buff) - 1, ppos, user_buf, count);
  445. if (retval < 0)
  446. return -EFAULT;
  447. ptr = strim(buff);
  448. if (ptr[0] == '!') {
  449. enable = false;
  450. ptr++;
  451. }
  452. len = strlen(ptr);
  453. if (!len)
  454. return count;
  455. mutex_lock(&rv_interface_lock);
  456. retval = -EINVAL;
  457. list_for_each_entry(mdef, &rv_monitors_list, list) {
  458. if (strcmp(ptr, mdef->monitor->name) != 0)
  459. continue;
  460. /*
  461. * Monitor found!
  462. */
  463. if (enable)
  464. retval = rv_enable_monitor(mdef);
  465. else
  466. retval = rv_disable_monitor(mdef);
  467. if (!retval)
  468. retval = count;
  469. break;
  470. }
  471. mutex_unlock(&rv_interface_lock);
  472. return retval;
  473. }
  474. static const struct file_operations enabled_monitors_ops = {
  475. .open = enabled_monitors_open,
  476. .read = seq_read,
  477. .write = enabled_monitors_write,
  478. .llseek = seq_lseek,
  479. .release = seq_release,
  480. };
  481. /*
  482. * Monitoring on global switcher!
  483. */
  484. static bool __read_mostly monitoring_on;
  485. /**
  486. * rv_monitoring_on - checks if monitoring is on
  487. *
  488. * Returns 1 if on, 0 otherwise.
  489. */
  490. bool rv_monitoring_on(void)
  491. {
  492. /* Ensures that concurrent monitors read consistent monitoring_on */
  493. smp_rmb();
  494. return READ_ONCE(monitoring_on);
  495. }
  496. /*
  497. * monitoring_on general switcher.
  498. */
  499. static ssize_t monitoring_on_read_data(struct file *filp, char __user *user_buf,
  500. size_t count, loff_t *ppos)
  501. {
  502. const char *buff;
  503. buff = rv_monitoring_on() ? "1\n" : "0\n";
  504. return simple_read_from_buffer(user_buf, count, ppos, buff, strlen(buff) + 1);
  505. }
  506. static void turn_monitoring_off(void)
  507. {
  508. WRITE_ONCE(monitoring_on, false);
  509. /* Ensures that concurrent monitors read consistent monitoring_on */
  510. smp_wmb();
  511. }
  512. static void reset_all_monitors(void)
  513. {
  514. struct rv_monitor_def *mdef;
  515. list_for_each_entry(mdef, &rv_monitors_list, list) {
  516. if (mdef->monitor->enabled)
  517. mdef->monitor->reset();
  518. }
  519. }
  520. static void turn_monitoring_on(void)
  521. {
  522. WRITE_ONCE(monitoring_on, true);
  523. /* Ensures that concurrent monitors read consistent monitoring_on */
  524. smp_wmb();
  525. }
  526. static void turn_monitoring_on_with_reset(void)
  527. {
  528. lockdep_assert_held(&rv_interface_lock);
  529. if (rv_monitoring_on())
  530. return;
  531. /*
  532. * Monitors might be out of sync with the system if events were not
  533. * processed because of !rv_monitoring_on().
  534. *
  535. * Reset all monitors, forcing a re-sync.
  536. */
  537. reset_all_monitors();
  538. turn_monitoring_on();
  539. }
  540. static ssize_t monitoring_on_write_data(struct file *filp, const char __user *user_buf,
  541. size_t count, loff_t *ppos)
  542. {
  543. int retval;
  544. bool val;
  545. retval = kstrtobool_from_user(user_buf, count, &val);
  546. if (retval)
  547. return retval;
  548. mutex_lock(&rv_interface_lock);
  549. if (val)
  550. turn_monitoring_on_with_reset();
  551. else
  552. turn_monitoring_off();
  553. /*
  554. * Wait for the execution of all events to finish
  555. * before returning to user-space.
  556. */
  557. tracepoint_synchronize_unregister();
  558. mutex_unlock(&rv_interface_lock);
  559. return count;
  560. }
  561. static const struct file_operations monitoring_on_fops = {
  562. .open = simple_open,
  563. .write = monitoring_on_write_data,
  564. .read = monitoring_on_read_data,
  565. };
  566. static void destroy_monitor_dir(struct rv_monitor_def *mdef)
  567. {
  568. reactor_cleanup_monitor(mdef);
  569. rv_remove(mdef->root_d);
  570. }
  571. /**
  572. * rv_register_monitor - register a rv monitor.
  573. * @monitor: The rv_monitor to be registered.
  574. *
  575. * Returns 0 if successful, error otherwise.
  576. */
  577. int rv_register_monitor(struct rv_monitor *monitor)
  578. {
  579. struct rv_monitor_def *r;
  580. int retval = 0;
  581. if (strlen(monitor->name) >= MAX_RV_MONITOR_NAME_SIZE) {
  582. pr_info("Monitor %s has a name longer than %d\n", monitor->name,
  583. MAX_RV_MONITOR_NAME_SIZE);
  584. return -1;
  585. }
  586. mutex_lock(&rv_interface_lock);
  587. list_for_each_entry(r, &rv_monitors_list, list) {
  588. if (strcmp(monitor->name, r->monitor->name) == 0) {
  589. pr_info("Monitor %s is already registered\n", monitor->name);
  590. retval = -1;
  591. goto out_unlock;
  592. }
  593. }
  594. r = kzalloc(sizeof(struct rv_monitor_def), GFP_KERNEL);
  595. if (!r) {
  596. retval = -ENOMEM;
  597. goto out_unlock;
  598. }
  599. r->monitor = monitor;
  600. retval = create_monitor_dir(r);
  601. if (retval) {
  602. kfree(r);
  603. goto out_unlock;
  604. }
  605. list_add_tail(&r->list, &rv_monitors_list);
  606. out_unlock:
  607. mutex_unlock(&rv_interface_lock);
  608. return retval;
  609. }
  610. /**
  611. * rv_unregister_monitor - unregister a rv monitor.
  612. * @monitor: The rv_monitor to be unregistered.
  613. *
  614. * Returns 0 if successful, error otherwise.
  615. */
  616. int rv_unregister_monitor(struct rv_monitor *monitor)
  617. {
  618. struct rv_monitor_def *ptr, *next;
  619. mutex_lock(&rv_interface_lock);
  620. list_for_each_entry_safe(ptr, next, &rv_monitors_list, list) {
  621. if (strcmp(monitor->name, ptr->monitor->name) == 0) {
  622. rv_disable_monitor(ptr);
  623. list_del(&ptr->list);
  624. destroy_monitor_dir(ptr);
  625. }
  626. }
  627. mutex_unlock(&rv_interface_lock);
  628. return 0;
  629. }
  630. int __init rv_init_interface(void)
  631. {
  632. struct dentry *tmp;
  633. int retval;
  634. rv_root.root_dir = rv_create_dir("rv", NULL);
  635. if (!rv_root.root_dir)
  636. goto out_err;
  637. rv_root.monitors_dir = rv_create_dir("monitors", rv_root.root_dir);
  638. if (!rv_root.monitors_dir)
  639. goto out_err;
  640. tmp = rv_create_file("available_monitors", RV_MODE_READ, rv_root.root_dir, NULL,
  641. &available_monitors_ops);
  642. if (!tmp)
  643. goto out_err;
  644. tmp = rv_create_file("enabled_monitors", RV_MODE_WRITE, rv_root.root_dir, NULL,
  645. &enabled_monitors_ops);
  646. if (!tmp)
  647. goto out_err;
  648. tmp = rv_create_file("monitoring_on", RV_MODE_WRITE, rv_root.root_dir, NULL,
  649. &monitoring_on_fops);
  650. if (!tmp)
  651. goto out_err;
  652. retval = init_rv_reactors(rv_root.root_dir);
  653. if (retval)
  654. goto out_err;
  655. turn_monitoring_on();
  656. return 0;
  657. out_err:
  658. rv_remove(rv_root.root_dir);
  659. printk(KERN_ERR "RV: Error while creating the RV interface\n");
  660. return 1;
  661. }