summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar liamwhite2024-01-25 16:21:38 -0500
committerGravatar GitHub2024-01-25 16:21:38 -0500
commite04368ad7cf4c8d8820ef4da451d9954ff38cb2d (patch)
treebe7e40d1bcd44304eff90e6e5a7a49c02628111e /src
parentMerge pull request #12777 from t895/firmware-warning (diff)
parentnvservices: close map handles on session close (diff)
downloadyuzu-e04368ad7cf4c8d8820ef4da451d9954ff38cb2d.tar.gz
yuzu-e04368ad7cf4c8d8820ef4da451d9954ff38cb2d.tar.xz
yuzu-e04368ad7cf4c8d8820ef4da451d9954ff38cb2d.zip
Merge pull request #12759 from liamwhite/mp-misc
core: miscellaneous fixes
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/kernel/k_page_table_base.cpp13
-rw-r--r--src/core/hle/service/nvdrv/core/container.cpp1
-rw-r--r--src/core/hle/service/nvdrv/core/nvmap.cpp13
-rw-r--r--src/core/hle/service/nvdrv/core/nvmap.h2
4 files changed, 25 insertions, 4 deletions
diff --git a/src/core/hle/kernel/k_page_table_base.cpp b/src/core/hle/kernel/k_page_table_base.cpp
index 3f0a39d33..1dd86fb3c 100644
--- a/src/core/hle/kernel/k_page_table_base.cpp
+++ b/src/core/hle/kernel/k_page_table_base.cpp
@@ -69,9 +69,14 @@ public:
69}; 69};
70 70
71template <typename AddressType> 71template <typename AddressType>
72void InvalidateInstructionCache(KernelCore& kernel, AddressType addr, u64 size) { 72void InvalidateInstructionCache(KernelCore& kernel, KPageTableBase* table, AddressType addr,
73 u64 size) {
73 // TODO: lock the process list 74 // TODO: lock the process list
74 for (auto& process : kernel.GetProcessList()) { 75 for (auto& process : kernel.GetProcessList()) {
76 if (std::addressof(process->GetPageTable().GetBasePageTable()) != table) {
77 continue;
78 }
79
75 for (size_t i = 0; i < Core::Hardware::NUM_CPU_CORES; i++) { 80 for (size_t i = 0; i < Core::Hardware::NUM_CPU_CORES; i++) {
76 auto* interface = process->GetArmInterface(i); 81 auto* interface = process->GetArmInterface(i);
77 if (interface) { 82 if (interface) {
@@ -1302,7 +1307,7 @@ Result KPageTableBase::UnmapCodeMemory(KProcessAddress dst_address, KProcessAddr
1302 bool reprotected_pages = false; 1307 bool reprotected_pages = false;
1303 SCOPE_EXIT({ 1308 SCOPE_EXIT({
1304 if (reprotected_pages && any_code_pages) { 1309 if (reprotected_pages && any_code_pages) {
1305 InvalidateInstructionCache(m_kernel, dst_address, size); 1310 InvalidateInstructionCache(m_kernel, this, dst_address, size);
1306 } 1311 }
1307 }); 1312 });
1308 1313
@@ -2036,7 +2041,7 @@ Result KPageTableBase::SetProcessMemoryPermission(KProcessAddress addr, size_t s
2036 for (const auto& block : pg) { 2041 for (const auto& block : pg) {
2037 StoreDataCache(GetHeapVirtualPointer(m_kernel, block.GetAddress()), block.GetSize()); 2042 StoreDataCache(GetHeapVirtualPointer(m_kernel, block.GetAddress()), block.GetSize());
2038 } 2043 }
2039 InvalidateInstructionCache(m_kernel, addr, size); 2044 InvalidateInstructionCache(m_kernel, this, addr, size);
2040 } 2045 }
2041 2046
2042 R_SUCCEED(); 2047 R_SUCCEED();
@@ -3277,7 +3282,7 @@ Result KPageTableBase::WriteDebugMemory(KProcessAddress dst_address, KProcessAdd
3277 R_TRY(PerformCopy()); 3282 R_TRY(PerformCopy());
3278 3283
3279 // Invalidate the instruction cache, as this svc allows modifying executable pages. 3284 // Invalidate the instruction cache, as this svc allows modifying executable pages.
3280 InvalidateInstructionCache(m_kernel, dst_address, size); 3285 InvalidateInstructionCache(m_kernel, this, dst_address, size);
3281 3286
3282 R_SUCCEED(); 3287 R_SUCCEED();
3283} 3288}
diff --git a/src/core/hle/service/nvdrv/core/container.cpp b/src/core/hle/service/nvdrv/core/container.cpp
index 21ef57d27..dc1b4d5be 100644
--- a/src/core/hle/service/nvdrv/core/container.cpp
+++ b/src/core/hle/service/nvdrv/core/container.cpp
@@ -112,6 +112,7 @@ SessionId Container::OpenSession(Kernel::KProcess* process) {
112 112
113void Container::CloseSession(SessionId session_id) { 113void Container::CloseSession(SessionId session_id) {
114 std::scoped_lock lk(impl->session_guard); 114 std::scoped_lock lk(impl->session_guard);
115 impl->file.UnmapAllHandles(session_id);
115 auto& session = impl->sessions[session_id.id]; 116 auto& session = impl->sessions[session_id.id];
116 auto& smmu = impl->host1x.MemoryManager(); 117 auto& smmu = impl->host1x.MemoryManager();
117 if (session.has_preallocated_area) { 118 if (session.has_preallocated_area) {
diff --git a/src/core/hle/service/nvdrv/core/nvmap.cpp b/src/core/hle/service/nvdrv/core/nvmap.cpp
index 1b59c6b15..bc1c033c6 100644
--- a/src/core/hle/service/nvdrv/core/nvmap.cpp
+++ b/src/core/hle/service/nvdrv/core/nvmap.cpp
@@ -326,4 +326,17 @@ std::optional<NvMap::FreeInfo> NvMap::FreeHandle(Handle::Id handle, bool interna
326 return freeInfo; 326 return freeInfo;
327} 327}
328 328
329void NvMap::UnmapAllHandles(NvCore::SessionId session_id) {
330 auto handles_copy = [&] {
331 std::scoped_lock lk{handles_lock};
332 return handles;
333 }();
334
335 for (auto& [id, handle] : handles_copy) {
336 if (handle->session_id.id == session_id.id) {
337 FreeHandle(id, false);
338 }
339 }
340}
341
329} // namespace Service::Nvidia::NvCore 342} // namespace Service::Nvidia::NvCore
diff --git a/src/core/hle/service/nvdrv/core/nvmap.h b/src/core/hle/service/nvdrv/core/nvmap.h
index d7f695845..b8be599ae 100644
--- a/src/core/hle/service/nvdrv/core/nvmap.h
+++ b/src/core/hle/service/nvdrv/core/nvmap.h
@@ -152,6 +152,8 @@ public:
152 */ 152 */
153 std::optional<FreeInfo> FreeHandle(Handle::Id handle, bool internal_session); 153 std::optional<FreeInfo> FreeHandle(Handle::Id handle, bool internal_session);
154 154
155 void UnmapAllHandles(NvCore::SessionId session_id);
156
155private: 157private:
156 std::list<std::shared_ptr<Handle>> unmap_queue{}; 158 std::list<std::shared_ptr<Handle>> unmap_queue{};
157 std::mutex unmap_queue_lock{}; //!< Protects access to `unmap_queue` 159 std::mutex unmap_queue_lock{}; //!< Protects access to `unmap_queue`