Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp5212303ybg; Mon, 21 Oct 2019 23:18:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqzYNuQunC3XMONgfCxsBu0tTPviAKmZadi2OanhF0mbVRFdz3SYwWGD1jZMtfzV3XspMyg+ X-Received: by 2002:a05:6402:12d4:: with SMTP id k20mr29619140edx.241.1571725122958; Mon, 21 Oct 2019 23:18:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571725122; cv=none; d=google.com; s=arc-20160816; b=GwaffXSca8u1VZnXXyBy6dxB2oykXT6KUsvS7I47j2bVr2WsqATJ2QKjrXkoYXx7SF yk3HOkdJQO8E7pygr1kk7hQDTXmzl27s57Fj4gjNg7JQx6VKeN5OdLYAUZR2VEgtybJT XA/V9pUBMF4X0uWZRSSVJnLPHXU1xLeMEACJRBlDR8GlvyolyTM3kz7GfyDfXU6WJ0uE sdfkMAcn8JV1mEYjQ6F/qFVcxpI+9NP9LdusgI3lEZKu7T9cPWpLQ+PGMsdJowfNNcPi StdiNIMFmj58VgpS1MLCDLt7UVEOo+Wz8myU6ZCrwwYJu2M/Hz9Cmut8AYQxlluif1BZ Zjfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=lBCgehJaYEokVyovfDxrNuWOBmyja0/uONPnSJyxpEg=; b=aPFTEf2Izn8Su+J8vkpVTD0dKyd+tqvH8BQ/e+XuFrVu6JqhdeQwExs3JsMC5pR4XG 4zv4Kwq7eSBmdH3vTJnMjqtpp5yBCvPnTv+RUykK6RyvsWnTCPfjUf5LHPqroyipIT0f IeLgm/MzpH7wPl++4jNhCE1RymHIBpiuEmy39Hd/9n3VXUnD2x/WZgR3Gm0QEMsWV+4x X0wAxC66PAXr22qqQ9GtWq8iweyu2pAzVUyOugw/HvnzRiw60udgHy4XJg/iEmk5exv1 WIbXQGnAQZY2uCNtdhVU21NhVyKNW3bG0HQWNzrllFWKWTzCoLeHVEFE569PZ6OSWn4k l6eQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ay2si10655335edb.343.2019.10.21.23.18.19; Mon, 21 Oct 2019 23:18:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387705AbfJVGQb (ORCPT + 99 others); Tue, 22 Oct 2019 02:16:31 -0400 Received: from mga07.intel.com ([134.134.136.100]:49039 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387508AbfJVGQb (ORCPT ); Tue, 22 Oct 2019 02:16:31 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Oct 2019 23:16:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.67,326,1566889200"; d="scan'208";a="227583987" Received: from local-michael-cet-test.sh.intel.com (HELO localhost) ([10.239.159.128]) by fmsmga002.fm.intel.com with ESMTP; 21 Oct 2019 23:16:21 -0700 Date: Tue, 22 Oct 2019 14:19:15 +0800 From: Yang Weijiang To: Jim Mattson Cc: Yang Weijiang , kvm list , LKML , Paolo Bonzini , Sean Christopherson , "Michael S. Tsirkin" , Radim =?utf-8?B?S3LEjW3DocWZ?= , yu.c.zhang@intel.com, alazar@bitdefender.com Subject: Re: [PATCH v5 0/9] Enable Sub-page Write Protection Support Message-ID: <20191022061915.GA18889@local-michael-cet-test> References: <20190917085304.16987-1-weijiang.yang@intel.com> <20191011075033.GA11817@local-michael-cet-test> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.3 (2019-02-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 11, 2019 at 09:11:54AM -0700, Jim Mattson wrote: > On Fri, Oct 11, 2019 at 12:48 AM Yang Weijiang wrote: > > > > On Thu, Oct 10, 2019 at 02:42:51PM -0700, Jim Mattson wrote: > > > On Tue, Sep 17, 2019 at 1:52 AM Yang Weijiang wrote: > > > > > > > > EPT-Based Sub-Page write Protection(SPP)is a HW capability which allows > > > > Virtual Machine Monitor(VMM) to specify write-permission for guest > > > > physical memory at a sub-page(128 byte) granularity. When this > > > > capability is enabled, the CPU enforces write-access check for sub-pages > > > > within a 4KB page. > > > > > > > > The feature is targeted to provide fine-grained memory protection for > > > > usages such as device virtualization, memory check-point and VM > > > > introspection etc. > > > > > > > > SPP is active when the "sub-page write protection" (bit 23) is 1 in > > > > Secondary VM-Execution Controls. The feature is backed with a Sub-Page > > > > Permission Table(SPPT), SPPT is referenced via a 64-bit control field > > > > called Sub-Page Permission Table Pointer (SPPTP) which contains a > > > > 4K-aligned physical address. > > > > > > > > To enable SPP for certain physical page, the gfn should be first mapped > > > > to a 4KB entry, then set bit 61 of the corresponding EPT leaf entry. > > > > While HW walks EPT, if bit 61 is set, it traverses SPPT with the guset > > > > physical address to find out the sub-page permissions at the leaf entry. > > > > If the corresponding bit is set, write to sub-page is permitted, > > > > otherwise, SPP induced EPT violation is generated. > > > > > > How do you handle sub-page permissions for instructions emulated by kvm? > > How about checking if the gpa is SPP protected, if it is, inject some > > exception to guest? > The SPP semantics are well-defined. If a kvm-emulated instruction > tries to write to a sub-page that is write-protected, then an > SPP-induced EPT violation should be synthesized. Hi, Jim, Regarding the emulated instructions in KVM, there're quite a few instructions can write guest memory, such as MOVS, XCHG, INS etc., check each destination against SPP protected area would be trivial if deals with them individually, and PIO/MMIO induced vmexit/page_fault also can link to a SPP protected page, e.g., a string instruction's the destination is SPP protected memory. Is there a good way to intercept these writes? emulate_ops.write_emulated() is called in most of the emulation cases to check and write guest memory, but not sure it's suitable. Do you have any suggestion? Thanks!