From patchwork Mon Jan 16 04:04:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 43964 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1010975wrn; Sun, 15 Jan 2023 20:10:36 -0800 (PST) X-Google-Smtp-Source: AMrXdXsWlMZy+8WruTK/UQip4370AasOLdvRbIn8XzZ/ofbwdAckSNhk8iyMg/6zUUbx4/QZApzs X-Received: by 2002:a17:906:dfe9:b0:84d:378b:8820 with SMTP id lc9-20020a170906dfe900b0084d378b8820mr12119059ejc.18.1673842236037; Sun, 15 Jan 2023 20:10:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673842236; cv=none; d=google.com; s=arc-20160816; b=iq5VcnZB14jGarQyKV9Pk5gMFkx0Pen+8U5p/D7HZ/COv1Q1rokAy7XgdriZ0gLemP uFjL+qDbHEBwBzZ+dl48XCHAYdbbip8EizFHAkJV6ebQ/aart8y/31ryUJI1XbOywT7K yJbGUtgo0MnXD878WRmieFBtEjnYishTjPSnKet/Cqa2iX8KQb0rfVxOZd13zgzwxnEn fAnI4g5to5/haiVPRsjZQNv1Efg+6kRUCvnS3XBq8/iTEP/cP3uDzuFGh6JqjOsXaMrE tCzyus6352AYYo1hy+oYDcRJeZ5bNeNJELTrOROINe2S3BQrqtRZx3vTlkpcXB6c4NC5 qLWQ== 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:cc:to:from :dkim-signature; bh=h7h2CvV8GXjZs4C73BUDvN+HXzxZqbt6pIrQ0tWeaXU=; b=j3x18AKAWo8wcXmBXdFw0I6fcyrsUKcsER2vjLWZljx4zYX96W/gRRM3UVwCeBhBEk xu3kHWnq7HXcMQ9gd5Q471D/NOMkElbaa6dfNo7YsABzT++ivioiBs9aF+nbGE9egK0i O8dF28SNvJV98nJ03vjOCTblrHMFCxfqfQ/CMSWIcrvaQ289/sWS23uB5h0vU0K66aBD wjzX0pbi7hTMKZZFusWIF+DFMcF0Xwa07Tf+kPMPSaBROO6ukCnaWJahrbalMOTk/ucr +saxJD7OfKSOiWXVD/gt710EOmbrOEiC3O+u7IZxvuTWI1mL7bNP54TwZuclF4+aggQ2 5DtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gdUb3NA1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xb3-20020a170907070300b007c1727f7c57si30393415ejb.243.2023.01.15.20.10.12; Sun, 15 Jan 2023 20:10:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gdUb3NA1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231964AbjAPEGc (ORCPT + 99 others); Sun, 15 Jan 2023 23:06:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231887AbjAPEFz (ORCPT ); Sun, 15 Jan 2023 23:05:55 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1655A83F1 for ; Sun, 15 Jan 2023 20:05:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673841906; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h7h2CvV8GXjZs4C73BUDvN+HXzxZqbt6pIrQ0tWeaXU=; b=gdUb3NA1uYvxLVZhVaPME0Kxrvzhb9FY3a8E/df/BfSnY/yMbke5F/5QSK8KO39U4IVekb Go48vGq2DInZnsTf3oXxVfx7OZsmlnWiZ3jHPcrCV3CFeR+mEB5HerK4xfwsKYrumbSiY/ TIQYEBvYda3+a0joqog7cKI9FVHpjV4= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-319-QQaliHT-O_6-bWuaXxHQkw-1; Sun, 15 Jan 2023 23:05:00 -0500 X-MC-Unique: QQaliHT-O_6-bWuaXxHQkw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AFF362A59543; Mon, 16 Jan 2023 04:04:59 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-98.bne.redhat.com [10.64.54.98]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 82BCA492B05; Mon, 16 Jan 2023 04:04:52 +0000 (UTC) From: Gavin Shan To: kvmarm@lists.linux.dev Cc: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, pbonzini@redhat.com, maz@kernel.org, corbet@lwn.net, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, ricarkol@google.com, eric.auger@redhat.com, yuzhe@nfschina.com, renzhengeek@gmail.com, ardb@kernel.org, peterx@redhat.com, seanjc@google.com, shan.gavin@gmail.com Subject: [PATCH 3/4] KVM: Refactor mark_page_dirty_in_slot() Date: Mon, 16 Jan 2023 12:04:04 +0800 Message-Id: <20230116040405.260935-4-gshan@redhat.com> In-Reply-To: <20230116040405.260935-1-gshan@redhat.com> References: <20230116040405.260935-1-gshan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755150796370196291?= X-GMAIL-MSGID: =?utf-8?q?1755150796370196291?= Refactor mark_page_dirty_in_slot() to bail early if the memory slot isn't existing or dirty page tracking is disabled on it. It's the preparatory work for the forth coming fixes. No functional change intended. Signed-off-by: Gavin Shan --- virt/kvm/kvm_main.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 9c60384b5ae0..90f538433916 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3317,6 +3317,8 @@ void mark_page_dirty_in_slot(struct kvm *kvm, gfn_t gfn) { struct kvm_vcpu *vcpu = kvm_get_running_vcpu(); + unsigned long rel_gfn; + u32 slot; #ifdef CONFIG_HAVE_KVM_DIRTY_RING if (WARN_ON_ONCE(vcpu && vcpu->kvm != kvm)) @@ -3325,15 +3327,16 @@ void mark_page_dirty_in_slot(struct kvm *kvm, WARN_ON_ONCE(!vcpu && !kvm_arch_allow_write_without_running_vcpu(kvm)); #endif - if (memslot && kvm_slot_dirty_track_enabled(memslot)) { - unsigned long rel_gfn = gfn - memslot->base_gfn; - u32 slot = (memslot->as_id << 16) | memslot->id; + if (!memslot || !kvm_slot_dirty_track_enabled(memslot)) + return; - if (kvm->dirty_ring_size && vcpu) - kvm_dirty_ring_push(vcpu, slot, rel_gfn); - else if (memslot->dirty_bitmap) - set_bit_le(rel_gfn, memslot->dirty_bitmap); - } + rel_gfn = gfn - memslot->base_gfn; + slot = (memslot->as_id << 16) | memslot->id; + + if (kvm->dirty_ring_size && vcpu) + kvm_dirty_ring_push(vcpu, slot, rel_gfn); + else if (memslot->dirty_bitmap) + set_bit_le(rel_gfn, memslot->dirty_bitmap); } EXPORT_SYMBOL_GPL(mark_page_dirty_in_slot);