Message ID | 20231121180223.12484-16-paul@xen.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp832901vqb; Tue, 21 Nov 2023 10:32:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IGFkOqLVwjBsEqSe7G/bvpXUGDi4oLYjBeUET9Bvcyded8F9Ho4gvzFUcaeFC1sTuVfgWKy X-Received: by 2002:a05:6808:171a:b0:3b8:37ae:af40 with SMTP id bc26-20020a056808171a00b003b837aeaf40mr141016oib.9.1700591520683; Tue, 21 Nov 2023 10:32:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700591520; cv=none; d=google.com; s=arc-20160816; b=nS5LTTP5W98MZBGEc7qrVpCBDx8p2KcDIR/41pDFcIzteDaviEtRGG5SwWyZfG+nAU crboQtrtGQqnsIo44VPWBXONK5gF0v+N1/f/q8Xj/wWihzl40n/Q9qj7Nbx1tyI8RNfA ozmKoAwURYxOLZQuD2VuJUsvVTjlv19i3M+bmPmbnCPmEtXIhFBc+ICRRTPNDakiqX6B vly1xKaXtvOfBKwlV6lgmxzYvG4nOvwvffJysFaZDfQ2mUlBicQjO5pXLy/1f+qW2dX+ R1eWSXdGF6fp1lKsNolNWkovr6LbalT3VNWREkJtoGlpJVLMN0xoACjB6Yz24JIY3uq2 bBSA== 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:to:from :dkim-signature; bh=CPp0Qc6lsksup1D7/LciCKmODvP2NLwil1ZR7D0Jz3s=; fh=Cum1qOF0YrAzH/5yQjcCBfU63B+V0l01YtzsDBRUOAc=; b=W8niAJhNWspL9Y5JDXouuX2OSog0Ppth2NCVMj1q0Dlh7iq8nPJs4C1WD8vjQeiJTH eb+FEaXz/qz+mTo00kTs1FPjk/ig9nV5ZvtYDUIFW1eHIV6/M9GAGoLgRNh1v2dD9T0F 1tZMxs52DHendlXdhBsmNUKqkwfH7yOd+FmCxD3yQqWA5TipSOY6T4TLr6T03U4bRmWC fzo2AjRbidOz4QBkQUwA/d2CBiquXljzovgBXFKIr1P6iQeQTGBiIlvSCs2JgvdIr8ZF FI6KYE/txV0Y2K4qOFdQwxGEVnumy2qnYEow95klwByTAl6sLej47ROWiXSCwXEMT5pK Aoiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=OF8rBuL3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id f14-20020a63100e000000b00578d0d070f4si10766537pgl.844.2023.11.21.10.32.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 10:32:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=OF8rBuL3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 5E64F804B12C; Tue, 21 Nov 2023 10:30:51 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234458AbjKUSak (ORCPT <rfc822;ouuuleilei@gmail.com> + 99 others); Tue, 21 Nov 2023 13:30:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229954AbjKUSad (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 21 Nov 2023 13:30:33 -0500 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A36F12E; Tue, 21 Nov 2023 10:30:29 -0800 (PST) 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:To:From; bh=CPp0Qc6lsksup1D7/LciCKmODvP2NLwil1ZR7D0Jz3s=; b=OF8rBuL3cRtIL0H6LalhIYs6Uj lUzSmdPd3UXsOfNZgD45+zNC+QQVAI4BN+pYXzmIHAAKL71LzsoRVAk1dhnEerAv9ioT8JTQj2u1b hZNgKZ4377UolqqyMA2CgwcYTpzX/37KnUGCsz0ON5KWcXeena6FhBjbgrPN4TkiBBKQ=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from <paul@xen.org>) id 1r5VVq-0000Bk-6T; Tue, 21 Nov 2023 18:30:18 +0000 Received: from 54-240-197-231.amazon.com ([54.240.197.231] 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 <paul@xen.org>) id 1r5V5u-0004Z3-CU; Tue, 21 Nov 2023 18:03:30 +0000 From: Paul Durrant <paul@xen.org> To: David Woodhouse <dwmw2@infradead.org>, Paul Durrant <paul@xen.org>, Sean Christopherson <seanjc@google.com>, Paolo Bonzini <pbonzini@redhat.com>, Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>, Dave Hansen <dave.hansen@linux.intel.com>, x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 15/15] KVM: xen: allow vcpu_info content to be 'safely' copied Date: Tue, 21 Nov 2023 18:02:23 +0000 Message-Id: <20231121180223.12484-16-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231121180223.12484-1-paul@xen.org> References: <20231121180223.12484-1-paul@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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,T_SCC_BODY_TEXT_LINE 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: <linux-kernel.vger.kernel.org> 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]); Tue, 21 Nov 2023 10:30:51 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783199454173078563 X-GMAIL-MSGID: 1783199454173078563 |
Series |
KVM: xen: update shared_info and vcpu_info handling
|
|
Commit Message
Paul Durrant
Nov. 21, 2023, 6:02 p.m. UTC
From: Paul Durrant <pdurrant@amazon.com> 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) there needs to be 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). 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, stop considering an inactive vcpu_info cache as a hard error in kvm_xen_set_evtchn_fast(). Signed-off-by: Paul Durrant <pdurrant@amazon.com> Reviewed-by: David Woodhouse <dwmw@amazon.co.uk> --- Cc: David Woodhouse <dwmw2@infradead.org> Cc: Sean Christopherson <seanjc@google.com> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@redhat.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: x86@kernel.org v8: - Update commit comment. v6: - New in this version. --- arch/x86/kvm/xen.c | 3 --- 1 file changed, 3 deletions(-)
Comments
On Tue, 2023-11-21 at 18:02 +0000, Paul Durrant wrote: > From: Paul Durrant <pdurrant@amazon.com> > > 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) there > needs to be 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). > > 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, stop considering an inactive vcpu_info > cache as a hard error in kvm_xen_set_evtchn_fast(). > > Signed-off-by: Paul Durrant <pdurrant@amazon.com> > Reviewed-by: David Woodhouse <dwmw@amazon.co.uk> Wait, didn't we realise that this leaves the bits set in the shadow evtchn_pending_sel that get lost on migration? The point in your previous patch which split out a shiny new set_shinfo_evtchn_pending() function was that you could then *call* that function to ensure that the corresponding index bit was set on the destination host after migration, if the bit in the shinfo is. So we'd do that from kvm_xen_setup_evtchn(), kvm_xen_eventfd_assign(), and when setting KVM_XEN_VCPU_ATTR_TYPE_TIMER. if (bit_is_set_in_shinfo) set_shinfo_evtchn_pending()
On Tue, 2023-11-21 at 22:53 +0000, David Woodhouse wrote: > On Tue, 2023-11-21 at 18:02 +0000, Paul Durrant wrote: > > From: Paul Durrant <pdurrant@amazon.com> > > > > 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) there > > needs to be 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). > > > > 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, stop considering an inactive vcpu_info > > cache as a hard error in kvm_xen_set_evtchn_fast(). > > > > Signed-off-by: Paul Durrant <pdurrant@amazon.com> > > Reviewed-by: David Woodhouse <dwmw@amazon.co.uk> > > Wait, didn't we realise that this leaves the bits set in the shadow > evtchn_pending_sel that get lost on migration? > > The point in your previous patch which split out a shiny new > set_shinfo_evtchn_pending() function was that you could then *call* > that function to ensure that the corresponding index bit was set on the > destination host after migration, if the bit in the shinfo is. > > So we'd do that from kvm_xen_setup_evtchn(), kvm_xen_eventfd_assign(), > and when setting KVM_XEN_VCPU_ATTR_TYPE_TIMER. > > if (bit_is_set_in_shinfo) > set_shinfo_evtchn_pending() I mean set_vcpu_info_evtchn_pending() of course. And we probably want to extend the xen_shinfo_test to test it, by setting the bit in the shinfo to mark the event as pending, and then doing each of • Set up timer (a bit like in TEST_TIMER_RESTORE at line 817). • Add incoming eventfd with KVM_SET_GSI_ROUTING (cf. line 563) • Add IPI with KVM_XEN_ATTR_TYPE_EVTCHN (cf. line 597) Each of those should set the index bit in the vcpu_info immediately if the evtchn port is already set (and unmasked) in the shinfo. (Ignore this part if you're cleverer than me or have had more coffee…) It took me a moment to get my head around the different setups we have for event channels, but that's because the standard KVM_SET_GSI_ROUTING one is for *incoming* events, just as we would for MSIs, and we use the standard way of attaching an eventfd to an incoming GSI/MSI/evtchn. The KVM_XEN_ATTR_TYPE_EVTCHN one is for *outbound* events where the guest does an EVTCHNOP_send. That can *raise* events on an eventfd, or it can be an IPI or loopback interdomain port, which is the case we need to test.
On 22/11/2023 10:39, David Woodhouse wrote: > On Tue, 2023-11-21 at 22:53 +0000, David Woodhouse wrote: >> On Tue, 2023-11-21 at 18:02 +0000, Paul Durrant wrote: >>> From: Paul Durrant <pdurrant@amazon.com> >>> >>> 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) there >>> needs to be 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). >>> >>> 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, stop considering an inactive vcpu_info >>> cache as a hard error in kvm_xen_set_evtchn_fast(). >>> >>> Signed-off-by: Paul Durrant <pdurrant@amazon.com> >>> Reviewed-by: David Woodhouse <dwmw@amazon.co.uk> >> >> Wait, didn't we realise that this leaves the bits set in the shadow >> evtchn_pending_sel that get lost on migration? >> Indeed we did not, but that's not something that *this* patch, or even this series, is dealing with. We also know that setting the 'width' of shared_info has some issues, but again, can we keep that for other patches? The series is at v9 and has already suffered a fair amount of scope-creep. Paul
On Wed, 2023-11-22 at 10:55 +0000, Paul Durrant wrote: > > > > Wait, didn't we realise that this leaves the bits set in the shadow > > > evtchn_pending_sel that get lost on migration? > > > > > Indeed we did not, but that's not something that *this* patch, or even > this series, is dealing with. We also know that setting the 'width' of > shared_info has some issues, but again, can we keep that for other > patches? The series is at v9 and has already suffered a fair amount of > scope-creep. Hrm... OK, that makes sense. This series is attempting to address the fact that we can't do overlays on memslots without temporarily taking away GPA ranges that we didn't mean to change. This patch is sufficient to allow evtchn delivery to work while the memslots are being frobbed, because userspace takes the vcpu_info away during the update. In that case the shadow works just fine. So yeah, if you want to handle the migration case separately then that seems reasonable.
diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c index eff405eead1c..cfd5051e0800 100644 --- a/arch/x86/kvm/xen.c +++ b/arch/x86/kvm/xen.c @@ -1742,9 +1742,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;