Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1145809imw; Tue, 5 Jul 2022 04:41:45 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vGCVFJeoe8iJsX7//n24Y0TJIQ1CEYcwLSvU74SwUlIcOIFTqUdIp8CH3Mven7NLFbM+7H X-Received: by 2002:a63:b105:0:b0:3fd:a875:d16 with SMTP id r5-20020a63b105000000b003fda8750d16mr29133842pgf.209.1657021305440; Tue, 05 Jul 2022 04:41:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657021305; cv=pass; d=google.com; s=arc-20160816; b=aOAbYrQ/AFpc9SgVFOYHx63/bnh1PDrjl81Nu5HrqyrfJBaLo1TapY1oojk8EuXx6b 2q2LQ+u/N9nwMOgB+eogXLkXBOUs9Xslez/AoTkg5epTGvW7KyPysDidPLRHjjIOwjW7 SSjy13y//JGW0OJSbdM+uixM9vbTs/pnoPMeejMaPQJw501jLm87mvwigNv5tA1USoNe uLorPLNTEo631F7TwvEIrp14raBc1bhvJSTG1RPaYNrKpNfDPppgcbv+uKSi29T1f+6G OA/0UScOPvlvb0FEBQT2iGRYcQ6iHeK2fVaFEcG277MpcAuWcuEC+WWZMK4bgpNyPHWF aAxg== 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 :in-reply-to:from:references:cc:to:content-language:subject :user-agent:date:message-id:dkim-signature; bh=DelXAiXGlRk2fvklJFbMtwD03U+BlcNKX6rBMkC+Bog=; b=w0600tqO5fV6o67bAteYVC1HJzur2IjTne5lRMF4RSVflCPUBjiZiCPVa39ZLUXhU4 BnwxMJ4EltwdIc2Jn09LCoo5U0BbTMmWqjBo59LUqqoWZGBbvfrJHXjDcjh+uchtZxIG KBtFuEPqNga/v+NolSZRmoONJ15BosUuKu+YvF1IejqG0AT9+4kqDYg1C3TkVFym4kJB YJWaVWpJO10oziyyAyaEK/hRY7RLu0aqy0/MjsEt7o0LvsPtmTiOgpke1V7V6D9x5hrN 03Lc2wGkddDNobgCdj03wsRpTIld0AyurXLxedNz/xoa2TQxKpj755rJw/VujHCLibbN OPOQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=ERdvSHk2; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j15-20020a056a00174f00b0052568123ceasi27412726pfc.315.2022.07.05.04.41.31; Tue, 05 Jul 2022 04:41:45 -0700 (PDT) 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=@amd.com header.s=selector1 header.b=ERdvSHk2; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229902AbiGELjd (ORCPT + 99 others); Tue, 5 Jul 2022 07:39:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229575AbiGELjb (ORCPT ); Tue, 5 Jul 2022 07:39:31 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2067.outbound.protection.outlook.com [40.107.93.67]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AC6913F1C; Tue, 5 Jul 2022 04:39:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TwIx9mx/0TyfwGU/h6nnC6NamuuLlMxx9EabhZJo8UyQeIwoKY2dmwM2sLy+bcHeBnJe0Xyir/ay8StyDohBlQfBofMTKnRUNvjO0zvwsI6AyQdNkeqAHsK6PjtNFMpQwXNx/XJOwECi4oh6lXCLecZMTUBIrLz3Bfv2kj/opCS9HOFNkZAwhyoLGoC1hrG803jExd/LOUJP1gW8mjtAa3KLZTLaJeoawKhdyzcfeQYWLrHheVVID7CivHPXg2T1M+g+gUNgWjJdMmyO45mIGxlQcgnE141XvblJ5AK8QPdBVdS9PNhrLFZkihCjjdRbLN8zxuJ+WmAqnaHdBlccAA== 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=DelXAiXGlRk2fvklJFbMtwD03U+BlcNKX6rBMkC+Bog=; b=dhQF1QYunGhYPKZ7AXD9Uqf4lBW7FN4zzFE8lbbViV8HCug4Z4Ew29wych5FZrW5B3fq2gm/3z1DTaWJ4ImCbE889Vsv615RUGaUNbWtQYozp6o/BssvCT2n8TB1vUu+7lL9U0Wx2j3cJBy9UQcRumTZeUDvMdb1mywRyGR41gpNk8q8oWfBJxi3c7wm5Li8gk+jljqWRFHYxLx+YxofCFzO/22rqAz9GVv6aHPaMH3zOAYvfRJAo6g/H5dIAS+YyM3oBjmu6Em2W3ULrhQuOWCkDI3Bdb0vn+suvIpNiHHWziXW/q7ZNCc1I66yPmKoOExvlvQ7LMtW1u49j093RQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=DelXAiXGlRk2fvklJFbMtwD03U+BlcNKX6rBMkC+Bog=; b=ERdvSHk2iGUleAGTWkVf7m38KUzCtnOwtp8C5HbR+98EkLg4Apcd9QjD9ZO2EphLoHnoy4ibjJ49h/vn3Q/Xaz5voQSoCb3ImVJimzM1Rs+6UY6ho9k+jwXpc4FL4EYvY3DN+e60Yg6Oc+qotumR+DVMrihqSU5ATdVCNqpO2z0= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from BN8PR12MB3587.namprd12.prod.outlook.com (2603:10b6:408:43::13) by DM4PR12MB5134.namprd12.prod.outlook.com (2603:10b6:5:391::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.14; Tue, 5 Jul 2022 11:39:28 +0000 Received: from BN8PR12MB3587.namprd12.prod.outlook.com ([fe80::905:1701:3b51:7e39]) by BN8PR12MB3587.namprd12.prod.outlook.com ([fe80::905:1701:3b51:7e39%2]) with mapi id 15.20.5395.021; Tue, 5 Jul 2022 11:39:28 +0000 Message-ID: <2bb95e80-b60a-36c0-76c8-a06833032c77@amd.com> Date: Tue, 5 Jul 2022 13:39:20 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [PATCH v8 2/2] drm/gem: Don't map imported GEMs Content-Language: en-US To: Dmitry Osipenko , David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Emil Velikov , =?UTF-8?Q?Thomas_Hellstr=c3=b6m?= Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Dmitry Osipenko , linux-tegra@vger.kernel.org, kernel@collabora.com, virtualization@lists.linux-foundation.org References: <20220701090240.1896131-1-dmitry.osipenko@collabora.com> <20220701090240.1896131-3-dmitry.osipenko@collabora.com> From: =?UTF-8?Q?Christian_K=c3=b6nig?= In-Reply-To: <20220701090240.1896131-3-dmitry.osipenko@collabora.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: FR3P281CA0076.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1f::14) To BN8PR12MB3587.namprd12.prod.outlook.com (2603:10b6:408:43::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 338052e8-da48-42ec-1e94-08da5e7b0493 X-MS-TrafficTypeDiagnostic: DM4PR12MB5134:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WyccyBLXdTD266a08cWaMRDyeZSrWSYubPUefUJy8Srck42wiYv4IHcbkJdsRluMLoTadhBGKDMZU5CZAXAS/4VrSYCYMedIwYLTDnjvdgIvxG0gV/0SW7A40XqumyF/KcBt/ggO1UvWdcsXtura/Ej7441xftKUg2pZ4yVeclkqA4S6fDLp/KpLnq2fKM1XHzamwaRsgh8BsHiS77JCtbETUQW/KQqzDL07qhtrY/0JOmNqtaKJvdCuE7/xO2go+EE7e8757aj4lYY/Ol5SMyjC4QU1+Q09bxGFlm/8kgBwBxCXBboMY0kXK1ztoZ7J9+guHb9q6MUkiPJxOZqc0/sitnbNBnm6DC+/R5TgOzvi5GyNNTd0gKEamGaD2pjzYstJ1sxN17w62f5Y/Du8Ug9gGDH9NJS9i2P5HsT4gg5JOIFLBDscKX6yak2fk8M/9oA9kdn4tEszcPymfB3GHEGT1n1PQyhLFt67l+4plzzJWXvbDDp2suRgnuOe1DOr3IiQzO6lj09y+cWKbkDf6OMK9Ot4i66XlT+9etWw5TzPvHByCPmoz82po6Kcw+LOZ3TyzvFmVEdwogg8PZVK4qPtr7fmGlp7g89gzgcX+2uUAj8gd+cELA9Tbk246WZmKWxWNyGOv50nuRZ1RuBjThWY1BsPDwH2T6kmm9wpwl9brnCdL2fBIZ0EonWyFHsIc+6Fpt0uo394ajrucjTjf/y+cZy6b3vR+F4gfPcnO0m1S2aNcbCD0332ORzKJi0XbNDOI8zGKAzvAwoI3kUtDc7BZAyRpFX7keJdi6RtmNkmjbar0QA2WZmds9pEhG0rMluVPRoMkhjZzkyiixVyz9/3Sl8aSpgwaDTdxpa9UyLEW+zbFXGVl5Cd0K6ZGFly X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR12MB3587.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(136003)(366004)(39860400002)(376002)(346002)(396003)(8936002)(7416002)(5660300002)(66574015)(4326008)(8676002)(66476007)(66556008)(66946007)(86362001)(41300700001)(921005)(31696002)(6666004)(110136005)(316002)(186003)(26005)(36756003)(6512007)(2616005)(6506007)(6486002)(2906002)(38100700002)(31686004)(83380400001)(478600001)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?L0lZMnBqZDRGMVhoN05qNUZNTy9YdCt1d2hpdUFBbHF2YllJa3YxWFJFYm1P?= =?utf-8?B?VmNVU2RTQW0zaTM2dTBzVW5ZKzIrdjRFdEZjeW5ReHE2dFU3MTROT0pVMklN?= =?utf-8?B?UW5McS9IMlBzWDV0bE8zanYvemROcUcrSTR1Vnh6TEdMQWMwOFZYNTM3T0ll?= =?utf-8?B?aXBjSlp6L3RNeGFyeGt2YTdhLzRMcnRZT2ZBa0FLZFFlUEk2aENhaFg4NmlX?= =?utf-8?B?c1lVcVJOdU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hn?= =?utf-8?B?QTUxbWxYaGtadDc2ckljbUhjcTc4T2dDSGFCRVdZc01rZllvWmtBWVc1bE9R?= =?utf-8?Q?J3u/J4OOsNmhhd4mVxEdC4n5M?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 338052e8-da48-42ec-1e94-08da5e7b0493 X-MS-Exchange-CrossTenant-AuthSource: BN8PR12MB3587.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jul 2022 11:39:27.9272 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: vhrDG4CkCs7BPCqORgpsPG3xyRFbBDynlhHUnJXvjofnxQa9vgRVq86jm44x9Jg5 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5134 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE 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: X-Mailing-List: linux-kernel@vger.kernel.org Am 01.07.22 um 11:02 schrieb Dmitry Osipenko: > Drivers that use drm_gem_mmap() and drm_gem_mmap_obj() helpers don't > handle imported dma-bufs properly, which results in mapping of something > else than the imported dma-buf. On NVIDIA Tegra we get a hard lockup when > userspace writes to the memory mapping of a dma-buf that was imported into > Tegra's DRM GEM. > > Majority of DRM drivers prohibit mapping of the imported GEM objects. > Mapping of imported GEMs require special care from userspace since it > should sync dma-buf because mapping coherency of the exporter device may > not match the DRM device. Let's prohibit the mapping for all DRM drivers > for consistency. > > Suggested-by: Thomas Hellström > Signed-off-by: Dmitry Osipenko I'm pretty sure that this is the right approach, but it's certainly more than possible that somebody abused this already. Anyway patch is Reviewed-by: Christian König since you are really fixing a major stability problem here. Regards, Christian. > --- > drivers/gpu/drm/drm_gem.c | 4 ++++ > drivers/gpu/drm/drm_gem_shmem_helper.c | 9 --------- > 2 files changed, 4 insertions(+), 9 deletions(-) > > diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c > index 86d670c71286..fc9ec42fa0ab 100644 > --- a/drivers/gpu/drm/drm_gem.c > +++ b/drivers/gpu/drm/drm_gem.c > @@ -1034,6 +1034,10 @@ int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size, > { > int ret; > > + /* Don't allow imported objects to be mapped */ > + if (obj->import_attach) > + return -EINVAL; > + > /* Check for valid size. */ > if (obj_size < vma->vm_end - vma->vm_start) > return -EINVAL; > diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c > index 8ad0e02991ca..6190f5018986 100644 > --- a/drivers/gpu/drm/drm_gem_shmem_helper.c > +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c > @@ -609,17 +609,8 @@ EXPORT_SYMBOL_GPL(drm_gem_shmem_vm_ops); > */ > int drm_gem_shmem_mmap(struct drm_gem_shmem_object *shmem, struct vm_area_struct *vma) > { > - struct drm_gem_object *obj = &shmem->base; > int ret; > > - if (obj->import_attach) { > - /* Drop the reference drm_gem_mmap_obj() acquired.*/ > - drm_gem_object_put(obj); > - vma->vm_private_data = NULL; > - > - return dma_buf_mmap(obj->dma_buf, vma, 0); > - } > - > ret = drm_gem_shmem_get_pages(shmem); > if (ret) { > drm_gem_vm_close(vma);