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 5262640E8E9 for ; Fri, 5 Jun 2026 19:14:51 +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=1780686897; cv=none; b=sX/wdteSIkcOWKvCFQhBonW/z1rm4na+ZMuf9zgpu1EGJG36NILvsumuEh1hxlTsRDyb04RW0PqUl6XxuuVR+WGnqbIJ0GqxpUzrAXi3bF9PJNCx0Tg6AMofXSBEVs+5B6m8mwn3t4b+N0oL0eljp9VnI0Jc4aVA4Y1C2AfTHaI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780686897; c=relaxed/simple; bh=At5Udh8CHpF85N4U7U4JZfbUuattsLHjBR78kcVf0AQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mX1cAEP3Qn7EfsOIzE6l97eZYgG98M8gsx16RGfEKyZnlJHZzzRBfitYFs/F6ur0um6n9/EMxc3Bx3L+nzjxb8wj3qjPkE7okdHllmfoQON1gU4ecLBRjUtm0yksK6aLQtuVi8pbPO2CMiVLab/GayhREXeZMEf2EFcWYfnK+lg= 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=AY7Vth/Y; 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="AY7Vth/Y" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-8423f1fe39eso2396440b3a.1 for ; Fri, 05 Jun 2026 12:14:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780686890; x=1781291690; 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=f2XqhZdHrHkagtDnOySYIP3nI8ujGms1N4fcjgqsFN4=; b=AY7Vth/YCDCT2RH0oj1f6eMMTnTM0jUmpXyzvWTzSB5nC2y6RCS03dptjKLeQmpGl/ 3VtXYMbZsKGf355i59aC7v+9dNRAs1vRQCzVHQqg7AmnZOLeTCZCVKx68K77q6WPpHad DdSR7HyBQzZB/1V4SVVr+jjeX0Y7aCiIwQV0WoraXoomE426Pl7hpTBRTwWSxjc8YW66 VpYM7ut07ccr5qbBBUvL3iFOfIiBa/k5PYdL5TE58LApOvskwY6eal5/6I+Op2qmV8il FE9PwO3tI2a6ZGY1NwL6l/ANAZ5fbQXDUP65nonVMNNogyCVZzi6dTgkufRelSRRC/sz lQ2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780686890; x=1781291690; 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=f2XqhZdHrHkagtDnOySYIP3nI8ujGms1N4fcjgqsFN4=; b=Qk0uT43Nj6rU1mVOB7D2OurnqQb2ghk9eAN5J5VUuc1GiqkihNrwKX9054NSu8687h Rdka/DcQsuAlIQ8w3PkbPetMeMMfIxqEzRsddg0/awelJGXJWTa90LGnOSmeIG8RrBM0 itqJhSxs8dtLc+/rGOwrJ2izLRI6iV3ZSofZzIlkKpJ0BllSCcXm3QDhAhcsZE+0E/SH Kbh/gkeF8DUWHeOZVnUzuI+BGCW2u2pErWBpE11633J2ttYvwgiCa/bt2bS1/Xi2olx9 CYuGZf2RtNgYJzy4t2RlgEER5TiwggRutZWVGsGV4IzFQ5SFq9fmJDZatoQg2IsdC2bh DrtA== X-Forwarded-Encrypted: i=1; AFNElJ86SVK9N7Ypq/lb3bSlLc8Y9O0Ji+9eXiaFozxVIG4MLSKd+7WvbaAOizsqUPE1XgTYlyhD68k2R0WeyzY=@vger.kernel.org X-Gm-Message-State: AOJu0Ywka/HjPbsPOFcTrGDmZlRZ/aPWlqjm1zZ+ZVlK3MYUkrlEnX6W 2UsnEFwvtG8JD7AI5x8JslILrI7+Yw+ovWgaGEmt7+dAcnHAxap+r2GBrUa+PSMQXf36Sc9Lmx+ hj/gh0Q== X-Received: from pfblh21.prod.google.com ([2002:a05:6a00:7115:b0:838:4903:1f13]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:1489:b0:82f:5034:77a4 with SMTP id d2e1a72fcca58-842b0e006a3mr5264197b3a.21.1780686890031; Fri, 05 Jun 2026 12:14:50 -0700 (PDT) Date: Fri, 5 Jun 2026 12:14:49 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260529222223.870923-1-seanjc@google.com> <20260529222223.870923-24-seanjc@google.com> Message-ID: Subject: Re: [PATCH v3 23/40] KVM: x86: Move kvm_{load,put}_guest_fpu() to fpu.h From: Sean Christopherson To: Kai Huang Cc: "pbonzini@redhat.com" , "vkuznets@redhat.com" , "dwmw2@infradead.org" , "paul@xen.org" , "kvm@vger.kernel.org" , "dwmw@amazon.co.uk" , "linux-kernel@vger.kernel.org" , "yosry@kernel.org" , "binbin.wu@linux.intel.com" Content-Type: text/plain; charset="us-ascii" On Thu, Jun 04, 2026, Kai Huang wrote: > On Fri, 2026-05-29 at 15:22 -0700, Sean Christopherson wrote: > > +/* Swap (qemu) user FPU context for the guest FPU context. */ > > +static inline void kvm_load_guest_fpu(struct kvm_vcpu *vcpu) > > +{ > > + if (KVM_BUG_ON(vcpu->arch.guest_fpu.fpstate->in_use, vcpu->kvm)) > > + return; > > + > > + /* Exclude PKRU, it's restored separately immediately after VM-Exit. */ > > + fpu_swap_kvm_fpstate(&vcpu->arch.guest_fpu, true); > > + trace_kvm_fpu(1); > > +} > > + > > +/* When vcpu_run ends, restore user space FPU context. */ > > +static inline void kvm_put_guest_fpu(struct kvm_vcpu *vcpu) > > +{ > > + if (KVM_BUG_ON(!vcpu->arch.guest_fpu.fpstate->in_use, vcpu->kvm)) > > + return; > > + > > + fpu_swap_kvm_fpstate(&vcpu->arch.guest_fpu, false); > > + ++vcpu->stat.fpu_reload; > > + trace_kvm_fpu(0); > > +} > > + > > Nit: to me it's a little bit weird to put the two functions before the typedefs > and macro defines below, though. Yeah, I don't disagree. But I think I'd prefer to keep it this way, so that the typedefs are more obviously bundled with the ugly XMM/AVX register helpers. > > > typedef u32 __attribute__((vector_size(16))) sse128_t; > > #define __sse128_u union { sse128_t vec; u64 as_u64[2]; u32 as_u32[4]; } > > #define sse128_lo(x) ({ __sse128_u t; t.vec = x; t.as_u64[0]; })