From patchwork Tue Dec 19 16:10:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 181086 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp2065727dyi; Tue, 19 Dec 2023 08:40:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IFTrSuJCmjBlvrXJYg5bCtNwwKYsyCFplyunswPII5YDpSZFdeRGJ538kOoRaxNIJIa/yOb X-Received: by 2002:a05:6214:c4b:b0:67f:42df:ecc2 with SMTP id r11-20020a0562140c4b00b0067f42dfecc2mr4100424qvj.105.1703004022114; Tue, 19 Dec 2023 08:40:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703004022; cv=none; d=google.com; s=arc-20160816; b=d4FV+3wwwrwukuV8ChPML2m4tfuV/7OLQmJaYyODMTXQlGygkEDhfR1iYo/WrpwmKv jJ/kDbayxxO9IGY6m+rguAvQsBYByTJaiUhFHBlkrNd1jU8/kIrbny1rMQ4LFw4/VhaL 9nkubrzFLF5roFRp8pqwxPkI0La3T+oMMiqOzxCjkTeFux6K4jJYAuJlOZL4wIvNwPw0 EKArGLyk6LMJYLx4EtuHsIeTiXwAQX+BmAQndS33B1h/4Hc5w5lllVwAKQjH8i/5grtk pOjzycy0hIDjvxZ0FQywVirVrlSkxHnY0mYFu8SG3RztxW9WX6jcB0ee809qJ7BePoEY 5J5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from:dkim-signature; bh=1JD8pX45SUH/HhG43DDtvS8SQK+3Lmy7845cO4NhDiI=; fh=aAPqvXm40pY9772UiBOljEePwtz/3Q0zIOpw238tj3M=; b=XzWPMF+cILj9jvKqzugS8BUkgiTX85MuDWDRjqpDxjiwIESbuogeejw44ZNVwLNRSI cYw18FBFlfbRygKXi122+v3cjdhoYVYvh4bvPl49xsxeHTf7QaboXaIPV49YxFKUYYKy u1erElaWAPAF5xuZf7vuiSJjUwUuINZcC24LD2tvtE38L5VzEYJmQLFH9BaBkS/inZ9j IzY/A5tNJE32tmP6YhvqzfHi0rQnMsenY+7XwByNGuW1jccJ9B6AZnMp8lrurIDz6tf/ iIY/G3hqyYMiUu9I9Yc1UlKMqCUTjX1dxc29+EfhbR8E0nVI98NCdQjWxXP8BqEx2z/c UPCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=hvis3Ih5; spf=pass (google.com: domain of linux-kernel+bounces-5570-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5570-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id q17-20020a0ce211000000b0067f4a5be921si3717129qvl.106.2023.12.19.08.40.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 08:40:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-5570-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=hvis3Ih5; spf=pass (google.com: domain of linux-kernel+bounces-5570-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5570-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id E10FB1C24583 for ; Tue, 19 Dec 2023 16:40:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4935C20DED; Tue, 19 Dec 2023 16:39:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xen.org header.i=@xen.org header.b="hvis3Ih5" X-Original-To: linux-kernel@vger.kernel.org Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B2AB20334; Tue, 19 Dec 2023 16:39:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xen.org 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=1JD8pX45SUH/HhG43DDtvS8SQK+3Lmy7845cO4NhDiI=; b=hvis3Ih5heosNtAj6Iiq+BVnXL qd+pBT4Rg/8xriuG6KKD6qmrFUoPvo03jZ6ky2ixbKMuzUubosZVLBboNml4Wn7yc4PRikjYawdKE 2xfjaxLCqQLbG2TOq/p+/u7OldQfYu72tPzKysAUtit7g515HyNubshlyBcV44rj9Ngo=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rFcju-0005Lk-MA; Tue, 19 Dec 2023 16:14:38 +0000 Received: from 54-240-197-226.amazon.com ([54.240.197.226] 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 1rFcju-0005h9-DO; Tue, 19 Dec 2023 16:14:38 +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 v11 03/19] KVM: xen: mark guest pages dirty with the pfncache lock held Date: Tue, 19 Dec 2023 16:10:53 +0000 Message-Id: <20231219161109.1318-4-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231219161109.1318-1-paul@xen.org> References: <20231219161109.1318-1-paul@xen.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785729145309666475 X-GMAIL-MSGID: 1785729145309666475 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 e43948b87f94..b63bf54bb376 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)