Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp218261pxb; Thu, 14 Jan 2021 04:17:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJxYFtEMmXjXNXR8kdwRf4M3jM0uqtZQTXCQbK33xslmvvHleuTBYlNmU990Y9um5k/lJnNm X-Received: by 2002:a05:6402:4251:: with SMTP id g17mr5357260edb.205.1610626643228; Thu, 14 Jan 2021 04:17:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610626643; cv=none; d=google.com; s=arc-20160816; b=kLmr1L5QjG8VAK02oCAOD+dPR5nvW5xGmZTzw2SQHdaLkmYknRidF3XqItOig48iKA nDXd8Kl71ZzN16cb+DRYIpauf6t9ZLHDctV+JKdXQOkx1fYi37DWihk7YAZIigS+ew6U DBmXb/Z7TEOvDHLJWidZz/6AdCXRl3KwkSrIDGG4l8cAQCxvKYUw1WtCVP2RLnwhN1ci 6ZLuerUITCqWlACssP5sep2VLKvVIeyk5HtAdst7BRAR46gSEfrjOjtsGG1OAVazu0Ko oEJ5sinR++ApRGRbKojS7Oihp0YZRtWmnQFhxTEI9hh6/DL8R0Gd6wTBJmHgseVAuja5 ZgZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=GJUWXLsnCNUM8Tq+vmChqCb5dS3eNJvcMP8RrWj5OR8=; b=MBXeg04aADWxaT3zVMnrI4MaJL8h9D6xgtSSescRp6AFcYKo+EmZTdkrXBACEPMmkq 3xHnYefQoe438iGjfav1Sb4CGBSWmIMS+SOgY82b3hWoekN2Z1YNmkXNrusB3TkRw4Sf UJ5FuTLovrcmxsHbJYwHXiRwdSK/msvwLaY9s7GzcMOeg5BXXRi2awD8Uy//q9LtUiBf lB8vonB6iEXRyNQkjabnGZHYoUUxZ5e48E/I4/rVctjyBr5t+Pe5dodgb6UbXQBrcITR RZbRJfPRWC1401mritTXqsz+uE9/cAuL6MCuL6Nh/rXezURT+IbFbATGtKViRTqK6C4G nYMQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c1si2411548edm.144.2021.01.14.04.16.57; Thu, 14 Jan 2021 04:17:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729062AbhANMOv (ORCPT + 99 others); Thu, 14 Jan 2021 07:14:51 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:11384 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727416AbhANMOv (ORCPT ); Thu, 14 Jan 2021 07:14:51 -0500 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4DGjrD61f6z7VLk; Thu, 14 Jan 2021 20:13:00 +0800 (CST) Received: from DESKTOP-TMVL5KK.china.huawei.com (10.174.187.128) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.498.0; Thu, 14 Jan 2021 20:13:55 +0800 From: Yanan Wang To: Marc Zyngier , Will Deacon , "Catalin Marinas" , , , , CC: James Morse , Julien Thierry , Suzuki K Poulose , Gavin Shan , Quentin Perret , , , , , Yanan Wang Subject: [PATCH v3 3/3] KVM: arm64: Mark the page dirty only if the fault is handled successfully Date: Thu, 14 Jan 2021 20:13:50 +0800 Message-ID: <20210114121350.123684-4-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210114121350.123684-1-wangyanan55@huawei.com> References: <20210114121350.123684-1-wangyanan55@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.187.128] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We now set the pfn dirty and mark the page dirty before calling fault handlers in user_mem_abort(), so we might end up having spurious dirty pages if update of permissions or mapping has failed. Let's move these two operations after the fault handlers, and they will be done only if the fault has been handled successfully. When an -EAGAIN errno is returned from the map handler, we hope to the vcpu to enter guest directly instead of exiting back to userspace, so adjust the return value at the end of function. Signed-off-by: Yanan Wang --- arch/arm64/kvm/mmu.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 7d2257cc5438..77cb2d28f2a4 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,11 +908,17 @@ 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); + } + out_unlock: spin_unlock(&kvm->mmu_lock); kvm_set_pfn_accessed(pfn); kvm_release_pfn_clean(pfn); - return ret; + return ret != -EAGAIN ? ret : 0; } /* Resolve the access fault by making the page young again. */ -- 2.19.1