Received: by 10.223.148.5 with SMTP id 5csp7099765wrq; Thu, 18 Jan 2018 00:37:07 -0800 (PST) X-Google-Smtp-Source: ACJfBotZUsjjzEugw/qiqzXwvSadnxIw4oK/XUJ2Ek2AOSkC2kNjMN0WxMDVxjiEZoB/SjyGAnja X-Received: by 10.98.194.212 with SMTP id w81mr18369509pfk.232.1516264627278; Thu, 18 Jan 2018 00:37:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516264627; cv=none; d=google.com; s=arc-20160816; b=Yblk5AMknK4hRzycT9Nzj5oo3IJQ527x/PXSMYdVu7dKv+0Z5NsCzXfE4RX0fM2arV vN+OiO2LRHtH4dNHCGJ863xp5OYyf45umPBwLmpmvr3IDsfyyGznerO3AZ1spabFLLum UeM6hlTLHAUwAIedpvpm1n8HPY4gn8QF0bukAVyxKPnPXE+3flZlkPjJ2ftz7VoxgKvX aHsvklWeosafJdLmdXf5QC5ni7pZ1FvLl3lB6aKkXMjIfec1PttZHSCGpb2H5MVjBNts IOQhDJGGassTzsI088wMyBSHI5VEauOzJFqPM81k/Z0zkBZliDb5iJRmB6GXBYsyLdjT W24w== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=umF5NZDZ/1Vd5E8FleNgDgGOYovZ259P8lfvYxXRnps=; b=OsKKZqNiOwxRbJY/isxpigviPIBihlOrDiLZUqIjy89wWz9p/FX1bAc5gdjwaZ00i6 EaXLlG3ZzCHWpPJMjPl9SClUcVcC+iJ7Ej8U98aaSKff3Hu8W9Q0CiMlpgD9jywupCjm lKrHBw5CMpYbueMiGNfJ1YOBnaKLHjxFAiEc7OdyCDtFb95rboI9vXkXINsONzYMWj9C EVAcGqWty2vTZKEECARjY+SSlDd8wS3wrnWQpiutpjSvwb2rhbnywVjPmto05oHjP3wH 7ardjqhzYrSvKJ4BGFVweeX8rK09MiotdPdrXm4QOuZYUGT2C++TugvU0ETja+EEQ1YJ EIGg== 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h16si6184100pfk.293.2018.01.18.00.36.53; Thu, 18 Jan 2018 00:37:07 -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; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754836AbeARIgV (ORCPT + 99 others); Thu, 18 Jan 2018 03:36:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53398 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753412AbeARIgU (ORCPT ); Thu, 18 Jan 2018 03:36:20 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 19B5912E51D; Thu, 18 Jan 2018 08:36:20 +0000 (UTC) Received: from [10.36.117.99] (ovpn-117-99.ams2.redhat.com [10.36.117.99]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B42D760CA1; Thu, 18 Jan 2018 08:36:18 +0000 (UTC) Subject: Re: [PATCH v2] kvm: Map PFN-type memory regions as writable (if possible) To: KarimAllah Ahmed , kvm@vger.kernel.org Cc: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , linux-kernel@vger.kernel.org References: <64411cad-77ee-2f6e-d431-78e853cae65d@redhat.com> <1516213136-12883-1-git-send-email-karahmed@amazon.de> From: Paolo Bonzini Message-ID: <091cebf2-4403-93b9-6eb2-2bc73a4c96af@redhat.com> Date: Thu, 18 Jan 2018 09:36:16 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <1516213136-12883-1-git-send-email-karahmed@amazon.de> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 18 Jan 2018 08:36:20 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 17/01/2018 19:18, KarimAllah Ahmed wrote: > 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 Reviewed-by: Paolo Bonzini > --- > 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) >