lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Wed, 18 Mar 2015 17:49:08 -0700
From:	Dmitry Torokhov <dmitry.torokhov@...il.com>
To:	Borislav Petkov <bp@...en8.de>,
	Doug Thompson <dougthompson@...ssion.com>,
	Tejun Heo <tj@...nel.org>
Cc:	linux-kernel@...r.kernel.org, linux-edac@...r.kernel.org,
	Mauro Carvalho Chehab <mchehab@....samsung.com>,
	Tetsuo Handa <penguin-kernel@...ove.SAKURA.ne.jp>,
	Olof Johansson <olof@...om.net>,
	Arjan van de Ven <arjan@...ux.intel.com>,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	"Luis R . Rodriguez" <mcgrof@...e.com>
Subject: [PATCH 1/3] EDAC: amd64: stop allocating ecc settings separately

There is no reason for allocating and managing ECC settings separately
when we can merge them into the dirver-private structure.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@...il.com>
---
 drivers/edac/amd64_edac.c | 77 ++++++++++++++---------------------------------
 drivers/edac/amd64_edac.h | 27 +++++++++--------
 2 files changed, 37 insertions(+), 67 deletions(-)

diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
index 92772ff..c0ebc06 100644
--- a/drivers/edac/amd64_edac.c
+++ b/drivers/edac/amd64_edac.c
@@ -20,9 +20,6 @@ static struct msr __percpu *msrs;
  */
 static atomic_t drv_instances = ATOMIC_INIT(0);
 
-/* Per-node stuff */
-static struct ecc_settings **ecc_stngs;
-
 /*
  * Valid scrub rates for the K8 hardware memory scrubber. We map the scrubbing
  * bandwidth to a valid bit pattern. The 'set' operation finds the 'matching-
@@ -2790,6 +2787,18 @@ static int init_one_instance(struct pci_dev *F2)
 	if (err)
 		goto err_free;
 
+	if (!ecc_enabled(pvt->F3, nid)) {
+		ret = -ENODEV;
+
+		if (!ecc_enable_override)
+			goto err_siblings;
+
+		amd64_warn("Forcing ECC on!\n");
+
+		if (!enable_ecc_error_reporting(&pvt->ecc, nid, pvt->F3))
+			goto err_siblings;
+	}
+
 	read_mc_regs(pvt);
 
 	/*
@@ -2818,7 +2827,7 @@ static int init_one_instance(struct pci_dev *F2)
 
 	mci = edac_mc_alloc(nid, ARRAY_SIZE(layers), layers, 0);
 	if (!mci)
-		goto err_siblings;
+		goto err_restore_ecc;
 
 	mci->pvt_info = pvt;
 	mci->pdev = &pvt->F2->dev;
@@ -2847,6 +2856,9 @@ static int init_one_instance(struct pci_dev *F2)
 err_add_mc:
 	edac_mc_free(mci);
 
+err_restore_ecc:
+	restore_ecc_error_reporting(&pvt->ecc, nid, pvt->F3);
+
 err_siblings:
 	free_mc_sibling_devs(pvt);
 
@@ -2860,10 +2872,7 @@ err_ret:
 static int probe_one_instance(struct pci_dev *pdev,
 			      const struct pci_device_id *mc_type)
 {
-	u16 nid = amd_get_node_id(pdev);
-	struct pci_dev *F3 = node_to_amd_nb(nid)->misc;
-	struct ecc_settings *s;
-	int ret = 0;
+	int ret;
 
 	ret = pci_enable_device(pdev);
 	if (ret < 0) {
@@ -2871,39 +2880,12 @@ static int probe_one_instance(struct pci_dev *pdev,
 		return -EIO;
 	}
 
-	ret = -ENOMEM;
-	s = kzalloc(sizeof(struct ecc_settings), GFP_KERNEL);
-	if (!s)
-		goto err_out;
-
-	ecc_stngs[nid] = s;
-
-	if (!ecc_enabled(F3, nid)) {
-		ret = -ENODEV;
-
-		if (!ecc_enable_override)
-			goto err_enable;
-
-		amd64_warn("Forcing ECC on!\n");
-
-		if (!enable_ecc_error_reporting(s, nid, F3))
-			goto err_enable;
-	}
-
 	ret = init_one_instance(pdev);
-	if (ret < 0) {
-		amd64_err("Error probing instance: %d\n", nid);
-		restore_ecc_error_reporting(s, nid, F3);
-	}
+	if (ret < 0)
+		amd64_err("Error probing instance: %d\n",
+			  amd_get_node_id(pdev));
 
 	return ret;
-
-err_enable:
-	kfree(s);
-	ecc_stngs[nid] = NULL;
-
-err_out:
-	return ret;
 }
 
 static void remove_one_instance(struct pci_dev *pdev)
@@ -2912,7 +2894,6 @@ static void remove_one_instance(struct pci_dev *pdev)
 	struct amd64_pvt *pvt;
 	u16 nid = amd_get_node_id(pdev);
 	struct pci_dev *F3 = node_to_amd_nb(nid)->misc;
-	struct ecc_settings *s = ecc_stngs[nid];
 
 	mci = find_mci_by_dev(&pdev->dev);
 	WARN_ON(!mci);
@@ -2924,7 +2905,7 @@ static void remove_one_instance(struct pci_dev *pdev)
 
 	pvt = mci->pvt_info;
 
-	restore_ecc_error_reporting(s, nid, F3);
+	restore_ecc_error_reporting(&pvt->ecc, nid, F3);
 
 	free_mc_sibling_devs(pvt);
 
@@ -2932,9 +2913,6 @@ static void remove_one_instance(struct pci_dev *pdev)
 	amd_report_gart_errors(false);
 	amd_unregister_ecc_decoder(decode_bus_error);
 
-	kfree(ecc_stngs[nid]);
-	ecc_stngs[nid] = NULL;
-
 	/* Free the EDAC CORE resources */
 	mci->pvt_info = NULL;
 
@@ -2998,13 +2976,9 @@ static int __init amd64_edac_init(void)
 		goto err_ret;
 
 	err = -ENOMEM;
-	ecc_stngs = kzalloc(amd_nb_num() * sizeof(ecc_stngs[0]), GFP_KERNEL);
-	if (!ecc_stngs)
-		goto err_free;
-
 	msrs = msrs_alloc();
 	if (!msrs)
-		goto err_free;
+		goto err_ret;
 
 	err = pci_register_driver(&amd64_pci_driver);
 	if (err)
@@ -3029,10 +3003,6 @@ err_pci:
 	msrs_free(msrs);
 	msrs = NULL;
 
-err_free:
-	kfree(ecc_stngs);
-	ecc_stngs = NULL;
-
 err_ret:
 	return err;
 }
@@ -3044,9 +3014,6 @@ static void __exit amd64_edac_exit(void)
 
 	pci_unregister_driver(&amd64_pci_driver);
 
-	kfree(ecc_stngs);
-	ecc_stngs = NULL;
-
 	msrs_free(msrs);
 	msrs = NULL;
 }
diff --git a/drivers/edac/amd64_edac.h b/drivers/edac/amd64_edac.h
index 4bdec75..a62ccba 100644
--- a/drivers/edac/amd64_edac.h
+++ b/drivers/edac/amd64_edac.h
@@ -340,6 +340,19 @@ struct chip_select {
 	u8 m_cnt;
 };
 
+/*
+ * per-node ECC settings descriptor
+ */
+struct ecc_settings {
+	u32 old_nbctl;
+	bool nbctl_valid;
+
+	struct flags {
+		unsigned long nb_mce_enable:1;
+		unsigned long nb_ecc_prev:1;
+	} flags;
+};
+
 struct amd64_pvt {
 	struct low_ops *ops;
 
@@ -385,6 +398,8 @@ struct amd64_pvt {
 	/* place to store error injection parameters prior to issue */
 	struct error_injection injection;
 
+	struct ecc_settings ecc;
+
 	/* cache the dram_type */
 	enum mem_type dram_type;
 };
@@ -439,18 +454,6 @@ static inline u8 dct_sel_interleave_addr(struct amd64_pvt *pvt)
 
 	return	((pvt)->dct_sel_lo >> 6) & 0x3;
 }
-/*
- * per-node ECC settings descriptor
- */
-struct ecc_settings {
-	u32 old_nbctl;
-	bool nbctl_valid;
-
-	struct flags {
-		unsigned long nb_mce_enable:1;
-		unsigned long nb_ecc_prev:1;
-	} flags;
-};
 
 #ifdef CONFIG_EDAC_DEBUG
 extern const struct attribute_group amd64_edac_dbg_group;
-- 
2.2.0.rc0.207.ga3a616c

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists