From patchwork Mon Oct 2 09:57:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 147369 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1545639vqb; Mon, 2 Oct 2023 09:33:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHGDhP8ZmWCO5ZkwFJLO2baylsm5IhMNNZyGG8ewlvj8Pk+/MN6IiAawlNLamOH5uc4AtVM X-Received: by 2002:a17:902:a415:b0:1c5:de06:9e5a with SMTP id p21-20020a170902a41500b001c5de069e5amr7994906plq.21.1696264431807; Mon, 02 Oct 2023 09:33:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696264431; cv=none; d=google.com; s=arc-20160816; b=fwak7+qIaQulJmr6Y2+kwdSu4zkEDJOmm94wkRxabY7x27kKZSWScrt/RmODJOZIj4 NVrnEdMcZvYBR/vM3zAdhjzj2iDBlrwLyX/DkSGdDJBrFToZ7M4sCLuZINDf4hd2vwlG zFtq4LwOq3Ml0m/jge+eF8RFhHGJU/v79ZIiys3/V7CRy3u9liwtBbPtnuMnqkxNi7Sq O9HPMGCzmi4E7y9wWBiT8lvi4PfLs7blJ+veT/GWoYG/4l+8x8tg5ekMlBh0zYJrCgZ8 83kEhA9DqDFMFEYh1/FsFLfo2sanLLPum8t+mQGfcce1XXVhBoD6LXM1QJ/H21K++ldb 115w== 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=CnnzQ4eiCWT/+IlcdQWASoCfyneq5mdBodDzIdnbsCc=; fh=8AvbwpPKF0Qe5WwS5eyABOVDUChKGxIrkPaOnjrOqKo=; b=SKOlOsICk3BGltL1L01J+GnDeZ0q270MZYrlDrTe7MwX8ZiHQCmLc9CZN48l3qOW1d 0XltSSGBzHE3pIABYUqpI0uwJ3RGsocKy75BWwU0QaryCQ97/18W48sUuSMYdenL97SB zNJ5wYxcxN1p1A1sMictj/zqFkIHj8zFvWDB3P+IW+aJvrrKosNZetD0iSRCuAaHb/jC PHtMzzV7TRVA+jq2ZhWQ3CxrsH6hoYWnUrVmhZdItn2fksmhPz5EFzYhMeGHZyuwDGNe AyARre6Bl9KTi0TUYf78oFYYg5rbnNqvm9RfzaZ0afp3qHIpDFeg44FFVHRinLxXxMP4 sdMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=puvNm2c5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id n8-20020a170902e54800b001bb8e3f3475si8170775plf.52.2023.10.02.09.33.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 09:33:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=puvNm2c5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id ED1B08057DB0; Mon, 2 Oct 2023 02:58:40 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236372AbjJBJ6L (ORCPT + 16 others); Mon, 2 Oct 2023 05:58:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236322AbjJBJ6A (ORCPT ); Mon, 2 Oct 2023 05:58:00 -0400 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6640C9F; Mon, 2 Oct 2023 02:57:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=CnnzQ4eiCWT/+IlcdQWASoCfyneq5mdBodDzIdnbsCc=; b=puvNm2c5vTtUnF/V0zEuIrdkDq kpmpkXdA3q/tWqwCPhvbJPTzxsQgit1dBY8IhppsfEyhO5YZrh1Yw4XXeNYYeyD3ptUC1vhCoFOWF h97rv37pAscg+GE+4QCAdgZPZUpL37Hn7pXSnKyIhq8GoSRnuDgn+Vf8VIgW/mNcu8w0=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qnFgX-0000vJ-3Q; Mon, 02 Oct 2023 09:57:53 +0000 Received: from ec2-63-33-11-17.eu-west-1.compute.amazonaws.com ([63.33.11.17] helo=REM-PW02S00X.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qnFgW-0000Ft-Rm; Mon, 02 Oct 2023 09:57:53 +0000 From: Paul Durrant To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Paul Durrant , David Woodhouse , David Woodhouse , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , x86@kernel.org Subject: [PATCH v7 03/11] KVM: pfncache: add a helper to get the gpa Date: Mon, 2 Oct 2023 09:57:32 +0000 Message-Id: <20231002095740.1472907-4-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231002095740.1472907-1-paul@xen.org> References: <20231002095740.1472907-1-paul@xen.org> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email 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 (lipwig.vger.email [0.0.0.0]); Mon, 02 Oct 2023 02:58:41 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778662172866309097 X-GMAIL-MSGID: 1778662172866309097 From: Paul Durrant A subsequent patch will rename this field since it will become overloaded. To avoid churn in places that currently retrieve the gpa, add a helper for that purpose now. No functional change intended. Signed-off-by: Paul Durrant Reviewed-by: David Woodhouse --- Cc: David Woodhouse Cc: Sean Christopherson Cc: Paolo Bonzini Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: x86@kernel.org --- arch/x86/kvm/xen.c | 15 ++++++++------- include/linux/kvm_host.h | 7 +++++++ virt/kvm/pfncache.c | 6 ++++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c index 33fddd29824b..8e6fdcd7bb6e 100644 --- a/arch/x86/kvm/xen.c +++ b/arch/x86/kvm/xen.c @@ -261,8 +261,8 @@ static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic) * alignment (and the 32-bit ABI doesn't align the 64-bit integers * anyway, even if the overall struct had been 64-bit aligned). */ - if ((gpc1->gpa & ~PAGE_MASK) + user_len >= PAGE_SIZE) { - user_len1 = PAGE_SIZE - (gpc1->gpa & ~PAGE_MASK); + if ((kvm_gpc_gpa(gpc1) & ~PAGE_MASK) + user_len >= PAGE_SIZE) { + user_len1 = PAGE_SIZE - (kvm_gpc_gpa(gpc1) & ~PAGE_MASK); user_len2 = user_len - user_len1; } else { user_len1 = user_len; @@ -343,7 +343,7 @@ static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic) * to the second page now because the guest changed to * 64-bit mode, the second GPC won't have been set up. */ - if (kvm_gpc_activate(gpc2, gpc1->gpa + user_len1, + if (kvm_gpc_activate(gpc2, kvm_gpc_gpa(gpc1) + user_len1, user_len2)) return; @@ -677,7 +677,8 @@ int kvm_xen_hvm_get_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data) case KVM_XEN_ATTR_TYPE_SHARED_INFO: if (kvm->arch.xen.shinfo_cache.active) - data->u.shared_info.gfn = gpa_to_gfn(kvm->arch.xen.shinfo_cache.gpa); + data->u.shared_info.gfn = + gpa_to_gfn(kvm_gpc_gpa(&kvm->arch.xen.shinfo_cache)); else data->u.shared_info.gfn = KVM_XEN_INVALID_GFN; r = 0; @@ -955,7 +956,7 @@ int kvm_xen_vcpu_get_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data) switch (data->type) { case KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO: if (vcpu->arch.xen.vcpu_info_cache.active) - data->u.gpa = vcpu->arch.xen.vcpu_info_cache.gpa; + data->u.gpa = kvm_gpc_gpa(&vcpu->arch.xen.vcpu_info_cache); else data->u.gpa = KVM_XEN_INVALID_GPA; r = 0; @@ -963,7 +964,7 @@ int kvm_xen_vcpu_get_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data) case KVM_XEN_VCPU_ATTR_TYPE_VCPU_TIME_INFO: if (vcpu->arch.xen.vcpu_time_info_cache.active) - data->u.gpa = vcpu->arch.xen.vcpu_time_info_cache.gpa; + data->u.gpa = kvm_gpc_gpa(&vcpu->arch.xen.vcpu_time_info_cache); else data->u.gpa = KVM_XEN_INVALID_GPA; r = 0; @@ -975,7 +976,7 @@ int kvm_xen_vcpu_get_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data) break; } if (vcpu->arch.xen.runstate_cache.active) { - data->u.gpa = vcpu->arch.xen.runstate_cache.gpa; + data->u.gpa = kvm_gpc_gpa(&vcpu->arch.xen.runstate_cache); r = 0; } break; diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index c71e8fbccaaf..4d8027fe9928 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1374,6 +1374,13 @@ void kvm_gpc_deactivate(struct gfn_to_pfn_cache *gpc); */ void kvm_gpc_mark_dirty(struct gfn_to_pfn_cache *gpc); +/** + * kvm_gpc_gpa - retrieve the guest physical address of a cached mapping + * + * @gpc: struct gfn_to_pfn_cache object. + */ +gpa_t kvm_gpc_gpa(struct gfn_to_pfn_cache *gpc); + void kvm_sigset_activate(struct kvm_vcpu *vcpu); void kvm_sigset_deactivate(struct kvm_vcpu *vcpu); diff --git a/virt/kvm/pfncache.c b/virt/kvm/pfncache.c index b68ed7fa56a2..17afbb464a70 100644 --- a/virt/kvm/pfncache.c +++ b/virt/kvm/pfncache.c @@ -386,6 +386,12 @@ int kvm_gpc_activate(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned long len) } EXPORT_SYMBOL_GPL(kvm_gpc_activate); +gpa_t kvm_gpc_gpa(struct gfn_to_pfn_cache *gpc) +{ + return gpc->gpa; +} +EXPORT_SYMBOL_GPL(kvm_gpc_gpa); + void kvm_gpc_mark_dirty(struct gfn_to_pfn_cache *gpc) { mark_page_dirty_in_slot(gpc->kvm, gpc->memslot, gpc->gpa >> PAGE_SHIFT);