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 74CF33D34A6 for ; Thu, 14 May 2026 21:54:09 +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=1778795651; cv=none; b=nn+T9OLASYz3pEQ3aAkbsAi4PcIxsuyuitpHUkGKU1h8Vdu7YSeFE5SU1vo6nJWidjMr3t2rzzKLw5cZtIh2aB1oXYtKeh+4P1k/qDGPVFrF4ZcA2tjvdiV1TxJt+KvG5I09RRqUQ4s5aNERZ6nrleGl0NWLBO886zWFsLEVlck= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778795651; c=relaxed/simple; bh=FsAq7KEuatX1Pn52xDkKa5S9Ii59O/tYrQdckY5bUaw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=l0aT06RbKsPk8BBGycc3uI4irN2DgA8vBAAYWwbaQptY/S6l0RUZr8WG1RMMgia9AgkztRnPAISjXIYRCI+9W0ywmdk+IKbPlY4is102mvIzvWIFgwbimm/479ku2z9Ee2dJxLWNCGpGQuNLxvp/9McNx1VehZK694OLx13LfvM= 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=s6hx7fWG; 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="s6hx7fWG" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-82fa7c6699fso10915678b3a.1 for ; Thu, 14 May 2026 14:54:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1778795649; x=1779400449; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=g9vonHXs6r1LN2kGlbzZfFmfFgWCjNXLKuYTABKAIiY=; b=s6hx7fWGUrmKMVbwXM37Ehqom4y48epHMsLjCmeIGb3CxN77F3xZd6W7ISncA5RHub aDSxH/pKMEKh3Qcq1wQB4yWepmQONhpHLAyguy60XZ7iX8AnEFYf1kP903HZevWY5se3 6psq9Br1E5ZnHIsLGUttid74bzsWyvHVBxTXMVPIAdCpYnZfVHS+HiPo7DxocDmTKyi8 jnccU91a6EnhVWZ7P1Dl/ETEXwJvZc1rWygU8NriXo6sWfcud6MWQ3hOFNmhUZW3EcAy c4OVo5TNS0AQVWMvqOMc193hwWzCD0jE14uY2LesCiTyO/4mLOP9Fw+k3xHQVpCcxcuV beyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778795649; x=1779400449; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=g9vonHXs6r1LN2kGlbzZfFmfFgWCjNXLKuYTABKAIiY=; b=hBvLG/yRojGtnftEGZcUW/IIxREvfqfIjjG/cOMVslbN8miYMFSASeF93VUII9gwHe 06TqrOe8TATgr94XjrX903ntg+5OHySWujfZANA60Hx1Xdt6n6YkKiHKc6ga/m5zl/IJ B5/6HPPQoND7RseE81FMElVoOsyTkvFH55/ILOFr06QuilJQpzdraBSnf2+V7rrjmbVj tEGgx9ikOAiag+QEklebQEUwtmjcPGo8jtDIf+bIWCZjL2FiDPjJVAZRtMV8M1JIzhV1 4GBZD/iXfmRVVPhVYDg6OH6muAtN6L8kML4hrpCtOHARNFz+/959EA153nXXnHvT0PFM F9ag== X-Forwarded-Encrypted: i=1; AFNElJ+mm3ULXSspv6y0SuPlUv0cI99EMrgjBhbJKiAxQ7gf1n+R192hkD0PE+ol20mwVLvkcLrteIauZtvte/U=@vger.kernel.org X-Gm-Message-State: AOJu0YyGuGb6Un2IYVJqu6cN8TPB6SIOapT+yh3ZvUA5FZxownMF8w4q XAuRU2UGPXtTHF2ZaZ31VM9K3J1/t88Iu2dIRM2iuAFmpKdQVeuLXszzNzxRekJPa33m6sR8dgz eGRVAyw== X-Received: from pfbem25.prod.google.com ([2002:a05:6a00:3759:b0:835:2a09:221c]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:3a25:b0:82f:1b42:11d0 with SMTP id d2e1a72fcca58-83f33c9bdc4mr1362504b3a.15.1778795648217; Thu, 14 May 2026 14:54:08 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 14 May 2026 14:53:50 -0700 In-Reply-To: <20260514215355.1648463-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260514215355.1648463-1-seanjc@google.com> X-Mailer: git-send-email 2.54.0.563.g4f69b47b94-goog Message-ID: <20260514215355.1648463-11-seanjc@google.com> Subject: [PATCH v2 10/15] KVM: nSVM: Use kvm_rax_read() now that it's mode-aware From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini , Vitaly Kuznetsov , Kiryl Shutsemau , David Woodhouse , Paul Durrant Cc: Dave Hansen , Rick Edgecombe , kvm@vger.kernel.org, x86@kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, Yosry Ahmed , Kai Huang , Binbin Wu Content-Type: text/plain; charset="UTF-8" Now that kvm_rax_read() truncates the output value to 32 bits if the vCPU isn't in 64-bit mode, use it instead of the more verbose (and very technically slower) kvm_register_read(). Note! VMLOAD, VMSAVE, and VMRUN emulation are still technically buggy, as they can use EAX (versus RAX) in 64-bit mode via an operand size prefix. Don't bother trying to handle that case, as it would require decoding the code stream, which would open an entirely different can of worms, and in practice no sane guest would shove garbage into RAX[63:32] and then execute VMLOAD/VMSAVE/VMRUN with just EAX. No functional change intended. Cc: Yosry Ahmed Reviewed-by: Yosry Ahmed Signed-off-by: Sean Christopherson --- arch/x86/kvm/svm/nested.c | 2 +- arch/x86/kvm/svm/svm.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index 7b2d804ef2b0..4b1259eecec5 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -1119,7 +1119,7 @@ int nested_svm_vmrun(struct kvm_vcpu *vcpu) if (WARN_ON_ONCE(!svm->nested.initialized)) return -EINVAL; - vmcb12_gpa = kvm_register_read(vcpu, VCPU_REGS_RAX); + vmcb12_gpa = kvm_rax_read(vcpu); if (!page_address_valid(vcpu, vmcb12_gpa)) { kvm_inject_gp(vcpu, 0); return 1; diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 02fb9560c26e..6379c389d811 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -2217,7 +2217,7 @@ static int intr_interception(struct kvm_vcpu *vcpu) static int vmload_vmsave_interception(struct kvm_vcpu *vcpu, bool vmload) { - u64 vmcb12_gpa = kvm_register_read(vcpu, VCPU_REGS_RAX); + u64 vmcb12_gpa = kvm_rax_read(vcpu); struct vcpu_svm *svm = to_svm(vcpu); struct vmcb *vmcb12; struct kvm_host_map map; @@ -2325,7 +2325,7 @@ static int gp_interception(struct kvm_vcpu *vcpu) if (nested_svm_check_permissions(vcpu)) return 1; - if (!page_address_valid(vcpu, kvm_register_read(vcpu, VCPU_REGS_RAX))) + if (!page_address_valid(vcpu, kvm_rax_read(vcpu))) goto reinject; /* -- 2.54.0.563.g4f69b47b94-goog