Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5790204rdb; Wed, 13 Dec 2023 22:14:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IEX8Qq58Ru0CrIWuSM7sm9V76T4Mh5C41rfQ7k6lkrUdt0BuZsvZd+z496QhYXM2O2h84nO X-Received: by 2002:a05:6808:4487:b0:3b9:e607:515c with SMTP id eq7-20020a056808448700b003b9e607515cmr12749992oib.93.1702534456167; Wed, 13 Dec 2023 22:14:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702534456; cv=none; d=google.com; s=arc-20160816; b=rBFoIB2cT/tDzPitjjwDtQfQFyRx9Ri7tYMK3RYGJ5iZy7bJsE4T9OmDW5iHOrSanq FKPhpf/5uHwMCHzi7QPsIZF0qmaNR9X/9IRW43H5zgRxQpG/zBwDU/KFry/2ygRGvcyL K+dbLfbunoN+TucRTsedwPxwtEsnz2vqa8sz4qlaU+EyMBGgaCwCH7JNP4UtiwY3bd/3 J7dXANveqcgJHW2vNo0pOLdDhdHhh1awP98ngTVbQKSG5bj0uu0nm/Sm044a16Lm5f0y uUL9416XLRmVCbIqrLaVJxMI9tLVDBKZ8BXVyKvkWZMPd9aWAraaj2Kw+L5BCrOfMQ0V cbjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=l3sMkRAMQECWLiukPZgPf+GGB55ddSK20MJ/gjXWD1s=; fh=QsU2GcRcheLmR8CDzqPOtI1HD+P+nrS+WXxzg7gb6nI=; b=yU/g12Wk9zoYt29XrqUVWNmmY35D1mtzh4QZJQkk8wbklqqooXV3o7GpSG2bcfAv88 6ZVpa9DzG2OQ4F8Tbb91sWSVugAzwHex11+w7hjhnpMXTr/ACLfDSriqhLQ1816pjQ0N KGppOEahAbxvoRut49rXKVd77c/8Yy2fEIoSUhCNF7ETDojTf7LNhECzcOqbn/eZQTcE mIx10VloPUDlXWnfxs7QF0Kaa3SblR118UbUSgwJImbgb551MbKVPgVwCNjafnDZzUsL VReEHpb8ncaca4SanmMBSHQK+Py7r+7U4SnLWX5anEanieV0MMrr1QxWpcmGlV0EUb9p fG2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20230601.gappssmtp.com header.s=20230601 header.b=OyVCbnto; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id x9-20020a056a00188900b006cda14566f1si10653096pfh.150.2023.12.13.22.14.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 22:14:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@brainfault-org.20230601.gappssmtp.com header.s=20230601 header.b=OyVCbnto; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 61BAA82D7518; Wed, 13 Dec 2023 22:14:13 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443121AbjLNGN6 (ORCPT + 99 others); Thu, 14 Dec 2023 01:13:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230117AbjLNGN5 (ORCPT ); Thu, 14 Dec 2023 01:13:57 -0500 Received: from mail-oi1-x235.google.com (mail-oi1-x235.google.com [IPv6:2607:f8b0:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7CEB107 for ; Wed, 13 Dec 2023 22:14:02 -0800 (PST) Received: by mail-oi1-x235.google.com with SMTP id 5614622812f47-3ba2dd905f9so566313b6e.2 for ; Wed, 13 Dec 2023 22:14:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20230601.gappssmtp.com; s=20230601; t=1702534442; x=1703139242; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=l3sMkRAMQECWLiukPZgPf+GGB55ddSK20MJ/gjXWD1s=; b=OyVCbntoESf3PuDmZz/t5WlC3rcPv1BiSso5hvDiLnGK7Dbjzx8dQPW3Wo73nxo+vS C5q28PKjbo8c4K1GE6Hjy7INqx6QAl1Ij4isbGgSsXYYJzSBf15H64MevWcYseE777ui HlZUlv/JsRTXIW7bCQXcJ7HWjKoMFajXiMyN+O609x6yqm6lRYJuOlBZ7ynKObBAAlJX mtazflA1hk/0P5Xuji/tZAbuRU7JR46A9d+HhmEaKrRkRMN4L8aZKCe2tCQcpMR5MO5M nv4aEDLXL7rsAyuxf3TG8EF0lhDSE9sPH+oVvZcj47YBzD+wa4XMq9ssrflavBuMDDWm aKvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702534442; x=1703139242; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=l3sMkRAMQECWLiukPZgPf+GGB55ddSK20MJ/gjXWD1s=; b=nnKvGjMAaXbcGTZh+rJ3DtZc4tnqI1LHqbiCtVeoMN7bhdZeJL+9KrgBQ76VvNI0tF KVMQS43fqynOKxSvGLMOuDDJbgL28fTOWhRPDsbPkOJdDEqzw4S6pP57NYdIsa0FdSKM kwm/eFrLeXBOzoawLzXH6GfM3S1HD63snrvwsOaySRSDeq+70Fw4dIKdBbxY50AS6aca exsI8141hSLq6kt9/bnxv0YgZLxyGT2N55ZrBjBbllNZ03fktELoIxxfbi7GJkDDXMvS AIYRRSXgEIvn0K4YEGRwI9sDv4Bh8RUrnHUqMmTGcTDb7AzNJvhJT7jsjTN3UqmWG6hA 9wGQ== X-Gm-Message-State: AOJu0Yw5B3XwhLT8ZS1NW/yisR2cAjyU4zamqZhutKWWSVVo5rcNA2z0 E21gD6nC7eDg30xZyqfi0Z30DY85Afzn4kt3y5p2zg== X-Received: by 2002:a05:6808:2e85:b0:3ba:8d5:4009 with SMTP id gt5-20020a0568082e8500b003ba08d54009mr11288098oib.110.1702534442120; Wed, 13 Dec 2023 22:14:02 -0800 (PST) MIME-Version: 1.0 References: <20230916003118.2540661-1-seanjc@google.com> <20230916003118.2540661-23-seanjc@google.com> In-Reply-To: <20230916003118.2540661-23-seanjc@google.com> From: Anup Patel Date: Thu, 14 Dec 2023 11:43:50 +0530 Message-ID: Subject: Re: [PATCH 22/26] entry/kvm: KVM: Move KVM details related to signal/-EINTR into KVM proper To: Sean Christopherson Cc: Catalin Marinas , Will Deacon , Marc Zyngier , Oliver Upton , Huacai Chen , Michael Ellerman , 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 , Paolo Bonzini , Tony Krowiak , Halil Pasic , Jason Herne , Harald Freudenberger , Alex Williamson , Andy Lutomirski , 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" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.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 (howler.vger.email [0.0.0.0]); Wed, 13 Dec 2023 22:14:13 -0800 (PST) On Sat, Sep 16, 2023 at 6:02=E2=80=AFAM Sean Christopherson wrote: > > 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 For KVM RISC-V: Anup Patel Regards, Anup > --- > 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 =3D xfer_to_guest_mode_handle_work(vcpu); > + ret =3D kvm_xfer_to_guest_mode_handle_work(vcpu); > if (!ret) > ret =3D 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 =3D KVM_EXIT_UNKNOWN; > while (ret > 0) { > /* Check conditions before entering the guest */ > - ret =3D xfer_to_guest_mode_handle_work(vcpu); > + ret =3D kvm_xfer_to_guest_mode_handle_work(vcpu); > if (ret) > continue; > ret =3D 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 =3D xfer_to_guest_mode_handle_work(vcpu); > + r =3D 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 m= ode > - * @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 tha= t > 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 k= vm_vcpu *vcpu) > vcpu->run->exit_reason =3D KVM_EXIT_INTR; > vcpu->stat.signal_exits++; > } > + > +static inline int kvm_xfer_to_guest_mode_handle_work(struct kvm_vcpu *vc= pu) > +{ > + int r =3D xfer_to_guest_mode_handle_work(); > + > + if (r) { > + WARN_ON_ONCE(r !=3D -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 *vcp= u, 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 *vcp= u) > 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 >