Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2093387ybp; Thu, 10 Oct 2019 02:04:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqxKTZMVaClxWcYK8UPaFwsaYpYD9ypwbBsfmMboTpTm/EkQPix+dSKMVW1KEwvohn/kIUv8 X-Received: by 2002:a05:6402:8cf:: with SMTP id d15mr6819356edz.225.1570698269675; Thu, 10 Oct 2019 02:04:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570698269; cv=none; d=google.com; s=arc-20160816; b=SIEZ/45ThSqsQdxAOC1MdFPoQf1pTW6QxqtnyTOQXwvLOz2AsOXXzUrP3YeU797yNw hYrdVeU/ZSZhYAr4A5uQygBGtbnknNuANWZ6vmVe9Cny2Eea9qb7fdVL3sbFUsZUi4SF AeA+eNohaJiEx1+XaNfg0hZ1tHKiLKwHCCke3HUFgzql60GBG3v6luPBnG5BN5j9wgo4 mZ2ZVz769XGFs4ifSiJ0IyQ4HB2rA9aTdWIMWHx5a8ILmz9f+cZ2eg6Zom/sz51Xs1U1 EE/oEuQLLo06Vuwg3Jj4eFiqcZP9IpZeGg38qZorjz2mLQfyKgNnKCdIUSdnidW9PFed lTug== 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=n2g17+AdcmR+cdRzfcuW1L9Xp5dop/AifFot6d76rDI=; b=aW5far2+U232sdx2Vw9RLE7rK1XM8auvhhcAM76kn/uSkh8zCDMWQL4BPUYwZkqXtf QKlm4lzuDVbjU/sB2GAHNYWaM5yTvejbGoADrSoQv6VuE0+yXGX09vGFb0LP/utuZkVl J5ZeUAacp1rh+Hdc17S7qSj4PVvUph1xOLnfy8kLs6UyP/COY/KCa6+BLEYFFlgw24ox bEKhfqQr3A2SslJ2P2d2FlqkzipkNnoNp3EPkfcNQT+6SYPxosfHJSWfpFxd0D0deJj7 gPsF08IkTTrSfufYw2Y4FnS/5sPV0MaeSpsexUu08ySotMQrJc8WCr/Qy3Z43J1sgXsV LJJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xAMtAQ38; 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 i10si3636291ede.101.2019.10.10.02.04.06; Thu, 10 Oct 2019 02:04:29 -0700 (PDT) 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=xAMtAQ38; 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 S2388175AbfJJIkr (ORCPT + 99 others); Thu, 10 Oct 2019 04:40:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:44862 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388163AbfJJIko (ORCPT ); Thu, 10 Oct 2019 04:40:44 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 5EE072196E; Thu, 10 Oct 2019 08:40:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570696843; bh=n/e/vaObw3kyd5fTVUpqKkcLIwSibsqLEzhB8D8JkZ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xAMtAQ38DRE7S+bIT7cDqPdzG7LW8pbHbeBJx52Hy4upWweyRGxBF2T11s0TvL79l AI2gopr8q1D0aHYLdqh5vrZWcsWbNWQpOtbXFJUp4k4IJ/ypjtT3+hemIKpWwUngL+ GzXoBwggt11kWYZNHmshJaTAXsn0fRQog7AS7DSo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chris Wilson , Tvrtko Ursulin Subject: [PATCH 5.3 071/148] drm/i915/userptr: Acquire the page lock around set_page_dirty() Date: Thu, 10 Oct 2019 10:35:32 +0200 Message-Id: <20191010083615.708820027@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191010083609.660878383@linuxfoundation.org> References: <20191010083609.660878383@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Chris Wilson commit cb6d7c7dc7ff8cace666ddec66334117a6068ce2 upstream. set_page_dirty says: For pages with a mapping this should be done under the page lock for the benefit of asynchronous memory errors who prefer a consistent dirty state. This rule can be broken in some special cases, but should be better not to. Under those rules, it is only safe for us to use the plain set_page_dirty calls for shmemfs/anonymous memory. Userptr may be used with real mappings and so needs to use the locked version (set_page_dirty_lock). Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=203317 Fixes: 5cc9ed4b9a7a ("drm/i915: Introduce mapping of user pages into video memory (userptr) ioctl") Signed-off-by: Chris Wilson Cc: Tvrtko Ursulin Cc: stable@vger.kernel.org Reviewed-by: Tvrtko Ursulin Link: https://patchwork.freedesktop.org/patch/msgid/20190708140327.26825-1-chris@chris-wilson.co.uk Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/i915/gem/i915_gem_userptr.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) --- a/drivers/gpu/drm/i915/gem/i915_gem_userptr.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_userptr.c @@ -664,7 +664,15 @@ i915_gem_userptr_put_pages(struct drm_i9 for_each_sgt_page(page, sgt_iter, pages) { if (obj->mm.dirty) - set_page_dirty(page); + /* + * As this may not be anonymous memory (e.g. shmem) + * but exist on a real mapping, we have to lock + * the page in order to dirty it -- holding + * the page reference is not sufficient to + * prevent the inode from being truncated. + * Play safe and take the lock. + */ + set_page_dirty_lock(page); mark_page_accessed(page); put_page(page);