Received: by 10.223.148.5 with SMTP id 5csp6174785wrq; Wed, 17 Jan 2018 10:20:03 -0800 (PST) X-Google-Smtp-Source: ACJfBou76hlaxzBsIDFpebu+rZxNCem3NF+nUeS2wSFZasi92TRQTQtfB8xt/AitutIcH97rpjjj X-Received: by 10.99.96.199 with SMTP id u190mr33240567pgb.290.1516213203773; Wed, 17 Jan 2018 10:20:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516213203; cv=none; d=google.com; s=arc-20160816; b=gDlDb+DMF5Ey35VSvkFCQzGSwRcml5SJg/Nfn/oxenAOwA8xjPN6s+z2PNAZichmxu N9YdbixhIAIJkU34jUfJL1E/YW7u9DXfYUzL/709s7+LJpnSuGLS06GpHot6cWOnr3+x meCnL5zcBynZ1fT0A7yOnr4bBOQSFzlmampw/pIlD5nHhh9Os5dDPuMrVW6SOMhwg5zQ CX37xGFYjOv1+V9jAGXvda6SO0NDvNfpzm8MozUTMRVSaQO1FzPkA2rYZOlbRvQiARIi TmkbMthrHr8HxoMMGdcULlwaKu6E85cdGszjGv/85UCJTs0Z5sQ73KyH2oxh7RePjpX1 Hugw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=e/IzGWlzlZMM6I4VjQvzYsHRBvdTMzbDTo7sYg2r3K0=; b=IGo/yZynLs0DUWaz/Z2f+XFmUPuyAXgZiqWgKe4JJLcIDtOMXH5qclCSeqR+baXMwn Qvu3Eg261OoxgNlRDCBiDRlyeaYb02htzgNT1MGcg+lxAoXCXC+qnyryxwZeDJXyH4+p XEg5lvnZYOluF5wCEfjNXZ7yAk0sIpV9ngUkt1S4NT3uMHmmAA4R/2GPTcuB5DWicyXw dXT+Ymj3Dwsnqj8aRtPAb1v9q9NXEOzAMh+JWuVTBamoMToPaBjksiEHs84dorRBlhig 5k0UygJEHXz5JbZB4PEqxhIS/ldkqReqBFik1neRigmHvtKKIB3oaTfG7B9U6fsxeI1M OH+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=e3v92acD; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k78si4731813pfk.142.2018.01.17.10.19.48; Wed, 17 Jan 2018 10:20:03 -0800 (PST) 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; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=e3v92acD; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753694AbeAQSTX (ORCPT + 99 others); Wed, 17 Jan 2018 13:19:23 -0500 Received: from smtp-fw-9102.amazon.com ([207.171.184.29]:53410 "EHLO smtp-fw-9102.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752268AbeAQSTW (ORCPT ); Wed, 17 Jan 2018 13:19:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1516213162; x=1547749162; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=e/IzGWlzlZMM6I4VjQvzYsHRBvdTMzbDTo7sYg2r3K0=; b=e3v92acD4vhneDiZw1pku1+lYAag89rHqMmJp4CV5IBK8gDRRSVtjvT+ m61gIxm1HDDIolwzCv34sC393i6m0TCDi5cbdvsHUSYqZIBmsoVo1Su4b l9XGcgBKP4u/rmVYaG8iiVZOicUFVykeMSVZERg9rb+bwGc6si6flHfH7 4=; X-IronPort-AV: E=Sophos;i="5.46,372,1511827200"; d="scan'208";a="587316527" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-1e-62350142.us-east-1.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 17 Jan 2018 18:19:16 +0000 Received: from u54e1ad5160425a4b64ea.ant.amazon.com (iad1-ws-svc-lb91-vlan3.amazon.com [10.0.103.150]) by email-inbound-relay-1e-62350142.us-east-1.amazon.com (8.14.7/8.14.7) with ESMTP id w0HIJBmM070163 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 17 Jan 2018 18:19:13 GMT Received: from u54e1ad5160425a4b64ea.ant.amazon.com (localhost [127.0.0.1]) by u54e1ad5160425a4b64ea.ant.amazon.com (8.15.2/8.15.2/Debian-3) with ESMTP id w0HIJA4C012949; Wed, 17 Jan 2018 19:19:10 +0100 Received: (from karahmed@localhost) by u54e1ad5160425a4b64ea.ant.amazon.com (8.15.2/8.15.2/Submit) id w0HIJ9sB012946; Wed, 17 Jan 2018 19:19:09 +0100 From: KarimAllah Ahmed To: kvm@vger.kernel.org Cc: KarimAllah Ahmed , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , linux-kernel@vger.kernel.org Subject: [PATCH v2] kvm: Map PFN-type memory regions as writable (if possible) Date: Wed, 17 Jan 2018 19:18:56 +0100 Message-Id: <1516213136-12883-1-git-send-email-karahmed@amazon.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <64411cad-77ee-2f6e-d431-78e853cae65d@redhat.com> References: <64411cad-77ee-2f6e-d431-78e853cae65d@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For EPT-violations that are triggered by a read, the pages are also mapped with write permissions (if their memory region is also writable). That would avoid getting yet another fault on the same page when a write occurs. This optimization only happens when you have a "struct page" backing the memory region. So also enable it for memory regions that do not have a "struct page". Cc: Paolo Bonzini Cc: Radim Krčmář Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: KarimAllah Ahmed --- v2: - Move setting writable to hva_to_pfn_remapped - Extend hva_to_pfn_remapped interface to accept writable as a parameter --- virt/kvm/kvm_main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 97da45e..88702d5 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1438,7 +1438,8 @@ static bool vma_is_valid(struct vm_area_struct *vma, bool write_fault) static int hva_to_pfn_remapped(struct vm_area_struct *vma, unsigned long addr, bool *async, - bool write_fault, kvm_pfn_t *p_pfn) + bool write_fault, bool *writable, + kvm_pfn_t *p_pfn) { unsigned long pfn; int r; @@ -1464,6 +1465,8 @@ static int hva_to_pfn_remapped(struct vm_area_struct *vma, } + if (writable) + *writable = true; /* * Get a reference here because callers of *hva_to_pfn* and @@ -1529,7 +1532,7 @@ static kvm_pfn_t hva_to_pfn(unsigned long addr, bool atomic, bool *async, if (vma == NULL) pfn = KVM_PFN_ERR_FAULT; else if (vma->vm_flags & (VM_IO | VM_PFNMAP)) { - r = hva_to_pfn_remapped(vma, addr, async, write_fault, &pfn); + r = hva_to_pfn_remapped(vma, addr, async, write_fault, writable, &pfn); if (r == -EAGAIN) goto retry; if (r < 0) -- 2.7.4