Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp871035rwr; Thu, 20 Apr 2023 07:19:21 -0700 (PDT) X-Google-Smtp-Source: AKy350bN1eFCxBYufwDV3beo31ws7/oxxKe6v3CGWmohIS3dybh8KwxeQnUOjRizVRny8N6xn6hX X-Received: by 2002:a05:6a20:158d:b0:f2:4076:9d1e with SMTP id h13-20020a056a20158d00b000f240769d1emr7312pzj.2.1682000361143; Thu, 20 Apr 2023 07:19:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682000361; cv=none; d=google.com; s=arc-20160816; b=ZGkXApBKcrEdI05WNLnSLirMfLrJnkCUKyA3vAhuBd4ZDvq5ZTDSNZxxDBgtTCSOMi sb6MTLD3OpHokAIL53qJPSo/9ccTB8DTQuAtCLwmLNlO0jVvh5IkKQmh+HrVItNRgVAO EDfl3hk4f2h4pl9u8WYLcY7aUlNZPUqeeKnhxhbl5+ahkYxaEihNIvrR+6O3KiaX4tL6 WII9sx+s60zKS6El86prclzhQJZhUb5EyKn0bDN1sF9oWsFzq5CC9IoTVKxTxvcHj0bu jcb8TyKd96HhVVzHepdVBqIgWyk2q3mp2MFBmKauCzRmye3IUlaHjT3sOff5VrRYur0E 9fJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=iTNAH9gHifVYFXl0c2C53aKN2pckS8H0h/R/vl25Qfg=; b=y48e7G3zVnTCfEg9GbfZY8wKyYjook/KhAf90Eg2Cn/i1DFEdaLQcGou1YGDWZ7aRY NjBNgGBU7esbG3YD5qWvupd3oxXxbUJeTCz1sKvvcfc+I+mkBLrpkWKRbsQ2dDH/Wq0g aOWpsw7/CrzehkrKvSjaD8a7qUzfWu+o1OB7rBig1X/FIbvmSyRNR9JuryPas2nebkRD UzgXlV5WX/NiSNz1P7r+DoVg8aB1uqF+69HQR3aQEp/4ndDtHr0x7ZUTTMFnfCJNS5n5 5q6PTuB8bCGLBttV0XTCxNktGR09GvZxiytpKaDx5e6oC4RFwjnGtKM8zcqm/N9GRZsB 6FAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hvxPxf42; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h5-20020a63e145000000b005181ce2302csi1547576pgk.749.2023.04.20.07.19.06; Thu, 20 Apr 2023 07:19:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hvxPxf42; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232039AbjDTOQa (ORCPT + 99 others); Thu, 20 Apr 2023 10:16:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231926AbjDTOQS (ORCPT ); Thu, 20 Apr 2023 10:16:18 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C355540DB; Thu, 20 Apr 2023 07:16:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1682000177; x=1713536177; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=DAVFBOgJwmbdVgPRUhLaouaTcJcJ1MnxKOkOedpXi1U=; b=hvxPxf42OVYIY39GpTsSGfjw3rEsjqU8OSQGrVMBo+TS7Zr5FBUgnRSH x9/1/I+C81J//Z8BwPYFAMiNfk7lmvCspzcL9GHPdqqvzLaLklDtJJJDb IlPOeKRc4cb/knbAOYa8Pl23xS/KeAHt2qmNqD/ENAhkb2n8YvTUtFrsf +de6EuiBVkd4ItdWjNYjrBVpooQM+tX3rVooeiq/sL0Udriz73HbfqMgp v32cRjiNYQDxs509N7Tqe3Xa2oof77Xx8KqBxrQlSMRej9lqKk2XmO5RT k64Nxa+Hni1IT+W5Y4CSHfWeUDqNilUBNVD0fU7tBcW90mhaUxRmeQw0E Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10686"; a="343217826" X-IronPort-AV: E=Sophos;i="5.99,212,1677571200"; d="scan'208";a="343217826" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Apr 2023 07:16:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10686"; a="816028858" X-IronPort-AV: E=Sophos;i="5.99,212,1677571200"; d="scan'208";a="816028858" Received: from arthur-vostro-3668.sh.intel.com ([10.238.200.53]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Apr 2023 07:16:06 -0700 From: Zeng Guang To: Paolo Bonzini , Sean Christopherson , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , H Peter Anvin , kvm@vger.kernel.org Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Gao Chao , Zeng Guang Subject: [PATCH 3/6] KVM: x86: Add emulator helper for LASS violation check Date: Thu, 20 Apr 2023 21:37:21 +0800 Message-Id: <20230420133724.11398-4-guang.zeng@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230420133724.11398-1-guang.zeng@intel.com> References: <20230420133724.11398-1-guang.zeng@intel.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When LASS is enabled, KVM need apply LASS violation check to instruction emulations. Add helper for the usage of x86 emulator to perform LASS protection. Signed-off-by: Zeng Guang --- arch/x86/kvm/kvm_emulate.h | 1 + arch/x86/kvm/x86.c | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/arch/x86/kvm/kvm_emulate.h b/arch/x86/kvm/kvm_emulate.h index 2d9662be8333..1c55247d52d7 100644 --- a/arch/x86/kvm/kvm_emulate.h +++ b/arch/x86/kvm/kvm_emulate.h @@ -224,6 +224,7 @@ struct x86_emulate_ops { int (*leave_smm)(struct x86_emulate_ctxt *ctxt); void (*triple_fault)(struct x86_emulate_ctxt *ctxt); int (*set_xcr)(struct x86_emulate_ctxt *ctxt, u32 index, u64 xcr); + bool (*check_lass)(struct x86_emulate_ctxt *ctxt, u64 access, u64 la, u64 flags); }; /* Type, address-of, and value of an instruction's operand. */ diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 87feb1249ad6..704c5e4b9e76 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -8193,6 +8193,14 @@ static void emulator_vm_bugged(struct x86_emulate_ctxt *ctxt) kvm_vm_bugged(kvm); } +static bool emulator_check_lass(struct x86_emulate_ctxt *ctxt, + u64 access, u64 la, u64 flags) +{ + struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt); + + return static_call(kvm_x86_check_lass)(vcpu, access, la, flags); +} + static const struct x86_emulate_ops emulate_ops = { .vm_bugged = emulator_vm_bugged, .read_gpr = emulator_read_gpr, @@ -8237,6 +8245,7 @@ static const struct x86_emulate_ops emulate_ops = { .leave_smm = emulator_leave_smm, .triple_fault = emulator_triple_fault, .set_xcr = emulator_set_xcr, + .check_lass = emulator_check_lass, }; static void toggle_interruptibility(struct kvm_vcpu *vcpu, u32 mask) -- 2.27.0