From patchwork Wed Jun 22 21:36:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12891501 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A50CACCA47F for ; Wed, 22 Jun 2022 21:37:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CF69D8E00E7; Wed, 22 Jun 2022 17:37:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A3DC58E00F8; Wed, 22 Jun 2022 17:37:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7C53D8E00E7; Wed, 22 Jun 2022 17:37:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 645FF8E00F6 for ; Wed, 22 Jun 2022 17:37:17 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 37086353FA for ; Wed, 22 Jun 2022 21:37:17 +0000 (UTC) X-FDA: 79607182914.12.E9DCFD9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf25.hostedemail.com (Postfix) with ESMTP id D87FEA0017 for ; Wed, 22 Jun 2022 21:37:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655933823; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Axt2VUkACz79svdtMZMKZayRpMe+CkTeXYc5hsBMhwY=; b=brh6/ZpZZ5UXMpzrZ1CMz+rOLjZi1+yUXWU1V0s+2lRzdTVinrWm+HC0rpGHqPN+zv3Ft9 VnUmSf3f6nvLRrmUdWEdFAtvkxMHwM1Da6E/0PKqatLbiXGqK45Wrs127v8FN2BtcdGlmQ yLq65664Nk3HgGla1phicmXAnJ12C+g= Received: from mail-io1-f70.google.com (mail-io1-f70.google.com [209.85.166.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-82-LLpdGV3pM8axl3d1rUhQKQ-1; Wed, 22 Jun 2022 17:37:02 -0400 X-MC-Unique: LLpdGV3pM8axl3d1rUhQKQ-1 Received: by mail-io1-f70.google.com with SMTP id l7-20020a6b7007000000b00669b2a0d497so9878408ioc.0 for ; Wed, 22 Jun 2022 14:37:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Axt2VUkACz79svdtMZMKZayRpMe+CkTeXYc5hsBMhwY=; b=52XKMu1kDerxJtJ/5m92TuUuFougRwMPpbVt4pFIIvCaw4Eq4BAGrfX9OLbevGZtsU k1ZM6ZgGvX7xYpUDH4Utv+PZtQyersNq4wwBzx3ZRlu5s+9kmEP2QDCpp0Rc3UWfIlrN 5c3bMBT3+RlBfKyCGm70l1oSlY5fn/5qDv1BsK2XLxShQL7iXYV3jxpA4nt6+s4h3OtP 0Cm3dYAqUyQv/IehWa8PT0t1C63i4bvcETF8ceZpgyFw57HTM35xYwwPAUYuD3/Omala FlpawfD/3Ha/cXfyKosHcEC46J5IjWwzB7apVB1zxTDKL1yIeOdfSyku5EQyMhlddCJe U7nA== X-Gm-Message-State: AJIora8qXjz73VnUZ1EJj1bvX4VfLOuGka6k8uYMJnTMsgXlOYf3yAIS YEHGKQ2IYw+azAGepsCzcn3/9a64GkFPeS0wPND0A9rbtnAxApIqvQGB+bcYMVS/PuhLXyaMf8y ULhVD2XvDmCc= X-Received: by 2002:a05:6e02:1885:b0:2d9:18c2:c5b6 with SMTP id o5-20020a056e02188500b002d918c2c5b6mr3160390ilu.201.1655933821463; Wed, 22 Jun 2022 14:37:01 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tKHnYViqxUOrsvW9fXe1CgwbG8CKvA7EufZmS7uLsZVAwWsBFk0s/qvUqeQP0pi/F5OXDiow== X-Received: by 2002:a05:6e02:1885:b0:2d9:18c2:c5b6 with SMTP id o5-20020a056e02188500b002d918c2c5b6mr3160383ilu.201.1655933821199; Wed, 22 Jun 2022 14:37:01 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id g7-20020a0566380c4700b00339d892cc89sm1510446jal.83.2022.06.22.14.36.58 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 22 Jun 2022 14:37:00 -0700 (PDT) From: Peter Xu To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: peterx@redhat.com, Paolo Bonzini , Andrew Morton , David Hildenbrand , "Dr . David Alan Gilbert" , Andrea Arcangeli , Linux MM Mailing List , Sean Christopherson Subject: [PATCH 0/4] kvm/mm: Allow GUP to respond to non fatal signals Date: Wed, 22 Jun 2022 17:36:52 -0400 Message-Id: <20220622213656.81546-1-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655933834; a=rsa-sha256; cv=none; b=ubO1oNGoj6ozaMswXWa9pcJDzn+2EYOCEr9GjHMmkqtuCIXfWmk6uOMjghb1g51y17lhgh 7QsiqzA8reW/7YTrb2DVKu7tzcgwvi3PEpt74EV/w1tuqqNCEgc6jTlKo7MepYr+EZNtaM oWASckYL8SaEEjk4KtLgnz2M7vWdvv8= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="brh6/ZpZ"; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf25.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655933834; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=Axt2VUkACz79svdtMZMKZayRpMe+CkTeXYc5hsBMhwY=; b=fmZIqMjUURA6aJkcU9Y8JoiHo0sYWB3wEbJLf3VUhYott84wR/imc4WvO38l6DO9GbS1H3 tlo4a7B+//Z6gKd9mSqparV5ewggVcHn0QEVrW1qkjey4cQKH4dvflDAjTVgJimlHWb7BJ 7Nk7q3xFsuHu4xrHznU77Z5vhJ+lLmw= X-Rspamd-Queue-Id: D87FEA0017 X-Rspam-User: Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="brh6/ZpZ"; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf25.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=peterx@redhat.com X-Rspamd-Server: rspam03 X-Stat-Signature: 6dauq1czxb16om7g8tmxhtetxk4p4mhr X-HE-Tag: 1655933832-932205 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: rfc->v1: - Fix non-x86 build reported by syzbot - Removing RFC tag One issue was reported that libvirt won't be able to stop the virtual machine using QMP command "stop" during a paused postcopy migration [1]. It won't work because "stop the VM" operation requires the hypervisor to kick all the vcpu threads out using SIG_IPI in QEMU (which is translated to a SIGUSR1). However since during a paused postcopy, the vcpu threads are hang death at handle_userfault() so there're simply not responding to the kicks. Further, the "stop" command will further hang the QMP channel. The mm has facility to process generic signal (FAULT_FLAG_INTERRUPTIBLE), however it's only used in the PF handlers only, not in GUP. Unluckily, KVM is a heavy GUP user on guest page faults. It means we won't be able to interrupt a long page fault for KVM fetching guest pages with what we have right now. I think it's reasonable for GUP to only listen to fatal signals, as most of the GUP users are not really ready to handle such case. But actually KVM is not such an user, and KVM actually has rich infrastructure to handle even generic signals, and properly deliver the signal to the userspace. Then the page fault can be retried in the next KVM_RUN. This patchset added FOLL_INTERRUPTIBLE to enable FAULT_FLAG_INTERRUPTIBLE, and let KVM be the first one to use it. One thing to mention is that this is not allowing all KVM paths to be able to respond to non fatal signals, but only on x86 slow page faults. In the future when more code is ready for handling signal interruptions, we can explore possibility to have more gup callers using FOLL_INTERRUPTIBLE. Tests ===== I created a postcopy environment, pause the migration by shutting down the network to emulate a network failure (so the handle_userfault() will stuck for a long time), then I tried three things: (1) Sending QMP command "stop" to QEMU monitor, (2) Hitting Ctrl-C from QEMU cmdline, (3) GDB attach to the dest QEMU process. Before this patchset, all three use case hang. After the patchset, all work just like when there's not network failure at all. Please have a look, thanks. [1] https://gitlab.com/qemu-project/qemu/-/issues/1052 Peter Xu (4): mm/gup: Add FOLL_INTERRUPTIBLE kvm: Merge "atomic" and "write" in __gfn_to_pfn_memslot() kvm: Add new pfn error KVM_PFN_ERR_INTR kvm/x86: Allow to respond to generic signals during slow page faults arch/arm64/kvm/mmu.c | 5 ++-- arch/powerpc/kvm/book3s_64_mmu_hv.c | 5 ++-- arch/powerpc/kvm/book3s_64_mmu_radix.c | 5 ++-- arch/x86/kvm/mmu/mmu.c | 19 ++++++++---- include/linux/kvm_host.h | 21 ++++++++++++- include/linux/mm.h | 1 + mm/gup.c | 33 ++++++++++++++++++--- virt/kvm/kvm_main.c | 41 ++++++++++++++++---------- virt/kvm/kvm_mm.h | 6 ++-- virt/kvm/pfncache.c | 2 +- 10 files changed, 104 insertions(+), 34 deletions(-)