From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63EBDC433E6 for ; Thu, 14 Jan 2021 09:30:00 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0790123A22 for ; Thu, 14 Jan 2021 09:29:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0790123A22 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Type: Content-Transfer-Encoding:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=FsBWqmoUjpXuYyfhHBUU3U/AD7WRE+WEouRYOUqktwI=; b=Og9fMk1yKT6Z+QEMjyhPN34m0 CG+yw27ZlgI9cvWxubHpd1BQh+c7/imndBB+8vZ2aV86wR6mhd4T88wrdmNHolWU99aI8qhWpf/VU UgTQIh8rfG51HkGOfIDWOf8K1QQsNOnqSfayX7CcaQeWqo4H7YcaJYOQfNTeqTGFK88Uc4oAZ5t0G ipOixLvYEObnM/orthK9UXFR6eKd8zEhKT61ApG97tTCyFLlAKtuH82pFxy52Uw5lbwiJPixqE9eC cMzt8hlfw71WkONVEPM376Xc9ZAWUSKSiJFC+aXOFwygefaxr+Qy0GV7kKT+EdtSoExllRxDSqzz5 D6bV51Qiw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kzyvS-0004iQ-HR; Thu, 14 Jan 2021 09:28:18 +0000 Received: from szxga08-in.huawei.com ([45.249.212.255]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kzyvP-0004gp-6R for linux-arm-kernel@lists.infradead.org; Thu, 14 Jan 2021 09:28:16 +0000 Received: from dggeme709-chm.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4DGf802hKGz13hBP; Thu, 14 Jan 2021 17:26:24 +0800 (CST) Received: from [10.174.187.128] (10.174.187.128) by dggeme709-chm.china.huawei.com (10.1.199.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2106.2; Thu, 14 Jan 2021 17:28:04 +0800 Subject: Re: [PATCH v2 3/3] KVM: arm64: Mark the page dirty only if the fault is handled successfully To: Will Deacon References: <20201216122844.25092-1-wangyanan55@huawei.com> <20201216122844.25092-4-wangyanan55@huawei.com> <20210113155101.GB11892@willie-the-truck> From: "wangyanan (Y)" Message-ID: <6cd9c7ba-cb73-bb77-3cfc-e06b204a76d9@huawei.com> Date: Thu, 14 Jan 2021 17:28:04 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 In-Reply-To: <20210113155101.GB11892@willie-the-truck> Content-Language: en-US X-Originating-IP: [10.174.187.128] X-ClientProxiedBy: dggeme702-chm.china.huawei.com (10.1.199.98) To dggeme709-chm.china.huawei.com (10.1.199.105) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210114_042815_548581_1579CBCF X-CRM114-Status: GOOD ( 17.36 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gavin Shan , Suzuki K Poulose , Marc Zyngier , Quentin Perret , linux-kernel@vger.kernel.org, yezengruan@huawei.com, James Morse , linux-arm-kernel@lists.infradead.org, Catalin Marinas , yuzenghui@huawei.com, wanghaibin.wang@huawei.com, zhukeqian1@huawei.com, Julien Thierry Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 2021/1/13 23:51, Will Deacon wrote: > On Wed, Dec 16, 2020 at 08:28:44PM +0800, Yanan Wang wrote: >> We now mark the page dirty and set the bitmap before calling fault handlers >> in user_mem_abort(), and we might end up having spurious dirty pages if >> update of permissions or mapping has failed. >> So, mark the page dirty only if the fault is handled successfully. >> >> Let the guest directly enter again but not return to userspace if we were >> trying to recreate the same mapping or only change access permissions >> with BBM, which is not permitted in the mapping path. >> >> Signed-off-by: Yanan Wang >> --- >> arch/arm64/kvm/mmu.c | 18 ++++++++++++++---- >> 1 file changed, 14 insertions(+), 4 deletions(-) >> >> diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c >> index 75814a02d189..72e516a10914 100644 >> --- a/arch/arm64/kvm/mmu.c >> +++ b/arch/arm64/kvm/mmu.c >> @@ -879,11 +879,8 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, >> if (vma_pagesize == PAGE_SIZE && !force_pte) >> vma_pagesize = transparent_hugepage_adjust(memslot, hva, >> &pfn, &fault_ipa); >> - if (writable) { >> + if (writable) >> prot |= KVM_PGTABLE_PROT_W; >> - kvm_set_pfn_dirty(pfn); >> - mark_page_dirty(kvm, gfn); >> - } >> >> if (fault_status != FSC_PERM && !device) >> clean_dcache_guest_page(pfn, vma_pagesize); >> @@ -911,6 +908,19 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, >> memcache); >> } >> >> + /* Mark the page dirty only if the fault is handled successfully */ >> + if (writable && !ret) { >> + kvm_set_pfn_dirty(pfn); >> + mark_page_dirty(kvm, gfn); >> + } >> + >> + /* Let the guest directly enter again if we were trying to recreate the >> + * same mapping or only change access permissions with BBM, which is not >> + * permitted in the mapping path. >> + */ >> + if (ret == -EAGAIN) >> + ret = 0; > Maybe just 'return ret != -EAGAIN ? ret : 0;' at the end of the function? Yes, it's more concise. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel