From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 EA449283FFB for ; Mon, 5 Jan 2026 15:52:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767628328; cv=none; b=p6bTlBcESYcZOMFP0roFhEA0aE92LBSPSUV8vhYkqqEKkyXeNMd4s7nJCVflhwG0ebM+J6LAtg/ZogGGGw3601LSypRUdmI2ZhklpEYDfEqP3sc2oZqdKLJU/cSeSmQvQXuNWWMes/igk0wZGovZT2Pm28NNPhKIYNpI9aXjTHw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767628328; c=relaxed/simple; bh=RCqc1K2H51T+0fRx+YAw2QfwgUtkd5MfFqKUMXEaI9E=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=pv2P2AhTgrvRgHhbgwYMJEApkNpO9S1Bi5pZolZcJ4JrOmKbPl7bD49yVUFDKRywzIlLrw6IFR4P6CJFR+F3mHt4maDoKT67biurrJM2a20S3HuFeq9KFdhD6I5acZZHGTo4KCVvcCuab/x2cnamkY4dg4UKlp9xBj0V0rE5N/A= 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=rNOiiN49; arc=none smtp.client-ip=209.85.216.74 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="rNOiiN49" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-34eb6589ed2so98751a91.2 for ; Mon, 05 Jan 2026 07:52:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1767628326; x=1768233126; 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=u7ZrFjM0PFkxi63NtaMx1QrjwmvFUSpNxs6Nn+92Dw8=; b=rNOiiN49uKrAUy7L3MlQ9Pc1V7zQT5OpFb0qagoODZ1LIonRE/Ncw87b+GRm7p4A7v UPOLJUZbppb8PMyVpxiPeHjwoxTUbibf2DLmqLQiCT7POZjeY37ma6tjTyPPH5jNJVBt LF7d27RP6iw77fGfMq9FfmK+fHBZlHN4MQ/S9RSD4koh3KdV/CG0YlU1I+0E8MYSMm2t R+jKPzqdzAU+GtiyrN0kpUojqDPqAmy3CRmQpRo7nymW2khgVbNSF9n/tRy8md0c0TQO 98PPH8kj1jdr8f45Ep6N1dbhdDV+F0y+swDVopHHRT78bi+nHGyPtVCWj/4serS/nQZv Ybqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767628326; x=1768233126; 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=u7ZrFjM0PFkxi63NtaMx1QrjwmvFUSpNxs6Nn+92Dw8=; b=TTQ6MK3Ptg4QRx8fRS7fLBBlsE9EtDgxWJAtG4DQt+Q6ABIyyNxy/UpHNSBvAqDzrX J2E0LwSGV0kk9o6JQQSkMfP2uPwWrw1J+nmHqx5glAQunP8GdAFZuXsDZCHFtWJN+BBs CsrevvVjUrUrtzjraF3KXSebxcqhk94OT5yawUpmxSIhJkZBRqM1KDTKadXEcmwsGvna c5XJ408LZxxsb7Ecu5hgDd+2w4ZwVPA9rbSxAcJ2cmDpsApKTtyne9h1ou9x/1j6pyZ1 VZRIneF7C1EiUAC35Utpvmx/498i6FGYgFUYUyUF4bM6rKBHpkZ3SiMLzSaSJNcUE/zI //Iw== X-Forwarded-Encrypted: i=1; AJvYcCVriO9wGU4DXfqWb7m92cdgX/20VLIR6ESR/L2NgOlOdS82XA9XvpUOwcB2y1D+aar6Dk8+M0aPDW1JJ+w=@vger.kernel.org X-Gm-Message-State: AOJu0YybJNhQSHxf7pxS8fpYDisLhOUDFBnTrDg8Z5hHODXhxk0jffDr GsOjTg090djppqdc+cedAVKTY9l5HUuez5JSsGBbR0fDkGRoOoz8t2g5/26sXGFh3t6TA9C279l R5W8vEg== X-Google-Smtp-Source: AGHT+IEWgZO5625IXW8fQ0Tp1xvUFHo/yvm04nNJi/rgYNfnXJNwr5M+AFDOogDHvIl8zXGJ+W/FMgqnXK4= X-Received: from pjca7.prod.google.com ([2002:a17:90b:5b87:b0:34e:8f5a:9197]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3c4b:b0:34c:e5fc:faec with SMTP id 98e67ed59e1d1-34e9212f72dmr34857608a91.2.1767628326173; Mon, 05 Jan 2026 07:52:06 -0800 (PST) Date: Mon, 5 Jan 2026 07:52:01 -0800 In-Reply-To: <87eco8bajg.fsf@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251230211347.4099600-1-seanjc@google.com> <20251230211347.4099600-9-seanjc@google.com> <87eco8bajg.fsf@redhat.com> Message-ID: Subject: Re: [PATCH v2 8/8] KVM: SVM: Assert that Hyper-V's HV_SVM_EXITCODE_ENL == SVM_EXIT_SW From: Sean Christopherson To: Vitaly Kuznetsov Cc: Paolo Bonzini , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , kvm@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, Jim Mattson , Yosry Ahmed Content-Type: text/plain; charset="us-ascii" On Fri, Jan 02, 2026, Vitaly Kuznetsov wrote: > Sean Christopherson writes: > > > Add a build-time assertiont that Hyper-V's "enlightened" exit code is that, > > same as the AMD-defined "Reserved for Host" exit code, mostly to help > > readers connect the dots and understand why synthesizing a software-defined > > exit code is safe/ok. > > > > Signed-off-by: Sean Christopherson > > --- > > arch/x86/kvm/svm/hyperv.c | 6 ++++++ > > 1 file changed, 6 insertions(+) > > > > diff --git a/arch/x86/kvm/svm/hyperv.c b/arch/x86/kvm/svm/hyperv.c > > index 3ec580d687f5..4f24dcb45116 100644 > > --- a/arch/x86/kvm/svm/hyperv.c > > +++ b/arch/x86/kvm/svm/hyperv.c > > @@ -10,6 +10,12 @@ void svm_hv_inject_synthetic_vmexit_post_tlb_flush(struct kvm_vcpu *vcpu) > > { > > struct vcpu_svm *svm = to_svm(vcpu); > > > > + /* > > + * The exit code used by Hyper-V for software-defined exits is reserved > > + * by AMD specifically for such use cases. > > + */ > > + BUILD_BUG_ON(HV_SVM_EXITCODE_ENL != SVM_EXIT_SW); > > + > > svm->vmcb->control.exit_code = HV_SVM_EXITCODE_ENL; > > svm->vmcb->control.exit_info_1 = HV_SVM_ENL_EXITCODE_TRAP_AFTER_FLUSH; > > svm->vmcb->control.exit_info_2 = 0; > > Reviewed-by: Vitaly Kuznetsov > > Alternatively (or additionally?) to BUG_ON, I guess we could've > > #define HV_SVM_EXITCODE_ENL SVM_EXIT_SW > > unless including SVM's headers into include/hyperv/hvgdk.h is too big of > a mess. Heh, I had the same thought[*], but Wei pointed out that the definitions in hvgdk.h mirror internal Microsoft headers: On Fri, Nov 14, 2025, Wei Liu wrote: > On Fri, Nov 14, 2025 at 07:22:41AM -0800, Sean Christopherson wrote: > > On Fri, Nov 14, 2025, Michael Kelley wrote: > > > From: Sean Christopherson Sent: Thursday, November 13, 2025 2:56 PM > > > > @@ -281,7 +281,7 @@ struct hv_vmcb_enlightenments { > > > > #define HV_VMCB_NESTED_ENLIGHTENMENTS 31 > > > > > > > > /* Synthetic VM-Exit */ > > > > -#define HV_SVM_EXITCODE_ENL 0xf0000000 > > > > +#define HV_SVM_EXITCODE_ENL 0xf0000000u > > > > > > Is there a reason for making this Hyper-V code just "u", while > > > making the SVM_VMGEXIT_* values "ull"? I don't think > > > "u" vs. "ull" shouldn't make any difference when assigning to a > > > u64, but the inconsistency piqued my interest .... > > > > I hedged and went for a more "minimal" change because it isn't KVM code, and at > > the time because I thought the value isn't defined by the APM. Though looking > > again at the APM, it does reserve that value for software > > > > F000_000h Unused Reserved for Host. > > > > and I can't find anything in the TLFS. Ah, my PDF copy is just stale, it's indeed > > defined as a synthetic exit. > > > > https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/tlfs/nested-virtualization#synthetic-vm-exit > > > > Anyways, I'm in favor of making HV_SVM_EXITCODE_ENL an ull, though part of me > > wonders if we should do: > > > > #define HV_SVM_EXITCODE_ENL SVM_EXIT_SW > > I know this is very tempting, but these headers are supposed to mirror > Microsoft's internal headers, so we would like to keep them > self-contained for ease of tracking. > > It should be fine to add the "ull" suffix here. I briefly talked to a > hypervisor developer and they agreed. [*] https://lore.kernel.org/all/aRdJQQ7_j6RcHwjJ@google.com