Skip to content

Commit 89e927b

Browse files
kaccardiKAGA-KOKO
authored andcommitted
x86/sgx: Replace kmap/kunmap_atomic() calls
kmap_local_page() is the preferred way to create temporary mappings when it is feasible, because the mappings are thread-local and CPU-local. kmap_local_page() uses per-task maps rather than per-CPU maps. This in effect removes the need to disable preemption on the local CPU while the mapping is active, and thus vastly reduces overall system latency. It is also valid to take pagefaults within the mapped region. The use of kmap_atomic() in the SGX code was not an explicit design choice to disable page faults or preemption, and there is no compelling design reason to using kmap_atomic() vs. kmap_local_page(). Signed-off-by: Kristen Carlson Accardi <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Reviewed-by: Fabio M. De Francesco <[email protected]> Reviewed-by: Ira Weiny <[email protected]> Link: https://lore.kernel.org/linux-sgx/Y0biN3%[email protected]/ Link: https://lore.kernel.org/r/[email protected]
1 parent 16a7fe3 commit 89e927b

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

arch/x86/kernel/cpu/sgx/encl.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ static int __sgx_encl_eldu(struct sgx_encl_page *encl_page,
160160
return ret;
161161

162162
pginfo.addr = encl_page->desc & PAGE_MASK;
163-
pginfo.contents = (unsigned long)kmap_atomic(b.contents);
164-
pcmd_page = kmap_atomic(b.pcmd);
163+
pginfo.contents = (unsigned long)kmap_local_page(b.contents);
164+
pcmd_page = kmap_local_page(b.pcmd);
165165
pginfo.metadata = (unsigned long)pcmd_page + b.pcmd_offset;
166166

167167
if (secs_page)
@@ -187,8 +187,8 @@ static int __sgx_encl_eldu(struct sgx_encl_page *encl_page,
187187
*/
188188
pcmd_page_empty = !memchr_inv(pcmd_page, 0, PAGE_SIZE);
189189

190-
kunmap_atomic(pcmd_page);
191-
kunmap_atomic((void *)(unsigned long)pginfo.contents);
190+
kunmap_local(pcmd_page);
191+
kunmap_local((void *)(unsigned long)pginfo.contents);
192192

193193
get_page(b.pcmd);
194194
sgx_encl_put_backing(&b);
@@ -197,10 +197,10 @@ static int __sgx_encl_eldu(struct sgx_encl_page *encl_page,
197197

198198
if (pcmd_page_empty && !reclaimer_writing_to_pcmd(encl, pcmd_first_page)) {
199199
sgx_encl_truncate_backing_page(encl, PFN_DOWN(page_pcmd_off));
200-
pcmd_page = kmap_atomic(b.pcmd);
200+
pcmd_page = kmap_local_page(b.pcmd);
201201
if (memchr_inv(pcmd_page, 0, PAGE_SIZE))
202202
pr_warn("PCMD page not empty after truncate.\n");
203-
kunmap_atomic(pcmd_page);
203+
kunmap_local(pcmd_page);
204204
}
205205

206206
put_page(b.pcmd);

arch/x86/kernel/cpu/sgx/ioctl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,11 @@ static int __sgx_encl_add_page(struct sgx_encl *encl,
221221
pginfo.secs = (unsigned long)sgx_get_epc_virt_addr(encl->secs.epc_page);
222222
pginfo.addr = encl_page->desc & PAGE_MASK;
223223
pginfo.metadata = (unsigned long)secinfo;
224-
pginfo.contents = (unsigned long)kmap_atomic(src_page);
224+
pginfo.contents = (unsigned long)kmap_local_page(src_page);
225225

226226
ret = __eadd(&pginfo, sgx_get_epc_virt_addr(epc_page));
227227

228-
kunmap_atomic((void *)pginfo.contents);
228+
kunmap_local((void *)pginfo.contents);
229229
put_page(src_page);
230230

231231
return ret ? -EIO : 0;

arch/x86/kernel/cpu/sgx/main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,17 +165,17 @@ static int __sgx_encl_ewb(struct sgx_epc_page *epc_page, void *va_slot,
165165
pginfo.addr = 0;
166166
pginfo.secs = 0;
167167

168-
pginfo.contents = (unsigned long)kmap_atomic(backing->contents);
169-
pginfo.metadata = (unsigned long)kmap_atomic(backing->pcmd) +
168+
pginfo.contents = (unsigned long)kmap_local_page(backing->contents);
169+
pginfo.metadata = (unsigned long)kmap_local_page(backing->pcmd) +
170170
backing->pcmd_offset;
171171

172172
ret = __ewb(&pginfo, sgx_get_epc_virt_addr(epc_page), va_slot);
173173
set_page_dirty(backing->pcmd);
174174
set_page_dirty(backing->contents);
175175

176-
kunmap_atomic((void *)(unsigned long)(pginfo.metadata -
176+
kunmap_local((void *)(unsigned long)(pginfo.metadata -
177177
backing->pcmd_offset));
178-
kunmap_atomic((void *)(unsigned long)pginfo.contents);
178+
kunmap_local((void *)(unsigned long)pginfo.contents);
179179

180180
return ret;
181181
}

0 commit comments

Comments
 (0)