From patchwork Tue Oct 11 19:58:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13004290 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 28B21C433FE for ; Tue, 11 Oct 2022 19:58:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9CF576B0075; Tue, 11 Oct 2022 15:58:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 909648E0002; Tue, 11 Oct 2022 15:58:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 733008E0001; Tue, 11 Oct 2022 15:58:16 -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 4EF656B0075 for ; Tue, 11 Oct 2022 15:58:16 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 13E141C6EC1 for ; Tue, 11 Oct 2022 19:58:15 +0000 (UTC) X-FDA: 80009730192.27.676FF9C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf25.hostedemail.com (Postfix) with ESMTP id 9C9A9A001A for ; Tue, 11 Oct 2022 19:58:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665518295; 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: in-reply-to:in-reply-to:references:references; bh=V/+ripU4Cn0e2jw5c/awHk5ywDVBelMr8KNke92yFbw=; b=bkun3Cln06Y6GtyXN0vys3GYlpr0GocFYNRIK0VPKIycDeaofmOELmVVKI3oDyNxNPSzbs NEvHXEYycwcwaU1A9kLGEQj7gTHivmsW4m4eLhdtNh+DJY60dbzXrnzJZ1ZS+6gaamT0T+ fOH2SnNP+gDEwuWtOvSbaH5BsSK3ys4= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-625-dMod-bCHPd-pnANwtB6ZbQ-1; Tue, 11 Oct 2022 15:58:13 -0400 X-MC-Unique: dMod-bCHPd-pnANwtB6ZbQ-1 Received: by mail-qt1-f198.google.com with SMTP id bv21-20020a05622a0a1500b00393a6724d4cso9982988qtb.23 for ; Tue, 11 Oct 2022 12:58:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=V/+ripU4Cn0e2jw5c/awHk5ywDVBelMr8KNke92yFbw=; b=v0/OQhrLjXfpWCwfizUfxylxdRduioRx1Td0sOIpqLl9NOCUOj12ZvyTXSw020vZJt 6jZ8cnEb03jJq+jtXeOEocYyKUAIm5AEpDNbzUEB2LkaajIG6ilWOZrMZPJOf7poDhxs aTuQgxCyFtwlDQIwyP1+0/xlICHJKsnDCRQlIgmVEnQ0i403e5CoCE7NLUIvhLwrPVny qwLORBXQah0ivSF3NRjF4ShmBZtOlgwcuioqLkONjOA50u72XwNwIPehUzT3WFMYXQrB nixDaddHl7UjKzcOizIae5H86NimW5VVaG1MRZHoi1QmKbfKlYjO+UKGqh7E05SfMJVi 9DWA== X-Gm-Message-State: ACrzQf1qvgtwTwgEmmN5DxRTLSTm+YSPcBJv0VIjKYrDRoUvs//JQVxV gDEHOPDNGHi+lAIOX2tiQsHRBo3ILcXNfuOQwl3Y+mtuSBJqdS403GZ3uuaYAWZ2azeDlyqHeb4 N9k5Ez4RnIuU= X-Received: by 2002:a0c:9a0d:0:b0:4b1:982e:96d4 with SMTP id p13-20020a0c9a0d000000b004b1982e96d4mr19788281qvd.114.1665518293326; Tue, 11 Oct 2022 12:58:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6PixulCqGkG8rkh18fizY4hjzT3AYfYhVR7T8bvGGt8538uBuPPVxwiplaUYFmIz1hwWZjbA== X-Received: by 2002:a0c:9a0d:0:b0:4b1:982e:96d4 with SMTP id p13-20020a0c9a0d000000b004b1982e96d4mr19788255qvd.114.1665518293119; Tue, 11 Oct 2022 12:58:13 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id az31-20020a05620a171f00b006ce9e880c6fsm13648837qkb.111.2022.10.11.12.58.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Oct 2022 12:58:12 -0700 (PDT) From: Peter Xu To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Sean Christopherson , peterx@redhat.com, John Hubbard , Paolo Bonzini , David Matlack , Andrew Morton , Andrea Arcangeli , "Dr . David Alan Gilbert" , David Hildenbrand , Linux MM Mailing List , Mike Kravetz Subject: [PATCH v4 1/4] mm/gup: Add FOLL_INTERRUPTIBLE Date: Tue, 11 Oct 2022 15:58:06 -0400 Message-Id: <20221011195809.557016-2-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221011195809.557016-1-peterx@redhat.com> References: <20221011195809.557016-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-type: text/plain ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665518295; a=rsa-sha256; cv=none; b=C9v64HijXcdWYq/XlQbRyH1SEGwtFfD6SeOofa69b1Tn5dm8i38Dl9I2IGVPxU2b7CKbpg GwSL2kRg1AJj4ACB0FBFNhuXY8wK748qGCU8c8hcAXRYuUV+DehmlKDa2/nyB4Sm9TZOjL qeC2r5UEbp2g8/dJpnkumelXgiXjsJ0= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bkun3Cln; spf=pass (imf25.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=1665518295; 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:in-reply-to:references:references:dkim-signature; bh=V/+ripU4Cn0e2jw5c/awHk5ywDVBelMr8KNke92yFbw=; b=CiM9bHwUp/rTYrHf/uijmsf+EOV4OJOYcnXRaZ28wQ2U+c+2+UBIukm1wbsI2Snorybpr4 eScl+RsHUQ8W84N+Y2sSZUto905Tw6izQeMpSEtrahEnNOIclA7jY5/ClrnCEwNhgU38GH Nr4S+rCC+ubY0aqX0ig0frx++/yQysI= X-Stat-Signature: mzj6846nmti617ah8phiayc114mk4mgt X-Rspamd-Queue-Id: 9C9A9A001A X-Rspam-User: Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bkun3Cln; spf=pass (imf25.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: rspam06 X-HE-Tag: 1665518295-998444 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: We have had FAULT_FLAG_INTERRUPTIBLE but it was never applied to GUPs. One issue with it is that not all GUP paths are able to handle signal delivers besides SIGKILL. That's not ideal for the GUP users who are actually able to handle these cases, like KVM. KVM uses GUP extensively on faulting guest pages, during which we've got existing infrastructures to retry a page fault at a later time. Allowing the GUP to be interrupted by generic signals can make KVM related threads to be more responsive. For examples: (1) SIGUSR1: which QEMU/KVM uses to deliver an inter-process IPI, e.g. when the admin issues a vm_stop QMP command, SIGUSR1 can be generated to kick the vcpus out of kernel context immediately, (2) SIGINT: which can be used with interactive hypervisor users to stop a virtual machine with Ctrl-C without any delays/hangs, (3) SIGTRAP: which grants GDB capability even during page faults that are stuck for a long time. Normally hypervisor will be able to receive these signals properly, but not if we're stuck in a GUP for a long time for whatever reason. It happens easily with a stucked postcopy migration when e.g. a network temp failure happens, then some vcpu threads can hang death waiting for the pages. With the new FOLL_INTERRUPTIBLE, we can allow GUP users like KVM to selectively enable the ability to trap these signals. Reviewed-by: John Hubbard Reviewed-by: David Hildenbrand Signed-off-by: Peter Xu --- include/linux/mm.h | 1 + mm/gup.c | 33 +++++++++++++++++++++++++++++---- mm/hugetlb.c | 5 ++++- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 21f8b27bd9fd..488a9f4cce07 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2897,6 +2897,7 @@ struct page *follow_page(struct vm_area_struct *vma, unsigned long address, #define FOLL_SPLIT_PMD 0x20000 /* split huge pmd before returning */ #define FOLL_PIN 0x40000 /* pages must be released via unpin_user_page */ #define FOLL_FAST_ONLY 0x80000 /* gup_fast: prevent fall-back to slow gup */ +#define FOLL_INTERRUPTIBLE 0x100000 /* allow interrupts from generic signals */ /* * FOLL_PIN and FOLL_LONGTERM may be used in various combinations with each diff --git a/mm/gup.c b/mm/gup.c index 5abdaf487460..d51e7ccaef32 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -970,8 +970,17 @@ static int faultin_page(struct vm_area_struct *vma, fault_flags |= FAULT_FLAG_WRITE; if (*flags & FOLL_REMOTE) fault_flags |= FAULT_FLAG_REMOTE; - if (locked) + if (locked) { fault_flags |= FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE; + /* + * FAULT_FLAG_INTERRUPTIBLE is opt-in. GUP callers must set + * FOLL_INTERRUPTIBLE to enable FAULT_FLAG_INTERRUPTIBLE. + * That's because some callers may not be prepared to + * handle early exits caused by non-fatal signals. + */ + if (*flags & FOLL_INTERRUPTIBLE) + fault_flags |= FAULT_FLAG_INTERRUPTIBLE; + } if (*flags & FOLL_NOWAIT) fault_flags |= FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_RETRY_NOWAIT; if (*flags & FOLL_TRIED) { @@ -1380,6 +1389,22 @@ int fixup_user_fault(struct mm_struct *mm, } EXPORT_SYMBOL_GPL(fixup_user_fault); +/* + * GUP always responds to fatal signals. When FOLL_INTERRUPTIBLE is + * specified, it'll also respond to generic signals. The caller of GUP + * that has FOLL_INTERRUPTIBLE should take care of the GUP interruption. + */ +static bool gup_signal_pending(unsigned int flags) +{ + if (fatal_signal_pending(current)) + return true; + + if (!(flags & FOLL_INTERRUPTIBLE)) + return false; + + return signal_pending(current); +} + /* * Please note that this function, unlike __get_user_pages will not * return 0 for nr_pages > 0 without FOLL_NOWAIT @@ -1461,11 +1486,11 @@ static __always_inline long __get_user_pages_locked(struct mm_struct *mm, * Repeat on the address that fired VM_FAULT_RETRY * with both FAULT_FLAG_ALLOW_RETRY and * FAULT_FLAG_TRIED. Note that GUP can be interrupted - * by fatal signals, so we need to check it before we + * by fatal signals of even common signals, depending on + * the caller's request. So we need to check it before we * start trying again otherwise it can loop forever. */ - - if (fatal_signal_pending(current)) { + if (gup_signal_pending(flags)) { if (!pages_done) pages_done = -EINTR; break; diff --git a/mm/hugetlb.c b/mm/hugetlb.c index e070b8593b37..202f3ad7f35c 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6206,9 +6206,12 @@ long follow_hugetlb_page(struct mm_struct *mm, struct vm_area_struct *vma, fault_flags |= FAULT_FLAG_WRITE; else if (unshare) fault_flags |= FAULT_FLAG_UNSHARE; - if (locked) + if (locked) { fault_flags |= FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE; + if (flags & FOLL_INTERRUPTIBLE) + fault_flags |= FAULT_FLAG_INTERRUPTIBLE; + } if (flags & FOLL_NOWAIT) fault_flags |= FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_RETRY_NOWAIT; From patchwork Tue Oct 11 19:58:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13004291 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 54FB4C4332F for ; Tue, 11 Oct 2022 19:58:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CDA8C6B0078; Tue, 11 Oct 2022 15:58:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C15298E0002; Tue, 11 Oct 2022 15:58:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A1ABB8E0001; Tue, 11 Oct 2022 15:58: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 899486B0078 for ; Tue, 11 Oct 2022 15:58:17 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 50F1E16113D for ; Tue, 11 Oct 2022 19:58:17 +0000 (UTC) X-FDA: 80009730234.18.E126A6B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf29.hostedemail.com (Postfix) with ESMTP id C4B1A12002B for ; Tue, 11 Oct 2022 19:58:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665518296; 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: in-reply-to:in-reply-to:references:references; bh=SAlECgJKwNknwoioVUeF/uXHuNVkO1eljRPrSr7m9O4=; b=XfBY+BpzifjONzdlKZfmEJu9cwztHrJJbXiVVe6QDjw4sHG5XBSZN6cqCSOcCkALat6Ezu FU6TQtdgvLJLqx2IPR0CT6rOaYDO/43bB8sB5z8eAiE1PXOPm3bGIrcH0s9cNME/Zrfzg+ 1OOwNVYhHZk8uS7yRUmD7+zKxfClc+0= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-349-tLqXs5ZgPPqYcNiz9ogRzg-1; Tue, 11 Oct 2022 15:58:15 -0400 X-MC-Unique: tLqXs5ZgPPqYcNiz9ogRzg-1 Received: by mail-qk1-f200.google.com with SMTP id bs30-20020a05620a471e00b006ed2a84071bso4800691qkb.0 for ; Tue, 11 Oct 2022 12:58:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SAlECgJKwNknwoioVUeF/uXHuNVkO1eljRPrSr7m9O4=; b=kfQ8inDbdWB7DJ0l2zSt+eHqqSBJsf13mBH3QG9wvmIQoOYNF1Utc1ckDVXlQChocd jBfIJBXTBjPHZnqbmSwkBsq/JA9H775cluxaq92WqJjL3rs4+Q+ldsPeYqf72PKltAGi 5uXruTCUgb9W2URzwQnfIft9lVStcc36QBJE+3maMY9LLfQh++9BZlDbq9BfiJ1M5aHT 9DVT1ExOIX3fC5MLH/CEzPSrTarR75f62/KJnJ8gprLtTH5LZmvBGBGjyYib0EKUnhXu vNkHQfwa0oy5DCnFKOkjZktt+tZx8RoiZvXcgW/AM+lDVVFQZ2mPoP4/CGsdIprDUow/ iaJg== X-Gm-Message-State: ACrzQf3ukpHMFKcU3Gv1D72KVoGixcWtfP7fBsv0LzLDxP0IX6SY4WJi 2UCxVUC6LoE8xTknLHXIE4KEZDBgKI6CweBB3D3PejSxoKLtlQv5Cayn5639Mv19D78Ac3/b2S0 c8plKHohyka4= X-Received: by 2002:ac8:574a:0:b0:394:3388:9fc3 with SMTP id 10-20020ac8574a000000b0039433889fc3mr20682006qtx.292.1665518294787; Tue, 11 Oct 2022 12:58:14 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5lzV/hWT/COel7yjUmDe/h42rtZvKalYrmBS4qOaAdmcwzGvcmWe1PC252299lW5tk7hr3pg== X-Received: by 2002:ac8:574a:0:b0:394:3388:9fc3 with SMTP id 10-20020ac8574a000000b0039433889fc3mr20681987qtx.292.1665518294584; Tue, 11 Oct 2022 12:58:14 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id az31-20020a05620a171f00b006ce9e880c6fsm13648837qkb.111.2022.10.11.12.58.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Oct 2022 12:58:14 -0700 (PDT) From: Peter Xu To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Sean Christopherson , peterx@redhat.com, John Hubbard , Paolo Bonzini , David Matlack , Andrew Morton , Andrea Arcangeli , "Dr . David Alan Gilbert" , David Hildenbrand , Linux MM Mailing List , Mike Kravetz Subject: [PATCH v4 2/4] kvm: Add KVM_PFN_ERR_SIGPENDING Date: Tue, 11 Oct 2022 15:58:07 -0400 Message-Id: <20221011195809.557016-3-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221011195809.557016-1-peterx@redhat.com> References: <20221011195809.557016-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-type: text/plain ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XfBY+Bpz; spf=pass (imf29.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665518296; a=rsa-sha256; cv=none; b=D+WPl0gvXt7fTkJ9rKIsUPf1DBlhURvQf3Dg+GqAhoUCtANYEHPK8n69UUBnjpUkdsm/Qr HHfW0sPNiSqF+dtc4+2zUFDPkSeikrC3SdaGLap/8/D1+wwLIKMu4P7aiL6InBYO+oADiV sZ+PChxwPjVoJHqSkASVmn9wlXZ3gYU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665518296; 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:in-reply-to:references:references:dkim-signature; bh=SAlECgJKwNknwoioVUeF/uXHuNVkO1eljRPrSr7m9O4=; b=aVnIJXb/wv2U8xXKJ8f1yihcomt7wmvqmd2RquJFxM8NwSzqSWiTGVfNoVcaLjn+kRKq2W N1CivOykDy3oVAyd8nRn3FFkzhu2wcNLw7BNwAIFsbwLpey/FbPV0X2Quz/RuumGbIkJEH YiL2Tsuuvu7eWWvRf0UBa6aZ/IFn374= X-Rspamd-Queue-Id: C4B1A12002B X-Rspam-User: Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XfBY+Bpz; spf=pass (imf29.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: rspam04 X-Stat-Signature: fgbs6mj1s6j4j8giaya6pc8m7mu8cgx3 X-HE-Tag: 1665518296-646915 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: Add a new pfn error to show that we've got a pending signal to handle during hva_to_pfn_slow() procedure (of -EINTR retval). Signed-off-by: Peter Xu Reviewed-by: Sean Christopherson --- include/linux/kvm_host.h | 10 ++++++++++ virt/kvm/kvm_main.c | 2 ++ 2 files changed, 12 insertions(+) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 32f259fa5801..92baa930b891 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -96,6 +96,7 @@ #define KVM_PFN_ERR_FAULT (KVM_PFN_ERR_MASK) #define KVM_PFN_ERR_HWPOISON (KVM_PFN_ERR_MASK + 1) #define KVM_PFN_ERR_RO_FAULT (KVM_PFN_ERR_MASK + 2) +#define KVM_PFN_ERR_SIGPENDING (KVM_PFN_ERR_MASK + 3) /* * error pfns indicate that the gfn is in slot but faild to @@ -106,6 +107,15 @@ static inline bool is_error_pfn(kvm_pfn_t pfn) return !!(pfn & KVM_PFN_ERR_MASK); } +/* + * KVM_PFN_ERR_SIGPENDING indicates that fetching the PFN was interrupted + * by a pending signal. Note, the signal may or may not be fatal. + */ +static inline bool is_sigpending_pfn(kvm_pfn_t pfn) +{ + return pfn == KVM_PFN_ERR_SIGPENDING; +} + /* * error_noslot pfns indicate that the gfn can not be * translated to pfn - it is not in slot or failed to diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index e30f1b4ecfa5..e20a59dcda32 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -2667,6 +2667,8 @@ kvm_pfn_t hva_to_pfn(unsigned long addr, bool atomic, bool *async, npages = hva_to_pfn_slow(addr, async, write_fault, writable, &pfn); if (npages == 1) return pfn; + if (npages == -EINTR) + return KVM_PFN_ERR_SIGPENDING; mmap_read_lock(current->mm); if (npages == -EHWPOISON || From patchwork Tue Oct 11 19:58:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13004292 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 DCAECC43219 for ; Tue, 11 Oct 2022 19:58:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8464F8E0001; Tue, 11 Oct 2022 15:58:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7CF056B007D; Tue, 11 Oct 2022 15:58:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 622758E0001; Tue, 11 Oct 2022 15:58:26 -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 4C4526B007B for ; Tue, 11 Oct 2022 15:58:26 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 1E977141198 for ; Tue, 11 Oct 2022 19:58:26 +0000 (UTC) X-FDA: 80009730612.02.672B9FE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf18.hostedemail.com (Postfix) with ESMTP id C250B1C0023 for ; Tue, 11 Oct 2022 19:58:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665518305; 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: in-reply-to:in-reply-to:references:references; bh=PgkB5amVUPRR3INxfCSynSvTKOcc2dw225AQHYbN8r0=; b=Sk2GlwMMdEgwGx8KlVg2SOzcxtcq2l4uE4yZme7AEy/uv753tTkSS56WEeyGBgSpFM2ToQ 8NP6cUpCZWbo0bpmKvwjMA0djbIB/SuT+O/5zMc0deP7g2c+jTUW/yygCzUJE1ywkZBU7y pn5PpJCpcEDhn7+JA0rmUdAlXpBqHNQ= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-421-cYf1lyBSM46QhZqMjfeSew-1; Tue, 11 Oct 2022 15:58:17 -0400 X-MC-Unique: cYf1lyBSM46QhZqMjfeSew-1 Received: by mail-qk1-f198.google.com with SMTP id x22-20020a05620a259600b006b552a69231so12480453qko.18 for ; Tue, 11 Oct 2022 12:58:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PgkB5amVUPRR3INxfCSynSvTKOcc2dw225AQHYbN8r0=; b=J6U4P/sBXHAhcksDjlzD+gMZjc2GKImOBj3hxrwzMiFTcOQ8YS9xZ0cfJ3EHf6GROQ oU3vC4FejrVn3L5gEcZR7y4cqJZTYnwp9YLr+GYWZEyiarWXmd6VdWdS+yzjEGkEc6Kf KUVPPQIS+r8nHJw6ugDCTsy5qXm1ib39SUnK/692wJx+M6kxHpLhy4Qbv03z0/zel1sx H6a72P0QxGYUX1THo6fkk6V1ngzVdH0kM977vTHe0wLLW+kfpz8reF3mV+P0lQcYCFUu kESRT34OSk5b3ggGeGTtQMwKRNvwBgPGCduTlT27KfA3RK85z41KyQMMa9SxC24skE+a oxDQ== X-Gm-Message-State: ACrzQf3JWMoqKzJouh5/vcer5tfDu14F4nYPyfdtoWSsKLVTkZ8/02PB Lk+O8jLT8DljlbDek0kxh4SiU37KUQXzomOUc2ZEua0F7J+8C8ENPxzxypCFFeKh1W5dCv8Ir1g DTzLhk67oSOY= X-Received: by 2002:ac8:7c54:0:b0:35c:ebfd:32b4 with SMTP id o20-20020ac87c54000000b0035cebfd32b4mr20412163qtv.30.1665518296186; Tue, 11 Oct 2022 12:58:16 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6eeX3q/UT6wqtgDWH/uPjS+MLsxyPYFVtszRACLZWTMTJNfYFrayyjfrXgbM3yPOUwQH7YEQ== X-Received: by 2002:ac8:7c54:0:b0:35c:ebfd:32b4 with SMTP id o20-20020ac87c54000000b0035cebfd32b4mr20412140qtv.30.1665518295920; Tue, 11 Oct 2022 12:58:15 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id az31-20020a05620a171f00b006ce9e880c6fsm13648837qkb.111.2022.10.11.12.58.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Oct 2022 12:58:15 -0700 (PDT) From: Peter Xu To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Sean Christopherson , peterx@redhat.com, John Hubbard , Paolo Bonzini , David Matlack , Andrew Morton , Andrea Arcangeli , "Dr . David Alan Gilbert" , David Hildenbrand , Linux MM Mailing List , Mike Kravetz Subject: [PATCH v4 3/4] kvm: Add interruptible flag to __gfn_to_pfn_memslot() Date: Tue, 11 Oct 2022 15:58:08 -0400 Message-Id: <20221011195809.557016-4-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221011195809.557016-1-peterx@redhat.com> References: <20221011195809.557016-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-type: text/plain ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Sk2GlwMM; spf=pass (imf18.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665518305; a=rsa-sha256; cv=none; b=26xiMFkTTGoUONledX4Gj7sqMxPAMqreTO1w4iFYi8jzGI2E5leQb9Kr4EiUuA17+HCpEJ p3TLOjuXz5UhAdZcmMzcOU02RhT3zXZl6dW+r99rG7bd6lnt6rN1hpq1ywb+LxzisJimZk nYrjOofA0GuKbHtBUnIB0WhVJ5KbYiU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665518305; 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:in-reply-to:references:references:dkim-signature; bh=PgkB5amVUPRR3INxfCSynSvTKOcc2dw225AQHYbN8r0=; b=DEkUL1uOPpfSwJIE2fQ0yWlLZcVxC5f00yyPRwbnfNNyHIu8SDfnQhgy5czBlwxTIuhVRu LfketycTQpTn6hnDlGBBhCEAY3NwPOTnXHOFDcF8ZrGyifT3Zt2BKrSte6Sz0luntPvaLk 64hYFrwh7a5FI1SuD1NyMvadODP9tns= X-Rspamd-Queue-Id: C250B1C0023 X-Rspam-User: Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Sk2GlwMM; spf=pass (imf18.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: rspam04 X-Stat-Signature: hsreimrp8mdnj8jzrfasp1j633iw1h11 X-HE-Tag: 1665518305-61813 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: Add a new "interruptible" flag showing that the caller is willing to be interrupted by signals during the __gfn_to_pfn_memslot() request. Wire it up with a FOLL_INTERRUPTIBLE flag that we've just introduced. This prepares KVM to be able to respond to SIGUSR1 (for QEMU that's the SIGIPI) even during e.g. handling an userfaultfd page fault. No functional change intended. Signed-off-by: Peter Xu Reviewed-by: Sean Christopherson --- 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 | 4 ++-- include/linux/kvm_host.h | 4 ++-- virt/kvm/kvm_main.c | 28 ++++++++++++++++---------- virt/kvm/kvm_mm.h | 4 ++-- virt/kvm/pfncache.c | 2 +- 8 files changed, 27 insertions(+), 21 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 34c5feed9dc1..7b990b33b337 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1232,7 +1232,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, */ smp_rmb(); - pfn = __gfn_to_pfn_memslot(memslot, gfn, false, NULL, + pfn = __gfn_to_pfn_memslot(memslot, gfn, false, false, NULL, write_fault, &writable, NULL); if (pfn == KVM_PFN_ERR_HWPOISON) { kvm_send_hwpoison_signal(hva, vma_shift); diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c index e9744b41a226..4939f57b6f6a 100644 --- a/arch/powerpc/kvm/book3s_64_mmu_hv.c +++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c @@ -598,7 +598,7 @@ int kvmppc_book3s_hv_page_fault(struct kvm_vcpu *vcpu, write_ok = true; } else { /* Call KVM generic code to do the slow-path check */ - pfn = __gfn_to_pfn_memslot(memslot, gfn, false, NULL, + pfn = __gfn_to_pfn_memslot(memslot, gfn, false, false, NULL, writing, &write_ok, NULL); if (is_error_noslot_pfn(pfn)) return -EFAULT; diff --git a/arch/powerpc/kvm/book3s_64_mmu_radix.c b/arch/powerpc/kvm/book3s_64_mmu_radix.c index 5d5e12f3bf86..9d3743ca16d5 100644 --- a/arch/powerpc/kvm/book3s_64_mmu_radix.c +++ b/arch/powerpc/kvm/book3s_64_mmu_radix.c @@ -846,7 +846,7 @@ int kvmppc_book3s_instantiate_page(struct kvm_vcpu *vcpu, unsigned long pfn; /* Call KVM generic code to do the slow-path check */ - pfn = __gfn_to_pfn_memslot(memslot, gfn, false, NULL, + pfn = __gfn_to_pfn_memslot(memslot, gfn, false, false, NULL, writing, upgrade_p, NULL); if (is_error_noslot_pfn(pfn)) return -EFAULT; diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 6f81539061d6..cc26f425f41c 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -4169,7 +4169,7 @@ static int kvm_faultin_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) } async = false; - fault->pfn = __gfn_to_pfn_memslot(slot, fault->gfn, false, &async, + fault->pfn = __gfn_to_pfn_memslot(slot, fault->gfn, false, false, &async, fault->write, &fault->map_writable, &fault->hva); if (!async) @@ -4186,7 +4186,7 @@ static int kvm_faultin_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) } } - fault->pfn = __gfn_to_pfn_memslot(slot, fault->gfn, false, NULL, + fault->pfn = __gfn_to_pfn_memslot(slot, fault->gfn, false, false, NULL, fault->write, &fault->map_writable, &fault->hva); return RET_PF_CONTINUE; diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 92baa930b891..1904162a041d 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1150,8 +1150,8 @@ kvm_pfn_t gfn_to_pfn_prot(struct kvm *kvm, gfn_t gfn, bool write_fault, kvm_pfn_t gfn_to_pfn_memslot(const struct kvm_memory_slot *slot, gfn_t gfn); kvm_pfn_t gfn_to_pfn_memslot_atomic(const struct kvm_memory_slot *slot, gfn_t gfn); kvm_pfn_t __gfn_to_pfn_memslot(const struct kvm_memory_slot *slot, gfn_t gfn, - bool atomic, bool *async, bool write_fault, - bool *writable, hva_t *hva); + bool atomic, bool interruptible, bool *async, + bool write_fault, bool *writable, hva_t *hva); void kvm_release_pfn_clean(kvm_pfn_t pfn); void kvm_release_pfn_dirty(kvm_pfn_t pfn); diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index e20a59dcda32..903ec86c4d54 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -2514,7 +2514,7 @@ static bool hva_to_pfn_fast(unsigned long addr, bool write_fault, * 1 indicates success, -errno is returned if error is detected. */ static int hva_to_pfn_slow(unsigned long addr, bool *async, bool write_fault, - bool *writable, kvm_pfn_t *pfn) + bool interruptible, bool *writable, kvm_pfn_t *pfn) { unsigned int flags = FOLL_HWPOISON; struct page *page; @@ -2529,6 +2529,8 @@ static int hva_to_pfn_slow(unsigned long addr, bool *async, bool write_fault, flags |= FOLL_WRITE; if (async) flags |= FOLL_NOWAIT; + if (interruptible) + flags |= FOLL_INTERRUPTIBLE; npages = get_user_pages_unlocked(addr, 1, &page, flags); if (npages != 1) @@ -2638,6 +2640,7 @@ static int hva_to_pfn_remapped(struct vm_area_struct *vma, * Pin guest page in memory and return its pfn. * @addr: host virtual address which maps memory to the guest * @atomic: whether this function can sleep + * @interruptible: whether the process can be interrupted by non-fatal signals * @async: whether this function need to wait IO complete if the * host page is not in the memory * @write_fault: whether we should get a writable host page @@ -2648,8 +2651,8 @@ static int hva_to_pfn_remapped(struct vm_area_struct *vma, * 2): @write_fault = false && @writable, @writable will tell the caller * whether the mapping is writable. */ -kvm_pfn_t hva_to_pfn(unsigned long addr, bool atomic, bool *async, - bool write_fault, bool *writable) +kvm_pfn_t hva_to_pfn(unsigned long addr, bool atomic, bool interruptible, + bool *async, bool write_fault, bool *writable) { struct vm_area_struct *vma; kvm_pfn_t pfn; @@ -2664,7 +2667,8 @@ kvm_pfn_t hva_to_pfn(unsigned long addr, bool atomic, bool *async, if (atomic) return KVM_PFN_ERR_FAULT; - npages = hva_to_pfn_slow(addr, async, write_fault, writable, &pfn); + npages = hva_to_pfn_slow(addr, async, write_fault, interruptible, + writable, &pfn); if (npages == 1) return pfn; if (npages == -EINTR) @@ -2699,8 +2703,8 @@ kvm_pfn_t hva_to_pfn(unsigned long addr, bool atomic, bool *async, } kvm_pfn_t __gfn_to_pfn_memslot(const struct kvm_memory_slot *slot, gfn_t gfn, - bool atomic, bool *async, bool write_fault, - bool *writable, hva_t *hva) + bool atomic, bool interruptible, bool *async, + bool write_fault, bool *writable, hva_t *hva) { unsigned long addr = __gfn_to_hva_many(slot, gfn, NULL, write_fault); @@ -2725,7 +2729,7 @@ kvm_pfn_t __gfn_to_pfn_memslot(const struct kvm_memory_slot *slot, gfn_t gfn, writable = NULL; } - return hva_to_pfn(addr, atomic, async, write_fault, + return hva_to_pfn(addr, atomic, interruptible, async, write_fault, writable); } EXPORT_SYMBOL_GPL(__gfn_to_pfn_memslot); @@ -2733,20 +2737,22 @@ EXPORT_SYMBOL_GPL(__gfn_to_pfn_memslot); kvm_pfn_t gfn_to_pfn_prot(struct kvm *kvm, gfn_t gfn, bool write_fault, bool *writable) { - return __gfn_to_pfn_memslot(gfn_to_memslot(kvm, gfn), gfn, false, NULL, - write_fault, writable, NULL); + return __gfn_to_pfn_memslot(gfn_to_memslot(kvm, gfn), gfn, false, false, + NULL, write_fault, writable, NULL); } EXPORT_SYMBOL_GPL(gfn_to_pfn_prot); kvm_pfn_t gfn_to_pfn_memslot(const struct kvm_memory_slot *slot, gfn_t gfn) { - return __gfn_to_pfn_memslot(slot, gfn, false, NULL, true, NULL, NULL); + return __gfn_to_pfn_memslot(slot, gfn, false, false, NULL, true, + NULL, NULL); } EXPORT_SYMBOL_GPL(gfn_to_pfn_memslot); kvm_pfn_t gfn_to_pfn_memslot_atomic(const struct kvm_memory_slot *slot, gfn_t gfn) { - return __gfn_to_pfn_memslot(slot, gfn, true, NULL, true, NULL, NULL); + return __gfn_to_pfn_memslot(slot, gfn, true, false, NULL, true, + NULL, NULL); } EXPORT_SYMBOL_GPL(gfn_to_pfn_memslot_atomic); diff --git a/virt/kvm/kvm_mm.h b/virt/kvm/kvm_mm.h index 41da467d99c9..a1ab15006af3 100644 --- a/virt/kvm/kvm_mm.h +++ b/virt/kvm/kvm_mm.h @@ -24,8 +24,8 @@ #define KVM_MMU_READ_UNLOCK(kvm) spin_unlock(&(kvm)->mmu_lock) #endif /* KVM_HAVE_MMU_RWLOCK */ -kvm_pfn_t hva_to_pfn(unsigned long addr, bool atomic, bool *async, - bool write_fault, bool *writable); +kvm_pfn_t hva_to_pfn(unsigned long addr, bool atomic, bool interruptible, + bool *async, bool write_fault, bool *writable); #ifdef CONFIG_HAVE_KVM_PFNCACHE void gfn_to_pfn_cache_invalidate_start(struct kvm *kvm, diff --git a/virt/kvm/pfncache.c b/virt/kvm/pfncache.c index 68ff41d39545..6f66808d7793 100644 --- a/virt/kvm/pfncache.c +++ b/virt/kvm/pfncache.c @@ -182,7 +182,7 @@ static kvm_pfn_t hva_to_pfn_retry(struct kvm *kvm, struct gfn_to_pfn_cache *gpc) } /* We always request a writeable mapping */ - new_pfn = hva_to_pfn(gpc->uhva, false, NULL, true, NULL); + new_pfn = hva_to_pfn(gpc->uhva, false, false, NULL, true, NULL); if (is_error_noslot_pfn(new_pfn)) goto out_error; From patchwork Tue Oct 11 19:59:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13004293 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 AFC36C433F5 for ; Tue, 11 Oct 2022 19:59:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1B6988E0003; Tue, 11 Oct 2022 15:59:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 13F6C8E0002; Tue, 11 Oct 2022 15:59:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ED4958E0003; Tue, 11 Oct 2022 15:59:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id D74B38E0002 for ; Tue, 11 Oct 2022 15:59:51 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 9E0EF1A1402 for ; Tue, 11 Oct 2022 19:59:51 +0000 (UTC) X-FDA: 80009734182.25.A08E556 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf10.hostedemail.com (Postfix) with ESMTP id 52C29C001E for ; Tue, 11 Oct 2022 19:59:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665518390; 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: in-reply-to:in-reply-to:references:references; bh=8Yevp9gp3Kfu1CI9DtUubsDde9/ctCFvT8SlIVvPvCA=; b=McMNtfh6O32LihUYx6rINatLvg0EyCC+fw+JRYmrk/EelGhcRDc7g1Ek5GoOvgnTY3uKHy GaHNk0km0/8TNEiygg4h6NX4ozKkft0uNAYdjvoA2DTsaBMkkE3vmEni3EwT7Hqk0Sev4Y XoDAGiZJBcUdK5hJoCUDvJcnVLU9ois= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-483-UP9fj5FVOye39tSAGlvnuw-1; Tue, 11 Oct 2022 15:59:49 -0400 X-MC-Unique: UP9fj5FVOye39tSAGlvnuw-1 Received: by mail-qv1-f70.google.com with SMTP id 71-20020a0c804d000000b004b2fb260447so6994680qva.10 for ; Tue, 11 Oct 2022 12:59:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8Yevp9gp3Kfu1CI9DtUubsDde9/ctCFvT8SlIVvPvCA=; b=BeVvlxhuru7wGoXlT/N9zhas7JHY+YVoO6X1kViv3Bqp+r9u2dFovM/Vr11OApyv2H HDAQPLFE0lh31p83n+zp3iyaitJV1mEgMqVDNQ6CPoxrxknKDZQNM2oSr5agpY67Vtuh ScsLok6kdcqlqcLo9PxhhGiqNNLnvzMXetOxuyMZAWxugA3D34oli000WoUDNf0bvgFA sotPDnV3FVcSUS/AYS3fZq5Ob9cfcKbadlOmj6tY8ZsPb2zLpkxM9b5k93OUVqt0qxVO fXbsiDUrwZvyMDzWnj7DlXg7mezrY5xJiL7XgLkvuhpU0VhJtDUfX1/nQ5EPtiNZvRoa g36Q== X-Gm-Message-State: ACrzQf25IRW0IjNhPlOiWqpaREmN0gUv5aOfeW9kfRTtE8FyZLdLc44U et/qTK9e4n6KjscNcnB6lfpIwboBMsZezX8rf13+yf5mncg7RKTePzgXVM2lQGr7hpNzOt/qyem oc+RGifAGMjA= X-Received: by 2002:a37:64cd:0:b0:6ec:545f:9095 with SMTP id y196-20020a3764cd000000b006ec545f9095mr10080152qkb.133.1665518389241; Tue, 11 Oct 2022 12:59:49 -0700 (PDT) X-Google-Smtp-Source: AMsMyM49LBnh/R6pXZ8ZDj9dNiopP/LCrCnUzgsu2WgP4jJEuB7vGoS/dPhB9OGhtxh5BKvDICMIgQ== X-Received: by 2002:a37:64cd:0:b0:6ec:545f:9095 with SMTP id y196-20020a3764cd000000b006ec545f9095mr10080132qkb.133.1665518389031; Tue, 11 Oct 2022 12:59:49 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id v4-20020a05622a014400b00343057845f7sm4477368qtw.20.2022.10.11.12.59.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Oct 2022 12:59:48 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: peterx@redhat.com, David Matlack , "Dr . David Alan Gilbert" , David Hildenbrand , John Hubbard , Andrew Morton , Linux MM Mailing List , Mike Kravetz , Paolo Bonzini , Andrea Arcangeli , Sean Christopherson Subject: [PATCH v4 4/4] kvm: x86: Allow to respond to generic signals during slow PF Date: Tue, 11 Oct 2022 15:59:47 -0400 Message-Id: <20221011195947.557281-1-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221011195809.557016-1-peterx@redhat.com> References: <20221011195809.557016-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-type: text/plain ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=McMNtfh6; spf=pass (imf10.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665518391; a=rsa-sha256; cv=none; b=0BKW/JPe2DEz0JSpoNwCHy1DDt8ouqh4cCI7XrfYxTBlmEZy+9FyRNd6CffUqxT5JOML3k UT+ZAmli6O/KFQozpah3riS0TdF30Sb5Z2s3yBYEdFWm9TsBMP5776vEp3u+X28WbkhBc0 iNytDMPC5wO1ubO+/ECpxlha8mZV09c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665518391; 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:in-reply-to:references:references:dkim-signature; bh=8Yevp9gp3Kfu1CI9DtUubsDde9/ctCFvT8SlIVvPvCA=; b=aiL6zjV/XDqK0P/4PjpgpT+yhIPxXVwIDWyq19MK7lBEMvizAKse6jg2G0g4PayKEX2w3T 6udVBBg6hMKX/lkLeEMjw6I55jhuU6HFTjhLV+HtQdzH2TAshwfNT88wXlTs+7qD1XGRk5 EEXFlVJ3/HBW3g0SEMUZHvsGX7dW2UE= X-Rspamd-Server: rspam05 X-Rspam-User: Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=McMNtfh6; spf=pass (imf10.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-Stat-Signature: o39rtircp6mxbbncciuz1ud5d1usm3et X-Rspamd-Queue-Id: 52C29C001E X-HE-Tag: 1665518391-445676 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: Enable x86 slow page faults to be able to respond to non-fatal signals, returning -EINTR properly when it happens. Signed-off-by: Peter Xu Reviewed-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index cc26f425f41c..83b9c034313d 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -3148,8 +3148,13 @@ static void kvm_send_hwpoison_signal(unsigned long address, struct task_struct * send_sig_mceerr(BUS_MCEERR_AR, (void __user *)address, PAGE_SHIFT, tsk); } -static int kvm_handle_bad_page(struct kvm_vcpu *vcpu, gfn_t gfn, kvm_pfn_t pfn) +static int kvm_handle_error_pfn(struct kvm_vcpu *vcpu, gfn_t gfn, kvm_pfn_t pfn) { + if (is_sigpending_pfn(pfn)) { + kvm_handle_signal_exit(vcpu); + return -EINTR; + } + /* * Do not cache the mmio info caused by writing the readonly gfn * into the spte otherwise read access on readonly gfn also can @@ -3171,7 +3176,7 @@ static int handle_abnormal_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fau { /* The pfn is invalid, report the error! */ if (unlikely(is_error_pfn(fault->pfn))) - return kvm_handle_bad_page(vcpu, fault->gfn, fault->pfn); + return kvm_handle_error_pfn(vcpu, fault->gfn, fault->pfn); if (unlikely(!fault->slot)) { gva_t gva = fault->is_tdp ? 0 : fault->addr; @@ -4186,7 +4191,12 @@ static int kvm_faultin_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) } } - fault->pfn = __gfn_to_pfn_memslot(slot, fault->gfn, false, false, NULL, + /* + * Allow gup to bail on pending non-fatal signals when it's also allowed + * to wait for IO. Note, gup always bails if it is unable to quickly + * get a page and a fatal signal, i.e. SIGKILL, is pending. + */ + fault->pfn = __gfn_to_pfn_memslot(slot, fault->gfn, false, true, NULL, fault->write, &fault->map_writable, &fault->hva); return RET_PF_CONTINUE;