From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33A8BC4363C for ; Wed, 7 Oct 2020 18:14:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 644542173E for ; Wed, 7 Oct 2020 18:14:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="lyjVFBq/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 644542173E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D64B26B006C; Wed, 7 Oct 2020 14:14:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D157A6B006E; Wed, 7 Oct 2020 14:14:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BDCF56B0071; Wed, 7 Oct 2020 14:14:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0027.hostedemail.com [216.40.44.27]) by kanga.kvack.org (Postfix) with ESMTP id 8E38E6B006E for ; Wed, 7 Oct 2020 14:14:18 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 2BF251EE6 for ; Wed, 7 Oct 2020 18:14:18 +0000 (UTC) X-FDA: 77345928996.04.touch91_280feaf271d1 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin04.hostedemail.com (Postfix) with ESMTP id 0F94F800ABAD for ; Wed, 7 Oct 2020 18:14:18 +0000 (UTC) X-HE-Tag: touch91_280feaf271d1 X-Filterd-Recvd-Size: 6081 Received: from mail-oo1-f67.google.com (mail-oo1-f67.google.com [209.85.161.67]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Wed, 7 Oct 2020 18:14:17 +0000 (UTC) Received: by mail-oo1-f67.google.com with SMTP id y127so852365ooa.5 for ; Wed, 07 Oct 2020 11:14:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=cQRYAtP+xjx5WuekS6OE0CV7kqmxj7BYflzO3gWdvvE=; b=lyjVFBq/8C4cx1xV9ChTXnV40ihqdqpwLDP0hKiWG7wMCAY1kcUxadTiFEkVrngi/w V9y6TiR2NUPQYfn7qatcnS2KH2rC4iURG1Imt+VcjCPG3gMt13p5HinunxSiaAfYb6mn oHrygbKnexw8amjrZlMfKtPR5lb/S9ssQU4cU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=cQRYAtP+xjx5WuekS6OE0CV7kqmxj7BYflzO3gWdvvE=; b=EbcmdNudkrao+eluDQXQbC0c4myWJ1hGkZ4qAFcNZ6F7wdTnAGoYccvsklErSS6cOP x0aZ06tNt1+x2iLOVB0N1dP1016QO17bGfpI/N1Zfb3kWZmWGvOIib1mjAEMfUpkoNU3 L45tpfqU0yH15qJzSZJ6r7eLz4Q2hohGBPPsG6ikdTu2+j5OGsEg7Cu2qv/q3vqtOfVq bdNL5UAVsJ55/+4cOUTUVGMofWBKexEEeGk/loDiNs6ntsNE8ZfavOkkBF3XSVr3iGcu 5F2yU2WZRZeNs9f4W0OvTCsyCw9PYREedFrGLScT5tqDmsOR5QJn5K9L0bktqvgpU7uX cvog== X-Gm-Message-State: AOAM533flUG6kRjd3O8EvpixokzOoM31OmfjRfhSLWs8nR28KQ2gn+/X ueisvm7zDiFg9Q7QyTSi5jMVbP/n9LoNVKdSz762r5UXGZDyow== X-Google-Smtp-Source: ABdhPJzjOjAMzRbSVSt+lqfvvsdq1EBjj80477iZlPA7zPuN7ej1AyuyFSKWwEDM91Ycyft1zzLM1yCXh0Q5piW4a7o= X-Received: by 2002:a4a:e592:: with SMTP id o18mr2831112oov.28.1602094456975; Wed, 07 Oct 2020 11:14:16 -0700 (PDT) MIME-Version: 1.0 References: <20201007164426.1812530-1-daniel.vetter@ffwll.ch> <20201007164426.1812530-14-daniel.vetter@ffwll.ch> <20201007173911.GX5177@ziepe.ca> In-Reply-To: <20201007173911.GX5177@ziepe.ca> From: Daniel Vetter Date: Wed, 7 Oct 2020 20:14:06 +0200 Message-ID: Subject: Re: [PATCH 13/13] vfio/type1: Mark follow_pfn as unsafe To: Jason Gunthorpe Cc: DRI Development , LKML , kvm@vger.kernel.org, Linux MM , Linux ARM , linux-samsung-soc , "open list:DMA BUFFER SHARING FRAMEWORK" , linux-s390@vger.kernel.org, Daniel Vetter , Kees Cook , Dan Williams , Andrew Morton , John Hubbard , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , Jan Kara , Alex Williamson , Cornelia Huck Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Oct 7, 2020 at 7:39 PM Jason Gunthorpe wrote: > > On Wed, Oct 07, 2020 at 06:44:26PM +0200, Daniel Vetter wrote: > > The code seems to stuff these pfns into iommu pts (or something like > > that, I didn't follow), but there's no mmu_notifier to ensure that > > access is synchronized with pte updates. > > > > Hence mark these as unsafe. This means that with > > CONFIG_STRICT_FOLLOW_PFN, these will be rejected. > > > > Real fix is to wire up an mmu_notifier ... somehow. Probably means any > > invalidate is a fatal fault for this vfio device, but then this > > shouldn't ever happen if userspace is reasonable. > > > > Signed-off-by: Daniel Vetter > > Cc: Jason Gunthorpe > > Cc: Kees Cook > > Cc: Dan Williams > > Cc: Andrew Morton > > Cc: John Hubbard > > Cc: J=C3=A9r=C3=B4me Glisse > > Cc: Jan Kara > > Cc: Dan Williams > > Cc: linux-mm@kvack.org > > Cc: linux-arm-kernel@lists.infradead.org > > Cc: linux-samsung-soc@vger.kernel.org > > Cc: linux-media@vger.kernel.org > > Cc: Alex Williamson > > Cc: Cornelia Huck > > Cc: kvm@vger.kernel.org > > --- > > drivers/vfio/vfio_iommu_type1.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_= type1.c > > index 5fbf0c1f7433..a4d53f3d0a35 100644 > > --- a/drivers/vfio/vfio_iommu_type1.c > > +++ b/drivers/vfio/vfio_iommu_type1.c > > @@ -421,7 +421,7 @@ static int follow_fault_pfn(struct vm_area_struct *= vma, struct mm_struct *mm, > > { > > int ret; > > > > - ret =3D follow_pfn(vma, vaddr, pfn); > > + ret =3D unsafe_follow_pfn(vma, vaddr, pfn); > > if (ret) { > > bool unlocked =3D false; > > > > @@ -435,7 +435,7 @@ static int follow_fault_pfn(struct vm_area_struct *= vma, struct mm_struct *mm, > > if (ret) > > return ret; > > > > - ret =3D follow_pfn(vma, vaddr, pfn); > > + ret =3D unsafe_follow_pfn(vma, vaddr, pfn); > > } > > This is actually being commonly used, so it needs fixing. > > When I talked to Alex about this last we had worked out a patch series > that adds a test on vm_ops that the vma came from vfio in the first > place. The VMA's created by VFIO are 'safe' as the PTEs are never changed= . Hm, but wouldn't need that the semi-nasty vma_open trick to make sure that vma doesn't untimely disappear? Or is the idea to look up the underlying vfio object, and refcount that directly? -Daniel --=20 Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch