From patchwork Fri Oct 23 12:21: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: 11853375 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 51E44C388F9 for ; Fri, 23 Oct 2020 12:40:30 +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 D5538208C3 for ; Fri, 23 Oct 2020 12:40:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Ns8dK05P"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="jwFffuS4"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="URbjYqZv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D5538208C3 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=V0aCcc/azKjz7y7l2dLJ4MvKTTJMOoeOHtqclU+gOGY=; b=Ns8dK05PespznLQZpQu9PnKI4 nkx9yfUEHYm86pOJBQkQe7WqlAoMCHc8kJ5XttX3lyxP7oqQkclNh6fuFZUhQbrgHVuJEgrkXAqSD dYD0OR4Q0n89g7m5prVRf0ZyZtjg0KIT/uCInfouqAoiPM3oKTZtVmd5AcPq48MaeuiobggEf0Xyy Ob1V5o7eUlyoTLd/uWDBJsFMrUo5ihb52BhxzteMtOqhuiz3geRBwcbn95WoEy1mb+UiugYTQQMEO 2m1OWPG1ZhCS6zXl3m0BeqgXNtcvNwVWSkiMOcJ/Er20JMIpQzswzAkDKTDZWot/vI7jHuAfflrEI mhecI49rQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kVwLO-0004iP-Nk; Fri, 23 Oct 2020 12:38:54 +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 1kVwLI-0004fb-IS for linux-arm-kernel@merlin.infradead.org; Fri, 23 Oct 2020 12:38:48 +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=hp7lChw6Uow+58XPniSHemIeAoNErbB/sdK6im80Iug=; b=jwFffuS41zuG2mfQr18xd/X/KQ SwNPjzP3XLGrQntPgmOejdkGdDN6eNBdLTDbNFwjAqjOpBtlSdd5C/1OX0a3P6MWACJKLB4bVRmyq BLPtBwF3vzKB6Diy0LLZS/pLM1xsB1TRWDUg7d4r0hNgk+5jGlLS8axWXcW4QcLcBj48nBDGljFFv o8AzBegnyfAxSUCsZp1mhPsbiEba7Z+8Tz8X+lppsUxlHhsVRuEnNrmNh4aO5JK9EL8E9FS22rJ9L GNIdSINx9qALxqNeV3jeflhSyu1nsrrfIQ8FHN739xJpH9cUTp+h8UooXxuQFImGDqiTIgQun+sMk X+PXC+0Q==; Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kVw6B-0001PT-Ii for linux-arm-kernel@lists.infradead.org; Fri, 23 Oct 2020 12:23:19 +0000 Received: by mail-wm1-x344.google.com with SMTP id e2so1305493wme.1 for ; Fri, 23 Oct 2020 05:23:09 -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=hp7lChw6Uow+58XPniSHemIeAoNErbB/sdK6im80Iug=; b=URbjYqZvij6vMp6zpIk/3WlniapSCelkh8qPhM9XSJmSi3JP0Pkq6JfYZq+gC0V2Ja Jq8vCQ4Ho/GAm6SQXrzJhiajzuA2XAwJXKB1Cll6tMyrVwJYz4NCmG2PdfE0KkUS7bh0 l5/AnqPDLrJU4JyaIv3jCsFac60g5JtxDcFVQ= 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=hp7lChw6Uow+58XPniSHemIeAoNErbB/sdK6im80Iug=; b=aCuYYfuumpfnEiSzOmy8jFI9ebn8yQoU+cKhG+jDrL6GIKqBe9rsmOqZoTzrSuCqQB ZvFEQaCNXAgbMcNcX8dD5AYZYpOdEjUBeV7LqIxukXHjlvx2XmKS1vfbNZyVPMwMPQsU hzybLXYyaTvgFXX0JxdOfhB0Z/fL1nwx67QvAWmQVhw5iKKNOjpuJNOGG74AkWWxMCKe I7tLnZtZ7MHIKmj5hA0RuLyWqNuVDC4srs2MKkPq91cVsQsUPTsfPASEYmervasEUMNF gRq6hxMfNrb5pFi1wEew+hY7xCpiLieQu5HIoqrW3zYHzxt2elJNFWCy+kam7vtC5d0L zK0g== X-Gm-Message-State: AOAM530q3cJQKi0cULT+D0qv7wwVZfdvjbY27cXCcAIdLpNYiW2yiepA mKkeYRaJVCjeAelg701RtGYiLQ== X-Google-Smtp-Source: ABdhPJwqZWBmXRQ8vY8ZKJrjdPXGP2WILf15a1TrVl8Pgis8iT7Odd2hX51Nk7fKP5ClvyukHiQ2vg== X-Received: by 2002:a1c:4d05:: with SMTP id o5mr1994877wmh.94.1603455788583; Fri, 23 Oct 2020 05:23:08 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id y4sm3056484wrp.74.2020.10.23.05.23.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Oct 2020 05:23:08 -0700 (PDT) From: Daniel Vetter To: DRI Development Subject: [PATCH 39/65] vfio/type1: Mark follow_pfn as unsafe Date: Fri, 23 Oct 2020 14:21:50 +0200 Message-Id: <20201023122216.2373294-39-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201023122216.2373294-1-daniel.vetter@ffwll.ch> References: <20201021163242.1458885-1-daniel.vetter@ffwll.ch> <20201023122216.2373294-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-20201023_132312_122120_AF524234 X-CRM114-Status: GOOD ( 18.27 ) 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: linux-samsung-soc@vger.kernel.org, Jan Kara , Kees Cook , kvm@vger.kernel.org, linux-mm@kvack.org, Daniel Vetter , Intel Graphics Development , Cornelia Huck , Alex Williamson , Jason Gunthorpe , =?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;