From patchwork Sat Oct 22 15:48:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emanuele Giuseppe Esposito X-Patchwork-Id: 7901 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1258524wrr; Sat, 22 Oct 2022 08:49:36 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Hgz5Hksu+W5MSfIkvXLd2UlSQunTWOY9ICw9LdUuT++dCvUauQyVMk9QEeS6uhoj+mXZ9 X-Received: by 2002:a17:907:2d1e:b0:78e:2c3b:559f with SMTP id gs30-20020a1709072d1e00b0078e2c3b559fmr20264117ejc.435.1666453775928; Sat, 22 Oct 2022 08:49:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666453775; cv=none; d=google.com; s=arc-20160816; b=l4heTOYpHNBd5vNismep+ERZCCdcOW+t4UJepXzLLUozUsQKcDUSlpv6tvAXvuNTOE GFKxSXt/omWe41iM7sSZ+qgcPSUUVZCr8TaX0LEsbXZ9wtj2ZC5HyoBwDwSZrnm+qqYq RdAvmjixMgnGEl0pb1mJH9Qz4L9MBf4gKxF+bkrql5ZMwtkn5RQLOVYnH+2y+661ZNU8 jjSHMPC13MpPpBm/UykZgOkbNHGlsWRrwqTm4LfsVNGZfC6Harwpy+K/g8sNhxBeNpuP 37pH+FiF8hrgXXMpBe34PZiGWEMKcfrZtT0OuLS3bbMExUZ9Ho143S3azLe596XB6oH8 GI5w== 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=SFuETpa6kYA2kfLTdzptBf2PIFoZB2DGXGMPa7uX8z4=; b=PYKowuzJgi+cXUFYWFPhrBg3glmAezecVDKVx7ClausfjbNDTO8kUx6+eQj6ViSnkw nsGvwX9EZJwZhz9sge9Z6UcBYcrcuqCUSXFNqup6yFDt8bJcZ2iBjkyHZrIm0p5ugvNU SNcBBbmVweNon0PHdtAPbiyuyGAU26cXNFqo0yd9HQApHjs+BjVvATei7fb9u6iv2kJv uw3hDpE2vh8ox6Cc2VF8IUrePQau/UF99FpqTIGghb5J3H1LliXA3V77GDdVCKWFuJSY Y2f0kZQ9OlVpl3a4UKsXskViZt+B9+dZdFHc5DGbov2rdziH2P5ZHGYjPj+nkHj3KUN5 oO3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OiMD00Ws; 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 a7-20020a50e707000000b00459039258b2si20184632edn.289.2022.10.22.08.49.09; Sat, 22 Oct 2022 08:49:35 -0700 (PDT) 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=OiMD00Ws; 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 S229917AbiJVPsf (ORCPT + 99 others); Sat, 22 Oct 2022 11:48:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229889AbiJVPsc (ORCPT ); Sat, 22 Oct 2022 11:48:32 -0400 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 9DC2A25029D for ; Sat, 22 Oct 2022 08:48:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666453707; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SFuETpa6kYA2kfLTdzptBf2PIFoZB2DGXGMPa7uX8z4=; b=OiMD00Wsw/FeM4lo8DUZClX5Lnv/o8U5r+1OrYjTtyPfhjqLXKj6qyxLLTJFqZwGYl8K4u Xtd+TAwqvnuLqUZDbRqjYeRNMe6L21eDgsXRdxPrtT7ERsm1jyax0FUykTLIdZdJ0jbgxq zCLSia6f909+CpCpiMjQ161QamV6Zeo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-465-Pe_Wdq8lNOudrwKkAqkw_g-1; Sat, 22 Oct 2022 11:48:23 -0400 X-MC-Unique: Pe_Wdq8lNOudrwKkAqkw_g-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 56FBE862FEC; Sat, 22 Oct 2022 15:48:22 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id ECC3C4A9268; Sat, 22 Oct 2022 15:48:21 +0000 (UTC) From: Emanuele Giuseppe Esposito To: kvm@vger.kernel.org Cc: Paolo Bonzini , Jonathan Corbet , Maxim Levitsky , Sean Christopherson , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , David Hildenbrand , x86@kernel.org, "H. Peter Anvin" , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Emanuele Giuseppe Esposito Subject: [PATCH 1/4] linux-headers/linux/kvm.h: introduce kvm_userspace_memory_region_list ioctl Date: Sat, 22 Oct 2022 11:48:16 -0400 Message-Id: <20221022154819.1823133-2-eesposit@redhat.com> In-Reply-To: <20221022154819.1823133-1-eesposit@redhat.com> References: <20221022154819.1823133-1-eesposit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Spam-Status: No, score=-2.4 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?1747403434561079266?= X-GMAIL-MSGID: =?utf-8?q?1747403434561079266?= Introduce new KVM_KICK_ALL_RUNNING_VCPUS and KVM_RESUME_ALL_KICKED_VCPUS ioctl that will be used respectively to pause and then resume all vcpus currently executing KVM_RUN in kvm. Signed-off-by: Emanuele Giuseppe Esposito --- include/uapi/linux/kvm.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index eed0315a77a6..d3cba8d4ca91 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -2227,4 +2227,7 @@ struct kvm_s390_zpci_op { /* flags for kvm_s390_zpci_op->u.reg_aen.flags */ #define KVM_S390_ZPCIOP_REGAEN_HOST (1 << 0) +#define KVM_KICK_ALL_RUNNING_VCPUS _IO(KVMIO, 0xd2) +#define KVM_RESUME_ALL_KICKED_VCPUS _IO(KVMIO, 0xd3) + #endif /* __LINUX_KVM_H */ From patchwork Sat Oct 22 15:48:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emanuele Giuseppe Esposito X-Patchwork-Id: 7902 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1259275wrr; Sat, 22 Oct 2022 08:51:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6PETwF2Hg6nuox4JLW9K9pTcLvsa+cVe7s9YL4MwfcM7NzBzYPuFKKKiW5IoFPWQalWyLd X-Received: by 2002:a17:907:320b:b0:780:280:7b72 with SMTP id xg11-20020a170907320b00b0078002807b72mr21031687ejb.146.1666453882060; Sat, 22 Oct 2022 08:51:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666453882; cv=none; d=google.com; s=arc-20160816; b=Lca2HGqdfb4JVqV4rz2obfkbg/RXoULyW9wM/hMIrf1854c7nLxLQyMqitVWrtDk3M z6IP9iSHnH0lAioyVUsOlL0AoMudhNzXO013oA/hvFMP/pXHUZ33WzkKt/OREY5Oa5ck TKP5Os/NbSQk715re4NimjmB39ho62NZ8xA07ih992U9hIX67FgqHD3WcnERMFUWSoCP y7Bf2af4ZUYhXRnsG7e5R9M9qG6+cPuatkrRt6532bI6MOlC9ALyFH1cyfcbf+mH3bbR n/RnYpIRyRblSbpko/qLL4ms+17jDCAlcR5qhXgGqp2S57b6D3ufbnMD6660QthEHcDS jAWA== 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=EDSXo8hsV8NzzkWo+KouABAzM9HOiQi26MuXJl4LsjA=; b=t+SqJHZ/aMoaaa2iXdkUAM7vjt22spa9XTLwk5YHYoozefcpHBD3PFbfgsX9UgaKw4 EKgspH1spP+a4+5x5gxZTeZi4JzHIP1Yhxi4r2Raoi2ib58DgMYUK3DKzmp8sQgWjONU t6RDtgBvRyKT/AJSxnGqbmA9ILF8iToNMkDsB67vYWBPRL1sCm9Whzn9zzkqzwQy6Vxs T1q3PUeKys+zfxWToId0Pqb8BlljqxUGM2eHeNn3DX0x4JCh2wlk3snZuM1jHkjc6znV +oSdpJL2QIHybNtEdGLDpqwT8ks9K8u6mesadrDHRpqryKHqSWAjpFvwIUyl6nYqLQET jlLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JK5ku7k1; 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 z20-20020aa7d414000000b0045915116d33si20080371edq.535.2022.10.22.08.50.57; Sat, 22 Oct 2022 08:51:22 -0700 (PDT) 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=JK5ku7k1; 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 S229920AbiJVPsl (ORCPT + 99 others); Sat, 22 Oct 2022 11:48:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229890AbiJVPsc (ORCPT ); Sat, 22 Oct 2022 11:48:32 -0400 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 20A9967455 for ; Sat, 22 Oct 2022 08:48:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666453707; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EDSXo8hsV8NzzkWo+KouABAzM9HOiQi26MuXJl4LsjA=; b=JK5ku7k1GI8ofebQoJNflX8ULdtgJbQvQSQKkLHnqpTLwXKC4Hmr03paaBhOAxgRshuAUD 6V1hnViORtnf/4lAcPopqI5qfKpMpA1CJctDhI3QvXrrujCOX7iGmlpLGOj44Ed/NDHUSL xxl3hia3Y81H4ntv/sJU5UontazszCA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-612-6wXycPoUPqGmjo96iTbJBQ-1; Sat, 22 Oct 2022 11:48:23 -0400 X-MC-Unique: 6wXycPoUPqGmjo96iTbJBQ-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 BD53585A583; Sat, 22 Oct 2022 15:48:22 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5F96D4A9268; Sat, 22 Oct 2022 15:48:22 +0000 (UTC) From: Emanuele Giuseppe Esposito To: kvm@vger.kernel.org Cc: Paolo Bonzini , Jonathan Corbet , Maxim Levitsky , Sean Christopherson , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , David Hildenbrand , x86@kernel.org, "H. Peter Anvin" , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Emanuele Giuseppe Esposito Subject: [PATCH 2/4] KVM: introduce kvm_clear_all_cpus_request Date: Sat, 22 Oct 2022 11:48:17 -0400 Message-Id: <20221022154819.1823133-3-eesposit@redhat.com> In-Reply-To: <20221022154819.1823133-1-eesposit@redhat.com> References: <20221022154819.1823133-1-eesposit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Spam-Status: No, score=-2.4 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?1747403545951451135?= X-GMAIL-MSGID: =?utf-8?q?1747403545951451135?= Clear the given request in all vcpus of the VM with struct kvm. Signed-off-by: Emanuele Giuseppe Esposito --- Documentation/virt/kvm/vcpu-requests.rst | 3 +++ virt/kvm/kvm_main.c | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/Documentation/virt/kvm/vcpu-requests.rst b/Documentation/virt/kvm/vcpu-requests.rst index 31f62b64e07b..468410dfe84d 100644 --- a/Documentation/virt/kvm/vcpu-requests.rst +++ b/Documentation/virt/kvm/vcpu-requests.rst @@ -36,6 +36,9 @@ its TLB with a VCPU request. The API consists of the following functions:: /* Make request @req of all VCPUs of the VM with struct kvm @kvm. */ bool kvm_make_all_cpus_request(struct kvm *kvm, unsigned int req); + /* Clear request @req of all VCPUs of the VM with struct kvm @kvm. */ + void kvm_clear_all_cpus_request(struct kvm *kvm, unsigned int req); + Typically a requester wants the VCPU to perform the activity as soon as possible after making the request. This means most requests (kvm_make_request() calls) are followed by a call to kvm_vcpu_kick(), diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 584a5bab3af3..c080b93edc0d 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -355,6 +355,16 @@ bool kvm_make_all_cpus_request(struct kvm *kvm, unsigned int req) } EXPORT_SYMBOL_GPL(kvm_make_all_cpus_request); +void kvm_clear_all_cpus_request(struct kvm *kvm, unsigned int req) +{ + unsigned long i; + struct kvm_vcpu *vcpu; + + kvm_for_each_vcpu(i, vcpu, kvm) + kvm_clear_request(req, vcpu); +} +EXPORT_SYMBOL_GPL(kvm_clear_all_cpus_request); + #ifndef CONFIG_HAVE_KVM_ARCH_TLB_FLUSH_ALL void kvm_flush_remote_tlbs(struct kvm *kvm) { From patchwork Sat Oct 22 15:48:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emanuele Giuseppe Esposito X-Patchwork-Id: 7903 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1259680wrr; Sat, 22 Oct 2022 08:52:36 -0700 (PDT) X-Google-Smtp-Source: AMsMyM78nZHx4qKYBzcC36yQMVnpixVOZQpshWjCGVg7rVu/Y/A2JcciRnBTp7R/bITlGmXArEnR X-Received: by 2002:a05:6402:274c:b0:461:9921:60cf with SMTP id z12-20020a056402274c00b00461992160cfmr548217edd.353.1666453955934; Sat, 22 Oct 2022 08:52:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666453955; cv=none; d=google.com; s=arc-20160816; b=p/8aSiSNJJz2DJ56FWSoAfjZcbKsA0F+QHgyFakcFu6xJeLsPKshdjeVZTPxIK7nu6 Rp/8pIzmjeVwqpJb/4EK+Ww8uji3+bsktoU6CDfjurCOtIAUCq5L4qQYjSZZIu/T3Oug dAT4W8j8QYXG4coQvfJ2RxnUJwpQsu4sxvGyCZmu+aIfaWk2KYtoCC/n0xrzda57GFa+ hms1y4zvImkY4fLOMb5P4cMt4tAmsheIJxatubF1xfGetMBfkRr6Z5rXBbsUhR2DSjXk lsGVIjU7oWi4m+vLOEawVUc40NLwpECnhkYTsdxnvAh3n5N5rmbPO3/GLE8XglCQrhoR HZJQ== 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=i+xYh4ED8NY+eSwwcDjW7bMv+eHis2lS261cJxu7qzg=; b=gbvrdxl+2BhHQBiqXfjHDsJemzgGZRHsqJETAKWpbWmkuLdk9mu26urrTNKJjBRATB nB4LkD7X35OZGpmtPGZBWJsFhsAlfoOrw5XlprmCGbrytEuj39Ya9WvAykPYDJujMOWS CXpey/oAwLbOj5t7hDbw/X00Iepq/AuWGabfa/b8ufC383YorkgaXTBBkj7CTOeoG8IU XRQxFeCBGq7iHa8skSqWdkyryaBOUlDtW0cLhEp/P8mPumj9cmeeZ5/oDNjhzcX56jfy b4vbTPVXlwTzTDltkHKI27ejNe5sPGWefHBQuBIZkX7sUOUYJU9IT8dZyRo+fKawk8y2 5d4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="CZgOp/Rx"; 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 hk6-20020a170906c9c600b0077497671e2asi21697270ejb.406.2022.10.22.08.52.10; Sat, 22 Oct 2022 08:52:35 -0700 (PDT) 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="CZgOp/Rx"; 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 S229900AbiJVPsp (ORCPT + 99 others); Sat, 22 Oct 2022 11:48:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229891AbiJVPsc (ORCPT ); Sat, 22 Oct 2022 11:48:32 -0400 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 3F6A924F0F for ; Sat, 22 Oct 2022 08:48:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666453708; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i+xYh4ED8NY+eSwwcDjW7bMv+eHis2lS261cJxu7qzg=; b=CZgOp/Rx10BA42ASxMKapDvLpj8fDMB+QecDc9iaU2zT3bMoxG/KWg+c0G7SJnVGnjjDgl GZnQ98kbHuN1AVI97ihZcHqkpG2RTgIG3otWMidp36L9/GTRTJcYXfv/UVVmbd7tb7jwGu HhJuAxilknplp/RyGNUvxUhK0Q2egok= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-63-cSLsb5qPObusKCwipu1UWA-1; Sat, 22 Oct 2022 11:48:23 -0400 X-MC-Unique: cSLsb5qPObusKCwipu1UWA-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 3122F85A59D; Sat, 22 Oct 2022 15:48:23 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id C65FD4A9279; Sat, 22 Oct 2022 15:48:22 +0000 (UTC) From: Emanuele Giuseppe Esposito To: kvm@vger.kernel.org Cc: Paolo Bonzini , Jonathan Corbet , Maxim Levitsky , Sean Christopherson , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , David Hildenbrand , x86@kernel.org, "H. Peter Anvin" , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Emanuele Giuseppe Esposito Subject: [PATCH 3/4] KVM: introduce memory transaction semaphore Date: Sat, 22 Oct 2022 11:48:18 -0400 Message-Id: <20221022154819.1823133-4-eesposit@redhat.com> In-Reply-To: <20221022154819.1823133-1-eesposit@redhat.com> References: <20221022154819.1823133-1-eesposit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Spam-Status: No, score=-2.4 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?1747403623396310015?= X-GMAIL-MSGID: =?utf-8?q?1747403623396310015?= Right now the semaphore is only used to signal that a vcpu entered KVM_RUN (not necessarly in guest mode, could be also blocked/halted). Later it will be used by specific ioctls (writers) to wait that all vcpus (readers) exit from KVM_RUN. Signed-off-by: Emanuele Giuseppe Esposito --- virt/kvm/kvm_main.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index c080b93edc0d..ae0240928a4a 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -119,6 +119,8 @@ static const struct file_operations stat_fops_per_vm; static struct file_operations kvm_chardev_ops; +static DECLARE_RWSEM(memory_transaction); + static long kvm_vcpu_ioctl(struct file *file, unsigned int ioctl, unsigned long arg); #ifdef CONFIG_KVM_COMPAT @@ -4074,7 +4076,19 @@ static long kvm_vcpu_ioctl(struct file *filp, synchronize_rcu(); put_pid(oldpid); } + /* + * Notify that a vcpu wants to run, and thus could be reading + * memslots. + * If KVM_KICK_ALL_RUNNING_VCPUS runs afterwards, it will have + * to wait that KVM_RUN exited and up_read() is called. + * If KVM_KICK_ALL_RUNNING_VCPUS already returned but + * KVM_RESUME_ALL_KICKED_VCPUS didn't start yet, then there + * is a request pending for the vcpu that will cause it to + * exit KVM_RUN. + */ + down_read(&memory_transaction); r = kvm_arch_vcpu_ioctl_run(vcpu); + up_read(&memory_transaction); trace_kvm_userspace_exit(vcpu->run->exit_reason, r); break; } From patchwork Sat Oct 22 15:48:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emanuele Giuseppe Esposito X-Patchwork-Id: 7904 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1259744wrr; Sat, 22 Oct 2022 08:52:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7ff62+X5p/mMwV3B0Nex/kHyjwS+CmCcyz3Q3BuiU633fdkbTsYiQapKpNhPsWSQISu76V X-Received: by 2002:a17:907:160e:b0:791:8ae7:4fb8 with SMTP id hb14-20020a170907160e00b007918ae74fb8mr21286076ejc.271.1666453966057; Sat, 22 Oct 2022 08:52:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666453966; cv=none; d=google.com; s=arc-20160816; b=TlXS9IILeVXmJGUOCT0b4v3Y4q7CjjQ00JHcTMvKYrfmBFF6EtHmXu+VrH1Qr4q8SA eowxl7P+d26HwOSkTtYZEmqYUCGaAlPkmHNmrzwmgiIrnDF7AR2DR2fQbs2L6tEmX3vF +iDTJ5pxHIIUbE/NsKdPkBskFAp4a18oSE5kcnoaOVsYmQaSwFDhZTITTem5EeoHEAuS EDn/oDmMvVQZka+9WRcEZNNjkgCNW9KIiVkJJOEz3JncDePxE9K6QpQm+FsSNaDVTaVp E7TOwcRF0Akd1cpOFfPUOZr9+vJBkRGuMZn9NlVCq3r4cj0kei66Y86anKbpZmcNVEI2 lxqg== 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=G1V0vMZpfXGyU72nQJGgurcWjMWd4+DUDDvGesYkw+w=; b=otWFK5OpiFFpnGEyF0Xg/lV0Wp8KqepcsXgl7hdo7wZuD9BLNEYbhr2yo8l52Pzl0/ 5jK9adMRVga6qQai3GIkT/CGaWlX8he5NZ9PzpZHqChM0TCTl/tNjaFwGuX21cFSQPEG X6GkJDV96k1RO2ox8V4+IGaVbOYi0zhGXwlMEdRkKz+35ET+CNWx3JOaInQC6lHZDYPr uQIU7d55d14wI3FeXZzTethmx9/XAC+Iks7zHsN7kuObhOovosFU3acL25rOdT7Af0y2 bzazDFIjHd8Yi4UpLz9LytAmvq79yN61zd8qjSs0flZxefUJgf1CPsH2EpIsS0isaAXw COVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TkytolYN; 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 s9-20020a508d09000000b004591f959c3bsi20471835eds.427.2022.10.22.08.52.21; Sat, 22 Oct 2022 08:52:46 -0700 (PDT) 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=TkytolYN; 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 S229975AbiJVPsu (ORCPT + 99 others); Sat, 22 Oct 2022 11:48:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229876AbiJVPsd (ORCPT ); Sat, 22 Oct 2022 11:48:33 -0400 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 BADB524F789 for ; Sat, 22 Oct 2022 08:48:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666453709; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=G1V0vMZpfXGyU72nQJGgurcWjMWd4+DUDDvGesYkw+w=; b=TkytolYNrexfMGbAD7fSZQujch3i2Yz2G/JbPva8cnWwM7eIBe4QsceJs7HM/A3a8AnHCe oHCjPO5eCRlvhcB+jsxjXbkTwqWQdRvWyb6T5ycnG9sUU+MhX2Gsp+3rtYRuXmlUG4YNdD gGc+dz1D9uqJ+j/2F80edbgGr6dWpLc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-103-_KyNeSWwMFydFnCfRiW-Lg-1; Sat, 22 Oct 2022 11:48:24 -0400 X-MC-Unique: _KyNeSWwMFydFnCfRiW-Lg-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 980EC800B30; Sat, 22 Oct 2022 15:48:23 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A31F4A9268; Sat, 22 Oct 2022 15:48:23 +0000 (UTC) From: Emanuele Giuseppe Esposito To: kvm@vger.kernel.org Cc: Paolo Bonzini , Jonathan Corbet , Maxim Levitsky , Sean Christopherson , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , David Hildenbrand , x86@kernel.org, "H. Peter Anvin" , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Emanuele Giuseppe Esposito Subject: [PATCH 4/4] KVM: use signals to abort enter_guest/blocking and retry Date: Sat, 22 Oct 2022 11:48:19 -0400 Message-Id: <20221022154819.1823133-5-eesposit@redhat.com> In-Reply-To: <20221022154819.1823133-1-eesposit@redhat.com> References: <20221022154819.1823133-1-eesposit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Spam-Status: No, score=-2.4 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?1747403633714788400?= X-GMAIL-MSGID: =?utf-8?q?1747403633714788400?= Once a vcpu exectues KVM_RUN, it could enter two states: enter guest mode, or block/halt. Use a signal to allow a vcpu to exit the guest state or unblock, so that it can exit KVM_RUN and release the read semaphore, allowing a pending KVM_KICK_ALL_RUNNING_VCPUS to continue. Note that the signal is not deleted and used to propagate the exit reason till vcpu_run(). It will be clearead only by KVM_RESUME_ALL_KICKED_VCPUS. This allows the vcpu to keep try entering KVM_RUN and perform again all checks done in kvm_arch_vcpu_ioctl_run() before entering the guest state, where it will return again if the request is still set. However, the userspace hypervisor should also try to avoid continuously calling KVM_RUN after invoking KVM_KICK_ALL_RUNNING_VCPUS, because such call will just translate in a back-to-back down_read() and up_read() (thanks to the signal). Signed-off-by: Emanuele Giuseppe Esposito --- arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/kvm/x86.c | 8 ++++++++ virt/kvm/kvm_main.c | 21 +++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index aa381ab69a19..d5c37f344d65 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -108,6 +108,8 @@ KVM_ARCH_REQ_FLAGS(30, KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP) #define KVM_REQ_MMU_FREE_OBSOLETE_ROOTS \ KVM_ARCH_REQ_FLAGS(31, KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP) +#define KVM_REQ_USERSPACE_KICK \ + KVM_ARCH_REQ_FLAGS(32, KVM_REQUEST_WAIT) #define CR0_RESERVED_BITS \ (~(unsigned long)(X86_CR0_PE | X86_CR0_MP | X86_CR0_EM | X86_CR0_TS \ diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index b0c47b41c264..2af5f427b4e9 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -10270,6 +10270,10 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) } if (kvm_request_pending(vcpu)) { + if (kvm_test_request(KVM_REQ_USERSPACE_KICK, vcpu)) { + r = -EINTR; + goto out; + } if (kvm_check_request(KVM_REQ_VM_DEAD, vcpu)) { r = -EIO; goto out; @@ -10701,6 +10705,10 @@ static int vcpu_run(struct kvm_vcpu *vcpu) r = vcpu_block(vcpu); } + /* vcpu exited guest/unblocked because of this request */ + if (kvm_test_request(KVM_REQ_USERSPACE_KICK, vcpu)) + return -EINTR; + if (r <= 0) break; diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index ae0240928a4a..13fa7229b85d 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3431,6 +3431,8 @@ static int kvm_vcpu_check_block(struct kvm_vcpu *vcpu) goto out; if (kvm_check_request(KVM_REQ_UNBLOCK, vcpu)) goto out; + if (kvm_test_request(KVM_REQ_USERSPACE_KICK, vcpu)) + goto out; ret = 0; out: @@ -4668,6 +4670,25 @@ static long kvm_vm_ioctl(struct file *filp, r = kvm_vm_ioctl_enable_cap_generic(kvm, &cap); break; } + case KVM_KICK_ALL_RUNNING_VCPUS: { + /* + * Notify all running vcpus that they have to stop. + * Caught in kvm_arch_vcpu_ioctl_run() + */ + kvm_make_all_cpus_request(kvm, KVM_REQ_USERSPACE_KICK); + + /* + * Use wr semaphore to wait for all vcpus to exit from KVM_RUN. + */ + down_write(&memory_transaction); + up_write(&memory_transaction); + break; + } + case KVM_RESUME_ALL_KICKED_VCPUS: { + /* Remove all requests sent with KVM_KICK_ALL_RUNNING_VCPUS */ + kvm_clear_all_cpus_request(kvm, KVM_REQ_USERSPACE_KICK); + break; + } case KVM_SET_USER_MEMORY_REGION: { struct kvm_userspace_memory_region kvm_userspace_mem;