Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3574516rdb; Wed, 13 Sep 2023 17:01:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEGMvBq8LRbIfs7iX6OGqzHs+4ts72OdwrCaCFnY4enolAEUpDOVgNbK5fEB6nQo5rQ+edc X-Received: by 2002:a17:902:e74c:b0:1c2:c60:8388 with SMTP id p12-20020a170902e74c00b001c20c608388mr4530488plf.6.1694649677840; Wed, 13 Sep 2023 17:01:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694649677; cv=none; d=google.com; s=arc-20160816; b=udRk19weIVcHlrZsuDOP2h70BE8vEHkI6CI7J3n1WIs0JR9ICmWWJFRu+xm5p+XbB1 jAEPEI+QSla1trOT+VHbRW5mlE9AP5gtMUb38h0dAKFd+6LDYoghgbmtJpSiIBBm8HZD JMzKGdLzd11/RJXTL9mkhHatN1M5QJ5uGl7aiGcms5XOqvNalqTgbfo4Fq1vINWpw+/T TGWwBmKB/QjdDbV71xPCPdZg1sV576HPbm6SKU9nT8OYJ/VbG4Eyy1NQ+n/IjAmrinFQ DLbBfQbEZyukQ25nwIcO3wDRqFBMPBGOH6xKKhb/re4fEMDE8GwwEgkyUaGLWe6K97Sv NzFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dmiR0cjXqzTHcW36wtvXJV3vIRz/Q77qoDFmwbT4H9s=; fh=XU07i6VjSHyq3GxtsXSBrQ3+Dy8rztqr00WST2j1mn0=; b=K1D0PKMTu4uodOtwVEhap2jodXcnQsnHyMEN9C66YRrXKgbuAyXlTimppUB2/lqsqN fofDN+VCyPoz6gpq+ntJMcy5aSbf+i7u6RsbcHTbKeFMcR3Zcxc5UG4Es5g6iO8DWDLs MxzOwXn4BWYNGmWjEbIXDie1wJqdFQb6JJkLtByoUAN7YmopNLwjzLj606PxrWKrUWAK p4MI1fZBBQ+dFxhs+3VS+cATv68R0MnyWPYC2wnpn9ZcBadcmrbgr/ANoNu0K1iuPLsH hgO8oN4pm1GfHP+NAMhrgGICmYA2HJomxyBISG1tSHE3h8s7uYvkbujCut9jVGn5lWgF KExw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Tp0Zda9a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id p12-20020a170902c70c00b001b8b7460620si390224plp.181.2023.09.13.17.01.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 17:01:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Tp0Zda9a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id E2F75842AD3F; Wed, 13 Sep 2023 08:39:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229805AbjIMPjx (ORCPT + 99 others); Wed, 13 Sep 2023 11:39:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229794AbjIMPjv (ORCPT ); Wed, 13 Sep 2023 11:39:51 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21260E6D; Wed, 13 Sep 2023 08:39:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694619587; x=1726155587; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AL9NLmjLAmLl2N/LQxSbngv0yfUQsc3dB+GYH+2Agn0=; b=Tp0Zda9arpcFQ2uhxcFTIb+9qNrVXXxt1yVltoHIxq5Fj9Q8RDTyTCIt SHujVft1Lwv50J+3YYnPXOialaDiCvPu66Q5QQdSIPHSSvlH6/7MATI/9 NRK+JltTsT2F38CxUiyTG4ifgi9CAaBRHsZi6HWt4FUnPLBkOL2U66fxz 2BZaGFp/jCzlX5/nhIHxJA6g2g6a6Ex536rjdqvHGs7+GZC7lf0sn2iqh 4G84FG22+Qlrkbv33W0KhLnmzaKWcps/lRkKNtC1C7e1dHYJvdADE5iyH nJdcxzbEHRDje7JQZX3yCVl2B2gDMQMi3Gadvlc1KbyKyWowaBS6GuYSo A==; X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="376030126" X-IronPort-AV: E=Sophos;i="6.02,143,1688454000"; d="scan'208";a="376030126" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 08:39:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="867852012" X-IronPort-AV: E=Sophos;i="6.02,143,1688454000"; d="scan'208";a="867852012" Received: from binbinwu-mobl.ccr.corp.intel.com (HELO binbinwu-mobl.sh.intel.com) ([10.93.2.44]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 08:39:43 -0700 From: Binbin Wu To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: seanjc@google.com, pbonzini@redhat.com, chao.gao@intel.com, kai.huang@intel.com, David.Laight@ACULAB.COM, robert.hu@linux.intel.com, guang.zeng@intel.com, binbin.wu@linux.intel.com Subject: [PATCH v11 02/16] KVM: x86: Use a new flag for branch targets Date: Wed, 13 Sep 2023 20:42:13 +0800 Message-Id: <20230913124227.12574-3-binbin.wu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230913124227.12574-1-binbin.wu@linux.intel.com> References: <20230913124227.12574-1-binbin.wu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 13 Sep 2023 08:39:57 -0700 (PDT) Use the new flag X86EMUL_F_BRANCH instead of X86EMUL_F_FETCH in assign_eip() to distinguish instruction fetch and branch target computation for features that handle differently on them, e.g. Linear Address Space Separation (LASS). As of this patch, X86EMUL_F_BRANCH and X86EMUL_F_FETCH are identical as far as KVM is concerned. No functional change intended. Signed-off-by: Binbin Wu Tested-by: Xuelian Guo --- arch/x86/kvm/emulate.c | 5 +++-- arch/x86/kvm/kvm_emulate.h | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 87ee1802166a..274d6e7aa0c1 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -721,7 +721,8 @@ static __always_inline int __linearize(struct x86_emulate_ctxt *ctxt, (flags & X86EMUL_F_WRITE)) goto bad; /* unreadable code segment */ - if (!(flags & X86EMUL_F_FETCH) && (desc.type & 8) && !(desc.type & 2)) + if (!(flags & (X86EMUL_F_FETCH | X86EMUL_F_BRANCH)) && + (desc.type & 8) && !(desc.type & 2)) goto bad; lim = desc_limit_scaled(&desc); if (!(desc.type & 8) && (desc.type & 4)) { @@ -772,7 +773,7 @@ static inline int assign_eip(struct x86_emulate_ctxt *ctxt, ulong dst) if (ctxt->op_bytes != sizeof(unsigned long)) addr.ea = dst & ((1UL << (ctxt->op_bytes << 3)) - 1); rc = __linearize(ctxt, addr, &max_size, 1, ctxt->mode, &linear, - X86EMUL_F_FETCH); + X86EMUL_F_BRANCH); if (rc == X86EMUL_CONTINUE) ctxt->_eip = addr.ea; return rc; diff --git a/arch/x86/kvm/kvm_emulate.h b/arch/x86/kvm/kvm_emulate.h index e24c8ac7b930..e1fd83908334 100644 --- a/arch/x86/kvm/kvm_emulate.h +++ b/arch/x86/kvm/kvm_emulate.h @@ -91,6 +91,7 @@ struct x86_instruction_info { /* x86-specific emulation flags */ #define X86EMUL_F_WRITE BIT(0) #define X86EMUL_F_FETCH BIT(1) +#define X86EMUL_F_BRANCH BIT(2) struct x86_emulate_ops { void (*vm_bugged)(struct x86_emulate_ctxt *ctxt); -- 2.25.1