Skip to content

Commit 2bc872f

Browse files
lian-bojfvogel
authored andcommitted
x86/ioremap: add a function ioremap_encrypted() to remap kdump old memory
Orabug: 28796835 When SME is enabled on AMD machine, the memory is encrypted in the first kernel. In this case, SME also needs to be enabled in kdump kernel, and we have to remap the old memory with the memory encryption mask. Signed-off-by: Lianbo Jiang <[email protected]> Signed-off-by: Lianbo Jiang <[email protected]> Signed-off-by: Dan Duval <[email protected]> Reviewed-by: Henry Willard <[email protected]>
1 parent 5e6f44a commit 2bc872f

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

arch/x86/include/asm/io.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ extern void __iomem *ioremap_cache(resource_size_t offset, unsigned long size);
192192
#define ioremap_cache ioremap_cache
193193
extern void __iomem *ioremap_prot(resource_size_t offset, unsigned long size, unsigned long prot_val);
194194
#define ioremap_prot ioremap_prot
195+
extern void __iomem *ioremap_encrypted(resource_size_t phys_addr,
196+
unsigned long size);
197+
#define ioremap_encrypted ioremap_encrypted
195198

196199
/**
197200
* ioremap - map bus memory into CPU space

arch/x86/mm/ioremap.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <asm/pgalloc.h>
2525
#include <asm/pat.h>
2626
#include <asm/setup.h>
27+
#include <linux/crash_dump.h>
2728

2829
#include "physaddr.h"
2930

@@ -131,7 +132,8 @@ static void __ioremap_check_mem(resource_size_t addr, unsigned long size,
131132
* caller shouldn't need to know that small detail.
132133
*/
133134
static void __iomem *__ioremap_caller(resource_size_t phys_addr,
134-
unsigned long size, enum page_cache_mode pcm, void *caller)
135+
unsigned long size, enum page_cache_mode pcm,
136+
void *caller, bool encrypted)
135137
{
136138
unsigned long offset, vaddr;
137139
resource_size_t last_addr;
@@ -199,7 +201,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
199201
* resulting mapping.
200202
*/
201203
prot = PAGE_KERNEL_IO;
202-
if (sev_active() && mem_flags.desc_other)
204+
if ((sev_active() && mem_flags.desc_other) || encrypted)
203205
prot = pgprot_encrypted(prot);
204206

205207
switch (pcm) {
@@ -291,7 +293,7 @@ void __iomem *ioremap_nocache(resource_size_t phys_addr, unsigned long size)
291293
enum page_cache_mode pcm = _PAGE_CACHE_MODE_UC_MINUS;
292294

293295
return __ioremap_caller(phys_addr, size, pcm,
294-
__builtin_return_address(0));
296+
__builtin_return_address(0), false);
295297
}
296298
EXPORT_SYMBOL(ioremap_nocache);
297299

@@ -324,7 +326,7 @@ void __iomem *ioremap_uc(resource_size_t phys_addr, unsigned long size)
324326
enum page_cache_mode pcm = _PAGE_CACHE_MODE_UC;
325327

326328
return __ioremap_caller(phys_addr, size, pcm,
327-
__builtin_return_address(0));
329+
__builtin_return_address(0), false);
328330
}
329331
EXPORT_SYMBOL_GPL(ioremap_uc);
330332

@@ -341,7 +343,7 @@ EXPORT_SYMBOL_GPL(ioremap_uc);
341343
void __iomem *ioremap_wc(resource_size_t phys_addr, unsigned long size)
342344
{
343345
return __ioremap_caller(phys_addr, size, _PAGE_CACHE_MODE_WC,
344-
__builtin_return_address(0));
346+
__builtin_return_address(0), false);
345347
}
346348
EXPORT_SYMBOL(ioremap_wc);
347349

@@ -358,14 +360,21 @@ EXPORT_SYMBOL(ioremap_wc);
358360
void __iomem *ioremap_wt(resource_size_t phys_addr, unsigned long size)
359361
{
360362
return __ioremap_caller(phys_addr, size, _PAGE_CACHE_MODE_WT,
361-
__builtin_return_address(0));
363+
__builtin_return_address(0), false);
362364
}
363365
EXPORT_SYMBOL(ioremap_wt);
364366

367+
void __iomem *ioremap_encrypted(resource_size_t phys_addr, unsigned long size)
368+
{
369+
return __ioremap_caller(phys_addr, size, _PAGE_CACHE_MODE_WB,
370+
__builtin_return_address(0), true);
371+
}
372+
EXPORT_SYMBOL(ioremap_encrypted);
373+
365374
void __iomem *ioremap_cache(resource_size_t phys_addr, unsigned long size)
366375
{
367376
return __ioremap_caller(phys_addr, size, _PAGE_CACHE_MODE_WB,
368-
__builtin_return_address(0));
377+
__builtin_return_address(0), false);
369378
}
370379
EXPORT_SYMBOL(ioremap_cache);
371380

@@ -374,7 +383,7 @@ void __iomem *ioremap_prot(resource_size_t phys_addr, unsigned long size,
374383
{
375384
return __ioremap_caller(phys_addr, size,
376385
pgprot2cachemode(__pgprot(prot_val)),
377-
__builtin_return_address(0));
386+
__builtin_return_address(0), false);
378387
}
379388
EXPORT_SYMBOL(ioremap_prot);
380389

0 commit comments

Comments
 (0)