From patchwork Fri Jun 17 01:41:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12885022 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 1A279C43334 for ; Fri, 17 Jun 2022 01:41:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 736FD6B0071; Thu, 16 Jun 2022 21:41:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6E7846B0073; Thu, 16 Jun 2022 21:41:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 560CE6B0074; Thu, 16 Jun 2022 21:41:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 41AC66B0071 for ; Thu, 16 Jun 2022 21:41:54 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 0DFD3209FD for ; Fri, 17 Jun 2022 01:41:54 +0000 (UTC) X-FDA: 79586026548.24.77306B9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf31.hostedemail.com (Postfix) with ESMTP id AC94D20042 for ; Fri, 17 Jun 2022 01:41:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655430113; 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=/DD/JbIqyCltKPwmfzhCpkXevQRYLJ0ZJFcUAJ03F54=; b=N8cuFGBcvKhKM8QMGhOn0sdq0k6ArxHGjmfN1wIIBImRNmNdu06Im3xYLEvnDQX87Jbfvd aWXD15GVvKw9b0S5rt2+xaq+6J4K1iyJdrx0yEACiY+M6iqNv+VtZyPqX3xDdAiDfZDPf8 NgQFB8LgNPK0O2s0e+djdQstY2rEcn8= Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-404-ZGJIjEkCMoGxKtVRiR1cBw-1; Thu, 16 Jun 2022 21:41:51 -0400 X-MC-Unique: ZGJIjEkCMoGxKtVRiR1cBw-1 Received: by mail-io1-f72.google.com with SMTP id z19-20020a05660200d300b0066583f8cf2eso1769557ioe.2 for ; Thu, 16 Jun 2022 18:41:51 -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=/DD/JbIqyCltKPwmfzhCpkXevQRYLJ0ZJFcUAJ03F54=; b=cD6kLPXDSu4AiFV26e+2n9MgD2bNLrzWFyQQ7VWQP+dXRGI0AJhoFfIXBVM54DbnGQ 4s3/m1HX1BT+GVAuoOCuN2EBU7JCCDGxus0jl4hx8WFyBuA1UJhS62zwM8yBY7ILBn5v 9rEFRzJi3VO34CU92kyebD+GDcwxKKP5M457a3Ww5ZYL3lNDI6UeI3N43vUpv8DoXTjP QvsJZHz/EJaL06VflI5cokyDc5fnJlwQaxV4QBU1zAdoj/OJTcHD+2HHBdN8xjPpuzg/ DmgeDHtpYP/8+923melxphZ7e5gT3BaDEycUdg8/aZ6q5tDhp9yQR+DsJYVXGbLaTx1G yJGA== X-Gm-Message-State: AJIora/CK8I3VLuOXmcc1XW3To7gp2sKXdjimTV0NWMCukuHaVtmTOBm cQ6sYMoLf69k8GrYUb80tnPpCeitjsLOQOjUqkS1z/S+zPwqfK9UG15aWK3lweBQPcNKMdhgIps VXsEt25t70VE= X-Received: by 2002:a05:6e02:f4f:b0:2d8:c9b1:d7b0 with SMTP id y15-20020a056e020f4f00b002d8c9b1d7b0mr4409626ilj.99.1655430111107; Thu, 16 Jun 2022 18:41:51 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vtH1fB1CTBTIxUDTUJnGxdyhGmr8yEs3Uk7gUcYkCtiqMAyVuKyZ5em+h2G7ONgFzOt+7eaw== X-Received: by 2002:a05:6e02:f4f:b0:2d8:c9b1:d7b0 with SMTP id y15-20020a056e020f4f00b002d8c9b1d7b0mr4409616ilj.99.1655430110891; Thu, 16 Jun 2022 18:41:50 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id n4-20020a056e02140400b002d522958fb4sm1726538ilo.2.2022.06.16.18.41.49 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 16 Jun 2022 18:41:50 -0700 (PDT) From: Peter Xu To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "Dr . David Alan Gilbert" , Linux MM Mailing List , Sean Christopherson , Paolo Bonzini , Andrea Arcangeli , Andrew Morton , peterx@redhat.com Subject: [PATCH RFC 0/4] kvm/mm: Allow GUP to respond to non fatal signals Date: Thu, 16 Jun 2022 21:41:43 -0400 Message-Id: <20220617014147.7299-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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655430113; 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=/DD/JbIqyCltKPwmfzhCpkXevQRYLJ0ZJFcUAJ03F54=; b=u5N9dtD/3Vsuhwgor9vWzjE/GzZnVl768yz88gbU3tKec9qw5S37O6l7t/zyg+y+a2Z4Cx LaltjYG4nNvS9wSWp45EvA1iYbGMY3Y/CYgrctc6WpR2kuW1BnlYESMaHRh7uKPiVYS3tb re0S7ZoEc2HELeh474ZCTvPKkqL3Avk= ARC-Authentication-Results: i=1; imf31.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=N8cuFGBc; spf=none (imf31.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655430113; a=rsa-sha256; cv=none; b=IXCJA8F/GmNqvMBpNSC0oXu9/e04f/kPvbQqtNbVryCDgpkergaoaUT7HD+IbngXbnGFaE VNpW/5Tk0vIior0+mGxnt6wraUqPyczm8m4aSJLHZ3hBHspt0j+ph2gOuEyAfttNgOOeTk JsN8ZgFtPH5p/4SHPz30g6gzqK4XgO0= X-Stat-Signature: pw35jj9eizpjbis9pqkqmmixmx1fihad X-Rspamd-Queue-Id: AC94D20042 X-Rspamd-Server: rspam11 X-Rspam-User: Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=N8cuFGBc; spf=none (imf31.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1655430113-409252 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000013, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: [Marked as RFC for now] 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. 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(-)