From patchwork Wed Nov 22 12:18:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 168336 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp1285583vqb; Wed, 22 Nov 2023 04:31:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IHMJeMvxOnycAPyzP5Ec1T8uQ9d12WoGGXbahGjqXbPKlqykfcCZ/3Q/0iWGfhX9PruvVzj X-Received: by 2002:a05:6a20:ce92:b0:188:d19:3fd4 with SMTP id if18-20020a056a20ce9200b001880d193fd4mr1621091pzb.18.1700656299283; Wed, 22 Nov 2023 04:31:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700656299; cv=none; d=google.com; s=arc-20160816; b=MdZ0lMTnBTm4b1fZ+UN7r/QUMFoSwsqjZI+S3TJ/cvmfh/lmiCim9aRlZV57QT/X5l 4TVdjGNV921L4RNdxQWb7CxJK58GXAtzpoQSWub98ofmp3OvI5B3+XJu/FnEc1jaZe9U AmIshCpDaQ9/EUAuQYEiZsLgOJVCDcPSvsnT6UFtxfaGNVzhvEWRoJNa+LzaErwBqnAL uZlduTxDl/g/5X982qtVlYgpaR0vv18faqV5989cUg/4/XasuvMOy9lp39lr/WGObT7q 5GGzyVEAwOg5uQQ4cxAaas4vtny0hvBMta6Pocdq/7iNbBeqNzexRZ2+SCtKnXMOM6LW EXKA== 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=MZExUPapDGprTQeB4qGg+AQaT86Su4wUNNQxiY1TpoVrrwjUqjJODQVqUJCA6vSjnq Ea7ja+lobrcs59WavLYwYf3q3AtmqJTs/L4WPTQoAUdRsgqm7Q/7Mi9qpW6+7HSftRak ZMsXgF+PZ5qLShcjFVXKi/GD2IXrNFYyD50asqY7FPpEzldVKM4qTVNn0u2x4Wz1Yix8 kz0tcNsNhRbDh2zJHfRo8o2abgA6AaX+vuzHArxnUk0YOdgSvzWTsGG7ONKLopKhcQG9 1530UV4yJDEeY3ygZm2Fmqh0lAtgiSgpfjN/m+AzCPkwzcxKLVNu+Tf+6C5tWeBKGP5F 572w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=CQhJKbRt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id u21-20020a634715000000b00578a2da998asi12805017pga.304.2023.11.22.04.31.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 04:31:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=CQhJKbRt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id B16C0806B73F; Wed, 22 Nov 2023 04:30:33 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344098AbjKVMac (ORCPT + 99 others); Wed, 22 Nov 2023 07:30:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343584AbjKVMaa (ORCPT ); Wed, 22 Nov 2023 07:30:30 -0500 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B174D92; Wed, 22 Nov 2023 04:30:25 -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=CQhJKbRt3pgU5rBJ+Vvi7X+I7D BhzUIaYVj/Dxf1Nj109ocJ0OWdOTWRTOsQJipQil38bfXXkD1IuL8wEzM5KlLjsZU+tj2yqgK9dfZ iU8GayAtIMOpi5M1HdWOnf48fZn9UHxekRKhPFPsWuId7rrvAIawOB3XTO5Ichu1nzuQ=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r5mN0-0005E6-2b; Wed, 22 Nov 2023 12: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 ) id 1r5mCp-0004y9-EI; Wed, 22 Nov 2023 12:19:47 +0000 From: Paul Durrant To: David Woodhouse , Paul Durrant , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v9 15/15] KVM: xen: allow vcpu_info content to be 'safely' copied Date: Wed, 22 Nov 2023 12:18:22 +0000 Message-Id: <20231122121822.1042-16-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231122121822.1042-1-paul@xen.org> References: <20231122121822.1042-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,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 fry.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 (fry.vger.email [0.0.0.0]); Wed, 22 Nov 2023 04:30:34 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783267379817629027 X-GMAIL-MSGID: 1783267379817629027 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 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;