Received: by 2002:a05:7412:8d11:b0:fa:4934:9f with SMTP id bj17csp521781rdb; Mon, 15 Jan 2024 05:11:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IESd20UwBL7zX93jwAd9uvMWA2IuCzakL7Z5Gyqkl16zIE+5yDh0wEvZimQr9/4VfKC3oFc X-Received: by 2002:a05:6870:3912:b0:206:7f6d:52ad with SMTP id b18-20020a056870391200b002067f6d52admr8434853oap.113.1705324276685; Mon, 15 Jan 2024 05:11:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705324276; cv=none; d=google.com; s=arc-20160816; b=rhZlvLRrVDstS3uA9WY/yVnMMALWR7u7tGITZuUWPKAQIBTDTqRS2GtRo1kzEis6Nx mbGrxYAh6aw88xvu4RP2c9PSte7LupdvQHiXmoo1dzbF3hhluEnXzLQ29eHbqmNBKi+Z r9UqyzRqAJ0bSc6uJwh7NxWoVhjxg14JgzRsI6pVDiM6jhYSn3a0/M5VdkVn4NxLCQyw k+DP//dXfOdHx7pQIVSXmbX5fowlsva0FIsUrXFZQYYjz3Ukv3944RrxM4Y3h322T3Qv PjDVX1krUT4/VIkRyZk4IOWj6D3WN5i5QW8TXaUX35AJ6+/4C/B2VDMVY6webyP2atyX TgCQ== 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=5P2JtCeSZO2zn4VBkHCTT9EEqwZefcJCWgY3hftSny4=; fh=aAPqvXm40pY9772UiBOljEePwtz/3Q0zIOpw238tj3M=; b=sA7L2FbOoeZe3QIajPTWI10946kaGEX2T4aVwVlCcCmNmP0nbzkthXtp8ja8hKuhIO 10tJsDAMLFIp+POvmbwsV+xNNHc1BIfd2r9vSylsKF/jforCTA+p46bkux3Lvc49MX0f 7RIqC/WXyLpTAseB9jYdGTSGOQgJ1SWpLyrbpC2gsnKW694GcvaEHCK9oZGeGv2ga3+h s5Z3NCI83Ev1yEl9ut9/b55kCTx5q2Y1+EWoxgUmjACi8sCRPKsVW8Qf0zmfLV9BxQQ9 ElbUzaj5GhUq5nSFnYr8T4+h7ZxGGoSbhu2JbKJa8cVFEQjdK0+B3sEI3hq2VBee+FbY /J1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b="V/caNzGA"; spf=pass (google.com: domain of linux-kernel+bounces-26001-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26001-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 s184-20020a635ec1000000b005cd786d8e3bsi8964509pgb.249.2024.01.15.05.11.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 05:11:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26001-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="V/caNzGA"; spf=pass (google.com: domain of linux-kernel+bounces-26001-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26001-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 CF2E928256B for ; Mon, 15 Jan 2024 13:11:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4E7A017745; Mon, 15 Jan 2024 13:09:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xen.org header.i=@xen.org header.b="V/caNzGA" 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 24C8017566; Mon, 15 Jan 2024 13:09:44 +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=5P2JtCeSZO2zn4VBkHCTT9EEqwZefcJCWgY3hftSny4=; b=V/caNzGAWaZDOBgEe5DDitmoiI v9XSah+J0bkMcpgftR6Wp/2ATTnlt/Pnjr7BNcDYMmkQ+WEz8uOTlIIA/CYWo+BOtoDOE4w9rPqHP W7iaaDgmlh6M0geahSO0wJ/HU1Oe14W9bIGimE1UJnLb59TsDGR+wz6rQzFApTHnv4BA=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rPMiZ-00035q-6D; Mon, 15 Jan 2024 13:09:31 +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 ) id 1rPMXi-0002kM-4r; Mon, 15 Jan 2024 12:58:18 +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 v12 19/20] KVM: xen: allow vcpu_info content to be 'safely' copied Date: Mon, 15 Jan 2024 12:57:06 +0000 Message-Id: <20240115125707.1183-20-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240115125707.1183-1-paul@xen.org> References: <20240115125707.1183-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 9168a6ec88fd..972098ec4f6a 100644 --- a/arch/x86/kvm/xen.c +++ b/arch/x86/kvm/xen.c @@ -1797,9 +1797,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