Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp5215874iog; Wed, 22 Jun 2022 14:50:59 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uV6Q8WjSOfz+Z+HHD7pREtQPepjmscQreB/bwguN028/S4VW2BWPdsUppLXfQYdzcN3Iiy X-Received: by 2002:a63:d50f:0:b0:408:994a:96d5 with SMTP id c15-20020a63d50f000000b00408994a96d5mr4711888pgg.299.1655934659546; Wed, 22 Jun 2022 14:50:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655934659; cv=none; d=google.com; s=arc-20160816; b=ApI0sJxdzuZ8/PSR+k6a5nR5EzwORpUrNzHcr2lFFfyimtgJtVr6dfPxM7Y4yofUH0 7gVo76Hoh7tisUO/EJrrmvUrwgscgV2co1yiFecNEuL5VKurY5PfSlmdzuJR6qNDcdVz 1Lh0mwGs5u5gz3dxN6ZdTG7yIE+3nAqIOvuQR0XH9aAUgMbL2qXrcWTDk9PuCGrl/EVW p26cwKUVOogDnRl0tLpJ1fMvD2FyDQjCjKfj4/B+4NeHgbk1Ah4Sg6cx+EEdMPZtgslR nYhhUKTef0Qgh5Gmcc4GNFANi8dmMsSElHPi/8WEhJDpWawXXA/SFIi2uJKyKzR9aZrS gRyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Axt2VUkACz79svdtMZMKZayRpMe+CkTeXYc5hsBMhwY=; b=IWEnW17rXRSb7p1mkYBpRppUINwQt1ZE5px3BpUs31OfakBsyT5xfq0SXG8sfLN24a JqKuJ7Ym1AxYpR+FIALebw34w0BKBOKZIMBYtNEHrm+t/F3FeSsf+HWVLiaHumV/rUEL gXvXlVanTJoEf5C0X2HNONtt2bPR4FUqF2aMzhwjf/3NuvVhFhwFvrikoASddK4FEDqT MYBzH0i2IaFuiObjGs5LJdRPLuWT8UqmO3mz1GC4f/rJx0P9eTb0dGUbVZX+Z89CmU0k SLMrrkdTs/fo4o79CA8GexGzdIfWweBzMn3f8XF75/ftbn6Ko8Y/13AHfr5OFbVl0rBx VM4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="brh6/ZpZ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u5-20020a637905000000b003fafdcf6bccsi25890108pgc.59.2022.06.22.14.50.48; Wed, 22 Jun 2022 14:50:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="brh6/ZpZ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232677AbiFVVhJ (ORCPT + 99 others); Wed, 22 Jun 2022 17:37:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230357AbiFVVhH (ORCPT ); Wed, 22 Jun 2022 17:37:07 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B0C9435DC6 for ; Wed, 22 Jun 2022 14:37:04 -0700 (PDT) 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-112-P-YBjRL_PSiSPafC9FrZ4g-1; Wed, 22 Jun 2022 17:37:02 -0400 X-MC-Unique: P-YBjRL_PSiSPafC9FrZ4g-1 Received: by mail-io1-f70.google.com with SMTP id m65-20020a6b3f44000000b00669c2aae17dso9798950ioa.23 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=C+y14XwFxP8wZSxov9XNydk2j2vxYafFjbeCWpiyyUdgta7vSWXH3EoBKA7dzmWpjq pk0nPyuWQ3DQLyius5l+EEcxIScbAHQTdawrUQfwrTAe48Q2EtX1XrUtRbml0sB4C71E oC5fHvpfBKB4P8H6EoP/Q8foY8KM5BCEqwCq+TzWOnW7X1rRCI1AGA+TtlKRYyc2O2bT vSSHTlIWVXRXa+1EQ2cQ/G8FlixUtwFdA4zxlYfqApK9n1tZi4g2RnBVjNfliYu4cywa iYd+ZZD16FY5wdFVl++PHNkHwKCCyzLgSThFDm2TbA8euWERMFwGDyEnBS0KEaFZzwDk 463w== X-Gm-Message-State: AJIora9TFCg+pjutjxszbSjSiV39UAmNXjCJjjX1OQzRZ3fWrhifhV8o eTL+g0ZCQCsuc1mdkik3uDffqN4Xz3HUSD178+8xjgtC/li+nckegOZCn7F5UtPcdv4B5tR7AzU SIh5nsbc/bhBtQOvHbGqsuuaZ X-Received: by 2002:a05:6e02:1885:b0:2d9:18c2:c5b6 with SMTP id o5-20020a056e02188500b002d918c2c5b6mr3160393ilu.201.1655933821464; Wed, 22 Jun 2022 14:37:01 -0700 (PDT) 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 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 2.32.0