From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org> mainline inclusion from mainline-v7.4-rc1 commit 33f849d808e2329f569bcd8fdbfe5ce22449466f category: feature bugzilla: https://atomgit.com/openeuler/kernel/issues/10374 CVE: NA Reference: https://github.com/torvalds/linux/commit/33f849d808e2329f569bcd8fdbfe5ce2244... -------------------------------- commit 33f849d808e2329f569bcd8fdbfe5ce22449466f upstream Currently kvm_s2_fault_pin_pfn() handles a poisoned page directly by sending a SIGBUS signal itself. This is an odd place to do it, the caller should decide what to do with errors, so move the handling to the sole caller, user_mem_abort(). This lays the foundation for stage 2 pre-faulting which, arising from a synthetic fault, should not send a signal. In order to do so, check to see if user_mem_abort()'s caller has set result - i.e. whether it wants to be informed about the outcome of the fault handling. If it does, then it is implied that it should handle the -EHWPOISON error itself. This is the case for pre-faulting. Otherwise this is real hardware, so send the signal. No functional change intended. [Backport note] Adapted for OLK-6.6: - OLK-6.6 has no kvm_s2_fault_pin_pfn() helper; PFN resolution and the KVM_PFN_ERR_HWPOISON check are inline in user_mem_abort(). The check now returns -EHWPOISON when fault_result is non-NULL and otherwise keeps the existing kvm_send_hwpoison_signal() behaviour. Reviewed-by: Oliver Upton <oupton@kernel.org> Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev> Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org> Tested-by: Fuad Tabba <fuad.tabba@linux.dev> Link: https://patch.msgid.link/20260923-kvm-arm-prefault-v4-8-d4b0b4dfa8c3@kernel.... Signed-off-by: Marc Zyngier <maz@kernel.org> Signed-off-by: Yanan Wang <wangyanan55@huawei.com> --- arch/arm64/kvm/mmu.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 47c1e6f46af9..d78c0509177c 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1773,6 +1773,9 @@ static int user_mem_abort(const struct kvm_s2_fault_desc *s2fd, pfn = __gfn_to_pfn_memslot(memslot, gfn, false, false, NULL, write_fault, &writable, NULL); if (pfn == KVM_PFN_ERR_HWPOISON) { + /* If a result is specified, let the caller handle this. */ + if (fault_result) + return -EHWPOISON; kvm_send_hwpoison_signal(hva, vma_shift); return 0; } -- 2.43.0