From patchwork Wed May 3 10:52:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 9709381 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 49D8660351 for ; Wed, 3 May 2017 10:54:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D4A328427 for ; Wed, 3 May 2017 10:54:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 32258285E9; Wed, 3 May 2017 10:54:41 +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=ham 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 DAEA828427 for ; Wed, 3 May 2017 10:54:40 +0000 (UTC) Received: from localhost ([::1]:35769 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d5rvc-0005Og-5E for patchwork-qemu-devel@patchwork.kernel.org; Wed, 03 May 2017 06:54:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32996) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d5ruK-0005NA-UC for qemu-devel@nongnu.org; Wed, 03 May 2017 06:53:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d5ruH-0006iY-2e for qemu-devel@nongnu.org; Wed, 03 May 2017 06:53:21 -0400 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]:34352) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d5ruG-0006iI-Th for qemu-devel@nongnu.org; Wed, 03 May 2017 06:53:17 -0400 Received: by mail-pf0-x242.google.com with SMTP id d1so741628pfe.1 for ; Wed, 03 May 2017 03:53:16 -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=AzYyNQ06Lx6H4cu9f2kHtVmblBmCV/fv62RkgDYmyCw=; b=jQnUB9n3//6HMfjxWm4CUlLx7VQYDNb3pWNJRCt8X13bECCqGOPhnQncMIPk5nbZ9u c/mL6U7r5cYB4lUj1l0d1a9W4BqfcfNVzCyWaSQAP7pY5ZR7WUg72YDxNYso/dMLK2Xg 0PuBSVsfoHA56tn1Q5rV3/jJkh6GRfGu0ZCZJQ5YpEDX1s7T7H7oapo37u1/jOoVup/X IctdvF8gpKej9m3oVjzkii3SIe04SCMCnbv7QlOffxkvH9JfbagximEDDK6eRG7pH+YE 2kGepjuaKaB+bf+h5pePT9nPSCfMANaVOhNmlmkhUojW4Q6aQh6o4Zi6pfFkEnCC5bBf x4iA== 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=AzYyNQ06Lx6H4cu9f2kHtVmblBmCV/fv62RkgDYmyCw=; b=WEGMpTyJFVx7w/FF3CPLtUnxmi7h14EcLJNljCwVklgNgLuVWVnxCZilSB96eMogSp IhE4Yr30hxZaXxa/RxdBs6HFC5xQ7V0iHSz2sacdGB0xqXeEJjPaHEM3eGTg57MTsLd+ 5lnMjTTVjBWNDFxIlhDQYvHyGHN5pjxK646AcrWumVWWJw5+8ciD0M1MnTR8FMzTfEb8 nNJMJaoMdZK27/DdJmfA/meVmht8IoSv5AeRNOdD3WZqn5EOZ/Yu+r5t8RNXR7MC1ce+ HdVt+N+s5W7E+5g9IU3d27hXlN//SLfaN7LGqLnA84teXrgaYlRpAJBLZFP3r7POnEL8 MrOQ== X-Gm-Message-State: AN3rC/4F2cIGWH78t/dDnRmcDJUm3DTZJjEyIkKlWEcTV1jk71gPJSJh t5OZPZOdnlgnPHY3 X-Received: by 10.99.66.1 with SMTP id p1mr38355373pga.107.1493808795978; Wed, 03 May 2017 03:53:15 -0700 (PDT) Received: from eric.tencent.com ([203.205.141.35]) by smtp.gmail.com with ESMTPSA id d24sm4395561pfb.97.2017.05.03.03.53.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 May 2017 03:53:15 -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: Wed, 3 May 2017 18:52:21 +0800 Message-Id: <20170503105224.19049-5-xiaoguangrong@tencent.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170503105224.19049-1-xiaoguangrong@tencent.com> References: <20170503105224.19049-1-xiaoguangrong@tencent.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::242 Subject: [Qemu-devel] [PATCH 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 | 6 ++++++ include/uapi/linux/kvm.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index be2ade5..dcbeaf4 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -2669,6 +2669,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) case KVM_CAP_SET_BOOT_CPU_ID: case KVM_CAP_SPLIT_IRQCHIP: case KVM_CAP_IMMEDIATE_EXIT: + case KVM_CAP_X86_WRITE_PROTECT_ALL_MEM: r = 1; break; case KVM_CAP_ADJUST_CLOCK: @@ -4204,6 +4205,11 @@ long kvm_arch_vm_ioctl(struct file *filp, r = 0; break; } + case KVM_WRITE_PROTECT_ALL_MEM: { + 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 {