From patchwork Wed Oct 21 08:56:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 11848863 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.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable 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 B83D0C56201 for ; Wed, 21 Oct 2020 09:22:35 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2C31E20770 for ; Wed, 21 Oct 2020 09:22:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="x1HVZhNM"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="UdsEne1c"; 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 2C31E20770 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=yWsKKYvq4031LwLke8qWjtM2TKf3ja4EpLbJyqHX+cc=; b=x1HVZhNM2vrPC/xq6EWDKtCy+ 1RztrczMxZ9H+l67wBh/qC+lPk7TPXMWf3Zu5YbvZJ/16d+GaS9wfD/bzFv4Z++whwqPAIejFZBSP 96mp/YLeRrjJIu1pmrAJwejJ7fyC4YHPwO9fcKWuhKQeqXF6tLLGqqJIx1JpU2Jp4AoN/XY6Skyq1 4k1oNpHdQTDW8h4eXmIkob9ArA/F5ZFMcl7sASggIgQoIhAzIhNz3w80GqUhbPB+XzoLgAPjvBhDl DpJNKD8NvY8Lp6Y1rOaMNu/pqJqQCFlNB1H75EIAD/bVmJxovCUS/sOT4+XZh0K7VbjnWstAod6IJ bRxcYOLDA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kVAJ2-0006OG-3z; Wed, 21 Oct 2020 09:21:16 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kVAIt-0006Es-66 for linux-arm-kernel@merlin.infradead.org; Wed, 21 Oct 2020 09:21:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:Content-Type: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-ID:Content-Description; bh=8pur25W5Shkh1hHfFCpksS7ceNn2PKF9z82vTsiLN4c=; b=UdsEne1cf/OyMD1M+5x1dyapGd 0DW5AMGYur7kRRmtqp4DnBkVQGaXRVv9BOO1QfyJUT0zGu8A+lZmsuK6+AlQn1AwR4w5nRbAkWT8S 2Ojb+UqVJ0hcdF2EzQeYnkUv5IQWPi3okWlz8nyYao8TqZj1IZ0wqoF27HpIdgEyTak5xpZ/dhKjZ YyaNHgfdShCic7Wfu/SFBhcMgH4tPZXjn925o+0OvwzJ71+rwCAQMFEB1NTZxnt5Sos+mudWDKax+ psuObFQyRdN22rYEdbvr6qdmIr18NpAkKq8n5/3K4O7/sTTCtj27NDJNFrH0DjvGC7w5Lh6gR4gVU 1xfxWqPA==; Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kV9vu-00013U-Bb for linux-arm-kernel@lists.infradead.org; Wed, 21 Oct 2020 08:57:34 +0000 Received: by mail-wm1-x341.google.com with SMTP id c16so894817wmd.2 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=CdoOYIXOLUjEN10BjQBlnCyXsV4Kl7e8/V1Px4x++yRdVkbSSREtC6YxdJ0GyMvizk TXIVRlCt6EW5OeKJKLkU4Y5XsnTDfKOs5LesmBZv/BfdrfTg4NUsgjKElXcVPn/B+mfC 6Rbv+3n9kLsSP1SAoBv+4lvSRTgAlTgAWSNYdKDgCZyk4lxOentsm8jV9hdnplHpvrPy /LBz5vwUehdhwj85X7wqO3rUn0r2ro9paZ2uNc5BGu5URvBxp5UM1WSjppAjNv+51NNH 9+FCDvX4jtwjCwduRcuKMmQiKjO/OV3XDsm5kBN2mkPTxcnU+6MdjKdvbqJtSnp6gFkL Te8w== X-Gm-Message-State: AOAM530vcucOydpE1I98XNoAulSbpvOLqGtkiWu4P8tsxqN4UntnIM57 Mi0b6Gi63rRzvlmy7YvoojKP2g== 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201021_095724_313941_87F59579 X-CRM114-Status: GOOD ( 19.08 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Vetter , linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, Jan Kara , Kees Cook , kvm@vger.kernel.org, Jason Gunthorpe , Daniel Vetter , Cornelia Huck , Alex Williamson , linux-mm@kvack.org, =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , John Hubbard , Daniel Vetter , Dan Williams , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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érôme 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_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 = follow_pfn(vma, vaddr, pfn); + ret = unsafe_follow_pfn(vma, vaddr, pfn); if (ret) { bool unlocked = false; @@ -435,7 +435,7 @@ static int follow_fault_pfn(struct vm_area_struct *vma, struct mm_struct *mm, if (ret) return ret; - ret = follow_pfn(vma, vaddr, pfn); + ret = unsafe_follow_pfn(vma, vaddr, pfn); } return ret;