From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 DCBDD284672 for ; Mon, 29 Dec 2025 23:46:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767051995; cv=none; b=RaHsMT+c9yDKPqnOvl0fs2oaAROw7hpQ6Q/k/LdgWIDALazEB/qSw+CUteIqZoo1RGbm7ufT+GPYWuTmr0bXwEvE7WSJ8mH6Xtqv4IlD41S5cB8D7ifN5o1nioof5Vc/ZlBjXDrv/pv1uwh6lwalLlKe3+3ujfEyvSWx1DT5zEY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767051995; c=relaxed/simple; bh=Hjv/TIV1UsxvAnQ5o/hxVXWRY8sl9BefdtdnfhdDtCU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Mh57jJbwnLNqPN2M4v3LIRnfanQyTL/+hOisoNf7cKT7uv5gfhIcR7hE8V74AUqTbQ3/Y8ytevUGVY30nqKtNDMhzhgodOOylYY7/UI1VFMXN3fc7muTGXl/ujFQ3sbWbKFj7phdKjTavOLG5tlImQaeCUXP78G4mbp/hOIEKAA= 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=ok7oz4Xh; arc=none smtp.client-ip=209.85.216.73 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="ok7oz4Xh" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-34c38781efcso19277126a91.2 for ; Mon, 29 Dec 2025 15:46:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1767051993; x=1767656793; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=l4xDJPMvIXKXvP5865Cb1+QQa5XZ/DHhQPRje5/U8PA=; b=ok7oz4XhZHvDJlf8nYmbn+eutgWWUTq7Y14M/qQ6IqH4vsZlbMG/hfRvSVWRTX4JNK jBT5ZHUL2tNUWFPIvW5Zm50WnpHJzo+AzAzGU4RW563zb5dIkG/GTwd3YizoTnpKnp8m dQWbkWY6JqEfKa7qjBx+ByYV6ElIegzZc0uD8/o02O4v8LXLDsjuOeVjkbzqYrlZMaGA GbtA48Rlo3iCCyHQsQZiAl/AlJYAWTObRo1xwOzgg3kfW5N6Pij0emlpQMbZtC9mq2Is b0eLJTydbFrXuE2r31C+hPxbXyxTq3pk5sOJRCvK4sJpxgdce99RL5v4l0Dp6uv0C1cj bLWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767051993; x=1767656793; h=content-transfer-encoding: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=l4xDJPMvIXKXvP5865Cb1+QQa5XZ/DHhQPRje5/U8PA=; b=MzWQCxL41/v/YgMrWnJNESGYtLGubPBcJ21uEFLdCDBU/q4NtVyXePJYM/8CFs+vpN SuBnLTHUJEO0PO27rjEnvAo0GnFJHkwfJguqHl4rGbjSdrKqmg92YK72nOweZnZGHFWK k9h8lSHROSIoWim60hpgTOs8BzJKKrEYYv4LUJ0+wpHaxLSgyJ3UkzWgBbUGBfz+9mDY Wimlu1ZA3MZSGFwhnZ2ejUhfGJtdBheH6ozc9ek1bpDXtQCrLnw5ZTScuD3UHCBE5ST5 z3uK6JeT0ZFaUqdVywnZWTLrZCwnxiLLBcAfEPs4kNQtL02id0j/i7d6l9zvmPd7pX6Q aesQ== X-Gm-Message-State: AOJu0YwBLOddQRsqpOX38EmdRKVEgeIhBV2TR7RxT5iKGE/GMW8OoHNn +UmjKvtU5eVuNU0CbVKAOSYNNmgivKCBnICgivmZcNjKDq1xYqV+RZDhO27dV1F7RiS5r5EfQAC oEV7ARw== X-Google-Smtp-Source: AGHT+IGp6fI0koV588PCow0DDG4AaijuZIFTuoh8Uj8mqtB242NSfI8x+gcm6e8CNXigvxl5p4tFT0QHKwU= X-Received: from pjot17.prod.google.com ([2002:a17:90a:9511:b0:349:a1a3:75fc]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:524b:b0:340:e529:5572 with SMTP id 98e67ed59e1d1-34e9212a495mr26328433a91.8.1767051993309; Mon, 29 Dec 2025 15:46:33 -0800 (PST) Date: Mon, 29 Dec 2025 15:46:31 -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: <20251224001249.1041934-1-pbonzini@redhat.com> <20251224001249.1041934-3-pbonzini@redhat.com> Message-ID: Subject: Re: [PATCH 2/5] x86, fpu: separate fpstate->xfd and guest XFD From: Sean Christopherson To: Paolo Bonzini Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, x86@kernel.org, stable@vger.kernel.org Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Tue, Dec 30, 2025, Paolo Bonzini wrote: > On Mon, Dec 29, 2025 at 11:45=E2=80=AFPM Sean Christopherson wrote: > > So, given that KVM's effective ABI is to record XSTATE_BV[i]=3D0 if XFD= [i]=3D=3D1, I > > vote to fix this by emulating that behavior when stuffing XFD in > > fpu_update_guest_xfd(), and then manually closing the hole Paolo found = in > > fpu_copy_uabi_to_guest_fpstate(). >=20 > I disagree with changing the argument from const void* to void*. > Let's instead treat it as a KVM backwards-compatibility quirk: >=20 > union fpregs_state *xstate =3D > (union fpregs_state *)guest_xsave->region; > xstate->xsave.header.xfeatures &=3D > ~vcpu->arch.guest_fpu.fpstate->xfd; >=20 > It keeps the kernel/ API const as expected and if anything I'd > consider adding a WARN to fpu_copy_uabi_to_guest_fpstate(), basically > asserting that there would be no #NM on the subsequent restore. Works for me. =20 > > @@ -319,10 +319,25 @@ EXPORT_SYMBOL_FOR_KVM(fpu_enable_guest_xfd_featur= es); > > #ifdef CONFIG_X86_64 > > void fpu_update_guest_xfd(struct fpu_guest *guest_fpu, u64 xfd) > > { > > + struct fpstate *fpstate =3D guest_fpu->fpstate; > > + > > fpregs_lock(); > > - guest_fpu->fpstate->xfd =3D xfd; > > - if (guest_fpu->fpstate->in_use) > > - xfd_update_state(guest_fpu->fpstate); > > + fpstate->xfd =3D xfd; > > + if (fpstate->in_use) > > + xfd_update_state(fpstate); > > + > > + /* > > + * If the guest's FPU state is NOT resident in hardware, clear = disabled > > + * components in XSTATE_BV as attempting to load disabled compo= nents > > + * will generate #NM _in the host_, and KVM's ABI is that savin= g guest > > + * XSAVE state should see XSTATE_BV[i]=3D0 if XFD[i]=3D1. > > + * > > + * If the guest's FPU state is in hardware, simply do nothing a= s XSAVE > > + * itself saves XSTATE_BV[i] as 0 if XFD[i]=3D1. >=20 > s/saves/(from fpu_swap_kvm_fpstate) will save/ >=20 > > + */ > > + if (xfd && test_thread_flag(TIF_NEED_FPU_LOAD)) > > + fpstate->regs.xsave.header.xfeatures &=3D ~xfd; >=20 > No objections to this part. I'll play with this to adjust the > selftests either tomorrow or, more likely, on January 2nd, and send a > v2 that also includes the change from preemption_disabled to > irqs_disabled. To hopefully save you some time, I responded to the selftests with cleanups= and adjustments to hit both bugs (see patch 3). > I take it that you don't have any qualms with the new > fpu_load_guest_fpstate function, Hmm, I don't have a strong opinion? Actually, after looking at patch 5, I = agree that adding fpu_load_guest_fpstate() is useful. My only hesitation was tha= t kvm_fpu_{get,put}() would be _very_ similar, but critically different, at w= hich point NOT using fpu_update_guest_xfd() in kvm_fpu_get() could be confusing. > but let me know if you prefer to have it in a separate submission destine= d to > 6.20 only. I'd say don't send it to stable@, otherwise I don't have a preference on 6.= 19 versus 6.20.