diff mbox series

[v4,08/24] EDAC/amd64: Define function to check DRAM limit address

Message ID 20220127204115.384161-9-yazen.ghannam@amd.com (mailing list archive)
State New, archived
Headers show
Series AMD MCA Address Translation Updates | expand

Commit Message

Yazen Ghannam Jan. 27, 2022, 8:40 p.m. UTC
Move the DRAM limit check into a separate helper function.

Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com>
---
Link:
https://lore.kernel.org/r/20211028175728.121452-13-yazen.ghannam@amd.com

v3->v4:
* Include pr_debug() on failure.

v2->v3:
* Was patch 13 in v2.

v1->v2:
* Moved from arch/x86 to EDAC.

 drivers/edac/amd64_edac.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

Comments

Borislav Petkov Feb. 14, 2022, 10:06 a.m. UTC | #1
On Thu, Jan 27, 2022 at 08:40:59PM +0000, Yazen Ghannam wrote:
> Move the DRAM limit check into a separate helper function.

You're still writing the "what" in commit messages - pls make a note to
write about "why" you're doing a change instead.

Because I don't see why you're doing this. Because
umc_normaddr_to_sysaddr() is supposed to call helper functions only?

Now if you had the "why" I wouldn't be wondering...

:)
Yazen Ghannam March 9, 2022, 10:03 p.m. UTC | #2
On Mon, Feb 14, 2022 at 11:06:07AM +0100, Borislav Petkov wrote:
> On Thu, Jan 27, 2022 at 08:40:59PM +0000, Yazen Ghannam wrote:
> > Move the DRAM limit check into a separate helper function.
> 
> You're still writing the "what" in commit messages - pls make a note to
> write about "why" you're doing a change instead.
> 
> Because I don't see why you're doing this. Because
> umc_normaddr_to_sysaddr() is supposed to call helper functions only?
> 
> Now if you had the "why" I wouldn't be wondering...
> 
> :)
>

Yes, you're right. I'll update this.

Yes, the goal is to break up the translation procedure into discrete
high-level steps.

Thanks,
Yazen
diff mbox series

Patch

diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
index da2d0d9ce406..139dca3a3ba4 100644
--- a/drivers/edac/amd64_edac.c
+++ b/drivers/edac/amd64_edac.c
@@ -1326,10 +1326,20 @@  static int add_base_and_hole(struct addr_ctx *ctx)
 	return 0;
 }
 
-static int umc_normaddr_to_sysaddr(u64 norm_addr, u16 nid, u8 umc, u64 *sys_addr)
+static int addr_over_limit(struct addr_ctx *ctx)
 {
-	u64 dram_limit_addr;
+	u64 dram_limit_addr  = ((ctx->reg_limit_addr & GENMASK_ULL(31, 12)) << 16)
+					| GENMASK_ULL(27, 0);
+
+	/* Is calculated system address above DRAM limit address? */
+	if (ctx->ret_addr > dram_limit_addr)
+		return -EINVAL;
+
+	return 0;
+}
 
+static int umc_normaddr_to_sysaddr(u64 norm_addr, u16 nid, u8 umc, u64 *sys_addr)
+{
 	struct addr_ctx ctx;
 
 	if (!df_ops) {
@@ -1365,8 +1375,6 @@  static int umc_normaddr_to_sysaddr(u64 norm_addr, u16 nid, u8 umc, u64 *sys_addr
 		goto out_err;
 	}
 
-	dram_limit_addr	  = ((ctx.reg_limit_addr & GENMASK_ULL(31, 12)) << 16) | GENMASK_ULL(27, 0);
-
 	if (add_base_and_hole(&ctx)) {
 		pr_debug("Failed to add DRAM base address and hole");
 		goto out_err;
@@ -1377,9 +1385,10 @@  static int umc_normaddr_to_sysaddr(u64 norm_addr, u16 nid, u8 umc, u64 *sys_addr
 		goto out_err;
 	}
 
-	/* Is calculated system address is above DRAM limit address? */
-	if (ctx.ret_addr > dram_limit_addr)
+	if (addr_over_limit(&ctx)) {
+		pr_debug("Calculated address is over limit");
 		goto out_err;
+	}
 
 	*sys_addr = ctx.ret_addr;
 	return 0;