From patchwork Mon Sep 18 14:40:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 141601 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2990397vqi; Mon, 18 Sep 2023 15:24:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGV2rxjHXdx6ZmzA0QgX6E9NPQ7/Of1Pwlj+X83/NktwPZRhuIUnL00sSfAD0Q5NJ1n4+2c X-Received: by 2002:a05:6a21:498a:b0:159:ee0f:b9e9 with SMTP id ax10-20020a056a21498a00b00159ee0fb9e9mr10634664pzc.53.1695075863967; Mon, 18 Sep 2023 15:24:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695075863; cv=none; d=google.com; s=arc-20160816; b=PRqQLxSj/2pr/hWn+4Ll4vnbtieZrut+0PTFwOadW2ZJN+Iw+fVNEizuPg++qJZKMH WOsD8OxajuaD/hi5RzF/xmdQVNovapNn3ljXQ/yjoQTbbchLVv5k51iUM8iAdvKwoTc4 VzbKbLM6rKle5ng/G/oQrIKlVVFfiiZbszyoBNN99ZDdAJ4ivcTeD34hYCUY/fSGXx7o CXVmpweDvGyynQfQwU2UyXI4nPQSR+OA+l1Q7ouK/bNICKJL7srYkdhqy6bMvfQP2POQ PSFVcXgxNa+9odTllBFX5lifbhziVj/YQ1Ox4JH79oOoCjv1ClQaG8JO6KTUil3b47j0 v4uA== 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=jvOmcsLACoe+aYwCOVTUhhHhMDjob15u+BiUav871xs=; fh=YQxcWeFtTLB3mMceSRxC2i/1m4lEYnAvVMXZ98qp9Z4=; b=ImRdDCEnbAy79uBzIoVwY5pDkHjscb1i47tMKjUnehBBeH2OCySfZuz/MWyJMVY/eq j6WKQ3dXR1tolPBcCZX3lLJBHoKMq/sbdF9iE/l1AhwjK7daHnFBGPEOTv25NLmWkSyz GiRH+k/j8UANMslu3chz8He1gW3KnQ80HHrl+zZ0ZdEXMtvgC/BnpSefxwwIZfH4ssrn dlY4qJ64UkleD+UpQgVo9GrjJlUd+Zo8JSj4Pvyn9HaWdXbnTUUXkuL/G5cdsV1YZy1i FvX7NtaSbDOEkEAKWjsEQ5VVyyRpPx+3mXnVBnzP85+EVfC9/UmPeOCDD1bAHQIoCTOw mKgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=GRCxX4YT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id ga19-20020a17090b039300b00267ba1c43adsi4722336pjb.101.2023.09.18.15.24.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 15:24:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=GRCxX4YT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 87357808725E; Mon, 18 Sep 2023 09:10:33 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230039AbjIRQKF (ORCPT + 25 others); Mon, 18 Sep 2023 12:10:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230021AbjIRQJP (ORCPT ); Mon, 18 Sep 2023 12:09:15 -0400 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8B31A2; Mon, 18 Sep 2023 09:07:54 -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=jvOmcsLACoe+aYwCOVTUhhHhMDjob15u+BiUav871xs=; b=GRCxX4YTF4slf9SBndQGZFfQcN LQ8ySwl28vuiIhH2mdN7b+bXi5FS9PaxfWombgQQEosy+roH2Y6pqDoc8ovf6s7Cvi4loxIHalDpu aP8sEF43iKkpMqH+5OFotPxkcYshf7alMxOA02KLW7p/L+71UF9K4AnRePCehusCPCEw=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qiFR6-0003Q4-R0; Mon, 18 Sep 2023 14:41:16 +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 1qiFR6-0006IJ-JI; Mon, 18 Sep 2023 14:41:16 +0000 From: Paul Durrant To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Paul Durrant , David Woodhouse , David Woodhouse , Paolo Bonzini Subject: [PATCH v3 01/13] KVM: pfncache: add a map helper function Date: Mon, 18 Sep 2023 14:40:59 +0000 Message-Id: <20230918144111.641369-2-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230918144111.641369-1-paul@xen.org> References: <20230918144111.641369-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 agentk.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 (agentk.vger.email [0.0.0.0]); Mon, 18 Sep 2023 09:10:34 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777415868953519102 X-GMAIL-MSGID: 1777415868953519102 From: Paul Durrant We have an unmap helper but mapping is open-coded. Arguably this is fine because mapping is done in only one place, hva_to_pfn_retry(), but adding the helper does make that function more readable. No functional change intended. Signed-off-by: Paul Durrant Reviewed-by: David Woodhouse --- Cc: David Woodhouse Cc: Paolo Bonzini --- virt/kvm/pfncache.c | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/virt/kvm/pfncache.c b/virt/kvm/pfncache.c index 2d6aba677830..0f36acdf577f 100644 --- a/virt/kvm/pfncache.c +++ b/virt/kvm/pfncache.c @@ -96,17 +96,28 @@ bool kvm_gpc_check(struct gfn_to_pfn_cache *gpc, unsigned long len) } EXPORT_SYMBOL_GPL(kvm_gpc_check); -static void gpc_unmap_khva(kvm_pfn_t pfn, void *khva) +static void *gpc_map(kvm_pfn_t pfn) +{ + if (pfn_valid(pfn)) + return kmap(pfn_to_page(pfn)); +#ifdef CONFIG_HAS_IOMEM + else + return memremap(pfn_to_hpa(pfn), PAGE_SIZE, MEMREMAP_WB); +#endif +} + +static void gpc_unmap(kvm_pfn_t pfn, void *khva) { /* Unmap the old pfn/page if it was mapped before. */ - if (!is_error_noslot_pfn(pfn) && khva) { - if (pfn_valid(pfn)) - kunmap(pfn_to_page(pfn)); + if (is_error_noslot_pfn(pfn) || !khva) + return; + + if (pfn_valid(pfn)) + kunmap(pfn_to_page(pfn)); #ifdef CONFIG_HAS_IOMEM - else - memunmap(khva); + else + memunmap(khva); #endif - } } static inline bool mmu_notifier_retry_cache(struct kvm *kvm, unsigned long mmu_seq) @@ -175,7 +186,7 @@ static kvm_pfn_t hva_to_pfn_retry(struct gfn_to_pfn_cache *gpc) * the existing mapping and didn't create a new one. */ if (new_khva != old_khva) - gpc_unmap_khva(new_pfn, new_khva); + gpc_unmap(new_pfn, new_khva); kvm_release_pfn_clean(new_pfn); @@ -193,15 +204,11 @@ static kvm_pfn_t hva_to_pfn_retry(struct gfn_to_pfn_cache *gpc) * too must be done outside of gpc->lock! */ if (gpc->usage & KVM_HOST_USES_PFN) { - if (new_pfn == gpc->pfn) { + if (new_pfn == gpc->pfn) new_khva = old_khva; - } else if (pfn_valid(new_pfn)) { - new_khva = kmap(pfn_to_page(new_pfn)); -#ifdef CONFIG_HAS_IOMEM - } else { - new_khva = memremap(pfn_to_hpa(new_pfn), PAGE_SIZE, MEMREMAP_WB); -#endif - } + else + new_khva = gpc_map(new_pfn); + if (!new_khva) { kvm_release_pfn_clean(new_pfn); goto out_error; @@ -326,7 +333,7 @@ static int __kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, gpa_t gpa, mutex_unlock(&gpc->refresh_lock); if (unmap_old) - gpc_unmap_khva(old_pfn, old_khva); + gpc_unmap(old_pfn, old_khva); return ret; } @@ -412,7 +419,7 @@ void kvm_gpc_deactivate(struct gfn_to_pfn_cache *gpc) list_del(&gpc->list); spin_unlock(&kvm->gpc_lock); - gpc_unmap_khva(old_pfn, old_khva); + gpc_unmap(old_pfn, old_khva); } } EXPORT_SYMBOL_GPL(kvm_gpc_deactivate); From patchwork Mon Sep 18 14:41:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 141546 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2916892vqi; Mon, 18 Sep 2023 12:59:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGEbdi+9Ji34GRhygWwIIYxcTswcunmWKs9DHlzFETWReITRuzpcEtViraoI6djK+b4LLUH X-Received: by 2002:a05:6a20:9147:b0:154:4246:d63b with SMTP id x7-20020a056a20914700b001544246d63bmr9923970pzc.25.1695067165233; Mon, 18 Sep 2023 12:59:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695067165; cv=none; d=google.com; s=arc-20160816; b=Nlje6x6On+Z4vps7Cc/onAEQGLwQaQEI4VFSqRysYd7tXTDgkuSjfTrktk/oxnZ2ye kjLjqGPKAq8JL8XMWAbCx7uQYxxXtAFnXuuksf9MwGC+k85kGaURjz3oMKRBRSK8vR04 ebcPWk1Eqdhj7yAc8jfnUWjy8pZZsI43gAjU3UBShn86a64d6YoAWTnC5H3Tm09/Kks1 sszct37Uot8JJmEvM2sqlmYSuhpE5uJXMgLGYd2BIduAsIgYxLJpk7jW5STJGzumZ36C +GIW9+6O6eHiFpZJK2HHxedk7cbjO4KxBSQZnOAuhsKf1t7F8aVfS7yGpDQNk9KPdq4S DDJA== 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=b9VmcvZpefxWPZmnCsAAti7ImeYt2ilYGEmGGgNIuv0=; fh=8AvbwpPKF0Qe5WwS5eyABOVDUChKGxIrkPaOnjrOqKo=; b=MGFl4w+U11AueVFn7diykAOtZSc5a97+unsxxHPnKakmY2C3jlCZElLsRWe7+2WtY4 3EzJxByuIHEOOO3alIZEXf1+RC7S9oBrBSNV/mdA2pEr84dt9OTxsg0upcL7ifWpW/XN 36UWw5XjDlN/IRxbXwvWfJm4y1uVwplJBwu6CWFtouO6/gmkiVq+oOuWQW8+c79XrbG6 jGsHMPSfmy6FihThvo01KNZqfzcPw7gpfvAe9PJjsWPZ3Txv9ZEIpRIrEnvZ1dlF3w2j ucYQsD4I3CuaMrWltoQpbS1hTw7UO7U4tE+R7HeJtFKR4Y9D3jJhaik8U/RNblp665sc ydzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=ybMMyzEK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id h38-20020a631226000000b0056950e1546asi7678354pgl.356.2023.09.18.12.59.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 12:59:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=ybMMyzEK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id 9E54E8021230; Mon, 18 Sep 2023 09:33:45 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230196AbjIRQdW (ORCPT + 25 others); Mon, 18 Sep 2023 12:33:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229630AbjIRQdH (ORCPT ); Mon, 18 Sep 2023 12:33:07 -0400 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6293683F0; Mon, 18 Sep 2023 09:12:58 -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=b9VmcvZpefxWPZmnCsAAti7ImeYt2ilYGEmGGgNIuv0=; b=ybMMyzEKORGms5HxTgNvH71Ykx H6WLiuAhI4oPEBeMXM9FG4OWFhPuFeR4mhZQmWoSQT64YfIWn7N4O2jlXS73dgsnB9drsLaBXG9/d QCQO9VrmutjZfWC2ik+MY4Pmv48d3FU6jadGpHT4Fv7W0sPM3aEJcIPp0d8TEJEOZvi0=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qiFR8-0003QB-HB; Mon, 18 Sep 2023 14:41:18 +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 1qiFR8-0006IJ-78; Mon, 18 Sep 2023 14:41:18 +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 v3 02/13] KVM: pfncache: add a mark-dirty helper Date: Mon, 18 Sep 2023 14:41:00 +0000 Message-Id: <20230918144111.641369-3-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230918144111.641369-1-paul@xen.org> References: <20230918144111.641369-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 fry.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 (fry.vger.email [0.0.0.0]); Mon, 18 Sep 2023 09:33:45 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777406748278287704 X-GMAIL-MSGID: 1777406748278287704 From: Paul Durrant At the moment pages are marked dirty by open-coded calls to mark_page_dirty_in_slot(), directly deferefencing the gpa and memslot from the cache. After a subsequent patch these may not always be set so add a helper now so that caller will protected from the need to know about this detail. NOTE: Pages are now marked dirty while the cache lock is held. This is to ensure that gpa and memslot are mutually consistent. 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/x86.c | 2 +- arch/x86/kvm/xen.c | 13 ++++++------- include/linux/kvm_host.h | 7 +++++++ virt/kvm/pfncache.c | 6 ++++++ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 6c9c81e82e65..d669a8801265 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3137,7 +3137,7 @@ static void kvm_setup_guest_pvclock(struct kvm_vcpu *v, guest_hv_clock->version = ++vcpu->hv_clock.version; - mark_page_dirty_in_slot(v->kvm, gpc->memslot, gpc->gpa >> PAGE_SHIFT); + kvm_gpc_mark_dirty(gpc); read_unlock_irqrestore(&gpc->lock, flags); trace_kvm_pvclock_update(v->vcpu_id, &vcpu->hv_clock); diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c index 40edf4d1974c..33fddd29824b 100644 --- a/arch/x86/kvm/xen.c +++ b/arch/x86/kvm/xen.c @@ -430,14 +430,13 @@ static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic) smp_wmb(); } - if (user_len2) + if (user_len2) { + kvm_gpc_mark_dirty(gpc2); read_unlock(&gpc2->lock); + } + kvm_gpc_mark_dirty(gpc1); read_unlock_irqrestore(&gpc1->lock, flags); - - mark_page_dirty_in_slot(v->kvm, gpc1->memslot, gpc1->gpa >> PAGE_SHIFT); - if (user_len2) - mark_page_dirty_in_slot(v->kvm, gpc2->memslot, gpc2->gpa >> PAGE_SHIFT); } void kvm_xen_update_runstate(struct kvm_vcpu *v, int state) @@ -543,13 +542,13 @@ void kvm_xen_inject_pending_events(struct kvm_vcpu *v) : "0" (evtchn_pending_sel32)); WRITE_ONCE(vi->evtchn_upcall_pending, 1); } + + kvm_gpc_mark_dirty(gpc); read_unlock_irqrestore(&gpc->lock, flags); /* For the per-vCPU lapic vector, deliver it as MSI. */ if (v->arch.xen.upcall_vector) kvm_xen_inject_vcpu_vector(v); - - mark_page_dirty_in_slot(v->kvm, gpc->memslot, gpc->gpa >> PAGE_SHIFT); } int __kvm_xen_has_interrupt(struct kvm_vcpu *v) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index fb6c6109fdca..c71e8fbccaaf 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1367,6 +1367,13 @@ int kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, unsigned long len); */ void kvm_gpc_deactivate(struct gfn_to_pfn_cache *gpc); +/** + * kvm_gpc_mark_dirty - mark a cached page as dirty. + * + * @gpc: struct gfn_to_pfn_cache object. + */ +void kvm_gpc_mark_dirty(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 0f36acdf577f..b68ed7fa56a2 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); +void kvm_gpc_mark_dirty(struct gfn_to_pfn_cache *gpc) +{ + mark_page_dirty_in_slot(gpc->kvm, gpc->memslot, gpc->gpa >> PAGE_SHIFT); +} +EXPORT_SYMBOL_GPL(kvm_gpc_mark_dirty); + void kvm_gpc_deactivate(struct gfn_to_pfn_cache *gpc) { struct kvm *kvm = gpc->kvm; From patchwork Mon Sep 18 14:41:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 141575 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2945357vqi; Mon, 18 Sep 2023 13:52:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGRlBBd/N6SekzQAbtgfE2uuzRxlcgtu3R9M8oanyaDt76paUV29Yu17GinOzl5PU2zkeIE X-Received: by 2002:a05:6a21:999d:b0:155:1710:664a with SMTP id ve29-20020a056a21999d00b001551710664amr843383pzb.18.1695070340717; Mon, 18 Sep 2023 13:52:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695070340; cv=none; d=google.com; s=arc-20160816; b=j7y+/M/pbwLeWK2dZMjItvhcZ0WwGPKCWLDfg5I2AgnE/TV11Ig5zhFfLn9fK9KOkv w1cXniBQ1tL+VzA6FG9FBnmPKuFBDqGZvy4wvDe+VdDwafxSbZJ4yFPn8GG8qxMNHhgY bHzYBiSMBWq2ztSlyYJcNNuQOdnZWI+PdvsR0rVr3S3WOoamDI4ddSLBmIQYUOUlSCpD EEy09XAMk4TcyzkGjriYmFrMznsHcVBO9VsaSftQgq4deHR+p3KeL+wTGTVCo7a6UFeG grbzOLnFBCC8zV5/JYxsIig1zBU55qCHoDDALNREREIEfWjHg6wZ4Y8DM5LEk1c20Q6C 0FQg== 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=T1V6pBHSGXCoMp1Qo8X3XK6OYoneRc3+59B2AoYywGbu5JxGJsnEGJRiY3Qn+PVYzC XiKo/OCnKD7hyKX0DgABz7c8/27aF8VF71bIwmQKxY+ytfLp2y1kYWgfbRRa9tkq4nVe qbabgv3xTMGwycIrC0WRde6lbK5QGuCweC65f3JREWpXbEeQYX6JJvOc8Dp1rFyd6v5c YPzp9jD67500u1dPn2MoPNSt8Bhlt7g3WqQHpXz4mIu7A3pLN6pA4r3f9WxuH41JOPms gAS1yWKBnCvu9gcBzg0fo0t3PYid0pMmv/cO5rmmlvFCMWF4jyYLzkTI1BksN988RDYq R8yA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=kG39+KSv; 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 Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id d9-20020a056a0010c900b006875398611csi8587242pfu.80.2023.09.18.13.52.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 13:52:20 -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=@xen.org header.s=20200302mail header.b=kG39+KSv; 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 Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id D3CB280AEE24; Mon, 18 Sep 2023 09:19:01 -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 S230021AbjIRQTB (ORCPT + 25 others); Mon, 18 Sep 2023 12:19:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230097AbjIRQSo (ORCPT ); Mon, 18 Sep 2023 12:18:44 -0400 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3830B55A3; Mon, 18 Sep 2023 09:09:29 -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=kG39+KSvtKJVp5vY5CwfM7TMNJ HAqO9ri+lg68hF5xBJ8KrAD5OQbumNV4bFPvi4r+fAkIiYZ2IQYF75s6rum798eb2yALcN9Y2qT+Q +HcXw6y/bNsB1CBlMbR8UEYp8TAW9nxROGsT/kIU0PCTQnGFKpMWqw6SjSz3nUyydHBM=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qiFRA-0003QG-4k; Mon, 18 Sep 2023 14:41:20 +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 1qiFR9-0006IJ-RC; Mon, 18 Sep 2023 14:41:20 +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 v3 03/13] KVM: pfncache: add a helper to get the gpa Date: Mon, 18 Sep 2023 14:41:01 +0000 Message-Id: <20230918144111.641369-4-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230918144111.641369-1-paul@xen.org> References: <20230918144111.641369-1-paul@xen.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 18 Sep 2023 09:19:01 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777410077809167800 X-GMAIL-MSGID: 1777410077809167800 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); From patchwork Mon Sep 18 14:41:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 141620 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3030844vqi; Mon, 18 Sep 2023 17:00:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGgUJipL/SuJfQPJZJTW+xGNkvsT9+Nj0O17r6R1rPGdhhoUH95/GtIV8+0IjUdqK52K1ry X-Received: by 2002:a05:6808:8e:b0:3a8:6b4d:6b78 with SMTP id s14-20020a056808008e00b003a86b4d6b78mr10909281oic.35.1695081632851; Mon, 18 Sep 2023 17:00:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695081632; cv=none; d=google.com; s=arc-20160816; b=yCGAITYK+tf7A5YwGJ1KgdOr96OUDmUx426NF5xKqcMoonG1QDhs2weI82AROY1Wxa yhg8QihaZOKMY0qJ3qOqnZaYlUH/5h6D8te4u0Uq0D+Gygvkmy6f7gwxZnYKRvYpomEe XBloMek68pF/guu0eEddAyqHaceo8wtAWDsnPIY5QceC4t/osa23D6CZF2jOeCy5Fenn 5r5LbwKtm74TMFdwN7aPEEc26tQXMZ2I51fUK0JoGlmtzfQNzpBroCEKC7tKKG/+H3sc fwT5aHp3qqmvD33u0F8SsmZw7Bhy/8qIp+tzkdR2p6Vax3bmX6wiGdOhg5e3rMp4NvqU ujAQ== 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=0eGGXnc5vBmAE8zpS0TzZWx5te66TwGgtV+bYpeTlu4=; fh=YQxcWeFtTLB3mMceSRxC2i/1m4lEYnAvVMXZ98qp9Z4=; b=MNGmFx8O9QB7qMi3+qg8PEd00wKXWKDbo/gML8Uic8aS0ohG6Q+NEsnAJRWVZKrnBK s01SseWhAMh16m0UchdDhWgh3/vzTdn5LYgqKXcg/83OdfT0fyrcrVLvb5uskJXV0odN QxTCkerKVuEa4Sl8pR8wHH5LwXBuA2T8RaUQo6fd0Kh0yC0P3zPdPqzzndatoEUoNzFn hKCki9w/e+2SrjKhStf5g8tm4mmg1AUQOzT5Ep1HTMa7/8kwX1ljlvEdr39B1o4fpbfI Us8A2bsdpdr63KqKNMm9TJmEcsqWyoMjzUSAeMW3mu5XsxxjWaIouzyaT77Al73SbJBs XxNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=xv4fEw7Q; 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 l37-20020a635725000000b005694492c259si8655216pgb.282.2023.09.18.17.00.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 17:00:32 -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=xv4fEw7Q; 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 3C0AE815CDB7; Mon, 18 Sep 2023 09:34:27 -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 S230193AbjIRQeP (ORCPT + 25 others); Mon, 18 Sep 2023 12:34:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229864AbjIRQdw (ORCPT ); Mon, 18 Sep 2023 12:33:52 -0400 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83D047A80; Mon, 18 Sep 2023 09:12:05 -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=0eGGXnc5vBmAE8zpS0TzZWx5te66TwGgtV+bYpeTlu4=; b=xv4fEw7Q9+E5M8WA0ZHC3Cbxe5 Q8KTOSvHlk4j+r5joqIH1D6QOvJqwVA5f+mNyvgkK0QpYl/j1w9xrlqFKuEI/oI6RgL1RkbuCk8+u 3FyMeo0bTeH81uJFuyoj5LoQ+3BcH1KHWB17+cUdTj9eX7aqrv+5xRARiH8GYltvvzyQ=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qiFRB-0003QI-0l; Mon, 18 Sep 2023 14:41:21 +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 1qiFRA-0006IJ-Pk; Mon, 18 Sep 2023 14:41:20 +0000 From: Paul Durrant To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Paul Durrant , David Woodhouse , David Woodhouse , Paolo Bonzini Subject: [PATCH v3 04/13] KVM: pfncache: base offset check on khva rather than gpa Date: Mon, 18 Sep 2023 14:41:02 +0000 Message-Id: <20230918144111.641369-5-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230918144111.641369-1-paul@xen.org> References: <20230918144111.641369-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, 18 Sep 2023 09:34:27 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777421918277838198 X-GMAIL-MSGID: 1777421918277838198 From: Paul Durrant After a subsequent patch, the gpa may not always be set whereas khva will (as long as the cache valid flag is also set). No functional change intended. Signed-off-by: Paul Durrant Reviewed-by: David Woodhouse --- Cc: David Woodhouse Cc: Paolo Bonzini --- virt/kvm/pfncache.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/virt/kvm/pfncache.c b/virt/kvm/pfncache.c index 17afbb464a70..37bcb4399780 100644 --- a/virt/kvm/pfncache.c +++ b/virt/kvm/pfncache.c @@ -83,15 +83,18 @@ bool kvm_gpc_check(struct gfn_to_pfn_cache *gpc, unsigned long len) if (!gpc->active) return false; - if ((gpc->gpa & ~PAGE_MASK) + len > PAGE_SIZE) + if (gpc->generation != slots->generation) return false; - if (gpc->generation != slots->generation || kvm_is_error_hva(gpc->uhva)) + if (kvm_is_error_hva(gpc->uhva)) return false; if (!gpc->valid) return false; + if (offset_in_page(gpc->khva) + len > PAGE_SIZE) + return false; + return true; } EXPORT_SYMBOL_GPL(kvm_gpc_check); From patchwork Mon Sep 18 14:41:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 142158 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3808768vqi; Tue, 19 Sep 2023 18:47:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEpctx/xlYN868LpLgiYsJe5wb9rwnxLE58eqkrCA1HmJYE7XPqcJ38gyPG7ZAKg3EUIA1m X-Received: by 2002:a05:6a00:3987:b0:68f:cbd3:5b01 with SMTP id fi7-20020a056a00398700b0068fcbd35b01mr6498774pfb.13.1695174431243; Tue, 19 Sep 2023 18:47:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695174431; cv=none; d=google.com; s=arc-20160816; b=PC4Djr+YLUCNhpYYVjkRi+BAeRVSTPzTfpNt/r8RvSllvsnJSl34lFYwkyDMWZJMX9 IcFei5eqoQjXJnscnahQCgLUW175X03gXqiMJXxEsgeIuFIFOiDgXQF5w8t2IjVkmqKm dXdJ1d+RWvtu1u18czwb9jbJsrIVZ1A5j6K0OsKQnKKjJ1EdWHPwYREwuDmnj85JglRs zY1a5kiM5zMI05SXgy2xsVULdUeIbylMjDkWBkHMSLdblJZiwa0vVLth5mbOdq0N55Xz EVLOw5g7PoAQICQIqKjsp9Gjj6Lz0pMTDm2U3hNJ4MLYyuAV7Hh3Rl7Tyty4ZX4YpmWL dCPg== 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=dozmN/ao3yu6ELwEpDJlaWpAf1h+h4oBUyHu8TvVQHM=; fh=garbXx6xThcytiY3nDlsqHTysvuL2ydFqtzT1pbUU/Y=; b=0Of+PSKV91hAoWP3jHVCugFPrDmxjsse8jDOS8ke89sVGKByicfkFIGWzH0LBXj9dI FtTVXmVviXWVXraUh2QAYlme27ZaJwmDrQZCJd5w6Ls+xL4TI/1Ybk955noNW1NxJZx0 zF5XbGEsXmktRSP9u+MCs/LBQ+ulzO88dmuz77D1Blt3/wo1KAnBcsVLsnNKpIV3YRGv g5P+fdEIRTjFyVKdRBMub/l+JhOx/RlOfSy7uPJZxVyWP9gTCCMecsvx/I4ttKwGEnN2 RMIxXCNwWNE91ZWQ6vkpKjF0aB+qlCXuIs4YsMUOQdB2cYAK6eOPy7CfPtekZ6Fcnfwr KcDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=UlFwc4IV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id e19-20020a056a001a9300b0068fe9c452acsi10843363pfv.376.2023.09.19.18.47.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 18:47:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=UlFwc4IV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 06E2280688A3; Mon, 18 Sep 2023 09:10:45 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230078AbjIRQKG (ORCPT + 25 others); Mon, 18 Sep 2023 12:10:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230209AbjIRQJs (ORCPT ); Mon, 18 Sep 2023 12:09:48 -0400 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0C441718; Mon, 18 Sep 2023 09:08:21 -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=dozmN/ao3yu6ELwEpDJlaWpAf1h+h4oBUyHu8TvVQHM=; b=UlFwc4IVH+jDvXOJI2aep3HJrY S6OZUu+Qh1jUeJqtqTdT4Vqcmv1Xhms4GNbizNdY317T1EXTu98CoA/kQP/ixCRsxsaku0OnYKk6S HcfofUuqyupt4PX6WqwvmvuL9kXnkK80fgh6np1crg35QJdocBFpHGwOKziZfBksj7wM=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qiFRB-0003QQ-Se; Mon, 18 Sep 2023 14:41:21 +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 1qiFRB-0006IJ-LH; Mon, 18 Sep 2023 14:41:21 +0000 From: Paul Durrant To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Paul Durrant , Paolo Bonzini , David Woodhouse Subject: [PATCH v3 05/13] KVM: pfncache: allow a cache to be activated with a fixed (userspace) HVA Date: Mon, 18 Sep 2023 14:41:03 +0000 Message-Id: <20230918144111.641369-6-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230918144111.641369-1-paul@xen.org> References: <20230918144111.641369-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 pete.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 (pete.vger.email [0.0.0.0]); Mon, 18 Sep 2023 09:10:45 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777519224096308134 X-GMAIL-MSGID: 1777519224096308134 From: Paul Durrant Some cached pages may actually be overlays on guest memory that have a fixed HVA within the VMM. It's pointless to invalidate such cached mappings if the overlay is moved so allow a cache to be activated directly with the HVA to cater for such cases. A subsequent patch will make use of this facility. Signed-off-by: Paul Durrant --- Cc: Paolo Bonzini Cc: David Woodhouse --- include/linux/kvm_host.h | 29 ++++++++++++++++ include/linux/kvm_types.h | 3 +- virt/kvm/pfncache.c | 73 ++++++++++++++++++++++++++++----------- 3 files changed, 84 insertions(+), 21 deletions(-) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 4d8027fe9928..6823bae5c66c 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1321,6 +1321,22 @@ void kvm_gpc_init(struct gfn_to_pfn_cache *gpc, struct kvm *kvm, */ int kvm_gpc_activate(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned long len); +/** + * kvm_gpc_activate_hva - prepare a cached kernel mapping and HPA for a given HVA. + * + * @gpc: struct gfn_to_pfn_cache object. + * @hva: userspace virtual address to map. + * @len: sanity check; the range being access must fit a single page. + * + * @return: 0 for success. + * -EINVAL for a mapping which would cross a page boundary. + * -EFAULT for an untranslatable guest physical address. + * + * The semantics of this function are the same as those of kvm_gpc_activate(). It + * merely bypasses a layer of address translation. + */ +int kvm_gpc_activate_hva(struct gfn_to_pfn_cache *gpc, unsigned long hva, unsigned long len); + /** * kvm_gpc_check - check validity of a gfn_to_pfn_cache. * @@ -1378,9 +1394,22 @@ 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. + * + * @return: If the cache was activated with a fixed HVA then INVALID_GPA + * will be returned. */ gpa_t kvm_gpc_gpa(struct gfn_to_pfn_cache *gpc); +/** + * kvm_gpc_hva - retrieve the fixed host physical address of a cached mapping + * + * @gpc: struct gfn_to_pfn_cache object. + * + * @return: If the cache was activated with a guest physical address then + * 0 will be returned. + */ +unsigned long kvm_gpc_hva(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/include/linux/kvm_types.h b/include/linux/kvm_types.h index 6f4737d5046a..d49946ee7ae3 100644 --- a/include/linux/kvm_types.h +++ b/include/linux/kvm_types.h @@ -64,7 +64,7 @@ struct gfn_to_hva_cache { struct gfn_to_pfn_cache { u64 generation; - gpa_t gpa; + u64 addr; unsigned long uhva; struct kvm_memory_slot *memslot; struct kvm *kvm; @@ -77,6 +77,7 @@ struct gfn_to_pfn_cache { enum pfn_cache_usage usage; bool active; bool valid; + bool addr_is_gpa; }; #ifdef KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE diff --git a/virt/kvm/pfncache.c b/virt/kvm/pfncache.c index 37bcb4399780..b3e3f7e38410 100644 --- a/virt/kvm/pfncache.c +++ b/virt/kvm/pfncache.c @@ -83,7 +83,7 @@ bool kvm_gpc_check(struct gfn_to_pfn_cache *gpc, unsigned long len) if (!gpc->active) return false; - if (gpc->generation != slots->generation) + if (gpc->addr_is_gpa && gpc->generation != slots->generation) return false; if (kvm_is_error_hva(gpc->uhva)) @@ -229,7 +229,7 @@ static kvm_pfn_t hva_to_pfn_retry(struct gfn_to_pfn_cache *gpc) gpc->valid = true; gpc->pfn = new_pfn; - gpc->khva = new_khva + (gpc->gpa & ~PAGE_MASK); + gpc->khva = new_khva + (gpc->addr & ~PAGE_MASK); /* * Put the reference to the _new_ pfn. The pfn is now tracked by the @@ -246,11 +246,11 @@ static kvm_pfn_t hva_to_pfn_retry(struct gfn_to_pfn_cache *gpc) return -EFAULT; } -static int __kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, gpa_t gpa, - unsigned long len) +static int __kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, u64 addr, + unsigned long len, bool addr_is_gpa) { struct kvm_memslots *slots = kvm_memslots(gpc->kvm); - unsigned long page_offset = gpa & ~PAGE_MASK; + unsigned long page_offset = addr & ~PAGE_MASK; bool unmap_old = false; unsigned long old_uhva; kvm_pfn_t old_pfn; @@ -282,22 +282,34 @@ static int __kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, gpa_t gpa, old_khva = gpc->khva - offset_in_page(gpc->khva); old_uhva = gpc->uhva; - /* If the userspace HVA is invalid, refresh that first */ - if (gpc->gpa != gpa || gpc->generation != slots->generation || + /* + * If the address has changed, switched from guest to host (or vice + * versa), or it's a guest address and the memory slots have been + * updated, we need to refresh the userspace HVA. + */ + if (gpc->addr != addr || + gpc->addr_is_gpa != addr_is_gpa || + (addr_is_gpa && gpc->generation != slots->generation) || kvm_is_error_hva(gpc->uhva)) { - gfn_t gfn = gpa_to_gfn(gpa); + gpc->addr = addr; + gpc->addr_is_gpa = addr_is_gpa; - gpc->gpa = gpa; - gpc->generation = slots->generation; - gpc->memslot = __gfn_to_memslot(slots, gfn); - gpc->uhva = gfn_to_hva_memslot(gpc->memslot, gfn); + if (addr_is_gpa) { + gfn_t gfn = gpa_to_gfn(addr); - if (kvm_is_error_hva(gpc->uhva)) { - ret = -EFAULT; - goto out; + gpc->generation = slots->generation; + gpc->memslot = __gfn_to_memslot(slots, gfn); + gpc->uhva = gfn_to_hva_memslot(gpc->memslot, gfn); + } else { + gpc->uhva = addr & PAGE_MASK; } } + if (kvm_is_error_hva(gpc->uhva)) { + ret = -EFAULT; + goto out; + } + /* * If the userspace HVA changed or the PFN was already invalid, * drop the lock and do the HVA to PFN lookup again. @@ -343,7 +355,7 @@ static int __kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, gpa_t gpa, int kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, unsigned long len) { - return __kvm_gpc_refresh(gpc, gpc->gpa, len); + return __kvm_gpc_refresh(gpc, gpc->addr, len, gpc->addr_is_gpa); } EXPORT_SYMBOL_GPL(kvm_gpc_refresh); @@ -364,7 +376,8 @@ void kvm_gpc_init(struct gfn_to_pfn_cache *gpc, struct kvm *kvm, } EXPORT_SYMBOL_GPL(kvm_gpc_init); -int kvm_gpc_activate(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned long len) +static int __kvm_gpc_activate(struct gfn_to_pfn_cache *gpc, u64 addr, unsigned long len, + bool addr_is_gpa) { struct kvm *kvm = gpc->kvm; @@ -385,19 +398,39 @@ int kvm_gpc_activate(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned long len) gpc->active = true; write_unlock_irq(&gpc->lock); } - return __kvm_gpc_refresh(gpc, gpa, len); + return __kvm_gpc_refresh(gpc, addr, len, addr_is_gpa); +} + +int kvm_gpc_activate(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned long len) +{ + return __kvm_gpc_activate(gpc, gpa, len, true); } EXPORT_SYMBOL_GPL(kvm_gpc_activate); gpa_t kvm_gpc_gpa(struct gfn_to_pfn_cache *gpc) { - return gpc->gpa; + return gpc->addr_is_gpa ? gpc->addr : INVALID_GPA; } EXPORT_SYMBOL_GPL(kvm_gpc_gpa); +int kvm_gpc_activate_hva(struct gfn_to_pfn_cache *gpc, unsigned long hva, unsigned long len) +{ + return __kvm_gpc_activate(gpc, hva, len, false); +} +EXPORT_SYMBOL_GPL(kvm_gpc_activate_hva); + +unsigned long kvm_gpc_hva(struct gfn_to_pfn_cache *gpc) +{ + return !gpc->addr_is_gpa ? gpc->addr : 0; +} +EXPORT_SYMBOL_GPL(kvm_gpc_hva); + void kvm_gpc_mark_dirty(struct gfn_to_pfn_cache *gpc) { - mark_page_dirty_in_slot(gpc->kvm, gpc->memslot, gpc->gpa >> PAGE_SHIFT); + if (!gpc->addr_is_gpa) + return; + + mark_page_dirty_in_slot(gpc->kvm, gpc->memslot, gpc->addr >> PAGE_SHIFT); } EXPORT_SYMBOL_GPL(kvm_gpc_mark_dirty); From patchwork Mon Sep 18 14:41:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 141487 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2819031vqi; Mon, 18 Sep 2023 10:15:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFODQBftJOuoG++YWOsGKx6VolZy9b9BClC7fkCAsSWneYwDdJ+ngdSqzCpANVe8jGyfFfk X-Received: by 2002:a05:6808:3b4:b0:3a7:1e98:80ad with SMTP id n20-20020a05680803b400b003a71e9880admr11017847oie.9.1695057306928; Mon, 18 Sep 2023 10:15:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695057306; cv=none; d=google.com; s=arc-20160816; b=saypkaYA7K/LQfBQFYdxcZLdnfH21WiqIR/8bctS5VozSCShRsVjH6rRr1l4Rqn/m1 cNyBkoSBRNNllHx7jm4jlmJLVFIynjDEReXvOCjeCJYpgVEZKhU9MPFMz6e0aY7Yb7P3 jCqKhLEjhxyPcz8fULKAHOdZFH8E1mQxGHrHn/5RBKi+/0+cuzb841tEc7Dx8pnuxtbv INq80dcY0btSCXNUZ9SLZrMoxGjVWHG57t1JuakjN0yQzkuSVQCL0T4fTXITl+tv10Ir Q/K41pWDv0DDs+LXTz9Fc4Odkgjc4adgalRWzuN9MoYlXSayjJjqSe8GkrVkPDm/NMID 2HcA== 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=7Xg3VsT+niHE2xRvzgMpdBgGz0Csn+Ig0JZVwwD1HsY=; fh=8AvbwpPKF0Qe5WwS5eyABOVDUChKGxIrkPaOnjrOqKo=; b=OGNUOrtPRiWUmsSXppzos4oKcZm5jh7uZVakPXyyrOgldkV0q/QptvTDIZ7Ht/vXct LKiYvGydstdcJQRUtrKs+ZwVsCKQUCVHEiG0qqQc5AZsYXhVTeJsNz4VeUr8CTMPRrsV BsucV3Zt0kXrrK2xKlqV1cUHhyQkOhmVDTX4SQGfXxyNmPEMn2lZNIz5kxB5go8MIO4w 24eCPQy6mFtiAh0NYto9um2U7XIucos7uPEGiTSlon7Q233qPdOI6ctKnU84kZ/jiJCV GAp2W3OwXj/iocWRnoH8iDpxpfsb+GQvK9v773H0xoYUj0mJE8wpAeDgfII/dZQff7aR 4uhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b="mPix606/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id l71-20020a63884a000000b00578a9192d91si261303pgd.696.2023.09.18.10.15.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 10:15:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b="mPix606/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 136F9808E57D; Mon, 18 Sep 2023 09:12:01 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229872AbjIRQL3 (ORCPT + 25 others); Mon, 18 Sep 2023 12:11:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230004AbjIRQLO (ORCPT ); Mon, 18 Sep 2023 12:11:14 -0400 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 196E32727; Mon, 18 Sep 2023 09:08:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:Content-Type:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=7Xg3VsT+niHE2xRvzgMpdBgGz0Csn+Ig0JZVwwD1HsY=; b=mPix606/0GpeMBl5vTXtJgMJC+ Ee1QXJdK3B35z4wZruMasnkIRjmWpM9yBPeiPWl0mqcBbzBeZzcfLJORkHzLS/x9K+tO4tbl28FCF drucMUtuZmaBC0971v9sn19GMvABw2YJGZSFjCUgnNzJxnRPibVwVkVQ/gyH//duvr+E=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qiFRD-0003Qk-Gi; Mon, 18 Sep 2023 14:41:23 +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 1qiFRD-0006IJ-9B; Mon, 18 Sep 2023 14:41:23 +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 v3 06/13] KVM: xen: allow shared_info to be mapped by fixed HVA Date: Mon, 18 Sep 2023 14:41:04 +0000 Message-Id: <20230918144111.641369-7-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230918144111.641369-1-paul@xen.org> References: <20230918144111.641369-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 agentk.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 (agentk.vger.email [0.0.0.0]); Mon, 18 Sep 2023 09:12:01 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777396410838835194 X-GMAIL-MSGID: 1777396410838835194 From: Paul Durrant The shared_info page is not guest memory as such. It is a dedicated page allocated by the VMM and overlaid onto guest memory in a GFN chosen by the guest. The guest may even request that shared_info be moved from one GFN to another, but the HVA is never going to change. Thus it makes much more sense to map the shared_info page in kernel once using this fixed HVA. Hence add a new KVM_XEN_ATTR_TYPE_SHARED_INFO_HVA attribute type for this purpose and a KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA flag to advertize its availability. Don't actually advertize it yet though. That will be done in a subsequent patch, which will also add tests for the new attribute type. Also update the KVM API documentation with the new attribute and also fix it up to consistently refer to 'shared_info' (with the underscore). NOTE: The change of the kvm_xen_hvm_attr shared_info from struct to union is technically an ABI change but it's entirely compatible with existing users. 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 v2: - Define the new attribute and capability but don't advertize the capability yet. - Add API documentation. --- Documentation/virt/kvm/api.rst | 25 +++++++++++++++++++------ arch/x86/kvm/xen.c | 28 ++++++++++++++++++++++------ include/uapi/linux/kvm.h | 6 +++++- 3 files changed, 46 insertions(+), 13 deletions(-) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index 21a7578142a1..e9df4df6fe48 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -353,7 +353,7 @@ The bits in the dirty bitmap are cleared before the ioctl returns, unless KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 is enabled. For more information, see the description of the capability. -Note that the Xen shared info page, if configured, shall always be assumed +Note that the Xen shared_info page, if configured, shall always be assumed to be dirty. KVM will not explicitly mark it such. @@ -5408,8 +5408,9 @@ KVM_PV_ASYNC_CLEANUP_PERFORM __u8 long_mode; __u8 vector; __u8 runstate_update_flag; - struct { + union { __u64 gfn; + __u64 hva; } shared_info; struct { __u32 send_port; @@ -5437,10 +5438,10 @@ type values: KVM_XEN_ATTR_TYPE_LONG_MODE Sets the ABI mode of the VM to 32-bit or 64-bit (long mode). This - determines the layout of the shared info pages exposed to the VM. + determines the layout of the shared_info page exposed to the VM. KVM_XEN_ATTR_TYPE_SHARED_INFO - Sets the guest physical frame number at which the Xen "shared info" + Sets the guest physical frame number at which the Xen shared_info page resides. Note that although Xen places vcpu_info for the first 32 vCPUs in the shared_info page, KVM does not automatically do so and instead requires that KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO be used @@ -5449,7 +5450,7 @@ KVM_XEN_ATTR_TYPE_SHARED_INFO not be aware of the Xen CPU id which is used as the index into the vcpu_info[] array, so may know the correct default location. - Note that the shared info page may be constantly written to by KVM; + Note that the shared_info page may be constantly written to by KVM; it contains the event channel bitmap used to deliver interrupts to a Xen guest, amongst other things. It is exempt from dirty tracking mechanisms — KVM will not explicitly mark the page as dirty each @@ -5458,9 +5459,21 @@ KVM_XEN_ATTR_TYPE_SHARED_INFO any vCPU has been running or any event channel interrupts can be routed to the guest. - Setting the gfn to KVM_XEN_INVALID_GFN will disable the shared info + Setting the gfn to KVM_XEN_INVALID_GFN will disable the shared_info page. +KVM_XEN_ATTR_TYPE_SHARED_INFO_HVA + If the KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA flag is also set in the + Xen capabilities, then this attribute may be used to set the + userspace address at which the shared_info page resides, which + will always be fixed in the VMM regardless of where it is mapped + in guest physical address space. This attribute should be used in + preference to KVM_XEN_ATTR_TYPE_SHARED_INFO as it avoids + unnecessary invalidation of an internal cache when the page is + re-mapped in guest physcial address space. + + Setting the hva to zero will disable the shared_info page. + KVM_XEN_ATTR_TYPE_UPCALL_VECTOR Sets the exception vector used to deliver Xen event channel upcalls. This is the HVM-wide vector injected directly by the hypervisor diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c index 8e6fdcd7bb6e..1abb4547642a 100644 --- a/arch/x86/kvm/xen.c +++ b/arch/x86/kvm/xen.c @@ -34,24 +34,27 @@ static bool kvm_xen_hcall_evtchn_send(struct kvm_vcpu *vcpu, u64 param, u64 *r); DEFINE_STATIC_KEY_DEFERRED_FALSE(kvm_xen_enabled, HZ); -static int kvm_xen_shared_info_init(struct kvm *kvm, gfn_t gfn) +static int kvm_xen_shared_info_init(struct kvm *kvm, u64 addr, bool addr_is_gfn) { struct gfn_to_pfn_cache *gpc = &kvm->arch.xen.shinfo_cache; struct pvclock_wall_clock *wc; - gpa_t gpa = gfn_to_gpa(gfn); u32 *wc_sec_hi; u32 wc_version; u64 wall_nsec; int ret = 0; int idx = srcu_read_lock(&kvm->srcu); - if (gfn == KVM_XEN_INVALID_GFN) { + if ((addr_is_gfn && addr == KVM_XEN_INVALID_GFN) || + (!addr_is_gfn && addr == 0)) { kvm_gpc_deactivate(gpc); goto out; } do { - ret = kvm_gpc_activate(gpc, gpa, PAGE_SIZE); + if (addr_is_gfn) + ret = kvm_gpc_activate(gpc, gfn_to_gpa(addr), PAGE_SIZE); + else + ret = kvm_gpc_activate_hva(gpc, addr, PAGE_SIZE); if (ret) goto out; @@ -604,7 +607,6 @@ int kvm_xen_hvm_set_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data) { int r = -ENOENT; - switch (data->type) { case KVM_XEN_ATTR_TYPE_LONG_MODE: if (!IS_ENABLED(CONFIG_64BIT) && data->u.long_mode) { @@ -619,7 +621,13 @@ int kvm_xen_hvm_set_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data) case KVM_XEN_ATTR_TYPE_SHARED_INFO: mutex_lock(&kvm->arch.xen.xen_lock); - r = kvm_xen_shared_info_init(kvm, data->u.shared_info.gfn); + r = kvm_xen_shared_info_init(kvm, data->u.shared_info.gfn, true); + mutex_unlock(&kvm->arch.xen.xen_lock); + break; + + case KVM_XEN_ATTR_TYPE_SHARED_INFO_HVA: + mutex_lock(&kvm->arch.xen.xen_lock); + r = kvm_xen_shared_info_init(kvm, data->u.shared_info.hva, false); mutex_unlock(&kvm->arch.xen.xen_lock); break; @@ -684,6 +692,14 @@ int kvm_xen_hvm_get_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data) r = 0; break; + case KVM_XEN_ATTR_TYPE_SHARED_INFO_HVA: + if (kvm->arch.xen.shinfo_cache.active) + data->u.shared_info.hva = kvm_gpc_hva(&kvm->arch.xen.shinfo_cache); + else + data->u.shared_info.hva = 0; + r = 0; + break; + case KVM_XEN_ATTR_TYPE_UPCALL_VECTOR: data->u.vector = kvm->arch.xen.upcall_vector; r = 0; diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 13065dd96132..062bfa14b4d9 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1282,6 +1282,7 @@ struct kvm_x86_mce { #define KVM_XEN_HVM_CONFIG_EVTCHN_2LEVEL (1 << 4) #define KVM_XEN_HVM_CONFIG_EVTCHN_SEND (1 << 5) #define KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG (1 << 6) +#define KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA (1 << 7) struct kvm_xen_hvm_config { __u32 flags; @@ -1793,9 +1794,10 @@ struct kvm_xen_hvm_attr { __u8 long_mode; __u8 vector; __u8 runstate_update_flag; - struct { + union { __u64 gfn; #define KVM_XEN_INVALID_GFN ((__u64)-1) + __u64 hva; } shared_info; struct { __u32 send_port; @@ -1837,6 +1839,8 @@ struct kvm_xen_hvm_attr { #define KVM_XEN_ATTR_TYPE_XEN_VERSION 0x4 /* Available with KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG */ #define KVM_XEN_ATTR_TYPE_RUNSTATE_UPDATE_FLAG 0x5 +/* Available with KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA */ +#define KVM_XEN_ATTR_TYPE_SHARED_INFO_HVA 0x6 /* Per-vCPU Xen attributes */ #define KVM_XEN_VCPU_GET_ATTR _IOWR(KVMIO, 0xca, struct kvm_xen_vcpu_attr) From patchwork Mon Sep 18 14:41:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 141610 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3003466vqi; Mon, 18 Sep 2023 15:56:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFSp6WpXzKlA8k2rV0+VP/ohEyphCkPD2CorHApaTg9z3doLKUoJigro3DnASGVo5cu3PGd X-Received: by 2002:a05:6358:931a:b0:139:db34:240b with SMTP id x26-20020a056358931a00b00139db34240bmr12981127rwa.8.1695077793880; Mon, 18 Sep 2023 15:56:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695077793; cv=none; d=google.com; s=arc-20160816; b=yKwTDrhPNAaLawa8Gwdq69ORb6l8LecFocN/9DBIgeKKUKbExjuI05lyk++S31/73L NMMSoJDzewsjeuXoqixv8MHM9Hc5BnmlAjQNNHyR/DYniyXuVfh3OyWsNvB7OkHHAmG3 RBDbNXlM+TLUl86kOe9CwSGTll16/364tT0p1W0VQgv7FO3D+p89XzR0BPS4VP8wZQDH 84DYL88UrLii5/hcVYCK30PlfLzA2naMtJPkShxEe2TanRXrB4/aJn1XrFbvAolo4YKW gFR6LEa7jQhougqJX0FIWJVQ2YawDsTgB0JncbiEqEnfRtLbn8uCEOaZwwX/9u9Md0DW U3Wg== 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=2ZU3phIU8w/IqLa7mF9REkj8Of9x76QWtODpH3/vsvM=; fh=8AvbwpPKF0Qe5WwS5eyABOVDUChKGxIrkPaOnjrOqKo=; b=rtP7LEik2A+6WF/7Ujev6EQDFIMwwxMxvY+3+339mx+/heGA5FC3wLOSFJ3ijbGRkZ ya2NAx5syoxJgD47W7z5IKqimN2T0YuHDwaTUGu37wqw9eCEsN0eQx0RZB7LYYRSQR/j YBuKt8RrwgSLPctbnBBRQLhGWqZ4XQw/u/EMNwPap6Ft78lX9cKrQAz6OAWygvvVmcfx PF7tU8Ls4ZvTz6J9qTtx2KvTqt3SOIK4UlFJlMTmvIMgcP3DE737V9Gd0gDoOFwLhAQ1 PlU/OemtScYJdKtVVcIP6QIqkf4Kp8wgcfUE7WHlDBQDT5s4jU+Ybli87k6n+F4ax52j xe8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=dD5cxQEL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id s72-20020a632c4b000000b00577475ee5f6si8704118pgs.618.2023.09.18.15.56.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 15:56:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=dD5cxQEL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id 88A2E808EEE5; Mon, 18 Sep 2023 09:09:52 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230059AbjIRQJI (ORCPT + 25 others); Mon, 18 Sep 2023 12:09:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230005AbjIRQIy (ORCPT ); Mon, 18 Sep 2023 12:08:54 -0400 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7350F3A88; Mon, 18 Sep 2023 09:07:10 -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=2ZU3phIU8w/IqLa7mF9REkj8Of9x76QWtODpH3/vsvM=; b=dD5cxQELops4YW4OAmlhhcKnZf M6Uf2Z6Iw+v1dEact0B+KJlSsFyVwVbtK5VBCj8cJGMiDq3j8leS5KxCf3KHpX91uQSlArgYR+w29 OqrjnRXgvO9WOTtZV0F4TtcQoIwTTVpNz19CFqpdjAFCOiKzSPEsQK/SqgboPnzJT5X4=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qiFRF-0003R9-5S; Mon, 18 Sep 2023 14:41:25 +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 1qiFRE-0006IJ-TH; Mon, 18 Sep 2023 14:41:25 +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 v3 07/13] KVM: xen: prepare for using 'default' vcpu_info Date: Mon, 18 Sep 2023 14:41:05 +0000 Message-Id: <20230918144111.641369-8-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230918144111.641369-1-paul@xen.org> References: <20230918144111.641369-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 fry.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 (fry.vger.email [0.0.0.0]); Mon, 18 Sep 2023 09:09:52 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777417893122111251 X-GMAIL-MSGID: 1777417893122111251 From: Paul Durrant The shared_info page contains an array of 32 vcpu_info structures which may be used by guests (with fewer than 32 vCPUs) if they don't explicitly register vcpu_info structures in their own memory, using a VCPUOP_register_vcpu_info hypercall. Currently we rely on the VMM always registering vcpu_info structures, even if the guest doesn't make that hypercall, which is somewhat bogus as (as has been stated in the comment of a previous commit) the shared_info page is not guest memory. Prepare to automatically use the vcpu_info info embedded in shared_info by default, by adding a get_vcpu_info_cache() helper function. This function also passes back an offset to be added to the cached khva. This is currently always zero since we're still relying on the current VMM behaviour. A subsequent patch will make proper use of it. No functional change intended. NOTE: To avoid leaking detail of the vcpu_info duality into the main x86 code, a kvm_xen_guest_time_update() has also been added and use of this requires that kvm_setup_guest_pvclock() ceases to be a static function. 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 v2: - Fix build warning. --- arch/x86/include/asm/kvm_host.h | 4 +++ arch/x86/kvm/x86.c | 12 +++----- arch/x86/kvm/xen.c | 50 ++++++++++++++++++++++++++------- arch/x86/kvm/xen.h | 6 +++- 4 files changed, 53 insertions(+), 19 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 1a4def36d5bb..6d896f9161c2 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -2238,4 +2238,8 @@ int memslot_rmap_alloc(struct kvm_memory_slot *slot, unsigned long npages); */ #define KVM_EXIT_HYPERCALL_MBZ GENMASK_ULL(31, 1) +void kvm_setup_guest_pvclock(struct kvm_vcpu *v, + struct gfn_to_pfn_cache *gpc, + unsigned int offset); + #endif /* _ASM_X86_KVM_HOST_H */ diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index d669a8801265..2d7d0ae18820 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3094,9 +3094,9 @@ u64 get_kvmclock_ns(struct kvm *kvm) return data.clock; } -static void kvm_setup_guest_pvclock(struct kvm_vcpu *v, - struct gfn_to_pfn_cache *gpc, - unsigned int offset) +void kvm_setup_guest_pvclock(struct kvm_vcpu *v, + struct gfn_to_pfn_cache *gpc, + unsigned int offset) { struct kvm_vcpu_arch *vcpu = &v->arch; struct pvclock_vcpu_time_info *guest_hv_clock; @@ -3232,11 +3232,7 @@ static int kvm_guest_time_update(struct kvm_vcpu *v) if (vcpu->pv_time.active) kvm_setup_guest_pvclock(v, &vcpu->pv_time, 0); - if (vcpu->xen.vcpu_info_cache.active) - kvm_setup_guest_pvclock(v, &vcpu->xen.vcpu_info_cache, - offsetof(struct compat_vcpu_info, time)); - if (vcpu->xen.vcpu_time_info_cache.active) - kvm_setup_guest_pvclock(v, &vcpu->xen.vcpu_time_info_cache, 0); + kvm_xen_guest_time_update(v); kvm_hv_setup_tsc_page(v->kvm, &vcpu->hv_clock); return 0; } diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c index 1abb4547642a..7fc4fc2e54d8 100644 --- a/arch/x86/kvm/xen.c +++ b/arch/x86/kvm/xen.c @@ -489,6 +489,29 @@ static void kvm_xen_inject_vcpu_vector(struct kvm_vcpu *v) WARN_ON_ONCE(!kvm_irq_delivery_to_apic_fast(v->kvm, NULL, &irq, &r, NULL)); } +static struct gfn_to_pfn_cache *get_vcpu_info_cache(struct kvm_vcpu *v, unsigned long *offset) +{ + if (offset) + *offset = 0; + + return &v->arch.xen.vcpu_info_cache; +} + +void kvm_xen_guest_time_update(struct kvm_vcpu *v) +{ + unsigned long offset; + struct gfn_to_pfn_cache *gpc = get_vcpu_info_cache(v, &offset); + + BUILD_BUG_ON(offsetof(struct vcpu_info, time) != + offsetof(struct compat_vcpu_info, time)); + + if (gpc->active) + kvm_setup_guest_pvclock(v, gpc, offset + offsetof(struct compat_vcpu_info, time)); + + if (v->arch.xen.vcpu_time_info_cache.active) + kvm_setup_guest_pvclock(v, &v->arch.xen.vcpu_time_info_cache, 0); +} + /* * On event channel delivery, the vcpu_info may not have been accessible. * In that case, there are bits in vcpu->arch.xen.evtchn_pending_sel which @@ -499,7 +522,8 @@ static void kvm_xen_inject_vcpu_vector(struct kvm_vcpu *v) void kvm_xen_inject_pending_events(struct kvm_vcpu *v) { unsigned long evtchn_pending_sel = READ_ONCE(v->arch.xen.evtchn_pending_sel); - struct gfn_to_pfn_cache *gpc = &v->arch.xen.vcpu_info_cache; + unsigned long offset; + struct gfn_to_pfn_cache *gpc = get_vcpu_info_cache(v, &offset); unsigned long flags; if (!evtchn_pending_sel) @@ -522,7 +546,7 @@ void kvm_xen_inject_pending_events(struct kvm_vcpu *v) /* Now gpc->khva is a valid kernel address for the vcpu_info */ if (IS_ENABLED(CONFIG_64BIT) && v->kvm->arch.xen.long_mode) { - struct vcpu_info *vi = gpc->khva; + struct vcpu_info *vi = gpc->khva + offset; asm volatile(LOCK_PREFIX "orq %0, %1\n" "notq %0\n" @@ -534,7 +558,7 @@ void kvm_xen_inject_pending_events(struct kvm_vcpu *v) WRITE_ONCE(vi->evtchn_upcall_pending, 1); } else { u32 evtchn_pending_sel32 = evtchn_pending_sel; - struct compat_vcpu_info *vi = gpc->khva; + struct compat_vcpu_info *vi = gpc->khva + offset; asm volatile(LOCK_PREFIX "orl %0, %1\n" "notl %0\n" @@ -556,7 +580,8 @@ void kvm_xen_inject_pending_events(struct kvm_vcpu *v) int __kvm_xen_has_interrupt(struct kvm_vcpu *v) { - struct gfn_to_pfn_cache *gpc = &v->arch.xen.vcpu_info_cache; + unsigned long offset; + struct gfn_to_pfn_cache *gpc = get_vcpu_info_cache(v, &offset); unsigned long flags; u8 rc = 0; @@ -598,7 +623,7 @@ int __kvm_xen_has_interrupt(struct kvm_vcpu *v) read_lock_irqsave(&gpc->lock, flags); } - rc = ((struct vcpu_info *)gpc->khva)->evtchn_upcall_pending; + rc = ((struct vcpu_info *)(gpc->khva + offset))->evtchn_upcall_pending; read_unlock_irqrestore(&gpc->lock, flags); return rc; } @@ -1567,7 +1592,7 @@ static void kvm_xen_check_poller(struct kvm_vcpu *vcpu, int port) */ int kvm_xen_set_evtchn_fast(struct kvm_xen_evtchn *xe, struct kvm *kvm) { - struct gfn_to_pfn_cache *gpc = &kvm->arch.xen.shinfo_cache; + struct gfn_to_pfn_cache *gpc; struct kvm_vcpu *vcpu; unsigned long *pending_bits, *mask_bits; unsigned long flags; @@ -1585,7 +1610,8 @@ int kvm_xen_set_evtchn_fast(struct kvm_xen_evtchn *xe, struct kvm *kvm) WRITE_ONCE(xe->vcpu_idx, vcpu->vcpu_idx); } - if (!vcpu->arch.xen.vcpu_info_cache.active) + gpc = get_vcpu_info_cache(vcpu, NULL); + if (!gpc->active) return -EINVAL; if (xe->port >= max_evtchn_port(kvm)) @@ -1594,6 +1620,7 @@ int kvm_xen_set_evtchn_fast(struct kvm_xen_evtchn *xe, struct kvm *kvm) rc = -EWOULDBLOCK; idx = srcu_read_lock(&kvm->srcu); + gpc = &kvm->arch.xen.shinfo_cache; read_lock_irqsave(&gpc->lock, flags); if (!kvm_gpc_check(gpc, PAGE_SIZE)) @@ -1624,10 +1651,13 @@ int kvm_xen_set_evtchn_fast(struct kvm_xen_evtchn *xe, struct kvm *kvm) rc = -ENOTCONN; /* Masked */ kvm_xen_check_poller(vcpu, xe->port); } else { + unsigned long offset; + rc = 1; /* Delivered to the bitmap in shared_info. */ + /* Now switch to the vCPU's vcpu_info to set the index and pending_sel */ read_unlock_irqrestore(&gpc->lock, flags); - gpc = &vcpu->arch.xen.vcpu_info_cache; + gpc = get_vcpu_info_cache(vcpu, &offset); read_lock_irqsave(&gpc->lock, flags); if (!kvm_gpc_check(gpc, sizeof(struct vcpu_info))) { @@ -1641,13 +1671,13 @@ int kvm_xen_set_evtchn_fast(struct kvm_xen_evtchn *xe, struct kvm *kvm) } if (IS_ENABLED(CONFIG_64BIT) && kvm->arch.xen.long_mode) { - struct vcpu_info *vcpu_info = gpc->khva; + struct vcpu_info *vcpu_info = gpc->khva + offset; if (!test_and_set_bit(port_word_bit, &vcpu_info->evtchn_pending_sel)) { WRITE_ONCE(vcpu_info->evtchn_upcall_pending, 1); kick_vcpu = true; } } else { - struct compat_vcpu_info *vcpu_info = gpc->khva; + struct compat_vcpu_info *vcpu_info = gpc->khva + offset; if (!test_and_set_bit(port_word_bit, (unsigned long *)&vcpu_info->evtchn_pending_sel)) { WRITE_ONCE(vcpu_info->evtchn_upcall_pending, 1); diff --git a/arch/x86/kvm/xen.h b/arch/x86/kvm/xen.h index f8f1fe22d090..c4d29ccbc3ab 100644 --- a/arch/x86/kvm/xen.h +++ b/arch/x86/kvm/xen.h @@ -16,6 +16,7 @@ extern struct static_key_false_deferred kvm_xen_enabled; +void kvm_xen_guest_time_update(struct kvm_vcpu *vcpu); int __kvm_xen_has_interrupt(struct kvm_vcpu *vcpu); void kvm_xen_inject_pending_events(struct kvm_vcpu *vcpu); int kvm_xen_vcpu_set_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data); @@ -52,7 +53,6 @@ static inline bool kvm_xen_hypercall_enabled(struct kvm *kvm) static inline int kvm_xen_has_interrupt(struct kvm_vcpu *vcpu) { if (static_branch_unlikely(&kvm_xen_enabled.key) && - vcpu->arch.xen.vcpu_info_cache.active && vcpu->kvm->arch.xen.upcall_vector) return __kvm_xen_has_interrupt(vcpu); @@ -80,6 +80,10 @@ static inline int kvm_xen_has_pending_timer(struct kvm_vcpu *vcpu) void kvm_xen_inject_timer_irqs(struct kvm_vcpu *vcpu); #else +static inline void kvm_xen_guest_time_update(struct kvm_vcpu *vcpu) +{ +} + static inline int kvm_xen_write_hypercall_page(struct kvm_vcpu *vcpu, u64 data) { return 1; From patchwork Mon Sep 18 14:41:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 141503 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2857952vqi; Mon, 18 Sep 2023 11:15:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGsxJb7gjdfLUZktdQC90xgubYNgSKdMhh0awWUEEZXF50Xa1JUdJVJKPnDCPj3OFyuUBYq X-Received: by 2002:a05:6a21:3297:b0:133:e3e3:dc07 with SMTP id yt23-20020a056a21329700b00133e3e3dc07mr10917114pzb.49.1695060915241; Mon, 18 Sep 2023 11:15:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695060915; cv=none; d=google.com; s=arc-20160816; b=h+XujV7X3u0a6mqfdPC0L7tNoNdKVTdj8LyqauW8CoAJpIS8mBwkrX/OSOseVYWz5b Ba76u60cNHWOgzeieGZRRG4vmSdqzzO8uouy2FkiIwTQw6YhA10sKYiSFxB9E5hL1+IH /MisFqeWnPdDWiTqA6cTn5cjRcIf9kSgssr7p3YFjHFS57qrDF9uY0eKzmHq6FEllS3L lhL0rqfAnuKFSTHcbMprKgSzb0rem6qesGI1nHR4gD1G3YgntAyYnKTxu4RQd7nKDP70 qyctee+5acJo3YQtDSgzksnzhtaJyg/qxw4WHefg0k0s085zre2PHHBmJsU6wU+HR5v7 PSVg== 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=5dx9h7SGIgzZx3McRPLzAIAziBr0OX4wLMeK0R+Vbo4=; fh=F/y/rQAitAoVhyEvV7npxQC+pmk+LQOxsxEGW4WYgok=; b=gr33XsrkYdHU6hTajDADPCAdZgdFHteo7LGCEOGQOr7REWHHP40Yo3a2W5bagNgIyB UkXSRts0BFzV8KoEji1L7WevgQi1l61Wy1/nKDv4Cx4p5CdnLmIgecFe5Nz8TevZfSOJ GSiCL5pvYN5xHrPmCkhkUU2fq4IIUMolQ5ggoazjmaVv+5jwUrO+EhxsYBoMndq8DsPY Tzfk7WbudRDG7UUEa5GbtcZ9IEdV9GnymaRan9NMAPjaroQWomHSCwCO4vaKrrTT4Bxv NzJ944EZumLMWRQr4ZJccuZbt789dxfO1drb7234BUY5cJayxtWwvhGFDQUw2I37Znab yreg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b="Gnf/zoQr"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id n3-20020a6546c3000000b00563a0bacbb4si209378pgr.694.2023.09.18.11.15.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 11:15:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b="Gnf/zoQr"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id B5B1E8040900; Mon, 18 Sep 2023 09:09:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229914AbjIRQJQ (ORCPT + 25 others); Mon, 18 Sep 2023 12:09:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230055AbjIRQJB (ORCPT ); Mon, 18 Sep 2023 12:09:01 -0400 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD42A4490; Mon, 18 Sep 2023 09:07:21 -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=5dx9h7SGIgzZx3McRPLzAIAziBr0OX4wLMeK0R+Vbo4=; b=Gnf/zoQr0L3d+R9LPNsUGbq9bn HzG3qkJHEhds8QKj4zCEfDn9lyoFzW4/0jEq/L93y57iXD3UO6VvyudUojAEt+NWCqbmkqFrQNtR1 WVAXGfWxzW/NRzKTCxp++ExLwZpbUFO66gw8qeGAwZfdq4DWdPDAKytgz9W7wqkxkyHY=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qiFRG-0003RQ-Lf; Mon, 18 Sep 2023 14:41:26 +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 1qiFRG-0006IJ-E8; Mon, 18 Sep 2023 14:41:26 +0000 From: Paul Durrant To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Paul Durrant , David Woodhouse , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , x86@kernel.org Subject: [PATCH v3 08/13] KVM: xen: prevent vcpu_id from changing whilst shared_info is valid Date: Mon, 18 Sep 2023 14:41:06 +0000 Message-Id: <20230918144111.641369-9-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230918144111.641369-1-paul@xen.org> References: <20230918144111.641369-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 morse.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 (morse.vger.email [0.0.0.0]); Mon, 18 Sep 2023 09:09:27 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777396452284052686 X-GMAIL-MSGID: 1777400194611676631 From: Paul Durrant To further prepare for automatically using the vcpu_info structures embedded in the shared_info page, we need to ensure that the Xen vcpu_id cannot change under our feet. We can do this by simply returning -EBUSY to any attempt to modify the attribute while the shinfo_cache is active. Signed-off-by: Paul Durrant --- 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 v3: - New in this version. --- arch/x86/kvm/xen.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c index 7fc4fc2e54d8..459f3ca4710e 100644 --- a/arch/x86/kvm/xen.c +++ b/arch/x86/kvm/xen.c @@ -752,6 +752,18 @@ int kvm_xen_hvm_get_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data) return r; } +static int kvm_xen_set_vcpu_id(struct kvm_vcpu *vcpu, unsigned int vcpu_id) +{ + struct kvm *kvm = vcpu->kvm; + struct gfn_to_pfn_cache *gpc = &kvm->arch.xen.shinfo_cache; + + if (gpc->active) + return -EBUSY; + + vcpu->arch.xen.vcpu_id = vcpu_id; + return 0; +} + int kvm_xen_vcpu_set_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data) { int idx, r = -ENOENT; @@ -941,10 +953,8 @@ int kvm_xen_vcpu_set_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data) case KVM_XEN_VCPU_ATTR_TYPE_VCPU_ID: if (data->u.vcpu_id >= KVM_MAX_VCPUS) r = -EINVAL; - else { - vcpu->arch.xen.vcpu_id = data->u.vcpu_id; - r = 0; - } + else + r = kvm_xen_set_vcpu_id(vcpu, data->u.vcpu_id); break; case KVM_XEN_VCPU_ATTR_TYPE_TIMER: From patchwork Mon Sep 18 14:41:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 141467 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2780650vqi; Mon, 18 Sep 2023 09:19:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHI1ShYFNRH5xjMc5jWCGDVEexNOMujnskY2bML86H6uKettvkKjUUmYq/4W7rqTQ73j4cz X-Received: by 2002:a05:6a00:2d20:b0:68f:cc0e:355d with SMTP id fa32-20020a056a002d2000b0068fcc0e355dmr9269228pfb.25.1695053976827; Mon, 18 Sep 2023 09:19:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695053976; cv=none; d=google.com; s=arc-20160816; b=iQen8OoDc0HhQgjeZpmqjtgYh1X14mBthXeRCfUrnB642EyNALVpmT5YmN/Blj7qsS hWcvn0rHYGIKVgjALXDdwNeQLI0m3Z7MgJ3e4dYI/iw7+Gtcspls1S1YLfxEMS22cO8Y S8MZ7S0kRWEvPhnxcxQ7BHqV2L9QKxytfwiwhMJeEO49t69LHVFhOp/yrHhhRLi1gNyR TNCsQgXVm2F4z1DC2dj6ZE+bub670m2DvzM2j7qswiUKCqgDxd3SJ6S/rM4COEhoZnsm KVrVX8GX12fZyP3lz9Ou5snh6q5k6nubcX59OKij8QoWizXNzJfXoqW290z4Jy6+h4ri LfSA== 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=Oc53yzU2VCdUyIo3BjcPhE5hr1+ghEoPGq4cggTejWY=; fh=Pw8ME2ioat+0rO24kCOjPSzdtMZ7IXXfoe/kHVOMV8g=; b=zN0UmG3PZ0DOY+YSZrn2dHTHmQuhuy4DdA+C6N7MJSpEggUSZ4F/QG+unubiVQRrhX F4Wh6cokAVd1Q6WE94DpzxbWOvtAy3gIo691yB2IYNm/UF4AVxO/EnBuR4P+viGoHVxW gwwX+cals7w6Rmlbpe6mhTKMcIsVc5AJ3DWnReaczrNneohZhhi0BuY7Ip+jn3+ZeLzR VDU81MXfR9OXZmMg07NNKJ5/DUq8XIGwTe68k/KRCBN4tP2tnH2pQSZFz4fh2bOV6Woi x7qbNRlmvsISeRVp+QKbxuYWK4CtJHqvQSDBaya0bWXkSAFVS856WDDH6pkyVW+JzZZF mt6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b="R/WcIPwh"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id ea13-20020a056a004c0d00b00686baf235easi8264931pfb.258.2023.09.18.09.19.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 09:19:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b="R/WcIPwh"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id D284080D754A; Mon, 18 Sep 2023 09:10:31 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229959AbjIRQJ6 (ORCPT + 25 others); Mon, 18 Sep 2023 12:09:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229957AbjIRQJW (ORCPT ); Mon, 18 Sep 2023 12:09:22 -0400 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F58D49C8; Mon, 18 Sep 2023 09:08:07 -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=Oc53yzU2VCdUyIo3BjcPhE5hr1+ghEoPGq4cggTejWY=; b=R/WcIPwhyvbzwQowjQg0taQRF7 mgRpElbPoVEYQLzQux7XmW2HdWINeMgZ8KT/ooK55CxcHrecXjIxuoJl2TpjufIdb1ftAu/zVYLkP ySz/H1HlWPq0jGQVNlxWKP/WPDyhv6rtzScpwYdzLAf9YiwVFCbKyfz0sPWPrbYJd1bE=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qiFRI-0003Rs-6X; Mon, 18 Sep 2023 14:41:28 +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 1qiFRH-0006IJ-VD; Mon, 18 Sep 2023 14:41:28 +0000 From: Paul Durrant To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Paul Durrant , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , David Woodhouse , x86@kernel.org Subject: [PATCH v3 09/13] KVM: xen: automatically use the vcpu_info embedded in shared_info Date: Mon, 18 Sep 2023 14:41:07 +0000 Message-Id: <20230918144111.641369-10-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230918144111.641369-1-paul@xen.org> References: <20230918144111.641369-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 agentk.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 (agentk.vger.email [0.0.0.0]); Mon, 18 Sep 2023 09:10:31 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777392918725376354 X-GMAIL-MSGID: 1777392918725376354 From: Paul Durrant The VMM should only need to set the KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO attribute in response to a VCPUOP_register_vcpu_info hypercall. We can handle the default case internally since we already know where the shared_info page is. Modify get_vcpu_info_cache() to pass back a pointer to the shared info pfn cache (and appropriate offset) for any of the first 32 vCPUs if the attribute has not been set. A VMM will be able to determine whether it needs to set up default vcpu_info using the previously defined KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA Xen capability flag, which will be advertized in a subsequent patch. Also update the KVM API documentation to describe the new behaviour. Signed-off-by: Paul Durrant --- Cc: Sean Christopherson Cc: Paolo Bonzini Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: David Woodhouse Cc: x86@kernel.org v3: - Add a note to the API documentation discussing vcpu_info copying. v2: - Dispense with the KVM_XEN_HVM_CONFIG_DEFAULT_VCPU_INFO capability. - Add API documentation. --- Documentation/virt/kvm/api.rst | 22 +++++++++++++++------- arch/x86/kvm/xen.c | 15 +++++++++++++++ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index e9df4df6fe48..47bf3db74674 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -5442,13 +5442,7 @@ KVM_XEN_ATTR_TYPE_LONG_MODE KVM_XEN_ATTR_TYPE_SHARED_INFO Sets the guest physical frame number at which the Xen shared_info - page resides. Note that although Xen places vcpu_info for the first - 32 vCPUs in the shared_info page, KVM does not automatically do so - and instead requires that KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO be used - explicitly even when the vcpu_info for a given vCPU resides at the - "default" location in the shared_info page. This is because KVM may - not be aware of the Xen CPU id which is used as the index into the - vcpu_info[] array, so may know the correct default location. + page resides. Note that the shared_info page may be constantly written to by KVM; it contains the event channel bitmap used to deliver interrupts to @@ -5564,12 +5558,26 @@ type values: KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO Sets the guest physical address of the vcpu_info for a given vCPU. + The vcpu_info for the first 32 vCPUs defaults to the structures + embedded in the shared_info page. + + If the KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA flag is also set in the + Xen capabilities then the VMM is not required to set this default + location; KVM will handle that internally. Otherwise this attribute + must be set for all vCPUs. + As with the shared_info page for the VM, the corresponding page may be dirtied at any time if event channel interrupt delivery is enabled, so userspace should always assume that the page is dirty without relying on dirty logging. Setting the gpa to KVM_XEN_INVALID_GPA will disable the vcpu_info. + Note that, if the guest sets an explicit vcpu_info location in guest + memory then the VMM is expected to copy the content of the structure + embedded in the shared_info page to the new location. It is therefore + important that no event delivery is in progress at this time, otherwise + events may be missed. + KVM_XEN_VCPU_ATTR_TYPE_VCPU_TIME_INFO Sets the guest physical address of an additional pvclock structure for a given vCPU. This is typically used for guest vsyscall support. diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c index 459f3ca4710e..660a808c0b50 100644 --- a/arch/x86/kvm/xen.c +++ b/arch/x86/kvm/xen.c @@ -491,6 +491,21 @@ static void kvm_xen_inject_vcpu_vector(struct kvm_vcpu *v) static struct gfn_to_pfn_cache *get_vcpu_info_cache(struct kvm_vcpu *v, unsigned long *offset) { + if (!v->arch.xen.vcpu_info_cache.active && v->arch.xen.vcpu_id < MAX_VIRT_CPUS) { + struct kvm *kvm = v->kvm; + + if (offset) { + if (IS_ENABLED(CONFIG_64BIT) && kvm->arch.xen.long_mode) + *offset = offsetof(struct shared_info, + vcpu_info[v->arch.xen.vcpu_id]); + else + *offset = offsetof(struct compat_shared_info, + vcpu_info[v->arch.xen.vcpu_id]); + } + + return &kvm->arch.xen.shinfo_cache; + } + if (offset) *offset = 0; From patchwork Mon Sep 18 14:41:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 141545 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2916654vqi; Mon, 18 Sep 2023 12:59:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE4OgQ9cw3RnCPrFFKrCCdj9EV35dNGxvlWTNuRcyxh8PQ8CNXHpomebt4pmWwn8JZ0kOP0 X-Received: by 2002:a17:902:e744:b0:1bc:2188:ef88 with SMTP id p4-20020a170902e74400b001bc2188ef88mr11957083plf.3.1695067144834; Mon, 18 Sep 2023 12:59:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695067144; cv=none; d=google.com; s=arc-20160816; b=Dw2Y24MKc79DaGl1dc/y/P7ewRrauhnifPM0kT0w+FNhqXJlhvVh3IzDY1UuO7sf0W Nnbhonv93dd87wGZomNkaOKladE7dbsxKNPGPoZl4ygIgbfQ3nfgOqPBFKjyRRm4EFFG YksVhprtq9lWZhE/C9p7waJNPhQXgaLkWwXD24WlYdOOVipQOiJNUPS1VCqJWbzsQYI+ 2pBBdsN7YBknJ+NFYdcUA3jxiy6//0qEq27G3Op0yv74gYSvlxAwUamVj8j7j6xe2/pf MMhxEHTKNPnTvdc+ofwBpmjqCL81fncConqFyUTRK72N2uX9JEdjo1ThtGmxlLlyPR3/ HBuw== 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=CigriqAWm5+Zqbh0ySs+Qdr8JUD6ix8xCQrHh/XGvCI=; fh=lKhNn3P8ZvksS1fElybz1iP8zlw6JVVQ9gjuN2JwMdc=; b=M89NA2PNAaTKwR8ivjbIA2c3UPpfYCJ+giliE8bkBACvtAEIjQwA6IU5WIPLMHfPpw wCq7/UF+Cnb81JhRJxagRjJKGDAvz93E6kcLAicHjllbz7tv/YyNIn1eN2XeA4Ots5mu vm0D7VICtTY7cmiGRFewB4UAV/gHKUTmaZS0pQqdPwDu/fdUAtphP6ziRi3e2PDmXODY qaCgftT1aTQFM0oyo64eMpuZ01yaNxb9jaVqdWY7b55LwSlkD9lK8snAMXcOCK2w8eDn KW9CeotNPbXCs8FDDqcYH6Y3bdTUXqwDY8OtbkG4k1ZvWN6ktSXEYc5S59GZNn+oW4Yd /mKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=G4dtPZ6Q; 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 Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id y15-20020a17090322cf00b001c589ba4a04si951789plg.24.2023.09.18.12.59.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 12:59:04 -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=@xen.org header.s=20200302mail header.b=G4dtPZ6Q; 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 Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 6922A81129AF; Mon, 18 Sep 2023 09:35:48 -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 S229750AbjIRQfa (ORCPT + 25 others); Mon, 18 Sep 2023 12:35:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229782AbjIRQfR (ORCPT ); Mon, 18 Sep 2023 12:35:17 -0400 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDD679EE5; Mon, 18 Sep 2023 09:13:38 -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=CigriqAWm5+Zqbh0ySs+Qdr8JUD6ix8xCQrHh/XGvCI=; b=G4dtPZ6QzC/Mx1ayMmja8UaCBz Wi7eWD989uB243EOAaMBUV0kNpWx2Px3IiB2gMVCvP9U9404uwIjfohnv3seFsVdfVzYML5ydU/bq rOijW6qVZrs8zYSqXoFAlBKBBu314MXcWDtra+epBiQDMxUCVaJvjMqDiYcQ/ga1Juyk=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qiFSh-0003UA-9J; Mon, 18 Sep 2023 14:42:55 +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 1qiFRJ-0006IJ-0Z; Mon, 18 Sep 2023 14:41:29 +0000 From: Paul Durrant To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Paul Durrant , David Woodhouse , Sean Christopherson , Paolo Bonzini , David Woodhouse Subject: [PATCH v3 10/13] KVM: selftests / xen: set KVM_XEN_VCPU_ATTR_TYPE_VCPU_ID Date: Mon, 18 Sep 2023 14:41:08 +0000 Message-Id: <20230918144111.641369-11-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230918144111.641369-1-paul@xen.org> References: <20230918144111.641369-1-paul@xen.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 18 Sep 2023 09:35:49 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777406726464203975 X-GMAIL-MSGID: 1777406726464203975 From: Paul Durrant If the capability (KVM_XEN_HVM_CONFIG_EVTCHN_SEND) is present then set the guest's vCPU id to match the chosen vcpu_info offset. Also make some cosmetic fixes to the code for clarity. Signed-off-by: Paul Durrant Reviewed-by: David Woodhouse --- Cc: Sean Christopherson Cc: Paolo Bonzini Cc: David Woodhouse v3: - Remame VCPU_ID to XEN_VCPU_ID. - Set vcpu_id before the shared_info page is set. v2: - New in this version. --- .../selftests/kvm/x86_64/xen_shinfo_test.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c b/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c index 05898ad9f4d9..b0c3a00ea6a6 100644 --- a/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c +++ b/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c @@ -38,6 +38,8 @@ #define VCPU_INFO_VADDR (SHINFO_REGION_GVA + 0x40) #define RUNSTATE_VADDR (SHINFO_REGION_GVA + PAGE_SIZE + PAGE_SIZE - 15) +#define XEN_VCPU_ID 1 /* Must correspond to offset of VCPU_INFO_[V]ADDR */ + #define EVTCHN_VECTOR 0x10 #define EVTCHN_TEST1 15 @@ -410,7 +412,7 @@ static void *juggle_shinfo_state(void *arg) struct kvm_xen_hvm_attr cache_activate = { .type = KVM_XEN_ATTR_TYPE_SHARED_INFO, - .u.shared_info.gfn = SHINFO_REGION_GPA / PAGE_SIZE + .u.shared_info.gfn = SHINFO_ADDR / PAGE_SIZE }; struct kvm_xen_hvm_attr cache_deactivate = { @@ -446,6 +448,7 @@ int main(int argc, char *argv[]) bool do_runstate_flag = !!(xen_caps & KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG); bool do_eventfd_tests = !!(xen_caps & KVM_XEN_HVM_CONFIG_EVTCHN_2LEVEL); bool do_evtchn_tests = do_eventfd_tests && !!(xen_caps & KVM_XEN_HVM_CONFIG_EVTCHN_SEND); + bool has_vcpu_id = !!(xen_caps & KVM_XEN_HVM_CONFIG_EVTCHN_SEND); clock_gettime(CLOCK_REALTIME, &min_ts); @@ -492,9 +495,17 @@ int main(int argc, char *argv[]) "Failed to read back RUNSTATE_UPDATE_FLAG attr"); } + if (has_vcpu_id) { + struct kvm_xen_vcpu_attr vid = { + .type = KVM_XEN_VCPU_ATTR_TYPE_VCPU_ID, + .u.vcpu_id = XEN_VCPU_ID, + }; + vcpu_ioctl(vcpu, KVM_XEN_VCPU_SET_ATTR, &vid); + } + struct kvm_xen_hvm_attr ha = { .type = KVM_XEN_ATTR_TYPE_SHARED_INFO, - .u.shared_info.gfn = SHINFO_REGION_GPA / PAGE_SIZE, + .u.shared_info.gfn = SHINFO_ADDR / PAGE_SIZE, }; vm_ioctl(vm, KVM_XEN_HVM_SET_ATTR, &ha); @@ -983,8 +994,8 @@ int main(int argc, char *argv[]) struct pvclock_wall_clock *wc; struct pvclock_vcpu_time_info *ti, *ti2; - wc = addr_gpa2hva(vm, SHINFO_REGION_GPA + 0xc00); - ti = addr_gpa2hva(vm, SHINFO_REGION_GPA + 0x40 + 0x20); + wc = addr_gpa2hva(vm, SHINFO_ADDR + 0xc00); + ti = addr_gpa2hva(vm, VCPU_INFO_ADDR + 0x20); ti2 = addr_gpa2hva(vm, PVTIME_ADDR); if (verbose) { From patchwork Mon Sep 18 14:41:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 141617 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3025732vqi; Mon, 18 Sep 2023 16:47:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEgkJ5vJaEkQBB/ORGO3Q9i0U48IRH/i1NdngvALCUWacNzdy54bBf693r8USZi2ezvMtfO X-Received: by 2002:a17:90b:1d11:b0:273:ee6c:ee5c with SMTP id on17-20020a17090b1d1100b00273ee6cee5cmr7835316pjb.7.1695080866461; Mon, 18 Sep 2023 16:47:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695080866; cv=none; d=google.com; s=arc-20160816; b=cw+9hMIx5QznRciIycc68G+v4lPXd8kNZlvLLOVYYes7BufQuQoDuoJiJ7zuu7sJ3P +U1xF4APpaKlebr3fJLzyqBlYz4+bCaAfD9ZPcjwMxGP1I++/M9ZpWTfT9ZEdovlIQjj RlKv2/tSQqSwbqq3xTAM4tn6hAh3v096qQTn87bHpKIcGytoHrFPJRLhNo6S4h88vXtz LRIT0nex7fZJ9X6roLWk07L1aOwS1/1COzmfGzH0Rt5e4/5+0j5+PSfPaAHq7tPc5UXc W+dpmL/nOyiSNB4oT85kClw+4yrzKAKxUKCllmOH27wZ86dYJMT1eG+Scl1TiZIg8KDR ICdQ== 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=O1UwdIApqICpUnoD3lgh45k1NJYOWtnkGJkAL8qzkG4=; fh=NVKswJvclYk1MEC7AfFzo67YIylApYMwZ7eFzXKDgdk=; b=WyaMYE1qlWbpSYZz7DKsv+0WUjF0OftpIibjUY+DX94CI8tUjVuhlhYtIuM/f1KFAb jBwteVL/0+LkPpg0xAHYu3p5ovxEL48y5G2ZL2I1/EinZ2Ls+ILAnpEQUthiGQlr3m8I tqA7RH8PrTkQTBHz47brMe0R0YlTeBw4C/9Ytdm9ofxkZ3vm7iPoOGTGILtMPRLGodn4 WZ6mzaxTW+DKJ39UNslNgVeR7REPV9sM1dLDUzLxqu4F9VY0UDu/lZjW1zzBw0dWr/bc 5c5mm/NbbNqF/CjokFsCowfmYSD5r++yc46E40VyjHbOF4BIAGl8mvDqX5y6MEczbpPi huuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=JMAaXKrq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id oc16-20020a17090b1c1000b0026824d6cb0fsi11596870pjb.164.2023.09.18.16.47.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 16:47:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=JMAaXKrq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 8D5D2803466A; Mon, 18 Sep 2023 09:10:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229898AbjIRQJZ (ORCPT + 25 others); Mon, 18 Sep 2023 12:09:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230005AbjIRQJI (ORCPT ); Mon, 18 Sep 2023 12:09:08 -0400 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 543DE4493; Mon, 18 Sep 2023 09:07:37 -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=O1UwdIApqICpUnoD3lgh45k1NJYOWtnkGJkAL8qzkG4=; b=JMAaXKrqSE5zJzdDvo2fQ96lEY JuA0MIG20ZNejCWvA6LxKgOcMI15NWQCVo6aDU8zTMQCtMUSRunNJStTfZy19nhDsGuHobNPausXE Ku8Fvi9pds9Mbq32WvruC/QaZK6obacO6Pid6yLkUue4v0hMZU+ECUXpgZsS+lED/uso=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qiFSh-0003U8-7g; Mon, 18 Sep 2023 14:42:55 +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 1qiFRJ-0006IJ-VQ; Mon, 18 Sep 2023 14:41:30 +0000 From: Paul Durrant To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Paul Durrant , Sean Christopherson , Paolo Bonzini , David Woodhouse Subject: [PATCH v3 11/13] KVM: selftests / xen: map shared_info using HVA rather than GFN Date: Mon, 18 Sep 2023 14:41:09 +0000 Message-Id: <20230918144111.641369-12-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230918144111.641369-1-paul@xen.org> References: <20230918144111.641369-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 morse.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 (morse.vger.email [0.0.0.0]); Mon, 18 Sep 2023 09:10:15 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777421114858989662 X-GMAIL-MSGID: 1777421114858989662 From: Paul Durrant Using the HVA of the shared_info page is more efficient, so if the capability (KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA) is present use that method to do the mapping. NOTE: Have the juggle_shinfo_state() thread map and unmap using both GFN and HVA, to make sure the older mechanism is not broken. Signed-off-by: Paul Durrant Reviewed-by: David Woodhouse --- Cc: Sean Christopherson Cc: Paolo Bonzini Cc: David Woodhouse v3: - Re-work the juggle_shinfo_state() thread v2: - New in this version. --- .../selftests/kvm/x86_64/xen_shinfo_test.c | 44 +++++++++++++++---- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c b/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c index b0c3a00ea6a6..e786fa370140 100644 --- a/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c +++ b/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c @@ -395,6 +395,7 @@ static int cmp_timespec(struct timespec *a, struct timespec *b) return 0; } +static struct shared_info *shinfo; static struct vcpu_info *vinfo; static struct kvm_vcpu *vcpu; @@ -410,20 +411,38 @@ static void *juggle_shinfo_state(void *arg) { struct kvm_vm *vm = (struct kvm_vm *)arg; - struct kvm_xen_hvm_attr cache_activate = { + struct kvm_xen_hvm_attr cache_activate_gfn = { .type = KVM_XEN_ATTR_TYPE_SHARED_INFO, .u.shared_info.gfn = SHINFO_ADDR / PAGE_SIZE }; - struct kvm_xen_hvm_attr cache_deactivate = { + struct kvm_xen_hvm_attr cache_deactivate_gfn = { .type = KVM_XEN_ATTR_TYPE_SHARED_INFO, .u.shared_info.gfn = KVM_XEN_INVALID_GFN }; + struct kvm_xen_hvm_attr cache_activate_hva = { + .type = KVM_XEN_ATTR_TYPE_SHARED_INFO_HVA, + .u.shared_info.hva = (unsigned long)shinfo + }; + + struct kvm_xen_hvm_attr cache_deactivate_hva = { + .type = KVM_XEN_ATTR_TYPE_SHARED_INFO, + .u.shared_info.hva = 0 + }; + + int xen_caps = kvm_check_cap(KVM_CAP_XEN_HVM); + for (;;) { - __vm_ioctl(vm, KVM_XEN_HVM_SET_ATTR, &cache_activate); - __vm_ioctl(vm, KVM_XEN_HVM_SET_ATTR, &cache_deactivate); + __vm_ioctl(vm, KVM_XEN_HVM_SET_ATTR, &cache_activate_gfn); pthread_testcancel(); + __vm_ioctl(vm, KVM_XEN_HVM_SET_ATTR, &cache_deactivate_gfn); + + if (xen_caps & KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA) { + __vm_ioctl(vm, KVM_XEN_HVM_SET_ATTR, &cache_activate_hva); + pthread_testcancel(); + __vm_ioctl(vm, KVM_XEN_HVM_SET_ATTR, &cache_deactivate_hva); + } } return NULL; @@ -449,6 +468,7 @@ int main(int argc, char *argv[]) bool do_eventfd_tests = !!(xen_caps & KVM_XEN_HVM_CONFIG_EVTCHN_2LEVEL); bool do_evtchn_tests = do_eventfd_tests && !!(xen_caps & KVM_XEN_HVM_CONFIG_EVTCHN_SEND); bool has_vcpu_id = !!(xen_caps & KVM_XEN_HVM_CONFIG_EVTCHN_SEND); + bool has_shinfo_hva = !!(xen_caps & KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA); clock_gettime(CLOCK_REALTIME, &min_ts); @@ -459,7 +479,7 @@ int main(int argc, char *argv[]) SHINFO_REGION_GPA, SHINFO_REGION_SLOT, 3, 0); virt_map(vm, SHINFO_REGION_GVA, SHINFO_REGION_GPA, 3); - struct shared_info *shinfo = addr_gpa2hva(vm, SHINFO_VADDR); + shinfo = addr_gpa2hva(vm, SHINFO_VADDR); int zero_fd = open("/dev/zero", O_RDONLY); TEST_ASSERT(zero_fd != -1, "Failed to open /dev/zero"); @@ -503,10 +523,16 @@ int main(int argc, char *argv[]) vcpu_ioctl(vcpu, KVM_XEN_VCPU_SET_ATTR, &vid); } - struct kvm_xen_hvm_attr ha = { - .type = KVM_XEN_ATTR_TYPE_SHARED_INFO, - .u.shared_info.gfn = SHINFO_ADDR / PAGE_SIZE, - }; + struct kvm_xen_hvm_attr ha = {}; + + if (has_shinfo_hva) { + ha.type = KVM_XEN_ATTR_TYPE_SHARED_INFO_HVA; + ha.u.shared_info.hva = (unsigned long)shinfo; + } else { + ha.type = KVM_XEN_ATTR_TYPE_SHARED_INFO; + ha.u.shared_info.gfn = SHINFO_ADDR / PAGE_SIZE; + } + vm_ioctl(vm, KVM_XEN_HVM_SET_ATTR, &ha); /* From patchwork Mon Sep 18 14:41:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 141591 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2980671vqi; Mon, 18 Sep 2023 15:05:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGSNcjFt9ePtnipYzCS/4cwWZfCcrgsp6WYzpMyi+YTtK2bjMNV+q030IeR7U81vXcCA+Sw X-Received: by 2002:a05:6a20:2583:b0:153:8db6:c4fe with SMTP id k3-20020a056a20258300b001538db6c4femr10071800pzd.39.1695074722966; Mon, 18 Sep 2023 15:05:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695074722; cv=none; d=google.com; s=arc-20160816; b=ijGwe+fhyOwifJ2VUcMB0V/FqL27Rp7LID85xZdoX18aeoWXMxn2wI2HuTOM+BA6wh kLCouFp0i9FsI0qehesygTUANdQRl4oNCs9R/Yi78vPoof0e0hmfFXxeGqSGVcV7JKN5 5YGK9/Em9B7XvJ5Eo/EM6VzaYn2iYWwx4F48P/ch0L/Lrs1wXBxpZiyvRQO8GJJFNQsW vCIq6v3lGON6tUpUVAnqA21afx87Ve+PmwBCBVxugSMLYXf/AppgQbEoqykOZCuzfYWa RS2zWAN/WeBDaC9StvQ7JkNXVrpwcbxJJ1V6t8WLB3EXZKna6Iyd50MFVf7aq1H0SI4w IdVA== 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=daQKqPz4lN3mboBM/jvRe9yPAi0c9kCRdyVAIEbpHSg=; fh=NVKswJvclYk1MEC7AfFzo67YIylApYMwZ7eFzXKDgdk=; b=iCogNk1CQqKlOiueF+Qxm/nv1RODA8LmMlM3/DFK86TujSHs7cPuo7ROnA6qneFfJv OX3hTcRC+LhsQc+SVsuUWdJ9SCSgEj5SDuu5WI9Cf6BcnDoj2P+MTAPALblSm+ffF5n8 uTbzDHpQoKA0Yz7x5t8zKYhPKX493LsXn12i8vUmmQTm1uZzliheGo7qoG9wwglXtUBm +bcF+bHUwIq4nL0AUOHXAwkaa6qoksrYjoYJFvVJAKnv6Sfwby3SPGKPQkZLuPey7eeO BqaAdqozCD2AJXzTz2mSOZmbiTaEGsEx8UpRAyM942GtzbaBIPWgOECgbSxIMfQRPbQP PfLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=oBLNzGO4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id bv190-20020a632ec7000000b00565f611a1f8si8145399pgb.263.2023.09.18.15.05.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 15:05:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=oBLNzGO4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 5642C8093D7E; Mon, 18 Sep 2023 09:21:39 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230217AbjIRQVV (ORCPT + 25 others); Mon, 18 Sep 2023 12:21:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230120AbjIRQVR (ORCPT ); Mon, 18 Sep 2023 12:21:17 -0400 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D85441334; Mon, 18 Sep 2023 09:14:09 -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=daQKqPz4lN3mboBM/jvRe9yPAi0c9kCRdyVAIEbpHSg=; b=oBLNzGO4uvOnKtz8aUtc1XyVxn xjknr6v97cYtOEoKTO6DeCSZmbfMiIWRqSJN5Yq6C9sWz8nuXeVQOsByMxoRtY9wkrfN74+qKVzlb fr9kIevqkNYOni4qHhEMTyrFam3PH81rLq9vzAudDvZuSRK5QpaZn6MGhEG2uJC14ZRE=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qiFSh-0003UC-Av; Mon, 18 Sep 2023 14:42:55 +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 1qiFRK-0006IJ-U1; Mon, 18 Sep 2023 14:41:31 +0000 From: Paul Durrant To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Paul Durrant , Sean Christopherson , Paolo Bonzini , David Woodhouse Subject: [PATCH v3 12/13] KVM: selftests / xen: don't explicitly set the vcpu_info address Date: Mon, 18 Sep 2023 14:41:10 +0000 Message-Id: <20230918144111.641369-13-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230918144111.641369-1-paul@xen.org> References: <20230918144111.641369-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 agentk.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 (agentk.vger.email [0.0.0.0]); Mon, 18 Sep 2023 09:21:39 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777414673086508376 X-GMAIL-MSGID: 1777414673086508376 From: Paul Durrant If the vCPU id is set and the shared_info is mapped using HVA then we can infer that KVM has the ability to use a default vcpu_info mapping. Hence we can stop setting the address of the vcpu_info structure. NOTE: We still explicitly set vcpu_info half way through testing (to point at exactly the place it already is) to make sure that setting the attribute does not fail. Signed-off-by: Paul Durrant Reviewed-by: David Woodhouse --- Cc: Sean Christopherson Cc: Paolo Bonzini Cc: David Woodhouse v3: - Add a guest sync point to set the vcpu_info attribute v2: - New in this version. --- .../testing/selftests/kvm/x86_64/xen_shinfo_test.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c b/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c index e786fa370140..7e74b3063437 100644 --- a/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c +++ b/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c @@ -68,6 +68,7 @@ enum { TEST_POLL_TIMEOUT, TEST_POLL_MASKED, TEST_POLL_WAKE, + SET_VCPU_INFO, TEST_TIMER_PAST, TEST_LOCKING_SEND_RACE, TEST_LOCKING_POLL_RACE, @@ -327,6 +328,10 @@ static void guest_code(void) GUEST_SYNC(TEST_POLL_WAKE); + /* Set the vcpu_info to point at exactly the place it already is to + * make sure the attribute is functional. */ + GUEST_SYNC(SET_VCPU_INFO); + /* A timer wake an *unmasked* port which should wake us with an * actual interrupt, while we're polling on a different port. */ ports[0]++; @@ -549,7 +554,10 @@ int main(int argc, char *argv[]) .type = KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO, .u.gpa = VCPU_INFO_ADDR, }; - vcpu_ioctl(vcpu, KVM_XEN_VCPU_SET_ATTR, &vi); + + if (!has_vcpu_id || !has_shinfo_hva) { + vcpu_ioctl(vcpu, KVM_XEN_VCPU_SET_ATTR, &vi); + } struct kvm_xen_vcpu_attr pvclock = { .type = KVM_XEN_VCPU_ATTR_TYPE_VCPU_TIME_INFO, @@ -903,6 +911,10 @@ int main(int argc, char *argv[]) alarm(1); break; + case SET_VCPU_INFO: + vcpu_ioctl(vcpu, KVM_XEN_VCPU_SET_ATTR, &vi); + break; + case TEST_TIMER_PAST: TEST_ASSERT(!evtchn_irq_expected, "Expected event channel IRQ but it didn't happen"); From patchwork Mon Sep 18 14:41:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 141516 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2878990vqi; Mon, 18 Sep 2023 11:51:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHApHzKeJhAYY0f7GHYWrMfv65ssRsqNE18y256XNZcKXpuLxs7TkXYK2Fr9urLatu10rv2 X-Received: by 2002:a17:90a:ca10:b0:26d:b12:8383 with SMTP id x16-20020a17090aca1000b0026d0b128383mr8080772pjt.8.1695063069057; Mon, 18 Sep 2023 11:51:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695063069; cv=none; d=google.com; s=arc-20160816; b=NnhemCZQyiy3olQH6/gvsVgYVqvaHOZFOjVhgUlHzZkQBjuKuqvipIKBm9Gva7GcXF zTPRhEtx3SHvB6mgdf7aWftVH/pW+GDnBOeP1LemDfbdCsfaIXTar2qJgW/YIISS7I/h 1FUtxMr21lYloD12CZtGP3p1PW8dBAHC7wHVA6cDmph8QwdSwSrmjUDd7MfO7NtgCJXM fkqUmLG4PWSItbuvTYpVQoE69UrrBKKi87qRY3wK5Q53mM6ijTz5MOLWLZhK2Ftz0Elw 0N5/KAxdhfqQHhjr0F1BwEy72gC1p5JkKpLbr+F/i0+5pNicACDt9VJlmqk4nvoQL2bV ly4w== 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=AwPzUZ/Z6+s02+eLaJ3LQ0RcvLB4vo4D1x3Qrf158Cc=; fh=jcKAuV9sx5P88dpWYyXihS1UO5TLmUGd/2Iq3QREE4o=; b=ne+bnAZz6Skwu5mTn2VnytLstnkl1n3PBinn0NUImDeGt8vw659Pqf7qbbBIbbwsjm qccQ44RpsjW9DaCIQicE8WhXe6sisIftmUwAsReYjzpm6JCo4uBgArsZ0QMrsK4k/gwb 3VPBckGwMUYzf6H90rZugSK+hra6oMaHCRYJGyludvYHpy6TJu9Ya++alKOl3Gm7ZDAg 39neuFSuSUCN4sL+EY4DbrGNuvzgLRvkJE9bl8vAiVbg5jBHxfb+6SQUljq51tm0/WUe 3CJT6D/Kov/8yt3dyg7HonLRD7TsHCsvGftp+mZ4nzZILmYWguMQRbYIu3UCsVufgYYO +Nlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=0+ep+zWi; 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 y6-20020a17090aa40600b002768052ba42si1087845pjp.12.2023.09.18.11.51.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 11:51:09 -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=0+ep+zWi; 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 2F2308148B95; Mon, 18 Sep 2023 08:44:26 -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 S229685AbjIRPoM (ORCPT + 25 others); Mon, 18 Sep 2023 11:44:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229636AbjIRPoF (ORCPT ); Mon, 18 Sep 2023 11:44:05 -0400 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE5D2E52; Mon, 18 Sep 2023 08:41:14 -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=AwPzUZ/Z6+s02+eLaJ3LQ0RcvLB4vo4D1x3Qrf158Cc=; b=0+ep+zWiORzxA56Tnase0hTPvo P9/UCv0B6Gl+U68MFx4BK7WhNvNwjHWqaIjvdSUDswILcFS1oN6Q51zqaY5VA8dgk9wGOuc758odz TRfOuFr54FSmrJQnsrtvkdOT/C5zMgH9dpZYBvMGdTM6+wbef3h8YJZ3H99ZeBEvVta0=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qiFSh-0003UE-Ce; Mon, 18 Sep 2023 14:42:55 +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 1qiFRM-0006IJ-Ho; Mon, 18 Sep 2023 14:41:32 +0000 From: Paul Durrant To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Paul Durrant , David Woodhouse , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , David Woodhouse , x86@kernel.org Subject: [PATCH v3 13/13] KVM: xen: advertize the KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA capability Date: Mon, 18 Sep 2023 14:41:11 +0000 Message-Id: <20230918144111.641369-14-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230918144111.641369-1-paul@xen.org> References: <20230918144111.641369-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, 18 Sep 2023 08:44:26 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777402452312286417 X-GMAIL-MSGID: 1777402452312286417 From: Paul Durrant Now that all relevant kernel changes and selftests are in place, enable the new capability. Signed-off-by: Paul Durrant Reviewed-by: 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: David Woodhouse Cc: x86@kernel.org v2: - New in this version. --- arch/x86/kvm/x86.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 2d7d0ae18820..4cd577d01bc4 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4527,7 +4527,8 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) KVM_XEN_HVM_CONFIG_INTERCEPT_HCALL | KVM_XEN_HVM_CONFIG_SHARED_INFO | KVM_XEN_HVM_CONFIG_EVTCHN_2LEVEL | - KVM_XEN_HVM_CONFIG_EVTCHN_SEND; + KVM_XEN_HVM_CONFIG_EVTCHN_SEND | + KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA; if (sched_info_on()) r |= KVM_XEN_HVM_CONFIG_RUNSTATE | KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG;