From patchwork Thu May 26 09:43:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oded Gabbay X-Patchwork-Id: 9136877 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 B98D0607D5 for ; Thu, 26 May 2016 09:44:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A95C725EF7 for ; Thu, 26 May 2016 09:44:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9DBF6280E5; Thu, 26 May 2016 09:44:07 +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=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 92E7D25EF7 for ; Thu, 26 May 2016 09:44:06 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E05836EA73; Thu, 26 May 2016 09:44:04 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4671B6EA72 for ; Thu, 26 May 2016 09:44:03 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id q62so3570047wmg.3 for ; Thu, 26 May 2016 02:44:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id; bh=8UvF5A/kTkbkh97R9AaidIimBTOncsDx6gKQxjt9/FA=; b=LjzIpmyIhcSTgY3NlYyR/RTc23HeDsBVsnifh8m8gmVOTFdhnQuoWyOlP7wUpmVvX+ oIQY4oXmtfsBbg/30fndkCQHgez5J0eOK3B9bri4OaG2N0S0xOHdN7i3zUQ2uxWZJTZc N43pPWKThHpiQRKGTNq+ASxYUC2Oht7UYqgW6623aKJCyL4NyEwsAP/qxsE1D/4vGQg+ GQyps5Lh17DJLGksNUjDKFYbLowdwT2WULE05L3Xi0/NUa9vYfwT82aIhI5QaXpWBYsW DMREMikhGaQEO5ZJ5051W5m6JyQs04l0iYjVwHw2m+IMKXr3MVcXZFI+14+kzOazGBOW zaqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=8UvF5A/kTkbkh97R9AaidIimBTOncsDx6gKQxjt9/FA=; b=lwH/uUaO36TmbTLkKvNpp0WigD2H+s6rBfYJmD1GSdUrDdrnCcJKVkVL6qJTVlLGg4 t06RcyCfv1VGFB2Yu8GwHY2CA2+q0sfucHWJ7pAmtF6Za+pOwRsQiBKtmlWZ7JndywOI hX56C/s6bk50WdKv35SnVwt2aUCGPvWWaIUs59CrFM6vLhE5NQeFMkF4KYWQc6CDVJgF /0ndKgKqQLjiX5xr03Xjv6GUvpH4GuujyI7mRBRbcPyIpWuD+rbe+Gg+cDDZdz40on59 ZkpQZX6oDh+hBwd1/sZYRgCd9oBTnsaBGRW1+EnCAEE4AL1mLdprQJBUpSzOTAEw6usQ fBig== X-Gm-Message-State: ALyK8tK3FqfhzbAXxwPd6zkJdRUi9Iixh0TvDYWEZ7Juf+ASlStFhluCEVAK4/tlehKUmQ== X-Received: by 10.28.136.84 with SMTP id k81mr2829872wmd.27.1464255841451; Thu, 26 May 2016 02:44:01 -0700 (PDT) Received: from odedg-tlv.redhat.com ([77.125.96.241]) by smtp.gmail.com with ESMTPSA id kz1sm13370868wjc.46.2016.05.26.02.44.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 May 2016 02:44:00 -0700 (PDT) From: Oded Gabbay To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/2] drm/amdkfd: unbind only existing processes Date: Thu, 26 May 2016 12:43:58 +0300 Message-Id: <1464255839-5205-1-git-send-email-oded.gabbay@gmail.com> X-Mailer: git-send-email 2.5.5 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: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP When unbinding a process from a device (initiated by amd_iommu_v2), the driver needs to make sure that process still exists in the process table. There is a possibility that amdkfd's own notifier handler - kfd_process_notifier_release() - was called before the unbind function and it already removed the process from the process table. Signed-off-by: Oded Gabbay --- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c index ac00579..248deb7 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c @@ -405,11 +405,17 @@ void kfd_unbind_process_from_device(struct kfd_dev *dev, unsigned int pasid) idx = srcu_read_lock(&kfd_processes_srcu); hash_for_each_rcu(kfd_processes_table, i, p, kfd_processes) - if (p->pasid == pasid) + if ((!p) || (p->pasid == pasid)) break; srcu_read_unlock(&kfd_processes_srcu, idx); + /* check if have a process in the hash. Maybe the relevant process was + * already erased in kfd_process_notifier_release() + */ + if (!p) + return; + BUG_ON(p->pasid != pasid); mutex_lock(&p->mutex);