From patchwork Tue Jun 20 09:15:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 9798977 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E0748600C5 for ; Tue, 20 Jun 2017 09:21:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D791527968 for ; Tue, 20 Jun 2017 09:21:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CCA0728456; Tue, 20 Jun 2017 09:21:36 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 187E527968 for ; Tue, 20 Jun 2017 09:21:35 +0000 (UTC) Received: from localhost ([::1]:47468 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dNFLr-0003Nc-24 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 20 Jun 2017 05:21:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52974) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dNFGR-0000DD-AP for qemu-devel@nongnu.org; Tue, 20 Jun 2017 05:16:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dNFGM-0007qq-Dc for qemu-devel@nongnu.org; Tue, 20 Jun 2017 05:15:59 -0400 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]:33916) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dNFGM-0007qY-7p for qemu-devel@nongnu.org; Tue, 20 Jun 2017 05:15:54 -0400 Received: by mail-pg0-x243.google.com with SMTP id j186so20089633pge.1 for ; Tue, 20 Jun 2017 02:15:54 -0700 (PDT) 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=6h6lJbBHkCA3XqAXe2DZkCql54xEdqH+8hsl0mTN37k=; b=Tz4t/zfnS9KenH5yliqOm1CfDkL7cFWLeFJt1g11PmanN8SZBF/iSvsC57LowKYSIp I4mvyCKRkWw4ftYiP/50qQbe/2E+PXRHyviiUBW8aHlfuaB++GmvA6ikVAsZBgMIArlt u64mCFADy5yOLfpPYkYd8Ba1hzbDle+5XsOfJT4uUNdgzrMSDttRR/tbms66lt9YmXgc dJV0O0o1awhyAaifLixA+fptvDJfkC2E4SlvfqyCfcdUrCTbErr90cFkg17jeSKmJ046 FKacuQl3ylwlufEiYYDcICPxwMwuJEzJSrtvpVGcBtDqnvKYcWmJuN3AyI0mXPpQpG+m GZTQ== 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=6h6lJbBHkCA3XqAXe2DZkCql54xEdqH+8hsl0mTN37k=; b=WcYX4QXIOBe2OF279GUVzgF6jN1NkKkG80HrcnN1TRUK/qRaHHlVHmaLmtuhMeTDu+ I+ciq4CZxTumL0JkDdjwXFjVeZXqE+D409lS45azWPGTpqMAqe6YN1xefpa5KJm+p0rF fLhN1u8RT8/pWetUSH+6ZE8ZePmf+GlTlW46TE1onFCIgNdsVQy8Gi8Tq11Q+tA40OcQ TJwM3GN4ZEAVWBATMKBAsbpNgFlP1HTqarnECpZiaBDdgHJrsSGuSscoRJcCJGR9/xRD HKJ2jDZQ8oxHOSRKRNd1Pr/N2k+vpp9ldfA2Bj/TOGMaRRyl5QDkR4PNp+MLZTnms6S4 3B1g== X-Gm-Message-State: AKS2vOyr7JOpQKIhAIFbpJePF+mKs2z12s7Pi7wGjVFvZ9SI0aI6PDzS SQx7R3ZSK0H7cw== X-Received: by 10.99.104.136 with SMTP id d130mr30378377pgc.236.1497950153428; Tue, 20 Jun 2017 02:15:53 -0700 (PDT) Received: from eric.tencent.com ([203.205.141.35]) by smtp.gmail.com with ESMTPSA id o12sm26343810pfi.9.2017.06.20.02.15.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Jun 2017 02:15:53 -0700 (PDT) From: guangrong.xiao@gmail.com X-Google-Original-From: xiaoguangrong@tencent.com To: pbonzini@redhat.com, mtosatti@redhat.com, avi.kivity@gmail.com, rkrcmar@redhat.com Date: Tue, 20 Jun 2017 17:15:23 +0800 Message-Id: <20170620091526.4287-5-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170620091526.4287-1-xiaoguangrong@tencent.com> References: <20170620091526.4287-1-xiaoguangrong@tencent.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::243 Subject: [Qemu-devel] [PATCH v2 4/7] KVM: MMU: enable KVM_WRITE_PROTECT_ALL_MEM X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Xiao Guangrong , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Xiao Guangrong The functionality of write protection for all guest memory is ready, it is the time to make its usable for userspace which is indicated by KVM_CAP_X86_WRITE_PROTECT_ALL_MEM Signed-off-by: Xiao Guangrong --- arch/x86/kvm/x86.c | 21 +++++++++++++++++++++ include/uapi/linux/kvm.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index a2cd099..ad62c44 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -2723,6 +2723,17 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) case KVM_CAP_X2APIC_API: r = KVM_X2APIC_API_VALID_FLAGS; break; + case KVM_CAP_X86_WRITE_PROTECT_ALL_MEM: + /* + * do not enable it if PML is supported, this is also the + * hint to tell userspace write-protect is not needed for + * dirty log. + */ + if (kvm_x86_ops->slot_enable_log_dirty) + r = 0; + else + r = 1; + break; default: r = 0; break; @@ -4208,6 +4219,16 @@ long kvm_arch_vm_ioctl(struct file *filp, r = 0; break; } + case KVM_WRITE_PROTECT_ALL_MEM: { + if (kvm_x86_ops->slot_enable_log_dirty) { + r = -EINVAL; + break; + } + + kvm_mmu_write_protect_all_pages(kvm, !!arg); + r = 0; + break; + } case KVM_ENABLE_CAP: { struct kvm_enable_cap cap; diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 577429a..7d4a395 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -895,6 +895,7 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_SPAPR_TCE_VFIO 142 #define KVM_CAP_X86_GUEST_MWAIT 143 #define KVM_CAP_ARM_USER_IRQ 144 +#define KVM_CAP_X86_WRITE_PROTECT_ALL_MEM 145 #ifdef KVM_CAP_IRQ_ROUTING @@ -1144,6 +1145,7 @@ struct kvm_vfio_spapr_tce { struct kvm_userspace_memory_region) #define KVM_SET_TSS_ADDR _IO(KVMIO, 0x47) #define KVM_SET_IDENTITY_MAP_ADDR _IOW(KVMIO, 0x48, __u64) +#define KVM_WRITE_PROTECT_ALL_MEM _IO(KVMIO, 0x49) /* enable ucontrol for s390 */ struct kvm_s390_ucas_mapping {