From patchwork Mon Jan 15 12:56:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 188168 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2614:b0:101:6a76:bbe3 with SMTP id mm20csp1707897dyc; Mon, 15 Jan 2024 05:41:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IEaSpGalbfEt9nMIOiSgUx1neht61tsDNDTwnEjVNuFS+f1jTz3kQCjrJAjx0kGBVDHnCwE X-Received: by 2002:a05:6871:5b05:b0:206:8614:f4f0 with SMTP id op5-20020a0568715b0500b002068614f4f0mr8993744oac.54.1705326078970; Mon, 15 Jan 2024 05:41:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705326078; cv=none; d=google.com; s=arc-20160816; b=HXVJooXCI0pCEUNzMudCOWvDVDmV8Vy+pqFxII24451S8sAAJTsMfEcXEN34lrxUmC ScMJXSgXUJWHiSeNPYNUSAC5SjkonkVPNFfk8ctdDO5nRgEolNhJr59/ZeBZ59ojNu4f mf8FlV2PybRCdiLeHhKtGMQXlYnmX3mn9MC2+fKPsG6yBCe5JEDl7uVeStFwByfyhKfG qlWbsJPcHVlecjnUsg2y6RCdtdA97AgvYtyCKjMSnsT6L5Mf5raU+iUcMA4sbJRNmSBX T+3Ug/A3iDEvvfzgsWnJB11Rnb6NdKt2KmHGD74rrLN13qYT/EAxbnLIJg/BX1KowgzM OG7w== 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26040-ouuuleilei=gmail.com@vger.kernel.org" Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id x12-20020a63f70c000000b005ce0b2ab7a3si8564198pgh.887.2024.01.15.05.41.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 05:41:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26040-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26040-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id ECCD9B21C61 for ; Mon, 15 Jan 2024 13:40:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1E67A17BBB; Mon, 15 Jan 2024 13:38:21 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788163998508432313 X-GMAIL-MSGID: 1788163998508432313 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)