Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1035282AbdD1IwR (ORCPT ); Fri, 28 Apr 2017 04:52:17 -0400 Received: from mail-dm3nam03on0066.outbound.protection.outlook.com ([104.47.41.66]:29984 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1424796AbdD1IbF (ORCPT ); Fri, 28 Apr 2017 04:31:05 -0400 Authentication-Results: lists.freedesktop.org; dkim=none (message not signed) header.d=none;lists.freedesktop.org; dmarc=none action=none header.from=amd.com; Subject: Re: [RFC] drm/amd/amdgpu: get rid of else branch To: Nikola Pajkovsky , References: CC: Alex Deucher , David Airlie , , =?UTF-8?Q?Christian_K=c3=b6nig?= , From: =?UTF-8?Q?Christian_K=c3=b6nig?= Message-ID: <6ce3044b-9473-94eb-e54c-e8e856f1c88f@amd.com> Date: Fri, 28 Apr 2017 10:30:49 +0200 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: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [2a02:908:1251:7981:38ad:ec37:c713:177b] X-ClientProxiedBy: HE1PR09CA0090.eurprd09.prod.outlook.com (10.174.50.162) To CY4PR12MB1301.namprd12.prod.outlook.com (10.168.168.138) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6a107a2f-d6d0-4f40-7155-08d48e10e873 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(48565401081)(201703131423075)(201703031133081);SRVR:CY4PR12MB1301; X-Microsoft-Exchange-Diagnostics: 1;CY4PR12MB1301;3:XEPY1jdOwQD+1U6TGukzD5v8TI4byV6WfVRLSaxDCWXpZMpVXp+RHz2S+UuCtmaMNzbI/XtHQzlz4BP0MIGE7uA1etKg08t0va2SswbZjx2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HPcGlIQYaf4EODyig0HTZEyb/XBYOk600yPOq315F56HvDzY+fLtYo/yqjk2nAyLmsXrHZ/dNUtQb/MKTZ+1clYuhlROpvkwkO7qd34gF+V8ije87ty227wIdm96kjloaBn38LLYmURg802vwUfPS07Tn97bAMvfcKQplLDF1vFjSie0zW1TB0FSSFVHjSsOUXc4OBnN1uFAoILkAMODZ+t1NJrLPRojOzdZtl9S1RBUxv8sg8zZNzgWWOvz+nh7jw9aCLLMyowwdtljgRuKrVRTSmSEPFLJkAq2nynEpgnBTGbMjhOaLka6zTyBhk/QqP/59mUhssl/92xJnrbtXy6WeBhOJySDj3sPIAsS5uDgDvPR0B5NVP3M6HyU5YqujDYMv5WVSw79W0RetG0ermqlTRdA3m+kSzUOIeEuvRTnLT1momUysNXy3ZxS6k/fgBo9fZR96SwDlqkz X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040450)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(93006095)(93001095)(6055026)(6041248)(20161123555025)(20161123560025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(20161123562025)(6072148);SRVR:CY4PR12MB1301;BCL:0;PCL:0;RULEID:;SRVR:CY4PR12MB1301; X-Microsoft-Exchange-Diagnostics: 1;CY4PR12MB1301;4:/gWLevgoD+rc3loYAwmqklSrWN5hYwgIr+c0x2WL/Z1NX3k2cS5TaUJJRsMd5yD2jCT2YGrqyBxk+eIWAcjZMzeWc6w2YFRXtS6OO5cdxflrBLDUD+fYEoRL4ElcwwHip2G5kxTkBd879xFbvHuyyCTu1AE9wrd0KSEciMoXE9iqN9KqWEgJlKjue0623lGGbZhi1KGuIk0ObrtcgeNn3e5koEo+hRejt44NJih5rlBzDZfiTnpSC5Etp1+Z/8dlUmB+0QUUwNahGnSfcb/CWp5u1HR+B8Ye3ae3IoTe2IgXjVQgGyBMwqTr7kDkNCl8SgPZkIoNAY7BwgYor34PZpDrugkKXA06XuIy63LMW2GbtZLv90cUCmFQx00qUK2dOzTnC7Upt2pOk2CPN/xL6lRoGm5u/8+hlJTJQzHPILKyGymnmJotkeaSdGqb1xujGh9L0IcyaixcUpyrzLpmFgrEdeumEOc/LLYS2HPRZxdy6UePMBNOuVDNR7ZCQnaKQ38+MTYuMsvXArnG6euAYMqTBMs8Ce7NLQzVIBAnFlu5iOpusYqy5VPUAmqHWgTdR2mH+4e3UmzZtIU79iDl1EmSwtA5URGG1IGeDea17OKHkTvLxP4PKR6i52SPkFOusOJT5kUz/3apFTszpEsnjQjeshYIA35o3FMgybcdNkMDOsA7Py+WUyhra513uTr6qly2YXaWcWjjFgkhRWDAnhDZ+yz0iSDRhS4ccCVQG/U= X-Forefront-PRVS: 029174C036 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6009001)(39860400002)(39840400002)(39450400003)(39410400002)(39850400002)(39400400002)(189998001)(31696002)(6116002)(33646002)(47776003)(5660300001)(76176999)(4001350100001)(50986999)(86362001)(2906002)(65956001)(42186005)(54356999)(229853002)(2950100002)(25786009)(6486002)(36756003)(7736002)(305945005)(65826007)(83506001)(6666003)(6246003)(53936002)(50466002)(8676002)(38730400002)(81166006)(54906002)(230700001)(4326008)(23676002);DIR:OUT;SFP:1101;SCL:1;SRVR:CY4PR12MB1301;H:[IPv6:2a02:908:1251:7981:38ad:ec37:c713:177b];FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtDWTRQUjEyTUIxMzAxOzIzOlcreCsrVTJyYS85Rm5hS2JPUHZyMmRhRVIy?= =?utf-8?B?cXllVWpqb2Mya0xpN3U2ZFI5YWxVYXJqTWQ0eDE5NHJRZmNveHVLczRQMUxn?= =?utf-8?B?a1NmRHAvNHZZeEszVHBjKzhsdW03anEyWDRwc2FNaHp2K0FkRmxNZ3ZsTTda?= =?utf-8?B?NE5RNXFKWEVYR3VOR09UajlWbkhoRHlRaH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yCGHUcng7uLcOm+8p03nFJItEldvxBfGb7jwtGaUKT+zyEDAHAgIbz1iUOXraTYtO9thS7noPROFKgGsEa2sjEbTT8t0jYP/7JF6eJt9vriO4X/j59A==;24:h0XjPaIaC34TWgUVuoc2cFfKB8kNxZOTiuxbW0GEr6Oq8IGDo7gcX8WUPQPCO/Gj1vcyfJNTP38KLIYfU5B+IMjbUVBpFZPnTb7P5dFrmTg= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;CY4PR12MB1301;7:4+zzC19ezlBe2U+NC5cnauZ3sFG5tYrTfOMGSDLbIKP4izsx+7Qo42FkqjJqNgolM++zHlTp+MaDYRdzt8VzDLIbjz1EFAtdbD5I61LhZpYKvauunI3pHVZE8/dED9gq7+PXDv9s/Zbxr6D9GQvBBeDgd6I2XjAnIJJZnNxmbvGorsDn47xPZU2O74UqVWpA6jMuz/s34lsAHDnYMPC7hf8nGb4bw/q2ZhvTGt2wj+IK5zju4/IDz+n50q8HJfk4cwf3Gl9h+OvbUkbWyOgrl8rnrk9DjIP0sPOeQt2qA4FuzoY3Bn4kyx6Z3kMh42q3xaR61ciNbBWTYCbmdpErxQ==;20:STh/wPPJacvLFg30itmSqCIjlkvRCkDsAn/W85YVw3nGwBtJbG4it5wwtmmS9IFjfYowPFUNTX4AtQOD9Z0rWZt0SUlga7BNdyDzL1O8/Iw//7qzMS74geYK6VrXhJJKwFboLnzb/bj/hR+Mzm0m+QuMer7dgLLcQV/rORX9z5JSec8nGO0aXE9x+TPdEw4Ny2wD50thiPAYCe5RAxPsQCgL5OgI4TeQXnzebdrojI4COOibj1sfrQUy2j6IOrF3 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Apr 2017 08:31:01.6796 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1301 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2852 Lines: 92 Am 27.04.2017 um 18:17 schrieb Nikola Pajkovsky: > This is super simple elimination of else branch and I should > probably even use unlikely in > > if (ring->count_dw < count_dw) { > > However, amdgpu_ring_write() has similar if condition, but does not > return after DRM_ERROR and it looks suspicious. On error, we still > adding v to ring and keeping count_dw-- below zero. > > if (ring->count_dw <= 0) > DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n"); > ring->ring[ring->wptr++] = v; > ring->wptr &= ring->ptr_mask; > ring->count_dw--; > > I can obviously be totaly wrong. Hmm? That's just choosing the lesser evil. When we write more DW to the ring than expected it is possible (but not likely) that we override stuff on the ring buffer which is still executed by the command processor leading to a possible CP crash. But when we completely drop the write the commands in the ring buffer will certainly be invalid and so the CP will certainly crash sooner or later. Please add the unlikely() as well and then send out the patch with a signed-of-by line and I will be happy to push it into our upstream branch. Regards, Christian. > > --------8<--------8<--------8<--------8<--------8<--------8<--------8<--------8<--------8< > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h > index c1b913541739..c6f4f874ea68 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h > @@ -1596,28 +1596,29 @@ static inline void amdgpu_ring_write_multiple(struct amdgpu_ring *ring, void *sr > > if (ring->count_dw < count_dw) { > DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n"); > - } else { > - occupied = ring->wptr & ring->ptr_mask; > - dst = (void *)&ring->ring[occupied]; > - chunk1 = ring->ptr_mask + 1 - occupied; > - chunk1 = (chunk1 >= count_dw) ? count_dw: chunk1; > - chunk2 = count_dw - chunk1; > - chunk1 <<= 2; > - chunk2 <<= 2; > - > - if (chunk1) > - memcpy(dst, src, chunk1); > - > - if (chunk2) { > - src += chunk1; > - dst = (void *)ring->ring; > - memcpy(dst, src, chunk2); > - } > - > - ring->wptr += count_dw; > - ring->wptr &= ring->ptr_mask; > - ring->count_dw -= count_dw; > + return; > } > + > + occupied = ring->wptr & ring->ptr_mask; > + dst = (void *)&ring->ring[occupied]; > + chunk1 = ring->ptr_mask + 1 - occupied; > + chunk1 = (chunk1 >= count_dw) ? count_dw: chunk1; > + chunk2 = count_dw - chunk1; > + chunk1 <<= 2; > + chunk2 <<= 2; > + > + if (chunk1) > + memcpy(dst, src, chunk1); > + > + if (chunk2) { > + src += chunk1; > + dst = (void *)ring->ring; > + memcpy(dst, src, chunk2); > + } > + > + ring->wptr += count_dw; > + ring->wptr &= ring->ptr_mask; > + ring->count_dw -= count_dw; > } > > static inline struct amdgpu_sdma_instance *