From patchwork Thu Feb 15 15:28:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 201561 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:b825:b0:106:860b:bbdd with SMTP id da37csp479333dyb; Thu, 15 Feb 2024 07:32:35 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUOxmNkHX3ciWM9aHtnlUeCCp1k5CNjzdZtvsYOEG+T2xX7SK9PrtAEoeDXMM8/bESCTgTNUTKXpydZdDNTd6UIGSEOJQ== X-Google-Smtp-Source: AGHT+IHrkGWWqABk1zDBkyMa94i30UrVmWFpbOUifG5WcOQbmVqHQlk+nw9V1yGJbDlgpYmd9FvZ X-Received: by 2002:a05:620a:1377:b0:785:b03a:7798 with SMTP id d23-20020a05620a137700b00785b03a7798mr2099640qkl.18.1708011155356; Thu, 15 Feb 2024 07:32:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708011155; cv=pass; d=google.com; s=arc-20160816; b=GZWR8VRZ4YyrwMqgUL/I9ZZCqwE3TLCBPwh2CfsIjcSXZPgKILyV7ErwA4QoDqHWd/ OtRdQELC2zPwbPNUwwP6ttXdAJ0wPtIRlLc5xY2JGSOt+CeWv1WY+7gjebfubnjK0hzF CO+lFO60b60QcPHVCc/Ow5w1GTbm7+XGS2SSHXvNo1S80HhdYrc1Fetjfl2hKIf6SmV0 +KwNMwdboeXxe8lekDuqvd/6Jr9A6JWS9Nw3lUUFMhvgq1AHAd1UwVmsFZHrYyY2GML1 jitFfcs7k9mDUTevIj+PSXauWa4rnbiX8iVsCsoOw9gZRqL/wgf559G5G8Q63xVJihyP lFgw== ARC-Message-Signature: i=2; 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=dgg90eY5E+PlYWhnmyGMGapEm6KwHKu4vEv19gqCPLo=; fh=NrOggL3VZvuSFh5W9Wj2+kLgS4v0nogfnAWvBJoouXQ=; b=RVXK/VLCf+YRGm4zjEjk8a+H2bSqlK9dxjegUCfG2WQlezOXh9mB8GlBRckgXqmnHH E+Myt3Pb2n2Adg2O99EdLwywKO6C3fU2khn8L3KYQBROkHrS4Gp8VrMVG1TF9kTaav1k fclT6Yh5rgOyeTMT/GrDaaVsUgI9n7l5bCFgvhRbL6scCiXtg97yZkmNsXXY9eQCx7Sw +/5s34OFqTsi6nNtxH2fDLN5AJBLiNsEaRMLcj6k68K+U1zmcBfv/h/lE8EVp/zN3wdF qalFB06/Ca5uO2hvUaSH00rYmMKY2K5VSzYaKnEk7xlBQ4ZsNctnYY8JQC5a4WXQ//zf pwcA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=R6SABlyO; arc=pass (i=1 spf=pass spfdomain=xen.org dkim=pass dkdomain=xen.org); spf=pass (google.com: domain of linux-kernel+bounces-67183-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67183-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id f16-20020ac84710000000b0042bee82eeb1si1506198qtp.633.2024.02.15.07.32.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 07:32:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-67183-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@xen.org header.s=20200302mail header.b=R6SABlyO; arc=pass (i=1 spf=pass spfdomain=xen.org dkim=pass dkdomain=xen.org); spf=pass (google.com: domain of linux-kernel+bounces-67183-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67183-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id A5ED91C23BCB for ; Thu, 15 Feb 2024 15:31:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 15C3F134CEF; Thu, 15 Feb 2024 15:30:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xen.org header.i=@xen.org header.b="R6SABlyO" 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 BB137133439; Thu, 15 Feb 2024 15:30:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=104.130.215.37 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708011035; cv=none; b=Y7JmPw/MkDvocQowXwfS8ot5MKEz6q2YWWMmzkL9lTpRnLyPZA4FPpBTMUuEnTBCudXl7t4xF7dFwUorJOUWTiI9i40hfa+X97vHrbnkYc5ChyZCgkPvZS7MC/cLilkjDX+i0EOmik6e3AFP+zh31e6k3vimsvQl/siRQpEDCBk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708011035; c=relaxed/simple; bh=Gjh7KJhrYjooGejRnZYLbWryu6U81mbFlCjbGUevu7k=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rxOtF+1yv6KjaxpNSeWmzj7/2906U4VuRUb8d551AhVlzpm/3W2VlibSmxgp+q0Wo+LSagIQuZ/uYVAUq5ZnbZEBigZinqETU4g6m5K484B1aRUQ4s39++4GcxGxfk1efRbhsbyAWd1gghHKuUlKifi2FBmHGb2cz+57JCApXJE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org; spf=pass smtp.mailfrom=xen.org; dkim=pass (1024-bit key) header.d=xen.org header.i=@xen.org header.b=R6SABlyO; arc=none smtp.client-ip=104.130.215.37 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=dgg90eY5E+PlYWhnmyGMGapEm6KwHKu4vEv19gqCPLo=; b=R6SABlyOYDCcI7WdYVjD8zW0zg Mgct0KIHxF04fvoHoDoAv7J9JHQjKIF5Qj4ykX1Tel7BWJt2gZHDVlL/O3APTkj352N6cjQhPrV7S 3Bjr8kCunaEB68GLNH+sWl2HTQiG8Q2banvc4O0NEhqIL86gNCiCbrx2rkNOeOhpP3M0=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1radgn-0001EK-JP; Thu, 15 Feb 2024 15:30:17 +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 1radgn-00089r-AZ; Thu, 15 Feb 2024 15:30:17 +0000 From: Paul Durrant To: Paolo Bonzini , Jonathan Corbet , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , David Hildenbrand , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Sven Schnelle , 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-s390@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v13 04/21] KVM: pfncache: add a mark-dirty helper Date: Thu, 15 Feb 2024 15:28:59 +0000 Message-Id: <20240215152916.1158-5-paul@xen.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240215152916.1158-1-paul@xen.org> References: <20240215152916.1158-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: 1790979505319217471 X-GMAIL-MSGID: 1790979505319217471 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 v13: - s/kvm_gpc_mark_dirty/kvm_gpc_mark_dirty_in_slot - Add a check for a NULL memslot pointer v8: - Make the helper a static inline. --- arch/x86/kvm/x86.c | 2 +- arch/x86/kvm/xen.c | 6 +++--- include/linux/kvm_host.h | 13 +++++++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index b66c45e7f6f8..16269430006f 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3151,7 +3151,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_in_slot(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 f3327508ae41..2d001a9c6378 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_in_slot(gpc2); read_unlock(&gpc2->lock); } - mark_page_dirty_in_slot(v->kvm, gpc1->memslot, gpc1->gpa >> PAGE_SHIFT); + kvm_gpc_mark_dirty_in_slot(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_in_slot(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 bbfefd7e612f..5a27b4389d32 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1398,6 +1398,19 @@ 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_in_slot - mark a cached guest page as dirty. + * + * @gpc: struct gfn_to_pfn_cache object. + */ +static inline void kvm_gpc_mark_dirty_in_slot(struct gfn_to_pfn_cache *gpc) +{ + lockdep_assert_held(&gpc->lock); + if (gpc->memslot) + 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);