From 09c40688e126011d58da4763dc0f3308d957a612 Mon Sep 17 00:00:00 2001 From: Johannes Schlatow Date: Mon, 24 Jun 2024 18:07:00 +0200 Subject: [PATCH] platform/pc: remove translations after Out_of_ram Since page tables might need to be allocated during insert_translation(), Out_of_ram or Out_of_caps exceptions might occur. Entries that have already been added by insert_translation() must thus be removed once one of those exceptions occurred. Fixes #5254 --- .../pc/src/driver/platform/pc/intel/io_mmu.cc | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/repos/pc/src/driver/platform/pc/intel/io_mmu.cc b/repos/pc/src/driver/platform/pc/intel/io_mmu.cc index be49fa3291..1c50d5ae4d 100644 --- a/repos/pc/src/driver/platform/pc/intel/io_mmu.cc +++ b/repos/pc/src/driver/platform/pc/intel/io_mmu.cc @@ -74,10 +74,23 @@ void Intel::Io_mmu::Domain::add_range(Range const & range, Page_flags flags { RW, NO_EXEC, USER, NO_GLOBAL, RAM, Genode::CACHED }; - _translation_table.insert_translation(vaddr, paddr, size, flags, - _table_allocator, - !_intel_iommu.coherent_page_walk(), - _intel_iommu.supported_page_sizes()); + auto cleanup_partial_translations = [&] () { + _translation_table.remove_translation(vaddr, size, _table_allocator, + !_intel_iommu.coherent_page_walk()); + }; + + try { + _translation_table.insert_translation(vaddr, paddr, size, flags, + _table_allocator, + !_intel_iommu.coherent_page_walk(), + _intel_iommu.supported_page_sizes()); + } catch (Out_of_ram) { + cleanup_partial_translations(); + throw; + } catch (Out_of_caps) { + cleanup_partial_translations(); + throw; + } if (_skip_invalidation) return;