From patchwork Wed Sep 26 16:18:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Hellstrom X-Patchwork-Id: 10616159 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4768C14BD for ; Wed, 26 Sep 2018 16:20:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C9C82B46D for ; Wed, 26 Sep 2018 16:20:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1BAEC2B45A; Wed, 26 Sep 2018 16:20:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 483442B434 for ; Wed, 26 Sep 2018 16:20:31 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E8B936E4C5; Wed, 26 Sep 2018 16:19:47 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM03-DM3-obe.outbound.protection.outlook.com (mail-dm3nam03on060a.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe49::60a]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1B2456E4B8 for ; Wed, 26 Sep 2018 16:19:24 +0000 (UTC) Received: from localhost.localdomain (155.4.205.56) by DM6PR05MB4588.namprd05.prod.outlook.com (2603:10b6:5:9f::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1185.14; Wed, 26 Sep 2018 16:19:21 +0000 From: Thomas Hellstrom To: dri-devel@lists.freedesktop.org Subject: [PATCH -next 13/18] drm/vmwgfx: Adapt validation code for reference-free lookups Date: Wed, 26 Sep 2018 18:18:34 +0200 Message-Id: <20180926161839.4549-13-thellstrom@vmware.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180926161839.4549-1-thellstrom@vmware.com> References: <20180926161839.4549-1-thellstrom@vmware.com> MIME-Version: 1.0 X-Originating-IP: [155.4.205.56] X-ClientProxiedBy: VI1PR0601CA0020.eurprd06.prod.outlook.com (2603:10a6:800:1e::30) To DM6PR05MB4588.namprd05.prod.outlook.com (2603:10b6:5:9f::25) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 79854f97-ec87-4159-3e8a-08d623cbd1d5 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:DM6PR05MB4588; X-Microsoft-Exchange-Diagnostics: 1; DM6PR05MB4588; 3:qTBI11ezivElk85rt1bl9mcvQiLndDx7GsewO+rJRvK7xI8SYjIjl017FTJUWIahJykV/lMZAZN4TuOGnSAGPsqhzMclE3uR71LSnVeAkKK+YHAhGOuV8AXJcvowBJRWHsDIBYREkCE3RI9OsgmzQG+abrATLot96iLMcPXiMk4vZQ7efWAlSz7jPZhH/Zw6eK/dkAp+wQgQ1DgnC7iCYMcN36HjmXwHnniuCY1jcSdgFDF46YAKI9+YWw5y9ubl; 25:Yz7e5NWWRSfyNkMHlxaBGjuWvwocV4UTfLg9zqQfPYMjQmyuWKYjFTDXFMDnGCiDnUBYhj1VCdRARtHEjqOCb7Qs7Etv+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Z39TanYkj6yIpUUSaJVJsL39E+lK4XhxcdEJ22kbvTt5cN1DVKuonx2rkctnlT4QrZT7Tfv5biEMhubborNyMeLOux25vo5gph08MwVd6u08ac=; 4:cf0c0Svv+2lExKgvzfoJ0FmG6HwreJ36xtxIBtIwnPX0Ke9R8Py942MDb6HdwlQy/PltAhYvso76tAeUuhA+WJ0LbJIk7rWlEtDjrQYzRIR66rv96sUI/1bfNmkUm36na7RZTE5uo5op9gchxEUFoNnKQ2IDjTPvtBhCrNlQPMSWIFTYE4ssja30KX8zI+fyj2ycGrs9aLlu4l5eQ0t48xGxFZt8w/5KQqTAEN1zQmG8uxLozznKf7bxVXVZEKdFUK/o/8NYxZ8+Ygqr8XkbgfZhXfYFsv32o0xeYZwoNZqA8w0OQAR3F43uPiq1SREl X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(61668805478150); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(10201501046)(93006095)(93001095)(3231355)(944501410)(52105095)(3002001)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123558120)(20161123560045)(20161123562045)(201708071742011)(7699051)(76991041); SRVR:DM6PR05MB4588; BCL:0; PCL:0; RULEID:; SRVR:DM6PR05MB4588; X-Forefront-PRVS: 08076ABC99 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6069001)(1496009)(346002)(376002)(366004)(396003)(136003)(39860400002)(199004)(189003)(11346002)(186003)(105586002)(36756003)(47776003)(26005)(66066001)(6512007)(2351001)(305945005)(14444005)(446003)(2361001)(486006)(16526019)(106356001)(7736002)(5660300001)(476003)(6666003)(53936002)(86362001)(6486002)(575784001)(97736004)(69590400006)(478600001)(68736007)(50466002)(25786009)(8936002)(316002)(16586007)(48376002)(956004)(2616005)(386003)(76176011)(6506007)(3846002)(6916009)(51416003)(1076002)(4326008)(8676002)(81166006)(50226002)(6116002)(107886003)(2906002)(81156014)(52116002)(34290500001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM6PR05MB4588; H:localhost.localdomain; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: vmware.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM6PR05MB4588; 23:lTkefPw+yUIpHbTASou71PzAOQn6DGloLEcjoSPdx?= izt4Tqer49mlcVJFeOCx+KNFBhwFUnsLXo0YYcROtyIQ3lT2SEFfQxlNluc1J5v9vaVEV1fffTfdoSNPapMvsLZM+PjVbMp8DvX0YqARtu8yP9NKfeO/2RihAUwksHbD4EF/IrSpKhS7abcu71NkDhsXGz7ArK0+yeAV2qTKHvQ8ntfSmK9TZ/YgTIFiGGi9Ei+AHnf77tKoDPgFdvJ9QtvPiJaynnt6GbnKOdhlnBBLFwd6XM9iPvRQEazTZSbIgdm9fTVWIDHT80B2YM5Co+0JYLwHYU3nb7MVgMBpLllZD6csrz4rGAMR8nXDxUq3Cav6HDh3+XzgfLLEuHdiw+do20cebmj3ndPcbYrA7Izeb2yMTYsryTRSKEEDkT1+qfU7J1Z5jf3VlsQ4D71tfMRHPG36SvoE1ad1TGGdzmpEGJ6gS7Xv/q1hrKnQt1AkQUvSINkyxhtCMdkjyuZrSgA25wZmXrafJjzhcjn4M8NXJ+8mv0KIQeu503nOcgpoGcY110suEnGoIPObZke9IMcXhUFuq2t/4WamqieUYUxC/NP7ONcgR7rXLNkY6SWrv22fWuUKyqOMEnZtaH6VufNDj/3EPaiUERMR2sDcuI10OEpUyzjWzhyKHpWonI6M2muq803P+yQPdyF+aP6lwLLVEzSH1VSk4AoEx4eF9RQyWr7adM658MAvOAN3RLz9bur1lXoPSIM4rvS6F0DPDyvXfc9b7gk36hIr04zPQVrDvOvF/tVvv0iihsBn8X1bft+jKCiAwtDCnXzwJClygvuB2m6uZF6KhN1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RDjCGfVWXU/6CHwv86+rL54+X6gMeHPzZrblaIYWEolNu7/Zu2QUpsHjBJJ2HcqOlRDIaTMUu5nmLxT9ulNqol+6IRc7hFtGrK9ljv3XiJWxXSVe7Wp8CGpEZf+0j69xw2MZiswIl+x2ZjfXmVvB2Cf65lm6YQiep8gLXWl1dvxvekXIjTXq/JyNSXWPJ8OGOmYJeAOIjFlt+obZ1jiK7lLk105JHq4iR9nWKH4TLwdJm/CeY6mWE7UO7QgRQv74JJhZBbhd/cXhhbjCfif4bUuiMcI1Poit/xVfsq1oBeuerRiHMSCsv6nUyK9TmpUP4wQAkOrYdBx879AjmU38t9z4rzl3AGldWHlssHP5ciMA==; 5:Cgv5cBBJMn+xF+su3CNbG/dk1UjImfvZfCRG8CKGK3HsRpJQkqbe9DMXWMn4uQhaJFR49kc38KKya9U2P0nfXpAboKo4YFWH9UXyoNdoNUJCHWsLFl0O1AsVex5vus6i7BWUpuACC99aOkYuKP0ZkUmC9sdZhTd0gwGPtlovpAE=; 7:TccsrOFc8KLN06KqdTj7okurBmTD9iKboNRPiUdwqaYkR+vbVWRceRgkio7Venmkgl+ZtJnvQ0JCppzpfuZSPLVKy3JMI1Y/x9ZThCvswXs1as5ckZu9J9xzTuQnUnCmgz2X+RydFuYkCcABS+HdS8zax31J8+ZyIMkzFa6erkTd4IQxPHUxjMnJQpT8pgdXuD0yJDsV8XJ+4FIJsXd+ge+ETTQT91wLMGGryY7j1GqCuGMe6uq2Wu26z0kRYxDQ SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM6PR05MB4588; 20:2QahP+MzVMnefXg7zLFiKkPxAEuxLrZuU0y71rKmJPQwxG+p4a06B03o/ODHml84dKBG3x9xRrYLXZn8p+4SwSy1Fb3+TugpHlyqu4ma/NYm99K1Yyh5QwX9O3ioYCPryDftL398CGjeIOhChxHJ5JSccwK5zhpNvNwbJgBM0RE= X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Sep 2018 16:19:21.6904 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 79854f97-ec87-4159-3e8a-08d623cbd1d5 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR05MB4588 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Hellstrom , linux-graphics-maintainer@vmware.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Adapt the validation code so that vmw_validation_add[res|bo] can be called under an rcu read lock (non-sleeping) and with rcu-only protected resource- or buffer object pointers. Signed-off-by: Thomas Hellstrom Reviewed-by: Sinclair Yeh --- drivers/gpu/drm/vmwgfx/vmwgfx_validation.c | 61 ++++++++++++++++++++++++++++-- drivers/gpu/drm/vmwgfx/vmwgfx_validation.h | 19 +++++++++- 2 files changed, 74 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_validation.c b/drivers/gpu/drm/vmwgfx/vmwgfx_validation.c index 3158fe161b2d..a5204d1a07d7 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_validation.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_validation.c @@ -94,11 +94,12 @@ struct vmw_validation_res_node { * * Return: Pointer to the allocated memory on success. NULL on failure. */ -void *vmw_validation_mem_alloc(struct vmw_validation_context *ctx, size_t size) +void *vmw_validation_mem_alloc(struct vmw_validation_context *ctx, + unsigned int size) { void *addr; - size = ALIGN(size, sizeof(long)); + size = vmw_validation_align(size); if (size > PAGE_SIZE) return NULL; @@ -262,7 +263,9 @@ int vmw_validation_add_bo(struct vmw_validation_context *ctx, } } val_buf = &bo_node->base; - val_buf->bo = ttm_bo_reference(&vbo->base); + val_buf->bo = ttm_bo_reference_unless_doomed(&vbo->base); + if (!val_buf->bo) + return -ESRCH; val_buf->shared = false; list_add_tail(&val_buf->head, &ctx->bo_list); bo_node->as_mob = as_mob; @@ -313,7 +316,10 @@ int vmw_validation_add_resource(struct vmw_validation_context *ctx, return ret; } } - node->res = vmw_resource_reference(res); + node->res = vmw_resource_reference_unless_doomed(res); + if (!node->res) + return -ESRCH; + node->first_usage = 1; if (!res->dev_priv->has_mob) { list_add_tail(&node->head, &ctx->resource_list); @@ -715,3 +721,50 @@ void vmw_validation_done(struct vmw_validation_context *ctx, mutex_unlock(ctx->res_mutex); vmw_validation_unref_lists(ctx); } + +/** + * vmw_validation_preload_bo - Preload the validation memory allocator for a + * call to vmw_validation_add_bo(). + * @ctx: Pointer to the validation context. + * + * Iff this function returns successfully, the next call to + * vmw_validation_add_bo() is guaranteed not to sleep. An error is not fatal + * but voids the guarantee. + * + * Returns: Zero if successful, %-EINVAL otherwise. + */ +int vmw_validation_preload_bo(struct vmw_validation_context *ctx) +{ + unsigned int size = sizeof(struct vmw_validation_bo_node); + + if (!vmw_validation_mem_alloc(ctx, size)) + return -ENOMEM; + + ctx->mem_size_left += size; + return 0; +} + +/** + * vmw_validation_preload_res - Preload the validation memory allocator for a + * call to vmw_validation_add_res(). + * @ctx: Pointer to the validation context. + * @size: Size of the validation node extra data. See below. + * + * Iff this function returns successfully, the next call to + * vmw_validation_add_res() with the same or smaller @size is guaranteed not to + * sleep. An error is not fatal but voids the guarantee. + * + * Returns: Zero if successful, %-EINVAL otherwise. + */ +int vmw_validation_preload_res(struct vmw_validation_context *ctx, + unsigned int size) +{ + size = vmw_validation_align(sizeof(struct vmw_validation_res_node) + + size) + + vmw_validation_align(sizeof(struct vmw_validation_bo_node)); + if (!vmw_validation_mem_alloc(ctx, size)) + return -ENOMEM; + + ctx->mem_size_left += size; + return 0; +} diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h b/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h index 0eb2d02d0c0c..b57e3292c386 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_validation.h @@ -177,6 +177,18 @@ vmw_validation_context_init(struct vmw_validation_context *ctx) INIT_LIST_HEAD(&ctx->bo_list); } +/** + * vmw_validation_align - Align a validation memory allocation + * @val: The size to be aligned + * + * Returns: @val aligned to the granularity used by the validation memory + * allocator. + */ +static inline unsigned int vmw_validation_align(unsigned int val) +{ + return ALIGN(val, sizeof(long)); +} + int vmw_validation_add_bo(struct vmw_validation_context *ctx, struct vmw_buffer_object *vbo, bool as_mob, bool cpu_blit); @@ -207,6 +219,9 @@ void vmw_validation_revert(struct vmw_validation_context *ctx); void vmw_validation_done(struct vmw_validation_context *ctx, struct vmw_fence_obj *fence); -void *vmw_validation_mem_alloc(struct vmw_validation_context *ctx, size_t size); - +void *vmw_validation_mem_alloc(struct vmw_validation_context *ctx, + unsigned int size); +int vmw_validation_preload_bo(struct vmw_validation_context *ctx); +int vmw_validation_preload_res(struct vmw_validation_context *ctx, + unsigned int size); #endif