x86/altp2m: p2m_altp2m_get_or_propagate() should honor ap2m->default_access

This patch addresses a behavior discrepancy in the handling of altp2m views,
where upon the creation and subsequent EPT violation, the page access
permissions were incorrectly inherited from the hostp2m instead of respecting
the altp2m default_access.

Previously, when a new altp2m view was established with restrictive
default_access permissions and activated via xc_altp2m_switch_to_view(),
it failed to trigger an event on the first access violation.  This behavior
diverged from the intended mechanism, where the altp2m's default_access
should dictate the initial permissions, ensuring proper event triggering on
access violations.

The correction involves modifying the handling mechanism to respect the
altp2m view's default_access upon its activation, eliminating the need for
setting memory access permissions for the entire altp2m range (e.g. within
xen-access.c).  This change not only aligns the behavior with the expected
access control logic but also results in a significant performance improvement
by reducing the overhead associated with setting memory access permissions
across the altp2m range.

Signed-off-by: Petr Beneš <w1benny@gmail.com>
Acked-by: Tamas K Lengyel <tamas@tklengyel.com>
This commit is contained in:
Petr Beneš authored and Andrew Cooper committed 2024-02-23 17:43:06 +00:00
1 parent 98e79be5b6
commit 7e5b662b28
2 files changed
+3 -14

No files matched your search

-14
View File
@@ -517,9 +517,6 @@ int main(int argc, char *argv[])
/* With altp2m we just create a new, restricted view of the memory */
if ( memaccess && altp2m )
{
xen_pfn_t gfn = 0;
unsigned long perm_set = 0;
if( altp2m_write_no_gpt )
{
rc = xc_monitor_inguest_pagefault(xch, domain_id, 1);
@@ -551,17 +548,6 @@ int main(int argc, char *argv[])
}
DPRINTF("altp2m view created with id %u\n", altp2m_view_id);
DPRINTF("Setting altp2m mem_access permissions.. ");
for(; gfn < xenaccess->max_gpfn; ++gfn)
{
rc = xc_altp2m_set_mem_access( xch, domain_id, altp2m_view_id, gfn,
default_access);
if ( !rc )
perm_set++;
}
DPRINTF("done! Permissions set on %lu pages.\n", perm_set);
rc = xc_altp2m_switch_to_view( xch, domain_id, altp2m_view_id );
if ( rc < 0 )
+3
View File
@@ -1850,6 +1850,9 @@ bool p2m_altp2m_get_or_propagate(struct p2m_domain *ap2m, unsigned long gfn_l,
amfn = _mfn(mfn_x(*mfn) & mask);
gfn = _gfn(gfn_l & mask);
/* Override the altp2m entry with its default access. */
*p2ma = ap2m->default_access;
rc = p2m_set_entry(ap2m, gfn, amfn, cur_order, *p2mt, *p2ma);
p2m_unlock(ap2m);
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.