From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 74AE8606A31F for ; Mon, 23 Nov 2026 15:09:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=J7n08E90; dkim=fail reason="signature verification failed" (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=B9x6wQRX DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=xfqswxh2rva+UxqURsK/HwHvsTRGY0FLRGO+r/nteHs=; b=J7n08E90v2hW15Xki5l3CaPnfX pThpQ3NIQ/IKZyS4+LTXCfuZ5JT7V7Y1tFobdf4NAcunIg1KsX7KgRT69DeZhY6yhgxD73nHuEMpa s6wxJdbD4yCzquFgejS+l7+dDycZ03zF8VdffNGT8n1Os7NaByYAYKD8IIlb1rvpTCZ6NfaRvH/FS VFcTJL/GKvvawdwYgpHp+Or+eORdus2fuSjzya+Y9ljqkdqByNUBQRpamQqd0Jpk2YCiAMw/LACdA XEYIS8cR8Xy+Z87L3Aj1cSoHEvoS80y5fqdDzw2VscxfEACDCbp3VWRwhwJwFZIrpfS2mWecEDAvf TrOUk7NA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xVVfw-00000003ubi-0MO6; Mon, 23 Nov 2026 15:09:48 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xVVfv-00000003ubb-1WrQ for kvm-riscv@lists.infradead.org; Mon, 23 Nov 2026 15:09:47 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id C951962264; Mon, 23 Nov 2026 15:09:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4A2F1F000C6; Mon, 23 Nov 2026 15:09:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795446586; bh=dnrRfjLKmIHDzHFw2YMyKPd3bYE0BLJV4hjG0NzpuHY=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=B9x6wQRXV+lRd06FkMrkTcZJeaS8e3jKOIyXDTANXZqBMOvrR7KOjDyWtCjEChBDL j5Y71qINNgguMOorYNzL7fKWDS1xnps2HarzILPgiCJxVqW9l/EC7xCStdAaT/eej2 RJyu8K2qXQou6Nv7kib6MPEB7zCBTWIZYIEwOLADYEg6x/lWkemMCtYlnUVk+utNKl LWINkzV/1Ome0GRNKk4Mwe/dZFz44LhqCnu7ys9jz8oLXgsulh3anRrU76m0FTriFc 32562AhcsRlcrH3xdfq4ALU+mZnwxHQP766Mmn+QFltMAR685VD564pFHboFGfb1qm s/gtz/HsAkX0g== Date: Mon, 23 Nov 2026 15:09:37 +0000 From: "Lorenzo Stoakes (ARM)" To: Fuad Tabba Cc: Paolo Bonzini , Sean Christopherson , kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Jonathan Corbet , Shuah Khan , Isaku Yamahata , Rick Edgecombe , Alexandru Elisei , Marc Zyngier , Oliver Upton , kvmarm@lists.linux.dev, Wei-Lin Chang , Anup Patel , Atish Patra , kvm-riscv@lists.infradead.org, Will Deacon , Fuad Tabba Subject: Re: [PATCH v3 2/3] KVM: Warn userspace against ioctls while an exit is pending Message-ID: References: <20261123113435.1170711-1-fuad.tabba@linux.dev> <20261123113435.1170711-3-fuad.tabba@linux.dev> X-Archived-By: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20261123113435.1170711-3-fuad.tabba@linux.dev> X-BeenThere: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "kvm-riscv" X-Spam-Status: No, score=-13.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Mon, Nov 23, 2026 at 11:34:34AM +0000, Fuad Tabba wrote: > KVM_PRE_FAULT_MEMORY sets run->exit_reason to KVM_EXIT_DIRTY_RING_FULL > when it stops on a full dirty ring. If an MMIO exit is pending at that > point, the next KVM_RUN on arm64 and riscv doesn't complete it. Rather > than document that case alone, which could suggest that other ioctls > are safe, warn against invoking any ioctl other than KVM_RUN before a > pending exit is completed. > > Suggested-by: Sean Christopherson > Signed-off-by: Fuad Tabba Very much agree with Sean's take here that we should instil sufficient fear in users at doing silly things (also in general not only KVM :). I wonder if we could add some specific examples or broad description of why it's unwise for better effect, though? Comments below. In general though: Reviewed-by: Lorenzo Stoakes (ARM) > --- > Documentation/virt/kvm/api.rst | 11 +++++++---- > 1 file changed, 7 insertions(+), 4 deletions(-) > > diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst > index 89eb6be9bc6e3..980ef0cdc1c91 100644 > --- a/Documentation/virt/kvm/api.rst > +++ b/Documentation/virt/kvm/api.rst > @@ -6974,10 +6974,13 @@ to the byte array. > > The pending state of the operation is not preserved in state which is > visible to userspace, thus userspace should ensure that the operation is > - completed before performing a live migration. Userspace can re-enter the > - guest with an unmasked signal pending or with the immediate_exit field set > - to complete pending operations without allowing any further instructions > - to be executed. > + completed before performing a live migration. In general, userspace should > + exercise extreme caution when invoking ioctls other than KVM_RUN prior to > + completing the original operation. Perhaps worth saying why? E.g. (as I understand it) that for these exits the operation is only completed on the next KVM_RUN, and that KVM relies on state left over from the exit (including parts of struct kvm_run such as exit_reason) to do so, so any ioctl invoked in between might clobber that state? I see you intentionally avoided documenting the pre-fault case on its own, but with the above stated I think a concrete example might be example here, like e.g.: "For example, if you were to ... that would result in ... which would absolutely ruin your day because ..." Kinda thing :) > + > + Userspace can re-enter the guest with an unmasked signal pending or with > + the immediate_exit field set to complete pending operations without > + allowing any further instructions to be executed. > > :: > > -- > 2.47.3 > > -- Cheers, Lorenzo -- kvm-riscv mailing list kvm-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kvm-riscv From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795446586; b=1IXKWd2z+BCIA/Dya2hw1ELupjBw9Nb9bYJRDLA4luZymftHIhwWYeIQ327UindjL9Hs WqV9ew5epBs706pEjuWReQCRtT7XEJ1rOxywGu3s893rqY2owAL98ee/VjLCEYX/uRGZj kHPsldJD5xFeu+E4xOcBJwt4tw8QD5gDrXedlh7tKvtDVWhF48EcNP+rCmkQvUjBL6SMw eSvoIP68nu7wz47IdCe7DNrBZHHpu6sJI9klOYJXb7Ud7/w4KghtCcj6tAtUjryp4U829 6zCBLO1C7tVL/12puyLppxKPw3uNKY1Uox+o7J162tarfKOxsRRhFJQjj3gFrN28CWg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795446586; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=dnrRfjLKmIHDzHFw2YMyKPd3bYE0BLJV4hjG0NzpuHY=; b=Jd6OFtQMPmUj2kCkK0IhAO4w7pgXveAzDelTzTmrmRwqfPz5/pS9YlUWsrwWAa6hJU8/ NMddgnss2SjVIsxNs0Z3K3rUEPinwBJcUVw61T6wU758V9H8e0EIn+AD7mAvlodoWN4Aq ItR2ssAuqgLQwvwRENv9pk+tVbEa0UOFUcTEvpqXHJ1QDhwFHOuAV1kY7Alz/iSWCksJz UH3ayA8Q32ER+Lrm7PE2iOhF+yP7J0ujh5KHOSevAP1XCvMYC/TP4Pu+2TGa7P+Nvt/+A Q/JtA+aqsyTDNmy/xHAzVncEJ8h9QN/5hHlR5dSN8kfM5lOrD9sbkDXOfjp4+jLo2cA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=B9x6wQRX; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1615606A31E; Mon, 23 Nov 2026 15:09:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=B9x6wQRX Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4A2F1F000C6; Mon, 23 Nov 2026 15:09:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795446586; bh=dnrRfjLKmIHDzHFw2YMyKPd3bYE0BLJV4hjG0NzpuHY=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=B9x6wQRXV+lRd06FkMrkTcZJeaS8e3jKOIyXDTANXZqBMOvrR7KOjDyWtCjEChBDL j5Y71qINNgguMOorYNzL7fKWDS1xnps2HarzILPgiCJxVqW9l/EC7xCStdAaT/eej2 RJyu8K2qXQou6Nv7kib6MPEB7zCBTWIZYIEwOLADYEg6x/lWkemMCtYlnUVk+utNKl LWINkzV/1Ome0GRNKk4Mwe/dZFz44LhqCnu7ys9jz8oLXgsulh3anRrU76m0FTriFc 32562AhcsRlcrH3xdfq4ALU+mZnwxHQP766Mmn+QFltMAR685VD564pFHboFGfb1qm s/gtz/HsAkX0g== Date: Mon, 23 Nov 2026 15:09:37 +0000 From: "Lorenzo Stoakes (ARM)" To: Fuad Tabba Cc: Paolo Bonzini , Sean Christopherson , kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Jonathan Corbet , Shuah Khan , Isaku Yamahata , Rick Edgecombe , Alexandru Elisei , Marc Zyngier , Oliver Upton , kvmarm@lists.linux.dev, Wei-Lin Chang , Anup Patel , Atish Patra , kvm-riscv@lists.infradead.org, Will Deacon , Fuad Tabba Subject: Re: [PATCH v3 2/3] KVM: Warn userspace against ioctls while an exit is pending Message-ID: References: <20261123113435.1170711-1-fuad.tabba@linux.dev> <20261123113435.1170711-3-fuad.tabba@linux.dev> X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261123113435.1170711-3-fuad.tabba@linux.dev> On Mon, Nov 23, 2026 at 11:34:34AM +0000, Fuad Tabba wrote: > KVM_PRE_FAULT_MEMORY sets run->exit_reason to KVM_EXIT_DIRTY_RING_FULL > when it stops on a full dirty ring. If an MMIO exit is pending at that > point, the next KVM_RUN on arm64 and riscv doesn't complete it. Rather > than document that case alone, which could suggest that other ioctls > are safe, warn against invoking any ioctl other than KVM_RUN before a > pending exit is completed. > > Suggested-by: Sean Christopherson > Signed-off-by: Fuad Tabba Very much agree with Sean's take here that we should instil sufficient fear in users at doing silly things (also in general not only KVM :). I wonder if we could add some specific examples or broad description of why it's unwise for better effect, though? Comments below. In general though: Reviewed-by: Lorenzo Stoakes (ARM) > --- > Documentation/virt/kvm/api.rst | 11 +++++++---- > 1 file changed, 7 insertions(+), 4 deletions(-) > > diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst > index 89eb6be9bc6e3..980ef0cdc1c91 100644 > --- a/Documentation/virt/kvm/api.rst > +++ b/Documentation/virt/kvm/api.rst > @@ -6974,10 +6974,13 @@ to the byte array. > > The pending state of the operation is not preserved in state which is > visible to userspace, thus userspace should ensure that the operation is > - completed before performing a live migration. Userspace can re-enter the > - guest with an unmasked signal pending or with the immediate_exit field set > - to complete pending operations without allowing any further instructions > - to be executed. > + completed before performing a live migration. In general, userspace should > + exercise extreme caution when invoking ioctls other than KVM_RUN prior to > + completing the original operation. Perhaps worth saying why? E.g. (as I understand it) that for these exits the operation is only completed on the next KVM_RUN, and that KVM relies on state left over from the exit (including parts of struct kvm_run such as exit_reason) to do so, so any ioctl invoked in between might clobber that state? I see you intentionally avoided documenting the pre-fault case on its own, but with the above stated I think a concrete example might be example here, like e.g.: "For example, if you were to ... that would result in ... which would absolutely ruin your day because ..." Kinda thing :) > + > + Userspace can re-enter the guest with an unmasked signal pending or with > + the immediate_exit field set to complete pending operations without > + allowing any further instructions to be executed. > > :: > > -- > 2.47.3 > > -- Cheers, Lorenzo