Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp4724199pxv; Tue, 6 Jul 2021 07:43:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYOqUolMYNSHQhELbISPWIXRbKZOQW3QGmw6Vfw8Uv9v8kN2FOs6X8fLiK3doBzh/L+JGX X-Received: by 2002:a17:906:99c2:: with SMTP id s2mr13139836ejn.16.1625582598194; Tue, 06 Jul 2021 07:43:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625582598; cv=none; d=google.com; s=arc-20160816; b=NVRTi7ZXGQOo2a8qZG3yC9ZlIULRqafpTWDAIIz24uGXu1TGAB+ogEZuDUAy2Fkl4y OTUK3nz5IEi78lMWK/AomI1PpFWhXIH5r5avglfJPLgKhM+hF9PPnacY7VptwplCthZZ mKjvftZwzYkqJafgHce5W9YWLRRu+HQeeBwtPpUNzGLUW/yiGvL4R+Ln3rGcifYRROyY wacNUFTWQeAVwHi+vhBJrIM1YA2gqapb7t14q8s3ta3tcBPCcAmf7XOss/2ofZfvvQky 2V4jnu6etiYjBE7QShq5xQ2Jwe73hegc/0zdLcrZQWJhmVtaFI6Jsqf7sZLccDnLunOj oOug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=jP5DGGxJWoHogq5jV5uZ5mGaY2kRQONzJzlVOQeyzM0=; b=oOtWE0hGCdqy19mHCfQ9N4ctDd7rLlH99YtrEIl3fmfqTK7Ft0UvzYaXPYOy+vuvcc +jyAew1tW1GK+DP9wJG77ADeC0oITB0s9TmR/cjnOVzRVGm2FgkCv12suG20JnEQhR4k Dh9aqxX2Wo/jwz7As4l+lCXsd9NxcdT6zUHyg+juTLMfXrQXK+lXPAoLRQfIgYzvnG5a y5wTxq+A7W0NVIXqv6KZ4/CcBrQfB8vPObZ4WykMso/IFFT+RTAQYeR5n/UiSNfSnIro Y1KbMXGpIvDenNyLXxd2K8F2qd15gvARFoqlm08orN51j0U+ckyt/iHzO7ZYS6RQNzLa fvHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=jONxPTpg; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z20si14764215edc.592.2021.07.06.07.42.55; Tue, 06 Jul 2021 07:43:18 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=jONxPTpg; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232222AbhGFOgC (ORCPT + 99 others); Tue, 6 Jul 2021 10:36:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:49827 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232318AbhGFOfr (ORCPT ); Tue, 6 Jul 2021 10:35:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625581681; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jP5DGGxJWoHogq5jV5uZ5mGaY2kRQONzJzlVOQeyzM0=; b=jONxPTpgylrsDkjyeSzbSIq+5ybobqnG0YL1rqRJSXpf1kEGD8mBfNmHozcTygte1IgzR1 n7ipIVAqNqtdKz/fz5ObP6eTuXYcaVtC6mZth1vNgj4iJUOQCc/vdCcebzQNU8HEm+kHii GBDJdCkdD84vOvxGFjyUinw/UY6cWqE= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-326-s1IvoWJxOV-_X_JwGsrtiw-1; Tue, 06 Jul 2021 10:11:01 -0400 X-MC-Unique: s1IvoWJxOV-_X_JwGsrtiw-1 Received: by mail-ed1-f72.google.com with SMTP id i8-20020a50fc080000b02903989feb4920so5400518edr.1 for ; Tue, 06 Jul 2021 07:11:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=jP5DGGxJWoHogq5jV5uZ5mGaY2kRQONzJzlVOQeyzM0=; b=JZ9xPERTOXWtMGSm1K0eC8MuQDZecimTU9o7F3yqMmkSD0GHDE+SRjlbrjtwF25URn rsuWqrjWzDA8Tg3w1oH+Al4HIAPDO4K1mDfb1AB4AICg1w0xsD0qM+wP+xQ7/cM5DxnM 0Qnw89JRvXvEu08zBozjGXBMG+yW3d/6re0NEUT4pKuycYT05bvRf5cZwaABuqFo+ug7 VIuNVoi6d3PrQemKltdPkQEwCJlypRD/Y1iEEco/VWgoUWohKDMmDTI6DZSznzExsviX 4ZEQ+VlVGXFvf1AhjKN+C2Ln+/sxTkCiMvCbrBxzBGsYkSWvDCA2hkq2WrFz1JScs/k3 56cQ== X-Gm-Message-State: AOAM533yTm2LxE5Hl9EJye2G0CdOTeMfiozGTkm2tfKNdeHdoFUBPKpH pnnWjh24UQNRGKIzC1PuQchhoPZCtKnv8E7RbSD/dFFsCpJ5dgjp9SczgfyM8VRS5xgV4OJm+a7 HSeibMIQ5g/JSKeAYEeWDLi2A X-Received: by 2002:a17:906:dc91:: with SMTP id cs17mr18827618ejc.389.1625580659905; Tue, 06 Jul 2021 07:10:59 -0700 (PDT) X-Received: by 2002:a17:906:dc91:: with SMTP id cs17mr18827594ejc.389.1625580659732; Tue, 06 Jul 2021 07:10:59 -0700 (PDT) Received: from ?IPv6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id lz19sm5925092ejb.48.2021.07.06.07.10.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 06 Jul 2021 07:10:58 -0700 (PDT) Subject: Re: [RFC PATCH v2 33/69] KVM: x86: Add kvm_x86_ops .cache_gprs() and .flush_gprs() To: isaku.yamahata@intel.com, Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , 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@gmail.com, Sean Christopherson , Tom Lendacky References: <1d51898908a53120e3c60944108730e1922c2206.1625186503.git.isaku.yamahata@intel.com> From: Paolo Bonzini Message-ID: <71ea2142-b299-0fbf-c6f5-5146ad8370a6@redhat.com> Date: Tue, 6 Jul 2021 16:10:56 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <1d51898908a53120e3c60944108730e1922c2206.1625186503.git.isaku.yamahata@intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/07/21 00:04, isaku.yamahata@intel.com wrote: > 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); > } > > Reviewed-by: Paolo Bonzini