Received: by 2002:a05:7412:d008:b0:f9:6acb:47ec with SMTP id bd8csp40006rdb; Tue, 19 Dec 2023 08:49:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IGDhN4khpnL1oqhuJVwB51rD07BP/IT+bh1v9jtTSOaRhFhxeHRAKS7nk4yv8kfNVN5IjVO X-Received: by 2002:a17:903:1105:b0:1d0:c502:e09d with SMTP id n5-20020a170903110500b001d0c502e09dmr20153938plh.99.1703004591849; Tue, 19 Dec 2023 08:49:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703004591; cv=none; d=google.com; s=arc-20160816; b=xyBCW9sSAwhHHMFf/90oT52W7hbKJvCiRqGfv2nxEMSCb8eqsa9/0RDi++EYvu8iJq TFBqDPbEXAoruOO+BUI2w1/O6Nwrm/dNgo/6pM5Ywrsc2G0IJ2XjPCNcyPxvmRb70Twv kklck7CQmBmvdtI1ryYkQfxOqmKH7XI0dSGBgV1op6JpfbhodISST+GoaXAazrnrUD8J zgV/4N6ZX8PRJHGp7/UihVfoyxcwXq+n0UdXk6MhHROSeo77dmlJ/vYNSo7r5sxwB35+ d50FOe30W3Pc7uuvbkhdpJOibWeMSE7P+yJmSgcaxjK0c3nVVcqqrWjeQh9eVUg5oLb6 jigQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from:dkim-signature; bh=AmbsIYupXhNEc+M3GAmFapvv+1Q9WOxTLba1bFXRLxM=; fh=aAPqvXm40pY9772UiBOljEePwtz/3Q0zIOpw238tj3M=; b=HOI0sDm2kMvEdYY1vK06iFsoERYceqK2X7cTdyFCMV43iaThRRwyKQqIR2zEunzn8D wW7DwePMpyTe4K+JbJ2cV2rBdw3QGr0W4fFS7DCcvyEe1xOMO+EAr5St+6w76fV00puw GWb5fYExnNgpbDtWD1I0ezvY5F9n3wiPlN1JOWKbAZCTQT6IuDyczL8wdgENrCZBOtHz yQaIX9dMPbBnohkdWVhTLa2m3UPoOysuE4Cm5LBXEbQrC6/S6brfbgDq1QPw8HjDrBBL ebGQox7DBKGeMLE9NYEJdu4Y7uLg0/G9fpPg63UVOVoEbZMwanGiHeMtW8bKbHuYrS40 rqWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=PHo4QIvo; spf=pass (google.com: domain of linux-kernel+bounces-5577-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5577-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id j9-20020a17090276c900b001d055315494si19714159plt.540.2023.12.19.08.49.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 08:49:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-5577-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=PHo4QIvo; spf=pass (google.com: domain of linux-kernel+bounces-5577-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5577-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 9EEE62891B4 for ; Tue, 19 Dec 2023 16:42:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3136E20DCF; Tue, 19 Dec 2023 16:41:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xen.org header.i=@xen.org header.b="PHo4QIvo" X-Original-To: linux-kernel@vger.kernel.org Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A6CE35896; Tue, 19 Dec 2023 16:41:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xen.org 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=AmbsIYupXhNEc+M3GAmFapvv+1Q9WOxTLba1bFXRLxM=; b=PHo4QIvo76d/X2kPOjUoZ5S0U0 vCjgR8KBqfgSBjMRuvjhQWkAGLcJbAfPHuhUu/WAFmVHrvXewvzknGM2a5uLuMrlbfLq5s9Nw/6Qb orT5HrYtc5BIlsxtq7TYgXWVhvF2AQebyZasGjsUiBEFmkMnGz7w88ShhPHlbxIEZXJo=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rFd9x-00064v-VF; Tue, 19 Dec 2023 16:41:33 +0000 Received: from 54-240-197-226.amazon.com ([54.240.197.226] 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 1rFckU-0005h9-1N; Tue, 19 Dec 2023 16:15:14 +0000 From: Paul Durrant To: Paolo Bonzini , Jonathan Corbet , Sean Christopherson , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , David Woodhouse , Paul Durrant , Shuah Khan , kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v11 19/19] KVM: xen: allow vcpu_info content to be 'safely' copied Date: Tue, 19 Dec 2023 16:11:09 +0000 Message-Id: <20231219161109.1318-20-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231219161109.1318-1-paul@xen.org> References: <20231219161109.1318-1-paul@xen.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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) 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 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 v8: - Update commit comment. 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 845ff23c8399..99eeb9b68a02 100644 --- a/arch/x86/kvm/xen.c +++ b/arch/x86/kvm/xen.c @@ -1799,9 +1799,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; -- 2.39.2