From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.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 30ACC32F762 for ; Fri, 30 Jan 2026 01:28:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769736486; cv=none; b=acjUrpE5ahlNzm6er/8zP2zs3DXwXfwUV26+rt+F3a5ngqWNUeqtCTsqm3JNQrLShAgqEikNLeuM967pVrLD7VdPURTqVGhGYWx2+WGQOPIdQTuuY9tWWqOLdZEhT8aJLc0pMfVJAsXfhX3h7tEIy/IyDIZhwPNdS/yT5nTPPQM= 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=Q6F/Bw4f; arc=none smtp.client-ip=209.85.210.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--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="Q6F/Bw4f" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-81f48cec0ccso1488198b3a.0 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=vger.kernel.org; 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=Q6F/Bw4fHY/M6k88jL+KHGi9SOH2idIJMvMec7UyMWbZJETTY/aRIBmi0M08Qi8Glq bzwVo7TSXdAT75iBaDFh/G+MK2ZN0zo+qGwRm99R8DNNzfz+cRT1ZV70htii2/b8DQVm YJZfGBd9XhiUzXagd2bZm3j/ftEODaS+yNcW116ImUlCbgo2WtONstkE9fEeFUc/Gwg4 BbOpAThfbTzV4TEi26Tu5KofRfE/P13fYUkdDFY7mAiQ8zF/jpvcE4MZC+8RG9J9WxZA FAR7jUqctnEeHTlfzzK6uBqIEEEvQ4Mxl0V6PgWim+Mt7uEY/U8/OMIrwqZWHerMuafv iYxA== 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=ZSsQRkWQwNspTgccEBcF7FWIP/4DYr5jJuC2KgRO79MiW3mrNXL1HtLQuIskPrIcG2 lFS/GXZLIkSMeW1fgHHLMMqKrfh/zRfXRBKDqP3Gl5mPy4zggdJTdU3OK0xr4zwz6m1p ZUN9KQR6a4np/BhheV6u4SPWEBzC/X66ggx4Zw0EP+iEgHBqqeDYGDbhlzBPFwnIgRcq XDLvzcnk1q+l8iDaGfqoZd2LBk5UDwtPKB5cBF6boQVyU2uHpKqvZT6raQA9yIU0UWvK 2EVrIMfWKmXWYH/dsExdF39l8dVxmge0hNbnUA+JSJTjbDVQ0tc8EoyY6gyx1xYgNAqi qquw== X-Forwarded-Encrypted: i=1; AJvYcCXYR+hb3GPyx6oU/3NPGRiA6wvIr0dViQlPwrGfOQph25m4OjIfzIWrBJJv/8kuO7TKNgdsccd8dF3rukI=@vger.kernel.org X-Gm-Message-State: AOJu0YxpUDDZFpDwM+vxBRNEisLJcaR0zscfX26EuA4nY2izDR05N6Ed kHwfU/l6G+lDAw3m/GLDgL4qp57a6jYfsyeE4asvzbJkc4fhGlQ3t8RFN2Z0AhUVTlp9mXQ4icj gX+T4xw== 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-kernel@vger.kernel.org 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