From patchwork Mon Nov 13 14:57:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrey Grodzovsky X-Patchwork-Id: 10056265 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1953860215 for ; Mon, 13 Nov 2017 14:57:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A16329591 for ; Mon, 13 Nov 2017 14:57:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1E2129593; Mon, 13 Nov 2017 14:57:46 +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=-2.6 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_WEB, T_DKIM_INVALID 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 AC4B029591 for ; Mon, 13 Nov 2017 14:57:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A542E6E62E; Mon, 13 Nov 2017 14:57:44 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM01-BN3-obe.outbound.protection.outlook.com (mail-bn3nam01on0071.outbound.protection.outlook.com [104.47.33.71]) by gabe.freedesktop.org (Postfix) with ESMTPS id B36CA6E0E5; Mon, 13 Nov 2017 14:57:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=IGu+TB1vfbtGLWdznuA4HYxo+dto80N1z49IzOQRwIo=; b=DbtJj4zgjlNrBjIo32MPpxLhnHfDh+ZTB0yNtxHUcG1Heghiv4Ziv7p4J5WDP/dgIPP5gsHtQ1f3AVjH9dkhHsvFMoxniUaTEj/5Fo162Z8eXf7mgGoeQ6ZYx5AJQkzDwXBvjjgEpC7sHiBrvav0KSKcSyIkiOyIa+U8uSXM3Dw= Received: from [172.27.225.149] (165.204.55.251) by BN6PR1201MB0098.namprd12.prod.outlook.com (10.174.114.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.20.218.12; Mon, 13 Nov 2017 14:57:40 +0000 Subject: Re: [PATCH libdrm 0/4] Dynamicly disable suites and tets. To: =?UTF-8?Q?Christian_K=c3=b6nig?= , =?UTF-8?Q?Michel_D=c3=a4nzer?= References: <1510288203-21716-1-git-send-email-andrey.grodzovsky@amd.com> <407f0a79-e15b-61b7-2e3a-8f4b680c9c6c@amd.com> <58c5d164-078d-74cc-b3ab-07bf6d39287c@amd.com> <1245c92c-bfc4-d343-c752-17fa036e1bad@amd.com> <7a5b2721-5938-c865-27b0-47dae1ad5883@daenzer.net> From: Andrey Grodzovsky Message-ID: Date: Mon, 13 Nov 2017 09:57:35 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: X-Originating-IP: [165.204.55.251] X-ClientProxiedBy: MWHPR19CA0006.namprd19.prod.outlook.com (10.173.246.144) To BN6PR1201MB0098.namprd12.prod.outlook.com (10.174.114.135) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 78b1a2fa-7996-4bfe-abb8-08d52aa6e350 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(48565401081)(2017052603258)(49563074); SRVR:BN6PR1201MB0098; X-Microsoft-Exchange-Diagnostics: 1; BN6PR1201MB0098; 3:xTSqstKbizbnlMSD6YEoNsNkh9LBQM0wVZKvHO+981+vnpSs++D3imbSv+pGwUjMoEIC7dtXBTvyjVv/z3q0h1bJ7PxiiYtbxXQwuQIOuGOQRu4EY1p3fpIrhcESX395pNVOm8a0j01pQ51rzeoekD4hKX5zDZvoTtm9rY2i3aTroXZ0r/9yWxwdZ+nIGGdMdkc1WmeoAP8wSE6LdY9jKZ4JHl7eaL8oI/0BjeY0dbLy831MidKRbxkAwKupCoLT; 25:oQtp6xlv/ZZ9WoMlkbHxi1ycwx5/CkArLYmALbvsaLythG++ynNohgSNxUQATZiXYrA/LEwKKfbmfh1dezgNsmZFoKeOoTN3ZTDNEFU6uMDOwbjzw+fgE4ICBWYEmfxlSHEiLJHWdcTdWEv4yvoCBtAYcx2E4w4MT7Y6eRpXhD8uKCCBQQcp9d4eOY+DIBBuOqfA5mduO3rpCCKr12tn33yyE5SNxICruVxr1wN2FuwpWB9MCU95VqdMQoBqbu+jL4NuzLtpSQaZOGvBsuVy7T1JaAIvChm/F/BQD5GJufBoqkRleaKmwINxz5Tx1uTLHoChYLrl+yg27Df5W+TXpg==; 31:6fQh2tVx42y+BCDTAk5Y8ytM+wTOtveYBti1ujosR5j5kNd+0SKtKczrx9NYKg9wAFKkyYwICgmy0e0t/dZlMJ7SKQFBMXKIr63JIV+cR3bU5F8gB3jihR3q5EmS3WtMQ1ep6xsMoCQ/QX6u8Y0csbMh9/Ujw9fZgMmr+9naO7nNAP5Q8vmne7Pdn32PN09ybuNwRXKjg6eR+z5H9n9vyrwd5rUhpU1Ar90Z6S1Foy0= X-MS-TrafficTypeDiagnostic: BN6PR1201MB0098: Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Andrey.Grodzovsky@amd.com; X-Microsoft-Exchange-Diagnostics: 1; BN6PR1201MB0098; 20:ObcznpuFVOQ1Xv+3sVq/LPsiuYacn5TugEi9qw4u8RO7JI5QxgSE3mOcuvw+8qC0lFR0R3Z/YPh5w2a4otrE5VauNE7i3kCnHvCd8TcdASitMrW8Qqrpp8eHxJrl4ydUvYRU6+/BecZAxxGb4qMcJ8F4kW28fbYeVCeHY6OkHyTNpercwB/XFPiCrDxx77QHdkVGZOMLX/F77L78a/Wzur8wqumJtNV7iE3qD7gmhdhsz79xcYQNYLFoqPkOHfX536KivxtA0RnaRIBakZ/G+3SWaMBCBsW5VHMfERTQsc3b6jW+McpnZ7H4hJXCDB8hS5zy8rk8qYuAd4puIaaAV3+EaWfVyH4AAmKndfIe6L/Jl4PsopmIvFxGrUVoNS9yvkrOA8ULYq19ufQw1GYSCNnZpR+xDg2LV0S6+AevUaIt6uVTHWT691MHbVLE+Qr9K7zGKP/lKIMinj6QgDFbw+tGLd5Vmoo8jB1rNaJ0P7HURM1cZ2ltGSzYvH/901Xw; 4:vFntR6RbBq8YPacJ2tdp6df8Uv8VR1sd3GvGoxytiYGMjGacCVlPSdqUu2QMHJCEoTmAHsFnCQYWW8UtSDEmjKT3Qv0F2Gwbzy05XXb+CREFMQn+fYgEEEuIf/gXM5LqxxwEXGQNoRA7DCWKppoYMRMONdmhqwpyLlcr5RYiSMWHFCf9Qp6cyfZfnmLj/UlJRdN+D3jTsVhDK5/5/is+a2UhPa9KPhJms0mdB+4U8YOada79iD2Xt0PyX2cvdo4nQFGlAa+9oaZrVFsmP7qAdQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(102415395)(6040450)(2401047)(8121501046)(5005006)(10201501046)(3002001)(3231022)(93006095)(93001095)(100000703101)(100105400095)(6055026)(6041248)(20161123562025)(20161123558100)(20161123560025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:BN6PR1201MB0098; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:BN6PR1201MB0098; X-Forefront-PRVS: 0490BBA1F0 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6049001)(6009001)(346002)(39860400002)(376002)(24454002)(189002)(199003)(6246003)(86362001)(5660300001)(65826007)(53936002)(65806001)(2906002)(105586002)(25786009)(4326008)(68736007)(31696002)(106356001)(2950100002)(6666003)(101416001)(4610100001)(305945005)(6116002)(7736002)(84326002)(65956001)(2476003)(16576012)(3846002)(16586007)(93886005)(270700001)(58126008)(31686004)(316002)(568964002)(229853002)(36756003)(97736004)(8676002)(83506002)(189998001)(81166006)(16526018)(81156014)(66066001)(8936002)(478600001)(50986999)(90366009)(33646002)(64126003)(6486002)(77096006)(110136005)(5890100001)(53546010)(37036004)(72206003)(76176999)(54356999); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR1201MB0098; H:[172.27.225.149]; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN6PR1201MB0098; 23:a+LALOuP/3afT67azLgzpbf3cW8ckzyxqluEbd4?= =?us-ascii?Q?OXWKnlJJBGFXH5+vDPnK2KrJiK3Pw0JeKj54MihL8Y0rGt77a5dNqnm9/wWO?= =?us-ascii?Q?S44a8pabjH9GwvpfphgFnqsFwCnsO2ESdE07GgUz/wTg9dMirFYoGeJat+rr?= =?us-ascii?Q?mV/6jKu/+xELmSN0t3rCWHSDpkdCaFoqzPVDXGHr/5oB+D+VJVxv7J5wpJVu?= =?us-ascii?Q?lcAJF1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x3OlNxhhPk/r0E+p5bx6iEnRZ+j6okyUnDlEAYqqe8=; 24:BbRJPtOPVuLPz+u2xoJt0q8O4G5rTkN0mPeeCoiOA/T49feqxNIYX8C0TqLpcF1aYxZy5+eFqgh7li44Ex+XXNfGeyz02ZCdqu6tAR38VTs=; 7:WBeV11AJEDCPSy1Uis3aYo1M9coadiVOYHMn5xCQjzP7dVhvynwHbgvxErNloSN2XI5fmjc8sNWEGjJjADOD2txPmQ4EcA3ZfojcWxFntZ4B00sWQgpfiPjBpB/kwP0C5q66iwzZo42HuJzsiiEW6ZotLP8w/S59E9OSpLwr02sM7ndku9/kT4f0yqquUXMZCQVslJYhymcBZi0HSHOJJcEoXq51afL1nV/fNIf5oXTUauXepIQlE9AM1yd01O/1 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN6PR1201MB0098; 20:TKcu14Giqqzifw3w1BX6/ernBp2z1/H2mdu7XVQM5yZzdb7HjZBdsAvFm1hyqj/0CNTgIZjlDAs7/DSF9nch68D8I4tOjvwaEF6Fuq+XLJoQ0RVTTh2VQ0KsYxOF3RnRZ831LdUBU+eGXuvnHaDvDdEtxL+8bD/6k6Lg5/jcL6o+RRuTvJCULkmew/RbS8ys+oPBpAbMvCjOQesC236V2mnpGjLf6204A2Kj+3ooK+Pw8yn7a2kMqCYseNVICXC/ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Nov 2017 14:57:40.0852 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 78b1a2fa-7996-4bfe-abb8-08d52aa6e350 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR1201MB0098 Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP On 11/13/2017 07:39 AM, Christian König wrote: > Am 13.11.2017 um 12:32 schrieb Michel Dänzer: >> On 12/11/17 10:35 AM, Christian König wrote: >>> A few comments on the code: >>> >>>> +/* Validate bo size is bit bigger then the request domain */ >>>> +static inline bool amdgpu_bo_validate_bo_size(struct amdgpu_device >>>> *adev, >>>> + unsigned long size, u32 domain) >>> Drop the inline keyword and the second _bo_ in the name here. >>> >>>> +{ >>>> + struct ttm_mem_type_manager *man = NULL; >>>> + >>>> + if (domain & AMDGPU_GEM_DOMAIN_VRAM) { >>>> + man = &adev->mman.bdev.man[TTM_PL_VRAM]; >>>> + >>>> + if (man && size < (man->size << PAGE_SHIFT)) >>> Drop the extra check that man is not NULL. We get the pointer to an >>> array element, that can't be NULL. >>> >>>> + return true; >>> Mhm, domain is a bitmask of allowed domains. >>> >>> So we should check all valid domains if the size fit, not just the >>> first >>> one. >> Assuming VRAM <-> system migration of BOs larger than the GTT domain >> works, I'd say we should only require that the BO can fit in any of the >> allowed domains. Otherwise it must also always fit in GTT. > Good point, and yes VRAM <-> system migration of BOs larger than the > GTT domain works now. > > I can agree on that VRAM should probably be optional, otherwise we > can't allocate anything large when the driver uses only very low > amounts of stolen VRAM on APUs. > > But I think when userspace requests VRAM and GTT at the same time we > still should be able to fall back to GTT. Attached V2 patch, I still don't understand why I experience the SIGSEV in the tester when the check fails and the IOCTLs will return ENOMEM I will update the libdrm test to correctly handle mem failure, it segfaults at the moment. Thanks, Andey > > Regards, > Christian. Reviewed-by: Christian König for this one, From 37369b3a58027dedf7e9dc65fd9bc0f9e86d0d80 Mon Sep 17 00:00:00 2001 From: Andrey Grodzovsky Date: Fri, 10 Nov 2017 18:35:56 -0500 Subject: drm/amdgpu: Implement BO size validation V2 Validates BO size against each requested domain's total memory. v2: Make GTT size check a MUST to allow fall back to GTT. Rmove redundant NULL check. Signed-off-by: Andrey Grodzovsky --- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c index a937c49..5acf20c 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c @@ -281,6 +281,44 @@ void amdgpu_bo_free_kernel(struct amdgpu_bo **bo, u64 *gpu_addr, *cpu_addr = NULL; } +/* Validate bo size is bit bigger then the request domain */ +static bool amdgpu_bo_validate_size(struct amdgpu_device *adev, + unsigned long size, u32 domain) +{ + struct ttm_mem_type_manager *man = NULL; + + /* + * If GTT is part of requested domains the check must succeed to + * allow fall back to GTT + */ + if (domain & AMDGPU_GEM_DOMAIN_GTT) { + man = &adev->mman.bdev.man[TTM_PL_TT]; + + if (size < (man->size << PAGE_SHIFT)) + return true; + else + goto fail; + } + + if (domain & AMDGPU_GEM_DOMAIN_VRAM) { + man = &adev->mman.bdev.man[TTM_PL_VRAM]; + + if (size < (man->size << PAGE_SHIFT)) + return true; + else + goto fail; + } + + + /* TODO add more domains checks, such as AMDGPU_GEM_DOMAIN_CPU */ + return true; + +fail: + DRM_ERROR("BO size %lu > total memory in domain: %llu\n", size, + man->size << PAGE_SHIFT); + return false; +} + static int amdgpu_bo_do_create(struct amdgpu_device *adev, unsigned long size, int byte_align, bool kernel, u32 domain, u64 flags, @@ -299,6 +337,9 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev, page_align = roundup(byte_align, PAGE_SIZE) >> PAGE_SHIFT; size = ALIGN(size, PAGE_SIZE); + if (!amdgpu_bo_validate_size(adev, size, domain)) + return -ENOMEM; + if (kernel) { type = ttm_bo_type_kernel; } else if (sg) { -- 2.7.4