From patchwork Tue Dec 19 16:10:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 181087 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp2066008dyi; Tue, 19 Dec 2023 08:40:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IF/jFaaTqAe+X5rZanNGyJ16kYPAvpEqJYBN6NQqj0ksJjJco6A5bkN4Baol2Yh2CiK2n67 X-Received: by 2002:a50:d4dc:0:b0:553:26db:ed73 with SMTP id e28-20020a50d4dc000000b0055326dbed73mr2766063edj.72.1703004050569; Tue, 19 Dec 2023 08:40:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703004050; cv=none; d=google.com; s=arc-20160816; b=NfSX1+Yg3eZ7WGe+qdiKnfLL8TspVMMUqFZw5e5pELwNN7TQ78Ody9NzfUj495LB/t qQnTrVDrlQ7QpiUXnYpboGWXG23MwauEzQWhBU2/8Fxrfwv9RdW5Xubi2PrwwbrkwVFY NG8QXDmm+LHMsCBYuxGbJoH2bhqgrEKi+LqgIj+W49qvyIKwfM+BtCY1IQgkiUkwIcDU KfFPEFjEfkghBLJqnGqbghqBdIGXWIhbxYVG1ROEKAyIidJ/ZZb31ZSNnitUDbNEsXNn oaKn7kxO2+yTJadHq0NYuWphqXPLt2HlFh7Pl23IHfR3QJjcokZIo7h3dbFHnIZGDfJe Gkaw== 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=QaaTs4MXvHBh+xOHU45v2/aOqOgbRLFCTiPVo6d9HLU=; fh=aAPqvXm40pY9772UiBOljEePwtz/3Q0zIOpw238tj3M=; b=oJIyrZy0BeUZOz3vDL/PzhbZ7tM+d5CPf1NLBRjF6/6/3p5NL/ULInJwouLIlFxZan 3O2sDTy65lwGhxEO+F/XYcQ+tGgZ8Z/Nl9w/96IIlKFJLtvXu/zrAIgxpiQ+2+S8qi3P FRL8h8O7nl0B0aeeW9GamwMYXE0mIJXrOk+FmjKBcvGn5TaKNgOV1N1Xljps3jnLVQRz k0XE4K1aIPubSW8YvM9g8SdSW8HNxL6rFGIS/kXZl1gQJoBhZxkHMtm3RWuINEOij+0w AgSy9wcvRRvPkGrjVhkSYWxPGCc03v+J4LODvOQXk8SiQx6MDF8Wb/9NR7+yqVQuLMd1 HwuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=yNxiNJ4X; spf=pass (google.com: domain of linux-kernel+bounces-5571-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5571-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id j12-20020a508a8c000000b0055251261802si5581906edj.403.2023.12.19.08.40.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 08:40:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-5571-ouuuleilei=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=yNxiNJ4X; spf=pass (google.com: domain of linux-kernel+bounces-5571-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5571-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 316831F25A43 for ; Tue, 19 Dec 2023 16:40:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 005B2210F9; Tue, 19 Dec 2023 16:40:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xen.org header.i=@xen.org header.b="yNxiNJ4X" 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 B819B31A62; Tue, 19 Dec 2023 16:40:15 +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=QaaTs4MXvHBh+xOHU45v2/aOqOgbRLFCTiPVo6d9HLU=; b=yNxiNJ4X2yG2fV6J+MmNju6UNc GuwktGKAayKluHXq+GBal/NRY0RzeI7ChcB/9zhvFiHVf4uKnaG2Of/Aj694O2pCIRio191j2kDjk 7zsglkXldXctTzRiHiTrF4w+ieJBY8puDE9IUAVwnvPOcVCMvvwrXGu1Fqfe1ryXs9us=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rFcjw-0005Lw-T1; Tue, 19 Dec 2023 16:14:40 +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 1rFcjw-0005h9-KR; Tue, 19 Dec 2023 16:14:40 +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 04/19] KVM: pfncache: add a mark-dirty helper Date: Tue, 19 Dec 2023 16:10:54 +0000 Message-Id: <20231219161109.1318-5-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: 1785729175509401572 X-GMAIL-MSGID: 1785729175509401572 From: Paul Durrant At the moment pages are marked dirty by open-coded calls to mark_page_dirty_in_slot(), directly deferefencing the gpa and memslot from the cache. After a subsequent patch these may not always be set so add a helper now so that caller will protected from the need to know about this detail. Signed-off-by: Paul Durrant Reviewed-by: David Woodhouse --- Cc: 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: x86@kernel.org v8: - Make the helper a static inline. --- arch/x86/kvm/x86.c | 2 +- arch/x86/kvm/xen.c | 6 +++--- include/linux/kvm_host.h | 11 +++++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 27e23714e960..0a0ac91a494f 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3156,7 +3156,7 @@ static void kvm_setup_guest_pvclock(struct kvm_vcpu *v, guest_hv_clock->version = ++vcpu->hv_clock.version; - mark_page_dirty_in_slot(v->kvm, gpc->memslot, gpc->gpa >> PAGE_SHIFT); + kvm_gpc_mark_dirty(gpc); read_unlock_irqrestore(&gpc->lock, flags); trace_kvm_pvclock_update(v->vcpu_id, &vcpu->hv_clock); diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c index b63bf54bb376..34c48d0029c1 100644 --- a/arch/x86/kvm/xen.c +++ b/arch/x86/kvm/xen.c @@ -453,11 +453,11 @@ static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic) } if (user_len2) { - mark_page_dirty_in_slot(v->kvm, gpc2->memslot, gpc2->gpa >> PAGE_SHIFT); + kvm_gpc_mark_dirty(gpc2); read_unlock(&gpc2->lock); } - mark_page_dirty_in_slot(v->kvm, gpc1->memslot, gpc1->gpa >> PAGE_SHIFT); + kvm_gpc_mark_dirty(gpc1); read_unlock_irqrestore(&gpc1->lock, flags); } @@ -565,7 +565,7 @@ void kvm_xen_inject_pending_events(struct kvm_vcpu *v) WRITE_ONCE(vi->evtchn_upcall_pending, 1); } - mark_page_dirty_in_slot(v->kvm, gpc->memslot, gpc->gpa >> PAGE_SHIFT); + kvm_gpc_mark_dirty(gpc); read_unlock_irqrestore(&gpc->lock, flags); /* For the per-vCPU lapic vector, deliver it as MSI. */ diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index ea1523a7b83a..64dd616612ed 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1400,6 +1400,17 @@ int kvm_gpc_refresh(struct gfn_to_pfn_cache *gpc, unsigned long len); */ void kvm_gpc_deactivate(struct gfn_to_pfn_cache *gpc); +/** + * kvm_gpc_mark_dirty - mark a cached page as dirty. + * + * @gpc: struct gfn_to_pfn_cache object. + */ +static inline void kvm_gpc_mark_dirty(struct gfn_to_pfn_cache *gpc) +{ + lockdep_assert_held(&gpc->lock); + mark_page_dirty_in_slot(gpc->kvm, gpc->memslot, gpc->gpa >> PAGE_SHIFT); +} + void kvm_sigset_activate(struct kvm_vcpu *vcpu); void kvm_sigset_deactivate(struct kvm_vcpu *vcpu);