From patchwork Wed Nov 22 12:18:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 168334 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp1281002vqb; Wed, 22 Nov 2023 04:23:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IGmb85ZP1dSwyQSi5KS/1+G9NmqfO8+3Ezoq1V7BhWl4/Vu8GTtA/XFC/9lhj/hJQkv/I5G X-Received: by 2002:a17:90b:3750:b0:280:1022:f00e with SMTP id ne16-20020a17090b375000b002801022f00emr2268187pjb.29.1700655774082; Wed, 22 Nov 2023 04:22:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700655774; cv=none; d=google.com; s=arc-20160816; b=IHub3dt32kH+2wX70fPMSQFJhN/bBDrFMIFJ9uohk6asFWtlAGByUeWgD89q3Y0H9r fOdyh7C99WRi1B+OMaKZl9AceTYo3ZTjfLTw0IZeOhS9ilpJFZEarfkbj7Gxr0fqnLKe SbAssGuYC2JwsxNhcNDtAV01POAZ6cZ8y9wdZXzjBowfOQvJk00qaLFpOD8VYZOJpX8k Re2uMDGywjnyPnQxEpZVnGO6Wg4tVIGKgvPnelJGD9AhU+vigbGd0Hj//bB9rm9J51JJ 0KcjtvX64yZ6XT4dJZS4uY0UK8Lg8TJRu3ma7BllY1HpzmXY6Ja5o8GUv1kmGN5GXqs/ 1BPA== 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=DQRk/cjLMnalf/maYtILBC/TdCgfY5UqNhefUqwe0Yfybjdgf8KtyyEePEZCTFtkyP Uu6N/nWoxaqQZB0wd8bh/98UoUl2VvA3FK6TjDS62jr4NjprB4SuKRYKnOQKGkH5tdH0 rjEx9VSupg+RzWmorPtAdU36aLPayyOKwW8MXGvuROPrXteDdxQc/8bQhyDvnomqScii vAGU1VJqEilIj3UHJIS6437iFKRiD9PB+yW4UyQ8loLS/VGEWsEVjshNCB4ngi/J6s0Z iWE0UezUqlbgaJk2WyVl2WKv7TJEt/Vqilq3IP83gJgh/wRVligXEGPkSEdW2aVWPRGh avGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=X3c8rCbe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id mm20-20020a17090b359400b00276e95d7657si1360725pjb.33.2023.11.22.04.22.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 04:22:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=X3c8rCbe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 8C7FC81B4AF5; Wed, 22 Nov 2023 04:20:55 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344232AbjKVMUf (ORCPT + 99 others); Wed, 22 Nov 2023 07:20:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344093AbjKVMUL (ORCPT ); Wed, 22 Nov 2023 07:20:11 -0500 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0167F1BDF; Wed, 22 Nov 2023 04:19:35 -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=X3c8rCbe9Wkq+3/XcRI9VxhDwY YcJWwdbOPk+XM/aZhx7zZyb+q8lHUgYgX/qivPTL2T5v7+RxmyAAROnWO7y0eqsvgItX5z3TnooC4 ypQgNjjsyJViNTVUHP9kn5Gup65/6aymgxkbNOYr9qM/y4RZnj9YDVPmE7M3nnZF3b7Y=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r5mCV-0004xD-7Q; Wed, 22 Nov 2023 12:19:27 +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 1r5mCU-0004y9-UU; Wed, 22 Nov 2023 12:19:27 +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 v9 04/15] KVM: pfncache: add a mark-dirty helper Date: Wed, 22 Nov 2023 12:18:11 +0000 Message-Id: <20231122121822.1042-5-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231122121822.1042-1-paul@xen.org> References: <20231122121822.1042-1-paul@xen.org> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email 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 (agentk.vger.email [0.0.0.0]); Wed, 22 Nov 2023 04:20:55 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783266828780819086 X-GMAIL-MSGID: 1783266828780819086 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);