From nobody Fri Jun 12 18:57:01 2026 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [160.30.148.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B48DF374E5A; Wed, 13 May 2026 07:39:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=160.30.148.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778657958; cv=none; b=PJlAcFOHDTEe5a16Y0nSwS3Qlr4pqUlzvt+/DMz6MVv6lChrpS0B/+cxBmuHas8HwsbQT9xUkVLYvYsV6CNDyttL0iZ5lhqGmGy7ttqRUAZ9uaS9YF4tVD6u/wTyZ+fuM7sIYcmNLKsbOfXV/bfyUmucf1yEne/GAkdgpofxFTg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778657958; c=relaxed/simple; bh=0G13UEX/c3db23ALPeTioVasYxFRaifDwgbNWLzCkB0=; h=Message-ID:In-Reply-To:References:Date:Mime-Version:From:To:Cc: Subject:Content-Type; b=fVbpK5P2qUm1mHzD/BYE0wckMEXSRBmyd8bdrgMZKlz81XNj9fecPNZodE52pLjKyhIWB8s0cvEaADpPjCmb9MDI5uDX270QIkhMPQTR41HqPY8WselGBaLsQvPnnDwZBbkMOwhWyBaKi8ZHAHJH4m0V6cEBtFLNAh+sYli7phk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zte.com.cn; spf=pass smtp.mailfrom=zte.com.cn; arc=none smtp.client-ip=160.30.148.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zte.com.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zte.com.cn Received: from mse-fl1.zte.com.cn (unknown [10.5.228.132]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mxhk.zte.com.cn (FangMail) with ESMTPS id 4gFlhY3fM6z5B0n0; Wed, 13 May 2026 15:39:09 +0800 (CST) Received: from szxlzmapp03.zte.com.cn ([10.5.231.207]) by mse-fl1.zte.com.cn with SMTP id 64D7cxSP050732; Wed, 13 May 2026 15:38:59 +0800 (+08) (envelope-from wang.yechao255@zte.com.cn) Received: from mapi (szxl2zmapp07[null]) by mapi (Zmail) with MAPI id mid12; Wed, 13 May 2026 15:39:01 +0800 (CST) X-Zmail-TransId: 2b096a042a95c50-ca1cc X-Mailer: Zmail v1.0 Message-ID: <20260513153901371U0gWZRa45N893VGbU7Gf9@zte.com.cn> In-Reply-To: <20260513153656847l3c4fI5hBsAyoIZi8aGIs@zte.com.cn> References: 20260513153656847l3c4fI5hBsAyoIZi8aGIs@zte.com.cn Date: Wed, 13 May 2026 15:39:01 +0800 (CST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 From: To: , , , , , Cc: , , , , Subject: =?UTF-8?B?W1BBVENIIDEvNF0gUklTQy1WOiBLVk06IEFkZCB0aGUgc3BsaXQgcGFnZSBjYWNoZSBmb3IgaW9jdGwgY29udGV4dA==?= X-MAIL: mse-fl1.zte.com.cn 64D7cxSP050732 X-TLS: YES X-SPF-DOMAIN: zte.com.cn X-ENVELOPE-SENDER: wang.yechao255@zte.com.cn X-SPF: None X-SOURCE-IP: 10.5.228.132 unknown Wed, 13 May 2026 15:39:09 +0800 X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 6A042A9D.002/4gFlhY3fM6z5B0n0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Wang Yechao Add the split page cache for dirty logging enablement and the KVM_CLEAR_DIRTY_LOG ioctl. Signed-off-by: Wang Yechao --- arch/riscv/include/asm/kvm_host.h | 2 ++ arch/riscv/kvm/mmu.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/arch/riscv/include/asm/kvm_host.h b/arch/riscv/include/asm/kvm= _host.h index 75b0a951c1bc..e2f40854305f 100644 --- a/arch/riscv/include/asm/kvm_host.h +++ b/arch/riscv/include/asm/kvm_host.h @@ -93,6 +93,8 @@ struct kvm_arch { /* KVM_CAP_RISCV_MP_STATE_RESET */ bool mp_state_reset; + + struct kvm_mmu_memory_cache split_page_cache; }; struct kvm_cpu_trap { diff --git a/arch/riscv/kvm/mmu.c b/arch/riscv/kvm/mmu.c index 2d3def024270..85a3fb2622a4 100644 --- a/arch/riscv/kvm/mmu.c +++ b/arch/riscv/kvm/mmu.c @@ -549,6 +549,7 @@ int kvm_riscv_mmu_alloc_pgd(struct kvm *kvm) kvm->arch.pgd =3D page_to_virt(pgd_page); kvm->arch.pgd_phys =3D page_to_phys(pgd_page); kvm->arch.pgd_levels =3D kvm_riscv_gstage_max_pgd_levels; + kvm->arch.split_page_cache.gfp_zero =3D __GFP_ZERO; return 0; } @@ -572,6 +573,8 @@ void kvm_riscv_mmu_free_pgd(struct kvm *kvm) if (pgd) free_pages((unsigned long)pgd, get_order(kvm_riscv_gstage_pgd_size)); + + kvm_mmu_free_memory_cache(&kvm->arch.split_page_cache); } void kvm_riscv_mmu_update_hgatp(struct kvm_vcpu *vcpu) --=20 2.27.0 From nobody Fri Jun 12 18:57:01 2026 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [160.30.148.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE2443D6CAE; Wed, 13 May 2026 07:41:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=160.30.148.35 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778658097; cv=none; b=rJhzI68U7RpUszE+DPeSBx4m4m7opRTovIi4Lcoe0dO1coQg8OWcY/bG8JyCM/F22FknR8s4IC1nvGHcz5Tu+70+8WfP4Gu7rSFJ0yZsrvwFuprAdHB/ll8JLMO0YiYUWOqhvDH8Ova/5WV4oWkdVG3xLM98dVKp9TGzukM9XCQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778658097; c=relaxed/simple; bh=ueZ/oET2+Kl1fM7gHo3GZCfnAHIqGlrK7bXx78z9Q8k=; h=Message-ID:In-Reply-To:References:Date:Mime-Version:From:To:Cc: Subject:Content-Type; b=tAlkf312GMvL9MfAmTt6tBNBJt2iJL01rMuT0z9gbBvOeOC1nrhFGcnr+3F0g5O2xlBcODI2eMBUR0fT3uNY2c9MOPuwODuQINA1oNGgagBGSXeR/dv94e+wQsfuwHwSfR75EOupEyoyiOq2l6kU45k8WUrZylokJnIDVEPsZc0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zte.com.cn; spf=pass smtp.mailfrom=zte.com.cn; arc=none smtp.client-ip=160.30.148.35 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zte.com.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zte.com.cn Received: from mse-fl1.zte.com.cn (unknown [10.5.228.132]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mxhk.zte.com.cn (FangMail) with ESMTPS id 4gFllL0ctXz8Xs6v; Wed, 13 May 2026 15:41:34 +0800 (CST) Received: from szxl2zmapp06.zte.com.cn ([10.1.32.108]) by mse-fl1.zte.com.cn with SMTP id 64D7fMim055036; Wed, 13 May 2026 15:41:22 +0800 (+08) (envelope-from wang.yechao255@zte.com.cn) Received: from mapi (szxlzmapp01[null]) by mapi (Zmail) with MAPI id mid12; Wed, 13 May 2026 15:41:25 +0800 (CST) X-Zmail-TransId: 2b036a042b2582b-ace00 X-Mailer: Zmail v1.0 Message-ID: <20260513154125023xfKNqfea7TklqO9_RRrkt@zte.com.cn> In-Reply-To: <20260513153656847l3c4fI5hBsAyoIZi8aGIs@zte.com.cn> References: 20260513153656847l3c4fI5hBsAyoIZi8aGIs@zte.com.cn Date: Wed, 13 May 2026 15:41:25 +0800 (CST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 From: To: , , , , , Cc: , , , , Subject: =?UTF-8?B?W1BBVENIIDIvNF0gUklTQy1WOiBLVk06IFNwbGl0IGh1Z2UgcGFnZXMgd2hlbiBkaXJ0eSBsb2dnaW5nIGlzwqBlbmFibGVk?= X-MAIL: mse-fl1.zte.com.cn 64D7fMim055036 X-TLS: YES X-SPF-DOMAIN: zte.com.cn X-ENVELOPE-SENDER: wang.yechao255@zte.com.cn X-SPF: None X-SOURCE-IP: 10.5.228.132 unknown Wed, 13 May 2026 15:41:34 +0800 X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 6A042B2E.000/4gFllL0ctXz8Xs6v Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Wang Yechao Split huge pages eagerly when enabling dirty logging. The goal is to avoid doing it while faulting on write-protected pages, which negatively impacts guest performance. The benefits of eager page splitting are the same as in x86 and arm64, added with commit a3fe5dbda0a4 ("KVM: x86/mmu: Split huge pages mapped by the TDP MMU when dirty logging is enabled") and commit e7bf7a490c68 ("KVM: arm64: Split huge pages when dirty logging is enabled") Signed-off-by: Wang Yechao --- arch/riscv/kvm/mmu.c | 62 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/arch/riscv/kvm/mmu.c b/arch/riscv/kvm/mmu.c index 85a3fb2622a4..14c558ee5f15 100644 --- a/arch/riscv/kvm/mmu.c +++ b/arch/riscv/kvm/mmu.c @@ -90,6 +90,50 @@ void kvm_riscv_mmu_iounmap(struct kvm *kvm, gpa_t gpa, u= nsigned long size) spin_unlock(&kvm->mmu_lock); } +static bool need_topup_split_caches_or_resched(struct kvm_mmu_memory_cache= *cache, + int count) +{ + if (need_resched()) + return true; + + return kvm_mmu_memory_cache_nr_free_objects(cache) < count; +} + +/* the caller must held mmu lock */ +static void kvm_riscv_split_huge_pages(struct kvm_gstage *gstage, + phys_addr_t start, phys_addr_t end, + bool flush) +{ + struct kvm *kvm =3D gstage->kvm; + struct kvm_mmu_memory_cache *pcache =3D &kvm->arch.split_page_cache; + int count =3D gstage->pgd_levels; + phys_addr_t addr =3D start; + int ret; + + while (addr < end) { + if (need_topup_split_caches_or_resched(pcache, count)) { + spin_unlock(&kvm->mmu_lock); + cond_resched(); + + ret =3D kvm_mmu_topup_memory_cache(pcache, count); + if (ret) { + kvm_err("Failed to toup split page cache\n"); + spin_lock(&kvm->mmu_lock); + return; + } + spin_lock(&kvm->mmu_lock); + } + + ret =3D kvm_riscv_gstage_split_huge(gstage, pcache, addr, 0, flush); + if (ret !=3D 0) { + kvm_err("split huge page for addr(0x%llx) failed %d\n", addr, ret); + break; + } + + addr +=3D PMD_SIZE; + } +} + void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, struct kvm_memory_slot *slot, gfn_t gfn_offset, @@ -136,6 +180,23 @@ void kvm_arch_flush_shadow_memslot(struct kvm *kvm, spin_unlock(&kvm->mmu_lock); } +static void kvm_riscv_split_memory_region(struct kvm *kvm, int slot) +{ + struct kvm_memslots *slots =3D kvm_memslots(kvm); + struct kvm_memory_slot *memslot =3D id_to_memslot(slots, slot); + phys_addr_t start =3D memslot->base_gfn << PAGE_SHIFT; + phys_addr_t end =3D (memslot->base_gfn + memslot->npages) << PAGE_SHIFT; + struct kvm_gstage gstage; + + kvm_riscv_gstage_init(&gstage, kvm); + + spin_lock(&kvm->mmu_lock); + kvm_riscv_split_huge_pages(&gstage, start, end, false); + spin_unlock(&kvm->mmu_lock); + + kvm_flush_remote_tlbs_memslot(kvm, memslot); +} + void kvm_arch_commit_memory_region(struct kvm *kvm, struct kvm_memory_slot *old, const struct kvm_memory_slot *new, @@ -150,6 +211,7 @@ void kvm_arch_commit_memory_region(struct kvm *kvm, if (kvm_dirty_log_manual_protect_and_init_set(kvm)) return; mmu_wp_memory_region(kvm, new->id); + kvm_riscv_split_memory_region(kvm, new->id); } } --=20 2.27.0 From nobody Fri Jun 12 18:57:01 2026 Received: from mxct.zte.com.cn (mxct.zte.com.cn [183.62.165.209]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF9C43D5657; Wed, 13 May 2026 07:43:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=183.62.165.209 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778658194; cv=none; b=T+KMMXMtVtH4S6R6DEOXiFfUWLsbmjbT/0AGqj5xl5sbxvqTE8eX0RPiQRyFiNZMADmf40WCuZn0h5+SUTDIsup3LuytgyxabGcMBhEGVQbWm93r0QL/X9e8qSfl7PCpl8v7n5xqRSZwp+Xt0vjNsXu12ArAoxDHbibd/JpTEvw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778658194; c=relaxed/simple; bh=Q7+dH9r8ieB47YeoC2uoVnB++45yBafVa+0WR9+P8TM=; h=Message-ID:In-Reply-To:References:Date:Mime-Version:From:To:Cc: Subject:Content-Type; b=mfVSZi0GHZy+PCk7WOPIPs9X9FxmUyQPz+0t3yiQU77ER0eFqYxIQpX5xIFjDf39pZPeMjWIU9KZDjntcEltMTPqArnuEaHL+8LbQVCu82wKwoiP4KfYkOodMyAoln8jANLgxE1jTyLzjysSSszrySOh0tdsDzVDZjyvccJNFAk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zte.com.cn; spf=pass smtp.mailfrom=zte.com.cn; arc=none smtp.client-ip=183.62.165.209 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zte.com.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zte.com.cn Received: from mse-fl2.zte.com.cn (unknown [10.5.228.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mxct.zte.com.cn (FangMail) with ESMTPS id 4gFlmw7479z51Sjv; Wed, 13 May 2026 15:42:56 +0800 (CST) Received: from szxl2zmapp07.zte.com.cn ([10.1.32.52]) by mse-fl2.zte.com.cn with SMTP id 64D7gnL4098084; Wed, 13 May 2026 15:42:49 +0800 (+08) (envelope-from wang.yechao255@zte.com.cn) Received: from mapi (szxlzmapp04[null]) by mapi (Zmail) with MAPI id mid12; Wed, 13 May 2026 15:42:51 +0800 (CST) X-Zmail-TransId: 2b066a042b7b6c7-fcc10 X-Mailer: Zmail v1.0 Message-ID: <20260513154251861FBOlxl8ySih_oqyoJL1iA@zte.com.cn> In-Reply-To: <20260513153656847l3c4fI5hBsAyoIZi8aGIs@zte.com.cn> References: 20260513153656847l3c4fI5hBsAyoIZi8aGIs@zte.com.cn Date: Wed, 13 May 2026 15:42:51 +0800 (CST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 From: To: , , , , , Cc: , , , , Subject: =?UTF-8?B?W1BBVENIIDMvNF0gUklTQy1WOiBLVk06IFNwbGl0IGh1Z2UgcGFnZXMgZHVyaW5nIEtWTV9DTEVBUl9ESVJUWV9MT0c=?= X-MAIL: mse-fl2.zte.com.cn 64D7gnL4098084 X-TLS: YES X-SPF-DOMAIN: zte.com.cn X-ENVELOPE-SENDER: wang.yechao255@zte.com.cn X-SPF: None X-SOURCE-IP: 10.5.228.133 unknown Wed, 13 May 2026 15:42:57 +0800 X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 6A042B80.000/4gFlmw7479z51Sjv Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Wang Yechao Split huge pages on the range specified using KVM_CLEAR_DIRTY_LOG. And do not split when enabling dirty logging if KVM_DIRTY_LOG_INITIALLY_SET is set. Signed-off-by: Wang Yechao Reviewed-by: Anup Patel --- arch/riscv/kvm/mmu.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/riscv/kvm/mmu.c b/arch/riscv/kvm/mmu.c index 14c558ee5f15..2cdea3e3ed4b 100644 --- a/arch/riscv/kvm/mmu.c +++ b/arch/riscv/kvm/mmu.c @@ -147,6 +147,9 @@ void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm= *kvm, kvm_riscv_gstage_init(&gstage, kvm); kvm_riscv_gstage_wp_range(&gstage, start, end); + + if (kvm_dirty_log_manual_protect_and_init_set(kvm)) + kvm_riscv_split_huge_pages(&gstage, start, end, true); } void kvm_arch_sync_dirty_log(struct kvm *kvm, struct kvm_memory_slot *mems= lot) --=20 2.27.0 From nobody Fri Jun 12 18:57:01 2026 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [160.30.148.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F1DA3D45C3; Wed, 13 May 2026 07:45:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=160.30.148.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778658312; cv=none; b=BNfFWLEPQxabE+Wo6l7EZP/rhdfSlfWELD2kvzwfElpe71kZPb0OOLFdS9Gwl5WYkXd4UHgVL/PNdPwEM03JQ/+Afnc6lFMDnwSgAz8vi/ZL48AJVRCSVsUteud6jb++rTE5NeqPi1AmLEVoO/MbzfLfXYQtBTxIaSCiklAhotY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778658312; c=relaxed/simple; bh=EVdAGi81ZFC4AJFt/PU8LxFuun9yKB9WVVWC/0TRdpI=; h=Message-ID:In-Reply-To:References:Date:Mime-Version:From:To:Cc: Subject:Content-Type; b=ufQHxXtJCpShnWqWVc3u4kb5n5XJndvfuWY7XuWkaG4dFRER0FRigAQzA1+KPh63oYT8lmvTgt3vGnT2/3a53yi1CBQ495ibladz8fl13e0eWQDfTa4K9S/1Ml/ha2MzioaX9DQUY72u9DwYYAebXXeddxVV4t4l7vudykg4jss= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zte.com.cn; spf=pass smtp.mailfrom=zte.com.cn; arc=none smtp.client-ip=160.30.148.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zte.com.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zte.com.cn Received: from mse-fl2.zte.com.cn (unknown [10.5.228.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mxhk.zte.com.cn (FangMail) with ESMTPS id 4gFlqT5v4cz57DCm; Wed, 13 May 2026 15:45:09 +0800 (CST) Received: from szxl2zmapp05.zte.com.cn ([10.1.32.37]) by mse-fl2.zte.com.cn with SMTP id 64D7iwAc002188; Wed, 13 May 2026 15:44:58 +0800 (+08) (envelope-from wang.yechao255@zte.com.cn) Received: from mapi (szxl2zmapp07[null]) by mapi (Zmail) with MAPI id mid12; Wed, 13 May 2026 15:45:00 +0800 (CST) X-Zmail-TransId: 2b096a042bfcf82-db4ed X-Mailer: Zmail v1.0 Message-ID: <20260513154500183qjAlxzbei98Q4B5HjLpMx@zte.com.cn> In-Reply-To: <20260513153656847l3c4fI5hBsAyoIZi8aGIs@zte.com.cn> References: 20260513153656847l3c4fI5hBsAyoIZi8aGIs@zte.com.cn Date: Wed, 13 May 2026 15:45:00 +0800 (CST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 From: To: , , , , , Cc: , , , , Subject: =?UTF-8?B?W1BBVENIIDQvNF0gUklTQy1WOiBLVk06IEFkZCB0aGUgZWFnZXJfcGFnZV9zcGxpdCBtb2R1bGUgcGFyYW1ldGVy?= X-MAIL: mse-fl2.zte.com.cn 64D7iwAc002188 X-TLS: YES X-SPF-DOMAIN: zte.com.cn X-ENVELOPE-SENDER: wang.yechao255@zte.com.cn X-SPF: None X-SOURCE-IP: 10.5.228.133 unknown Wed, 13 May 2026 15:45:09 +0800 X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 6A042C05.003/4gFlqT5v4cz57DCm Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Wang Yechao Add an eager_page_split module parameter for RISC-V KVM, following the same approach as on x86. This parameter controls whether eager page splitting is enabled. The default value is on. When eager page splitting is enabled, KVM proactively splits large pages (huge pages) into smaller pages when needed for dirty logging or other operations. Disabling it can be beneficial for VM workloads that rarely perform writes, or that only write to a small region of memory, as it allows huge pages to remain intact for read accesses. Signed-off-by: Wang Yechao --- arch/riscv/kvm/mmu.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/arch/riscv/kvm/mmu.c b/arch/riscv/kvm/mmu.c index 2cdea3e3ed4b..2af03c48aff3 100644 --- a/arch/riscv/kvm/mmu.c +++ b/arch/riscv/kvm/mmu.c @@ -16,6 +16,9 @@ #include #include +bool __read_mostly eager_page_split =3D true; +module_param(eager_page_split, bool, 0644); + static void mmu_wp_memory_region(struct kvm *kvm, int slot) { struct kvm_memslots *slots =3D kvm_memslots(kvm); @@ -148,8 +151,10 @@ void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kv= m *kvm, kvm_riscv_gstage_wp_range(&gstage, start, end); - if (kvm_dirty_log_manual_protect_and_init_set(kvm)) - kvm_riscv_split_huge_pages(&gstage, start, end, true); + if (kvm_dirty_log_manual_protect_and_init_set(kvm)) { + if (READ_ONCE(eager_page_split)) + kvm_riscv_split_huge_pages(&gstage, start, end, true); + } } void kvm_arch_sync_dirty_log(struct kvm *kvm, struct kvm_memory_slot *mems= lot) @@ -214,7 +219,9 @@ void kvm_arch_commit_memory_region(struct kvm *kvm, if (kvm_dirty_log_manual_protect_and_init_set(kvm)) return; mmu_wp_memory_region(kvm, new->id); - kvm_riscv_split_memory_region(kvm, new->id); + + if (READ_ONCE(eager_page_split)) + kvm_riscv_split_memory_region(kvm, new->id); } } --=20 2.27.0