From mboxrd@z Thu Jan 1 00:00:00 1970 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 D7128C19F2D for ; Thu, 11 Aug 2022 20:58:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E9E976B0073; Thu, 11 Aug 2022 16:58:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E4DA66B0075; Thu, 11 Aug 2022 16:58:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D17088E0001; Thu, 11 Aug 2022 16:58:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id C29066B0073 for ; Thu, 11 Aug 2022 16:58:12 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 9C5A3161813 for ; Thu, 11 Aug 2022 20:58:12 +0000 (UTC) X-FDA: 79788524424.18.E72D772 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf05.hostedemail.com (Postfix) with ESMTP id DB25010004B for ; Thu, 11 Aug 2022 20:58:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660251491; 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: in-reply-to:in-reply-to:references:references; bh=umhJQzJAWrnjkW3zfGMLL67VJqv1wRHTW7++Jt2gnz8=; b=RYHHOqkLJQ8+Gy6iHhjK1QkzGE56NXIm7L2UQEQEHguko+UCYLBNrDuR/f6YfSTg9yGjIZ 7dAHASWYh9MAcoJE2BhWyUB3w+46VW+5vQCWN/WYKYqzdElVzsi4o5Mx0augekIrcDiIcM JLU+V4fgi9XLAgTRABaVNJx/CcwBf8Q= Received: from mail-il1-f199.google.com (mail-il1-f199.google.com [209.85.166.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-663-OqeE_4kKNbydqjMhXt_qjA-1; Thu, 11 Aug 2022 16:58:10 -0400 X-MC-Unique: OqeE_4kKNbydqjMhXt_qjA-1 Received: by mail-il1-f199.google.com with SMTP id n13-20020a056e02140d00b002dfa5464967so11865225ilo.19 for ; Thu, 11 Aug 2022 13:58:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=umhJQzJAWrnjkW3zfGMLL67VJqv1wRHTW7++Jt2gnz8=; b=i2odvjZ2G4WvVE7XZ2hWLI7WtKn9Nl41VAswRBuKeQK9LWvsHrdzfK0Zu5lFEUzc4e 5owkWMuPZe30Q25Q0YlpqhGXUu2rzfEvj7m0x/+egSyXvoljRv8ZJijZNEab9b1/1j0P /NrYjkSO87MZb6dBTkay1pHcrkJ3HMcbG//NCe6L/OBb90pYJmRoxeh0/o5eu/+x/DS6 ik5HTMAyAKiTLlDo9qMJle8t2SpY9LFkvLluDaNHojcBXxmcI75kLbjQByzgP61KSwwH FDKkDe0gUrkwf3SPUSw+NK6SjAl4OtDNodcrLZzcYoaxEDJsbs/ahS32hltdbFTNb8rj 6DbA== X-Gm-Message-State: ACgBeo07s+/gP5IWEHR+3AvL7Zk2HDBn9jqfxD9wlzfBJc3a17ki+xtj LM/Q5rC0eGv0MScHyl6cfDyM1s4NKgiI30DOa+JfcGXY0iI8doiDC3A24fLAVrfW6Cq4OqBDDgi DOeQdd6shS/0= X-Received: by 2002:a05:6602:2b84:b0:684:fb55:663b with SMTP id r4-20020a0566022b8400b00684fb55663bmr420190iov.13.1660251489443; Thu, 11 Aug 2022 13:58:09 -0700 (PDT) X-Google-Smtp-Source: AA6agR7xVXDdje7GojW2eJGsfbGHzi0u/S8iOtnP4nn3QprAKSMlWTOAhg/IOfoqAcJtKHrMPgHh7A== X-Received: by 2002:a05:6602:2b84:b0:684:fb55:663b with SMTP id r4-20020a0566022b8400b00684fb55663bmr420184iov.13.1660251489147; Thu, 11 Aug 2022 13:58:09 -0700 (PDT) Received: from xz-m1.local (bras-base-aurron9127w-grc-35-70-27-3-10.dsl.bell.ca. [70.27.3.10]) by smtp.gmail.com with ESMTPSA id z6-20020a05663822a600b0034294118e1bsm215302jas.126.2022.08.11.13.58.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Aug 2022 13:58:08 -0700 (PDT) Date: Thu, 11 Aug 2022 16:58:07 -0400 From: Peter Xu To: Sean Christopherson Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, David Hildenbrand , "Dr . David Alan Gilbert" , John Hubbard , Linux MM Mailing List , Andrew Morton , Paolo Bonzini , Andrea Arcangeli Subject: Re: [PATCH v2 3/3] kvm/x86: Allow to respond to generic signals during slow page faults Message-ID: References: <20220721000318.93522-1-peterx@redhat.com> <20220721000318.93522-4-peterx@redhat.com> MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660251492; a=rsa-sha256; cv=none; b=JN8Kr2QE3LAR7f5tAvl4XDF9t1/zAUTRaH1tJBWR956t4QN3I+NNFqYtcN6Owp3650ReZb ESWv674RShCQ736W6dJlfTA1xs5TzjdClx+07/2slDo1zCPmiEgcRoPC2bmTBe3zrMx2z4 5rc56J98vyrmyiQXRt3UxhC7cUxEpuY= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RYHHOqkL; spf=pass (imf05.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660251492; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=umhJQzJAWrnjkW3zfGMLL67VJqv1wRHTW7++Jt2gnz8=; b=K2EMrWmOqSCNli4OmmqX7/w+4n5ctG7C4bvKes34zuOoDJc7a0OPIhwmu0h3xQxBeW7/J7 gtq725SY/WNX5AvVR1Q22gfMK7C8mhoEuWYYTUByIvYZllcwpvSpqZEHVGIT/Al69UeqGV GLuxHgBsDdr5ftUsPJ+PLQKY+Plnldk= X-Rspam-User: X-Stat-Signature: 6zowwdmjjdizwbx78u7c57fhofuzz3e8 X-Rspamd-Queue-Id: DB25010004B Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RYHHOqkL; spf=pass (imf05.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam01 X-HE-Tag: 1660251491-84257 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: On Thu, Aug 11, 2022 at 08:12:38PM +0000, Sean Christopherson wrote: > On Wed, Jul 20, 2022, Peter Xu wrote: > > All the facilities should be ready for this, what we need to do is to add a > > new "interruptible" flag showing that we're willing to be interrupted by > > common signals during the __gfn_to_pfn_memslot() request, and wire it up > > with a FOLL_INTERRUPTIBLE flag that we've just introduced. > > > > Note that only x86 slow page fault routine will set this to true. The new > > flag is by default false in non-x86 arch or on other gup paths even for > > x86. It can actually be used elsewhere too but not yet covered. > > > > When we see the PFN fetching was interrupted, do early exit to userspace > > with an KVM_EXIT_INTR exit reason. > > > > Signed-off-by: Peter Xu > > --- > > arch/arm64/kvm/mmu.c | 2 +- > > arch/powerpc/kvm/book3s_64_mmu_hv.c | 2 +- > > arch/powerpc/kvm/book3s_64_mmu_radix.c | 2 +- > > arch/x86/kvm/mmu/mmu.c | 16 ++++++++++++-- > > include/linux/kvm_host.h | 4 ++-- > > virt/kvm/kvm_main.c | 30 ++++++++++++++++---------- > > virt/kvm/kvm_mm.h | 4 ++-- > > virt/kvm/pfncache.c | 2 +- > > 8 files changed, 41 insertions(+), 21 deletions(-) > > I don't usually like adding code without a user, but in this case I think I'd > prefer to add the @interruptible param and then activate x86's kvm_faultin_pfn() > in a separate patch. It's rather difficult to tease out the functional x86 > change, and that would also allow other architectures to use the interruptible > support without needing to depend on the functional x86 change. > > And maybe squash the addition of @interruptible with the previous patch? I.e. > add all of the infrastructure for KVM_PFN_ERR_SIGPENDING in patch 2, then use it > in x86 in patch 3. Sounds good. > > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > > index 17252f39bd7c..aeafe0e9cfbf 100644 > > --- a/arch/x86/kvm/mmu/mmu.c > > +++ b/arch/x86/kvm/mmu/mmu.c > > @@ -3012,6 +3012,13 @@ static int kvm_handle_bad_page(struct kvm_vcpu *vcpu, gfn_t gfn, kvm_pfn_t pfn) > > static int handle_abnormal_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault, > > unsigned int access) > > { > > + /* NOTE: not all error pfn is fatal; handle sigpending pfn first */ > > + if (unlikely(is_sigpending_pfn(fault->pfn))) { > > Move this into kvm_handle_bad_page(), then there's no need for a comment to call > out that this needs to come before the is_error_pfn() check. This _is_ a "bad" > PFN, it just so happens that userspace might be able to resolve the "bad" PFN. It's a pity it needs to be in "bad pfn" category since that's the only thing we can easily use, but true it is now. > > > + vcpu->run->exit_reason = KVM_EXIT_INTR; > > + ++vcpu->stat.signal_exits; > > + return -EINTR; > > For better or worse, kvm_handle_signal_exit() exists and can be used here. I > don't love that KVM details bleed into xfer_to_guest_mode_work(), but that's a > future problem. > > I do think that the "return -EINTR" should be moved into kvm_handle_signal_exit(), > partly for code reuse and partly because returning -EINTR is very much KVM ABI. > Oof, but there are a _lot_ of paths that can use kvm_handle_signal_exit(), and > some of them don't select KVM_XFER_TO_GUEST_WORK, i.e. kvm_handle_signal_exit() > should be defined unconditionally. I'll work on a series to handle that separately, > no reason to take a dependency on that cleanup. > > So for now, > > static int kvm_handle_bad_page(struct kvm_vcpu *vcpu, gfn_t gfn, kvm_pfn_t pfn) > { > if (pfn == KVM_PFN_ERR_SIGPENDING) { > kvm_handle_signal_exit(vcpu); > return -EINTR; > } > > ... > } Sounds good too here. Also all points taken in the wording of patch 2. Will respin shortly, thanks Sean. -- Peter Xu