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 5E2FFC4332F for ; Sun, 5 Nov 2023 16:33:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E7FED44015D; Sun, 5 Nov 2023 11:33:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E0A17440150; Sun, 5 Nov 2023 11:33:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C82EC44015D; Sun, 5 Nov 2023 11:33:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id B3FE1440150 for ; Sun, 5 Nov 2023 11:33:01 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8B6BA802A7 for ; Sun, 5 Nov 2023 16:33:01 +0000 (UTC) X-FDA: 81424444962.11.9697D13 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf08.hostedemail.com (Postfix) with ESMTP id D8EBF160013 for ; Sun, 5 Nov 2023 16:32:59 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=WHQW2+66; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.hostedemail.com: domain of pbonzini@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=pbonzini@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1699201979; 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=/uJI+ktz023TpGUQ2S26wAEUImlf4SsMQChBB/pSoBc=; b=tzFKqNtOz13kKGCZ0ZKe6s6GcWfrqxScV1uVP0DJMuHEdiwoBCmdkVkftJQl3erVzi6gNj ejQd3g0Q3tgdPVleXSZ7pqVOcNGUK6Doa8epecpDtfwnm/17StEFIWT1/m6kclIYejipdd 4IB2CEClEZyggO+hOOZ0Gyz94EemG2E= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=WHQW2+66; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.hostedemail.com: domain of pbonzini@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=pbonzini@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699201979; a=rsa-sha256; cv=none; b=KuQqWipCh7K/Ygzms9yMqwWR8sLFpjHsrfez8eT+VRf0ytvQw6I1O+Dco1NHH5j7Rd4wx+ EUPOY7qslXyYYx7m0msXGLm9kPfpGJQAYuHIaLxb7Lat8uAqFyN6T1fFVETpYgGdOj7U/u ++Qwd/bxvP/0To+b9B/DfpLOMItHP00= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699201979; 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=/uJI+ktz023TpGUQ2S26wAEUImlf4SsMQChBB/pSoBc=; b=WHQW2+66oeNaMalcmWBAM4ENIJ6K++16JoOdpEDCXrxeVGEfDStJR5iKKR3CyvYGBBpCcc 5cfaBV70j78NylSVNhFMGV0NLcmj3QNzuMgIHygQqmdrEWxwAe7m3jMd15HjX0Wy+ixk0k uqs+VB6VZz/co5kjiCJJMJHLhP7QhMI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-607-8MBsWsOoPKueD2L7R-1tiA-1; Sun, 05 Nov 2023 11:32:56 -0500 X-MC-Unique: 8MBsWsOoPKueD2L7R-1tiA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2F691810FC3; Sun, 5 Nov 2023 16:32:54 +0000 (UTC) Received: from avogadro.redhat.com (unknown [10.39.192.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 620112166B26; Sun, 5 Nov 2023 16:32:47 +0000 (UTC) From: Paolo Bonzini To: Paolo Bonzini , Marc Zyngier , Oliver Upton , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Sean Christopherson , Alexander Viro , Christian Brauner , "Matthew Wilcox (Oracle)" , Andrew Morton Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Xiaoyao Li , Xu Yilun , Chao Peng , Fuad Tabba , Jarkko Sakkinen , Anish Moorthy , David Matlack , Yu Zhang , Isaku Yamahata , =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Vlastimil Babka , Vishal Annapurve , Ackerley Tng , Maciej Szmigiero , David Hildenbrand , Quentin Perret , Michael Roth , Wang , Liam Merwick , Isaku Yamahata , "Kirill A. Shutemov" Subject: [PATCH 16/34] KVM: x86: "Reset" vcpu->run->exit_reason early in KVM_RUN Date: Sun, 5 Nov 2023 17:30:19 +0100 Message-ID: <20231105163040.14904-17-pbonzini@redhat.com> In-Reply-To: <20231105163040.14904-1-pbonzini@redhat.com> References: <20231105163040.14904-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Rspamd-Queue-Id: D8EBF160013 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: c1qag9wibt4xhyh3juzsp6krddy6gkcb X-HE-Tag: 1699201979-925676 X-HE-Meta: U2FsdGVkX19FQKXdgQNxeWBlRR2zEacYVxCVmAaGJAdcJnDE/9a3rQFlS/s7a0Wc3yTRGPPZ247R/9kbLxuXgOZtJucteZVlapPjZUDFTO3Kh6//QoOu3hLYg5tUCTPdP0W7GqAqAprh0Dj99E40cfW2WUaMN7q9CspBO7PYhfQpYp3gUZn4DvWrFVDhOnjZpGpewI4WFr/xgfsI3Mm0RfgK5Y6k4uk4sUPFC02YFnL9Wu1qmRrmiMWnL4P+JbFKqRLVUk04Vf7H9uM+ttf04dbRDzVoGkYiUmSYPp8N43AGEY9TVqdAfDYpCwr/gPrrx6xWYTAVY3h02M4Ss7s32UgG+WDM5BxYjBwpwGmBDmtHQcah19kYvMGfmT45PsEPo+mMgVxiBmTAZdOzDYJYi47FklLh7TEqJ8gUI1FR+J53jCqJGFQiXSm4teXDXo8KyKjfSqNxShklxXpU1tH1PZXwJpyEh2WGpn69a5i9HBH8VUuHD/+Aa2STCTSYxBX5KeJJHLQUwN7OfDsQ9wsdmf/IMqp7t/PEcEgGDIazYhE4RYoG843CEaRAWNTkTz1KLVAz2dnOgVryMba+EmLO+cCHNC2a+eESnLOVklIeJS0IHnWQKc07HCRcVzalTn1wYUOg4A4oKpSLIGkK5HJ4qnWd8j3QKCTH1+Yzgf7Fd8WYiHORgUsvLJnbn2QfBwHWblnAgE4LEaVqFMMvFY7vb5ow5m1824MIVNKLgJOtcfbHTW4TPrmTKIKzWSEs5nxmlU6dPqfDLTxB/yCFiX1t98+OgcRB7rMd37FAmbaHPQW0B7NdJ8tUCKYjM5QahzOiugcqYK+7YgISDgjE5X7SpqgQhIfc9Yn3MDSgJJHuEQ7T7iuoHJ2Nd5qncpAUpYTyHE2WXWiiaGw1DWb+vAX3U1vc1iGfQfNDP4xqaGapBWFotic6dMTaaUliDQApGJDZdHPc82R28UqHUYVV/Ye U8X6SgV1 WXf877Tyc5dRB3qWrncDFlk/4cxQvz9kupAxnYFkfSATYVH6qmwiWGw/GoQ4oHXzPwVCjUTUPGaKbRHalr7GkBbTyWJFG76BDDMFSuSuWtM/Qdw0a1VmO8d+5MKC7TACz1W1Kz0EgcQ/AZOII3dqXQf0ucy7ScwzVZdMpP0+VSJQpUich0sIVKwg67BR47W04Kn0IC4WZhE46QXj1iaun2AvOUGslI+rXk5I/wVT8ayp3SXKOTRxFf5U2MUuG/g+unw/KFToX3HzncJtRB0fVY80s1IUU0KrCE/ZoDQiGJeELuMZzsfXj4rWecvIBNA3F3SSkHwh/QQDMcBn6L0Eso9F3HOoBZUTH3/ub9ahQlhCpRvW1tIQWYcCmFA== 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: List-Subscribe: List-Unsubscribe: From: Sean Christopherson Initialize run->exit_reason to KVM_EXIT_UNKNOWN early in KVM_RUN to reduce the probability of exiting to userspace with a stale run->exit_reason that *appears* to be valid. To support fd-based guest memory (guest memory without a corresponding userspace virtual address), KVM will exit to userspace for various memory related errors, which userspace *may* be able to resolve, instead of using e.g. BUS_MCEERR_AR. And in the more distant future, KVM will also likely utilize the same functionality to let userspace "intercept" and handle memory faults when the userspace mapping is missing, i.e. when fast gup() fails. Because many of KVM's internal APIs related to guest memory use '0' to indicate "success, continue on" and not "exit to userspace", reporting memory faults/errors to userspace will set run->exit_reason and corresponding fields in the run structure fields in conjunction with a a non-zero, negative return code, e.g. -EFAULT or -EHWPOISON. And because KVM already returns -EFAULT in many paths, there's a relatively high probability that KVM could return -EFAULT without setting run->exit_reason, in which case reporting KVM_EXIT_UNKNOWN is much better than reporting whatever exit reason happened to be in the run structure. Note, KVM must wait until after run->immediate_exit is serviced to sanitize run->exit_reason as KVM's ABI is that run->exit_reason is preserved across KVM_RUN when run->immediate_exit is true. Link: https://lore.kernel.org/all/20230908222905.1321305-1-amoorthy@google.com Link: https://lore.kernel.org/all/ZFFbwOXZ5uI%2Fgdaf@google.com Signed-off-by: Sean Christopherson Reviewed-by: Paolo Bonzini Reviewed-by: Fuad Tabba Tested-by: Fuad Tabba Message-Id: <20231027182217.3615211-19-seanjc@google.com> Signed-off-by: Paolo Bonzini --- arch/x86/kvm/x86.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 8f9d8939b63b..f661acb01c58 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -11082,6 +11082,7 @@ static int vcpu_run(struct kvm_vcpu *vcpu) { int r; + vcpu->run->exit_reason = KVM_EXIT_UNKNOWN; vcpu->arch.l1tf_flush_l1d = true; for (;;) { -- 2.39.1