Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp583249rdf; Tue, 21 Nov 2023 10:17:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IGSD59tHl4ALyxHwSEras4pRB2KZpYCXQUBvwzgwwMoTlF5GrJyImJmNVN3bIFy1rLKZpcE X-Received: by 2002:a17:902:d48a:b0:1cf:65e1:b767 with SMTP id c10-20020a170902d48a00b001cf65e1b767mr6240281plg.26.1700590639933; Tue, 21 Nov 2023 10:17:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700590639; cv=none; d=google.com; s=arc-20160816; b=01Y3Yj2LPr/i2Dtvxd4IrRG/EXVA5yiz5brQy1DPPC+PhCLYZezMsaSrziArP/LaVG 2wkNlOq7b2zhLFGy3J7M5D8SxjlfSXSm9pe+0fKr8l/5d9sf2zjnp5JQubxS159Jd/sg 5X8PejiCal9e/vywR8ynco75Umncmw3WhU2yXGlB0PQ7H5pvzY6SKV+37ZQFNRMDuOOM /VYYuqlV/xGkMPAqLoybjjRE/VS/GF1xjfKHh/GD5O7pFTCp6W7Ogypjbo4fvXFsCNOF O20/6/em0KgFR1Nqlu/pxtogLzKWN+sLgFclxg7qD7dwQTKiuraMdUaT/PEvbpaOLzCI +n0Q== 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=NQsNWrELjG5Cq/2sI7DaoTTJ1sioU7rwnFvf1GPJFQs=; fh=Cum1qOF0YrAzH/5yQjcCBfU63B+V0l01YtzsDBRUOAc=; b=Y3oTyDTfcfMbYJ6AoAd5LOPae/YDcNKR5hwMUY3LcqBh7r02Hn3I9SFrSTC/oF+6dc Ysuq3/ZAttXoGFeCo3CTIoi+cOepZ/X5avSh+yBf9PKk46RX8X2EFiFP64oSBuEY4Wcp vbliGpwYHoca2ZRKO3s7Q+el/AinwCUJxqzu8Wzw3pYICi0zdMvDLFlSzhPjwIzoVrLE rvLlCEh7BFO4EPu+/vDrMFcCWo0Yp+OV0yZBk+HAV/bk2lTCIKA17bBvLgG17xNSAq/0 q7nW7/0v50fjDoQmNa0dbNIS1N/KQqWL871DWdypSgUDMoD0Slo/E5uXR1BX9zV8Fia3 yPOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=oBCMkhgx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id c11-20020a170902aa4b00b001c5fc13fb2dsi10217406plr.294.2023.11.21.10.17.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 10:17:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=oBCMkhgx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 B2371801BA7D; Tue, 21 Nov 2023 10:03:47 -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 S234346AbjKUSDi (ORCPT + 99 others); Tue, 21 Nov 2023 13:03:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234310AbjKUSD2 (ORCPT ); Tue, 21 Nov 2023 13:03:28 -0500 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F7C519E; Tue, 21 Nov 2023 10:03:24 -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=NQsNWrELjG5Cq/2sI7DaoTTJ1sioU7rwnFvf1GPJFQs=; b=oBCMkhgx5AVtxuiRw7K/K1lLhr dCbSJZAdTiYwJX9S3Wkz50Tics7DBPuHnac886shdq6SGqlihTpnUSZ9Smu1jt+xrUkae8zgTxBms n7pul+Iz+Yx44fNl0hjqkN8q8vNWL7KyeoXHuZqlr4w+xrRQxiUzbqJ7wIIlBB8bs1+I=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r5V5a-00084O-DW; Tue, 21 Nov 2023 18:03:10 +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 1r5V5a-0004Z3-4p; Tue, 21 Nov 2023 18:03:10 +0000 From: Paul Durrant To: David Woodhouse , Paul Durrant , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 04/15] KVM: pfncache: add a mark-dirty helper Date: Tue, 21 Nov 2023 18:02:12 +0000 Message-Id: <20231121180223.12484-5-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231121180223.12484-1-paul@xen.org> References: <20231121180223.12484-1-paul@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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]); Tue, 21 Nov 2023 10:03:47 -0800 (PST) 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 | 10 ++++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 2c924075f6f1..f4ebac198ff5 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3145,7 +3145,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 fb6c6109fdca..ae83caa99974 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1367,6 +1367,16 @@ 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) +{ + 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); -- 2.39.2