Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp5120683rdb; Sat, 16 Sep 2023 04:03:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGTr9j6WHW/Og2mlUvITc0DnsI32VdK4ugbsl/ySUDTj0N0f1J6wu58b/AqH6lwo7/uYJyp X-Received: by 2002:a17:90a:bc84:b0:26f:b228:faea with SMTP id x4-20020a17090abc8400b0026fb228faeamr3170652pjr.18.1694862194626; Sat, 16 Sep 2023 04:03:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694862194; cv=none; d=google.com; s=arc-20160816; b=stWuJKfBhPGk+1L8gdGI2jZbnGh7LfC7HUSBKa1ILj8BUGq7IupYqsnUeBUnZepQC8 U+iNSgYQx2oEcNseJWkJREa8DiU6ksU6zAk1mvAc0gPPd3kBIUCln9HyR+RjoG0MFnK7 cT7BtSv9HX+FKQXldZiMrYC1WZ/xL8OgcGvM0mnC+CI9AxeGpVcT2hLXrkPwRMba5q9W 8nxMcrqWw2my0kSOE8icf4knn4aU0CAW3OAoYx5aS+leyYaamsug+3+sWjH0lHGNNEr3 AkPzH+X8N/q31W0jJElNqOgxMFRhW2ta/Zgcc5Vj7Gyb9LxnWeUgG8JekFhoDtdk3vd1 VwGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=JU2E1RY5jYghlRVsn3OuL2a/W8MVmnBu3lS2NKbXZTA=; fh=61hsfVoef5Tbbo+Rm06/Hxsz4fAtyORDF8Po5ZVRZDI=; b=0vIRY9DZLPY8dPX6hiGE2tQ9DzUXEoJyHYWghIRrmbSWUT4no/Hp+L7bUlsxBnH9Dy N7BTkHUbF0VSeQpouP+bk/F71+7/khy7O6RiRILdImBt0zCxGEysJ7MKjKRH/xvAsiYM 2bk5DzezQ24Oy7KQwsP82y5Axe47xV3G0A45MQ5tMLJ3lUQnkF4ZHZlAVyd56vqBX5Nt vEhfyIgt742mNTiJj2wd0am/okdFPGT/QZ21PQhQy++Eb3UbnJaJzYjtdj/dDzM/2HsJ vxgImcCgL+TlLf2YebTaXyX7CFm4EjZ97HsB8UWNGJDkwLcjAvKrhF/iow5VAnXfJ8p6 ekig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=oAq7aV5a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id t18-20020a17090ad51200b00274aeabd1d8si1649278pju.70.2023.09.16.04.03.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 04:03:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=oAq7aV5a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id AB55280C65FF; Wed, 13 Sep 2023 18:58:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234020AbjINB66 (ORCPT + 99 others); Wed, 13 Sep 2023 21:58:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234205AbjINB6X (ORCPT ); Wed, 13 Sep 2023 21:58:23 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 569171BF8 for ; Wed, 13 Sep 2023 18:56:08 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-1c1fe87fc29so4090285ad.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=vger.kernel.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=oAq7aV5afuCDrDhksAp6R3Y2m/B9q8Zz1fCcjIeqx2bSsmI6MI0B9fHUW8quNlCfN0 q+oUpTgw0YdUMQaapPASrAjK+qmBMAHEIEcyDQm4zvG4VutP0aJICCRwOocO1rhcnt3c cFemar5xl2oCEzJycWRVwb0Bg06tyE0Rm0VgyspJk0g4p1syt4HVg/uiCjZLXwSZrIx9 mn9WOa/WpTBaNJkUP/51L9NHWTaLbkice/GZV3ifVSVAUXQ1G4+OXXTQvDoSnC6CYhLI iJZrG2WaITXLCY3WqU9WRUtYJJdL28xlQUskut7kJ2r25pQRjV9cKun3ucr8tfD4MnEB vc/Q== 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=lc6BUsduhLPbo4HIgBF4FSR1isJgUa/OXYRndEzXNzNHWPRxJDlrr5hcl1FZYz6Ojt y8hSye5Kwz22MfsNhmct0uD9pu3RdPE4cM9C2i1vKqyVNrT7z6WAWPfJmlSkNn2dRrxz 2DH9BurGR9PUTXFJ4KDIUAcTH/IwsqNkE6QaAH8cZUwEXWoCX6bMuodycnQaFA3Audl0 5SyMFkC4AfRb3Rew3h4kVDrclPrjGOQbtGVyDA8oVtOjLs1w+pDZI531tMQzKgyD3HAr is8DWWyfAaI7g97xUFjhg0y4P4dml1MVhj5P+xqoHnIMFYF1aBZC8rj1CXN3igrpDgxo bl9g== X-Gm-Message-State: AOJu0YwBtWtDcjzKywRsC8MzVrO5ZwGo7p2N+viU+Ydf4FaKg6Hm1Lkd RuwOhSUsr9QgVeLR+Db4DkWz7IDgBRE= 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" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 13 Sep 2023 18:58:59 -0700 (PDT) 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 (;;) { -- 2.42.0.283.g2d96d420d3-goog