Received: by 2002:ab2:69cc:0:b0:1fd:c486:4f03 with SMTP id n12csp104993lqp; Mon, 10 Jun 2024 20:46:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXYNiHk7Ih/HKMN69Chd/g4pEIRkF9/DUh6Q85dKIyPVDsPQAKFUTZUVnCo4s+PkF5IvyU4syVF7n0enXaHLBblkXODoJOo84E7yRsl2A== X-Google-Smtp-Source: AGHT+IGT3fjxRKUor6zREbslnzDHu6qvYnndKPqCbv1OsSibc0my7aNxQiLJ+C+jKzOYxr0u/uDO X-Received: by 2002:a05:6a20:9151:b0:1b6:dd1e:da40 with SMTP id adf61e73a8af0-1b6dd1edd85mr5553229637.0.1718077586906; Mon, 10 Jun 2024 20:46:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718077586; cv=pass; d=google.com; s=arc-20160816; b=nih1V2O0qId2MQjYS4FhcORPZgGDFfp/XhsB8mkh257wrlPKMigOtYOOwHnoqUW5zH MTDFq4JQp49Ir01MF+j/OQNBABKiev8o6VX5VC+DOGlQtoBXRIfYDKzWIV3ZWkT/1uvr 0HiJ834Esf6gDb89jPTySFXXpbD9UY9k7XKa6t6sBRgS0ms3d9g1QP6/O57JloSY2X+L qyMAsdh8I2wJABLfDTJSc0JPPW14aCsKCsAr+YxxdZMyfNSrq7M4yLKN+P30+BYppZGA dA7F3X26X4fpZBZFQ+7+3IWcudpEzm9Ghsg+cbT4o79jffPNZgZO7JihWTykCKvqK+SV uTMQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=HnaBgiKXngBvkqQpiSehWp2NZrw0KSvGl1ii8+TGi0A=; fh=JOrDXAv7dX9lqUsWenmIinruxsV5NNS7FV+l4Q4onAY=; b=0y+79wRzhGJP9bDoI3RLOGnF3ivWVyFXP3+RdOloL7t67xfeA+L2k7+shJ5KvLJ490 57YYWgfIo/ncrr83vtF5m9xhiGRTHuAeOghm2eC3/+wR5W01A96WC6w9/PRDchyUW3Ff FpS811fMqGK3J3Dy46C9TEiUETxLGXDS9h2rtUsCWu2mxnabIESYqJA6rb8g8/SCeDwJ AynhTFjV21TKL+fVbiz6PYLruNpHjkvSZdG/TQS/JQ9fS7KzvPe0PJzCKZXqHyuDDWGZ xfw/C6EqeR6SbxtQudBXIGkHt3/UqO4xbR/MThBQbK4rmwnAt3CSzBDHv/IZwYjS+/Ph FAdA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=loongson.cn); spf=pass (google.com: domain of linux-kernel+bounces-209226-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-209226-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2c2d113a655si5991770a91.157.2024.06.10.20.46.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 20:46:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-209226-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=loongson.cn); spf=pass (google.com: domain of linux-kernel+bounces-209226-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-209226-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 7E13A283CAD for ; Tue, 11 Jun 2024 03:46:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9D66B16F919; Tue, 11 Jun 2024 03:46:16 +0000 (UTC) Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7A20F64B; Tue, 11 Jun 2024 03:46:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718077576; cv=none; b=YO1cU+D3RWpGT72A+wKt1VHgRkUumJWH54BEtb6AntMSJN9D9uGNw5NOqAdX9q4hecPxYlhVR83IBW4KzTk5v3NAPwf6M3jO6Cj+iQzkMWb6iPQrWGUwaz19ilWEgqoJ8QlgAy/+7JjwYyStqKXHA8W0KkTe89ZJGFNZaBROF0M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718077576; c=relaxed/simple; bh=0BH+fAS9ZOA6hr0JSTRf8Cs4cB23bbOhM+PVeB1ZOAQ=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=aOmSbOadJKKF+DgUtKycZetEHEJlIMthi6w/xmnVyKw2B35QlZGKAjws+46NuJZTlavT7nfirWiPbbklNuR+EUdCyYAbSjV6nrRGgCfDhpzYmpFQgEziFmKpPfKI/0PmPXMRd0DEmR159y0Rn4yPnFKgdAA19KY9zNs2UJlRJC0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [10.2.5.213]) by gateway (Coremail) with SMTP id _____8Ax3eqCyGdmwo0FAA--.22746S3; Tue, 11 Jun 2024 11:46:10 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxBMWCyGdme5sbAA--.57783S2; Tue, 11 Jun 2024 11:46:10 +0800 (CST) From: Bibo Mao To: Tianrui Zhao , Huacai Chen Cc: WANG Xuerui , kvm@vger.kernel.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH] LoongArch: KVM: Mark page accessed and dirty with mmu_lock Date: Tue, 11 Jun 2024 11:46:09 +0800 Message-Id: <20240611034609.3442344-1-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:AQAAf8AxBMWCyGdme5sbAA--.57783S2 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Function kvm_set_pfn_accessed() is somewhat complicated, originally we want to reduce coverity range of mmu_lock, so move function kvm_set_pfn_accessed() and kvm_set_pfn_dirty() out of mmu_lock. However with migration test where vm has some workload, there is no response when VM finishes migration. When mmu_lock is released, pfn page may be replaced with other pages, it is unreasonable to set old replaced pfn page with accessed or dirty. Here move function kvm_set_pfn_accessed() and kvm_set_pfn_dirty() with mmu_lock held, VM works after many times of migrations. Signed-off-by: Bibo Mao --- arch/loongarch/kvm/mmu.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/arch/loongarch/kvm/mmu.c b/arch/loongarch/kvm/mmu.c index ec8c43aad724..91998e95db87 100644 --- a/arch/loongarch/kvm/mmu.c +++ b/arch/loongarch/kvm/mmu.c @@ -591,21 +591,14 @@ static int kvm_map_page_fast(struct kvm_vcpu *vcpu, unsigned long gpa, bool writ if (changed) { kvm_set_pte(ptep, new); pfn = kvm_pte_pfn(new); - } - spin_unlock(&kvm->mmu_lock); - - /* - * Fixme: pfn may be freed after mmu_lock - * kvm_try_get_pfn(pfn)/kvm_release_pfn pair to prevent this? - */ - if (kvm_pte_young(changed)) - kvm_set_pfn_accessed(pfn); + if (kvm_pte_young(changed)) + kvm_set_pfn_accessed(pfn); - if (kvm_pte_dirty(changed)) { - mark_page_dirty(kvm, gfn); - kvm_set_pfn_dirty(pfn); + if (kvm_pte_dirty(changed)) { + mark_page_dirty(kvm, gfn); + kvm_set_pfn_dirty(pfn); + } } - return ret; out: spin_unlock(&kvm->mmu_lock); return ret; base-commit: 2df0193e62cf887f373995fb8a91068562784adc -- 2.39.3