From patchwork Wed Nov 22 12:18:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 168326 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp1279506vqb; Wed, 22 Nov 2023 04:20:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IGKVmv4dFyUAGbLFjG5+G5e36NNJjunE9Si9kpeMVDml4i4Ew2MMNPanT/4s5ha3NoupwJo X-Received: by 2002:a05:6808:1389:b0:3b8:3e7d:db75 with SMTP id c9-20020a056808138900b003b83e7ddb75mr1664629oiw.55.1700655626189; Wed, 22 Nov 2023 04:20:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700655626; cv=none; d=google.com; s=arc-20160816; b=JiFgVyjq2bfxfJObrWE0BNUofL0imlEwEx/tolA4Gd/iAseKe88URJ2o7VKzR9Ibu2 V+Y6y2CEvJh6mAfDfbfP1Dbl0Gl+8IXa2V8nxjWiDgctZ+zn36iPDcmd/zSTYKYBymbK g+YoKR+6o90i1r1Bq4oIssPbJl4RrOVGCdn8Ux5L/U8G3L1nJMMkJFCuLP1eLRZo50ll Mh9T/23rSAISVJs/5TuqPANUh787gXoC+K38ThQvPMp82oB4ywmMQlqU8jFotCVedKiS V8I74ZikNYvQPS0EP0kRfW0CBSKOKHJhXpilVaktkTGnUTJnHlAV4tdjj+Y3Hd3n3cKr rOZA== 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=ptFuN2jCQTukRrWUGFV9UbE6tldJktPz8nHhLhWjreU=; fh=Cum1qOF0YrAzH/5yQjcCBfU63B+V0l01YtzsDBRUOAc=; b=K+7+ixvzPi6UyJExx1O71tr4XiUNt1/ktxxMST1M5mNseWwlQ1hXc7SPxwLjvIsdiS nloMP3P1jZhUA/V1UZBlyumAbXW1q9D6hNhQdlrqXbZ+vg2xaig1lsL9InTJfroPx5Kr 4xUH40V4Ail84MiojgyZfjRVm05zMJI5m4vhSNg+t1hN2JnnViOrxlt9YayLzCzVtaAx 94G83oDCO/tOIPYaZCuLP7aTlWNVgEdixnjiBDC02S6UPvNnUFrmngalQuh7tT2og/Cs kxgvFEeAGKUftolzvnh7KcaixYnGrv+FRPTX3IvTsoUIUmShdevVjpbz27I447si2rny QgVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=qH12veQX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id q19-20020a635c13000000b005c1cc7273basi12601351pgb.257.2023.11.22.04.20.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 04:20:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=qH12veQX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id C1BD481DE225; Wed, 22 Nov 2023 04:20:24 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344181AbjKVMUT (ORCPT + 99 others); Wed, 22 Nov 2023 07:20:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344085AbjKVMUE (ORCPT ); Wed, 22 Nov 2023 07:20:04 -0500 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7791D51; Wed, 22 Nov 2023 04:19:36 -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=ptFuN2jCQTukRrWUGFV9UbE6tldJktPz8nHhLhWjreU=; b=qH12veQXrXcPAFcXs6FWQIX7Vw AkcRTjkSZ0DYJNC/lXl01AN44qiGIjdod6LdNxJMeMtjQz6IaZQbb2tvNy3VZdV5+TADd1QtIADjr WgaxrG0HIs7AfV3Gswd/9RE3vDGmoPRaFJudetxKZv2CzCTcWxUcj4hTn8dvusiUdTgg=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r5mCT-0004x5-BZ; Wed, 22 Nov 2023 12:19:25 +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 1r5mCT-0004y9-2b; Wed, 22 Nov 2023 12:19:25 +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 03/15] KVM: xen: mark guest pages dirty with the pfncache lock held Date: Wed, 22 Nov 2023 12:18:10 +0000 Message-Id: <20231122121822.1042-4-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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Wed, 22 Nov 2023 04:20:24 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783266673455428540 X-GMAIL-MSGID: 1783266673455428540 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)