Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp5213639rdb; Sat, 16 Sep 2023 07:25:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHxkcsC6Q1gjNLT1KeP+KPBk246/joJD3lBbS7dzNBkbhrjIKX4h3k6EVBc0EFVwGJZmEA0 X-Received: by 2002:a05:6a00:813:b0:68e:39b5:7e63 with SMTP id m19-20020a056a00081300b0068e39b57e63mr4994868pfk.16.1694874330381; Sat, 16 Sep 2023 07:25:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694874330; cv=none; d=google.com; s=arc-20160816; b=TbkG3F20stZk1Yh69+nuBFh02f82H1+FR9TLLQVIhi/3n/K6hhrp4nR5d1JC5lGW0o AXJUyhbVkXlWx86VzU4UIvrAFubhg9utY69eIaVHdQmIDsc1jeQMm8w1zNNw7sJBLDwL xDJyPFwrAui0Z4QyzLIlFFORZy2W85AXPAhomJMLDiZiNMfzV2cpDPrs53qnNMO/3jIJ 2dcnSKYlHWKTJ9F7hlCP9bKcyjonchHkOE2PuqvdAeQXJFOYmGBhQNkuWd5+W+o0X513 zCrm3Wz1shH4ytGv6MINdBe66RY6xg6DrfNWgEMYPxbIqzg4Cwj//zVOG+XJlPPeMwH6 P5wg== 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=xxhu5mShS80K2/3vPmWMk/nseLaV4p5fitYU0fke5+k=; fh=kXSkXFacTVTlVHq0XnHvR0iN61knZqi7sPJIGv3JAWo=; b=yr8bTk6p0qS/qlrPuw6jFQz1MaNh6rbcIfxZZCdsdkphLUiYLTXVXS9OPrJvplRsj/ nE03xhBngE7noxhpBdHHw2HuFf9aCt15ILjK1rtkCIEGEZp65NKJnQkWYFGD7n4ubQ8J deP2+Q9/I2BwG1dEAasLwzNxx4nPPi8+9ZuQR0QMJKVxYk7x+nfCmEVGwuWudGjpPKJh Y0d4KvomxKCQ5CvOjQVkIyyNJZPzNXpLUC7znwkO0IynjruYIhOw7hgBWnp6VIi3an3S h4FKuu+5fkuNlH2T7oqU3OAwH/nFy1sZacWBYo9FC9wicBo8mQ0GEtpfhQfeDPjLCnJ8 yrkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=I0twIbH0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id ca21-20020a056a00419500b0068fcb779a3esi4938542pfb.278.2023.09.16.07.25.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 07:25:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=I0twIbH0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id F0F2E808BD1D; Fri, 15 Sep 2023 17:35:46 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239159AbjIPAfG (ORCPT + 99 others); Fri, 15 Sep 2023 20:35:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238889AbjIPAeY (ORCPT ); Fri, 15 Sep 2023 20:34:24 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D063319A5 for ; Fri, 15 Sep 2023 17:32:05 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-59beea5ce93so44687467b3.0 for ; Fri, 15 Sep 2023 17:32:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694824325; x=1695429125; 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=xxhu5mShS80K2/3vPmWMk/nseLaV4p5fitYU0fke5+k=; b=I0twIbH0JWDnve96saXAKVyhd09K4ELG8M0LyS636cxkXlCdGwfc8cMH/2napwy6L6 kwxP8eYF66+YeOwkMvIAfRGMqc+Idqqzof6dupRSi7LsejOODbUYP43KPeQzeITwE5pu Rq442nYS09zx/bwnt9NFvBkQ7bJ8b8rZhUNM99sGT3cE1Vmu0I6QA0ngcoF/0AFqt/3g abOA5+iG7SRrFJKspHTWyb0K7zSMVzmVb0QhxUtsK7vEsDBABuS9q7jnsYrmVP9PTar4 aa3kYKL8Rxgh2n+rtckXA9FfTVW3KksoNht9J/SSkTQlGfbIUf4Quy9U9kfsgwP4Zc14 fgBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694824325; x=1695429125; 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=xxhu5mShS80K2/3vPmWMk/nseLaV4p5fitYU0fke5+k=; b=h5Eoc7U/cyOkDSHv8uO3lTN7SWTPykh+YfygUz9fGLT3ylUhZy8FHwhIx7hDDSo/3D zBDShhg5sehDvSIyhwJ+vR1S0Ft/lUzSxNkuPabwTE3l3u0Rvb9la1wkerAP4DYWeio1 SW/LEzVOqtrZM8lwQSZyIaaLCDWLJOi3da/a6xs8vnvrbeFK2ZI1NovD+7zb6+/nx49e VESgSgTS3a8jGNnWjE8KlmDIUlmerYa7KV0ubuJ/Le4IkirZRPGnuI/kJJ84PD60M+3y +uH5D2leW3hVF5T+/XFS5hRt2yTG5+L+bsbhNbr5WOBCgHJOxmgBhxOg30mF0sgQnQrU 1Jmg== X-Gm-Message-State: AOJu0YwV6ct/fVbfTw1Djpvn74LJbqkVkSg1zVIMTNgaZ/wcHXzdzAc1 g/pMN1K88AVlJG/PLt/hO9hI71PJNvY= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:690c:2f05:b0:589:a533:405b with SMTP id ev5-20020a05690c2f0500b00589a533405bmr205315ywb.3.1694824325035; Fri, 15 Sep 2023 17:32:05 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 15 Sep 2023 17:31:14 -0700 In-Reply-To: <20230916003118.2540661-1-seanjc@google.com> Mime-Version: 1.0 References: <20230916003118.2540661-1-seanjc@google.com> X-Mailer: git-send-email 2.42.0.459.ge4e396fd5e-goog Message-ID: <20230916003118.2540661-23-seanjc@google.com> Subject: [PATCH 22/26] entry/kvm: KVM: Move KVM details related to signal/-EINTR into KVM proper From: Sean Christopherson To: Catalin Marinas , Will Deacon , Marc Zyngier , Oliver Upton , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Peter Zijlstra , Arnaldo Carvalho de Melo , Sean Christopherson , Paolo Bonzini , Tony Krowiak , Halil Pasic , Jason Herne , Harald Freudenberger , Alex Williamson , Andy Lutomirski Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Anish Ghulati , Venkatesh Srinivas , Andrew Thornton Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email 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 (fry.vger.email [0.0.0.0]); Fri, 15 Sep 2023 17:35:47 -0700 (PDT) Move KVM's morphing of pending signals into exits to userspace into KVM proper, and drop the @vcpu param from xfer_to_guest_mode_handle_work(). How KVM responds to -EINTR is a detail that really belongs in KVM itself, and removing the non-KVM call to kvm_handle_signal_exit() will allow hiding said API and the definition of "struct kvm_vcpu" from the kernel. Alternatively, entry/kvm.c could be treated as part of KVM, i.e. be given access to KVM internals, but that's not obviously better than having KVM react to -EINTR (though it's not obviously worse either). Signed-off-by: Sean Christopherson --- arch/arm64/kvm/arm.c | 3 +-- arch/riscv/kvm/vcpu.c | 2 +- arch/x86/kvm/vmx/vmx.c | 1 - arch/x86/kvm/x86.c | 3 +-- include/linux/entry-kvm.h | 3 +-- include/linux/kvm_host.h | 13 ++++++++++++- kernel/entry/kvm.c | 11 ++++------- 7 files changed, 20 insertions(+), 16 deletions(-) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 6480628197b4..641df091e46b 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -6,7 +6,6 @@ #include #include -#include #include #include #include @@ -929,7 +928,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) /* * Check conditions before entering the guest */ - ret = xfer_to_guest_mode_handle_work(vcpu); + ret = kvm_xfer_to_guest_mode_handle_work(vcpu); if (!ret) ret = 1; diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c index 82229db1ce73..c313f4e90e70 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -667,7 +667,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) run->exit_reason = KVM_EXIT_UNKNOWN; while (ret > 0) { /* Check conditions before entering the guest */ - ret = xfer_to_guest_mode_handle_work(vcpu); + ret = kvm_xfer_to_guest_mode_handle_work(vcpu); if (ret) continue; ret = 1; diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index faf0071566ef..43b87ad5fde8 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 6c9c81e82e65..aab095f89d9e 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -59,7 +59,6 @@ #include #include #include -#include #include #include @@ -10987,7 +10986,7 @@ static int vcpu_run(struct kvm_vcpu *vcpu) if (__xfer_to_guest_mode_work_pending()) { kvm_vcpu_srcu_read_unlock(vcpu); - r = xfer_to_guest_mode_handle_work(vcpu); + r = kvm_xfer_to_guest_mode_handle_work(vcpu); kvm_vcpu_srcu_read_lock(vcpu); if (r) return r; diff --git a/include/linux/entry-kvm.h b/include/linux/entry-kvm.h index e7d90d06e566..e235a91d28fc 100644 --- a/include/linux/entry-kvm.h +++ b/include/linux/entry-kvm.h @@ -42,11 +42,10 @@ static inline int arch_xfer_to_guest_mode_handle_work(unsigned long ti_work) /** * xfer_to_guest_mode_handle_work - Check and handle pending work which needs * to be handled before going to guest mode - * @vcpu: Pointer to current's VCPU data * * Returns: 0 or an error code */ -int xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu); +int xfer_to_guest_mode_handle_work(void); /** * xfer_to_guest_mode_prepare - Perform last minute preparation work that diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index fb6c6109fdca..d520d6801070 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -2,7 +2,7 @@ #ifndef __KVM_HOST_H #define __KVM_HOST_H - +#include #include #include #include @@ -2293,6 +2293,17 @@ static inline void kvm_handle_signal_exit(struct kvm_vcpu *vcpu) vcpu->run->exit_reason = KVM_EXIT_INTR; vcpu->stat.signal_exits++; } + +static inline int kvm_xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu) +{ + int r = xfer_to_guest_mode_handle_work(); + + if (r) { + WARN_ON_ONCE(r != -EINTR); + kvm_handle_signal_exit(vcpu); + } + return r; +} #endif /* CONFIG_KVM_XFER_TO_GUEST_WORK */ /* diff --git a/kernel/entry/kvm.c b/kernel/entry/kvm.c index c2fc39824157..872617468b4a 100644 --- a/kernel/entry/kvm.c +++ b/kernel/entry/kvm.c @@ -1,17 +1,14 @@ // SPDX-License-Identifier: GPL-2.0 #include -#include -static int xfer_to_guest_mode_work(struct kvm_vcpu *vcpu, unsigned long ti_work) +static int xfer_to_guest_mode_work(unsigned long ti_work) { do { int ret; - if (ti_work & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL)) { - kvm_handle_signal_exit(vcpu); + if (ti_work & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL)) return -EINTR; - } if (ti_work & _TIF_NEED_RESCHED) schedule(); @@ -28,7 +25,7 @@ static int xfer_to_guest_mode_work(struct kvm_vcpu *vcpu, unsigned long ti_work) return 0; } -int xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu) +int xfer_to_guest_mode_handle_work(void) { unsigned long ti_work; @@ -44,6 +41,6 @@ int xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu) if (!(ti_work & XFER_TO_GUEST_MODE_WORK)) return 0; - return xfer_to_guest_mode_work(vcpu, ti_work); + return xfer_to_guest_mode_work(ti_work); } EXPORT_SYMBOL_GPL(xfer_to_guest_mode_handle_work); -- 2.42.0.459.ge4e396fd5e-goog