Message ID | TYCP286MB232339970F7009B962E2F1BECA029@TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1665569wru; Sun, 13 Nov 2022 04:49:11 -0800 (PST) X-Google-Smtp-Source: AA0mqf5IKu5WFNyDfSFKD2fmnejV4oYB72sU0QSMgLw/yfxLFNb6FVd7U+ibop1Fcb/aRqxLodHk X-Received: by 2002:a17:906:7e4e:b0:7a8:3ecb:bd62 with SMTP id z14-20020a1709067e4e00b007a83ecbbd62mr7592869ejr.721.1668343751143; Sun, 13 Nov 2022 04:49:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668343751; cv=pass; d=google.com; s=arc-20160816; b=VaVBBn75HHLfZ1aWtbOiY7yW31qF/25LtTxOrgoGYNrEnq2n8vxIri6gclqr7hQNNC y4AEyqf+wZMvWvkimd0fmPuyEOi4EVerWAw/+EhTXzxM4PXoEbJob2m+Czbgg1AdP/2U qdAN4iHkLraE5XKqY6d/ZdFHNmSB//tNo68SlgIVWapUTPBUZHShHvfxIncFIkpMwZ4Y TgnIA65qyqc/qcGU06fynL5Kc51VIvz3A+DL4farqHJsmZtpRTkdFcADD7S5oJ1tBlqx 3fClIr+9L5vm/t9OXaV9eDASVi7CGwX5kCSDRAUcYXmZnZiyOxyYG60+C7UWN1c5lKMC Wsxw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=orgT42Omv8iP6Yl7CUg/UjNucnJq3jfST9+LgqExNQM=; b=IU2Je4V583++sObPScG9yxLjF+HAaXsKM6ZqCG0jWnu3+KfhFdDESfjQkscYvo4rM7 MDOklbPvzDblLDuBIaJuFE4wy1lqGpCMGTQA5DpBaLPdR2KRoxddxTArwODG7W+wwxnp yZwIe+psPH/R71t49+m+/w6n1FMs6QqTyl+el+EsnPYUikayD2ycV7s8NMbv0gXLGOIY KGJUBguKbqOMMxhxgOKt7L9Tq8QSjA6KLG5M5Vq4+XcZ5ElPkDet1yJ7FTOYyKHtLJOM rJmwtKFoO35j5NhDb0yRGgqzUCKy2AaqouDFSplRYmit8IsXwi56d7wPvVNkvnJRXQ+a jTBw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=Tz49o2MF; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sa6-20020a1709076d0600b007418e87eea8si7386329ejc.770.2022.11.13.04.48.47; Sun, 13 Nov 2022 04:49:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@outlook.com header.s=selector1 header.b=Tz49o2MF; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233401AbiKMMme (ORCPT <rfc822;winker.wchi@gmail.com> + 99 others); Sun, 13 Nov 2022 07:42:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231252AbiKMMmc (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 13 Nov 2022 07:42:32 -0500 Received: from JPN01-OS0-obe.outbound.protection.outlook.com (mail-os0jpn01olkn2109.outbound.protection.outlook.com [40.92.98.109]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FC181115D for <linux-kernel@vger.kernel.org>; Sun, 13 Nov 2022 04:42:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=i8pNtE+RnJH1CDj0KniH2VjJ3xYhEl0OPXyPgOHoIKHnrnlczlJnE9ia8377Ayi/rzXqgt3DL/ZR8fkJniUjOlk8/4HaoTsWT6S8Cr5hvECK4nCA/8G7J+fhi0yykUUFJpktTW8Un0/m5ibKNC2nx+vlBoDyfedkLWyABuVSkLJDQ9NNDSvhcqxt+VIozpTMkNMY+foTac2HFtUed3TDF05+aRiVrSGFNTdkCifDlrHejeTiKycIlHKtTB9R5e6P5jK3y6zWh6hnJ5FsIsH428oo6rKguETsb0sVoxUhmEp/G291hxI15Bmq4VIwp7EKi3I21nLETnfgYo42CtzCkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=orgT42Omv8iP6Yl7CUg/UjNucnJq3jfST9+LgqExNQM=; b=YNG7NjU9Fq7FAWBSGFVN3Hk0JFB4rzgT5yX+jLfg/tPZqwSRoHRtvRENoSiH2XVpl7FiWEFfoDWpJCd1X9sWRF4n1Sf9s5WhCDxOrJASTBHsrhaqRlzaGiwvLo7FiJ1JQZ07/anDSfFBkmiAvGZMq19BuaciiY9WVLMCqKLbhVAJuTHlUCYJJQ7C3XmfwD5RDG1LUxP8WkPFBliBGzpmrWG/ZYf3ADZK11oV4bLvkJoiER/xIwHTQR9Een5lTRa6Y3h9J+w1uPJFO8pqH0ompmvM6pmqHV1VnMrG+Ji9/2wa+OnwAfFJxyyMeJazxaqQhrmXWhpcUzScvbfEVxcdbQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=orgT42Omv8iP6Yl7CUg/UjNucnJq3jfST9+LgqExNQM=; b=Tz49o2MF2b33FdquYkaHPOgqC099U9MdzjC3qSuAoFNmzTRHbAgRlyrsRbmZA8rAVQGoPCJ5OKO1Uc1TQZTF0edm8wNz28pzimSYllCcSqEcYP9mFzJs0ov6GCXD6NBUj3EtfWpFeB/v6IKhT/U38I+YfVn3Xdi3uzWIrLQG1qXWRUafFxhYxQ+wKwWz3jGvdJKpCQ4mQeI5VaUwXzjii7tio4wrUfh0X6ao79/fTss2XUyAR5aNz4w+k7pJGCQKfIsVz3/NV0O6ZX3WhvXvr7kCBqaS3QPMH7q+0JUt87ke1iZOkbwKK/QGtEmgc9Scnu3OZyWCpuu25s9rL4tipA== Received: from TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:152::9) by OSZP286MB1558.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1b3::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.17; Sun, 13 Nov 2022 12:42:28 +0000 Received: from TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM ([fe80::ff96:9cb6:e047:c605]) by TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM ([fe80::ff96:9cb6:e047:c605%4]) with mapi id 15.20.5813.017; Sun, 13 Nov 2022 12:42:28 +0000 From: Dawei Li <set_pte_at@outlook.com> To: alexander.deucher@amd.com, christian.koenig@amd.com, Xinhui.Pan@amd.com Cc: airlied@gmail.com, daniel@ffwll.ch, jglisse@redhat.com, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Dawei Li <set_pte_at@outlook.com> Subject: [PATCH] drm/radeon: fix potential racing issue due to mmap_lock Date: Sun, 13 Nov 2022 20:42:15 +0800 Message-ID: <TYCP286MB232339970F7009B962E2F1BECA029@TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM> X-Mailer: git-send-email 2.25.1 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-TMN: [0+5NliQOW+jHJS3TfmEQZoi9idqBjqK2] X-ClientProxiedBy: SG2PR06CA0229.apcprd06.prod.outlook.com (2603:1096:4:ac::13) To TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:152::9) X-Microsoft-Original-Message-ID: <20221113124215.2723318-1-set_pte_at@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYCP286MB2323:EE_|OSZP286MB1558:EE_ X-MS-Office365-Filtering-Correlation-Id: d18a857b-f5f9-47df-e3d5-08dac57485ed X-MS-Exchange-SLBlob-MailProps: fNPDeqDZc0LhcnwXkCC2ybqWGJ5u/EXML2J5Ddo+QJ5u30gFk+ZKLYkdSu0tTCFt800dTSLcaHk4WFJbwHSYwehJ3096e0EX8MJIcIERgHFXHnYY3YvEkSAFJIvrSi3ZRpAejPSZd0wfoEPFScYbnWpudgW3hf6D3AwD6NJ8Qob2HV89I77mEZbH5oHbgfVXge5bmxyZPGRX4T35jKXG6hF3BMRKk1FAAts/lnn5tiPoIcihVg6sgVLUfihn6H5B+HU04OnCsm3qaUKi4SWSMWIKQp4g/nzlhorKCoGfHcmV/5wp6KM0wHAUWHpA+G+HI1E8fngzyGS+xZszchR5hm+tOJCT+dNduvAGk66z3yhECengGTkxqkSTz9//Jo6//rKEJOZcUx5RlxF0BOYD7aNQI5ZrBXUFaWjkpHCOVpY2FzyKuKd/UuLuhQXK4nlmSnpTi3fjP5nMTHxpDdnUankNJEYnVoa+4gkOR79bXHV1aHsHtw1v+kECZqaR3Rpk8aI4bAH/+diwMDubooQVEs3zfCBMedM6HozXcQZDO9WwFCCX6tqDxPLeaRFs1B7To6m0EbgtHwcPgXyZ4qLNl2UufXmp78UZXyChOoct/xDu6NCJ9MWpt8DvElnl4rdRC+1/CbfdT7id7/BsuHlrEwDkBvRDrz7IkE/z32jLNBw8xOOLG+ysLwDK8KgiENkIB8rZOf4LK3V6ErcbAvgE1Ly1xtd+AsoG79K6PAUmK7w++DJgzqJKs2Ysod8HTtjUv9jK7QnXEOM5odAetIIeXg== X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0/I8NVe4zX4XdR2qmsgQAucQngA9KUWcN4A/KohD1EdIB+Og3krFZYbYBZZTqMwhia2fjBmSlFJAeuz6awbqt92Zw/641J+3KLQ185LDPdKIjQscE0XkW6NJ/AxNZHYjrlOhxcah0L70elBVhaQEoRGT4RGyZuvfL/oE6AEXxTntnStvgNRJJVxufLr8z7azp92JIa9vdBInWJdC/e3aooUSl7iAuCzkXmD54MmDf+jIj31rao5GL/aC3wCyuHTInvHHKXSTfWOl/1+isx5ch/mLCxNiXy98pPKQ5hKOhthS0sVIA5bJyAiiEahL2u0q1etVZjjR2hT4f5XoRLrNydADsmaLRAzJdQwGsYcOETFG0DrehlQkzhdbHCgRTEGF57L9vOlWKELyhchAH2CVpmPXZcrWuLcGr4H9u71dte+5NA7k3MqqWPwQDcD3tJ4RXlmvVgU2X4iEHCPL0JtVbM1T7c/nRWGKe8SKAciWx/Buugbyf2CZ6S0YrICVGiZBmgaSgYK5qxoIS/4oXRAy/T338NhxVnidJH7jnGwKPqinNBFNsayqqED/Z3DpCazEErFPgL/UOjnYiskEKW4wV27nfxJl1nYPf1fvksDKNM5adTeBhe9P+yC2cAL3hosg8NUWlyUbXjE4oGxmm485Ftp/uyG5s0hD2+hrT2ZuaIYRnf8h2fSzNjx3tZ2ftuLD X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 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kFVRFIwpAqK+tLN9PUvIHR6Og3P3m4C/1L7UzbjNSXQCSaviQqV5r9RZKahx2mdXV1mlABJky8GtnnsxoZ1bHuSng6l3U3AfI7qSELLIxQL1l73j49ZefYWWmySrinFIUKgo3Au9dLYw0a/qqIg+//fRfeKBDJB1j/zFzJjomebt3x4prX0SbwohrF32zuErD0bNJC95f4VmDYFqYnbapjk5W0mW5OGA0H4LSdWZ3SsQ7MHpWoKQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: d18a857b-f5f9-47df-e3d5-08dac57485ed X-MS-Exchange-CrossTenant-AuthSource: TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Nov 2022 12:42:28.2384 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: OSZP286MB1558 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749385216896435789?= X-GMAIL-MSGID: =?utf-8?q?1749385216896435789?= |
Series |
drm/radeon: fix potential racing issue due to mmap_lock
|
|
Commit Message
Dawei Li
Nov. 13, 2022, 12:42 p.m. UTC
Both find_vma() and get_user_pages() need explicit protection of
mmap lock, fix them by mmap_lock and get_user_pages_fast().
Fixes: ddd00e33e17a ("drm/radeon: add userptr flag to limit it to anonymous memory v2")
Fixes: f72a113a71ab ("drm/radeon: add userptr support v8")
Signed-off-by: Dawei Li <set_pte_at@outlook.com>
---
drivers/gpu/drm/radeon/radeon_ttm.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
Comments
Am 13.11.22 um 13:42 schrieb Dawei Li: > Both find_vma() and get_user_pages() need explicit protection of > mmap lock, fix them by mmap_lock and get_user_pages_fast(). NAK, the MM read lock should already be taken when we reach this function. Could be that this is buggy and the function is called without holding the lock, but trying to grab it while holding the reservation lock is also forbidden. Christian. > > Fixes: ddd00e33e17a ("drm/radeon: add userptr flag to limit it to anonymous memory v2") > Fixes: f72a113a71ab ("drm/radeon: add userptr support v8") > Signed-off-by: Dawei Li <set_pte_at@outlook.com> > --- > drivers/gpu/drm/radeon/radeon_ttm.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c > index d33fec488713..741ea64b9402 100644 > --- a/drivers/gpu/drm/radeon/radeon_ttm.c > +++ b/drivers/gpu/drm/radeon/radeon_ttm.c > @@ -351,7 +351,10 @@ static int radeon_ttm_tt_pin_userptr(struct ttm_device *bdev, struct ttm_tt *ttm > to prevent problems with writeback */ > unsigned long end = gtt->userptr + (u64)ttm->num_pages * PAGE_SIZE; > struct vm_area_struct *vma; > + > + mmap_read_lock(gtt->usermm); > vma = find_vma(gtt->usermm, gtt->userptr); > + mmap_read_unlock(gtt->usermm); > if (!vma || vma->vm_file || vma->vm_end < end) > return -EPERM; > } > @@ -361,8 +364,7 @@ static int radeon_ttm_tt_pin_userptr(struct ttm_device *bdev, struct ttm_tt *ttm > uint64_t userptr = gtt->userptr + pinned * PAGE_SIZE; > struct page **pages = ttm->pages + pinned; > > - r = get_user_pages(userptr, num_pages, write ? FOLL_WRITE : 0, > - pages, NULL); > + r = get_user_pages_fast(userptr, num_pages, write ? FOLL_WRITE : 0, pages); > if (r < 0) > goto release_pages; >
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c index d33fec488713..741ea64b9402 100644 --- a/drivers/gpu/drm/radeon/radeon_ttm.c +++ b/drivers/gpu/drm/radeon/radeon_ttm.c @@ -351,7 +351,10 @@ static int radeon_ttm_tt_pin_userptr(struct ttm_device *bdev, struct ttm_tt *ttm to prevent problems with writeback */ unsigned long end = gtt->userptr + (u64)ttm->num_pages * PAGE_SIZE; struct vm_area_struct *vma; + + mmap_read_lock(gtt->usermm); vma = find_vma(gtt->usermm, gtt->userptr); + mmap_read_unlock(gtt->usermm); if (!vma || vma->vm_file || vma->vm_end < end) return -EPERM; } @@ -361,8 +364,7 @@ static int radeon_ttm_tt_pin_userptr(struct ttm_device *bdev, struct ttm_tt *ttm uint64_t userptr = gtt->userptr + pinned * PAGE_SIZE; struct page **pages = ttm->pages + pinned; - r = get_user_pages(userptr, num_pages, write ? FOLL_WRITE : 0, - pages, NULL); + r = get_user_pages_fast(userptr, num_pages, write ? FOLL_WRITE : 0, pages); if (r < 0) goto release_pages;