Skip to content

Commit de544d1

Browse files
jgunthorpegregkh
authored andcommitted
mm: always have io_remap_pfn_range() set pgprot_decrypted()
commit f8f6ae5 upstream. The purpose of io_remap_pfn_range() is to map IO memory, such as a memory mapped IO exposed through a PCI BAR. IO devices do not understand encryption, so this memory must always be decrypted. Automatically call pgprot_decrypted() as part of the generic implementation. This fixes a bug where enabling AMD SME causes subsystems, such as RDMA, using io_remap_pfn_range() to expose BAR pages to user space to fail. The CPU will encrypt access to those BAR pages instead of passing unencrypted IO directly to the device. Places not mapping IO should use remap_pfn_range(). Fixes: aca20d5 ("x86/mm: Add support to make use of Secure Memory Encryption") Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Tom Lendacky <thomas.lendacky@amd.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Andrey Ryabinin <aryabinin@virtuozzo.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Brijesh Singh <brijesh.singh@amd.com> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: "Dave Young" <dyoung@redhat.com> Cc: Alexander Potapenko <glider@google.com> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Larry Woodman <lwoodman@redhat.com> Cc: Matt Fleming <matt@codeblueprint.co.uk> Cc: Ingo Molnar <mingo@kernel.org> Cc: "Michael S. Tsirkin" <mst@redhat.com> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Rik van Riel <riel@redhat.com> Cc: Toshimitsu Kani <toshi.kani@hpe.com> Cc: <stable@vger.kernel.org> Link: https://lkml.kernel.org/r/0-v1-025d64bdf6c4+e-amd_sme_fix_jgg@nvidia.com Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 08bf0cd commit de544d1

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

include/linux/mm.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2735,6 +2735,15 @@ static inline vm_fault_t vmf_insert_page(struct vm_area_struct *vma,
27352735
return VM_FAULT_NOPAGE;
27362736
}
27372737

2738+
#ifndef io_remap_pfn_range
2739+
static inline int io_remap_pfn_range(struct vm_area_struct *vma,
2740+
unsigned long addr, unsigned long pfn,
2741+
unsigned long size, pgprot_t prot)
2742+
{
2743+
return remap_pfn_range(vma, addr, pfn, size, pgprot_decrypted(prot));
2744+
}
2745+
#endif
2746+
27382747
static inline vm_fault_t vmf_error(int err)
27392748
{
27402749
if (err == -ENOMEM)

include/linux/pgtable.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,10 +1399,6 @@ typedef unsigned int pgtbl_mod_mask;
13991399

14001400
#endif /* !__ASSEMBLY__ */
14011401

1402-
#ifndef io_remap_pfn_range
1403-
#define io_remap_pfn_range remap_pfn_range
1404-
#endif
1405-
14061402
#ifndef has_transparent_hugepage
14071403
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
14081404
#define has_transparent_hugepage() 1

0 commit comments

Comments
 (0)