From patchwork Fri Oct 27 18:22:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13438945 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 EB68FC25B48 for ; Fri, 27 Oct 2023 18:23:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 733628001A; Fri, 27 Oct 2023 14:23:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6BB8980018; Fri, 27 Oct 2023 14:23:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4BEC18001A; Fri, 27 Oct 2023 14:23:04 -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 33AC980018 for ; Fri, 27 Oct 2023 14:23:04 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 0763B809E5 for ; Fri, 27 Oct 2023 18:23:04 +0000 (UTC) X-FDA: 81392063088.10.8E15EA8 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf20.hostedemail.com (Postfix) with ESMTP id 36D531C000C for ; Fri, 27 Oct 2023 18:23:02 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=pWglAb9v; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf20.hostedemail.com: domain of 3BQA8ZQYKCCYUGCPLEIQQING.EQONKPWZ-OOMXCEM.QTI@flex--seanjc.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3BQA8ZQYKCCYUGCPLEIQQING.EQONKPWZ-OOMXCEM.QTI@flex--seanjc.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698430982; h=from:from:sender:reply-to: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=QVHGnajj4HOCkrhgrdEXP5z3IZ3KkliWY6Z9SNVyio0=; b=elspQxk8ExZY6D3dmGT07zqfYDcOZvto8LrT0RWy4qYoLJrRiKM0cGDWUBWltP2bfDWkNg 7hMkBRsdl0AI8BmA5wxeJHq1/LXaI7eDSg+dv4Ik3naUDaNh7z6pv6n3P7nz9phmRTttoJ +PvShi5HXEmHZsVauI02u4aJU3V0FX8= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=pWglAb9v; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf20.hostedemail.com: domain of 3BQA8ZQYKCCYUGCPLEIQQING.EQONKPWZ-OOMXCEM.QTI@flex--seanjc.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3BQA8ZQYKCCYUGCPLEIQQING.EQONKPWZ-OOMXCEM.QTI@flex--seanjc.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698430982; a=rsa-sha256; cv=none; b=qT+1nEw1pjTdgJ0YsTzaAOBquVV/267QwlR6qD3w/NgB9f66kchIWihCH706SrawxaKtgf SJ2O/+Znm9aiLRkkf9uRTgvqr0iBV7HYEWFAph5YDSCbd7kU88f9aQJ1PJuqnKTHXqxEeC 2qfDisEJLxdGlXg/pbj/RmGtOH126LE= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-5b064442464so1204107b3.3 for ; Fri, 27 Oct 2023 11:23:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698430981; x=1699035781; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=QVHGnajj4HOCkrhgrdEXP5z3IZ3KkliWY6Z9SNVyio0=; b=pWglAb9vGQYzzswSn8lfXA3nA95pDi3Fhvub2HX/5GGZaCSgj8qqJHqVzJEgdPbKJS atMCnhmYMRv3+AZhhAjOmfoHJu1RRnHnbLd6jDIMf2eJXawe90SybLUs1tJd6pB8Q77O vY0TMdrjFd+tLmKLYIfqO4K8aZQhNkT8OqUB26Po6Mrvv+RRADO3KXqwrfyjWVv559ph eQLdqgSCLRKZif0A39EoPZwrYyXwQNP0Di/T1MQt9FSEQ+UbDaJLEGPmj7LSfHshmVbz fpFTwXF0S7n11qBX178LemR7a9EDwftwkffUjyppNwcJQ3wjRkN1I/boFouxL0vBEl+C WR+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698430981; x=1699035781; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=QVHGnajj4HOCkrhgrdEXP5z3IZ3KkliWY6Z9SNVyio0=; b=OKo8TY3Ksej+xR2dZHZMtHr/tSbPgNaXF5CxvxdRzWIjbVN/lkCj93UiJl/OXL1beA NTtd4Qx0gRZ/WcN751h2HMPFFZBbXhL1xyA9y7rJBN0TmwPzC5gQxSzx7AV4Kxa+9IRK Y2IJgNBx3kWCOGxCsbUUrEGKMFpXo5OXWKeflZC2jOipQ6tuQxQZDDnofviMvnhU39x5 RavXBeK6KmPxjIjfqPa4fAU55wKpE6L5g/WxUqd3y/P9ZXTlxdPyPvV9HKCzVU0fa1fK UiEr3NPGl566rJ/Rhe/G9cplrE/qt0wHgLACm3MMPkdtE16AHYTjkT4eB3yHTD/hXzTW A1jg== X-Gm-Message-State: AOJu0Yw61YLVKi6h3MrxSS5bBZJtzDwb7BAa18taAnoTeP5kFT3nu+Wr qLCZirE11OIT9N7+A4DPqCJBWdeYMaA= X-Google-Smtp-Source: AGHT+IGhdcD7DYxvJo53MxSFMcue6wHqMJ/dJKXwjBlyW/fIhxTWfdSD8wIFRBeoqz4UflCFK1Su3DgQ67Q= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:1083:b0:da0:567d:f819 with SMTP id v3-20020a056902108300b00da0567df819mr78702ybu.10.1698430981246; Fri, 27 Oct 2023 11:23:01 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 27 Oct 2023 11:22:00 -0700 In-Reply-To: <20231027182217.3615211-1-seanjc@google.com> Mime-Version: 1.0 References: <20231027182217.3615211-1-seanjc@google.com> X-Mailer: git-send-email 2.42.0.820.g83a721a137-goog Message-ID: <20231027182217.3615211-19-seanjc@google.com> Subject: [PATCH v13 18/35] KVM: x86: "Reset" vcpu->run->exit_reason early in KVM_RUN From: Sean Christopherson 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_Sala?= =?utf-8?q?=C3=BCn?= " , Vlastimil Babka , Vishal Annapurve , Ackerley Tng , Maciej Szmigiero , David Hildenbrand , Quentin Perret , Michael Roth , Wang , Liam Merwick , Isaku Yamahata , "Kirill A . Shutemov" X-Rspamd-Queue-Id: 36D531C000C X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 7onzu5mg7h3d9qo4krhb93k8orfgdweq X-HE-Tag: 1698430982-240589 X-HE-Meta: U2FsdGVkX18mouc2QiQgw2c0EcqNjef8eKqMRAt+7K7C+USyBjTj2D2aYrMcFGNThqVLXS5SF7Xqr23iNkyx7PDMJL1XRx1VrMwH2Xd3CELVei9YU7/9sRuwTB63WhkUolHeqdBQ2ST1GET7S6KrLHOKJ57gA2FmmghPf8fRQtgnQLZeW19JbC6rt9cjiDW0x55/wMLWFDiAmOGBO6E3LljK5StsSiI0IpzkYEfJ41iioOqMTgvxP9/Gar3ESZfflMcF7hHKPWPhpjJp78CoGHyWv4jltjOYEaVcMWxDBJ48FaGEaJWg3Oj3l8JaRdv+pQyarJZsRco6Qe6fVOWlI+xBqFnjLVCVonMR/9IZu+565Hxw1YMPOGKbDZ1wZklh4DrxIDbb9yw0kYBkCUn07Pv9yrlMNsNde0iWcJ14JYJd5AA4ofm8Ajw+2h5MyGCzRR7V2yGblGlq5QodzDPFK9ANVElLoLpxN9C4TdxfMhcOt+BooGd4/3qgH+qX4lliD5kdS1rD8w2/2xb7r2C+OSdnQ+H6bNiey2fWRP7W+DKkCTApu0zP6lUg7PEL0hgMTyCUYb3imn+uk/EMZ3SiP3EFheNx1nbu9wZdzWUfPeqDgrSOG3RsF0HT/qOSnnjCINo3nRcjuFBVIZNCaK3xi8U+3uvExJeKRPLfJDQ6aWJWDSB4c/w2vvoqTM6n4AyDlsg6+XWYl9oHb2WIneZSCCQ4fEmxKPBcDrUo4v/PpGERGRuF451zru6Yewb8bYL8qCfr5HiT5QaYGrXlzMXv3JcaC4l09ThU9T7/MjVKJWvvy3Ic0uybtZBTXQTL5U65rvfXgiEG+PPu5d6XeHnhmDuXkq0IE026DVSA4qert+eyl9ClWegbTgfEheUdXF+IKXOoOD14/N/5pqUjOP9fjd4fB0kuQ+MrgK6KGFX6f92qm7lZ6bTBHEyDIzLpQ6PC8dN5qkMrLRv67c6Ivd3 Qh5xZtJd DXEZyk+C6yN6L1EPaNW4QVzD4TUoCYqdmor8PKDi1m9LtKuJiUUdXuVhaJJxT1S29tOakw7EcNC0zePtfGzOnguDaCgsfV4inXV/I0rRcK3YcdJxJbWVjg+fDPWSZCGA8iVsVUWm4cQp1G1IUqA8BQVhmtswuKFPsCvxqxk2S+5/F9HZJHB7bN2SvAF6dlQc9MOwzdHiTJ/eUibsdsLB98Kkx79UrgEkyyqH0fVebAYxdrNQYortNOmh14SaJl6B97C9OUcV/GWXYmaV5gDRHSSI8SlKRrhEEb/dSfrkYQn7Ws8HCiOrrNEUZv2Y+X89tIAqQTJHtXoCoq75kjUFGZNhjgescEVmfCZ662Jx7WZ0F26ElYJ6+Ie/Ev2SBXKR1+6r9RWTlEeXJHeG/EUJAwor8KJOYkSqDAW2yZKQqnJA7JBg1FfYcrwRucVd/7iJKawpmkxMaSJhiPISaK8LNyqWwiMnYUMWLUG2SL5cmM6WaL9boabDjUs0HKhfHVZ5yU7WGYBT0rZYM/HyGZ39ooiLyWfRvIVHeudsdog9IVR0Fj/NGwieudo9Lm5fbmfqROrty21LU+FXwrYnobRGMheac2FXMNHe4SgRqJnRw8xzzK3Nl0kmXKqjGybXF6SkLyUAaFWkhXuah2miYcUl+lz4GPYGD783cxwiszYCq5XE6W7AYuae7ihEDXVBTmwua+yh42Ead1A2JQ+fOuVsHNBiO7KM+vVnB8Kotq1VYCtu+pmTHWuv2vFhAB44knqPDQU6pMP1UIhLcFwDO/fbl7zsIK23buI+Ml9kljbXWuyAxPT+0+u06cVu6AFP1EVLJpjI1aqjA+E6aMSB3ipVMKnU36c+wInrn0Fr88xuVuUswyJUOWEE9dS/4BQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000003, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 --- 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 ee3cd8c3c0ef..f41dbb1465a0 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -10963,6 +10963,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 (;;) {