From nobody Sat Feb 7 22:21:10 2026 Received: from mail-oi1-f201.google.com (mail-oi1-f201.google.com [209.85.167.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB0BE215055 for ; Thu, 15 Jan 2026 22:52:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768517563; cv=none; b=JT+PEeHZz9yS8/1Lt99k84LPAR/ul2lkCp0H9jAdL0HI9qulrvJEBDMDL+0phfuAmiqK0ScT0Tqk8SYLxJLT+iR30gAIAJVPvyvpRdkrqT9gOca+Lx+0lIjq+N3Z6GTg+I64mawjPUNCI8g6r65BNyCFYT3uZ6yjcDLsY4gdHLo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768517563; c=relaxed/simple; bh=E+D/xWOr1s8GCE/Wqb9NdzI/sxSTWm/3fxHESTDH6c8=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=EnLRO1zRPxiTP3uI6i8INPOfMPD7LChwTwZeIuE4RAJWowcV3bfgRAjk2D4rm0J19K/eqlIOjEG/VjorXlq0bhNNWCKHkWbc9iQfKp8iRym6x+o0Im4Zj6Od4nSYkJL7N/pdN6J3FG3p/6w7YQnNrzfP4ot/VL56oRVmZLwgzVk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--sagis.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=LlEwYoMn; arc=none smtp.client-ip=209.85.167.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--sagis.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="LlEwYoMn" Received: by mail-oi1-f201.google.com with SMTP id 5614622812f47-45c840f19f4so3065761b6e.3 for ; Thu, 15 Jan 2026 14:52:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1768517561; x=1769122361; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=TRmKjaBXNK+AvtD0p9RP9J8FQ82ubxpDWL/utJgxLnI=; b=LlEwYoMnDMAE9vmARkr9Y5EDlNs0TpqSF3FByyYPMC5UWH0SIw4Krr6ow3PZOXN+S9 yKaMh8oJjsxkVL3RpiP7QX8vLDZnpuPEWgsoVI+BYuJMHpQRGBrIMHrUk6vlcVD/QUGg f3Hw9XKi8rld2u5gQtJrHG3Ld+IqUo1N7jfZmvRbSzfEozA7Exo+eKXm+LjnME+egzb4 4op7ZPsZ3CWeOo95WI2hDT922CWpkL1mDURZo0Et4QdK1qZLdR6+jfpvADv1B9r/QtDv ymQywLIrMIYBPRqy8mn0OUTi3w2T6MKHyAe01jFyQzAguoJxOt1TjN9nic1UMqw1jayJ CD6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768517561; x=1769122361; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=TRmKjaBXNK+AvtD0p9RP9J8FQ82ubxpDWL/utJgxLnI=; b=fleP/QQ8H0TlLk/ZV6lFEicJtvfanIawf+QAJ1KXqz4Twla4em/kp4nwt1caM4oxcU +vdqCb9Am/wqioxPPg3S+qw9BQFaR43FFES3d5uaafYHpT40AYV/uQ2jfpwH0HsAGeLl zld2Lpqjj2KFoR5VfYmHx9YGqRBVoHPBOTR0KeSMDBztEDpd7qsDhYUgy5UMkKWoMb/J U1FOAAoGeDs0GBUZt1QpNbtwfA4cNDwMH6qLRzNTqr6xo/Nmzvh78TXK4lgvEsPzyKmk 9AqoBGJ1wGJmDJbFeI0T3AK4edOP2kytXWHnWnmy7+B4f//RRWYRvg8rSeR7RxujORae ojcg== X-Forwarded-Encrypted: i=1; AJvYcCUejYIyAKvKylD54hmkyPMMRJDWwYg1fql1OLbzgWtLH4Cg6GAE1kvRQ40chkicv5ALVX4r2xjUaMZpwE0=@vger.kernel.org X-Gm-Message-State: AOJu0YxgN1aeOvNzPSnVP9G+mV5YymBrcVYju4kBTE5Jwbc0hoEKVPxP G54L0f8CmpwQFmYDkevVY9f3MX4WueLE650UdCEGGPrghF6GipPoqrgsiGBL6yJQh3MRIAvzwFV cUA== X-Received: from oijr5.prod.google.com ([2002:a05:6808:aa5:b0:45c:7cc1:5636]) (user=sagis job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6808:1b1f:b0:45a:4189:d2cf with SMTP id 5614622812f47-45c9d70a437mr379132b6e.8.1768517560722; Thu, 15 Jan 2026 14:52:40 -0800 (PST) Date: Thu, 15 Jan 2026 22:52:37 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260115225238.2837449-1-sagis@google.com> Subject: [PATCH v2] KVM: TDX: Allow userspace to return errors to guest for MAPGPA From: Sagi Shahar To: Sean Christopherson , Paolo Bonzini , Dave Hansen , Kiryl Shutsemau , Rick Edgecombe Cc: Thomas Gleixner , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-coco@lists.linux.dev, Vishal Annapurve , Sagi Shahar Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Vishal Annapurve MAPGPA request from TDX VMs gets split into chunks by KVM using a loop of userspace exits until the complete range is handled. In some cases userspace VMM might decide to break the MAPGPA operation and continue it later. For example: in the case of intrahost migration userspace might decide to continue the MAPGPA operation after the migration is completed. Allow userspace to signal to TDX guests that the MAPGPA operation should be retried the next time the guest is scheduled. This is potentially a breaking change since if userspace sets hypercall.ret to a value other than EBUSY or EINVAL an EINVAL error code will be returned to userspace. As of now QEMU never sets hypercall.ret to a non-zero value after handling KVM_EXIT_HYPERCALL so this change should be safe. Signed-off-by: Vishal Annapurve Co-developed-by: Sagi Shahar Signed-off-by: Sagi Shahar --- arch/x86/kvm/vmx/tdx.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index 2d7a4d52ccfb..9bd4ffbdfecf 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -1189,7 +1189,13 @@ static int tdx_complete_vmcall_map_gpa(struct kvm_vc= pu *vcpu) struct vcpu_tdx *tdx =3D to_tdx(vcpu); =20 if (vcpu->run->hypercall.ret) { - tdvmcall_set_return_code(vcpu, TDVMCALL_STATUS_INVALID_OPERAND); + if (vcpu->run->hypercall.ret =3D=3D EAGAIN) + tdvmcall_set_return_code(vcpu, TDVMCALL_STATUS_RETRY); + else if (vcpu->run->hypercall.ret =3D=3D EINVAL) + tdvmcall_set_return_code(vcpu, TDVMCALL_STATUS_INVALID_OPERAND); + else + return -EINVAL; + tdx->vp_enter_args.r11 =3D tdx->map_gpa_next; return 1; } --=20 2.52.0.457.g6b5491de43-goog