From patchwork Thu Sep 14 01:55:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13384023 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 37EC0EE0203 for ; Thu, 14 Sep 2023 01:56:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 074A06B02AE; Wed, 13 Sep 2023 21:56:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F41056B02B1; Wed, 13 Sep 2023 21:56:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D6B896B02AF; Wed, 13 Sep 2023 21:56:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id C187A6B02AD for ; Wed, 13 Sep 2023 21:56:10 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id A156F40C99 for ; Thu, 14 Sep 2023 01:56:10 +0000 (UTC) X-FDA: 81233537700.14.71DCAED Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by imf02.hostedemail.com (Postfix) with ESMTP id DAA4980007 for ; Thu, 14 Sep 2023 01:56:08 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=bwUni2QH; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf02.hostedemail.com: domain of 3N2gCZQYKCEAugcpleiqqing.eqonkpwz-oomxcem.qti@flex--seanjc.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3N2gCZQYKCEAugcpleiqqing.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=1694656568; 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=JU2E1RY5jYghlRVsn3OuL2a/W8MVmnBu3lS2NKbXZTA=; b=B8Y/snSiDmvXKRkGUT475WF7OOKgJwIMe4Ss8CbXedABve57Hlq9oclmZPqlfkJ7ddlQXU 2B3BEtp66SAB/cnVs/ZssqL35uc5tXDNGvtbLNSDwvZ5cyCwDb0n0dNQAUzny2Pg10jm97 lWsrcdCzKiEK4IYgS9zVmZ2Y4ah9VNE= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=bwUni2QH; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf02.hostedemail.com: domain of 3N2gCZQYKCEAugcpleiqqing.eqonkpwz-oomxcem.qti@flex--seanjc.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3N2gCZQYKCEAugcpleiqqing.eqonkpwz-oomxcem.qti@flex--seanjc.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694656568; a=rsa-sha256; cv=none; b=X7ngsLQEx83/f5tS2Zfyb/GcdkWts5KE0m9lICoGhar2ot8kb36mDL0f5zNwpvr8m7FnT7 hvqfFsGEUR3PeDyibiXR3ihObNyuH/LCaXkCEVsnFuKViL0EyXIQBdRcA1kg7+k4ulkfXK qRiRlVI+AiIfVvRcaAkOWc2uM2XTxmQ= Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-273fa168866so433203a91.0 for ; Wed, 13 Sep 2023 18:56:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694656568; x=1695261368; 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=JU2E1RY5jYghlRVsn3OuL2a/W8MVmnBu3lS2NKbXZTA=; b=bwUni2QHbrALVQDofU3OaNr0lvVY6JjK4YYPK+k3GUA9QVMM0pM3NYJoUHFk6XBcwS cpy1nxWQp3+N9POo28Xzmy+JNxAumAa0fpYR0s9rU66Em96H6XVHWvJJKFFJOVoUZJ3Z ROoo2R11/tXQvxXFapSIg6kaxFUB03a6c/2Wl5T0eDCMMf4xQ5K/GOerayREK5bmmdYH 3c9LT8S19CDdS+ljSAnJU1P63eq8o7HAEfrnZaZ8saXc/Fnmms41gbBeNr8El/TCAIUL FC35pDeHgf2VLkkZrX4FxnM+LuhpLI+HnmPR4MDUP3zSZ00fXpj4WDtK5hRTq6K1JYSu 9eYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694656568; x=1695261368; 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=JU2E1RY5jYghlRVsn3OuL2a/W8MVmnBu3lS2NKbXZTA=; b=VvUvYWKIMojbl4QuZYoq884f3rlvJZZpv0UHsGuvSUfKo7Aw4uzWxisOBHrmsH4p3G woqC97ns2Pucw4NpiK6aQRxfTzGCWKA729hIpqpWvkto1iMBZ/KHy1sjtND6weS8Ppld qHKUIm7rIykmb7HSCXYR5xH+nBKX6zLAq2HE5TKA2ONEQqvPl9RrzC/+BGShuN+q2f20 y+1K5fvXiwU9gwdGR8QYI69ui8sYvsd01XsrhkyJQ+guqb/Et8bKrjbXpYWM35urO/Sw 3khGtflDtnN2laqXinqARH7bDntaGEQlITfzt6MrJFYR/nA9k8hHZgbEN5IN0Z9VwYDb Nbiw== X-Gm-Message-State: AOJu0YyBepI8J5/SPf+GBd3/7HF4o2IwRDTsHgCUQI5O4QdpV7E9W55V rxMGA4GfrStUIIevbQ+Fck2KpSv9OcA= X-Google-Smtp-Source: AGHT+IHMQPQ3k0d/UtHxD4b9hamrYXMHgCSNyIGKdggb9SAJfpQFP9N68H8VlXpWCI6NE2xrZ7HMeRXjSd4= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:da8e:b0:1c0:e87e:52b9 with SMTP id j14-20020a170902da8e00b001c0e87e52b9mr204006plx.12.1694656567699; Wed, 13 Sep 2023 18:56:07 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 13 Sep 2023 18:55:14 -0700 In-Reply-To: <20230914015531.1419405-1-seanjc@google.com> Mime-Version: 1.0 References: <20230914015531.1419405-1-seanjc@google.com> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog Message-ID: <20230914015531.1419405-17-seanjc@google.com> Subject: [RFC PATCH v12 16/33] 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 , "Matthew Wilcox (Oracle)" , Andrew Morton , Paul Moore , James Morris , "Serge E. Hallyn" 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-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Chao Peng , Fuad Tabba , Jarkko Sakkinen , Anish Moorthy , Yu Zhang , Isaku Yamahata , Xu Yilun , 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: DAA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unEM0B9 50l2ztHfn7fIJIm8UArufrI6t3x16a06Q3kYZd4Yif3N6AJbNKsEO3NpncdPXAEkAoqh2pw09iSt/lJ5tCgbReGKj1+9OZFUSOvWi2jxdM5S2KvyYggInXuMaQzGSuC3AyHSOQNybS7kHCGtElXaIZ2B6h5WBnu/w9kRB2cC3lSfDCwO4/8tpBdUAA0GL5xU6IdiJ5/U++1xVJYBoC6jbC53qBvDCSNCR4FKYc7pB5AOcOLqK2zHjef0wu8iVo9LBrfxArwWhykXp9FXHYj9BhdHTopbYOq1vf9A0p2cH1cMeRBZ/jOstZjAWUhld1MWsRZxlrFMzvRESN857dPL0pVkMvrrp99e/rtvlyknWyZ0uoaD3hjgtnjql6wyN9qkEiwUmEyVqC++GIc8m/2/gw9bBvLfO1XYAJ+RQ6YoUruB//Bt5vEvVs4gc3GMv/c9aafBOHRv0bXDrxPP+nV3L2Y/BXVt8XBeQj3TMEEwQW1po/qqzYmKonRJ38psJvYLcmXbpV6TsbezJeWMpPMtFD3hxgQIpudQ4C1AQCrjpLFKFQITvBonHbtm+O/i5H2ShK0qaN/rMSNxtz5UngOLR0df+oP7JS3vLQqFotYUYoWAGZRb9Beg/eYr+SogH5ts+Y6xMtVWAlBq6lEH/XHtFTCRxgAtdD/ovKKhUetjdt3ecz/r8B5Zljgs116TTVdULg2MUTTUzts1Xmfxrp3GUaep6FS6MBj+Ystkm0BHlZbyopSLt3H0/W2TFRiTn9z5uGEU3WSXDUxn7h3B0cK1nd9oYYC278w0NJ3mLITg+NnCi3xyoXvLBZmTrMNWdU+68X0Lmtkx1/cGdM/E3nN9hOOOR8NIsss116RuwUw+arkvE++6qPJFAiy3WKA== 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: 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 --- 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 8356907079e1..8d21b7b09bb5 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -10951,6 +10951,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 (;;) {