From patchwork Thu Sep 1 14:20:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 12962744 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 80FBCC54EE9 for ; Thu, 1 Sep 2022 14:21:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234584AbiIAOVD (ORCPT ); Thu, 1 Sep 2022 10:21:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232685AbiIAOVB (ORCPT ); Thu, 1 Sep 2022 10:21:01 -0400 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2071.outbound.protection.outlook.com [40.107.237.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6729432EC1; Thu, 1 Sep 2022 07:21:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mQDuxmPMKgq+5eat+j7TfqmgVBa9QJwwxIWNNAdarunVYn1CdbZSx0bCz9W3WPZuBzedFgg/fWp2Ep97Dg4OCi+2AgPpeYCPXRnoO4Ua8WfXa2DikxXdTz6zcFec8mxA1KD/kEoY7e1fA1yDi8OG1y6RXP25hGKA0rsMBvoRkxpOb+rh8cePmJoOhFlBmAGbUDZzLJ+9GCNvIkRpgNuMLHa0l+rwwX8DXtdeyo+eWkJljV567N9ePeDvelpCS9f2AhjsB3CqGKP7zSpb6OwbBMBT6A2NAQ5PJesxsY+spYj1QkBBN84sGQUaEcJqPOL90stDTVKKI9YoYmfijtIfxQ== 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=/aB2fdyup4zXlO7Fs2az03ubJD/zt2/t60pbinRpFNQ=; b=aBt/156TwEDGCmZgi6MygQeDDQjTKmCV4Lpa575aKRhkvFmmM2GlvYsi/jLGILTvIzy7945rIBP9W8WLj8uPraxebGaHYO7AoTH7paTEA7AOUfin54hzwvMVTD30ZWhjsLDjfzIgywRV+NYT5nyRxaoyAKlmwZy6StQRFQO4Y5cJy08wf5iOGJBf0X4jOyJUIZCbGtWftS1C4USbdPdxO9NQU5IOZklRdeQTEQESIohmZ1L5/4CKvWDIbO4abqUu6Hk2ANGh2MLHcMpQkPGvv8fbBs6fuh5hLUedC7l591RbIADJZwZ8ojzAfIgn9Bhw/rIXQkokmtOSSjR1z97BlQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/aB2fdyup4zXlO7Fs2az03ubJD/zt2/t60pbinRpFNQ=; b=fhZmiN7U8rZs0slqgczpOzdTFY4A/es294tSxlbS6qTlnkg2JPTIWmw60A2jFK4Mbc7bbnpjIINDfTqK+L725dh1267yyQfGzpk3TGTEJmaLTEmzSGri+y+6zknHB0Achf6pIbb9D7XVkfet5IZbV3YOdEvLZJ2hh6oqtTTLlpMQdz6SushKoQ4cHG4z9I8wWGKFEahlCsB99nVPcsHYi3TZC9kUiTBpX9+EiqAN3eRn5wIIGN3627I0KFlPfY6WfKEP+9eQ3fRlzRP6Kcn4V9pjAslq1Ae8hU5pXcwsKcGZ2DmRSIUWgIv8ZlvyRNp7vUbVIi0GIGXUMlrThJlHCQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from MN2PR12MB4192.namprd12.prod.outlook.com (2603:10b6:208:1d5::15) by BY5PR12MB5000.namprd12.prod.outlook.com (2603:10b6:a03:1d7::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.15; Thu, 1 Sep 2022 14:20:57 +0000 Received: from MN2PR12MB4192.namprd12.prod.outlook.com ([fe80::462:7fe:f04f:d0d5]) by MN2PR12MB4192.namprd12.prod.outlook.com ([fe80::462:7fe:f04f:d0d5%7]) with mapi id 15.20.5588.012; Thu, 1 Sep 2022 14:20:57 +0000 From: Jason Gunthorpe To: =?utf-8?q?Christian_K=C3=B6nig?= , dri-devel@lists.freedesktop.org, Leon Romanovsky , linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org, linux-rdma@vger.kernel.org, netdev@vger.kernel.org, Saeed Mahameed , Sumit Semwal Cc: Kamal Heib , Mohammad Kabat Subject: [PATCH 2/4] RDMA/core: Add UVERBS_ATTR_RAW_FD Date: Thu, 1 Sep 2022 11:20:54 -0300 Message-Id: <2-v1-bd147097458e+ede-umem_dmabuf_jgg@nvidia.com> In-Reply-To: <0-v1-bd147097458e+ede-umem_dmabuf_jgg@nvidia.com> References: X-ClientProxiedBy: MN2PR01CA0007.prod.exchangelabs.com (2603:10b6:208:10c::20) To MN2PR12MB4192.namprd12.prod.outlook.com (2603:10b6:208:1d5::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9e4e12a6-d60d-496c-015d-08da8c253009 X-MS-TrafficTypeDiagnostic: BY5PR12MB5000:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pDIhVsbNPCH+LhanUheLaUnlGaYL1t0kAYkMcEFk7HH6dbs2Lero7nX8e0hrGuY7rZARQW4B6415QmY63s5m2X+TSJ/7b+gP4hfid6K4MnfwamloC5R2XOBxe+SyUGKYG+2p5PrGBXJwBFhhgnXtYfwZbHf2dtYRzGl0NfXnRk5s72fsd4d720RKSDelHTZTZQwj3pOf/BKHYLrOeMSxO2KOOQ5iorgJ9ydF6BLnqB57wiDOYfKvs0JLCC0KVQX39qRwJMNOajOKLaQ7YTJZWXsnQEI//H0ACkW21qxu2hAEDGQx3r3lk4MjxKSOBaga2c2SQpUL1RjlTOLIL1DbAmR1/Oy2uDFFahiZDZ486bI4UrCQ8O+O8/tBPcDxmnIbaGtaKHBBJlmpcg0IsD5XzwSPU0p3gOkjMeLhgbMGu7K05kKntJni2xThuq9oyXtVdTHMHxTPs73rze7jlsc/L8O9iToIKoTUIIzAc/Jgh/4uizYPQ1MirPXt4jRn2401OtNxH7qKlVYRlW/ShZxVXGWRn1uq/Hk5Nq0QYXEwARdh65d22iFhBJMeAH5ac8wsujBh3CeLzfdZ+r/N6KeC2dj2t09HKm5FvoyzzmkkKWdCXzTh93QSZ0CC+FJcUhFz7NSbTylkE1uBo3CxQzykzVOG2f+ejXXS76902UqgQaYrTD+dVI6chZiincaTmkAXEt8kRXdgd6UBzmpAG0tDZgukU48HQxXKJ+wCYwFdRHwhU2Au2iKPmb67+NRmBnck X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR12MB4192.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(39860400002)(376002)(346002)(136003)(366004)(396003)(6512007)(66946007)(4326008)(5660300002)(66476007)(6666004)(6506007)(478600001)(107886003)(8676002)(66556008)(6486002)(8936002)(86362001)(41300700001)(83380400001)(2906002)(2616005)(26005)(38100700002)(186003)(316002)(36756003)(110136005)(54906003)(4216001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-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lo5jyZeRwYKNF4mnnU8aaDHQv9tLM+QdVTaOx3rML99BAqnx5QW1QXHZa/okrLP5nErLILJYrKRrpNUa/vwT+oKw/Jq2y8TIR3LH3BRI46s4YiSVotDeKPYcObYD7QesOajWpSnzrcuw+seSAIOjEW/f2Z+LqqteX82zexU2UYGXriRFkZLa0Sxqv13mXm19ZoMB5GrUb6KW1Ab58AD+JbjQJNfzitK4o6co6HZBrtJPQRGl445yA0sDoF70yiVimFPqTTw+mflnpSIbiRMAP7SqT07hAJyJOKvHGIyR/KRRc/dCiqgqh/BeTgIi/EWdBhp9PeoRTzmcvqW2wP1ceR/q/YaVfrihBKURFMFLVescSqODH8oGF7giiP2FwMfaLvPYdTxcUhG8/erM6pqIx20idLDVAZ2Y0sDlJ6uJV3LQEviab4+DGLGGnW0kS95iitfWtoHh5PcS/2+JyZs+VXj0Wt6TcDleOPzxgXgFWEuYkQLjz5fcvHRP914O3X8Br9AEXwdn1TKRkIe26/2FoQXGVXaAmj2uRdag X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9e4e12a6-d60d-496c-015d-08da8c253009 X-MS-Exchange-CrossTenant-AuthSource: MN2PR12MB4192.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2022 14:20:57.5171 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 3MayONxtN/zL4PW7xCehQvlc2ay4mi/jVluEOkJMaoVCyd0vXa+ydBenYoQ9bb9D X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB5000 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org This uses the same passing protocol as UVERBS_ATTR_FD (eg len = 0 data_s64 = fd), except that the FD is not required to be a uverbs object and the core code does not covert the FD to an object handle automatically. Access to the int fd is provided by uverbs_get_raw_fd(). Signed-off-by: Jason Gunthorpe --- drivers/infiniband/core/uverbs_ioctl.c | 8 ++++++++ include/rdma/uverbs_ioctl.h | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/drivers/infiniband/core/uverbs_ioctl.c b/drivers/infiniband/core/uverbs_ioctl.c index 990f0724acc6b6..d9799706c58e99 100644 --- a/drivers/infiniband/core/uverbs_ioctl.c +++ b/drivers/infiniband/core/uverbs_ioctl.c @@ -337,6 +337,14 @@ static int uverbs_process_attr(struct bundle_priv *pbundle, break; + case UVERBS_ATTR_TYPE_RAW_FD: + if (uattr->attr_data.reserved || uattr->len != 0 || + uattr->data_s64 < INT_MIN || uattr->data_s64 > INT_MAX) + return -EINVAL; + /* _uverbs_get_const_signed() is the accessor */ + e->ptr_attr.data = uattr->data_s64; + break; + case UVERBS_ATTR_TYPE_IDRS_ARRAY: return uverbs_process_idrs_array(pbundle, attr_uapi, &e->objs_arr_attr, uattr, diff --git a/include/rdma/uverbs_ioctl.h b/include/rdma/uverbs_ioctl.h index 23bb404aba12c0..9d45a5b203169e 100644 --- a/include/rdma/uverbs_ioctl.h +++ b/include/rdma/uverbs_ioctl.h @@ -24,6 +24,7 @@ enum uverbs_attr_type { UVERBS_ATTR_TYPE_PTR_OUT, UVERBS_ATTR_TYPE_IDR, UVERBS_ATTR_TYPE_FD, + UVERBS_ATTR_TYPE_RAW_FD, UVERBS_ATTR_TYPE_ENUM_IN, UVERBS_ATTR_TYPE_IDRS_ARRAY, }; @@ -521,6 +522,11 @@ struct uapi_definition { .u.obj.access = _access, \ __VA_ARGS__ } }) +#define UVERBS_ATTR_RAW_FD(_attr_id, ...) \ + (&(const struct uverbs_attr_def){ \ + .id = (_attr_id), \ + .attr = { .type = UVERBS_ATTR_TYPE_RAW_FD, __VA_ARGS__ } }) + #define UVERBS_ATTR_PTR_IN(_attr_id, _type, ...) \ (&(const struct uverbs_attr_def){ \ .id = _attr_id, \ @@ -999,4 +1005,11 @@ _uverbs_get_const_unsigned(u64 *to, uverbs_get_const_default_unsigned(_to, _attrs_bundle, _idx, \ _default)) +static inline int +uverbs_get_raw_fd(int *to, const struct uverbs_attr_bundle *attrs_bundle, + size_t idx) +{ + return uverbs_get_const_signed(to, attrs_bundle, idx); +} + #endif