From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) (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 1F93C53446B for ; Thu, 1 Oct 2026 19:39:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.72 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790883545; cv=none; b=KaooHf9mQc9Hjp228mMeexBQ0XRQe42z/v7VKqlqzbyUpEXm+UBaoUDC88yC//67ZAQDtp+EGvShrzv4Q6vcvkPm8DL+PirXS1xk1aH8LBF3gPjCq5tJaZpJovDEjHAm3sKrd4lM76dhpIzZmeONVTlOClJa/gRKiKJNgExc0rk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790883545; c=relaxed/simple; bh=6/G8XOzXqcANkVLz4qIxDCJ+3yExyENjEYd5u2PiG0g=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Xi+48ABL2zXPnwunXj33yvcWPES6KzBIXfOx7L5NKLD7u6MqkNpjWOQRMolOJ7+tqp8er8oZ4lDLhvaBA9aTMsfpo99pNN4Pe9lboQ/ey/5GhKY0cqC4nNkiX6cN32rOTVbXo7NzatgLH4Z3/ypsy3Uwbef87tWag1zrFpJkx+4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--wyihan.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=wEd7m3Nl; arc=none smtp.client-ip=209.85.216.72 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--wyihan.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="wEd7m3Nl" Received: by mail-pj1-f72.google.com with SMTP id 98e67ed59e1d1-39de4e72b33so12095058a91.2 for ; Thu, 01 Oct 2026 12:39:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1790883541; x=1791488341; darn=lists.linux.dev; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=3ua8tU2uXWDcJJvbxGqdIItetaC1EcMoKaALryYwrxc=; b=wEd7m3Nl7Fs+xZbG3pNWs0cGp1z5aXUmZFIYqz96opc4F7wXYN+43fUjdeOdgExSKO 8A4Wv0eD/qarSfEhlbOKdgJG+dyuV8cWHzvVzkr/zYYG3ZmczBHuPhkNnHrSU8iX3Nsk lCWRpaAqaOn6+UCguxNM4+hGmYjS+eAUbx4H57Nk4oet0ZrFthbZN7DACqTMrXBMcbkH U/2HN9L9MvHBKxcQ4D4pxYzlMeLDbPt5fHm9/PqxjrCotxpMFky+bD7I7pE0NszpOafL mUsSQHkmz57b3X/rVfVkw9vgixEqiCBuj7A3dEDiUyJkBSBOv19hBWRUGRVaU96RnQmG 3Z2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790883541; x=1791488341; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=3ua8tU2uXWDcJJvbxGqdIItetaC1EcMoKaALryYwrxc=; b=Tsxwh5CZY79ybtx23yQlgtaDHildFdDX+NslGBd0jfD3IygPCwWuQGSKs997vtXFa4 bzUzXGFe3DeZhCIEW45lMGxnmlLQZ+OBTYINsrImvhcV7cMSzwFQw+MOe+pHhHL8KFnS TBsm/qCt6535W0ux7er4AbGhLUinbxc+NRvXivDlbNPvH9IigBdCvwwdIOBxdbrt9mxR ejEwQAAjg1Jf4AjpflEP6jWEdLWMWNlCMfYnmMiP4d4i/fkN9+Q3CZupBSyODbBlFQL/ 2jaU8bcjMSWCDU/zUalB0qo1XVf3jUStcpuvUZq4WbGdPMn9T4X2rrx7Tc71xdREDL2g Br1A== X-Forwarded-Encrypted: i=1; AKwUvBzLG3MaMEgNpQX1vO0sfl2AR4h8C7N8bM3jrxAJoG5zOFwYbuvnvjQA3d6UZs/zwqLnvjMtXai4zHnR@lists.linux.dev X-Gm-Message-State: AFq9FYK/75sDwRYL5YPs1BlDBePqyPh/NybtgTLPoVYLybD+uBpgTnSh T9wRbkUrQnjP4I02pN04dd87ItAM6g5ufWj3tRWsILXbXu+RX7vbsPuYKrEBbpyfTkGwsJTCDtY obwaP5Q== X-Received: from pjps3.prod.google.com ([2002:a17:90a:a103:b0:3a0:e112:7ce0]) (user=wyihan job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3b8b:b0:3a0:d82b:2390 with SMTP id 98e67ed59e1d1-3a6cecfe7f7mr498796a91.46.1790883540606; Thu, 01 Oct 2026 12:39:00 -0700 (PDT) Date: Thu, 01 Oct 2026 19:37:48 +0000 In-Reply-To: <20261001-tdx-selftests-v15-0-7c62a5d8a992@google.com> Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20261001-tdx-selftests-v15-0-7c62a5d8a992@google.com> X-Developer-Key: i=wyihan@google.com; a=ed25519; pk=cRi0fKzS5BMxlHyHY2pJv3w/1zcgfYKr6EYGYppdMYc= X-Developer-Signature: v=1; a=ed25519-sha256; t=1790883521; l=2651; i=wyihan@google.com; s=20260319; h=from:subject:message-id; bh=Pns2Ik0aLmzPL3HWlqfh0hW7xhXQIK/Nnf6snCP/pbM=; b=tDOV13jr3yq7FK6cFemC9g4TUxsjq1VIRNHSlotPMUIQYyH/P2dXtT/tlbEUQKMGyNTDBkI+H Q2X3XTJHhXDDp6ASw/rLshmbffH3Q9nriKd6tDi/oU/J80He3qQ0pjH X-Mailer: b4 0.14.3 Message-ID: <20261001-tdx-selftests-v15-21-7c62a5d8a992@google.com> Subject: [PATCH v15 21/23] KVM: selftests: Add support for per-VM ucall ops on x86 From: Lisa Wang To: Andrew Jones , Ackerley Tng , Binbin Wu , Chao Gao , Chenyi Qiang , Dave Hansen , Erdem Aktas , Ira Weiny , Isaku Yamahata , Kiryl Shutsemau , linux-kselftest@vger.kernel.org, Paolo Bonzini , "Pratik R. Sampat" , Reinette Chatre , Rick Edgecombe , Roger Wang , Ryan Afranji , Sagi Shahar , Sean Christopherson , Shuah Khan , Xiaoyao Li , Oliver Upton Cc: Jeremiah McReynolds , kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, x86@kernel.org, Lisa Wang Content-Type: text/plain; charset="utf-8" From: Sean Christopherson Add a layer of indirection to x86's ucall infrastructure to allow wiring up a different set of {do,get}_ucall() operations for TDX VMs. TDX can't use port I/O (at least, not robustly), as the TDX ABI doesn't allow the guest to share arbitrary register state with the host on a PIO exit, and the PIO data payload is limited to 4 bytes, i.e. would potentially truncate the address of the per-ucall structure. No functional change intended, as the ops are still hardwired to the common x86 ucall functions. Signed-off-by: Sean Christopherson Signed-off-by: Lisa Wang --- tools/testing/selftests/kvm/include/x86/ucall.h | 6 +----- tools/testing/selftests/kvm/lib/x86/ucall.c | 27 +++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86/ucall.h b/tools/testing/selftests/kvm/include/x86/ucall.h index 0e4950041e3e..3639f03a4da9 100644 --- a/tools/testing/selftests/kvm/include/x86/ucall.h +++ b/tools/testing/selftests/kvm/include/x86/ucall.h @@ -2,12 +2,8 @@ #ifndef SELFTEST_KVM_UCALL_H #define SELFTEST_KVM_UCALL_H -#include "kvm_util.h" +#include "linux/kvm.h" #define UCALL_EXIT_REASON KVM_EXIT_IO -static inline void ucall_arch_init(struct kvm_vm *vm, gpa_t mmio_gpa) -{ -} - #endif diff --git a/tools/testing/selftests/kvm/lib/x86/ucall.c b/tools/testing/selftests/kvm/lib/x86/ucall.c index 38050c60a067..c003df3c7b8a 100644 --- a/tools/testing/selftests/kvm/lib/x86/ucall.c +++ b/tools/testing/selftests/kvm/lib/x86/ucall.c @@ -8,13 +8,13 @@ #define UCALL_PIO_PORT ((u16)0x1000) -void ucall_arch_do_ucall(gva_t uc) +static void ucall_x86_do_ucall(gva_t uc) { asm volatile("in %[port], %%al" : : [port] "d" (UCALL_PIO_PORT), "D" (uc) : "rax", "memory"); } -void *ucall_arch_get_ucall(struct kvm_vcpu *vcpu) +static void *ucall_x86_get_ucall(struct kvm_vcpu *vcpu) { struct kvm_run *run = vcpu->run; @@ -26,3 +26,26 @@ void *ucall_arch_get_ucall(struct kvm_vcpu *vcpu) } return NULL; } + +static struct { + void (*do_ucall)(gva_t uc); + void *(*get_ucall)(struct kvm_vcpu *vcpu); +} ucall_x86_ops = { + .do_ucall = ucall_x86_do_ucall, + .get_ucall = ucall_x86_get_ucall, +}; + +void ucall_arch_init(struct kvm_vm *vm, gpa_t mmio_gpa) +{ + sync_global_to_guest(vm, ucall_x86_ops); +} + +void ucall_arch_do_ucall(gva_t uc) +{ + return ucall_x86_ops.do_ucall(uc); +} + +void *ucall_arch_get_ucall(struct kvm_vcpu *vcpu) +{ + return ucall_x86_ops.get_ucall(vcpu); +} -- 2.56.0.rc1.315.gc6ed9934b7-goog