mce.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * NFIT - Machine Check Handler
  3. *
  4. * Copyright(c) 2013-2016 Intel Corporation. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of version 2 of the GNU General Public License as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. */
  15. #include <linux/notifier.h>
  16. #include <linux/acpi.h>
  17. #include <asm/mce.h>
  18. #include "nfit.h"
  19. static int nfit_handle_mce(struct notifier_block *nb, unsigned long val,
  20. void *data)
  21. {
  22. struct mce *mce = (struct mce *)data;
  23. struct acpi_nfit_desc *acpi_desc;
  24. struct nfit_spa *nfit_spa;
  25. /* We only care about memory errors */
  26. if (!(mce->status & MCACOD))
  27. return NOTIFY_DONE;
  28. /*
  29. * mce->addr contains the physical addr accessed that caused the
  30. * machine check. We need to walk through the list of NFITs, and see
  31. * if any of them matches that address, and only then start a scrub.
  32. */
  33. mutex_lock(&acpi_desc_lock);
  34. list_for_each_entry(acpi_desc, &acpi_descs, list) {
  35. struct device *dev = acpi_desc->dev;
  36. int found_match = 0;
  37. mutex_lock(&acpi_desc->init_mutex);
  38. list_for_each_entry(nfit_spa, &acpi_desc->spas, list) {
  39. struct acpi_nfit_system_address *spa = nfit_spa->spa;
  40. if (nfit_spa_type(spa) == NFIT_SPA_PM)
  41. continue;
  42. /* find the spa that covers the mce addr */
  43. if (spa->address > mce->addr)
  44. continue;
  45. if ((spa->address + spa->length - 1) < mce->addr)
  46. continue;
  47. found_match = 1;
  48. dev_dbg(dev, "%s: addr in SPA %d (0x%llx, 0x%llx)\n",
  49. __func__, spa->range_index, spa->address,
  50. spa->length);
  51. /*
  52. * We can break at the first match because we're going
  53. * to rescan all the SPA ranges. There shouldn't be any
  54. * aliasing anyway.
  55. */
  56. break;
  57. }
  58. mutex_unlock(&acpi_desc->init_mutex);
  59. /*
  60. * We can ignore an -EBUSY here because if an ARS is already
  61. * in progress, just let that be the last authoritative one
  62. */
  63. if (found_match)
  64. acpi_nfit_ars_rescan(acpi_desc);
  65. }
  66. mutex_unlock(&acpi_desc_lock);
  67. return NOTIFY_DONE;
  68. }
  69. static struct notifier_block nfit_mce_dec = {
  70. .notifier_call = nfit_handle_mce,
  71. };
  72. void nfit_mce_register(void)
  73. {
  74. mce_register_decode_chain(&nfit_mce_dec);
  75. }
  76. void nfit_mce_unregister(void)
  77. {
  78. mce_unregister_decode_chain(&nfit_mce_dec);
  79. }