lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <d494ead2-73c9-e9e0-0082-0036efca35c7@huawei.com>
Date:   Thu, 14 Jan 2021 17:28:09 +0800
From:   "wangyanan (Y)" <wangyanan55@...wei.com>
To:     Will Deacon <will@...nel.org>
CC:     <linux-kernel@...r.kernel.org>,
        <linux-arm-kernel@...ts.infradead.org>,
        Marc Zyngier <maz@...nel.org>,
        Catalin Marinas <catalin.marinas@....com>,
        James Morse <james.morse@....com>,
        Julien Thierry <julien.thierry.kdev@...il.com>,
        Suzuki K Poulose <suzuki.poulose@....com>,
        Gavin Shan <gshan@...hat.com>,
        Quentin Perret <qperret@...gle.com>,
        <wanghaibin.wang@...wei.com>, <yezengruan@...wei.com>,
        <zhukeqian1@...wei.com>, <yuzenghui@...wei.com>
Subject: Re: [PATCH v2 2/3] KVM: arm64: Add prejudgement for relaxing
 permissions only case in stage2 translation fault handler


On 2021/1/13 23:44, Will Deacon wrote:
> On Wed, Dec 16, 2020 at 08:28:43PM +0800, Yanan Wang wrote:
>> In dirty-logging, or dirty-logging-stopped time, even normal running
>> time of a guest configed with huge mappings and numbers of vCPUs,
>> translation faults by different vCPUs on the same GPA could occur
>> successively almost at the same time. There are two reasons for it.
>>
>> (1) If there are some vCPUs accessing the same GPA at the same time and
>> the leaf PTE is not set yet, then they will all cause translation faults
>> and the first vCPU holding mmu_lock will set valid leaf PTE, and the
>> others will later update the old PTE with a new one if they are different.
>>
>> (2) When changing a leaf entry or a table entry with break-before-make,
>> if there are some vCPUs accessing the same GPA just catch the moment when
>> the target PTE is set invalid in a BBM procedure coincidentally, they will
>> all cause translation faults and will later update the old PTE with a new
>> one if they are different.
>>
>> The worst case can be like this: vCPU A causes a translation fault with RW
>> prot and sets the leaf PTE with RW permissions, and then the next vCPU B
>> with RO prot updates the PTE back to RO permissions with break-before-make.
>> And the BBM-invalid moment may trigger more unnecessary translation faults,
>> then some useless small loops might occur which could lead to vCPU stuck.
>>
>> To avoid unnecessary update and small loops, add prejudgement in the
>> translation fault handler: Skip updating the PTE with break-before-make
>> if we are trying to recreate the exact same mapping or only change the
>> access permissions. Actually, change of permissions will be handled
>> through the relax_perms path next time if necessary.
>>
>> Signed-off-by: Yanan Wang <wangyanan55@...wei.com>
>> ---
>>   arch/arm64/kvm/hyp/pgtable.c | 28 +++++++++++++++++++---------
>>   1 file changed, 19 insertions(+), 9 deletions(-)
>>
>> diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c
>> index 350f9f810930..8225ced49bad 100644
>> --- a/arch/arm64/kvm/hyp/pgtable.c
>> +++ b/arch/arm64/kvm/hyp/pgtable.c
>> @@ -45,6 +45,10 @@
>>   
>>   #define KVM_PTE_LEAF_ATTR_HI_S2_XN	BIT(54)
>>   
>> +#define KVM_PTE_LEAF_ATTR_S2_PERMS	(KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R | \
>> +					 KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W | \
>> +					 KVM_PTE_LEAF_ATTR_HI_S2_XN)
>> +
>>   struct kvm_pgtable_walk_data {
>>   	struct kvm_pgtable		*pgt;
>>   	struct kvm_pgtable_walker	*walker;
>> @@ -460,7 +464,7 @@ static int stage2_map_set_prot_attr(enum kvm_pgtable_prot prot,
>>   	return 0;
>>   }
>>   
>> -static bool stage2_map_walker_try_leaf(u64 addr, u64 end, u32 level,
>> +static int stage2_map_walker_try_leaf(u64 addr, u64 end, u32 level,
>>   				       kvm_pte_t *ptep,
>>   				       struct stage2_map_data *data)
>>   {
>> @@ -469,13 +473,18 @@ static bool stage2_map_walker_try_leaf(u64 addr, u64 end, u32 level,
>>   	struct page *page = virt_to_page(ptep);
>>   
>>   	if (!kvm_block_mapping_supported(addr, end, phys, level))
>> -		return false;
>> +		return 1;
> It would probably be cleaner to return another error code here, as we
> have failed to install a mapping (e.g. E2BIG or perhaps more perversely,
> ENOTBLK). Then the caller can decide to install a trable.
>
Ok, I will make some adjustment for this and post the v3 soon after.

Thanks,

Yanan.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ