Received: by 2002:a05:7412:8d11:b0:fa:4934:9f with SMTP id bj17csp536879rdb; Mon, 15 Jan 2024 05:39:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IFXv1j1DzLSq0CYS7AGmw+gWoIEdl1EW6x1GqFwMnoIb70u/6kDirqNUwK8FKNl3emtDrOL X-Received: by 2002:a17:906:f210:b0:a23:701b:a160 with SMTP id gt16-20020a170906f21000b00a23701ba160mr5291024ejb.38.1705325991492; Mon, 15 Jan 2024 05:39:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705325991; cv=none; d=google.com; s=arc-20160816; b=CebqaHomTV9VZlBu8g8k7d+3lQGOtjFuOwY0dUAwj+lQoQw+aLxKMa6jE99ezBQX5Z nVT/Bvu3KBfeoUdnMV5KYZUtSjGCZXASCxXgamjzEHW31g6JwvJfBZ5Zj/eyzG2nAlkz Y02UrwkpmqYaqJBH89Pzi0l7pOVsMiP2WvSAUE7bDEoo6gUCTmoqRSsG8yFUMKCJY8Np kWGtsC+P3uiRl26QsuEzFDEeYeIHJ/J0SV00SbI9QF/q6FodO+gqdU2vpCg257jdssvk l6EGW5039xHIGK+PGT7CYHCmTt358AnAsDdyTSsuZL5pxTdirjrVcNdFVu2dVxgxsdOJ YEpQ== 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=fgACEwLZ6lYf/MpYHQVfAlI0Y8l9tr/6SEL9cRJXGiPWfGco9jW5rXBCuHkQRicbpX GRsmId+4MFTao+7SttLhiz4jfLMLfvv/Zo7vSaNXF/0wtqnMKT8/l4v3LZ1DbaX4Qru8 XtWCC56xpCJLlHq1Syy0RSJbg18ITWkd4hWjW40LODpx7ENlwlWKO66z7aDqQJg1Uoaj 5t1L4paFgPuPBFdvFN5H3iEDEoEdhfghgjWTSR1gIC+nilINK/dv3vDDqXyAwo534wUA 2/lnp93ZrpPmbjkf8BFp6xsAi9TkrLOK/LaA3M8NDehnujcfkBeN65UJL5w6GWXcS9+A AFbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=o1zy6FsB; spf=pass (google.com: domain of linux-kernel+bounces-26040-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26040-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id k17-20020a170906681100b00a2da5b570a2si1129615ejr.996.2024.01.15.05.39.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 05:39:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26040-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=o1zy6FsB; spf=pass (google.com: domain of linux-kernel+bounces-26040-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26040-linux.lists.archive=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 1B0151F222F7 for ; Mon, 15 Jan 2024 13:39:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 497A217BA0; Mon, 15 Jan 2024 13:38:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xen.org header.i=@xen.org header.b="o1zy6FsB" 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 3CC3317591; Mon, 15 Jan 2024 13:38:16 +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=o1zy6FsBpp+W4T+pIxsO/Wf0Ja nvV0Rek/BZZYtx7YCw3ONnfe6hilzL1hqkdvQ5mP4cZAHK4AYIGJJ05VrF2yNqg2O1lmPX+bayYVZ bh5h2pFL1y/d7tk6nwd95UOeBnH3QAp7NbZKG4tPJ6qvsHXkz/MwePtvsYCurSlY7RyM=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rPMX7-0002j4-1p; Mon, 15 Jan 2024 12:57:41 +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 1rPMX6-0002kM-PK; Mon, 15 Jan 2024 12:57:41 +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 v12 03/20] KVM: xen: mark guest pages dirty with the pfncache lock held Date: Mon, 15 Jan 2024 12:56:50 +0000 Message-Id: <20240115125707.1183-4-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240115125707.1183-1-paul@xen.org> References: <20240115125707.1183-1-paul@xen.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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) -- 2.39.2