From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (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 30A35311952 for ; Fri, 30 Jan 2026 01:28:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769736486; cv=none; b=gnvUUYoHTCJZUZBt6hPuRGvTF7yEyg5bpkhVNr1U7bCAb0A98wxqAjmngdM8BwtcW0fU+ry9IbLNox+AiVwYlXdbvKZKJQ3aVptZnYdATphBTGfZzmrOyiUD5KlwEP1jBJbfvvVGHz4ny7nEqWZRn2y96xlXcDIsPtRI5W3dIt4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769736486; c=relaxed/simple; bh=3taJYbZdCbrpWbXI7XIdYXHLYZ3hNlpBVda8BMbduFE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=FCsgRK131IHjetXKpOY0RDI2cyPKfqWlxGzbuTSoXYrcCffRxmsn3vNCg7lhhgOVKihZBtlmboRCreXS7CJJyVGqw039Ltz6kh8xN3dDBr54VXmPBNXP1dy2soD97pa1SmljnHkGbauW6lBWF6jI9IMcur5fzICFi7fiJKQATWg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=EKPwrU0c; arc=none smtp.client-ip=209.85.210.202 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--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="EKPwrU0c" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-81f53036ac9so1429713b3a.3 for ; Thu, 29 Jan 2026 17:28:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769736484; x=1770341284; darn=lists.linux.dev; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Go9/SPH+2Gh6etMrbpw5IFO/ov1QdlQoCkDEqINUYds=; b=EKPwrU0cl97IB4ICzo7nTpVWT7y8kQ8rH4ah9Cy875asF/mc0jaGNVZFbHoGIggCBr W8B1jfOiZ3ohW7aT7CkFRsUYdPGYCx1l8pLyT4yD9MO+9dHqPFp0mMef+y7SBeHSGZ3X 70gbHQX3nqTdwhvshuHbhAmkRAd3Lzm22QLMVYcOt0KMgSsiIaHzsjZqQ91oTtCZOKQV lH6uQgf/+R7XkYCe60Wl/XLHYz7Xx/Nd7BvqGUuKYqVRIvwX7+qqv564Vk6un0W2w6YT OIECFFVU2OEau7juYddlBZrr93wUhSaiV57q8p5sm7zwhmPqgwJuYYNrrbbo3X+ntKYp 0G9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769736484; x=1770341284; h=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; bh=Go9/SPH+2Gh6etMrbpw5IFO/ov1QdlQoCkDEqINUYds=; b=C0olHdXu0FH4eqdwBMJ3u7oCSByKLWPUz5PArUaOnJd5cXRA3ka2TQFgPxzAmKzc/j p21SKNiEHrnZRmzkY/5e3+Flom1Bp6o2c3/6zTxE98t7eIpiW+ft8v8Ata/x8ZAB3bS7 Jb5SDXL15E/J6jgrWH4Vtj74Ab4xXCLfm6vN48bdSQO5C7ttDIw1UqqKXjxDC1DACNmj 2rA6W6/lKe470VFjtGCd7MiuHYmOZR3kp4Sbi2bd/c6zHs8BpRhyR85qRFPYuX6k8u6K ropbG23HtQncXuh8jsK2bpdSW68rmB/3enPLdJ9nGENm7ssjMPltsqtpsZVtny01bKNX nWfw== X-Forwarded-Encrypted: i=1; AJvYcCVU97IOCWKn+Fh7txvHKhRBNagYvCH8PlxLLX/m5DS9DopxfYCIkC6Pkac8DF2BDR9ej76ukJcESBgE@lists.linux.dev X-Gm-Message-State: AOJu0YxgANKh3maNN/v1VaRVXq5IIUxEu59vLji+0xLbBrlEMKNTuxKW urG8yBnIrb1vDj//MhIwFvXTVxBfLjZUikBVzIB6w6LmjE/AbBczZ8tjEiNg8yXGqx64tjXC2w1 6JjCiew== X-Received: from pfbgi12.prod.google.com ([2002:a05:6a00:63cc:b0:7dd:8bba:6393]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:aa89:b0:821:8569:7f19 with SMTP id d2e1a72fcca58-823ab9853fdmr1132825b3a.59.1769736484397; Thu, 29 Jan 2026 17:28:04 -0800 (PST) Date: Thu, 29 Jan 2026 17:28:02 -0800 In-Reply-To: Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260129011517.3545883-1-seanjc@google.com> <20260129011517.3545883-5-seanjc@google.com> Message-ID: Subject: Re: [RFC PATCH v5 04/45] KVM: x86: Make "external SPTE" ops that can fail RET0 static calls From: Sean Christopherson To: Rick P Edgecombe Cc: "x86@kernel.org" , "dave.hansen@linux.intel.com" , "kas@kernel.org" , "bp@alien8.de" , "mingo@redhat.com" , "pbonzini@redhat.com" , "tglx@kernel.org" , Kai Huang , "ackerleytng@google.com" , "sagis@google.com" , Vishal Annapurve , "linux-kernel@vger.kernel.org" , Yan Y Zhao , Xiaoyao Li , "kvm@vger.kernel.org" , "linux-coco@lists.linux.dev" , Isaku Yamahata , "binbin.wu@linux.intel.com" Content-Type: text/plain; charset="us-ascii" On Thu, Jan 29, 2026, Rick P Edgecombe wrote: > On Wed, 2026-01-28 at 17:14 -0800, Sean Christopherson wrote: > > Define kvm_x86_ops .link_external_spt(), .set_external_spte(), and > > .free_external_spt() as RET0 static calls so that an unexpected call to a > > a default operation doesn't consume garbage. > > > > Fixes: 77ac7079e66d ("KVM: x86/tdp_mmu: Propagate building mirror page tables") > > Fixes: 94faba8999b9 ("KVM: x86/tdp_mmu: Propagate tearing down mirror page tables") > > Signed-off-by: Sean Christopherson > > We don't want to crash unnecessarily, but do we want to get some sort of notice? Hmm, that's probably doable, but definitely in a separate patch. E.g. something like: diff --git a/arch/x86/include/asm/kvm-x86-ops.h b/arch/x86/include/asm/kvm-x86-ops.h index 6083fb07cd3b..270149f84bb4 100644 --- a/arch/x86/include/asm/kvm-x86-ops.h +++ b/arch/x86/include/asm/kvm-x86-ops.h @@ -3,6 +3,13 @@ BUILD_BUG_ON(1) #endif +#ifndef KVM_X86_OP_OPTIONAL +#define KVM_X86_OP_OPTIONAL KVM_X86_OP +#define KVM_X86_OP_OPTIONAL_RET0 KVM_X86_OP +#define KVM_X86_OP_OPTIONAL_WARN KVM_X86_OP +#define KVM_X86_OP_OPTIONAL_RET0_WARN KVM_X86_OP +#endif + /* * KVM_X86_OP() and KVM_X86_OP_OPTIONAL() are used to help generate * both DECLARE/DEFINE_STATIC_CALL() invocations and @@ -94,11 +101,11 @@ KVM_X86_OP_OPTIONAL_RET0(set_tss_addr) KVM_X86_OP_OPTIONAL_RET0(set_identity_map_addr) KVM_X86_OP_OPTIONAL_RET0(get_mt_mask) KVM_X86_OP(load_mmu_pgd) -KVM_X86_OP_OPTIONAL(alloc_external_sp) -KVM_X86_OP_OPTIONAL(free_external_sp) -KVM_X86_OP_OPTIONAL_RET0(set_external_spte) -KVM_X86_OP_OPTIONAL(reclaim_external_sp) -KVM_X86_OP_OPTIONAL_RET0(topup_external_cache) +KVM_X86_OP_OPTIONAL_WARN(alloc_external_sp) +KVM_X86_OP_OPTIONAL_WARN(free_external_sp) +KVM_X86_OP_OPTIONAL_RET0_WARN(set_external_spte) +KVM_X86_OP_OPTIONAL_WARN(reclaim_external_sp) +KVM_X86_OP_OPTIONAL_RET0_WARN(topup_external_cache) KVM_X86_OP(has_wbinvd_exit) KVM_X86_OP(get_l2_tsc_offset) KVM_X86_OP(get_l2_tsc_multiplier) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index cd3e7dc6ab9b..663c9943c0dd 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -2004,8 +2004,6 @@ extern struct kvm_x86_ops kvm_x86_ops; #define KVM_X86_OP(func) \ DECLARE_STATIC_CALL(kvm_x86_##func, *(((struct kvm_x86_ops *)0)->func)); -#define KVM_X86_OP_OPTIONAL KVM_X86_OP -#define KVM_X86_OP_OPTIONAL_RET0 KVM_X86_OP #include int kvm_x86_vendor_init(struct kvm_x86_init_ops *ops); diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index c3d71ba9a1dc..1748f44c81c0 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -143,8 +143,6 @@ struct kvm_x86_ops kvm_x86_ops __read_mostly; #define KVM_X86_OP(func) \ DEFINE_STATIC_CALL_NULL(kvm_x86_##func, \ *(((struct kvm_x86_ops *)0)->func)); -#define KVM_X86_OP_OPTIONAL KVM_X86_OP -#define KVM_X86_OP_OPTIONAL_RET0 KVM_X86_OP #include EXPORT_STATIC_CALL_GPL(kvm_x86_get_cs_db_l_bits); EXPORT_STATIC_CALL_GPL(kvm_x86_cache_reg); @@ -9965,6 +9963,17 @@ static struct notifier_block pvclock_gtod_notifier = { }; #endif +static void kvm_static_call_warn(void) +{ + WARN_ON_ONCE(1); +} + +static long kvm_static_call_warn_return0(void) +{ + WARN_ON_ONCE(1); + return 0; +} + static inline void kvm_ops_update(struct kvm_x86_init_ops *ops) { memcpy(&kvm_x86_ops, ops->runtime_ops, sizeof(kvm_x86_ops)); @@ -9977,6 +9986,12 @@ static inline void kvm_ops_update(struct kvm_x86_init_ops *ops) #define KVM_X86_OP_OPTIONAL_RET0(func) \ static_call_update(kvm_x86_##func, (void *)kvm_x86_ops.func ? : \ (void *)__static_call_return0); +#define KVM_X86_OP_OPTIONAL_WARN(func) \ + static_call_update(kvm_x86_##func, (void *)kvm_x86_ops.func ? : \ + (void *)kvm_static_call_warn); +#define KVM_X86_OP_OPTIONAL_RET0_WARN(func) \ + static_call_update(kvm_x86_##func, (void *)kvm_x86_ops.func ? : \ + (void *)kvm_static_call_warn_return0); #include #undef __KVM_X86_OP