mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-07 19:30:30 +09:00
ANDROID: KVM: arm64: Add __pkvm_guest_unshare_host()
Introduce __pkvm_guest_unshare_host() to remove host access to a page which was previously shared by protected guest. Signed-off-by: Will Deacon <will@kernel.org> Bug: 209580772 Change-Id: I0a11a2458d6ff5bf1e9b8ece871ba1383ed4611d Signed-off-by: Will Deacon <willdeacon@google.com>
This commit is contained in:
@@ -64,6 +64,7 @@ int __pkvm_host_donate_hyp(u64 pfn, u64 nr_pages);
|
||||
int __pkvm_hyp_donate_host(u64 pfn, u64 nr_pages);
|
||||
int __pkvm_host_share_guest(u64 pfn, u64 gfn, struct kvm_vcpu *vcpu);
|
||||
int __pkvm_guest_share_host(struct kvm_vcpu *vcpu, u64 ipa);
|
||||
int __pkvm_guest_unshare_host(struct kvm_vcpu *vcpu, u64 ipa);
|
||||
|
||||
bool addr_is_memory(phys_addr_t phys);
|
||||
int host_stage2_idmap_locked(phys_addr_t addr, u64 size, enum kvm_pgtable_prot prot);
|
||||
|
||||
@@ -860,6 +860,11 @@ static int host_ack_donation(u64 addr, const struct pkvm_mem_transition *tx)
|
||||
return __host_ack_transition(addr, tx, PKVM_NOPAGE);
|
||||
}
|
||||
|
||||
static int host_ack_unshare(u64 addr, const struct pkvm_mem_transition *tx)
|
||||
{
|
||||
return __host_ack_transition(addr, tx, PKVM_PAGE_SHARED_BORROWED);
|
||||
}
|
||||
|
||||
static int host_complete_share(u64 addr, const struct pkvm_mem_transition *tx,
|
||||
enum kvm_pgtable_prot perms)
|
||||
{
|
||||
@@ -868,6 +873,14 @@ static int host_complete_share(u64 addr, const struct pkvm_mem_transition *tx,
|
||||
return __host_set_page_state_range(addr, size, PKVM_PAGE_SHARED_BORROWED);
|
||||
}
|
||||
|
||||
static int host_complete_unshare(u64 addr, const struct pkvm_mem_transition *tx)
|
||||
{
|
||||
u64 size = tx->nr_pages * PAGE_SIZE;
|
||||
pkvm_id owner_id = initiator_owner_id(tx);
|
||||
|
||||
return host_stage2_set_owner_locked(addr, size, owner_id);
|
||||
}
|
||||
|
||||
static int host_complete_donation(u64 addr, const struct pkvm_mem_transition *tx)
|
||||
{
|
||||
u64 size = tx->nr_pages * PAGE_SIZE;
|
||||
@@ -1101,6 +1114,13 @@ static int guest_request_share(u64 *completer_addr,
|
||||
PKVM_PAGE_OWNED);
|
||||
}
|
||||
|
||||
static int guest_request_unshare(u64 *completer_addr,
|
||||
const struct pkvm_mem_transition *tx)
|
||||
{
|
||||
return __guest_request_page_transition(completer_addr, tx,
|
||||
PKVM_PAGE_SHARED_OWNED);
|
||||
}
|
||||
|
||||
static int __guest_initiate_page_transition(u64 *completer_addr,
|
||||
const struct pkvm_mem_transition *tx,
|
||||
enum pkvm_page_state state)
|
||||
@@ -1136,6 +1156,13 @@ static int guest_initiate_share(u64 *completer_addr,
|
||||
PKVM_PAGE_SHARED_OWNED);
|
||||
}
|
||||
|
||||
static int guest_initiate_unshare(u64 *completer_addr,
|
||||
const struct pkvm_mem_transition *tx)
|
||||
{
|
||||
return __guest_initiate_page_transition(completer_addr, tx,
|
||||
PKVM_PAGE_OWNED);
|
||||
}
|
||||
|
||||
static int check_share(struct pkvm_mem_share *share)
|
||||
{
|
||||
const struct pkvm_mem_transition *tx = &share->tx;
|
||||
@@ -1240,6 +1267,9 @@ static int check_unshare(struct pkvm_mem_share *share)
|
||||
case PKVM_ID_HOST:
|
||||
ret = host_request_unshare(&completer_addr, tx);
|
||||
break;
|
||||
case PKVM_ID_GUEST:
|
||||
ret = guest_request_unshare(&completer_addr, tx);
|
||||
break;
|
||||
default:
|
||||
ret = -EINVAL;
|
||||
}
|
||||
@@ -1248,6 +1278,9 @@ static int check_unshare(struct pkvm_mem_share *share)
|
||||
return ret;
|
||||
|
||||
switch (tx->completer.id) {
|
||||
case PKVM_ID_HOST:
|
||||
ret = host_ack_unshare(completer_addr, tx);
|
||||
break;
|
||||
case PKVM_ID_HYP:
|
||||
ret = hyp_ack_unshare(completer_addr, tx);
|
||||
break;
|
||||
@@ -1268,6 +1301,9 @@ static int __do_unshare(struct pkvm_mem_share *share)
|
||||
case PKVM_ID_HOST:
|
||||
ret = host_initiate_unshare(&completer_addr, tx);
|
||||
break;
|
||||
case PKVM_ID_GUEST:
|
||||
ret = guest_initiate_unshare(&completer_addr, tx);
|
||||
break;
|
||||
default:
|
||||
ret = -EINVAL;
|
||||
}
|
||||
@@ -1276,6 +1312,9 @@ static int __do_unshare(struct pkvm_mem_share *share)
|
||||
return ret;
|
||||
|
||||
switch (tx->completer.id) {
|
||||
case PKVM_ID_HOST:
|
||||
ret = host_complete_unshare(completer_addr, tx);
|
||||
break;
|
||||
case PKVM_ID_HYP:
|
||||
ret = hyp_complete_unshare(completer_addr, tx);
|
||||
break;
|
||||
@@ -1458,6 +1497,37 @@ int __pkvm_guest_share_host(struct kvm_vcpu *vcpu, u64 ipa)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int __pkvm_guest_unshare_host(struct kvm_vcpu *vcpu, u64 ipa)
|
||||
{
|
||||
int ret;
|
||||
struct pkvm_mem_share share = {
|
||||
.tx = {
|
||||
.nr_pages = 1,
|
||||
.initiator = {
|
||||
.id = PKVM_ID_GUEST,
|
||||
.addr = ipa,
|
||||
.guest = {
|
||||
.vcpu = vcpu,
|
||||
},
|
||||
},
|
||||
.completer = {
|
||||
.id = PKVM_ID_HOST,
|
||||
},
|
||||
},
|
||||
.completer_prot = PKVM_HOST_MEM_PROT,
|
||||
};
|
||||
|
||||
host_lock_component();
|
||||
guest_lock_component(vcpu);
|
||||
|
||||
ret = do_unshare(&share);
|
||||
|
||||
guest_unlock_component(vcpu);
|
||||
host_unlock_component();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int __pkvm_host_unshare_hyp(u64 pfn)
|
||||
{
|
||||
int ret;
|
||||
|
||||
Reference in New Issue
Block a user