Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1887037pxv; Fri, 2 Jul 2021 15:11:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUChSFdD7uTcpUld2vdySYIOSOiR04ONLhyAbylvDT1EQC5wKXXuM7PN0iaAONZFxwOLKO X-Received: by 2002:aa7:d38d:: with SMTP id x13mr1956780edq.23.1625263883330; Fri, 02 Jul 2021 15:11:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625263883; cv=none; d=google.com; s=arc-20160816; b=sG5yGuEkmAeDPkHghBwXGShACHzg6QtpfBA4rTtQ0EygoEv8DVhjpvGORxXRwFOnZn Dlog6Ey7/nGH7uyumzzT2Ham0fnzoARnz3OfCz01pyg0XlSd4bwSwSRmMGMsMGAMX0RX AluK2cnGGtlOxf00WlMJXgYY8o3APbScSTdu6KlWJi0sLrch5k4k5xS9vSIYmzC66etE YpceK+Y0/5+4+pg0BaopfwFrQ33LwBrDciAxrUYb7sNZC8UGWZKqTJhGNnvtbNCLWo9D 0OjE2J8Dqv7NcbBdQDrqZ+DitgtNwziwFeTfVmWrhMKmhU6pyLltdKXBDm+VI2bxaIlT iAvw== 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; bh=LpJxD52TtFYPk6a/7umK+b7kkRzJcijCIXXIk4tHYvo=; b=MA2aOkY2Z6kng7uTHREGN5lJAzIPEqx/QsRRJDd8co3a1J/ECQwhyranN8NhgzJpdh 1aBRauC3M0gOUVntQGaCfyP/67/5gXc+quGU5tx+dMJLVhGoI7/WkSspBKfIZzskKC9I fAzyXoCp4Pzupb47xXRYsoWA/OqywSKkp6bCYOGHWR/snW4xpNFK0zDyR2QQj2FghXAh EcZfz7smK8WghdrU+ivfymJ9mPTamRGm0t3O8i0vpK0LJV/Fvca2nUkegeK3r0sC8u/6 0fVxH5qcEcj7wGWGMVyW0WgaH6W4Bcmo4R0TfRBcYbbPZyHZM7RU1bjI0xPvzzTdq1Wi ey1Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hs27si2899126ejc.348.2021.07.02.15.11.00; Fri, 02 Jul 2021 15:11:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234479AbhGBWKH (ORCPT + 99 others); Fri, 2 Jul 2021 18:10:07 -0400 Received: from mga12.intel.com ([192.55.52.136]:50201 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233135AbhGBWH6 (ORCPT ); Fri, 2 Jul 2021 18:07:58 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10033"; a="188472740" X-IronPort-AV: E=Sophos;i="5.83,320,1616482800"; d="scan'208";a="188472740" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 15:05:25 -0700 X-IronPort-AV: E=Sophos;i="5.83,320,1616482800"; d="scan'208";a="642814782" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 15:05:25 -0700 From: isaku.yamahata@intel.com To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , erdemaktas@google.com, Connor Kuehl , Sean Christopherson , x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Sean Christopherson , Tom Lendacky Subject: [RFC PATCH v2 33/69] KVM: x86: Add kvm_x86_ops .cache_gprs() and .flush_gprs() Date: Fri, 2 Jul 2021 15:04:39 -0700 Message-Id: <1d51898908a53120e3c60944108730e1922c2206.1625186503.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson Add hooks to cache and flush GPRs and invoke them from KVM_GET_REGS and KVM_SET_REGS respecitively. TDX will use the hooks to read/write GPRs from TDX-SEAM on-demand (for debug TDs). Cc: Tom Lendacky Signed-off-by: Sean Christopherson Signed-off-by: Isaku Yamahata --- arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/kvm/x86.c | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 00333af724d7..9791c4bb5198 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1248,6 +1248,8 @@ struct kvm_x86_ops { void (*set_gdt)(struct kvm_vcpu *vcpu, struct desc_ptr *dt); void (*sync_dirty_debug_regs)(struct kvm_vcpu *vcpu); void (*set_dr7)(struct kvm_vcpu *vcpu, unsigned long value); + void (*cache_gprs)(struct kvm_vcpu *vcpu); + void (*flush_gprs)(struct kvm_vcpu *vcpu); void (*cache_reg)(struct kvm_vcpu *vcpu, enum kvm_reg reg); unsigned long (*get_rflags)(struct kvm_vcpu *vcpu); void (*set_rflags)(struct kvm_vcpu *vcpu, unsigned long rflags); diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index c231a88d5946..f7ae0a47e555 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -9850,6 +9850,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) static void __get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) { + if (kvm_x86_ops.cache_gprs) + kvm_x86_ops.cache_gprs(vcpu); + if (vcpu->arch.emulate_regs_need_sync_to_vcpu) { /* * We are here if userspace calls get_regs() in the middle of @@ -9924,6 +9927,9 @@ static void __set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) vcpu->arch.exception.pending = false; + if (kvm_x86_ops.flush_gprs) + kvm_x86_ops.flush_gprs(vcpu); + kvm_make_request(KVM_REQ_EVENT, vcpu); } -- 2.25.1