From patchwork Mon Jan 16 04:04:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 43963 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1010560wrn; Sun, 15 Jan 2023 20:08:54 -0800 (PST) X-Google-Smtp-Source: AMrXdXvMS1LW28BoXDwSV3GS+S5ZFbrNWW0AvtfirYH7fWNECsv4DSQV92jN7Zf7E5AJvPBJjXR8 X-Received: by 2002:a17:90a:ead2:b0:226:f8dc:b237 with SMTP id ev18-20020a17090aead200b00226f8dcb237mr31338978pjb.31.1673842134157; Sun, 15 Jan 2023 20:08:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673842134; cv=none; d=google.com; s=arc-20160816; b=JgP11fWxWa2aEzmUhkpcwUB6GLJSIfDMDzVq98DJndA9gMSAcfHBb5bgglFrOOY0r2 SbkiL2gp1MyIlzROG3ZZ5Uj6In8EMwEONYcHtBf9sTq7iAbsh6v7pWh5/qbNQ7sL9aru NWM4GQBiRHgVS87Nihj/ko+Ml4bFBGKysvaicceo87rCm4SR6asZPSGHMAyxAUBkzCAF SvPh3VKV478c/6KXgRmnjMSjGye/EI8tRDfMekHr5A8aBJPSfVfjNQlfMD15Z2Su97Sx i7fy7BwVDq1GwQdm5yxDAujAT6MQzMlFaYonIoXE8GC7akoCytMD4GyXX14DRZ3Xg6YH 4jUg== 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=QaWOUNPCOLrCK48ZZkRvvzXiWltPmrtQJNoTHypPAnc=; b=cGKRgeRs5+oVu8Epqlads/gex8c9tFBbWHwuoCCWShz1mKsJ6IwAlBkNT7JE0QFh27 QHsnTh4Ye9FOZmR6IJ4pNm2DwtJROHz+00DkMXVIcJUgJaUia7c0JSDk0eRjaY7rQzM5 3NJ9rd9IlEBwwvoD49olPpSvQwH+frRF7DkdtArcZfffYBfBPEoH41gL9h8nr9KdETFg u+5luzq6u1sMwg0l5UhNGEHXDx5x7me9kmBf7AWQF/VA4Ipl+eZbtbrGO8Lfh7WxNmYS 7uNzMYTzRtFVyNsqATnz/yuKwdOFrhfFg9Lkv43se+GRfVBFZgltlyoOViKBZuVsE8u6 hhyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HKDbWkaD; 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 g6-20020a636b06000000b004788e156154si28764903pgc.360.2023.01.15.20.08.42; Sun, 15 Jan 2023 20:08:54 -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=HKDbWkaD; 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 S231874AbjAPEFv (ORCPT + 99 others); Sun, 15 Jan 2023 23:05:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231831AbjAPEFj (ORCPT ); Sun, 15 Jan 2023 23:05:39 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 548F672B0 for ; Sun, 15 Jan 2023 20:04:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673841890; 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=QaWOUNPCOLrCK48ZZkRvvzXiWltPmrtQJNoTHypPAnc=; b=HKDbWkaDlwvANzXdGDMBuAvQQLQ5wZgG+kfzUKN96ItVWuO08B1eTLHdqFAUx13ulTRGvK 4LOKJxSep5X2Nv+N/e6NPSJoLlwkOjqD64tpL8uxWLDhU9mAjVLoY5Oh/UyJYc6cxN2Pbk MFUrAZbHzwSrdqSCn5TRMAydDtxLIrA= 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-556-v6iwQVNQNJqo5UeIelcYkA-1; Sun, 15 Jan 2023 23:04:45 -0500 X-MC-Unique: v6iwQVNQNJqo5UeIelcYkA-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 3F8691C08DA2; Mon, 16 Jan 2023 04:04:44 +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 44027492B05; Mon, 16 Jan 2023 04:04:36 +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 1/4] KVM: arm64: Allow saving vgic3 LPI pending status in no running vcpu context Date: Mon, 16 Jan 2023 12:04:02 +0800 Message-Id: <20230116040405.260935-2-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?1755150689576176683?= X-GMAIL-MSGID: =?utf-8?q?1755150689576176683?= When dirty ring is enabled, the dirty page information is pushed to the dirty ring if there is a running VCPU context. Otherwise, the dirty page information is still tracked by the backup dirty bitmap. In order to detect if there is a running VCPU context when a guest page becomes dirty, kvm_arch_allow_write_without_running_vcpu() was introduced to warn when no running VCPU context exists on unknown cases. Other than the site of saving ITS tables, it's possible to save vgic3 LPI pending status in no running vcpu context because it can happen when ITS ITE is restored through the command KVM_DEV_ARM_ITS_RESTORE_TABLES on 'kvm-arm-vgic-its' device. Fix it by allowing to save vgic3 LPI pending status in no running vcpu context. Signed-off-by: Gavin Shan --- Documentation/virt/kvm/api.rst | 5 +++-- arch/arm64/kvm/vgic/vgic-its.c | 3 ++- arch/arm64/kvm/vgic/vgic-v3.c | 3 +++ include/kvm/arm_vgic.h | 1 + 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index 9807b05a1b57..18b245a0ba02 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -8071,8 +8071,9 @@ state is final and avoid missing dirty pages from another ioctl ordered after the bitmap collection. NOTE: One example of using the backup bitmap is saving arm64 vgic/its -tables through KVM_DEV_ARM_{VGIC_GRP_CTRL, ITS_SAVE_TABLES} command on -KVM device "kvm-arm-vgic-its" when dirty ring is enabled. +tables and vgic3 LPI pending status through KVM_DEV_ARM_{VGIC_GRP_CTRL, +ITS_SAVE_TABLES} and KVM_DEV_ARM_{VGIC_GRP_CTRL, ITS_RESTORE_TABLES} +command on KVM device "kvm-arm-vgic-its" when dirty ring is enabled. 8.30 KVM_CAP_XEN_HVM -------------------- diff --git a/arch/arm64/kvm/vgic/vgic-its.c b/arch/arm64/kvm/vgic/vgic-its.c index 94a666dd1443..119a9c7a0a52 100644 --- a/arch/arm64/kvm/vgic/vgic-its.c +++ b/arch/arm64/kvm/vgic/vgic-its.c @@ -2792,7 +2792,8 @@ bool kvm_arch_allow_write_without_running_vcpu(struct kvm *kvm) { struct vgic_dist *dist = &kvm->arch.vgic; - return dist->save_its_tables_in_progress; + return dist->save_vgic_v3_tables_in_progress || + dist->save_its_tables_in_progress; } static int vgic_its_set_attr(struct kvm_device *dev, diff --git a/arch/arm64/kvm/vgic/vgic-v3.c b/arch/arm64/kvm/vgic/vgic-v3.c index 2074521d4a8c..32998c8587a8 100644 --- a/arch/arm64/kvm/vgic/vgic-v3.c +++ b/arch/arm64/kvm/vgic/vgic-v3.c @@ -304,6 +304,7 @@ void vgic_v3_enable(struct kvm_vcpu *vcpu) int vgic_v3_lpi_sync_pending_status(struct kvm *kvm, struct vgic_irq *irq) { struct kvm_vcpu *vcpu; + struct vgic_dist *dist = &kvm->arch.vgic; int byte_offset, bit_nr; gpa_t pendbase, ptr; bool status; @@ -339,7 +340,9 @@ int vgic_v3_lpi_sync_pending_status(struct kvm *kvm, struct vgic_irq *irq) if (status) { /* clear consumed data */ val &= ~(1 << bit_nr); + dist->save_vgic_v3_tables_in_progress = true; ret = kvm_write_guest_lock(kvm, ptr, &val, 1); + dist->save_vgic_v3_tables_in_progress = false; if (ret) return ret; } diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h index 9270cd87da3f..0485b4e82b00 100644 --- a/include/kvm/arm_vgic.h +++ b/include/kvm/arm_vgic.h @@ -264,6 +264,7 @@ struct vgic_dist { bool has_its; bool save_its_tables_in_progress; + bool save_vgic_v3_tables_in_progress; /* * Contains the attributes and gpa of the LPI configuration table. From patchwork Mon Jan 16 04:04:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 43962 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1010460wrn; Sun, 15 Jan 2023 20:08:28 -0800 (PST) X-Google-Smtp-Source: AMrXdXt+3+1ls3hwzNaUDYIy8coqlKQhXJaZGcx9qyYTQV8899f2l+0tFXdMUpdWQhqRy9ZDiPOc X-Received: by 2002:a05:6a21:3a94:b0:9d:efbe:52c3 with SMTP id zv20-20020a056a213a9400b0009defbe52c3mr41552697pzb.51.1673842108677; Sun, 15 Jan 2023 20:08:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673842108; cv=none; d=google.com; s=arc-20160816; b=NTYhvH1RUtGnUFRX+Imzt4qtr/fObCMx9hRqTbS5pXhJ24El4/8t+RIbTjVLv6GBUA fh7oUyDoUCVNpny/Me+H/ZrbZPIr5zl5CQvZtQx+puZ3sKd5pDmU59KRF9M1VDe5yM8/ 1SFJFxmHkeZXZ/8DT/WweYGYcWEOyBIgsizMilnJhjjhFbSjbhP6klgmdDI7UzzdBlua ik4CjKeBSliC1EUwThH/9SZ4A9Kzrp1xM+zH+co9B4kAXNRuAf+CzKszM0/NZnYKHmvd id1fYQtHllc5OtxXqRio5WZL1jAO049IL8GTU+Jttlf5oPmc5vUziq7gtzVyuXaFAQzc YJ2g== 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=bA+wbP792KXwkm3/fGkTmvYSd+miHBdshWBI6pE7H5E=; b=edbPoGLjN1GN9XMB8Z7g/TbCRaAAaGioO04fnL3su+iNbAKQVUbys7480aXGq+21O4 vcjOe9nJ1ft7kczJ7wjhizJKS7ynPQXIXpZqJ9yElCe+dDAXi1Yvy+gmfqY3M8q9s7KV ycyl0lxG6HGIrAElpeB+n6xxef36SPH/pUt5+7H0q12uu91UAvTB/1JKB4qi8bCBumsu R4nzeRDdzmG1Ra9pHnoPYOY0OOXn7RBVy4Eydk3XxtYn7ml9u/KE+6c2fR+I5XFjcvCr s+qOSIaugRyJfMMSNvfEe4XBpe8CZdR0jfPAmYJqW0kcSLCcmUp4B8gKdgQ5OMNL5azq 7bdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bD0ez8qv; 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 g11-20020a63520b000000b00476f2b0b330si28022746pgb.700.2023.01.15.20.08.16; Sun, 15 Jan 2023 20:08:28 -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=bD0ez8qv; 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 S231828AbjAPEFq (ORCPT + 99 others); Sun, 15 Jan 2023 23:05:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231721AbjAPEFh (ORCPT ); Sun, 15 Jan 2023 23:05:37 -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 64D1383EA for ; Sun, 15 Jan 2023 20:04:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673841898; 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=bA+wbP792KXwkm3/fGkTmvYSd+miHBdshWBI6pE7H5E=; b=bD0ez8qvAjjDAoE3ZQJtffTTrJu2zJm+q37v56usfR8Cqa8oJufpMWkg1gR4LEy2sPYl5D t8NPuk5sI3ky3sK9mTMVMGRE/bD3PBES4dDSCAiQKyAWsaB8PQ8QA41yRlsz+cPGdZ+gZt vsgQ1yIrYep9ZcYyw+uaEZXbT+wF/aw= 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-25-8MvBQx6yPoCdaaYFkjo74w-1; Sun, 15 Jan 2023 23:04:52 -0500 X-MC-Unique: 8MvBQx6yPoCdaaYFkjo74w-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 CBA301C08DA5; Mon, 16 Jan 2023 04:04:51 +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 D0EAD492B05; Mon, 16 Jan 2023 04:04:44 +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 2/4] KVM: arm64: Allow saving vgic3 pending tables in no running vcpu context Date: Mon, 16 Jan 2023 12:04:03 +0800 Message-Id: <20230116040405.260935-3-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=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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755150662865750362?= X-GMAIL-MSGID: =?utf-8?q?1755150662865750362?= It's possible to save vgic3 pending tables in no running VCPU context. This is another unknown case detected by 'kvm-unit-tests'. # ./kvm-unit-tests/tests/its-pending-migration WARNING: CPU: 120 PID: 7973 at arch/arm64/kvm/../../../virt/kvm/kvm_main.c:3325 \ mark_page_dirty_in_slot+0x60/0xe0 : mark_page_dirty_in_slot+0x60/0xe0 __kvm_write_guest_page+0xcc/0x100 kvm_write_guest+0x7c/0xb0 vgic_v3_save_pending_tables+0x148/0x2a0 vgic_set_common_attr+0x158/0x240 vgic_v3_set_attr+0x4c/0x5c kvm_device_ioctl+0x100/0x160 __arm64_sys_ioctl+0xa8/0xf0 invoke_syscall.constprop.0+0x7c/0xd0 el0_svc_common.constprop.0+0x144/0x160 do_el0_svc+0x34/0x60 el0_svc+0x3c/0x1a0 el0t_64_sync_handler+0xb4/0x130 el0t_64_sync+0x178/0x17c Fix it by allowing to save VGIC3 pending tables in no running VCPU context. Reported-by: Zenghui Yu Signed-off-by: Gavin Shan --- Documentation/virt/kvm/api.rst | 3 +++ arch/arm64/kvm/vgic/vgic-v3.c | 2 ++ 2 files changed, 5 insertions(+) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index 18b245a0ba02..7cf3d4b77703 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -8074,6 +8074,9 @@ NOTE: One example of using the backup bitmap is saving arm64 vgic/its tables and vgic3 LPI pending status through KVM_DEV_ARM_{VGIC_GRP_CTRL, ITS_SAVE_TABLES} and KVM_DEV_ARM_{VGIC_GRP_CTRL, ITS_RESTORE_TABLES} command on KVM device "kvm-arm-vgic-its" when dirty ring is enabled. +The backup bitmap is also used when vgic3 pending table is saved +through KVM_DEV_ARM_{VGIC_GRP_CTRL, VGIC_SAVE_PENDING_TABLES} command +on KVM device "kvm-arm-vgic-v3". 8.30 KVM_CAP_XEN_HVM -------------------- diff --git a/arch/arm64/kvm/vgic/vgic-v3.c b/arch/arm64/kvm/vgic/vgic-v3.c index 32998c8587a8..1e6b5f19d524 100644 --- a/arch/arm64/kvm/vgic/vgic-v3.c +++ b/arch/arm64/kvm/vgic/vgic-v3.c @@ -440,7 +440,9 @@ int vgic_v3_save_pending_tables(struct kvm *kvm) else val &= ~(1 << bit_nr); + dist->save_vgic_v3_tables_in_progress = true; ret = kvm_write_guest_lock(kvm, ptr, &val, 1); + dist->save_vgic_v3_tables_in_progress = false; if (ret) goto out; } 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); From patchwork Mon Jan 16 04:04:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 43965 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1011490wrn; Sun, 15 Jan 2023 20:12:50 -0800 (PST) X-Google-Smtp-Source: AMrXdXt3HqZ+W3BJvWKx0eLiN5e9SQShDL4KsyTYRMaXuRw0ycx+R1rQSTbjCGqbWm+R6HvjX4hV X-Received: by 2002:a17:906:75b:b0:7e0:eed0:8beb with SMTP id z27-20020a170906075b00b007e0eed08bebmr10858180ejb.41.1673842369994; Sun, 15 Jan 2023 20:12:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673842369; cv=none; d=google.com; s=arc-20160816; b=LK+MLN/2vUR54h8RX1S13nhA3bfG0aNgNqu3Xw8lzxsO888SMLteOtu10Dts2eRy+0 K7CKLFTqTKM1mfMdg+uaHXDU7MRgyu/wslJMuC2NPsLKvHzOFusqqltvNxYnYsuSjSOr mIwxS4mUOogCiCqOTWWxb+swmxx98vh1/UnoAZSF10IhqL3CaE/2ZFSsEKZoaGSXnbD0 SHpYP/0rBmWgXT7t1saV73OfNTNjjXRx6i7oSSbmBrVcq5z223mQeNOucIjJDu/zi3hB 3KBZXf12wqmTy6eRcYpx0/6HR+cFZ98T3QKfOqsDzbh8OEEVY1LXohaLz8BYDilWuzh9 Ojkw== 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=ohcJPZKvAgOpbS44T4QtlSyb+QSlTiMgmt0MSyKR4Gk=; b=FWUa+SDLns45LSuct+1aFAVG6SKF0oPFi+N0Vd2G+QYQAZBxps81hGBpaiECNKk3vQ j+cRaM8WXTx2eMxksYMTVDdIN3IfuAng2ibxj5ZrHKNJ30Z0rtmv6k6GISu7hcm1TWGB 9Bhmgp7iJLEGQBBz8k8pLUULHKcmsX1kmwMUitdBTCqb6u3M0JvQclbe0qgoFyEmYZcQ LtIiuGwmddcSqlrAbLeP1b3EVicaayOeTEEUrj154oPrt53+IgInmbyL/GhZTBOQ/T/R 8RIwzlsyt2/EhtLhA6oAOR4fL1Et5xVzyKHQUeQfoRTv5ikmse9JWGDZYBSeu1kqFVBC 4qVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dByWWlzJ; 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 sd34-20020a1709076e2200b008705d5bb5d1si2517882ejc.951.2023.01.15.20.12.26; Sun, 15 Jan 2023 20:12:49 -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=dByWWlzJ; 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 S231781AbjAPEGl (ORCPT + 99 others); Sun, 15 Jan 2023 23:06:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231932AbjAPEGO (ORCPT ); Sun, 15 Jan 2023 23:06:14 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 357A683F4 for ; Sun, 15 Jan 2023 20:05:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673841911; 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=ohcJPZKvAgOpbS44T4QtlSyb+QSlTiMgmt0MSyKR4Gk=; b=dByWWlzJUlJr4Ilzvfb/vn2zJBtGAdEkS1umPLChqlx/OIekOuVLwkK2ED6xblUFGE13Bq JUaUml7h/yxIRiWdGOJz7q7b7IF0M3aVHmBcSdUX5y7CTAb+APGDXSWN2k38eySkuquzYC tQ86uN2qlorQaaZQOjVLN6jO4Z46otY= 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-404-oZ03pT2jOM-OSGkw5ehlOg-1; Sun, 15 Jan 2023 23:05:08 -0500 X-MC-Unique: oZ03pT2jOM-OSGkw5ehlOg-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 61A6F3828883; Mon, 16 Jan 2023 04:05:07 +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 4DDB0492B05; Mon, 16 Jan 2023 04:05:00 +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 4/4] KVM: Improve warning report in mark_page_dirty_in_slot() Date: Mon, 16 Jan 2023 12:04:05 +0800 Message-Id: <20230116040405.260935-5-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=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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755150936849976380?= X-GMAIL-MSGID: =?utf-8?q?1755150936849976380?= There are two warning reports about the dirty ring in the function. We have the wrong assumption that the dirty ring is always enabled when CONFIG_HAVE_KVM_DIRTY_RING is selected. This leads to warning messages about the dirty ring is reported even the dirty ring isn't enabled by the user space. Actually, the expected behaviour is to report the warning messages only when the dirty ring is enabled, instead of being configured. Fix it by enabling the checks and warning reports when the dirty ring has been enabled by the user space. Signed-off-by: Gavin Shan --- include/linux/kvm_dirty_ring.h | 5 +++++ virt/kvm/kvm_main.c | 25 ++++++++++++++----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/include/linux/kvm_dirty_ring.h b/include/linux/kvm_dirty_ring.h index 4862c98d80d3..3fda0aa42858 100644 --- a/include/linux/kvm_dirty_ring.h +++ b/include/linux/kvm_dirty_ring.h @@ -42,6 +42,11 @@ static inline bool kvm_use_dirty_bitmap(struct kvm *kvm) return true; } +static inline bool kvm_arch_allow_write_without_running_vcpu(struct kvm *kvm) +{ + return false; +} + static inline int kvm_dirty_ring_alloc(struct kvm_dirty_ring *ring, int index, u32 size) { diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 90f538433916..a35c32bc84e1 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3316,26 +3316,29 @@ void mark_page_dirty_in_slot(struct kvm *kvm, const struct kvm_memory_slot *memslot, gfn_t gfn) { - struct kvm_vcpu *vcpu = kvm_get_running_vcpu(); + struct kvm_vcpu *vcpu; unsigned long rel_gfn; u32 slot; -#ifdef CONFIG_HAVE_KVM_DIRTY_RING - if (WARN_ON_ONCE(vcpu && vcpu->kvm != kvm)) - return; - - WARN_ON_ONCE(!vcpu && !kvm_arch_allow_write_without_running_vcpu(kvm)); -#endif - if (!memslot || !kvm_slot_dirty_track_enabled(memslot)) return; 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) + if (kvm->dirty_ring_size) { + vcpu = kvm_get_running_vcpu(); + if (vcpu) { + if (!WARN_ON_ONCE(vcpu->kvm != kvm)) + kvm_dirty_ring_push(vcpu, slot, rel_gfn); + + return; + } + + WARN_ON_ONCE(!kvm_arch_allow_write_without_running_vcpu(kvm)); + } + + if (memslot->dirty_bitmap) set_bit_le(rel_gfn, memslot->dirty_bitmap); } EXPORT_SYMBOL_GPL(mark_page_dirty_in_slot);