Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp967450pxu; Wed, 2 Dec 2020 07:49:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJyfXRuaeqqWy6QMfs6BA2xaXWAVxe/FYDXNAYBoNt3VqJ9v6OxAjV+mC1dAbVuNZmTJr1DJ X-Received: by 2002:a17:906:3883:: with SMTP id q3mr411031ejd.160.1606924187622; Wed, 02 Dec 2020 07:49:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606924187; cv=none; d=google.com; s=arc-20160816; b=m7mK2T+c/tZGfXXRHq0AQ/MroTrpjAahzJb8IXnCqB9Fxc6eZx97nHKrVobNs0qtC9 LoZWz4jt8oxNPaRmsxuZMwU9xjJfPJ1RYwVOD6iT0iF5dFz1SE0pflUfD4bzam/qE7di PqohbQmQa3uhxUZg2nZDcXTqI/bH/XHMKuZH91zFlSnNDEp4nio+RGzw7sitGnzrzweR ylCY54UJuNI70GbTQ22NN63d5KSncvh3k8H6CkBvb92IgQClO+7Ocb3yIKlu27WuqdES SFEj6xXNpw9noK62G8QTnWG3IQUf/V1dK2NKDvOe0eH8n2X+NJ4362daNP8YXhpy68d0 uDQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=rYeojU2BV32koHjOp1T69U+yIm9pG6hdZwR2k7JADHk=; b=Q4lw9d1b0Di7yWhCaVUu3ZqU5afh6z34LWsCbRKxfiDCjL06Cp4zsCbrKJNJX/QSNW vN+U2dPw70bq7rxhK4Sfxwe8hYSU/YXbIJlp+WTNyzP7HwaFyVfwzSj/ekhwAollIodQ HV94MtH72qrt+EgOhZ3i9DfNA9eAnv0vqw6lx0WBQQYzudVQkvvP4ykY4cy1M4dF/7zr cmlR8X+3GYW3G0fhdMC9atwwT5eFdqvk8Q3/TF/ezwSZlSjSUxjjMP+W4FUdtTgHJJ4A v07Cy498mo5up/80uLY5URfsARlX+E3yslnHTN6AH3wxOYcl+5n1kUTbZJmAdcK58xmr fe/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZevwB4CH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a3si124571ejx.101.2020.12.02.07.49.24; Wed, 02 Dec 2020 07:49:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZevwB4CH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728462AbgLBPqn (ORCPT + 99 others); Wed, 2 Dec 2020 10:46:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:25938 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726307AbgLBPqm (ORCPT ); Wed, 2 Dec 2020 10:46:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606923916; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=rYeojU2BV32koHjOp1T69U+yIm9pG6hdZwR2k7JADHk=; b=ZevwB4CH244ZL5zLGCLK+zRgLfaEBCxm11S9i1Dqp3kC1JXLC0qt8gyvI9xvGp5FgO2QrM k9L6bE2dV6Mkgc8pWBoIP7NLfIYO+5kLxR6UkhNO5sbum2Xy8jAWd6tZ5T9ECtt3eWmU5d 5Lz2HQFbA5ReSBMDd2e37B84LBIGu/4= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-395-5qLib_7XO8WbdKpY8Yr0xA-1; Wed, 02 Dec 2020 10:45:15 -0500 X-MC-Unique: 5qLib_7XO8WbdKpY8Yr0xA-1 Received: by mail-qv1-f71.google.com with SMTP id o16so1503069qvq.4 for ; Wed, 02 Dec 2020 07:45:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=rYeojU2BV32koHjOp1T69U+yIm9pG6hdZwR2k7JADHk=; b=cQkVIUhvHJUZ6hhdGfmnNsltwVVlVLQiJ/oDpVjcOj7kpnEGsVLKH8RDxJLVx7tv71 5UEEcIck/zYrI7TEzwvd3NL741TJSVfb24nvWK0kJjBuksnh5cFk4UNo0QGWO55YX4LY 2uhm1qR5ISoLi8LTBVHhMfrwCnGOohLjWEsbjeCkLR3Hfd7Y3LhKAS8PRFaERJICd9f9 QMAdV1ARDFcCME9HRBIjFdNg223XjLX2DKIeus++yUY2kJLV2yMd5ELjyXD4d+/I/dGw FG7i4mYTaon8qyiRwZHTbVIRL7UWVJxc/sd/bbKjsaMAEL7zVSG4dtwGdMENpf2gVd+f RSVQ== X-Gm-Message-State: AOAM533kCqcVxHvzXzoBlfdb2Cx9SZfo9R7yv11hD7KmhAa2Acz+kHjC tkzloW9smBDZeeQTYV4UuUT9DB+LXKJHmgIRauwdZ1ovODyIMUp55da6Yy+TANKEv0JJ2U9ACuR Uu8phJO8WippmVfwrL9rO9ZGr X-Received: by 2002:a0c:fa4f:: with SMTP id k15mr2997620qvo.62.1606923914282; Wed, 02 Dec 2020 07:45:14 -0800 (PST) X-Received: by 2002:a0c:fa4f:: with SMTP id k15mr2997597qvo.62.1606923914031; Wed, 02 Dec 2020 07:45:14 -0800 (PST) Received: from xz-x1 ([142.126.94.187]) by smtp.gmail.com with ESMTPSA id j17sm1975151qtn.2.2020.12.02.07.45.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2020 07:45:13 -0800 (PST) Date: Wed, 2 Dec 2020 10:45:11 -0500 From: Peter Xu To: Stefan Hajnoczi Cc: Justin He , Alex Williamson , Cornelia Huck , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] vfio iommu type1: Bypass the vma permission check in vfio_pin_pages_remote() Message-ID: <20201202154511.GI3277@xz-x1> References: <20201119142737.17574-1-justin.he@arm.com> <20201124181228.GA276043@xz-x1> <20201125155711.GA6489@xz-x1> <20201202143356.GK655829@stefanha-x1.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20201202143356.GK655829@stefanha-x1.localdomain> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Stefan, On Wed, Dec 02, 2020 at 02:33:56PM +0000, Stefan Hajnoczi wrote: > On Wed, Nov 25, 2020 at 10:57:11AM -0500, Peter Xu wrote: > > On Wed, Nov 25, 2020 at 01:05:25AM +0000, Justin He wrote: > > > > I'd appreciate if you could explain why vfio needs to dma map some > > > > PROT_NONE > > > > > > Virtiofs will map a PROT_NONE cache window region firstly, then remap the sub > > > region of that cache window with read or write permission. I guess this might > > > be an security concern. Just CC virtiofs expert Stefan to answer it more accurately. > > > > Yep. Since my previous sentence was cut off, I'll rephrase: I was thinking > > whether qemu can do vfio maps only until it remaps the PROT_NONE regions into > > PROT_READ|PROT_WRITE ones, rather than trying to map dma pages upon PROT_NONE. > > Userspace processes sometimes use PROT_NONE to reserve virtual address > space. That way future mmap(NULL, ...) calls will not accidentally > allocate an address from the reserved range. > > virtio-fs needs to do this because the DAX window mappings change at > runtime. Initially the entire DAX window is just reserved using > PROT_NONE. When it's time to mmap a portion of a file into the DAX > window an mmap(fixed_addr, ...) call will be made. Yes I can understand the rational on why the region is reserved. However IMHO the real question is why such reservation behavior should affect qemu memory layout, and even further to VFIO mappings. Note that PROT_NONE should likely mean that there's no backing page at all in this case. Since vfio will pin all the pages before mapping the DMAs, it also means that it's at least inefficient, because when we try to map all the PROT_NONE pages we'll try to fault in every single page of it, even if they may not ever be used. So I still think this patch is not doing the right thing. Instead we should somehow teach qemu that the virtiofs memory region should only be the size of enabled regions (with PROT_READ|PROT_WRITE), rather than the whole reserved PROT_NONE region. Thanks, -- Peter Xu