From patchwork Tue Nov 21 18:02:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 167887 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp823994vqb; Tue, 21 Nov 2023 10:16:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IG+H6UNpmN67pxqX0YqBKdFUBWTAbBqSLi6wAPYBgosTEItsoznMBr8Dcagn7IhQo0HVgh7 X-Received: by 2002:a05:6a20:9188:b0:187:c2be:3c41 with SMTP id v8-20020a056a20918800b00187c2be3c41mr11386234pzd.1.1700590604277; Tue, 21 Nov 2023 10:16:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700590604; cv=none; d=google.com; s=arc-20160816; b=hepudGQ+1WpKwvrfswwL2pQZm8X1gAE3ZHd1iPT2qR6EZDT3Nw4r2VFxKFRXE8Tr3q Vl6iFnI3NH/LWFKQ01vejrjIxOclgRDqi+6BAhVvsfU4ApKuM2zNDz/ziwjSyZaWOvzd fiv5Qj5n5YDAUOnAFtF//MUvV3l8he/zHWPaer7MjQ1VQ+XCdrgiOMS27xyO+fyd4u7P WFFooWzzwBZWGP23DzHPpsdHKpsjFPU/rypEvy5j4XeyIf1O2Cim8i4JsBrJBz3WLFyv 1skDE1DQawZSJp+4z0XOawXvY7WNsq37qnzRI+UR2mlfaz9cvxoJqZhmyxmpL52Kce6H obuA== 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 Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id x23-20020aa79417000000b006cb4b97ace8si7986079pfo.323.2023.11.21.10.16.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 10:16:44 -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 DE7B381552DD; Tue, 21 Nov 2023 10:04:17 -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 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:18 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783198493409972226 X-GMAIL-MSGID: 1783198493409972226 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 Reviewed-by: 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: 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)