From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1DD9F51AEF4; Wed, 30 Sep 2026 21:35:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790804104; cv=none; b=DZ2+MnI3fUT4q2gGa0YYfUXc08c1mUByfQ/qr4AykwLBTHiOAhZ+Q9V4n/gvk04AnLFXpbNbYEx/aKhVW7w3o9TvzlVThLBL4OsaxD4QJc+5scDfhRpEZ/a0ZpWOuhqKBiDV3ofuFoIr9KpsJWao96uSFeGmWcW5Pwq8xOWVSrM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790804104; c=relaxed/simple; bh=wAHC/yBpSAZTWpCJUgkzTuClMyeASljlPiSjk/nqt3U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JMb1DOKAiC5SgN1qfcWPO0GY0X5DrFxDCHXB1vO4RTt8alxEX872C0VSNFuLwfcss+AtbKauaCYCyCMDcQeii+0qO5yLpNsUukUCs+MNdcrva9BCGrdtRFpSn50aTEHEM0FK4gDyRK1J0tUm9L+CFMsxTtpEZ4vqQ+KXDdb98vY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=edgCt+BU; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="edgCt+BU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1790804102; x=1822340102; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wAHC/yBpSAZTWpCJUgkzTuClMyeASljlPiSjk/nqt3U=; b=edgCt+BUm/lTA44cxfmf4lD+4DDw8OPjT+CB47ea7GeTBzn2qoVzCHJr iiXlsavjvUvUmzhs5+AJs7nk3nxsGJ4ZlbwloXBq6UAbLPyuyoHuKAQB2 wNkuUbzPDm22UJt/Da+eVwBkN8O3k6R1C78mgJ2FCoEEL+oRb8uVCS0k+ bTEX7v48pU99ataOs+ZB7w4xXRM9KG/CEQT7VOsEO64wJu27CrqbTerOW +ernaMHIR6c1Oa2pIr2WsBOGubjl1DFM8zGfnVgHo+wA64kqAMf8dKdMq KrU0hLEDbIngpMviSDKHliqkwZcTuBGQVayVm+SeI3zp6AZkm46KenqBM g==; X-CSE-ConnectionGUID: QRFWOiPQSrGFJs6L4RpsYQ== X-CSE-MsgGUID: 0L+U18MiQWGpfVREJ6MNGQ== X-IronPort-AV: E=McAfee;i="6800,10657,11921"; a="94432682" X-IronPort-AV: E=Sophos;i="6.27,133,1787036400"; d="scan'208";a="94432682" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2026 14:35:01 -0700 X-CSE-ConnectionGUID: 1WcZTNM7SzGGkigu0pedMQ== X-CSE-MsgGUID: mYZRNp2FTuyrJfECbijqkA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,133,1787036400"; d="scan'208";a="283867237" Received: from chang-linux-3.sc.intel.com (HELO chang-linux-3) ([172.25.66.174]) by fmviesa005.fm.intel.com with ESMTP; 30 Sep 2026 14:35:01 -0700 From: "Chang S. Bae" To: pbonzini@redhat.com, seanjc@google.com Cc: kvm@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, zhao1.liu@intel.com, chang.seok.bae@intel.com Subject: [PATCH v8 07/20] KVM: VMX: Refactor register index retrieval from exit qualification Date: Wed, 30 Sep 2026 21:07:37 +0000 Message-ID: <20260930210750.1487547-8-chang.seok.bae@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260930210750.1487547-1-chang.seok.bae@intel.com> References: <20260930210750.1487547-1-chang.seok.bae@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Introduce a helper to extract the register index from the VMX exit qualification field. In addition to the VMX instruction information field, exit qualification also encodes a register index. This field will expand into the previously reserved bit for extended register IDs. This refactoring will simplify the extended register handling without code duplication. No functional change intended. Tested-by: Zhao Liu Signed-off-by: Chang S. Bae --- arch/x86/include/asm/vmx.h | 1 - arch/x86/kvm/vmx/nested.c | 2 +- arch/x86/kvm/vmx/vmx.c | 4 ++-- arch/x86/kvm/vmx/vmx.h | 5 +++++ 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h index 68835ad9af71..f98e40df5004 100644 --- a/arch/x86/include/asm/vmx.h +++ b/arch/x86/include/asm/vmx.h @@ -455,7 +455,6 @@ enum vmcs_field { #define DEBUG_REG_ACCESS_TYPE 0x10 /* 4, direction of access */ #define TYPE_MOV_TO_DR (0 << 4) #define TYPE_MOV_FROM_DR (1 << 4) -#define DEBUG_REG_ACCESS_REG(eq) (((eq) >> 8) & 0xf) /* 11:8, general purpose reg. */ /* diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index f05ac3c9aa12..7229934c38bb 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -6358,7 +6358,7 @@ static bool nested_vmx_exit_handled_cr(struct kvm_vcpu *vcpu, switch ((exit_qualification >> 4) & 3) { case 0: /* mov to cr */ - reg = (exit_qualification >> 8) & 15; + reg = vmx_get_exit_qual_reg(exit_qualification); val = kvm_register_read(vcpu, reg); switch (cr) { case 0: diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index bd8505d69420..ee975a1ae42f 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -5698,7 +5698,7 @@ static int handle_cr(struct kvm_vcpu *vcpu) exit_qualification = vmx_get_exit_qual(vcpu); cr = exit_qualification & 15; - reg = (exit_qualification >> 8) & 15; + reg = vmx_get_exit_qual_reg(exit_qualification); switch ((exit_qualification >> 4) & 3) { case 0: /* mov to cr */ val = kvm_register_read(vcpu, reg); @@ -5816,7 +5816,7 @@ static int handle_dr(struct kvm_vcpu *vcpu) return 1; } - reg = DEBUG_REG_ACCESS_REG(exit_qualification); + reg = vmx_get_exit_qual_reg(exit_qualification); if (exit_qualification & TYPE_MOV_FROM_DR) { kvm_register_write(vcpu, reg, kvm_get_dr(vcpu, dr)); err = 0; diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h index 92eed58f48ad..863b08478544 100644 --- a/arch/x86/kvm/vmx/vmx.h +++ b/arch/x86/kvm/vmx/vmx.h @@ -330,6 +330,11 @@ static __always_inline unsigned long vmx_get_exit_qual(struct kvm_vcpu *vcpu) return vt->exit_qualification; } +static inline int vmx_get_exit_qual_reg(unsigned long exit_qualification) +{ + return (exit_qualification >> 8) & 0xf; +} + static __always_inline u32 vmx_get_intr_info(struct kvm_vcpu *vcpu) { struct vcpu_vt *vt = to_vt(vcpu); -- 2.53.0