From patchwork Thu Feb 15 15:29:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 201580 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:b825:b0:106:860b:bbdd with SMTP id da37csp487523dyb; Thu, 15 Feb 2024 07:46:03 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXZ9Hk4ngblFxV9hZJKBPY3zCfDTYINc7d298eQBXx2VIxv+0PH98q3tM6rBP6oVwhNGp+ZpIUqWNoRcg3IRXYiZnMBvA== X-Google-Smtp-Source: AGHT+IFtZQ8CdOwaUK/o+grIv/pI1JCAVpaf8PhdaZ1FEyGpw1dRgsarPDeFdFUSXuEvGCJPJ39T X-Received: by 2002:a0c:df88:0:b0:68c:cdbe:b995 with SMTP id w8-20020a0cdf88000000b0068ccdbeb995mr3392060qvl.22.1708011963308; Thu, 15 Feb 2024 07:46:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708011963; cv=pass; d=google.com; s=arc-20160816; b=Y4kOtrqm0kozXCgGnWJmJt1g5CAr+rcFE42gz55ErggZEw9sa5gGGjde1y9WBmOhKH 2EabwPnOlbI7werM21m8OFRjLMx/LeTFWqix/r/BPKysjF+nkr+TW3EBl1oguXDTWfTl uQTQy1KGKW2KCHLt99CB2KrD8CurIa60DICt8H56ONyHK0CVJczqvIQw4BYigXm6TBVB rpEhEBcsLrnQWqS9f8wfFL35H4AO6v3w5cs7VaKy7jqW/HhNjMA42KAGRBeqcQa1axXf jHiOI0GgEe1aTRUj6iCiaRhDgILCwNZjNQUYo24H2VuRxfE1mAJ81hJl+EtCEv3r2sXx IUMg== ARC-Message-Signature: i=2; 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=I+0HAEEY7B8ebrh7W7mzXaPfOq28o4tU8rT0p+AqpXE=; fh=NrOggL3VZvuSFh5W9Wj2+kLgS4v0nogfnAWvBJoouXQ=; b=jlKVHWu10wcAdCXkV2ev9rTm4tNaowtg3XT4iLQKf6ceziiW7kMpt/zrw4cenHvnr+ Jvy4CmZ/bRoh9fDB3hxBRditvRvfmyuj4ZjSTtAbo5Zz/u0fqWnMm6mQnvrD7gW/yth9 GTGveTR9yQdF2UZf9Ft32vbrmvWGdfNdWCSxQNkQk8Dlkb/BIDvHO/Wz3Ixh5unKNckI cmgiSgLre1ZmtKKzBmUI29RS72hLmkZHtiyeEzu4Qx3gBUBZzkio3SMbwdpvha4dR2xQ WiTIsHmRD5/XXwSQW/kAr6ZnUbkPlzId09G29XDXTSk5zGSKvloZ99yaTsGKrc7qfrUy TlRA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=wOERm6ZT; arc=pass (i=1 spf=pass spfdomain=xen.org dkim=pass dkdomain=xen.org); spf=pass (google.com: domain of linux-kernel+bounces-67222-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67222-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id gh3-20020a05621429c300b0067f056ee1dasi1589638qvb.68.2024.02.15.07.46.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 07:46:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-67222-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=wOERm6ZT; arc=pass (i=1 spf=pass spfdomain=xen.org dkim=pass dkdomain=xen.org); spf=pass (google.com: domain of linux-kernel+bounces-67222-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67222-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 3C0B21C23828 for ; Thu, 15 Feb 2024 15:45:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CA773134CF0; Thu, 15 Feb 2024 15:44:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xen.org header.i=@xen.org header.b="wOERm6ZT" 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 822B8131E32; Thu, 15 Feb 2024 15:44:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=104.130.215.37 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708011872; cv=none; b=u3tau9wW1xXZF/ic6t0Z2NqTe+seSHubrVhy+QsC6EBxxhnWmM21cQ48Tf7Gde068ISvNdv1BqK32PP5bENKcy8S/ZpYaY+igy647U+ZXa9TBvQzC4FCC8SltQt/TPRO/ai9c7ZxwjaI3rFZOYm4A61U58ZMJP3qd0k5OMJE41Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708011872; c=relaxed/simple; bh=tf6LMRayvs8aoSZxiqZEwaZ7V5TgcIo9fVJuyWSO+FU=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MIbkIkbfq95LFtAdnYBXvTYW5WXkvUI8pwJCZxe9tw9Hqj+ruhCEzlj1fO1wU8tQzkYNKaSxV/lTzsaWJsrgjFPtPcE8qhoJq/JIo+dyZG8J1OOAMEFPhPa9jsLDTDgWkvGtq9WimbL5LCb3gw4Z6FKiK6Be9tjzIBpBjbbBNnM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org; spf=pass smtp.mailfrom=xen.org; dkim=pass (1024-bit key) header.d=xen.org header.i=@xen.org header.b=wOERm6ZT; arc=none smtp.client-ip=104.130.215.37 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=I+0HAEEY7B8ebrh7W7mzXaPfOq28o4tU8rT0p+AqpXE=; b=wOERm6ZTM/pzHUgQEadMvJJAX3 PDRpCWSkDxShRD5XRBxbf1et0sPLU3iAt1IbskBDHW/J8BU/g8YpTS1anHfvaF0bKlU1WFfLcbMFz JDd+Zzm2ACaDvFpGoWLTWLSyL0gFq+2eJ/LcA/mJQz/1+DJF0P7MkfJcWIWbsgx6sf18=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1raduL-0001WM-SP; Thu, 15 Feb 2024 15:44:17 +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 1radhd-00089r-Po; Thu, 15 Feb 2024 15:31:10 +0000 From: Paul Durrant To: Paolo Bonzini , Jonathan Corbet , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , David Hildenbrand , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Sven Schnelle , 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-s390@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v13 20/21] KVM: x86/xen: allow vcpu_info content to be 'safely' copied Date: Thu, 15 Feb 2024 15:29:15 +0000 Message-Id: <20240215152916.1158-21-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240215152916.1158-1-paul@xen.org> References: <20240215152916.1158-1-paul@xen.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790980352070659545 X-GMAIL-MSGID: 1790980352070659545 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 v13: - Patch title change. 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 8650141b266e..11ab62ca011d 100644 --- a/arch/x86/kvm/xen.c +++ b/arch/x86/kvm/xen.c @@ -1802,9 +1802,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;