From patchwork Fri Jan 4 08:53:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 10748143 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 946EE6C5 for ; Fri, 4 Jan 2019 08:54:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8550D27F94 for ; Fri, 4 Jan 2019 08:54:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7898327FA5; Fri, 4 Jan 2019 08:54:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A1BE427F94 for ; Fri, 4 Jan 2019 08:54:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727042AbfADIy2 (ORCPT ); Fri, 4 Jan 2019 03:54:28 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:41828 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727010AbfADIy2 (ORCPT ); Fri, 4 Jan 2019 03:54:28 -0500 Received: by mail-pl1-f195.google.com with SMTP id u6so17152437plm.8; Fri, 04 Jan 2019 00:54:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=i8dTC8urZcLwzyeR/Vu4fyO0uZy0FNHekKBQ29Y6YMc=; b=bdMxIz2guzLdRdqjth6wjnjPZpbVIL8eDJoyDtFD6lpVDG7+fysF4tr92TwaeGD1UJ qRmQlP4GDRzHhqiUly7mOgKQGoRufG5jOxCQprD7BlFuSMnoSILnCdYWNYs+6Ifx/Sln BGPnkmqSEvmUauOGa4FkchQZedbLOMT0dOl6y1mzlvMOjHfyYIKmxF2lovPJcLAPFIyg gILasOp6WzoJ3XwF459ntkbpt1eusiDJxR2P1Wx8GAlWuPYMWPGZ7tqoeLUStKpgHcy+ lM5Z8J2RLqWHa11em3HaSKFHjEgz+xGNaSjMe9S5fSyqT57yTB128mxRtrlcPWt36UEC q27A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=i8dTC8urZcLwzyeR/Vu4fyO0uZy0FNHekKBQ29Y6YMc=; b=Kqzd/zts0WBWRsVQ2aviZAePf7bi2hOJIimFgq3MC61njQWzoKwXc1rmHufz0TtlOq KUnjs9ZJ774uOE84wV1PUUfKyGIqZozUJjlG8C527UUvhNqjd9smzTN73q0BVnhtBDoy 9uyLOx2S0OoPFLNRQm8in7yG99EVJxvySjy2Uh/c++WvgF4uQswKE0/1UU2G9BtZZoc3 1za7SThCEgnrXzpqBvu9VkXBvfK2KLQci7zEAIX3kEfybh4F099FhsW7YzkjPwR/5eVX 8HRfEALvjsq8gf+JvK16HdQk0a/SdsU4mNBHUH04qbyuKRVwMdo0lLfyOPWAoMqUVNi9 3tyQ== X-Gm-Message-State: AJcUukevbvZ/h0FYOsPcZW/qPpspN6yyjvv6ils8AyQJgW/fGcb/EvZp HvDPouWVnzOqgqfbueWU6s4= X-Google-Smtp-Source: ALg8bN7Hd/i8EVRwXrchiQNQpGOa141b9ceEW8y8b4HLeNCBSzMideSbEpZ9osZHG5VKjOcZ5XywAA== X-Received: by 2002:a17:902:59c8:: with SMTP id d8mr50066601plj.116.1546592067395; Fri, 04 Jan 2019 00:54:27 -0800 (PST) Received: from localhost.corp.microsoft.com ([2404:f801:9000:1a:d9bd:62c6:740b:9fc4]) by smtp.googlemail.com with ESMTPSA id i21sm99772145pgm.17.2019.01.04.00.54.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Jan 2019 00:54:26 -0800 (PST) From: lantianyu1986@gmail.com X-Google-Original-From: Tianyu.Lan@microsoft.com Cc: Lan Tianyu , christoffer.dall@arm.com, marc.zyngier@arm.com, linux@armlinux.org.uk, catalin.marinas@arm.com, will.deacon@arm.com, jhogan@kernel.org, ralf@linux-mips.org, paul.burton@mips.com, paulus@ozlabs.org, benh@kernel.crashing.org, mpe@ellerman.id.au, kys@microsoft.com, haiyangz@microsoft.com, sthemmin@microsoft.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, x86@kernel.org, pbonzini@redhat.com, rkrcmar@redhat.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, kvm-ppc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, devel@linuxdriverproject.org, kvm@vger.kernel.org, michael.h.kelley@microsoft.com, vkuznets@redhat.com Subject: [PATCH 1/11] X86/Hyper-V: Add parameter offset for hyperv_fill_flush_guest_mapping_list() Date: Fri, 4 Jan 2019 16:53:55 +0800 Message-Id: <20190104085405.40356-2-Tianyu.Lan@microsoft.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20190104085405.40356-1-Tianyu.Lan@microsoft.com> References: <20190104085405.40356-1-Tianyu.Lan@microsoft.com> To: unlisted-recipients:; (no To-header on input) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Lan Tianyu Add parameter offset to specify start position to add flush ranges in guest address list of struct hv_guest_mapping_flush_list. Signed-off-by: Lan Tianyu --- arch/x86/hyperv/nested.c | 4 ++-- arch/x86/include/asm/mshyperv.h | 2 +- arch/x86/kvm/vmx/vmx.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/hyperv/nested.c b/arch/x86/hyperv/nested.c index dd0a843f766d..96f8bac7476d 100644 --- a/arch/x86/hyperv/nested.c +++ b/arch/x86/hyperv/nested.c @@ -58,11 +58,11 @@ EXPORT_SYMBOL_GPL(hyperv_flush_guest_mapping); int hyperv_fill_flush_guest_mapping_list( struct hv_guest_mapping_flush_list *flush, - u64 start_gfn, u64 pages) + int offset, u64 start_gfn, u64 pages) { u64 cur = start_gfn; u64 additional_pages; - int gpa_n = 0; + int gpa_n = offset; do { /* diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index cc60e617931c..d6be685ab6b0 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -357,7 +357,7 @@ int hyperv_flush_guest_mapping_range(u64 as, hyperv_fill_flush_list_func fill_func, void *data); int hyperv_fill_flush_guest_mapping_list( struct hv_guest_mapping_flush_list *flush, - u64 start_gfn, u64 end_gfn); + int offset, u64 start_gfn, u64 end_gfn); #ifdef CONFIG_X86_64 void hv_apic_init(void); diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 87224e4c2fd9..2c159efedc40 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -428,7 +428,7 @@ int kvm_fill_hv_flush_list_func(struct hv_guest_mapping_flush_list *flush, { struct kvm_tlb_range *range = data; - return hyperv_fill_flush_guest_mapping_list(flush, range->start_gfn, + return hyperv_fill_flush_guest_mapping_list(flush, 0, range->start_gfn, range->pages); } From patchwork Fri Jan 4 08:53:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 10748149 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C13DF6C5 for ; Fri, 4 Jan 2019 08:54:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B204927F94 for ; Fri, 4 Jan 2019 08:54:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A58C827FA1; Fri, 4 Jan 2019 08:54:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1BD027FA3 for ; Fri, 4 Jan 2019 08:54:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727173AbfADIyg (ORCPT ); Fri, 4 Jan 2019 03:54:36 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:45999 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727103AbfADIyf (ORCPT ); Fri, 4 Jan 2019 03:54:35 -0500 Received: by mail-pl1-f196.google.com with SMTP id a14so17135840plm.12; Fri, 04 Jan 2019 00:54:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3xvjZ/wjhJvQ+EiSQdkuRkphovQlZ1pkKAij+DudaK0=; b=UfoGxhg+Hd437kHWcocOKD4R7AEnDRlzv3+9E9HJw9uGV7/pvCZrMR6ZoCK0BaqvmA 77Mu3LTWe655ERI5Dx3fl4LFYedAvptTqCeFZZV9fkMKJGpW12xQcbXlTMWvnlaPeKtD 1+xxgO+uhbCznYh4qlV1zGwrCM9GFUEipbnIkCZPi04bRrGL2ONf/Z9HO1fHrvkWEmJ0 FD46PfpqMUag74dDDGZGWKMOsdJlPqLQM/KOrNyNNZjhHBQPqSwWFxJirOueeWMCLZn/ xbs/7qlpNmF0vIj9CJjAubmh84omLHTWBxD1AhGu4ws7s4c0KGWR/JFEk5A2OpbMg3oa x9XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=3xvjZ/wjhJvQ+EiSQdkuRkphovQlZ1pkKAij+DudaK0=; b=gIQWXBgUVR7wL2PIT5LNV62e01qoFG55/87iktbMtrQ+GIGwhf7+HyjUwfG2BBGcku q4LJ6LdKfPD7VoYSgVivsiLlRxEkSbrdMu10rt8Y9VakEyN350Z3sB6Y8ih2BrKs5/YR 2BxvCWDWew7nmYkp97q1WGBFKeluTN4pT7XRvaDfahrDbQKdtACPGe+UNarrbE3SWLkU Ri4xWW4bwNvu2eLSi34X0ulUdSYV/Teem/0UHHcQlOBGw5Yo74PSaKFlDS9nWjipEq0o D2TCjJWyoGaa/HtTx5pKDEJa+YxbInShG+l6fgK6Iuu7DTgF2LukjHSPzI6h2MddF8Og ipPA== X-Gm-Message-State: AJcUukf8xf/VMXEnVqFzb7tytgVq3EBcLV8trkTvAg8JZ5loyag7KJ03 2uMODYksQAI6VPz/MtQS5MM= X-Google-Smtp-Source: ALg8bN5WGbG/X0YfKxi+O0qWupEnRFREachjWFJDxbXTB00aKKZLPgBmf4DoRkBwMh4mrFM0l5hDCw== X-Received: by 2002:a17:902:6b87:: with SMTP id p7mr50903905plk.282.1546592074861; Fri, 04 Jan 2019 00:54:34 -0800 (PST) Received: from localhost.corp.microsoft.com ([2404:f801:9000:1a:d9bd:62c6:740b:9fc4]) by smtp.googlemail.com with ESMTPSA id i21sm99772145pgm.17.2019.01.04.00.54.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Jan 2019 00:54:34 -0800 (PST) From: lantianyu1986@gmail.com X-Google-Original-From: Tianyu.Lan@microsoft.com Cc: Lan Tianyu , christoffer.dall@arm.com, marc.zyngier@arm.com, linux@armlinux.org.uk, catalin.marinas@arm.com, will.deacon@arm.com, jhogan@kernel.org, ralf@linux-mips.org, paul.burton@mips.com, paulus@ozlabs.org, benh@kernel.crashing.org, mpe@ellerman.id.au, pbonzini@redhat.com, rkrcmar@redhat.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, x86@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, kvm-ppc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, michael.h.kelley@microsoft.com, kys@microsoft.com, vkuznets@redhat.com Subject: [PATCH 2/11] KVM/VMX: Fill range list in kvm_fill_hv_flush_list_func() Date: Fri, 4 Jan 2019 16:53:56 +0800 Message-Id: <20190104085405.40356-3-Tianyu.Lan@microsoft.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20190104085405.40356-1-Tianyu.Lan@microsoft.com> References: <20190104085405.40356-1-Tianyu.Lan@microsoft.com> To: unlisted-recipients:; (no To-header on input) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Lan Tianyu Populate ranges on the flush list into struct hv_guest_mapping_flush_list when flush list is available in the struct kvm_tlb_range. Signed-off-by: Lan Tianyu --- arch/x86/kvm/vmx/vmx.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 2c159efedc40..384f4782afba 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -427,9 +427,23 @@ int kvm_fill_hv_flush_list_func(struct hv_guest_mapping_flush_list *flush, void *data) { struct kvm_tlb_range *range = data; + struct kvm_mmu_page *sp; - return hyperv_fill_flush_guest_mapping_list(flush, 0, range->start_gfn, - range->pages); + if (!range->flush_list) { + return hyperv_fill_flush_guest_mapping_list(flush, + 0, range->start_gfn, range->pages); + } else { + int offset = 0; + + list_for_each_entry(sp, range->flush_list, flush_link) { + int pages = KVM_PAGES_PER_HPAGE(sp->role.level); + + offset = hyperv_fill_flush_guest_mapping_list(flush, + offset, sp->gfn, pages); + } + + return offset; + } } static inline int __hv_remote_flush_tlb_with_range(struct kvm *kvm, From patchwork Fri Jan 4 08:53:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 10748187 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 94EBE13AD for ; Fri, 4 Jan 2019 08:56:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8315027FA1 for ; Fri, 4 Jan 2019 08:56:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 73A0727FAC; Fri, 4 Jan 2019 08:56:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F52427FA1 for ; Fri, 4 Jan 2019 08:55:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727256AbfADIyo (ORCPT ); Fri, 4 Jan 2019 03:54:44 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:45596 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727220AbfADIyo (ORCPT ); Fri, 4 Jan 2019 03:54:44 -0500 Received: by mail-pg1-f196.google.com with SMTP id y4so17213298pgc.12; Fri, 04 Jan 2019 00:54:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sAXI9KUfdDUDhWP7B1nKmtj4xb/BMelYpMd0QbjlSBM=; b=nUohI3AjWQx6ybvOgpH7SxHa8o5nsYzlNw8zm2CmuYood2//x0Ie4POL9QksnHBF2I YUbLZhd1Rp+Pw6ZIBVPNdREu5ob8/NSLRq6m6/VDtSShPyah6oXk0qwJ6GERJPgXeO6u EUrdYFIOaWou/NJf40/UaAiehOFsZxMS2TqrBcwpH33yZixYhEMZPtTbO+uZ+PPeOhxm zlA1ylEHJ9eNnEnCg0PxAzkRvuMGjQSok91W0OHcF2QBzYWHJGfBB0JFkC9KNPbDKMby Hmyv2RXoicnEdLehOZJWYCkBrWb+0Z28p/1rQQ6j0R0WDyLlpYjwaX0cBTOkQtA6E5YA Z3Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sAXI9KUfdDUDhWP7B1nKmtj4xb/BMelYpMd0QbjlSBM=; b=Nh59qEzGcKlq0nvNuHu9ZT4LQP3maCBYFy5TZVQdg3zVIZ9pYQnTtRHL2ELUv1Rg5+ UpOQHTZFABkvZ88PJiHPQPDYt2mpRuWcYZtNo9ce7sFFv0fbXdpxW+N22QSG0g/QvtZa Sl82v2aOIDbzC3VGMeOFWRbnGeEKioLfx+YbeDPlea6k1noprCuREYIVG+qVKinksbPp CwJYzyp2UZIIaWPXWFsnRR9sxzpvhcb9ajhLN82JYBjRHPWHUdwDJSBy6olehOtJZg5i SI7Uz0dxn74aOJHdkZPG1TIFnPN/ZhVvvtihqpwiGJwZ/oCHt745SKE7jXyvUjf//b2J kqtA== X-Gm-Message-State: AJcUukdqZW2zTxYetvNW4y7HC4IyROPxwxel09gNVJZ2jeVsw7fcbSIk xmGK1YgTiwVYUdkL/rAgUfw= X-Google-Smtp-Source: ALg8bN7Fz7+aq6w8K/s4ukB3gYF8YzqWG/pOgvQxWE6lOgsKscCNdev/1KgoCdAPP4uOC2Ddj7PWew== X-Received: by 2002:a63:e5c:: with SMTP id 28mr842672pgo.369.1546592082509; Fri, 04 Jan 2019 00:54:42 -0800 (PST) Received: from localhost.corp.microsoft.com ([2404:f801:9000:1a:d9bd:62c6:740b:9fc4]) by smtp.googlemail.com with ESMTPSA id i21sm99772145pgm.17.2019.01.04.00.54.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Jan 2019 00:54:41 -0800 (PST) From: lantianyu1986@gmail.com X-Google-Original-From: Tianyu.Lan@microsoft.com Cc: Lan Tianyu , christoffer.dall@arm.com, marc.zyngier@arm.com, linux@armlinux.org.uk, catalin.marinas@arm.com, will.deacon@arm.com, jhogan@kernel.org, ralf@linux-mips.org, paul.burton@mips.com, paulus@ozlabs.org, benh@kernel.crashing.org, mpe@ellerman.id.au, pbonzini@redhat.com, rkrcmar@redhat.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, x86@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, kvm-ppc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, michael.h.kelley@microsoft.com, kys@microsoft.com, vkuznets@redhat.com Subject: [PATCH 3/11] KVM: Add spte's point in the struct kvm_mmu_page Date: Fri, 4 Jan 2019 16:53:57 +0800 Message-Id: <20190104085405.40356-4-Tianyu.Lan@microsoft.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20190104085405.40356-1-Tianyu.Lan@microsoft.com> References: <20190104085405.40356-1-Tianyu.Lan@microsoft.com> To: unlisted-recipients:; (no To-header on input) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Lan Tianyu It's necessary to check whether mmu page is last or large page when add mmu page into flush list. "spte" is needed for such check and so add spte point in the struct kvm_mmu_page. Signed-off-by: Lan Tianyu --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/mmu.c | 5 +++++ arch/x86/kvm/paging_tmpl.h | 2 ++ 3 files changed, 8 insertions(+) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 4660ce90de7f..78d2a6714c3b 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -332,6 +332,7 @@ struct kvm_mmu_page { int root_count; /* Currently serving as active root */ unsigned int unsync_children; struct kvm_rmap_head parent_ptes; /* rmap pointers to parent sptes */ + u64 *sptep; /* The page is obsolete if mmu_valid_gen != kvm->arch.mmu_valid_gen. */ unsigned long mmu_valid_gen; diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index ce770b446238..068694fa2371 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -3160,6 +3160,7 @@ static int __direct_map(struct kvm_vcpu *vcpu, int write, int map_writable, pseudo_gfn = base_addr >> PAGE_SHIFT; sp = kvm_mmu_get_page(vcpu, pseudo_gfn, iterator.addr, iterator.level - 1, 1, ACC_ALL); + sp->sptep = iterator.sptep; link_shadow_page(vcpu, iterator.sptep, sp); } @@ -3588,6 +3589,7 @@ static int mmu_alloc_direct_roots(struct kvm_vcpu *vcpu) sp = kvm_mmu_get_page(vcpu, 0, 0, vcpu->arch.mmu->shadow_root_level, 1, ACC_ALL); ++sp->root_count; + sp->sptep = NULL; spin_unlock(&vcpu->kvm->mmu_lock); vcpu->arch.mmu->root_hpa = __pa(sp->spt); } else if (vcpu->arch.mmu->shadow_root_level == PT32E_ROOT_LEVEL) { @@ -3604,6 +3606,7 @@ static int mmu_alloc_direct_roots(struct kvm_vcpu *vcpu) i << 30, PT32_ROOT_LEVEL, 1, ACC_ALL); root = __pa(sp->spt); ++sp->root_count; + sp->sptep = NULL; spin_unlock(&vcpu->kvm->mmu_lock); vcpu->arch.mmu->pae_root[i] = root | PT_PRESENT_MASK; } @@ -3644,6 +3647,7 @@ static int mmu_alloc_shadow_roots(struct kvm_vcpu *vcpu) vcpu->arch.mmu->shadow_root_level, 0, ACC_ALL); root = __pa(sp->spt); ++sp->root_count; + sp->sptep = NULL; spin_unlock(&vcpu->kvm->mmu_lock); vcpu->arch.mmu->root_hpa = root; return 0; @@ -3681,6 +3685,7 @@ static int mmu_alloc_shadow_roots(struct kvm_vcpu *vcpu) 0, ACC_ALL); root = __pa(sp->spt); ++sp->root_count; + sp->sptep = NULL; spin_unlock(&vcpu->kvm->mmu_lock); vcpu->arch.mmu->pae_root[i] = root | pm_mask; diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h index 6bdca39829bc..833e8855bbc9 100644 --- a/arch/x86/kvm/paging_tmpl.h +++ b/arch/x86/kvm/paging_tmpl.h @@ -633,6 +633,7 @@ static int FNAME(fetch)(struct kvm_vcpu *vcpu, gva_t addr, table_gfn = gw->table_gfn[it.level - 2]; sp = kvm_mmu_get_page(vcpu, table_gfn, addr, it.level-1, false, access); + sp->sptep = it.sptep; } /* @@ -663,6 +664,7 @@ static int FNAME(fetch)(struct kvm_vcpu *vcpu, gva_t addr, sp = kvm_mmu_get_page(vcpu, direct_gfn, addr, it.level-1, true, direct_access); + sp->sptep = it.sptep; link_shadow_page(vcpu, it.sptep, sp); } From patchwork Fri Jan 4 08:53:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 10748153 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CD4CC13AD for ; Fri, 4 Jan 2019 08:55:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC7AD27F94 for ; Fri, 4 Jan 2019 08:55:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B006527FA5; Fri, 4 Jan 2019 08:55:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C93F727F94 for ; Fri, 4 Jan 2019 08:54:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727348AbfADIyw (ORCPT ); Fri, 4 Jan 2019 03:54:52 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:47003 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727291AbfADIyv (ORCPT ); Fri, 4 Jan 2019 03:54:51 -0500 Received: by mail-pf1-f193.google.com with SMTP id c73so17983620pfe.13; Fri, 04 Jan 2019 00:54:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DbPYODlBh2cswgOkm5n3Xtx1VG29YKWZuHO2kRQx3jE=; b=uIGZ66sWc3MSyPixVlFIwqq9X9Xawe/7lcCM/24F9OUU1MhgIXXEp+AbmzflEK13nM 2o+Z7uoAl1u/wmPUG3KdiBwSgFXXPl4EIy5LvDsMJPUd2xQxtWZR+TAhyRkwglbNz5am o/KasvYoE5o7W/xDHeUq9nW1U+hq6D2rEmY+fBsBoq/f34Ew+f9isuerC2+UXmqf/7xW VEHXij5Tmwcu8CH5Sve62zd3WlvJk2e1xqpMBDePH5ZEkitNlq/TWfWZEQBZXcHzrVop sJBt1UN3Ju9tBhxkEk4LYvpZdCJEK2L7xGpWi4h9Qu/xiaccyXt/cvhCySXdqM36T05O eX1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DbPYODlBh2cswgOkm5n3Xtx1VG29YKWZuHO2kRQx3jE=; b=l8s7Cj5BLYVnFE6FhK2apEawje3HBY9Vd8LC98DlyZndxVR8+3tPGbBgW8/0CRu6QC PK4rA+uj2qp9BISciFoQ+Far1e/GPgpDz7hZJDuI4to4vH5zPHkEJvIF2YQIKuuOwLUk el8wWhAFhLViNiwV4nXtQ/P9VofXNREN9sKQTRQ8kj6+6xkQZx7FOyxsYyJ9LcBOepAF sEBlzuqHbSRD6XarZQPE7Mb+DXUIhPuVC0+E9MAmaKWFQ13xt+xe3cnOqaBXQkoFKMxS ufDciJq5tzG1I7uXQacySLxEYJ92WczZG2Nyb5B3CmdK2hXktjdmS/5PduqS7dUCHBpF c0YA== X-Gm-Message-State: AA+aEWZPD7o3G44AzcB2cWnlHRV8ZWqraoCbnUi+lq/70phv1Wkkfc0D xMFLIa0KkninVv4KSCoUp4c= X-Google-Smtp-Source: ALg8bN4wIfpC3j2afh4wGFjYegQADeZ0K/ccHcj0qIsaA3H5W5N7IpT4CBOOzO8AUje2LUSMO2pDwg== X-Received: by 2002:a62:1992:: with SMTP id 140mr51523150pfz.33.1546592089991; Fri, 04 Jan 2019 00:54:49 -0800 (PST) Received: from localhost.corp.microsoft.com ([2404:f801:9000:1a:d9bd:62c6:740b:9fc4]) by smtp.googlemail.com with ESMTPSA id i21sm99772145pgm.17.2019.01.04.00.54.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Jan 2019 00:54:49 -0800 (PST) From: lantianyu1986@gmail.com X-Google-Original-From: Tianyu.Lan@microsoft.com Cc: Lan Tianyu , christoffer.dall@arm.com, marc.zyngier@arm.com, linux@armlinux.org.uk, catalin.marinas@arm.com, will.deacon@arm.com, jhogan@kernel.org, ralf@linux-mips.org, paul.burton@mips.com, paulus@ozlabs.org, benh@kernel.crashing.org, mpe@ellerman.id.au, pbonzini@redhat.com, rkrcmar@redhat.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, x86@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, kvm-ppc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, michael.h.kelley@microsoft.com, kys@microsoft.com, vkuznets@redhat.com Subject: [PATCH 4/11] KVM/MMU: Introduce tlb flush with range list Date: Fri, 4 Jan 2019 16:53:58 +0800 Message-Id: <20190104085405.40356-5-Tianyu.Lan@microsoft.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20190104085405.40356-1-Tianyu.Lan@microsoft.com> References: <20190104085405.40356-1-Tianyu.Lan@microsoft.com> To: unlisted-recipients:; (no To-header on input) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Lan Tianyu This patch is to introduce tlb flush with range list interface and use struct kvm_mmu_page as list entry. Use flush list function in the kvm_mmu_commit_zap_page(). Signed-off-by: Lan Tianyu --- arch/x86/include/asm/kvm_host.h | 7 +++++++ arch/x86/kvm/mmu.c | 24 +++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 78d2a6714c3b..22dbaa8fba32 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -316,6 +316,12 @@ struct kvm_rmap_head { struct kvm_mmu_page { struct list_head link; + + /* + * Tlb flush with range list uses struct kvm_mmu_page as list entry + * and all list operations should be under protection of mmu_lock. + */ + struct list_head flush_link; struct hlist_node hash_link; bool unsync; @@ -443,6 +449,7 @@ struct kvm_mmu { struct kvm_tlb_range { u64 start_gfn; u64 pages; + struct list_head *flush_list; }; enum pmc_type { diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 068694fa2371..d3272c5066ea 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -289,6 +289,17 @@ static void kvm_flush_remote_tlbs_with_address(struct kvm *kvm, range.start_gfn = start_gfn; range.pages = pages; + range.flush_list = NULL; + + kvm_flush_remote_tlbs_with_range(kvm, &range); +} + +static void kvm_flush_remote_tlbs_with_list(struct kvm *kvm, + struct list_head *flush_list) +{ + struct kvm_tlb_range range; + + range.flush_list = flush_list; kvm_flush_remote_tlbs_with_range(kvm, &range); } @@ -2708,6 +2719,7 @@ static void kvm_mmu_commit_zap_page(struct kvm *kvm, struct list_head *invalid_list) { struct kvm_mmu_page *sp, *nsp; + LIST_HEAD(flush_list); if (list_empty(invalid_list)) return; @@ -2721,7 +2733,17 @@ static void kvm_mmu_commit_zap_page(struct kvm *kvm, * In addition, kvm_flush_remote_tlbs waits for all vcpus to exit * guest mode and/or lockless shadow page table walks. */ - kvm_flush_remote_tlbs(kvm); + if (kvm_available_flush_tlb_with_range()) { + list_for_each_entry(sp, invalid_list, link) + if (sp->sptep && is_last_spte(*sp->sptep, + sp->role.level)) + list_add(&sp->flush_link, &flush_list); + + if (!list_empty(&flush_list)) + kvm_flush_remote_tlbs_with_list(kvm, &flush_list); + } else { + kvm_flush_remote_tlbs(kvm); + } list_for_each_entry_safe(sp, nsp, invalid_list, link) { WARN_ON(!sp->role.invalid || sp->root_count); From patchwork Fri Jan 4 08:53:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 10748157 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6D9F06C5 for ; Fri, 4 Jan 2019 08:55:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E3CD27F94 for ; Fri, 4 Jan 2019 08:55:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5287C27FA8; Fri, 4 Jan 2019 08:55:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7477727F94 for ; Fri, 4 Jan 2019 08:55:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727391AbfADIy7 (ORCPT ); Fri, 4 Jan 2019 03:54:59 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:47018 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726924AbfADIy6 (ORCPT ); Fri, 4 Jan 2019 03:54:58 -0500 Received: by mail-pf1-f195.google.com with SMTP id c73so17983777pfe.13; Fri, 04 Jan 2019 00:54:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=lVVdEslgom8hND2ea3FWWDCI/x9Q6uJ8jZfIIsF2DSM=; b=OW2Ji7XBSYB1+gGPVjstYoLKPTzQ1AmfMKSKOstz5QdPudY86VQ380UUUsnf/zGmVM xn6Mh0pYG3xrcy20WnDqchjHf0s2vor5WP0jYSxpDbJWJjbYB3QmqZJ0fwIHRl8AAQNK lxbecV+o95hItU6JP7PaPD8X3TJPHKx2mAM6ZTHdq6sV5V9Krp4xs8TdoVqrAT8V0Xt9 X9+ykYR1/2wD4+G1Z4KIV0Ml1JTrhu5uudJqftY/TkXmydDiAMUHPf4qFOrUwiy9y1Gm C8XClO7UzUvFQDxjE0HxdBZXHppJjVWt0tiZIPFJ3583Ah2FqOq6EH1oP+MPBMLn9PvU zBog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=lVVdEslgom8hND2ea3FWWDCI/x9Q6uJ8jZfIIsF2DSM=; b=k/T8JVAFcEXglAw6jKUATiwLoAihZxR4lBSCwzJd64FqlQlvVpDj3JCMys4KeVBGRm +1DoMghawheMAIgBmNk5vT8bx+bhOGShLq6/kiZryWVtWeAOm7OBNNkc4FhBP7KDGxK8 krAxP9HA2H5wCdI/kijSsapgEKxkDz07640qU7FzEEBxrcAxy4yAUrxYXeAK1thlIDoW r4Fgt8xS0oqzZkSmBedpx56UDOH/rKzHYL390+r5QBO6DBQjYjtUdFcG8qppsCFzndup EbbbKeA7C4rEIfEJ0NUooxwAJJHbzNJiwQLcdqc938qkzYvX75vIr7OQocSuPYZnj3BA di2g== X-Gm-Message-State: AA+aEWaADgN1mD+xBfdtoZj+MDjNnJeR/Se6doaH9UiCx/Of6odBlAH7 nh9TXl8WIP2ZJ7z0tPCjH4AJ8qi/Ln24wg== X-Google-Smtp-Source: ALg8bN6Kuw2ITWSZOeeG0JAVP4GO5UzPiaRW5tnwjEiTZXlCq7w6q2DQ3Tfsj+QkVgS7pj1Cmr9+qg== X-Received: by 2002:a62:56c7:: with SMTP id h68mr53695204pfj.134.1546592097417; Fri, 04 Jan 2019 00:54:57 -0800 (PST) Received: from localhost.corp.microsoft.com ([2404:f801:9000:1a:d9bd:62c6:740b:9fc4]) by smtp.googlemail.com with ESMTPSA id i21sm99772145pgm.17.2019.01.04.00.54.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Jan 2019 00:54:56 -0800 (PST) From: lantianyu1986@gmail.com X-Google-Original-From: Tianyu.Lan@microsoft.com Cc: Lan Tianyu , christoffer.dall@arm.com, marc.zyngier@arm.com, linux@armlinux.org.uk, catalin.marinas@arm.com, will.deacon@arm.com, jhogan@kernel.org, ralf@linux-mips.org, paul.burton@mips.com, paulus@ozlabs.org, benh@kernel.crashing.org, mpe@ellerman.id.au, pbonzini@redhat.com, rkrcmar@redhat.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, x86@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, kvm-ppc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, michael.h.kelley@microsoft.com, kys@microsoft.com, vkuznets@redhat.com Subject: [PATCH 5/11] KVM/MMU: Flush tlb directly in the kvm_mmu_slot_gfn_write_protect() Date: Fri, 4 Jan 2019 16:53:59 +0800 Message-Id: <20190104085405.40356-6-Tianyu.Lan@microsoft.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20190104085405.40356-1-Tianyu.Lan@microsoft.com> References: <20190104085405.40356-1-Tianyu.Lan@microsoft.com> To: unlisted-recipients:; (no To-header on input) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Lan Tianyu This patch is to flush tlb directly in the kvm_mmu_slot_gfn_write_protect() when range flush is available. Signed-off-by: Lan Tianyu --- arch/x86/kvm/mmu.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index d3272c5066ea..6d4f7dfeaa57 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -1715,6 +1715,11 @@ bool kvm_mmu_slot_gfn_write_protect(struct kvm *kvm, write_protected |= __rmap_write_protect(kvm, rmap_head, true); } + if (write_protected && kvm_available_flush_tlb_with_range()) { + kvm_flush_remote_tlbs_with_address(kvm, gfn, 1); + write_protected = false; + } + return write_protected; } From patchwork Fri Jan 4 08:54:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 10748163 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 828566C5 for ; Fri, 4 Jan 2019 08:55:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 733FA27FA1 for ; Fri, 4 Jan 2019 08:55:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 67A0627FA3; Fri, 4 Jan 2019 08:55:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9342927FA8 for ; Fri, 4 Jan 2019 08:55:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727438AbfADIzG (ORCPT ); Fri, 4 Jan 2019 03:55:06 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:40020 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726924AbfADIzF (ORCPT ); Fri, 4 Jan 2019 03:55:05 -0500 Received: by mail-pl1-f196.google.com with SMTP id u18so17152346plq.7; Fri, 04 Jan 2019 00:55:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VAVkaVsyvHGb3944LCTx3RYQpKB8eIkyndjj2Ikvaks=; b=JSNQv0hto48d+cy9OmeC8+vpqtt4/8EI9u9HIqEmmUbj6f2TxB9IIfx/sXfdswigSu EfVz+80dJ8PkWlx+96miP5z94XhYM+ykxX3Fmq4clNe8KPorrdKxjWxhLblkovBxKOoE xNYBVIAgaXQScDW+EAKSKC9Vr5FCyiuV4d9SXDVbYKPiXlyZHItxqT9jBQmvUlY+lIX6 QQxwdeg3r8Jc/hvz7dkxYLqoh+osKRZY5AyLcBIZ0cLUIsntPEjJnC3IB6sc65dcu4X5 0h2aJEJSkwZD10HfzE989QUcENXgc2JHiKAXwoElzz9FnMX6UUYrCm3geYrKeF6nQ2K2 q/cQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=VAVkaVsyvHGb3944LCTx3RYQpKB8eIkyndjj2Ikvaks=; b=gouEeRzpn6TEdVDuQbn4PoAaZD95TxS/DO9XR1wvZql3KAqLDJzub0mBQbSbA6/2sb YstxyRPW8Cja7Dx97Hyr52eBeeo7d90JM60ZzrRLNET2XLIgPGQitYM874nmOdwO9jp6 V9XaK6CM64tORSZqUzzEcOo4RKUNLG+5JdnJsYR9b4/qKMSkexjW0aO6uontBoD7Wm9y sFgV36Mhszs7RjL4Jj/XwZob802jLyXedd1JMAfv1Ygl99HYZMX+nZxTFo/3Mxd16Z5q ncogPwiFh1CJEkqittHyNEaTRKBscHa9qGZYJ57upUsmwXjsnGfscJ9/8HfSkk7nDPlH HuTw== X-Gm-Message-State: AJcUuke/pL6SG5xDE6ts3voX5gaOBgmTwpHOGtjb8MTatj37Li8eCpwe quTGaWg4kcFd+Td/GLNmoAc= X-Google-Smtp-Source: ALg8bN4OjtFEk71VDHPjiuzCk2TCpCOEwCai/Wt7CBSpw62HsAigCPIHdjQRvUBI364td6kTt3nr6A== X-Received: by 2002:a17:902:7882:: with SMTP id q2mr51489397pll.305.1546592104889; Fri, 04 Jan 2019 00:55:04 -0800 (PST) Received: from localhost.corp.microsoft.com ([2404:f801:9000:1a:d9bd:62c6:740b:9fc4]) by smtp.googlemail.com with ESMTPSA id i21sm99772145pgm.17.2019.01.04.00.54.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Jan 2019 00:55:04 -0800 (PST) From: lantianyu1986@gmail.com X-Google-Original-From: Tianyu.Lan@microsoft.com Cc: Lan Tianyu , christoffer.dall@arm.com, marc.zyngier@arm.com, linux@armlinux.org.uk, catalin.marinas@arm.com, will.deacon@arm.com, jhogan@kernel.org, ralf@linux-mips.org, paul.burton@mips.com, paulus@ozlabs.org, benh@kernel.crashing.org, mpe@ellerman.id.au, pbonzini@redhat.com, rkrcmar@redhat.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, x86@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, kvm-ppc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, michael.h.kelley@microsoft.com, kys@microsoft.com, vkuznets@redhat.com Subject: [PATCH 6/11] KVM/MMU: Flush tlb with range list in sync_page() Date: Fri, 4 Jan 2019 16:54:00 +0800 Message-Id: <20190104085405.40356-7-Tianyu.Lan@microsoft.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20190104085405.40356-1-Tianyu.Lan@microsoft.com> References: <20190104085405.40356-1-Tianyu.Lan@microsoft.com> To: unlisted-recipients:; (no To-header on input) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Lan Tianyu This patch is to flush tlb via flush list function. Signed-off-by: Lan Tianyu --- arch/x86/kvm/paging_tmpl.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h index 833e8855bbc9..866ccdea762e 100644 --- a/arch/x86/kvm/paging_tmpl.h +++ b/arch/x86/kvm/paging_tmpl.h @@ -973,6 +973,7 @@ static int FNAME(sync_page)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp) bool host_writable; gpa_t first_pte_gpa; int set_spte_ret = 0; + LIST_HEAD(flush_list); /* direct kvm_mmu_page can not be unsync. */ BUG_ON(sp->role.direct); @@ -980,6 +981,7 @@ static int FNAME(sync_page)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp) first_pte_gpa = FNAME(get_level1_sp_gpa)(sp); for (i = 0; i < PT64_ENT_PER_PAGE; i++) { + int tmp_spte_ret = 0; unsigned pte_access; pt_element_t gpte; gpa_t pte_gpa; @@ -1029,14 +1031,24 @@ static int FNAME(sync_page)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp) host_writable = sp->spt[i] & SPTE_HOST_WRITEABLE; - set_spte_ret |= set_spte(vcpu, &sp->spt[i], + tmp_spte_ret = set_spte(vcpu, &sp->spt[i], pte_access, PT_PAGE_TABLE_LEVEL, gfn, spte_to_pfn(sp->spt[i]), true, false, host_writable); + + if (kvm_available_flush_tlb_with_range() + && (tmp_spte_ret & SET_SPTE_NEED_REMOTE_TLB_FLUSH)) { + struct kvm_mmu_page *leaf_sp = page_header(sp->spt[i] + & PT64_BASE_ADDR_MASK); + list_add(&leaf_sp->flush_link, &flush_list); + } + + set_spte_ret |= tmp_spte_ret; + } if (set_spte_ret & SET_SPTE_NEED_REMOTE_TLB_FLUSH) - kvm_flush_remote_tlbs(vcpu->kvm); + kvm_flush_remote_tlbs_with_list(vcpu->kvm, &flush_list); return nr_present; } From patchwork Fri Jan 4 08:54:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 10748165 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1C1CE6C5 for ; Fri, 4 Jan 2019 08:55:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B71A27F94 for ; Fri, 4 Jan 2019 08:55:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F3E4927FA5; Fri, 4 Jan 2019 08:55:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2360227F94 for ; Fri, 4 Jan 2019 08:55:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727496AbfADIzO (ORCPT ); Fri, 4 Jan 2019 03:55:14 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:45647 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727415AbfADIzN (ORCPT ); Fri, 4 Jan 2019 03:55:13 -0500 Received: by mail-pg1-f196.google.com with SMTP id y4so17213827pgc.12; Fri, 04 Jan 2019 00:55:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3CQvyPlxafLLMYYmnidZXL6MopPPAyOd1R4OKDK3Tg8=; b=bERgKUKu51PAzYg3Rrzv52DBjdnCcfNkUuGl0QEWhiWj6W0MmP1KserqG3gw+V0uOz 717BaRsb17KQy9DlLpRwN73NDF+JlNIwIa6Vtid3Wn7/unsJsMpEWzLVhDoWsO+jPqBK CXzhbDQK4O0iY5rU0gimk9NZuMJOLue/IM7psgZOst2rkKV6QjkUQ+xy9R5CHlRtE0yf 6eYDVGquJEt/gVb0OBEtL7uwYx/NIUXuq7ZJAts2E7VLsvPLZYf9o1OEXSsCvqx1R+Fm FOz/j9UPfBj3duCoLjjODwHV5/2+j1i4jVT/zc46j+B8Sqj4H5cNFpIum3Jq9ABDTfbu UfaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=3CQvyPlxafLLMYYmnidZXL6MopPPAyOd1R4OKDK3Tg8=; b=tvJ42Ds9o0dmfO3COqfxvZvWQA3UTpvqrH9CYNr2N5A3zi+RmugjrlC1jmZPAYKR19 wTNT2M+FP3wuv4J8GPJFqI7oSlJduPrqGOkiQEo9GjCY14Y7DphEMN7ETtiLdhICH5Nd RvnahsfKmwpak0Y/b87hzJSud7OrTHhtvL/Ab4NKw9rDxKyoYbxI7wYoE08HbrU4kaL4 H+rhBQDe4ImFGdejc4VIlGfjkfZ4wxQH+TFi+xQgLFj3I/wdHcuiNwXrTS8u0fmlM7Bz 3lL58YDl/TnWVu0E1gzCS7cMhrvQx77z2cQ1z9kLEVao8WSr5Jayu2D6FZ3jdXsOwfav Oc/A== X-Gm-Message-State: AJcUukdcqJhcStxj6ijhzJ47/OmYxS2CLHjgAUtbzCrZrLCBK/NTnjLA 89KogFCFAQAAnz0ZoLb8Mv8= X-Google-Smtp-Source: ALg8bN52JNWJUY4wd3KWz56nhScCreos1hBMy4NTN0TRzwOHpvOyEaRyBz6+s+XGkePV/idoh2nHEQ== X-Received: by 2002:a63:557:: with SMTP id 84mr19472589pgf.411.1546592112418; Fri, 04 Jan 2019 00:55:12 -0800 (PST) Received: from localhost.corp.microsoft.com ([2404:f801:9000:1a:d9bd:62c6:740b:9fc4]) by smtp.googlemail.com with ESMTPSA id i21sm99772145pgm.17.2019.01.04.00.55.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Jan 2019 00:55:11 -0800 (PST) From: lantianyu1986@gmail.com X-Google-Original-From: Tianyu.Lan@microsoft.com Cc: Lan Tianyu , christoffer.dall@arm.com, marc.zyngier@arm.com, linux@armlinux.org.uk, catalin.marinas@arm.com, will.deacon@arm.com, jhogan@kernel.org, ralf@linux-mips.org, paul.burton@mips.com, paulus@ozlabs.org, benh@kernel.crashing.org, mpe@ellerman.id.au, pbonzini@redhat.com, rkrcmar@redhat.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, x86@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, kvm-ppc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, michael.h.kelley@microsoft.com, kys@microsoft.com, vkuznets@redhat.com Subject: [PATCH 7/11] KVM: Remove redundant check in the kvm_get_dirty_log_protect() Date: Fri, 4 Jan 2019 16:54:01 +0800 Message-Id: <20190104085405.40356-8-Tianyu.Lan@microsoft.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20190104085405.40356-1-Tianyu.Lan@microsoft.com> References: <20190104085405.40356-1-Tianyu.Lan@microsoft.com> To: unlisted-recipients:; (no To-header on input) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Lan Tianyu The dirty bits have already been checked in the previous check of "dirty_bitmap" and mask must be non-zero value at this point. Signed-off-by: Lan Tianyu --- virt/kvm/kvm_main.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index cf7cc0554094..e75dbb15fd09 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1206,11 +1206,9 @@ int kvm_get_dirty_log_protect(struct kvm *kvm, mask = xchg(&dirty_bitmap[i], 0); dirty_bitmap_buffer[i] = mask; - if (mask) { - offset = i * BITS_PER_LONG; - kvm_arch_mmu_enable_log_dirty_pt_masked(kvm, memslot, - offset, mask); - } + offset = i * BITS_PER_LONG; + kvm_arch_mmu_enable_log_dirty_pt_masked(kvm, memslot, + offset, mask); } spin_unlock(&kvm->mmu_lock); } From patchwork Fri Jan 4 08:54:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 10748171 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 40AE46C5 for ; Fri, 4 Jan 2019 08:55:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F78727F94 for ; Fri, 4 Jan 2019 08:55:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 22F6327FA8; Fri, 4 Jan 2019 08:55:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3527727FA1 for ; Fri, 4 Jan 2019 08:55:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727536AbfADIzV (ORCPT ); Fri, 4 Jan 2019 03:55:21 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:44488 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727415AbfADIzU (ORCPT ); Fri, 4 Jan 2019 03:55:20 -0500 Received: by mail-pl1-f195.google.com with SMTP id e11so17153212plt.11; Fri, 04 Jan 2019 00:55:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xRXc/XwU+0JK+tTKqDimxoIXZnhU9RFFAnNgcWVG9mA=; b=lvSEP/K+omY4BY0Ld25k59kJSSur3J2dCgRgr+6yby9CvFFfsgXTOn3+D1aJsvNalY eTPJapgS5iRWe8Q3VJfTJ0Bthyr9frF7QnBsGgTCvldicoKf7P4ofSI8pZ09IAgB4oJH S57zVxQI3vvPDAKwm0oQsJsa4UNZsPZkF0t/oCsc/oq0RtM8Bl0af8yVHC4PZOGlv3vr xk5+cqM8Wco6xLzbT7VEmWSN2LwGnGl4YyFdTsgfVbY6uz3M5hvZsFc6A91Yr6tdVH+Z ElpfqsR5cbQQTFpFgingD74oF7Tm329wgchjSs/dW+HIz+j+Txq5ZkJoxgkX4QVwmqbB /xgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xRXc/XwU+0JK+tTKqDimxoIXZnhU9RFFAnNgcWVG9mA=; b=gNNRWwonjpnlRCnIL1YafC1MrT1dhlYhkLNSYE78ZBnooYfLU3ypAg+MqHKYgSQ1pM siK36V8xWhtU97KqCm6CHEO0yZzXBfVreOTnA0WAFDPt58iniLXphjdiEHtSBKosJYAI PE+IPJ1KiAWT1AIg3eo2WOY4ocxZ8ZTN7tSNQUGTixsOqqIQh2tkdNyRC/YOfgoXdETL VG8B3lHeyov8S4VLCGOIqwDINnv5zicUwfOQjU9kMs7gvCaqBbNLvzpObTfcd6SqLPss 06h7RgDklClibilp1qb3LYtXKuqt0KxbJdFzVdbTFtwd6nee+IKHzWSS8gmdimQmXLIm YvNA== X-Gm-Message-State: AJcUukcL0gvTpL09qoVoPf2aQtg7ch3N5DogbIuo+idlvE3Mpnqa5NYC AxshztEnce47gNeU3ZKG9Ck= X-Google-Smtp-Source: ALg8bN6SD6ySHgduF3UiOSRUnfYBNpkE+dVu9pEO0AqBi2lbwhCbWkSW6krUk3+TRsHaKT0HX3RnDg== X-Received: by 2002:a17:902:2b84:: with SMTP id l4mr50247049plb.191.1546592119875; Fri, 04 Jan 2019 00:55:19 -0800 (PST) Received: from localhost.corp.microsoft.com ([2404:f801:9000:1a:d9bd:62c6:740b:9fc4]) by smtp.googlemail.com with ESMTPSA id i21sm99772145pgm.17.2019.01.04.00.55.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Jan 2019 00:55:19 -0800 (PST) From: lantianyu1986@gmail.com X-Google-Original-From: Tianyu.Lan@microsoft.com Cc: Lan Tianyu , christoffer.dall@arm.com, marc.zyngier@arm.com, linux@armlinux.org.uk, catalin.marinas@arm.com, will.deacon@arm.com, jhogan@kernel.org, ralf@linux-mips.org, paul.burton@mips.com, paulus@ozlabs.org, benh@kernel.crashing.org, mpe@ellerman.id.au, pbonzini@redhat.com, rkrcmar@redhat.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, x86@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, kvm-ppc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, michael.h.kelley@microsoft.com, kys@microsoft.com, vkuznets@redhat.com Subject: [PATCH 8/11] KVM: Make kvm_arch_mmu_enable_log_dirty_pt_masked() return value Date: Fri, 4 Jan 2019 16:54:02 +0800 Message-Id: <20190104085405.40356-9-Tianyu.Lan@microsoft.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20190104085405.40356-1-Tianyu.Lan@microsoft.com> References: <20190104085405.40356-1-Tianyu.Lan@microsoft.com> To: unlisted-recipients:; (no To-header on input) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Lan Tianyu This patch is to make kvm_arch_mmu_enable_log_dirty_pt_masked() return value and caller can use it to determine whether tlb flush is necessary. kvm_get_dirty_log_protect() and kvm_clear_dirty_log_protect() use the return value of kvm_arch_mmu_enable_log_dirty_pt_masked() to populate flush parameter. Signed-off-by: Lan Tianyu --- arch/mips/kvm/mmu.c | 5 ++++- arch/x86/kvm/mmu.c | 6 +++++- include/linux/kvm_host.h | 2 +- virt/kvm/arm/mmu.c | 5 ++++- virt/kvm/kvm_main.c | 10 ++++------ 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/arch/mips/kvm/mmu.c b/arch/mips/kvm/mmu.c index 97e538a8c1be..f36ccb2d43ec 100644 --- a/arch/mips/kvm/mmu.c +++ b/arch/mips/kvm/mmu.c @@ -437,8 +437,10 @@ int kvm_mips_mkclean_gpa_pt(struct kvm *kvm, gfn_t start_gfn, gfn_t end_gfn) * * Walks bits set in mask write protects the associated pte's. Caller must * acquire @kvm->mmu_lock. + * + * Returns: Whether caller needs to flush tlb. */ -void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, +bool kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, struct kvm_memory_slot *slot, gfn_t gfn_offset, unsigned long mask) { @@ -447,6 +449,7 @@ void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, gfn_t end = base_gfn + __fls(mask); kvm_mips_mkclean_gpa_pt(kvm, start, end); + return true; } /* diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 6d4f7dfeaa57..9d8ee6ea02db 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -1676,8 +1676,10 @@ EXPORT_SYMBOL_GPL(kvm_mmu_clear_dirty_pt_masked); * * Used when we do not need to care about huge page mappings: e.g. during dirty * logging we do not have any such mappings. + * + * Return value means whether caller needs to flush tlb. */ -void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, +bool kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, struct kvm_memory_slot *slot, gfn_t gfn_offset, unsigned long mask) { @@ -1686,6 +1688,8 @@ void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, mask); else kvm_mmu_write_protect_pt_masked(kvm, slot, gfn_offset, mask); + + return true; } /** diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index c38cc5eb7e73..e86b8c38342b 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -759,7 +759,7 @@ int kvm_get_dirty_log_protect(struct kvm *kvm, int kvm_clear_dirty_log_protect(struct kvm *kvm, struct kvm_clear_dirty_log *log, bool *flush); -void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, +bool kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, struct kvm_memory_slot *slot, gfn_t gfn_offset, unsigned long mask); diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c index 3053bf2584f8..232007ff3208 100644 --- a/virt/kvm/arm/mmu.c +++ b/virt/kvm/arm/mmu.c @@ -1564,12 +1564,15 @@ static void kvm_mmu_write_protect_pt_masked(struct kvm *kvm, * * It calls kvm_mmu_write_protect_pt_masked to write protect selected pages to * enable dirty logging for them. + * + * Return value means whether caller needs to flush tlb. */ -void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, +bool kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, struct kvm_memory_slot *slot, gfn_t gfn_offset, unsigned long mask) { kvm_mmu_write_protect_pt_masked(kvm, slot, gfn_offset, mask); + return true; } static void clean_dcache_guest_page(kvm_pfn_t pfn, unsigned long size) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index e75dbb15fd09..bcbe059d98be 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1202,13 +1202,12 @@ int kvm_get_dirty_log_protect(struct kvm *kvm, if (!dirty_bitmap[i]) continue; - *flush = true; mask = xchg(&dirty_bitmap[i], 0); dirty_bitmap_buffer[i] = mask; offset = i * BITS_PER_LONG; - kvm_arch_mmu_enable_log_dirty_pt_masked(kvm, memslot, - offset, mask); + *flush = kvm_arch_mmu_enable_log_dirty_pt_masked(kvm, + memslot, offset, mask); } spin_unlock(&kvm->mmu_lock); } @@ -1275,9 +1274,8 @@ int kvm_clear_dirty_log_protect(struct kvm *kvm, * a problem if userspace sets them in log->dirty_bitmap. */ if (mask) { - *flush = true; - kvm_arch_mmu_enable_log_dirty_pt_masked(kvm, memslot, - offset, mask); + *flush = kvm_arch_mmu_enable_log_dirty_pt_masked(kvm, + memslot, offset, mask); } } spin_unlock(&kvm->mmu_lock); From patchwork Fri Jan 4 08:54:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 10748177 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7D88A6C5 for ; Fri, 4 Jan 2019 08:55:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E59627F94 for ; Fri, 4 Jan 2019 08:55:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 624DD27FA5; Fri, 4 Jan 2019 08:55:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8BDE127F94 for ; Fri, 4 Jan 2019 08:55:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727581AbfADIz3 (ORCPT ); Fri, 4 Jan 2019 03:55:29 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:36724 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726849AbfADIz2 (ORCPT ); Fri, 4 Jan 2019 03:55:28 -0500 Received: by mail-pg1-f196.google.com with SMTP id n2so17234652pgm.3; Fri, 04 Jan 2019 00:55:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZK8Ep/iS40KCOfUlldAdh4saGJOIzh8GKtl9Mv0nhLM=; b=G1NjRFrN/C6osVf7UtbSVtMVpqA9Ea/+QkseFh5fipznXIehIqBOj+WICVCUWsH4fm XXrhC1ChDLsoNN78/Jf69XvF4QTvyKS9C0EiG02MtsqGdb/vznYx/ApjHr3GqQaAnc59 iAzfvakgMPJ9lrvgBNJm4sYCxASvjQdGTWmPXRnBeoYThC7wrSDBO3dfRbcb5WIyDr3H /Cn6OmQEBoOqFU++9g31s+9rVVQi9bp8oJg2/DBj/pdk8x12iaIwwR0R4dkwHBh3RkSW 8wMmO9dWO47ftRi5WiiLwFVdRdVrMEsSK046I7vBDMukcSQjf0h6zVVmkLcMYlYK+egF HwzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ZK8Ep/iS40KCOfUlldAdh4saGJOIzh8GKtl9Mv0nhLM=; b=CjZ1hrpb8+xeNGltu6TeqGk7YfS3gNM6CYoG/+KkMPodaXOM/WfrgpyuDif9Y8tlOq aS3gZlJJs9WaM6MvDSVOzsWJoLt0eW9C0HmQ6ZgjCRDijXj+taHbtbVMFy8jm4KOScv7 MegEzcha3OjwFgS04a3qj+blYQjI2QTxUXYwHWIWgxSkge+WKbsSobqoLGlamxPgrjYj gJYMJHJ/8rRkfF5EI/Xu7UfWO31ip4Ho6ygjaeqvG0EYzeN44cEI5BFEdsfcuQ5DuwPl J8GNtLwPsa0CZcmHTC3n3BnPPgLuoZD5B0N/z7OJYB/2ApZFG8ZiRVCaLmCkUEA1OaEv kh0w== X-Gm-Message-State: AJcUukfXGaqS8x+obwUwvb9cSlsXw+O/V/IALEpWpZ5QZdvfqPYaLSc5 FbddI9zlM51WJqDYnmiZJFA= X-Google-Smtp-Source: ALg8bN75sfO1wfGgbU1C9NYyKaexIVA3NbEhpqovnyfTJeb3GDT9BdXc/J/k5irnfWBqolOtTpXZ/g== X-Received: by 2002:a63:da45:: with SMTP id l5mr909998pgj.111.1546592127395; Fri, 04 Jan 2019 00:55:27 -0800 (PST) Received: from localhost.corp.microsoft.com ([2404:f801:9000:1a:d9bd:62c6:740b:9fc4]) by smtp.googlemail.com with ESMTPSA id i21sm99772145pgm.17.2019.01.04.00.55.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Jan 2019 00:55:26 -0800 (PST) From: lantianyu1986@gmail.com X-Google-Original-From: Tianyu.Lan@microsoft.com Cc: Lan Tianyu , christoffer.dall@arm.com, marc.zyngier@arm.com, linux@armlinux.org.uk, catalin.marinas@arm.com, will.deacon@arm.com, jhogan@kernel.org, ralf@linux-mips.org, paul.burton@mips.com, paulus@ozlabs.org, benh@kernel.crashing.org, mpe@ellerman.id.au, pbonzini@redhat.com, rkrcmar@redhat.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, x86@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, kvm-ppc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, michael.h.kelley@microsoft.com, kys@microsoft.com, vkuznets@redhat.com Subject: [PATCH 9/11] KVM/MMU: Flush tlb in the kvm_mmu_write_protect_pt_masked() Date: Fri, 4 Jan 2019 16:54:03 +0800 Message-Id: <20190104085405.40356-10-Tianyu.Lan@microsoft.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20190104085405.40356-1-Tianyu.Lan@microsoft.com> References: <20190104085405.40356-1-Tianyu.Lan@microsoft.com> To: unlisted-recipients:; (no To-header on input) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Lan Tianyu This patch is to flush tlb in the kvm_mmu_write_protect_pt_masked() when tlb range flush is available and make kvm_mmu_write_protect_pt_masked() return flush request. Signed-off-by: Lan Tianyu --- arch/x86/kvm/mmu.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 9d8ee6ea02db..30ed7a79335b 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -1624,20 +1624,30 @@ static bool __rmap_set_dirty(struct kvm *kvm, struct kvm_rmap_head *rmap_head) * Used when we do not need to care about huge page mappings: e.g. during dirty * logging we do not have any such mappings. */ -static void kvm_mmu_write_protect_pt_masked(struct kvm *kvm, +static bool kvm_mmu_write_protect_pt_masked(struct kvm *kvm, struct kvm_memory_slot *slot, gfn_t gfn_offset, unsigned long mask) { struct kvm_rmap_head *rmap_head; + bool flush = false; while (mask) { rmap_head = __gfn_to_rmap(slot->base_gfn + gfn_offset + __ffs(mask), PT_PAGE_TABLE_LEVEL, slot); - __rmap_write_protect(kvm, rmap_head, false); + flush |= __rmap_write_protect(kvm, rmap_head, false); /* clear the first set bit */ mask &= mask - 1; } + + if (flush && kvm_available_flush_tlb_with_range()) { + kvm_flush_remote_tlbs_with_address(kvm, + slot->base_gfn + gfn_offset, + hweight_long(mask)); + flush = false; + } + + return flush; } /** @@ -1683,13 +1693,14 @@ bool kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, struct kvm_memory_slot *slot, gfn_t gfn_offset, unsigned long mask) { - if (kvm_x86_ops->enable_log_dirty_pt_masked) + if (kvm_x86_ops->enable_log_dirty_pt_masked) { kvm_x86_ops->enable_log_dirty_pt_masked(kvm, slot, gfn_offset, mask); - else - kvm_mmu_write_protect_pt_masked(kvm, slot, gfn_offset, mask); - - return true; + return true; + } else { + return kvm_mmu_write_protect_pt_masked(kvm, slot, gfn_offset, + mask); + } } /** From patchwork Fri Jan 4 08:54:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 10748183 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 30DC113AD for ; Fri, 4 Jan 2019 08:55:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1DD0727F94 for ; Fri, 4 Jan 2019 08:55:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 11D0D27FA8; Fri, 4 Jan 2019 08:55:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 21C6B27FA1 for ; Fri, 4 Jan 2019 08:55:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727638AbfADIzh (ORCPT ); Fri, 4 Jan 2019 03:55:37 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:45926 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726831AbfADIzg (ORCPT ); Fri, 4 Jan 2019 03:55:36 -0500 Received: by mail-pf1-f194.google.com with SMTP id g62so17990669pfd.12; Fri, 04 Jan 2019 00:55:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=jpcu1UDIzC/kZYsb/gD7gMQHyU/ryGJIi1afoCM5WAo=; b=uYtXsf4KIDh9LezuYtZ7zSYxTE+/XshKGvpm0xrDg3LRur0+tzRgdIreLklPxEYVIe PecWg6ZXtTLu08gU2tz3BPlYcDb7BHisnyzcvGV44YmgI2UVh0+hcc9JNnr3m3Iycc/0 PgAwxujtUIe+QPtpRx+M5VdEq8fXlXGeqkaUTr9810fDzMNow8Gtxx64SSQ4l+yTgGV0 sJctkDYrAF1DYO2wZ8o4l/KtIr0vFeUCP1/s4XPtdIWCF8k7RgBUsUlvvgrhaVBdJA68 6BOnYnxN2EDB29YpMebA227bqbaCBL66cIlthj/Wqqq1zUZ0dibvkmdSV3Kzcl1Aouyq qlhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=jpcu1UDIzC/kZYsb/gD7gMQHyU/ryGJIi1afoCM5WAo=; b=I03QrOoHrTJKN2T4RIk1z8E3QibT9BPc/79Kz6ry8yYs3VOavC6JfI02IROc37GP3v L1R+tiTItzLiLCs6L2vmJN5jqWBdFGrL+YywCGg5Ox08W/yvYkm34V2A+pvxlOmc0Ych q4mufC7QMK0leYTs2AVeAfMiAtobnlfQAVl9EiE3Q3IPiCmmLzFoqeEL6mA+g17hJsZK QtAaUPsY1r4FoXqDtbosxX8xSIU6imE37hjb5OF5alfmF8Mpz++KurPl++d58SHzWSy0 LSqLVZ3Kq8o2GhCHxZFCLd9lUksl+b9hK+b5/s8EkvdrhcvjHau8nLlml4f7wCSfKyq1 faHA== X-Gm-Message-State: AJcUukdmol3BNun+61lLBPDMNc6O1Y/iVtlU4IoDM9L0tNJbS4aKD/8s VXmvTgG15obOaLqRoGKx+xE= X-Google-Smtp-Source: ALg8bN6ahrlL+oFKWxOoz2sJm1EjP7AL3RCAAXyAPt/DmDTu1SnMvuyb7+QWMxqcv2be9BRNLP48DA== X-Received: by 2002:a65:5286:: with SMTP id y6mr19921670pgp.439.1546592134904; Fri, 04 Jan 2019 00:55:34 -0800 (PST) Received: from localhost.corp.microsoft.com ([2404:f801:9000:1a:d9bd:62c6:740b:9fc4]) by smtp.googlemail.com with ESMTPSA id i21sm99772145pgm.17.2019.01.04.00.55.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Jan 2019 00:55:34 -0800 (PST) From: lantianyu1986@gmail.com X-Google-Original-From: Tianyu.Lan@microsoft.com Cc: Lan Tianyu , christoffer.dall@arm.com, marc.zyngier@arm.com, linux@armlinux.org.uk, catalin.marinas@arm.com, will.deacon@arm.com, jhogan@kernel.org, ralf@linux-mips.org, paul.burton@mips.com, paulus@ozlabs.org, benh@kernel.crashing.org, mpe@ellerman.id.au, pbonzini@redhat.com, rkrcmar@redhat.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, x86@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, kvm-ppc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, michael.h.kelley@microsoft.com, kys@microsoft.com, vkuznets@redhat.com Subject: [PATCH 10/11] KVM: Add flush parameter for kvm_age_hva() Date: Fri, 4 Jan 2019 16:54:04 +0800 Message-Id: <20190104085405.40356-11-Tianyu.Lan@microsoft.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20190104085405.40356-1-Tianyu.Lan@microsoft.com> References: <20190104085405.40356-1-Tianyu.Lan@microsoft.com> To: unlisted-recipients:; (no To-header on input) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Lan Tianyu This patch is to add flush parameter for kvm_aga_hva() and inside code can check whether tlb flush is necessary when associated sptes are changed. The platform may just flush affected address tlbs instead of entire table's. Signed-off-by: Lan Tianyu --- arch/arm/include/asm/kvm_host.h | 3 ++- arch/arm64/include/asm/kvm_host.h | 3 ++- arch/mips/include/asm/kvm_host.h | 3 ++- arch/mips/kvm/mmu.c | 3 ++- arch/powerpc/include/asm/kvm_host.h | 3 ++- arch/powerpc/kvm/book3s.c | 3 ++- arch/powerpc/kvm/e500_mmu_host.c | 3 ++- arch/x86/include/asm/kvm_host.h | 3 ++- arch/x86/kvm/mmu.c | 5 +++-- virt/kvm/arm/mmu.c | 3 ++- virt/kvm/kvm_main.c | 4 ++-- 11 files changed, 23 insertions(+), 13 deletions(-) diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h index 4f3400a74a17..7d7f9ff27500 100644 --- a/arch/arm/include/asm/kvm_host.h +++ b/arch/arm/include/asm/kvm_host.h @@ -229,7 +229,8 @@ int kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte); unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu); int kvm_arm_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *indices); -int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end); +int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end, + bool flush); int kvm_test_age_hva(struct kvm *kvm, unsigned long hva); struct kvm_vcpu *kvm_arm_get_running_vcpu(void); diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 063886be25ad..6f4539e13a26 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -361,7 +361,8 @@ int __kvm_arm_vcpu_set_events(struct kvm_vcpu *vcpu, int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end); int kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte); -int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end); +int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end, + bool flush); int kvm_test_age_hva(struct kvm *kvm, unsigned long hva); struct kvm_vcpu *kvm_arm_get_running_vcpu(void); diff --git a/arch/mips/include/asm/kvm_host.h b/arch/mips/include/asm/kvm_host.h index 71c3f21d80d5..ae1b079ad740 100644 --- a/arch/mips/include/asm/kvm_host.h +++ b/arch/mips/include/asm/kvm_host.h @@ -934,7 +934,8 @@ enum kvm_mips_fault_result kvm_trap_emul_gva_fault(struct kvm_vcpu *vcpu, int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end); int kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte); -int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end); +int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end, + bool flush); int kvm_test_age_hva(struct kvm *kvm, unsigned long hva); /* Emulation */ diff --git a/arch/mips/kvm/mmu.c b/arch/mips/kvm/mmu.c index f36ccb2d43ec..b69baf01dbac 100644 --- a/arch/mips/kvm/mmu.c +++ b/arch/mips/kvm/mmu.c @@ -582,7 +582,8 @@ static int kvm_test_age_hva_handler(struct kvm *kvm, gfn_t gfn, gfn_t gfn_end, return pte_young(*gpa_pte); } -int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end) +int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end, + bool flush) { return handle_hva_to_gpa(kvm, start, end, kvm_age_hva_handler, NULL); } diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h index 0f98f00da2ea..d160e6b8ccfb 100644 --- a/arch/powerpc/include/asm/kvm_host.h +++ b/arch/powerpc/include/asm/kvm_host.h @@ -70,7 +70,8 @@ extern int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end); -extern int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end); +extern int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end, + bool flush); extern int kvm_test_age_hva(struct kvm *kvm, unsigned long hva); extern int kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte); diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c index bd1a677dd9e4..430a8b81ef81 100644 --- a/arch/powerpc/kvm/book3s.c +++ b/arch/powerpc/kvm/book3s.c @@ -841,7 +841,8 @@ int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end) return kvm->arch.kvm_ops->unmap_hva_range(kvm, start, end); } -int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end) +int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end, + bool flush) { return kvm->arch.kvm_ops->age_hva(kvm, start, end); } diff --git a/arch/powerpc/kvm/e500_mmu_host.c b/arch/powerpc/kvm/e500_mmu_host.c index c3f312b2bcb3..e2f6c23ec39a 100644 --- a/arch/powerpc/kvm/e500_mmu_host.c +++ b/arch/powerpc/kvm/e500_mmu_host.c @@ -745,7 +745,8 @@ int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end) return 0; } -int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end) +int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end, + bool flush) { /* XXX could be more clever ;) */ return 0; diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 22dbaa8fba32..4f3ff9d5b631 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1518,7 +1518,8 @@ asmlinkage void kvm_spurious_fault(void); #define KVM_ARCH_WANT_MMU_NOTIFIER int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end); -int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end); +int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end, + bool flush); int kvm_test_age_hva(struct kvm *kvm, unsigned long hva); int kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte); int kvm_cpu_has_injectable_intr(struct kvm_vcpu *v); diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 30ed7a79335b..a5728f51bf7d 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -1995,9 +1995,10 @@ static void rmap_recycle(struct kvm_vcpu *vcpu, u64 *spte, gfn_t gfn) KVM_PAGES_PER_HPAGE(sp->role.level)); } -int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end) +int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end, + bool flush) { - return kvm_handle_hva_range(kvm, start, end, 0, kvm_age_rmapp); + return kvm_handle_hva_range(kvm, start, end, flush, kvm_age_rmapp); } int kvm_test_age_hva(struct kvm *kvm, unsigned long hva) diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c index 232007ff3208..bbea7cfd6909 100644 --- a/virt/kvm/arm/mmu.c +++ b/virt/kvm/arm/mmu.c @@ -2110,7 +2110,8 @@ static int kvm_test_age_hva_handler(struct kvm *kvm, gpa_t gpa, u64 size, void * return pte_young(*pte); } -int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end) +int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end, + bool flush) { if (!kvm->arch.pgd) return 0; diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index bcbe059d98be..afec5787fc1d 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -432,7 +432,7 @@ static int kvm_mmu_notifier_clear_flush_young(struct mmu_notifier *mn, idx = srcu_read_lock(&kvm->srcu); spin_lock(&kvm->mmu_lock); - young = kvm_age_hva(kvm, start, end); + young = kvm_age_hva(kvm, start, end, true); if (young) kvm_flush_remote_tlbs(kvm); @@ -465,7 +465,7 @@ static int kvm_mmu_notifier_clear_young(struct mmu_notifier *mn, * cadence. If we find this inaccurate, we might come up with a * more sophisticated heuristic later. */ - young = kvm_age_hva(kvm, start, end); + young = kvm_age_hva(kvm, start, end, false); spin_unlock(&kvm->mmu_lock); srcu_read_unlock(&kvm->srcu, idx); From patchwork Fri Jan 4 08:54:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 10748181 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 51B4713AD for ; Fri, 4 Jan 2019 08:55:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4164E27F94 for ; Fri, 4 Jan 2019 08:55:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 33FF527FA9; Fri, 4 Jan 2019 08:55:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 32E7227F94 for ; Fri, 4 Jan 2019 08:55:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727627AbfADIzl (ORCPT ); Fri, 4 Jan 2019 03:55:41 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:37689 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727670AbfADIzj (ORCPT ); Fri, 4 Jan 2019 03:55:39 -0500 Received: by mail-pf1-f196.google.com with SMTP id y126so17999622pfb.4; Fri, 04 Jan 2019 00:55:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bFhTxRoojn12l2v/yr4tpMYZ43n7CONVzFkfmruJPC4=; b=rM10repyD4Y8kcaAjETDg1X0Bu+JhXLQo7cbDWx1hrA5ucTIzCisQdDHXPXEW3YmC6 Dy/1/PYVjvwOG3yOmAmghVexXTkBXomdTbwfMEKLdoeeqxbADR+1XxYbZaLPz9sV/2zP vAyRxQSq338vFtvyc64w5EJxUPHWh5PyII0oOi1UqvjX1OV76erQvJtnIu1iX2qXzR0z 4hWxsOGZ1df656/DeY6cw8iLEU5qHIXTLLthKxvVEQSIGqmJu0mug0SAZcWBpZBy/vmw qJKb21fNaCA2jjoesZ8A+Ms898MgN7NXyWh8Hnaw81sTt9FZeGbAiKK0rhudGJM3bpEc cmBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bFhTxRoojn12l2v/yr4tpMYZ43n7CONVzFkfmruJPC4=; b=JlKZ1qhIbyy7XfBdvo5gKBjrsc441qReDQOWn+IpVrY7/shlOnghT4Wv2q84zlGbqB h1luAwAyyhjI0dEzulr1lkj2HNFYwAL/q0CJM70otFCdXf4Sjy36lriBmB5ppI2x9uyL zMrQdRSlEPcnL1ieDykn2xtLHwiJV0quZ5MnIc71Abu/cFxHOcI9X/JTTEP2NON3RtbZ 3ESkq+euUebcvSJiMHspwl2fFjaIGcTcCaYUTmGnbHYCZ8H/Pfeky7R3i6JdZAhO4EU+ 0MKolqE+Pr1wUMCe+QkQO1cBDNODQi+7H5Z6uQwCWfIT42WfR/ipVRPdC1k2JL7lxOd0 v13w== X-Gm-Message-State: AA+aEWZp9I4soD+9iu7h7JFdRUO9Mm7UTJIk3wR0FII2TTeSkQTdaIti dwUP+DKukA17mSUoDjD/ZsM= X-Google-Smtp-Source: AFSGD/WLbcK/sBL1vUFtY+st3cDiVTDCkscYZofl5pg01nGixnT8QCsj2JBsXfbZXiFRU4LU4JyZ2g== X-Received: by 2002:a62:61c3:: with SMTP id v186mr51896451pfb.55.1546592139149; Fri, 04 Jan 2019 00:55:39 -0800 (PST) Received: from localhost.corp.microsoft.com ([2404:f801:9000:1a:d9bd:62c6:740b:9fc4]) by smtp.googlemail.com with ESMTPSA id i21sm99772145pgm.17.2019.01.04.00.55.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Jan 2019 00:55:38 -0800 (PST) From: lantianyu1986@gmail.com X-Google-Original-From: Tianyu.Lan@microsoft.com Cc: Lan Tianyu , pbonzini@redhat.com, rkrcmar@redhat.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, michael.h.kelley@microsoft.com, kys@microsoft.com, vkuznets@redhat.com, linux@armlinux.org.uk Subject: [PATCH 11/11] KVM/MMU: Flush tlb in the kvm_age_rmapp() Date: Fri, 4 Jan 2019 16:54:05 +0800 Message-Id: <20190104085405.40356-12-Tianyu.Lan@microsoft.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20190104085405.40356-1-Tianyu.Lan@microsoft.com> References: <20190104085405.40356-1-Tianyu.Lan@microsoft.com> To: unlisted-recipients:; (no To-header on input) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Lan Tianyu This patch is to flush tlb in the kvm_age_rmapp() when tlb range flush is available and flush request is true. Signed-off-by: Lan Tianyu --- arch/x86/kvm/mmu.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index a5728f51bf7d..bc402a72956a 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -1958,10 +1958,17 @@ static int kvm_age_rmapp(struct kvm *kvm, struct kvm_rmap_head *rmap_head, u64 *sptep; struct rmap_iterator uninitialized_var(iter); int young = 0; + bool flush = (bool)data; for_each_rmap_spte(rmap_head, &iter, sptep) young |= mmu_spte_age(sptep); + if (young && flush) { + kvm_flush_remote_tlbs_with_address(kvm, gfn, + KVM_PAGES_PER_HPAGE(level)); + young = 0; + } + trace_kvm_age_page(gfn, level, slot, young); return young; }