From patchwork Mon Dec 4 14:43:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 173408 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2808939vqy; Mon, 4 Dec 2023 06:44:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IGNMmcVUYJ6T1KXw6on+2kr+FJQpCS8MZQZOQulgjrtjwRSDeHX0rDXwyAhQiZfxAK81AXD X-Received: by 2002:a05:6a20:be10:b0:18f:97c:4f63 with SMTP id ge16-20020a056a20be1000b0018f097c4f63mr1918313pzb.111.1701701072571; Mon, 04 Dec 2023 06:44:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701701072; cv=none; d=google.com; s=arc-20160816; b=CTttCyC22yHPvwEIf7UZw5tRWRHlZ6i7Hq8hlreTYlEDDI2BR1QZZ8KsnXbgbOlgeh 58FeDl/7C8Nz9ozPZs3TXpuIwcZmKN83KbQpX8O0q4HiWiTkzirNKbhAk2ZR2k6KRtZz o1RrDARd2E4LAzzoFgSMbrSdR7mIub27tqlIJlJqwmKeLl911bFEgiICcTKrN8vIRkbv WsV35m68d3epDemiNYfg8YrxKM7YRWBZQT8VCVS/HYfb000x2rYYsJG3hscma/EvFTGW GnEADmS1YowAXblTjx9snEe7avsfNWX7blqGiqmA2/JLfTF9yl7Sum3I7yBWvGzeZMW0 mh/A== 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=aAPqvXm40pY9772UiBOljEePwtz/3Q0zIOpw238tj3M=; b=k/wrO51JqixSB8xbMndGk8CYFUDVJxcJva0eASY3UQxjUluU56eJct/jrlcSJetCxY wrHfJ0tSJpnkHbJ7pOLDRL4G8HzxpjX33Y8ufpg4lM7u3r3NuJGgbCVw2GCiPl4BVzpA dZ7oDlzjmV0O+SrGuxikg8OFtwWaAZ3UlPTWHsBaUdav/YmdIhLlGHukCepoNa7TLiws Abj0ZaUnKQkDGyOfv0Fey6fr4bgeg1Hfg4XLoKMksYRcb+6HWBg/m9G6JnJEDqXPuEwJ OEQVo++zmEOHOAW2SF1Xy3WDlA1H7Zkd1laDGqJ9Pc8bn15bOxiDOHIQ7rS6JHGcZ8Pr yGHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=hjp0SqUP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id d1-20020a056a0010c100b006ce4e330b8asi2059807pfu.124.2023.12.04.06.44.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 06:44:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=hjp0SqUP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 7BB11808BD2E; Mon, 4 Dec 2023 06:44:26 -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 S234155AbjLDOoR (ORCPT + 99 others); Mon, 4 Dec 2023 09:44:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234387AbjLDOoP (ORCPT ); Mon, 4 Dec 2023 09:44:15 -0500 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5782F2; Mon, 4 Dec 2023 06:44:20 -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=hjp0SqUPe/G7dgYIalb+sdTM2U HnS9e3Cz/nikgNFzgekg1PBRIZWAiRg5jpXMB1YUs2aQQFe8cgHQoHEQNZKr3jLvSTOlz+7ilGkJ4 EKxiBcFM8CqeGQdGFk/WGV2Tg/vXxhpW0SceVIGsDQyt+ufcSKsNVlfvQ64+z1Lac6jQ=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rAAAz-0003dk-AF; Mon, 04 Dec 2023 14:44:01 +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 1rAAAz-00088g-13; Mon, 04 Dec 2023 14:44:01 +0000 From: Paul Durrant To: Paolo Bonzini , Jonathan Corbet , 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-kselftest@vger.kernel.org Subject: [PATCH v10 03/19] KVM: xen: mark guest pages dirty with the pfncache lock held Date: Mon, 4 Dec 2023 14:43:18 +0000 Message-Id: <20231204144334.910-4-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231204144334.910-1-paul@xen.org> References: <20231204144334.910-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]); Mon, 04 Dec 2023 06:44:26 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784362903984667993 X-GMAIL-MSGID: 1784362903984667993 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)