Skip to content

Commit d5811a1

Browse files
jallen-amdbp3tk0v
authored andcommitted
RAS/AMD/ATL: Validate address map when information is gathered
Validate address maps at the time the information is gathered as the address map will not change during translation. Signed-off-by: John Allen <john.allen@amd.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Yazen Ghannam <yazen.ghannam@amd.com> Link: https://lore.kernel.org/r/20240606203313.51197-5-john.allen@amd.com
1 parent 6cce048 commit d5811a1

2 files changed

Lines changed: 77 additions & 43 deletions

File tree

drivers/ras/amd/atl/dehash.c

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,10 @@
1212

1313
#include "internal.h"
1414

15-
/*
16-
* Verify the interleave bits are correct in the different interleaving
17-
* settings.
18-
*
19-
* If @num_intlv_dies and/or @num_intlv_sockets are 1, it means the
20-
* respective interleaving is disabled.
21-
*/
22-
static inline bool map_bits_valid(struct addr_ctx *ctx, u8 bit1, u8 bit2,
23-
u8 num_intlv_dies, u8 num_intlv_sockets)
24-
{
25-
if (!(ctx->map.intlv_bit_pos == bit1 || ctx->map.intlv_bit_pos == bit2)) {
26-
pr_debug("Invalid interleave bit: %u", ctx->map.intlv_bit_pos);
27-
return false;
28-
}
29-
30-
if (ctx->map.num_intlv_dies > num_intlv_dies) {
31-
pr_debug("Invalid number of interleave dies: %u", ctx->map.num_intlv_dies);
32-
return false;
33-
}
34-
35-
if (ctx->map.num_intlv_sockets > num_intlv_sockets) {
36-
pr_debug("Invalid number of interleave sockets: %u", ctx->map.num_intlv_sockets);
37-
return false;
38-
}
39-
40-
return true;
41-
}
42-
4315
static int df2_dehash_addr(struct addr_ctx *ctx)
4416
{
4517
u8 hashed_bit, intlv_bit, intlv_bit_pos;
4618

47-
if (!map_bits_valid(ctx, 8, 9, 1, 1))
48-
return -EINVAL;
49-
5019
intlv_bit_pos = ctx->map.intlv_bit_pos;
5120
intlv_bit = !!(BIT_ULL(intlv_bit_pos) & ctx->ret_addr);
5221

@@ -67,9 +36,6 @@ static int df3_dehash_addr(struct addr_ctx *ctx)
6736
bool hash_ctl_64k, hash_ctl_2M, hash_ctl_1G;
6837
u8 hashed_bit, intlv_bit, intlv_bit_pos;
6938

70-
if (!map_bits_valid(ctx, 8, 9, 1, 1))
71-
return -EINVAL;
72-
7339
hash_ctl_64k = FIELD_GET(DF3_HASH_CTL_64K, ctx->map.ctl);
7440
hash_ctl_2M = FIELD_GET(DF3_HASH_CTL_2M, ctx->map.ctl);
7541
hash_ctl_1G = FIELD_GET(DF3_HASH_CTL_1G, ctx->map.ctl);
@@ -171,9 +137,6 @@ static int df4_dehash_addr(struct addr_ctx *ctx)
171137
bool hash_ctl_64k, hash_ctl_2M, hash_ctl_1G;
172138
u8 hashed_bit, intlv_bit;
173139

174-
if (!map_bits_valid(ctx, 8, 8, 1, 2))
175-
return -EINVAL;
176-
177140
hash_ctl_64k = FIELD_GET(DF4_HASH_CTL_64K, ctx->map.ctl);
178141
hash_ctl_2M = FIELD_GET(DF4_HASH_CTL_2M, ctx->map.ctl);
179142
hash_ctl_1G = FIELD_GET(DF4_HASH_CTL_1G, ctx->map.ctl);
@@ -247,9 +210,6 @@ static int df4p5_dehash_addr(struct addr_ctx *ctx)
247210
u8 hashed_bit, intlv_bit;
248211
u64 rehash_vector;
249212

250-
if (!map_bits_valid(ctx, 8, 8, 1, 2))
251-
return -EINVAL;
252-
253213
hash_ctl_64k = FIELD_GET(DF4_HASH_CTL_64K, ctx->map.ctl);
254214
hash_ctl_2M = FIELD_GET(DF4_HASH_CTL_2M, ctx->map.ctl);
255215
hash_ctl_1G = FIELD_GET(DF4_HASH_CTL_1G, ctx->map.ctl);
@@ -360,9 +320,6 @@ static int mi300_dehash_addr(struct addr_ctx *ctx)
360320
bool hashed_bit, intlv_bit, test_bit;
361321
u8 num_intlv_bits, base_bit, i;
362322

363-
if (!map_bits_valid(ctx, 8, 8, 4, 1))
364-
return -EINVAL;
365-
366323
hash_ctl_4k = FIELD_GET(DF4p5_HASH_CTL_4K, ctx->map.ctl);
367324
hash_ctl_64k = FIELD_GET(DF4_HASH_CTL_64K, ctx->map.ctl);
368325
hash_ctl_2M = FIELD_GET(DF4_HASH_CTL_2M, ctx->map.ctl);

drivers/ras/amd/atl/map.c

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,79 @@ static int get_global_map_data(struct addr_ctx *ctx)
642642
return 0;
643643
}
644644

645+
/*
646+
* Verify the interleave bits are correct in the different interleaving
647+
* settings.
648+
*
649+
* If @num_intlv_dies and/or @num_intlv_sockets are 1, it means the
650+
* respective interleaving is disabled.
651+
*/
652+
static inline bool map_bits_valid(struct addr_ctx *ctx, u8 bit1, u8 bit2,
653+
u8 num_intlv_dies, u8 num_intlv_sockets)
654+
{
655+
if (!(ctx->map.intlv_bit_pos == bit1 || ctx->map.intlv_bit_pos == bit2)) {
656+
pr_debug("Invalid interleave bit: %u", ctx->map.intlv_bit_pos);
657+
return false;
658+
}
659+
660+
if (ctx->map.num_intlv_dies > num_intlv_dies) {
661+
pr_debug("Invalid number of interleave dies: %u", ctx->map.num_intlv_dies);
662+
return false;
663+
}
664+
665+
if (ctx->map.num_intlv_sockets > num_intlv_sockets) {
666+
pr_debug("Invalid number of interleave sockets: %u", ctx->map.num_intlv_sockets);
667+
return false;
668+
}
669+
670+
return true;
671+
}
672+
673+
static int validate_address_map(struct addr_ctx *ctx)
674+
{
675+
switch (ctx->map.intlv_mode) {
676+
case DF2_2CHAN_HASH:
677+
case DF3_COD4_2CHAN_HASH:
678+
case DF3_COD2_4CHAN_HASH:
679+
case DF3_COD1_8CHAN_HASH:
680+
if (!map_bits_valid(ctx, 8, 9, 1, 1))
681+
goto err;
682+
break;
683+
684+
case DF4_NPS4_2CHAN_HASH:
685+
case DF4_NPS2_4CHAN_HASH:
686+
case DF4_NPS1_8CHAN_HASH:
687+
case DF4p5_NPS4_2CHAN_1K_HASH:
688+
case DF4p5_NPS4_2CHAN_2K_HASH:
689+
case DF4p5_NPS2_4CHAN_1K_HASH:
690+
case DF4p5_NPS2_4CHAN_2K_HASH:
691+
case DF4p5_NPS1_8CHAN_1K_HASH:
692+
case DF4p5_NPS1_8CHAN_2K_HASH:
693+
case DF4p5_NPS1_16CHAN_1K_HASH:
694+
case DF4p5_NPS1_16CHAN_2K_HASH:
695+
if (!map_bits_valid(ctx, 8, 8, 1, 2))
696+
goto err;
697+
break;
698+
699+
case MI3_HASH_8CHAN:
700+
case MI3_HASH_16CHAN:
701+
case MI3_HASH_32CHAN:
702+
if (!map_bits_valid(ctx, 8, 8, 4, 1))
703+
goto err;
704+
break;
705+
706+
/* Nothing to do for modes that don't need special validation checks. */
707+
default:
708+
break;
709+
}
710+
711+
return 0;
712+
713+
err:
714+
atl_debug(ctx, "Inconsistent address map");
715+
return -EINVAL;
716+
}
717+
645718
static void dump_address_map(struct dram_addr_map *map)
646719
{
647720
u8 i;
@@ -678,5 +751,9 @@ int get_address_map(struct addr_ctx *ctx)
678751

679752
dump_address_map(&ctx->map);
680753

754+
ret = validate_address_map(ctx);
755+
if (ret)
756+
return ret;
757+
681758
return ret;
682759
}

0 commit comments

Comments
 (0)