Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2428994imj; Mon, 18 Feb 2019 05:57:58 -0800 (PST) X-Google-Smtp-Source: AHgI3IYEdsm25P6QEbCEbbFRtfkWE9zr6M5eoJL8VMd6aIGcUWVU/cOIUQxs/kp79I+B7e1tt6LG X-Received: by 2002:a63:e752:: with SMTP id j18mr1416697pgk.313.1550498278435; Mon, 18 Feb 2019 05:57:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550498278; cv=none; d=google.com; s=arc-20160816; b=Jlhy6oumD8zxEoH1WstbA7csA4cC894weVNVPs6fHcH2NhK4D7t/VetFIwBtm/nKVY s95pT6N9nHrrItVL0PfA/eVwsMFkDEoevMwaSsDtdOti1N242Sk2B2vqwta7C2SkjnoY RejUN9usZjiS0tUgeD8eygSY0vW3sHttCqOi6zlmGVhLO9H5aNv0kc+KvmrNGNxVpxIu vu743ox85xp2ZC2sKV33g+Rlv3Ib74x1eKVKykvtH743cbgc1VmTgUowE7el/FipqSYL UcYfjiHER87wkZEmlmyUMtx9xDJytG5jbh6e2rQHeogq/qr/mEMmFd6QYxnKEVx453Rt IQYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Gkbtif+PzMnVPy4tRx4e5Qp4FtHROF635RhNjeH3sCg=; b=f3DVCt9auZvFfTdt/j0yB2auRcMsmWUSzo2qQviGE9G4Ku5+HzI4j3dXPrvbTZapQr 3+hbrGRX4BHlFhxnRgY/btuGLL4DqI77ugHgpdsBGKZb2GVhStzvSeODzYy1hjMWdZ48 XSYzFw+SF12R+namk3F8+3sguOdSqk7HfJk4fYorFPuhIsvN3C7aK8DtJWbvO5JyikGt wehV/XGXWmexvKFk8XVU916wSfzijwpfLoapSkZhlg5uFUetFb7qXJ0CDh/ZtcN+IOGt vsILQLK/Vdn1PkeH7FDc4lVqGnEMGc1s7+bDnA6//0VA6vldvpCTPn8CqZ52p9hXnYMF iKtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ObVKVyAJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y4si12532648pgv.520.2019.02.18.05.57.43; Mon, 18 Feb 2019 05:57:58 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ObVKVyAJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387918AbfBRN4x (ORCPT + 99 others); Mon, 18 Feb 2019 08:56:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:37176 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387912AbfBRN4v (ORCPT ); Mon, 18 Feb 2019 08:56:51 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4A3B2217D9; Mon, 18 Feb 2019 13:56:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550498210; bh=ntYefK9ARmAhYbTXMksCfI1UGCm12Snrj/FV6pd278k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ObVKVyAJvtOwhj4M4Q+3Z/6dOiJ/v29Y0u6k1V2AT7ZoZmFzJ+UAYwTL5WhGrhibF EPGagwTebCjBRKM+lEsvbwRtivTUxKJ8dA6qQ7uo7/hpM/ru6Qh2F5TkHfoH5/DBHc mom313LHbD+zJlAMzA5OgF2pN1KtqSrlRlASq4AE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Adam Zabrocki , Linus Torvalds , Joonas Lahtinen , Akash Goel , Chris Wilson , Tvrtko Ursulin , Jani Nikula , Tvrtko Ursulin Subject: [PATCH 4.14 59/62] drm/i915: Prevent a race during I915_GEM_MMAP ioctl with WC set Date: Mon, 18 Feb 2019 14:44:05 +0100 Message-Id: <20190218133510.823296615@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190218133505.801423074@linuxfoundation.org> References: <20190218133505.801423074@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Joonas Lahtinen commit 2e7bd10e05afb866b5fb13eda25095c35d7a27cc upstream. Make sure the underlying VMA in the process address space is the same as it was during vm_mmap to avoid applying WC to wrong VMA. A more long-term solution would be to have vm_mmap_locked variant in linux/mmap.h for when caller wants to hold mmap_sem for an extended duration. v2: - Refactor the compare function Fixes: 1816f9236303 ("drm/i915: Support creation of unbound wc user mappings for objects") Reported-by: Adam Zabrocki Suggested-by: Linus Torvalds Signed-off-by: Joonas Lahtinen Cc: # v4.0+ Cc: Akash Goel Cc: Chris Wilson Cc: Tvrtko Ursulin Cc: Adam Zabrocki Reviewed-by: Chris Wilson Reviewed-by: Tvrtko Ursulin #v1 Link: https://patchwork.freedesktop.org/patch/msgid/20190207085454.10598-1-joonas.lahtinen@linux.intel.com (cherry picked from commit 5c4604e757ba9b193b09768d75a7d2105a5b883f) Signed-off-by: Jani Nikula Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/i915/i915_gem.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -1633,6 +1633,16 @@ i915_gem_sw_finish_ioctl(struct drm_devi return 0; } +static inline bool +__vma_matches(struct vm_area_struct *vma, struct file *filp, + unsigned long addr, unsigned long size) +{ + if (vma->vm_file != filp) + return false; + + return vma->vm_start == addr && (vma->vm_end - vma->vm_start) == size; +} + /** * i915_gem_mmap_ioctl - Maps the contents of an object, returning the address * it is mapped to. @@ -1691,7 +1701,7 @@ i915_gem_mmap_ioctl(struct drm_device *d return -EINTR; } vma = find_vma(mm, addr); - if (vma) + if (vma && __vma_matches(vma, obj->base.filp, addr, args->size)) vma->vm_page_prot = pgprot_writecombine(vm_get_page_prot(vma->vm_flags)); else