Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp582863rdf; Tue, 21 Nov 2023 10:16:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IEb/b/CIuMbRgCwdF5pYz2N9Hp8p9EV1xK1MO5Q/Bdia6/8uS53AO8uw0thA61VicyZE7m4 X-Received: by 2002:a05:6808:3099:b0:3b2:f2e0:6b39 with SMTP id bl25-20020a056808309900b003b2f2e06b39mr111462oib.12.1700590603261; Tue, 21 Nov 2023 10:16:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700590603; cv=none; d=google.com; s=arc-20160816; b=XEiCG58XTuXUPupL2jGLM0Rl6gnic06ypMI5EHI2kpOYcVhHj1Dk5ukq7E+rCxsA7r SboEhkzbUscJEXowiy25WKTH3Ygg/YcIYcW6cNLtKSjWzyA39OxU5f6lD1k/Yt64EYX6 XMkF6zrqDVKSzFMZzMPXPgAPvODkIjMVjHwuqvSAWB8pM9EvJU5GW32o+QK7WVhMpqYO UXQu9h1FF8p3MQZ3pN2wFmiN0pLsN6FmKjT9cCIP3bBrDQbrrRuI/6LhrqUTP8kwrYkB WcTOec+svjqEs+wBX8A96yWIsCHo0C1yGzIEV27JJRKSfpTELh3GM8JaaTN/fi0Yb1Yj 5hvg== 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=0DZ85GBDIX7OEp0bx4GOzWNATdcequDe+9yrjRRR5Lc=; fh=Cum1qOF0YrAzH/5yQjcCBfU63B+V0l01YtzsDBRUOAc=; b=SgiJDiqf8mos/SmItj5iQ9kVlYfSG/m242Pbcdr0ds2PRfsHG7YF1cppEx/a/uaSjR i4FAstMaQTWlUWXO19ZlJl2E/WITukJ9tZm5A/QBH859fcE4qPrbJ6DnUjlp5fTlnBhB DEz/dIpNKCDZ2QRzneQGT0EuThDs0PyWlfaO0YbwMebdrBb8Kh5OBnSHJXm7upNB06c5 w9JV4lihSlJdAFjNih/yfESe1v0pgTZyKM58f5AfT2ljqIPzf0jhxc9uUrcZUgd31Qj5 N51GCzfPtd5ewUY/+FZdKgWaIziBbVEgGp496Ppc0Bxxhl6lVf8yR/CEB3uyAWlCOhir r+MA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=QPHWpDWT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id cb4-20020a056a02070400b00563f627f2easi11718917pgb.122.2023.11.21.10.16.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 10:16:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=QPHWpDWT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id B30E081552E1; Tue, 21 Nov 2023 10:04:32 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234299AbjKUSD3 (ORCPT + 99 others); Tue, 21 Nov 2023 13:03:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229472AbjKUSD0 (ORCPT ); Tue, 21 Nov 2023 13:03:26 -0500 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BEEC18E; Tue, 21 Nov 2023 10:03:22 -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=0DZ85GBDIX7OEp0bx4GOzWNATdcequDe+9yrjRRR5Lc=; b=QPHWpDWTF64a1Q8LRuy9FsaxGj qgs616ONQTPUJwL6dHLQxsNYmXVUUMadGze218LMMosWMbbW4LKEmTi+2C4WRvAbb/AIJ66jogYzn VYjSqDfTlhhS0Smp+qtpz5CcCStloYCRWq97p0ej5wvmdkhPm15I/B8sa4fuYqn8HYeo=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r5V5Y-00084M-Iw; Tue, 21 Nov 2023 18:03:08 +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 1r5V5Y-0004Z3-9v; Tue, 21 Nov 2023 18:03:08 +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 v8 03/15] KVM: xen: mark guest pages dirty with the pfncache lock held Date: Tue, 21 Nov 2023 18:02:11 +0000 Message-Id: <20231121180223.12484-4-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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Tue, 21 Nov 2023 10:04:32 -0800 (PST) From: Paul Durrant Sampling gpa and memslot from an unlocked pfncache may yield inconsistent values so, since there is no problem with calling mark_page_dirty_in_slot() with the pfncache lock held, relocate the calls in kvm_xen_update_runstate_guest() and kvm_xen_inject_pending_events() accordingly. Signed-off-by: Paul Durrant --- Cc: Sean Christopherson Cc: Paolo Bonzini Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: David Woodhouse Cc: x86@kernel.org v8: - New in this version. --- arch/x86/kvm/xen.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c index e53fad915a62..426306022c2f 100644 --- a/arch/x86/kvm/xen.c +++ b/arch/x86/kvm/xen.c @@ -452,14 +452,13 @@ static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic) smp_wmb(); } - if (user_len2) + if (user_len2) { + mark_page_dirty_in_slot(v->kvm, gpc2->memslot, gpc2->gpa >> PAGE_SHIFT); read_unlock(&gpc2->lock); - - read_unlock_irqrestore(&gpc1->lock, flags); + } mark_page_dirty_in_slot(v->kvm, gpc1->memslot, gpc1->gpa >> PAGE_SHIFT); - if (user_len2) - mark_page_dirty_in_slot(v->kvm, gpc2->memslot, gpc2->gpa >> PAGE_SHIFT); + read_unlock_irqrestore(&gpc1->lock, flags); } void kvm_xen_update_runstate(struct kvm_vcpu *v, int state) @@ -565,13 +564,13 @@ void kvm_xen_inject_pending_events(struct kvm_vcpu *v) : "0" (evtchn_pending_sel32)); WRITE_ONCE(vi->evtchn_upcall_pending, 1); } + + mark_page_dirty_in_slot(v->kvm, gpc->memslot, gpc->gpa >> PAGE_SHIFT); read_unlock_irqrestore(&gpc->lock, flags); /* For the per-vCPU lapic vector, deliver it as MSI. */ if (v->arch.xen.upcall_vector) kvm_xen_inject_vcpu_vector(v); - - mark_page_dirty_in_slot(v->kvm, gpc->memslot, gpc->gpa >> PAGE_SHIFT); } int __kvm_xen_has_interrupt(struct kvm_vcpu *v) -- 2.39.2