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=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 D7010C64E90 for ; Wed, 21 Oct 2020 08:57:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5B023223C6 for ; Wed, 21 Oct 2020 08:57:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="Ijq3ip5+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5B023223C6 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 2D3C16B0078; Wed, 21 Oct 2020 04:57:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2AB696B007B; Wed, 21 Oct 2020 04:57:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1298B6B007D; Wed, 21 Oct 2020 04:57:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0233.hostedemail.com [216.40.44.233]) by kanga.kvack.org (Postfix) with ESMTP id C99846B0078 for ; Wed, 21 Oct 2020 04:57:20 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 639D6181AC9CC for ; Wed, 21 Oct 2020 08:57:20 +0000 (UTC) X-FDA: 77395328640.22.cord91_0603d8e27247 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 24A9818038E60 for ; Wed, 21 Oct 2020 08:57:20 +0000 (UTC) X-HE-Tag: cord91_0603d8e27247 X-Filterd-Recvd-Size: 5372 Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by imf22.hostedemail.com (Postfix) with ESMTP for ; Wed, 21 Oct 2020 08:57:19 +0000 (UTC) Received: by mail-wm1-f66.google.com with SMTP id b127so897130wmb.3 for ; Wed, 21 Oct 2020 01:57:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8pur25W5Shkh1hHfFCpksS7ceNn2PKF9z82vTsiLN4c=; b=Ijq3ip5+wV7cd7njUb6RsVnXV8g8Owp5iMrdu9TyvAk5qDDhPeT5XCXN2ALGJhsrbp P5zOBKKXwRlNfH4L8OnR7mPoL971Mg4a7xN8q3N/PXmFtuMp/lDcW0snMDX7TnNSFxlk g5M5E6R5TEskXfmkH4sQcqsHcoV8Z7W9kahWs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8pur25W5Shkh1hHfFCpksS7ceNn2PKF9z82vTsiLN4c=; b=Ad/j60YVDMxHqQ+H6VvM9SB186fiBwgPJUFcUFy406QFCBjSBBAOqu6zgfWuX81c8e VFCBl6h9/qJLpOaf5bJNhdpyJ9hFQ7hFJTc1DbFj8xg3UZEjTcpqviso7cn2VgfOh0Id RvLYsVT8Ns4+1x7oBnxrusYfee9mMENUU5WzUHrckgXz5PB57Zo8Js4yL0jYpj2dJcvC zP0LfLFm8Gz/a7K8iRyFBUsnqo4b5MVsgL4VWdcR31HJfwacWgivLhxMAGRg9TenQfHc q37crpMMpPAlcI/CC2wHD0XUpul9X41sIADn3VAlhqm26Nu4o6T/Bt26ZsxiALo+LJ9T dwxQ== X-Gm-Message-State: AOAM530WDPo5MiWnduSrDLM2JISauzC8EmuzxnrdICutpKXcGBn7NRbI cvy5ty1r7CTYrLo6IYBYW/YUwQ== X-Google-Smtp-Source: ABdhPJzNaFnr3EWeDP7k0cF2AHbtycSZcq0l7yhT5Nq82x3yeqTKgKPKUR9qmyptj9g+y8CFHwWMGg== X-Received: by 2002:a1c:2c02:: with SMTP id s2mr2512532wms.66.1603270638556; Wed, 21 Oct 2020 01:57:18 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id q8sm2675939wro.32.2020.10.21.01.57.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 01:57:17 -0700 (PDT) From: Daniel Vetter To: DRI Development , LKML Cc: kvm@vger.kernel.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-media@vger.kernel.org, linux-s390@vger.kernel.org, Daniel Vetter , Daniel Vetter , Jason Gunthorpe , Kees Cook , Dan Williams , Andrew Morton , John Hubbard , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , Jan Kara , Alex Williamson , Cornelia Huck , Daniel Vetter Subject: [PATCH v3 11/16] vfio/type1: Mark follow_pfn as unsafe Date: Wed, 21 Oct 2020 10:56:50 +0200 Message-Id: <20201021085655.1192025-12-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201021085655.1192025-1-daniel.vetter@ffwll.ch> References: <20201021085655.1192025-1-daniel.vetter@ffwll.ch> MIME-Version: 1.0 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: 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 Signed-off-by: Daniel Vetter --- 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_ty= pe1.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 *vm= a, struct mm_struct *mm, { int ret; =20 - ret =3D follow_pfn(vma, vaddr, pfn); + ret =3D unsafe_follow_pfn(vma, vaddr, pfn); if (ret) { bool unlocked =3D false; =20 @@ -435,7 +435,7 @@ static int follow_fault_pfn(struct vm_area_struct *vm= a, struct mm_struct *mm, if (ret) return ret; =20 - ret =3D follow_pfn(vma, vaddr, pfn); + ret =3D unsafe_follow_pfn(vma, vaddr, pfn); } =20 return ret; --=20 2.28.0