From patchwork Mon Jan 2 13:41:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Moisieiev X-Patchwork-Id: 13086741 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D7BEC4708E for ; Mon, 2 Jan 2023 13:42:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232769AbjABNmP (ORCPT ); Mon, 2 Jan 2023 08:42:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231445AbjABNmN (ORCPT ); Mon, 2 Jan 2023 08:42:13 -0500 Received: from mx0b-0039f301.pphosted.com (mx0b-0039f301.pphosted.com [148.163.137.242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B914463AB; Mon, 2 Jan 2023 05:42:11 -0800 (PST) Received: from pps.filterd (m0174682.ppops.net [127.0.0.1]) by mx0b-0039f301.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 302Bx46C011991; Mon, 2 Jan 2023 13:41:51 GMT Received: from eur04-he1-obe.outbound.protection.outlook.com (mail-he1eur04lp2054.outbound.protection.outlook.com [104.47.13.54]) by mx0b-0039f301.pphosted.com (PPS) with ESMTPS id 3mtd0uv746-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 02 Jan 2023 13:41:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ABPLD1J8Kgnw715Dt1/2KX2dbDeje4uBexVMcbPScdgoa5Ic6kYbKvXO+cui/dem3U9LADmf/iKoHKFFeXuMfbZPp3U8KglwR5PTslS7OJkTJdQp1K0l5J+ufIDB1UpU6afpou/jC8ue08RNNHJqG+UAqfB0oXgLWtTqx2eFp0IugPVZKZxp2KBA9mz0yGdAbrY47e1FKNCJUk+PR/jWpeFBu6UTOMc5t9USRBdxJNGM5Tea+l/KV9Gzy0alkFTwZSbun43ey5NU6CC0bpzw1G5HdvUI5+hyMm0a08yqFJ66FNIlODhiPyNcLXPPdnwYy+pjje5Yu5kS8FKcst9ovQ== 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=iuEwZFP31bPDffsqU14aI2kPMruZO5ACTYwm5FDPm60=; b=B9R/I6QLYSiJU+rii9DHveI07cMZtlbZXngAXR/puw/cgHHwLp5JGWxVLrg+b3BTF2Q7WU4Z/DObyL6xLwXHlx5G4RAV2k2bKDhbyidMnRDo5sq8xCD15iFtpVjzL3tC2L3q7Qgy14QvilN3S7zgyf1O/3oP9sfwKGFY9V3w8iyghobsDLk5DlQiHN1H45QBzs6GaUwrXSaCRNBbehQ+mmg04w0fAWeuJ85YUoLzIy7XP1+qOwq4Uj5eTTpGWKuLuT6iO52xYVsv/P8iPYqExb6tmrAToRvAPHfOpeb8SW2sjIPtgQpKRfXvVk0CEXx3Y1mVGn8A6C2/v6RKrCdi1Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=epam.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iuEwZFP31bPDffsqU14aI2kPMruZO5ACTYwm5FDPm60=; b=Fj64byEjy6KUX0YgNrwxi4w4yTqByFsOVPSfZxAYH/vd6Q4mO6K0I929JQcT0CGUSh1iLJ6OVIt03Hl0cStQ0yQ2hhePHeIwmn19mSxc9aCbP25w3FPYsWgvVm19EMr7G5NnbGkWJW7LQe2uejzlWo8014RWSliHs/GLKMs60J++lOEHifxY81phUlClQxIRKuWZBr9pKxptY6IbkuS9T2dM5jEMgIOYRwsrBv1nc7DmGbBw5TfeFPY55tieXLeAmWgIvmVtzouTWQTpHKx0rAYrYA3eT5h88OeQjYD6iAV/jIgdyGWp0cAMtdP9mOVsKmFLBusZfvIdGW39WVP9WA== Received: from PA4PR03MB7136.eurprd03.prod.outlook.com (2603:10a6:102:ea::23) by DB9PR03MB9709.eurprd03.prod.outlook.com (2603:10a6:10:459::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.19; Mon, 2 Jan 2023 13:41:48 +0000 Received: from PA4PR03MB7136.eurprd03.prod.outlook.com ([fe80::2da6:6d63:389b:3552]) by PA4PR03MB7136.eurprd03.prod.outlook.com ([fe80::2da6:6d63:389b:3552%9]) with mapi id 15.20.5944.019; Mon, 2 Jan 2023 13:41:48 +0000 From: Oleksii Moisieiev To: "jgross@suse.com" CC: Oleksii Moisieiev , Stefano Stabellini , Oleksandr Tyshchenko , "xen-devel@lists.xenproject.org" , "linux-kernel@vger.kernel.org" , Sumit Semwal , =?iso-8859-1?q?Christian_K=F6nig?= , "linux-media@vger.kernel.org" , "dri-devel@lists.freedesktop.org" , "linaro-mm-sig@lists.linaro.org" Subject: [PATCH v1 0/3] Add ioctls to map grant refs on the external backing storage Thread-Topic: [PATCH v1 0/3] Add ioctls to map grant refs on the external backing storage Thread-Index: AQHZHq/2qxwFjlIdpkaeJi9xnPE21Q== Date: Mon, 2 Jan 2023 13:41:48 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: PA4PR03MB7136:EE_|DB9PR03MB9709:EE_ x-ms-office365-filtering-correlation-id: d61e592b-7ca9-4505-ba47-08daecc7189d x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: K//txomNbdnSgoB7Ft87gMsqzlplA7ByfPveZH2lOQbvzABfonhwPmW8pHTNVcWTtxhsA5pikAmzM4H43dTGp5i67FfOE6KrsVW/xqecWgvPNpwRErzxifu/6Dh7LMSihwMtaA4ZNSJsAR5Bh7Ofo8G9TJ4zwgbQxcC+i8EvuQn5oFj41yWqthGpy5doxFGUZsePuUZrrZJURNp7H9wTJfZPr9M66lcICykSQJtytLyBXnYk4VFdf3OuCKWUkxXPLnhzpdAgsil+oTjBXbDQ5TEacgQB4Y6L9lt59W8/XuaaHqPUVUE96QFFTMU4tASrqj1T5GqGgxNvbMo05ijG7i5rDAUW8galctv+eyyR2EF1ygZBYj9ce+q4rmgE9g6b7MPadEhwy1bAhh52OVhgqA4UaaTD0ffgE6xLbwm8J2FoadXZY4dxq54JF8XrbLVHAxiEPseciaNfVFWVKslvmPS105pRW1ZRN2d0X8DLzQN9SGU40rj4rgm40/KDPDoS9wBlsa9fJwktvRREvui4tdnsPGj4DuhJzy42AsxUQ12Kz21QKNgm4rpEdmCSgXz/Q8KAFDQWpEqY7Jn2dfTwQw/X/ubqmjfaWPQx0nOFRjjwxO9qfOMc6BFaJ2V9qABylklJMBrGgAt3QNQ/5tlqJRftRFbfu0Dm0EyOIIUqZq61zsUty87JKWX/ln3ZTgwBGU35xLvoW+hkIb0dRxV2XLtAlHyksYaGai0kIpUbyHk= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PA4PR03MB7136.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(396003)(346002)(136003)(376002)(39860400002)(366004)(451199015)(38100700002)(122000001)(86362001)(8676002)(38070700005)(66476007)(76116006)(66946007)(64756008)(66446008)(66556008)(6916009)(91956017)(4326008)(41300700001)(54906003)(316002)(2906002)(5660300002)(8936002)(2616005)(83380400001)(6512007)(478600001)(71200400001)(6486002)(6506007)(26005)(55236004)(186003)(36756003)(22166006);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?PimHRKzqh67sap2y2kDEW/C?= =?iso-8859-1?q?M2rd3FBGTTabLIqTqSyMy/RLiHOm+gXm8aGHnuj2k+DTRaDD5ESNOehMMM84?= =?iso-8859-1?q?6HY5OaQIkW3l4pjaaUfzUEhxjby2Ac1xKXeDLrvdsSK+2BnhMlDHiXB7MTLe?= =?iso-8859-1?q?SE2E8GriDNay6Rg0zoIhthgVUqQAUbtifrpBbeO/oc3ErtvBDnbAFM1svMTk?= =?iso-8859-1?q?3dXPcybVgnRTXTuDoFieCZawXZrWeZiT5Dm3BVL0nXr2lRJ1ze8mcYM+OHSE?= =?iso-8859-1?q?tZirldOJoduV6vXz552ddktFqz7qg1SsTjGNJtSLptzQ88HYATYXZHeeWJgz?= =?iso-8859-1?q?EEHwX6IpOVxazUWzHnKpwEtBW4HnbQnEZy49jw28MWMsy8UYmt71KYKShDc+?= =?iso-8859-1?q?uBjCDTp1Xqdh1WLU5mxP5ZEViFQvCbsLM0jx67476k8SJMC4ZZOzupO0AZPM?= =?iso-8859-1?q?a29Z9R1RzyaTXiOCa9zHHAjNR19bieXK/4dylgt4UGDyCQOrBWxDbRG4y64S?= =?iso-8859-1?q?ljszHiGtZ4iZdzu1aA60nVLEhmpk2KtQKqjBA+HYQZXrX8sg2SWXEa3pObkL?= =?iso-8859-1?q?txAjdoWmWdiuT8SKYnb7gq3NO+o9syurpCfSjxqvCParte6GjpYJP91ItCJU?= =?iso-8859-1?q?Wb0HPFJg1GFPAHvDZNEQhimJzXKW+p/BQmdN9DWNWpSYInuTnWDuvGXyeRp0?= =?iso-8859-1?q?ixOGNlVMN5ycww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Gj6yzADmZbzlbnUSocfa+hX+?= =?iso-8859-1?q?HGmntj5hKBCpd0H0n7CK5Sv0tJkYz6ImXTtQyIw=3D=3D?= MIME-Version: 1.0 X-OriginatorOrg: epam.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PA4PR03MB7136.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: d61e592b-7ca9-4505-ba47-08daecc7189d X-MS-Exchange-CrossTenant-originalarrivaltime: 02 Jan 2023 13:41:48.1514 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b41b72d0-4e9f-4c26-8a69-f949f367c91d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: v8p9FkNMGcd+IAcNLFIF+4SgKpMOoAi7zGCwL0Q8hm7GPRWT8c9uD3HtozKM872KL0egO8w00Y3Y/YZBdiHg4+4C35ro1kP5trBmjT97ZdU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR03MB9709 X-Proofpoint-GUID: xU2f70Y-pvWxurXYXUo2TyiosKfNjL_N X-Proofpoint-ORIG-GUID: xU2f70Y-pvWxurXYXUo2TyiosKfNjL_N X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2023-01-02_08,2022-12-30_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=835 phishscore=0 lowpriorityscore=0 bulkscore=0 impostorscore=0 spamscore=0 priorityscore=1501 adultscore=0 suspectscore=0 mlxscore=0 malwarescore=0 clxscore=1011 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301020124 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Hello, Let me introduce the new ioctls, which are intended to allow gntdev to map scatter-gather table on top of the existing dmabuf, referenced by file descriptor. When using dma-buf exporter to create dma-buf with backing storage and map it to the grant refs, provided from the domain, we've met a problem, that several HW (i.MX8 gpu in our case) do not support external buffer and requires backing storage to be created using it's native tools. That's why new ioctls were added to be able to pass existing dma-buffer fd as input parameter and use it as backing storage to export to refs. Following calls were added: IOCTL_GNTDEV_DMABUF_MAP_REFS_TO_BUF - map existing buffer as the backing storage and export it to the provided grant refs; IOCTL_GNTDEV_DMABUF_MAP_RELEASE - detach buffer from the grant table and set notification to unmap grant refs before releasing the external buffer. After this call the external buffer should be detroyed. IOCTL_GNTDEV_DMABUF_MAP_WAIT_RELEASED - wait for timeout until buffer is completely destroyed and gnt refs unmapped so domain could free grant pages. Should be called after buffer was destoyed. Our setup is based on IMX8QM board. We're trying to implement zero-copy support for DomU graphics using Wayland zwp_linux_dmabuf_v1_interface implementation. For dma-buf exporter we used i.MX8 gpu native tools to create backing storage grant-refs, received from DomU. Buffer for the backing storage was allocated using gbm_bo_create call because gpu do not support external buffer and requires backing storage to be created using it's native tools (eglCreateImageKHR returns EGL_NO_IMAGE_KHR for buffers, which were not created using gbm_bo_create). This behaviour was also tested on Qemu setup using DRM_IOCTL_MODE_CREATE_DUMB call to create backing storage buffer. --- Oleksii Moisieiev (3): xen/grant-table: save page_count on map and use if during async unmapping dma-buf: add dma buffer release notifier callback xen/grant-table: add new ioctls to map dmabuf to existing fd drivers/dma-buf/dma-buf.c | 44 ++++ drivers/xen/gntdev-common.h | 8 +- drivers/xen/gntdev-dmabuf.c | 416 +++++++++++++++++++++++++++++++++++- drivers/xen/gntdev-dmabuf.h | 7 + drivers/xen/gntdev.c | 101 ++++++++- drivers/xen/grant-table.c | 73 +++++-- include/linux/dma-buf.h | 15 ++ include/uapi/xen/gntdev.h | 62 ++++++ include/xen/grant_table.h | 8 + 9 files changed, 703 insertions(+), 31 deletions(-)