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;