From patchwork Mon Oct 2 09:57:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 147553 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1732830vqb; Mon, 2 Oct 2023 15:45:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGyQU8EVvIpT/dLtQ/+MAJ7lUCzkdmTNzesNUrs6oyaHQnNx3MV/KCTYNhrgbzETykfwjlz X-Received: by 2002:a17:902:d4c3:b0:1c5:c23c:a9ff with SMTP id o3-20020a170902d4c300b001c5c23ca9ffmr13608351plg.58.1696286709113; Mon, 02 Oct 2023 15:45:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696286709; cv=none; d=google.com; s=arc-20160816; b=rwBsitNGtfFZJYxcmB3+zBz6ouYVsoO+USCRdGBj+VsYICC5JFKOhAZEuE34m9Ryci sTdNtDoSIh0knzfbLwEoc7retSm0KUZu2I0oAeyeW+errHKNrZRUhhRZwOu4ur9JzneO NsAiqtRYygyz1PsnXJpWBluVPLG3Oa2t2zMtabKIV0J5z5MJX62iLppptEkWenpHkCtM iQJeZqyVc1OLrGn6IyoOjzuu0QyscMsmFvXRucfoli6vXoNeqhwaTluWkz3SxdnBlMB9 rZtpFWfYKU/7rKoqIvr+/2NnKLLKrzrQkNok6X4Bs+hqoj/VYUMnkMY6z8iD9zDQCfzt PKXQ== 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=cQ02ZWi3OXJZ36oKzuEnX4ff/ZDsG5TQqSf2+fKM4a0=; fh=eFj9v25W9Wrh6fN+JLpeVaL0rwE8+rsOVorNY/OMc1Y=; b=WJciHPrhcIVv51wMFsV6K+8xVgnOj6IlAaP0qWhlltiK6Z8g9elio4DWgSKtCcdiRY LBtPs6QN/WCudcC3GfZWUMsVqBVq6BIs0e2/EmvCHSc/G4igrwEiSx9Ss1rCDBHw9zFT Pvy1pyhY4r68u54LmfutjrZplPj4dYA3lhULvFa5lJTZgDf+rVJzt8cwR4NFaaA+SaWz x9cZKXyO1yafgohAJBVz0voFvk8mAVN3y6pHRZ8BzQN9jxwilE9uJZPdZ9epIbJ4BqYt 8IFWII4Hed+Y78BrGr0jjHpuX5clJjhF3ivgCJ67EJbJkaG3P9B3QCHxsAyTOpx/IQSL u4CQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=HktkN30a; 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 b11-20020a170902d50b00b001b811261289si30826908plg.482.2023.10.02.15.45.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 15:45: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=HktkN30a; 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 0D94F80963B4; Mon, 2 Oct 2023 02:58:15 -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 S236306AbjJBJ57 (ORCPT + 16 others); Mon, 2 Oct 2023 05:57:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236298AbjJBJ55 (ORCPT ); Mon, 2 Oct 2023 05:57:57 -0400 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06A74B0; Mon, 2 Oct 2023 02:57:53 -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=cQ02ZWi3OXJZ36oKzuEnX4ff/ZDsG5TQqSf2+fKM4a0=; b=HktkN30axQojx0wotuTnOunyDm Y1xDKecGGk/+oX9k0SJo22r+q4XAISbQl2Bp/rjKt385sqQtXE5apQbl7D57aD+dxIjO9PRnSjNCL v+IIvQlm1V7YsZzU0g4OAGXnbC1l9/ZYT/quiL8Af1UUuEeuGuV2Rj+VmYFNqz7q7v5A=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qnFgT-0000v6-O5; Mon, 02 Oct 2023 09:57:49 +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 1qnFgT-0000Ft-GD; Mon, 02 Oct 2023 09:57:49 +0000 From: Paul Durrant To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Paul Durrant , David Woodhouse , Sean Christopherson , David Woodhouse , Paolo Bonzini Subject: [PATCH v7 01/11] KVM: pfncache: add a map helper function Date: Mon, 2 Oct 2023 09:57:30 +0000 Message-Id: <20231002095740.1472907-2-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231002095740.1472907-1-paul@xen.org> References: <20231002095740.1472907-1-paul@xen.org> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 02 Oct 2023 02:58:15 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778685532222017581 X-GMAIL-MSGID: 1778685532222017581 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: Sean Christopherson 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 Oct 2 09:57:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 147228 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1316149vqb; Mon, 2 Oct 2023 03:04:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHADf9BfgNvCjTsqVEPv3RvzGTbt5JxCx3QmulQ2M8SU6qzLdclqQvRWszekcdlMUwnftlq X-Received: by 2002:a05:6870:14c6:b0:1bb:83e9:6277 with SMTP id l6-20020a05687014c600b001bb83e96277mr3872047oab.33.1696241094180; Mon, 02 Oct 2023 03:04:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696241094; cv=none; d=google.com; s=arc-20160816; b=lNo3kQcUrq38F3r7E8BJ5pFumHObqOP5fMrlcGicSkd1xZjgcaLpBmbnS48dm9QxXN ZgVV9KlQa/0lFVmpgPo523vy67swMdahNXRNbr33KyS652GoZtUObRA/FMpfdJBcVZr7 imweTlvIsgkYYm1jzcjVW/BJviHHsoGOFzilpUBZWrELMqH7ML/HfI1J8/5KZEzT31AE rzSxESYtUYWy/j/22TQrmHb5lrs2Ycr7LXLrR30GjoBvJ4+lhFNXAzNBqeQFj9CmOtPg Bc9sOFmBFTlhvJjvS95Zh2Ub7MhdOL/sB4CVqfLdFBnzrXT0uVp77fbqs5wNPVyuohiy p7pA== 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=Td5ruHo6Q2QX376Io/aSuBJ2RV4JnjFu8kAGXdrnyqU=; fh=8AvbwpPKF0Qe5WwS5eyABOVDUChKGxIrkPaOnjrOqKo=; b=ufYRf5VlBJCw1134UCxH5+/fIF/Svxlp6OwyLvLSxhTVZNZIlsXuutbj9/tbJcT9d3 unF20iOwj46iMld0ViYOJI6tARu9+YncY3G3TGgHCqXb+LIx/VdVidY6u8ubdcjkBFPq xzsyjX3o1joOKsKwY2Sp8i8YTA3DRMGC+0sZOgESsWqB/hDSatNAtBclq/NONPd07Urm SHmpc5DaopHeS0semiKybOsYV4p2Nq8cxyV4oVJInkpu7XsHtfJf4peD62B1BE4i/DY5 Y6gZ/bsYV0OUOlp7Zy/WCuq6X86Dd6DNt4ALj4Ovi0dnmbkcEN5rg3Cxll4ojMyd6Sms 06/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=rFPIpTf0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id l62-20020a633e41000000b00569362d6cebsi27190567pga.2.2023.10.02.03.04.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 03:04:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=rFPIpTf0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 F2419801D5AD; Mon, 2 Oct 2023 02:58:27 -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 S236361AbjJBJ6H (ORCPT + 16 others); Mon, 2 Oct 2023 05:58:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236318AbjJBJ57 (ORCPT ); Mon, 2 Oct 2023 05:57:59 -0400 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F376A7; Mon, 2 Oct 2023 02:57:56 -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=Td5ruHo6Q2QX376Io/aSuBJ2RV4JnjFu8kAGXdrnyqU=; b=rFPIpTf0P8/DtHlYZG6sxNYKwn WbvSCwFqUvWqKhTGNdM7dkDl69RhaY7o/MuNKDz3QB98uyMyzcS1J4bBOeocj1w5n15WK+nGXKByM imf0Y1b9W4dQFKVyBzcPJBZ/C/uANbaWyAqjAM8n5L+DezOZp8g+84txl7CXe91QQOwg=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qnFgV-0000vB-Jw; Mon, 02 Oct 2023 09:57:51 +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 1qnFgV-0000Ft-5q; Mon, 02 Oct 2023 09:57:51 +0000 From: Paul Durrant To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Paul Durrant , David Woodhouse , David Woodhouse , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , x86@kernel.org Subject: [PATCH v7 02/11] KVM: pfncache: add a mark-dirty helper Date: Mon, 2 Oct 2023 09:57:31 +0000 Message-Id: <20231002095740.1472907-3-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231002095740.1472907-1-paul@xen.org> References: <20231002095740.1472907-1-paul@xen.org> MIME-Version: 1.0 X-Spam-Status: No, score=-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, 02 Oct 2023 02:58:28 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778637701203270075 X-GMAIL-MSGID: 1778637701203270075 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 9f18b06bbda6..eee252a0afef 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 Oct 2 09:57:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 147369 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1545639vqb; Mon, 2 Oct 2023 09:33:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHGDhP8ZmWCO5ZkwFJLO2baylsm5IhMNNZyGG8ewlvj8Pk+/MN6IiAawlNLamOH5uc4AtVM X-Received: by 2002:a17:902:a415:b0:1c5:de06:9e5a with SMTP id p21-20020a170902a41500b001c5de069e5amr7994906plq.21.1696264431807; Mon, 02 Oct 2023 09:33:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696264431; cv=none; d=google.com; s=arc-20160816; b=fwak7+qIaQulJmr6Y2+kwdSu4zkEDJOmm94wkRxabY7x27kKZSWScrt/RmODJOZIj4 NVrnEdMcZvYBR/vM3zAdhjzj2iDBlrwLyX/DkSGdDJBrFToZ7M4sCLuZINDf4hd2vwlG zFtq4LwOq3Ml0m/jge+eF8RFhHGJU/v79ZIiys3/V7CRy3u9liwtBbPtnuMnqkxNi7Sq O9HPMGCzmi4E7y9wWBiT8lvi4PfLs7blJ+veT/GWoYG/4l+8x8tg5ekMlBh0zYJrCgZ8 83kEhA9DqDFMFEYh1/FsFLfo2sanLLPum8t+mQGfcce1XXVhBoD6LXM1QJ/H21K++ldb 115w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CnnzQ4eiCWT/+IlcdQWASoCfyneq5mdBodDzIdnbsCc=; fh=8AvbwpPKF0Qe5WwS5eyABOVDUChKGxIrkPaOnjrOqKo=; b=SKOlOsICk3BGltL1L01J+GnDeZ0q270MZYrlDrTe7MwX8ZiHQCmLc9CZN48l3qOW1d 0XltSSGBzHE3pIABYUqpI0uwJ3RGsocKy75BWwU0QaryCQ97/18W48sUuSMYdenL97SB zNJ5wYxcxN1p1A1sMictj/zqFkIHj8zFvWDB3P+IW+aJvrrKosNZetD0iSRCuAaHb/jC PHtMzzV7TRVA+jq2ZhWQ3CxrsH6hoYWnUrVmhZdItn2fksmhPz5EFzYhMeGHZyuwDGNe AyARre6Bl9KTi0TUYf78oFYYg5rbnNqvm9RfzaZ0afp3qHIpDFeg44FFVHRinLxXxMP4 sdMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=puvNm2c5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id n8-20020a170902e54800b001bb8e3f3475si8170775plf.52.2023.10.02.09.33.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 09:33:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=puvNm2c5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id ED1B08057DB0; Mon, 2 Oct 2023 02:58:40 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236372AbjJBJ6L (ORCPT + 16 others); Mon, 2 Oct 2023 05:58:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236322AbjJBJ6A (ORCPT ); Mon, 2 Oct 2023 05:58:00 -0400 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6640C9F; Mon, 2 Oct 2023 02:57:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=CnnzQ4eiCWT/+IlcdQWASoCfyneq5mdBodDzIdnbsCc=; b=puvNm2c5vTtUnF/V0zEuIrdkDq kpmpkXdA3q/tWqwCPhvbJPTzxsQgit1dBY8IhppsfEyhO5YZrh1Yw4XXeNYYeyD3ptUC1vhCoFOWF h97rv37pAscg+GE+4QCAdgZPZUpL37Hn7pXSnKyIhq8GoSRnuDgn+Vf8VIgW/mNcu8w0=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qnFgX-0000vJ-3Q; Mon, 02 Oct 2023 09:57:53 +0000 Received: from ec2-63-33-11-17.eu-west-1.compute.amazonaws.com ([63.33.11.17] helo=REM-PW02S00X.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qnFgW-0000Ft-Rm; Mon, 02 Oct 2023 09:57:53 +0000 From: Paul Durrant To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Paul Durrant , David Woodhouse , David Woodhouse , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , x86@kernel.org Subject: [PATCH v7 03/11] KVM: pfncache: add a helper to get the gpa Date: Mon, 2 Oct 2023 09:57:32 +0000 Message-Id: <20231002095740.1472907-4-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231002095740.1472907-1-paul@xen.org> References: <20231002095740.1472907-1-paul@xen.org> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 02 Oct 2023 02:58:41 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778662172866309097 X-GMAIL-MSGID: 1778662172866309097 From: Paul Durrant A subsequent patch will rename this field since it will become overloaded. To avoid churn in places that currently retrieve the gpa, add a helper for that purpose now. No functional change intended. Signed-off-by: Paul Durrant Reviewed-by: David Woodhouse --- Cc: David Woodhouse Cc: Sean Christopherson Cc: Paolo Bonzini Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: x86@kernel.org --- arch/x86/kvm/xen.c | 15 ++++++++------- include/linux/kvm_host.h | 7 +++++++ virt/kvm/pfncache.c | 6 ++++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c index 33fddd29824b..8e6fdcd7bb6e 100644 --- a/arch/x86/kvm/xen.c +++ b/arch/x86/kvm/xen.c @@ -261,8 +261,8 @@ static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic) * alignment (and the 32-bit ABI doesn't align the 64-bit integers * anyway, even if the overall struct had been 64-bit aligned). */ - if ((gpc1->gpa & ~PAGE_MASK) + user_len >= PAGE_SIZE) { - user_len1 = PAGE_SIZE - (gpc1->gpa & ~PAGE_MASK); + if ((kvm_gpc_gpa(gpc1) & ~PAGE_MASK) + user_len >= PAGE_SIZE) { + user_len1 = PAGE_SIZE - (kvm_gpc_gpa(gpc1) & ~PAGE_MASK); user_len2 = user_len - user_len1; } else { user_len1 = user_len; @@ -343,7 +343,7 @@ static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic) * to the second page now because the guest changed to * 64-bit mode, the second GPC won't have been set up. */ - if (kvm_gpc_activate(gpc2, gpc1->gpa + user_len1, + if (kvm_gpc_activate(gpc2, kvm_gpc_gpa(gpc1) + user_len1, user_len2)) return; @@ -677,7 +677,8 @@ int kvm_xen_hvm_get_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data) case KVM_XEN_ATTR_TYPE_SHARED_INFO: if (kvm->arch.xen.shinfo_cache.active) - data->u.shared_info.gfn = gpa_to_gfn(kvm->arch.xen.shinfo_cache.gpa); + data->u.shared_info.gfn = + gpa_to_gfn(kvm_gpc_gpa(&kvm->arch.xen.shinfo_cache)); else data->u.shared_info.gfn = KVM_XEN_INVALID_GFN; r = 0; @@ -955,7 +956,7 @@ int kvm_xen_vcpu_get_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data) switch (data->type) { case KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO: if (vcpu->arch.xen.vcpu_info_cache.active) - data->u.gpa = vcpu->arch.xen.vcpu_info_cache.gpa; + data->u.gpa = kvm_gpc_gpa(&vcpu->arch.xen.vcpu_info_cache); else data->u.gpa = KVM_XEN_INVALID_GPA; r = 0; @@ -963,7 +964,7 @@ int kvm_xen_vcpu_get_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data) case KVM_XEN_VCPU_ATTR_TYPE_VCPU_TIME_INFO: if (vcpu->arch.xen.vcpu_time_info_cache.active) - data->u.gpa = vcpu->arch.xen.vcpu_time_info_cache.gpa; + data->u.gpa = kvm_gpc_gpa(&vcpu->arch.xen.vcpu_time_info_cache); else data->u.gpa = KVM_XEN_INVALID_GPA; r = 0; @@ -975,7 +976,7 @@ int kvm_xen_vcpu_get_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data) break; } if (vcpu->arch.xen.runstate_cache.active) { - data->u.gpa = vcpu->arch.xen.runstate_cache.gpa; + data->u.gpa = kvm_gpc_gpa(&vcpu->arch.xen.runstate_cache); r = 0; } break; diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index c71e8fbccaaf..4d8027fe9928 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1374,6 +1374,13 @@ void kvm_gpc_deactivate(struct gfn_to_pfn_cache *gpc); */ void kvm_gpc_mark_dirty(struct gfn_to_pfn_cache *gpc); +/** + * kvm_gpc_gpa - retrieve the guest physical address of a cached mapping + * + * @gpc: struct gfn_to_pfn_cache object. + */ +gpa_t kvm_gpc_gpa(struct gfn_to_pfn_cache *gpc); + void kvm_sigset_activate(struct kvm_vcpu *vcpu); void kvm_sigset_deactivate(struct kvm_vcpu *vcpu); diff --git a/virt/kvm/pfncache.c b/virt/kvm/pfncache.c index b68ed7fa56a2..17afbb464a70 100644 --- a/virt/kvm/pfncache.c +++ b/virt/kvm/pfncache.c @@ -386,6 +386,12 @@ int kvm_gpc_activate(struct gfn_to_pfn_cache *gpc, gpa_t gpa, unsigned long len) } EXPORT_SYMBOL_GPL(kvm_gpc_activate); +gpa_t kvm_gpc_gpa(struct gfn_to_pfn_cache *gpc) +{ + return gpc->gpa; +} +EXPORT_SYMBOL_GPL(kvm_gpc_gpa); + void kvm_gpc_mark_dirty(struct gfn_to_pfn_cache *gpc) { mark_page_dirty_in_slot(gpc->kvm, gpc->memslot, gpc->gpa >> PAGE_SHIFT); From patchwork Mon Oct 2 09:57:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 147282 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1407150vqb; Mon, 2 Oct 2023 06:00:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEkJFKcEEIBdevjV77GhWGpcbClxFU/XC0fU2vxtoDvWEJMSqF+J6l7M+9Ir/qqzEUixjEH X-Received: by 2002:a05:6a00:3a1e:b0:68e:417c:ed5c with SMTP id fj30-20020a056a003a1e00b0068e417ced5cmr10896980pfb.32.1696251656421; Mon, 02 Oct 2023 06:00:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696251656; cv=none; d=google.com; s=arc-20160816; b=T974KMZPuBUgxql+ipYxpya5webkjM5viqWgD+xjBLp19DueaWaA5a0AFnAI4BjPzi D+Zo6hSiy9HOlPU+aUVy6cQNxi5MxrWFQfHraXAXHrHKu2v6z5GpiflisvuHWQJp0cwm F1Hau6C7H20Svg08W+4So+hW8H7vc/ndUac4JA3a7TNySmT3u/T1ob6SsX7DYCWoW/4M 6mJ5LmZP2qoSHzZUReRRFZT1IAtRtLbtcuLIRol/I1L78093O/sfDBQkHbhKwyRPsqyJ eljVQa0K0HF52H/LYqtfvl6cr6pF30bPDu5HsvoElHcmdH2mTr78D9NSOtzzl8VEk3nG llQw== 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=e3Vz0tH7MeijOYhCrJMXMH52NUfYnF7z8/TCVVMfMcA=; fh=eFj9v25W9Wrh6fN+JLpeVaL0rwE8+rsOVorNY/OMc1Y=; b=Ko4ngKvNbTqSg9TSe30KlyArz5x4xF4+CrI3i7Cd02jtE+0sCwqrJD4+/7xSMvMo+f ds+Inj/1hWKJ5fzJqosm4EP0LPgjbU9Dor5bZnoo3P0M7eXSv1jr+waSsL33IScS+u7t NlQMV+6AALiKOU61D3SQCfBnro1NcVq/EKTCuLKcmRQhBRcQdrwy/cOoeywAUjdA8zPG t+rIVkKaZZdPdXE6wRbUTFBALhKdoyyBWirN9nJJluL9pTt8y80W24Jmu3r9gLncn7Ge 8VXS7LjCmVf5QTbFVnFjXw36RvcW/o28FsTL7uFz7BGU91tHDlXVOwFcpXjClAlxPZ2u wnxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=UhrWedc2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id t23-20020a056a00139700b0069058764684si29686049pfg.367.2023.10.02.06.00.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 06:00:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=UhrWedc2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 16534809B755; Mon, 2 Oct 2023 02:58:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236350AbjJBJ6F (ORCPT + 16 others); Mon, 2 Oct 2023 05:58:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236307AbjJBJ56 (ORCPT ); Mon, 2 Oct 2023 05:57:58 -0400 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF4FC8E; Mon, 2 Oct 2023 02:57: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:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=e3Vz0tH7MeijOYhCrJMXMH52NUfYnF7z8/TCVVMfMcA=; b=UhrWedc2ETd6hv21kAS/H9HsLA g2p7N0GoSaVmF2VoZcVu0DN0fCKq+NB4bfZUKOaDqVnv/KZJCYGYr0+f5/UuQVwR2BmgO9oLpPwgI VEpVB8ldkn0GPnT1ROnEXA0ty2Dj0WjlrGoA9VPPJPr6CW2T+h4Ul9zOPlFVAZjPkHqA=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qnFgY-0000vN-5s; Mon, 02 Oct 2023 09:57:54 +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 1qnFgX-0000Ft-Ub; Mon, 02 Oct 2023 09:57:54 +0000 From: Paul Durrant To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Paul Durrant , David Woodhouse , Sean Christopherson , David Woodhouse , Paolo Bonzini Subject: [PATCH v7 04/11] KVM: pfncache: base offset check on khva rather than gpa Date: Mon, 2 Oct 2023 09:57:33 +0000 Message-Id: <20231002095740.1472907-5-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231002095740.1472907-1-paul@xen.org> References: <20231002095740.1472907-1-paul@xen.org> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.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 (groat.vger.email [0.0.0.0]); Mon, 02 Oct 2023 02:58:47 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778648776664353189 X-GMAIL-MSGID: 1778648776664353189 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: Sean Christopherson 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 Oct 2 09:57:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 147274 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1395815vqb; Mon, 2 Oct 2023 05:38:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH1jWXd6R4ZL110EvQTlZjlyA93b8rYepfq5dB1L4vXnf0o1Ek69H2ESHNLcN7OkG3NkVTH X-Received: by 2002:a05:6a20:1049:b0:154:b1f7:b396 with SMTP id gt9-20020a056a20104900b00154b1f7b396mr11080944pzc.35.1696250324758; Mon, 02 Oct 2023 05:38:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696250324; cv=none; d=google.com; s=arc-20160816; b=t1IXD/1oFJTZw29bV1S8iV0Bj7sBbmrJwqkKLCPX8gail9Bejp40nL1PRw6vLPa3eb F6IpZ/cu8yOrqvf0GVWe0OPaDnu91sKldCnrm/amHZfLADyNM2061RyrbSn5ibawdQd7 oEHZijSK/0TAcW4iwS0sg57cEU9C5E+9li2XgGKbCo/LQvvV3Yf2Mj9sGO+stB/+Jmop bD3gzWUverZa7qJ12hu2o2M5niF4fRi1stNrbNSy7YXLaVGWAagf7mtZU58rDT6qAy8w Cn1ZrbX+OdgsZz7Q4bbbJVUEkhbU1LNcCbTtQulbw1T8EvbhjELYlJXfoPYdAdbDzzV+ Mtrg== 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=uR3RY44FOYUdZ/yYeXcGIkRXrRmwuyl6HvHad0MhhqE=; fh=lKhNn3P8ZvksS1fElybz1iP8zlw6JVVQ9gjuN2JwMdc=; b=cKHO10A2d+FtnEduM7XA7tmd3vOADcrK8pzvE+VBRkR7VOwRmzkw9SaCbtrF4NU9EX sqUWYi2jkBHRm6mk89UqE1GCRzXyka/K0So8aJ3ylKxvNlrmxRcLYaIDmMFPbj09hzqG 5yl6i0ZiNuwaX2YbKe76M8Jew0bGBL7yZk13XYOcg5LmBZGqIhrnLBeFSfvI5v1E5Asb 0FgH5UyGj3IaQr9B5VR4n1wgFwTClO5Icp6S9j5iH3jR3wmj/H8O1Tl6OY5mYjpxk3oh 2pzS/NgZrQ9HBw5O27A/uuIkh2JxSdV6rR60QxIS5aouoFFyMS4ah2yV0GstJgK/RzCc uTGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=I8fSrgKU; 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 lb14-20020a170902fa4e00b001b837f239c4si24564848plb.651.2023.10.02.05.38.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 05:38:44 -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=I8fSrgKU; 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 C4895803FC3E; Mon, 2 Oct 2023 02:58:50 -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 S236367AbjJBJ6J (ORCPT + 16 others); Mon, 2 Oct 2023 05:58:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236215AbjJBJ57 (ORCPT ); Mon, 2 Oct 2023 05:57:59 -0400 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F47AAC; Mon, 2 Oct 2023 02:57:56 -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=uR3RY44FOYUdZ/yYeXcGIkRXrRmwuyl6HvHad0MhhqE=; b=I8fSrgKUJUgNKT1JDty86GwFZx E0QmJjjNx0v7i8AIeny6oS6uYfzW0bzWex2+WG2shcK4XifpYfxQB4nC1IkpgdR0dHfKlC5ZTT63k v2yJroihDfWG6B/hre34RROPncvLKU7HdKZYh+BLA1AL9pqc4HF5HwciTFx/h6eHVBDY=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qnFgZ-0000va-8g; Mon, 02 Oct 2023 09:57: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 1qnFgZ-0000Ft-1A; Mon, 02 Oct 2023 09:57:55 +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 v7 05/11] KVM: pfncache: allow a cache to be activated with a fixed (userspace) HVA Date: Mon, 2 Oct 2023 09:57:34 +0000 Message-Id: <20231002095740.1472907-6-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231002095740.1472907-1-paul@xen.org> References: <20231002095740.1472907-1-paul@xen.org> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on 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, 02 Oct 2023 02:58:50 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778647380584561624 X-GMAIL-MSGID: 1778647380584561624 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 Reviewed-by: David Woodhouse --- Cc: Sean Christopherson 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 Oct 2 09:57:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 147290 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1419833vqb; Mon, 2 Oct 2023 06:17:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFjvJM5mCTjp/255n8i6Q33jCuZRgkWSFzvgOjzqpUhRNeFHD4FEBgNbiOM2EpCGke+bw2k X-Received: by 2002:a17:90a:ab91:b0:279:11db:2fe1 with SMTP id n17-20020a17090aab9100b0027911db2fe1mr9416559pjq.31.1696252631039; Mon, 02 Oct 2023 06:17:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696252631; cv=none; d=google.com; s=arc-20160816; b=z2xD9iGdlsBcp/+p5Clt/2Q3VGlrmx+PuCaQVLZhHCJYt2m8cf4mE9mPRVECTlXDiS GV9HhPQa85Px/O+oib66OEq5TXNUVa3+6DitWf4btmjpFMxqJ6Tj9HtThcgGMvZmAtzh lkoELTDYjCNG80V/JJAN+cW24Me6n678kYlJqH6N2dIOEDYuQk3P1DMgNQtE3JInKrne uUFsp7xRq1w/zxxCCogDUWg/5lgCqTCnRCaCpzO7g4L9zk7hL+wezojFcuMmsf0qtCp4 wo/ZKVhJopHYpYFJa10PYVCW6//+Zsao8Ca8slDbDXuMi+11/jG2Za3LDd4mw0M5Gq8j cO3g== 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=FyKaHX+JLdlnkDcImruy5k7un3y8dcMPSUgfSfvX1FY=; fh=8AvbwpPKF0Qe5WwS5eyABOVDUChKGxIrkPaOnjrOqKo=; b=qEUCLwYkQFpdAO+UcoiGYFx0sILcwLle1gScCIzVPx/++Hj2x9kljn7lIszicejqjL jPL2J8XBBheUoa01EPInCafNF3oJULDODEc2OlypgJ4fGMKU6rnn2a2IFiNgHmU07o3n r2XuZuLWv36lc0h89w3BkZ/PdzEJX9ax5RVLEqz/VEuctN7DPkuNOfGhCHq1hzVH/jDq QxkY970d9gS2ZE6OuXasM8QMIYxzIRd9TTXl4AXkxFOBtHYqfLSAFdU6GbvEwNVDCUbY SaA2R4MIZDFyEPqkLxmFgAOlU7O0LvXz7Yvsjq0Qw5olOhirGtG3YirXkYh5QlxBKue9 Xw1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b="wdUO3/h6"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id fw20-20020a17090b129400b002683f507990si7382394pjb.109.2023.10.02.06.17.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 06:17:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b="wdUO3/h6"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 554A88072150; Mon, 2 Oct 2023 02:58:37 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236378AbjJBJ6M (ORCPT + 16 others); Mon, 2 Oct 2023 05:58:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236338AbjJBJ6C (ORCPT ); Mon, 2 Oct 2023 05:58:02 -0400 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4E16A7; Mon, 2 Oct 2023 02:57: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:Content-Type:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=FyKaHX+JLdlnkDcImruy5k7un3y8dcMPSUgfSfvX1FY=; b=wdUO3/h6pN0+er/XEfAKqlZCFw gPgH3UTzP/CBOC9kYudsF85fJzNhCqS0naZqOdbtANyhiaml8oa1IJMfMLPzOiDR/jWaR3kQ4JdeY H+DXGRhVI6qwVStGMi5JPk6OmPzaDexvC08veA+k+UNZnH66/ihV7SAE6Z9yGfheaP04=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qnFga-0000vq-Uo; Mon, 02 Oct 2023 09:57:56 +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 1qnFga-0000Ft-N1; Mon, 02 Oct 2023 09:57:56 +0000 From: Paul Durrant To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Paul Durrant , David Woodhouse , David Woodhouse , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , x86@kernel.org Subject: [PATCH v7 06/11] KVM: xen: allow shared_info to be mapped by fixed HVA Date: Mon, 2 Oct 2023 09:57:35 +0000 Message-Id: <20231002095740.1472907-7-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231002095740.1472907-1-paul@xen.org> References: <20231002095740.1472907-1-paul@xen.org> MIME-Version: 1.0 X-Spam-Status: No, score=-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 (snail.vger.email [0.0.0.0]); Mon, 02 Oct 2023 02:58:37 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778649798402708346 X-GMAIL-MSGID: 1778649798402708346 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 and specified in the XENMEM_add_to_physmap hypercall. The guest may even request that shared_info be moved from one GFN to another by re-issuing that hypercall, but the HVA is never going to change. Because the shared_info page is an overlay we need to update the memory slots in response to the hypercall. However, memory slot adjustment is not atomic and, whilst all vCPUs are paused, there is still the possibility that events may be delivered (which requires the shared_info page to be updated) whilst the shared_info GPA is absent. The HVA is never absent though, so it makes much more sense to use that as the basis for the kernel's mapping. 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 Oct 2 09:57:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 147412 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1604213vqb; Mon, 2 Oct 2023 11:11:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGzVmjjYgZbrtoYYrNlQqGaCQ9Jc9JKI49NkPbX46rXIl9FXguYHFjyC2C+rWE+mEtYHSEi X-Received: by 2002:a17:903:2452:b0:1c5:9c73:c91c with SMTP id l18-20020a170903245200b001c59c73c91cmr13917212pls.48.1696270274064; Mon, 02 Oct 2023 11:11:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696270274; cv=none; d=google.com; s=arc-20160816; b=O86ZAM/fvxZdJ/VvVt1nqiWIdv2OPjk1x3pkpF159dpRs51ueVmjwdquQXkY3nvCJc 6sfRBgEljvBmYngzoTsXptzNna5b1o/JPMhfnBPMl/RSTOCBxsT1tZZxfAuF9fMjUtim McdnN70sgooGkz04GCM5gvkxcmvo7QiYyq7g/tUDYZJOTWrEFvbRijL1kFpywGFnrjSI cA2NXU9gHOlsF6qtWoJ4T8/K/SulPvCRuROO7vdn621n/TDf1WrdnXWSR5wEr6RHGfsq RRX4kW4wGkRhoH8B9dqXzMlrqMkGnUVZW9YTb4+ANQO1mLV74W/p7XOrcc7X7W73sFKR JcWQ== 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=l33abFY8+LeWK4/A7cj6ffiqEBnVQtpFfXFd8rLMTOU=; fh=8AvbwpPKF0Qe5WwS5eyABOVDUChKGxIrkPaOnjrOqKo=; b=vvLyj5OiclPkFpd/hDPG1s0yqsRabBFyW5vqUg3eBct2OpkIDyGfcfW+/vVnDrP6u4 E/7lrnyL/AyHPi675fWb0T2m5wORd4bWNQtCXDnwkgtYO9x+Eihht9mvFGkWnn//BVGR YASj9C+ayIdmk+Zd3wP375VKJI9BAns+k14yIs2zHR5yKEv3e+E6w+HJw9hjiS2Mo85/ 8KBwoldxQ+BTlBb4QMtBwLMJmuExrKap3Gkjj2nGXxEchLugXCRPjTKMYNJaZKEi+V4C IOIp8bjHlwjhEfzzN+czsqw0NvtERLLkrXP/N8C+tHJyKdakW47HfRiZwuPXosSXyQmT wOvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=svGh5KUK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id kg5-20020a170903060500b001b973681493si24995339plb.16.2023.10.02.11.11.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 11:11:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=svGh5KUK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id AF177808E642; Mon, 2 Oct 2023 02:58:42 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236347AbjJBJ6Z (ORCPT + 16 others); Mon, 2 Oct 2023 05:58:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236353AbjJBJ6F (ORCPT ); Mon, 2 Oct 2023 05:58:05 -0400 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44F83B0; Mon, 2 Oct 2023 02:58:01 -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=l33abFY8+LeWK4/A7cj6ffiqEBnVQtpFfXFd8rLMTOU=; b=svGh5KUKZNg7VNJb5eytX3KWMH gE5aBzgV50ZUN3fuFk8xQ0dvcFXpvapKm0plAOYoVu945US7ELX16EdLVl+MmK2PsPvtdJFOnf0pc JLWsIXn2nQScSzuYOUyxHOUJ8XaR8vGmZzQZMntE5pdytgjrJY/kRMHir6d5pjtuvNH8=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qnFgc-0000wa-KE; Mon, 02 Oct 2023 09:57:58 +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 1qnFgc-0000Ft-Cb; Mon, 02 Oct 2023 09:57:58 +0000 From: Paul Durrant To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Paul Durrant , David Woodhouse , David Woodhouse , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , x86@kernel.org Subject: [PATCH v7 07/11] KVM: xen: allow vcpu_info to be mapped by fixed HVA Date: Mon, 2 Oct 2023 09:57:36 +0000 Message-Id: <20231002095740.1472907-8-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231002095740.1472907-1-paul@xen.org> References: <20231002095740.1472907-1-paul@xen.org> MIME-Version: 1.0 X-Spam-Status: No, score=-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 (snail.vger.email [0.0.0.0]); Mon, 02 Oct 2023 02:58:42 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778668298809712314 X-GMAIL-MSGID: 1778668298809712314 From: Paul Durrant If the guest does not explicitly set the GPA of vcpu_info structure in memory then, for guests with 32 vCPUs or fewer, the vcpu_info embedded in the shared_info page may be used. As described in a previous commit, the shared_info page is an overlay at a fixed HVA within the VMM, so in this case it also more optimal to activate the vcpu_info cache with a fixed HVA to avoid unnecessary invalidation if the guest memory layout is modified. 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 v5: - New in this version. --- Documentation/virt/kvm/api.rst | 26 +++++++++++++++++++++----- arch/x86/kvm/xen.c | 33 +++++++++++++++++++++++++++------ include/uapi/linux/kvm.h | 3 +++ 3 files changed, 51 insertions(+), 11 deletions(-) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index e9df4df6fe48..5adc6dfc8c6e 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -5444,11 +5444,12 @@ 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. + and instead requires that KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO or + KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO_HVA 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. Note that the shared_info page may be constantly written to by KVM; it contains the event channel bitmap used to deliver interrupts to @@ -5570,6 +5571,21 @@ KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO on dirty logging. Setting the gpa to KVM_XEN_INVALID_GPA will disable the vcpu_info. +KVM_XEN_VCPU_ATTR_TYPE_VCPU_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 of the vcpu_info for a given vCPU. It should + only be used when the vcpu_info resides at the "default" location + in the shared_info page. In this case it is safe to assume the + userspace address will not change, because the shared_info page is + an overlay on guest memory and remains at a fixed host address + regardless of where it is mapped in guest physical address space + and hence unnecessary invalidation of an internal cache may be + avoided if the guest memory layout is modified. + If the vcpu_info does not reside at the "default" location then + it is not guaranteed to remain at the same host address and + hence the aforementioned cache invalidation is required. + 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 1abb4547642a..aafc794940e4 100644 --- a/arch/x86/kvm/xen.c +++ b/arch/x86/kvm/xen.c @@ -736,20 +736,33 @@ int kvm_xen_vcpu_set_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data) switch (data->type) { case KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO: + case KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO_HVA: /* No compat necessary here. */ BUILD_BUG_ON(sizeof(struct vcpu_info) != sizeof(struct compat_vcpu_info)); BUILD_BUG_ON(offsetof(struct vcpu_info, time) != offsetof(struct compat_vcpu_info, time)); - if (data->u.gpa == KVM_XEN_INVALID_GPA) { - kvm_gpc_deactivate(&vcpu->arch.xen.vcpu_info_cache); - r = 0; - break; + if (data->type == KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO) { + if (data->u.gpa == KVM_XEN_INVALID_GPA) { + kvm_gpc_deactivate(&vcpu->arch.xen.vcpu_info_cache); + r = 0; + break; + } + + r = kvm_gpc_activate(&vcpu->arch.xen.vcpu_info_cache, + data->u.gpa, sizeof(struct vcpu_info)); + } else { + if (data->u.hva == 0) { + kvm_gpc_deactivate(&vcpu->arch.xen.vcpu_info_cache); + r = 0; + break; + } + + r = kvm_gpc_activate_hva(&vcpu->arch.xen.vcpu_info_cache, + data->u.hva, sizeof(struct vcpu_info)); } - r = kvm_gpc_activate(&vcpu->arch.xen.vcpu_info_cache, - data->u.gpa, sizeof(struct vcpu_info)); if (!r) kvm_make_request(KVM_REQ_CLOCK_UPDATE, vcpu); @@ -978,6 +991,14 @@ int kvm_xen_vcpu_get_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data) r = 0; break; + case KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO_HVA: + if (vcpu->arch.xen.vcpu_info_cache.active) + data->u.hva = kvm_gpc_hva(&vcpu->arch.xen.vcpu_info_cache); + else + data->u.hva = 0; + r = 0; + break; + case KVM_XEN_VCPU_ATTR_TYPE_VCPU_TIME_INFO: if (vcpu->arch.xen.vcpu_time_info_cache.active) data->u.gpa = kvm_gpc_gpa(&vcpu->arch.xen.vcpu_time_info_cache); diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 062bfa14b4d9..0267c2ef43de 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1858,6 +1858,7 @@ struct kvm_xen_vcpu_attr { union { __u64 gpa; #define KVM_XEN_INVALID_GPA ((__u64)-1) + __u64 hva; __u64 pad[8]; struct { __u64 state; @@ -1888,6 +1889,8 @@ struct kvm_xen_vcpu_attr { #define KVM_XEN_VCPU_ATTR_TYPE_VCPU_ID 0x6 #define KVM_XEN_VCPU_ATTR_TYPE_TIMER 0x7 #define KVM_XEN_VCPU_ATTR_TYPE_UPCALL_VECTOR 0x8 +/* Available with KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA */ +#define KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO_HVA 0x9 /* Secure Encrypted Virtualization command */ enum sev_cmd_id { From patchwork Mon Oct 2 09:57:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 147238 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1350567vqb; Mon, 2 Oct 2023 04:17:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFUGwE+Lh4PCxsrqnCXAldA/9TKy/1D89diYtGpSAJMxfGLpZBbASLRtBRICVTi01zbqk50 X-Received: by 2002:a9d:6d0a:0:b0:6bd:93e:460b with SMTP id o10-20020a9d6d0a000000b006bd093e460bmr11839221otp.19.1696245431314; Mon, 02 Oct 2023 04:17:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696245431; cv=none; d=google.com; s=arc-20160816; b=kgySwD2bH78q30MTQrQ22TOEB1vQOJ+EyDjItUG8+X5JHbADQNR1iXcFrh8anh97VC De2uq9QZvW+4p5UUzJnunIEdKhX1NZpo5WIsmqsq28EDeKV/RLDKUtXiE/JLNLJpTpYf oGx2dHkyAw8H6D7ocBi06W6YZRQlInrFZiwif3zYnwVabQzF2dL20WnOjuSF3Qa1XA8B 8wBWK7PS6OjmZrjfv1yt6Mj2zEmWXlD7hztHehO7jRf47Q/yzwdRx6zLurYMlCiw6QCb WzGQyUMhncTuDyqb1Gg+MsCXD2iuGz6muSGhP2TAwLmCq9SdMBXvto9K9yMrghA50HW5 pZjw== 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=kUR93LtEabvdWOBCjvrvvT9F7wNuAiZe4sASBA03DEM=; fh=lKhNn3P8ZvksS1fElybz1iP8zlw6JVVQ9gjuN2JwMdc=; b=V6KdSqIfAhjgtHIVT4hsNkAd4k3xHz3Wf2iUthR2VOn9E/uM4AgSIXh7RZit+S+dNA NSFqycH/UpRm0am7x6m+oo80P+xBMeitFqiMFLdh8Pn6hAN8eBQJuhJ20s7t2w6VVGZa Xin4arEr+aRlE85QlrEvky/4/myrTXg+o9wz/Dd6gDEvdoOStL9K6ZAHMMA/5hyy8K+Q Q87udABfs3wqlG62hZIfr4rR8ht7tQpvo7S+iacjegxraleoeUofAPJyPlodrR716l61 FeMtWhAqx/3HnY4823Kz6oO64V3Hax0j/4kfp4h+9E/zflxB75T3lsqC+VNIByBsZQKn RyWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=HSr0gBjY; 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 l5-20020a633e05000000b0056546b5fef4si27616680pga.232.2023.10.02.04.17.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 04:17:11 -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=HSr0gBjY; 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 2DB6D8112475; Mon, 2 Oct 2023 02:58:47 -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 S236394AbjJBJ6W (ORCPT + 16 others); Mon, 2 Oct 2023 05:58:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236333AbjJBJ6F (ORCPT ); Mon, 2 Oct 2023 05:58:05 -0400 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6D04BD; Mon, 2 Oct 2023 02:58:01 -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=kUR93LtEabvdWOBCjvrvvT9F7wNuAiZe4sASBA03DEM=; b=HSr0gBjYviTZNCAukOXnyCfe15 AlvKGUNpRUhVlpSm9kyBhsdfi1CPuQJbw6kl86SHo7nTFUWABFnJKyXmhk3YjRTvMCuoDAOSQLSbj /Wity/0sLFBvaz7MpefyWtcYyhApmjItCt02sA4b0opYtbPKbHK7QkVd+CIL1UjJVDSU=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qnFgd-0000wp-Mr; Mon, 02 Oct 2023 09:57:59 +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 1qnFgd-0000Ft-FM; Mon, 02 Oct 2023 09:57:59 +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 v7 08/11] KVM: selftests / xen: map shared_info using HVA rather than GFN Date: Mon, 2 Oct 2023 09:57:37 +0000 Message-Id: <20231002095740.1472907-9-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231002095740.1472907-1-paul@xen.org> References: <20231002095740.1472907-1-paul@xen.org> MIME-Version: 1.0 X-Spam-Status: No, score=-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, 02 Oct 2023 02:58:47 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778642248970800358 X-GMAIL-MSGID: 1778642248970800358 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 05898ad9f4d9..e6672ae1d9de 100644 --- a/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c +++ b/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c @@ -393,6 +393,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; @@ -408,20 +409,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_REGION_GPA / 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; @@ -446,6 +465,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_shinfo_hva = !!(xen_caps & KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA); clock_gettime(CLOCK_REALTIME, &min_ts); @@ -456,7 +476,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"); @@ -492,10 +512,16 @@ int main(int argc, char *argv[]) "Failed to read back RUNSTATE_UPDATE_FLAG attr"); } - struct kvm_xen_hvm_attr ha = { - .type = KVM_XEN_ATTR_TYPE_SHARED_INFO, - .u.shared_info.gfn = SHINFO_REGION_GPA / 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 Oct 2 09:57:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 147411 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1603386vqb; Mon, 2 Oct 2023 11:09:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFaMZclCkPfi7KYFIIhW2BBOmw+qk5xHgNwssinlcg2rZpuCJk5ZW0aqE4TuZ8jhpdqwCFZ X-Received: by 2002:a17:90a:eb03:b0:274:24e2:ae6d with SMTP id j3-20020a17090aeb0300b0027424e2ae6dmr9829107pjz.0.1696270193044; Mon, 02 Oct 2023 11:09:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696270193; cv=none; d=google.com; s=arc-20160816; b=qP3zJZzT6PtHIKV4TIqsOWcBg7WhKYasI9tgRkQQtkPIYeNLsS5+cWzk79Tkinzh62 ykF+PbqgcIp9+2w2b0ofZWOUGgQH8+vBX2fe3XqZSFjB8VOVKYjkgk54fAwSR5qsaRVf NaNoZ4Tb9S0UsqBXUYZCOEx+nRgee0xG49r0YeKNE9Lkxr+nGMSYuAapK7mCeoB3Ajbs hYtwO+flld0T2u15VhcMABd4bVhorQ6DKQq4osUO5adjEjugmCh8+wMSU0pkqBUqhrns FxuiZ5z7/NP0EWZg4o95eoS90vq+TIOkm5y5tg2HHUf3mbSWpHDjMS7DDQttI/Dqq1HD YC8A== 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=GVRP7ZhX9y66fV8la0Z0phq4YOuv61LMjBgGZkw2zl4=; fh=lKhNn3P8ZvksS1fElybz1iP8zlw6JVVQ9gjuN2JwMdc=; b=FcI5e4u/PMh6OqD1yDjiXA/mxFJ9cvtXMFb1dSlwOJrg1Ew6tyqVzGGvh6OO981klr dajrxkzLvU+w7LUfBS+rYLRXRB8sEOj68jKrluYmWW/DXqT7iRIUzgaz0gQX+pj+f64H 3tTV6+N78fcjOP6Ek/MKGrdM7k/meOnW22Q8it/WzI7EQ3Q8xr85bFoJujUGvqXfo1JR Qb9YF+Tj8bH/JsGq+wWfLv78TaLDSeSPIGhQF1CcCI06PW0OHGw8JmKR2Igau+A9iKmd 4O+kbAtQS7Vw6ixZG2t60b1iSqfLifN/QWHvDlqw3cW4z7D2dc6ftLwqs/DGQZF2hjtd 0A8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=MYIyM3Rc; 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 a1-20020a17090a854100b0026b698fdda6si7587279pjw.98.2023.10.02.11.09.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 11:09:53 -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=MYIyM3Rc; 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 8AC0D807C5C1; Mon, 2 Oct 2023 02:59:53 -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 S236387AbjJBJ62 (ORCPT + 16 others); Mon, 2 Oct 2023 05:58:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236352AbjJBJ6F (ORCPT ); Mon, 2 Oct 2023 05:58:05 -0400 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6E67C4; Mon, 2 Oct 2023 02:58:01 -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=GVRP7ZhX9y66fV8la0Z0phq4YOuv61LMjBgGZkw2zl4=; b=MYIyM3RcvwaRbDjAKvQUPqHPe/ Kd8oc2UrJTmvAwD+3Wpo+MPjaVZUzMiCqO8h9YAsOk1WGNkzLlv1MdtrUhbrFhs0QAUU4FcrVT7uA wULosAIqVySsd/JKEL6DW49cwlpyRvGRyH8t3r/hlBADE+j3KiA7kqCpWXoErqm+C5Ew=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qnFge-0000ww-PZ; Mon, 02 Oct 2023 09:58:00 +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 1qnFge-0000Ft-I8; Mon, 02 Oct 2023 09:58:00 +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 v7 09/11] KVM: selftests / xen: re-map vcpu_info using HVA rather than GPA Date: Mon, 2 Oct 2023 09:57:38 +0000 Message-Id: <20231002095740.1472907-10-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231002095740.1472907-1-paul@xen.org> References: <20231002095740.1472907-1-paul@xen.org> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 02 Oct 2023 02:59:54 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778668214004192077 X-GMAIL-MSGID: 1778668214004192077 From: Paul Durrant If the relevant capability (KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA) is present then re-map vcpu_info using the HVA part way through the tests to make sure then there is no functional change. Signed-off-by: Paul Durrant Reviewed-by: David Woodhouse --- Cc: Sean Christopherson Cc: Paolo Bonzini Cc: David Woodhouse v5: - New in this version. --- .../selftests/kvm/x86_64/xen_shinfo_test.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 e6672ae1d9de..a5d3aea8fd95 100644 --- a/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c +++ b/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c @@ -66,6 +66,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, @@ -325,6 +326,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]++; @@ -892,6 +897,16 @@ int main(int argc, char *argv[]) alarm(1); break; + case SET_VCPU_INFO: + if (has_shinfo_hva) { + struct kvm_xen_vcpu_attr vih = { + .type = KVM_XEN_VCPU_ATTR_TYPE_VCPU_INFO_HVA, + .u.hva = (unsigned long)vinfo + }; + vcpu_ioctl(vcpu, KVM_XEN_VCPU_SET_ATTR, &vih); + } + break; + case TEST_TIMER_PAST: TEST_ASSERT(!evtchn_irq_expected, "Expected event channel IRQ but it didn't happen"); From patchwork Mon Oct 2 09:57:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 147338 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1499727vqb; Mon, 2 Oct 2023 08:22:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGT1trNiFVfFqXmchb6Nqd74QzdXgvMKVECAe+C5JOI2NNDPjeAVHl2SsVvoKZLPg2740Qq X-Received: by 2002:a17:902:e544:b0:1c7:61a1:9688 with SMTP id n4-20020a170902e54400b001c761a19688mr3932728plf.7.1696260148768; Mon, 02 Oct 2023 08:22:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696260148; cv=none; d=google.com; s=arc-20160816; b=zo7vvJWclx1nMcLsNgkb9BVV337aUis3CxB2Ch15qCrxrd+S5GV0vRisp7BfusgG+2 M1mKgAy9MgRx4f1QT5mjKGgqr5EHVYElLLEeXdlr+sNpEggttZ7oJOAqh7YUIYcfXeAb GxAUjvuLqJ3dbdm1UyPCfXFehOxZtNf/3rN1duC3NmRdCQO3CvLlhj4wFICckTT4/jiz G2Uny/syEgdqaD8yxapQSM+RWiZNdFrG9kLG2i6R72euuOpuT5c/DGpAsQ4ePAjPoubY p+lofi2GUNpYfkl5g6M8Wqm3PzS5wiSIFmF1E0OXyG0YQ51UdfGyiWnCDSTT8tRq8RG9 dXKw== 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=Yx86vZBs7HZcWBbvoo5tY2OVXe5f+cPwzpmsB3avRzM=; fh=jcKAuV9sx5P88dpWYyXihS1UO5TLmUGd/2Iq3QREE4o=; b=uU7zK7vWJou+BUu1Ziqik5toxMS6j50YHLhNTRc7NeiiPu0twIU5Hfz+mptM8WoRJF liDIsk2IEU1dVdD1Qh2/Y78CVsmdFfAhAKxl6JhCyqykEXIFPjqtC9x+U//kN3t1/TP7 3CMkAcLnYVivJn7+2fnrB5rmhKjraWI0OcMZHf6jlUh1AlchAYa6jP2/4hVxiIsgrF9P Z48nnZIihWM0QbXfU/EDAuOXepzioeT/k5qJ+q9SMnolpkw6BcE3sXIYVMzmgH3RSI3o wVh9puWTShc2QYX39+wsVCBdJAnzinjr+Acrtw1O4QMCIqRt91e1bk1jE2peEYwAtBRz q40Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=m1QmWjOR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id j6-20020a170903024600b001c470c5906bsi28971993plh.221.2023.10.02.08.22.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 08:22:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=m1QmWjOR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 6B62A8047D70; Mon, 2 Oct 2023 03:01:13 -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 S236490AbjJBKAk (ORCPT + 16 others); Mon, 2 Oct 2023 06:00:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236351AbjJBKAW (ORCPT ); Mon, 2 Oct 2023 06:00:22 -0400 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99E73BD; Mon, 2 Oct 2023 03:00:19 -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=Yx86vZBs7HZcWBbvoo5tY2OVXe5f+cPwzpmsB3avRzM=; b=m1QmWjORSP6UgcpdMBl+J4P++b NYZVhLYf+qjCqCRoB9tmISLYh5uPLDbdRXKtBz3t0wLby3NTfLJ5FGR1HalTU6xEyC2mABgxpB3g1 rkMlHcoz/s4Gfcv2W50tD9i1dQ2pWhl7FpBKWN33oYYxwpiZCzhjAOl9Ubu+QKjKGTqo=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qnFiq-00017A-KC; Mon, 02 Oct 2023 10:00: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 1qnFgg-0000Ft-7i; Mon, 02 Oct 2023 09:58:02 +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 v7 10/11] KVM: xen: advertize the KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA capability Date: Mon, 2 Oct 2023 09:57:39 +0000 Message-Id: <20231002095740.1472907-11-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231002095740.1472907-1-paul@xen.org> References: <20231002095740.1472907-1-paul@xen.org> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 02 Oct 2023 03:01:13 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778657682043015444 X-GMAIL-MSGID: 1778657682043015444 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 eee252a0afef..1487b679ae45 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4531,7 +4531,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; From patchwork Mon Oct 2 09:57:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 147280 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1404982vqb; Mon, 2 Oct 2023 05:57:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IExvJCnU8ZzJQ8yBPHieJ4QFgjjQo9BlJ39lN1zqTV5VQ2Z7peeAzRb6UDcJvQuQhw5uRv2 X-Received: by 2002:a17:90a:bb96:b0:26d:54de:b0d6 with SMTP id v22-20020a17090abb9600b0026d54deb0d6mr8672520pjr.20.1696251440587; Mon, 02 Oct 2023 05:57:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696251440; cv=none; d=google.com; s=arc-20160816; b=TU3koJUA74k4OygAvXetr/3YtNHCG3UeZNHXstwL5tXdztWrQjBFfc5rb+iiOd5dYE 1/HlzQDeq9QtksGzmq5iRhDxhIXoD+uTa4AHHMubiXYYLQRwcgJ5j1qopuS69DMGu4kL 3ZqlicjWFmlDV8HG2U2tu3UzX7g5wlz+9KY5tJT2o2AIZVqXLvHj0n/J9o1umM+uXXCp 20bQORQbV+WtbZqiO6ZeO05fUjpCSWO9mXwq5GetfcBAIwAd0pFCWs9zZaF9f2ZVKBL6 fyL788QPlwm8nDAP+IL1m3U2zS/8B2BFxArJXTeVicbqJS6xxLylR19fQSCRZa6MW440 IxsQ== 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=oaLU75npsvq/54a8Sa025V+4+WzNDRn33upnn1s6+Ig=; fh=8AvbwpPKF0Qe5WwS5eyABOVDUChKGxIrkPaOnjrOqKo=; b=Cj+LEZqi8zDQcyh0z2XZeSvGbwLq39+YyLZJfZ94L8yxjhHNSlBASPjJtBM5XwXu5j eB6wwsNkmzT1BT36SBMMF8dg0O3XlqwUcywVgZXiY0unmrmFYkYqvT+eYPJ6N5KCenne J1qEy9uQPc6u/CJ8iRJye62aYPl7IRmr7hRxEwgAsQzUJJ7DwR/MmF/LRoIp09pPRdQb ZT4thegC3GnSZnznQBQY1SNqMUkaY7LBYX06WRUbC+lug1ZidlDwiAmM4WyceyOw7yG4 QfedCU7OSrplm8Bs/2DAVUqnsNDfuBC9vRo2DDNG+Ag7y1ra7Fz77fcsmeldhS6GvRE5 EiNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b="q/ykCRK8"; 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 gx15-20020a17090b124f00b00277374d74afsi7256226pjb.12.2023.10.02.05.57.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 05:57: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="q/ykCRK8"; 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 8A03180756FD; Mon, 2 Oct 2023 03:00:52 -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 S236317AbjJBKAc (ORCPT + 16 others); Mon, 2 Oct 2023 06:00:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236241AbjJBKAV (ORCPT ); Mon, 2 Oct 2023 06:00:21 -0400 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 513B0CC6; Mon, 2 Oct 2023 03:00:18 -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=oaLU75npsvq/54a8Sa025V+4+WzNDRn33upnn1s6+Ig=; b=q/ykCRK8JD/cssMkft43adWnmO dgFcx/5EExveHYpHaN2qOKKGko25vBzWjhhf5/NVwSP5/M/WTCNqBb4ip0t0km23eeoB95Lt1bDXf JOulZfz2FlZxo7iEZB51Q0Ks17fLm6Vha27xljU5mmelsOkNb5XOTZS8jn+Mukq7VcrM=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qnFiq-000178-IA; Mon, 02 Oct 2023 10:00: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 1qnFgh-0000Ft-TV; Mon, 02 Oct 2023 09:58:04 +0000 From: Paul Durrant To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Paul Durrant , David Woodhouse , David Woodhouse , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , x86@kernel.org Subject: [PATCH v7 11/11] KVM: xen: allow vcpu_info content to be 'safely' copied Date: Mon, 2 Oct 2023 09:57:40 +0000 Message-Id: <20231002095740.1472907-12-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231002095740.1472907-1-paul@xen.org> References: <20231002095740.1472907-1-paul@xen.org> MIME-Version: 1.0 X-Spam-Status: No, score=-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, 02 Oct 2023 03:00:52 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778648550583994324 X-GMAIL-MSGID: 1778648550583994324 From: Paul Durrant If the guest sets an explicit vcpu_info GPA then, for any of the first 32 vCPUs, the content of the default vcpu_info in the shared_info page must be copied into the new location. Because this copy may race with event delivery (which updates the 'evtchn_pending_sel' field in vcpu_info) we need a way to defer that until the copy is complete. Happily there is already a shadow of 'evtchn_pending_sel' in kvm_vcpu_xen that is used in atomic context if the vcpu_info PFN cache has been invalidated so that the update of vcpu_info can be deferred until the cache can be refreshed (on vCPU thread's the way back into guest context). So let's also use this shadow if the vcpu_info cache has been *deactivated*, so that the VMM can safely copy the vcpu_info content and then re-activate the cache with the new GPA. To do this, all we need to do is stop considering an inactive vcpu_info cache as a hard error in kvm_xen_set_evtchn_fast(). 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 v6: - New in this version. --- arch/x86/kvm/xen.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c index aafc794940e4..e645066217bb 100644 --- a/arch/x86/kvm/xen.c +++ b/arch/x86/kvm/xen.c @@ -1606,9 +1606,6 @@ 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) - return -EINVAL; - if (xe->port >= max_evtchn_port(kvm)) return -EINVAL;