From patchwork Mon Dec 4 14:43:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 173407 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2808944vqy; Mon, 4 Dec 2023 06:44:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IGeFpeEH5jSFqmAAQhwZHNtiPr01SDGHI9iTBBgqg9G9E911PawcAELMlTn8ZWSteZNnI+n X-Received: by 2002:a17:902:8f96:b0:1c9:c6f4:e0c3 with SMTP id z22-20020a1709028f9600b001c9c6f4e0c3mr4022154plo.62.1701701072801; 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=GoU+UpFQCjpVeAw8c4HEinCSNFd+NWb/u7w+Dr8jq+0RLLndsM6Epg+8dkXY9oBhoo mNZb0DiwdF+kone2an7iGMx1dVrW5CyTAqZip6oYwu+Du86ycQSbJNw/rQeoKiz+Qv5q aJ5/oJZ5d0Rl+IC5MCTBk0u3bqtM9Gj32DQdtQgE5ZLKM/wpEZOdUrTMqmRC7ofOaFkd dwkWHzdwEWfO+qiDE6x7QtZMuPpaGR8L7rwnfz1OSB2Vb3FhJT4Gy4wD5fDyzAkC47jF tKg1gPfhN7iQGF8B3uFTLcOsJHe6SkrQQRNH9OcixvmDDDVSxTy/1Hw5f9LN9U0Ex2RC JNVw== 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=AcWxJ2IxmvvwuaaDlz6mRCIARKvPvTaq2blqqhPlBQc=; fh=aAPqvXm40pY9772UiBOljEePwtz/3Q0zIOpw238tj3M=; b=Fbe/slvsi2atgXJibFQ9sMfYmdH4YpGxfALXzBwL4m7/zummc23yO9yb5K9O9RpcOz fSaap+V38Rroz5SJ1sgBi+mRJ9PMqw8CN87eoap7jx1smPX2K7rVI4tMJZOpgtS7ZqEa 0MBSIsNHYJ5Jx+uExQGNzVl1LEVhJ0/e9XDp8WAaq7Rx0O/h6jXbOP22nOARAge0q06S 9Jjx5XldNHmZHeBw9o6uMj/abfQKaN7FT/WnXTAND+XJRxdmv1qcnvHtnvufAV9TKI3C Oo10nCQrwvgs+0CuFrJMG1Slw/73lPO/hQBCfn6UkzUiI6/fc4cJqP7eGh4sN5PYf2Fd FX+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=eN7tjOJv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id q18-20020a17090311d200b001cc282684c6si8123086plh.278.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:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=eN7tjOJv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 7B70F80A9184; Mon, 4 Dec 2023 06:44:31 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345730AbjLDOoT (ORCPT + 99 others); Mon, 4 Dec 2023 09:44:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233602AbjLDOoP (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 B2A45DF; Mon, 4 Dec 2023 06:44:19 -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=AcWxJ2IxmvvwuaaDlz6mRCIARKvPvTaq2blqqhPlBQc=; b=eN7tjOJvWw6JAvqd04dEWa+xuv GBEfBh0NdUFzs5OGO6C7nSLHLVs0rJV26jwPVNiRy0lmZCH+x4HkmXKeNjNDxtodaQkp0hSryq+wg /fPWt10fE+E2Ma0ZOWrrUG2L0bblJViLUTPon9oIY7VyOOcAqK22Bm+tFG90eddcEEAQ=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rAAB1-0003eP-OG; Mon, 04 Dec 2023 14:44:03 +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 1rAAB1-00088g-Eu; Mon, 04 Dec 2023 14:44:03 +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 04/19] KVM: pfncache: add a mark-dirty helper Date: Mon, 4 Dec 2023 14:43:19 +0000 Message-Id: <20231204144334.910-5-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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 04 Dec 2023 06:44:31 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784362903716172133 X-GMAIL-MSGID: 1784362903716172133 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 1983947b8965..09827c07be61 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3148,7 +3148,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 426306022c2f..41a7c03f7204 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);