From nobody Tue Feb 10 20:07:23 2026 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1572293576; cv=none; d=zoho.com; s=zohoarc; b=JrU1gPXMGBdXgeKSGfnLFQNbrIhIk6kxy7C7EJBPZdViKRK/X/xls0Z13Ol7VQTK0ZdPIIOkgE8ZH1jK/uNB16bH7CVZJoEzi/qKfZwhafDQ4p6wQGDatFFQWLA3YVB/2IAAwha8ZpfCetr8Ei9YaeVVWAaJLiqbw9G7e3tTkNk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572293576; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=+DigfnXNweQhFVpUjCvVSaU3VJR5nTbUbw1Bz5ttXk0=; b=NC5ZdshKs3eWsT1Yg0ddQQeFkrXe6JssmK8SQXJQQFYVsMZMGXze1hHI7HXksPtW4slez5NZ/BhwPKj8H6slD7jBex2N/xTbYtJq2GQq+is1t86F4ErrGAx7t35dQxyLUyo53z33ElhT3ISKSkQPSzJ/ni7VsQSMmd59fbondl0= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1572293576310616.7789490173969; Mon, 28 Oct 2019 13:12:56 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iPBMm-000210-61; Mon, 28 Oct 2019 20:11:52 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iPBMk-0001zt-PO for xen-devel@lists.xenproject.org; Mon, 28 Oct 2019 20:11:50 +0000 Received: from mail-qt1-x842.google.com (unknown [2607:f8b0:4864:20::842]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 09c76ed0-f9bf-11e9-8aca-bc764e2007e4; Mon, 28 Oct 2019 20:10:51 +0000 (UTC) Received: by mail-qt1-x842.google.com with SMTP id e14so16574672qto.1 for ; Mon, 28 Oct 2019 13:10:51 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-142-162-113-180.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.162.113.180]) by smtp.gmail.com with ESMTPSA id y33sm10527481qta.18.2019.10.28.13.10.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Oct 2019 13:10:48 -0700 (PDT) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1iPBLf-0001h9-Ir; Mon, 28 Oct 2019 17:10:43 -0300 X-Inumbo-ID: 09c76ed0-f9bf-11e9-8aca-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=F2P8/bWutEEexpXtgY3Ri54G2hYwzd51MYRSkoxVUFY=; b=f9VJ69PD3RaUkbEbccVYeRFDh/thjTQCzF5PuJ+gvt+IG6OkssL4Za0EKWGJI3j+0E HLSRRQqMXLrz5Gxqj9/Q7HBPvcvH4eX8f81f9tWwJzMf/Kvz1p+RSsKPa8Aqw6sRhOF1 Ci6tCvrYka+pGRB45g/D9/kkwjGtIvI70tHdkxrH/C2yY97y+krIusL/sDyIaNisQg6v qVOhr1RtmNaMOuz4sPbCR/gy0XgHfVy8Z38tgeJWChrZRpsSaK+vcI6dRNWyH4tJvL8A b5RnhHZBFnkXiK2WV1K4WPo4s9VnYg1eiHNZQ2qUzq0o8pj/0x8HMVMYPMRl0Q10ejMR z6Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=F2P8/bWutEEexpXtgY3Ri54G2hYwzd51MYRSkoxVUFY=; b=IPgcx4bS4tQcgZh3omwxpq5D8Iwn/CcRPyu8LuuvaQRKmZIB6jnwTU8PxQh4QCz1Lf EKdFUeKMzfRi4ESY3iLXgRb6mJnu4WeGVTQCblbsWMY8gksrdmqeW5eypsIJXB/SrLC0 ViZVF1jANeDCBE4WycN5p8XQIdtkNItwWWTQFMhcirRghPTc7kHI6X4mdyQ8fNCCo/8F DIeEHei97AJ19wNINT/9jKcE/PkBbWYvLbHWDCZMP4q7aMCWlM2yYsioFnHq4Ve7pd3p VUeMhy7TVJ8kg5dwBhxHTdVvVqxwn3Oz7o5PS3gbw8L62VIG24Ecmb1v+IHpvvHibzwe xBHQ== X-Gm-Message-State: APjAAAWGWrQn8azywwXEA9Sgz/aBb+SeAMWLxN0GO1j8Q6LIGaoK/zem 1ikSgP1uhu1SE8rIjTGckRTshg== X-Google-Smtp-Source: APXvYqwTcskfH9Xiak0a57YVk8h4p5RuEjqynPFL5VtkKYVgvqVrkyouZ1IxJ09RUdRPaJJt1AiVUg== X-Received: by 2002:ac8:6783:: with SMTP id b3mr300845qtp.25.1572293450670; Mon, 28 Oct 2019 13:10:50 -0700 (PDT) From: Jason Gunthorpe To: linux-mm@kvack.org, Jerome Glisse , Ralph Campbell , John Hubbard , Felix.Kuehling@amd.com Date: Mon, 28 Oct 2019 17:10:29 -0300 Message-Id: <20191028201032.6352-13-jgg@ziepe.ca> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191028201032.6352-1-jgg@ziepe.ca> References: <20191028201032.6352-1-jgg@ziepe.ca> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 12/15] drm/amdgpu: Call find_vma under mmap_sem X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , David Zhou , Mike Marciniszyn , Stefano Stabellini , Oleksandr Andrushchenko , linux-rdma@vger.kernel.org, nouveau@lists.freedesktop.org, Dennis Dalessandro , amd-gfx@lists.freedesktop.org, Christoph Hellwig , Jason Gunthorpe , dri-devel@lists.freedesktop.org, Alex Deucher , xen-devel@lists.xenproject.org, Boris Ostrovsky , Petr Cvek , =?UTF-8?q?Christian=20K=C3=B6nig?= , Ben Skeggs Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Jason Gunthorpe find_vma() must be called under the mmap_sem, reorganize this code to do the vma check after entering the lock. Further, fix the unlocked use of struct task_struct's mm, instead use the mm from hmm_mirror which has an active mm_grab. Also the mm_grab must be converted to a mm_get before acquiring mmap_sem or calling find_vma(). Fixes: 66c45500bfdc ("drm/amdgpu: use new HMM APIs and helpers") Fixes: 0919195f2b0d ("drm/amdgpu: Enable amdgpu_ttm_tt_get_user_pages in wo= rker threads") Cc: Alex Deucher Cc: Christian K=C3=B6nig Cc: David (ChunMing) Zhou Cc: amd-gfx@lists.freedesktop.org Signed-off-by: Jason Gunthorpe Acked-by: Christian K=C3=B6nig Reviewed-by: Felix Kuehling --- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 37 ++++++++++++++----------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/= amdgpu/amdgpu_ttm.c index dff41d0a85fe96..c0e41f1f0c2365 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -788,7 +789,7 @@ int amdgpu_ttm_tt_get_user_pages(struct amdgpu_bo *bo, = struct page **pages) struct hmm_mirror *mirror =3D bo->mn ? &bo->mn->mirror : NULL; struct ttm_tt *ttm =3D bo->tbo.ttm; struct amdgpu_ttm_tt *gtt =3D (void *)ttm; - struct mm_struct *mm =3D gtt->usertask->mm; + struct mm_struct *mm; unsigned long start =3D gtt->userptr; struct vm_area_struct *vma; struct hmm_range *range; @@ -796,25 +797,14 @@ int amdgpu_ttm_tt_get_user_pages(struct amdgpu_bo *bo= , struct page **pages) uint64_t *pfns; int r =3D 0; =20 - if (!mm) /* Happens during process shutdown */ - return -ESRCH; - if (unlikely(!mirror)) { DRM_DEBUG_DRIVER("Failed to get hmm_mirror\n"); - r =3D -EFAULT; - goto out; + return -EFAULT; } =20 - vma =3D find_vma(mm, start); - if (unlikely(!vma || start < vma->vm_start)) { - r =3D -EFAULT; - goto out; - } - if (unlikely((gtt->userflags & AMDGPU_GEM_USERPTR_ANONONLY) && - vma->vm_file)) { - r =3D -EPERM; - goto out; - } + mm =3D mirror->hmm->mmu_notifier.mm; + if (!mmget_not_zero(mm)) /* Happens during process shutdown */ + return -ESRCH; =20 range =3D kzalloc(sizeof(*range), GFP_KERNEL); if (unlikely(!range)) { @@ -847,6 +837,17 @@ int amdgpu_ttm_tt_get_user_pages(struct amdgpu_bo *bo,= struct page **pages) hmm_range_wait_until_valid(range, HMM_RANGE_DEFAULT_TIMEOUT); =20 down_read(&mm->mmap_sem); + vma =3D find_vma(mm, start); + if (unlikely(!vma || start < vma->vm_start)) { + r =3D -EFAULT; + goto out_unlock; + } + if (unlikely((gtt->userflags & AMDGPU_GEM_USERPTR_ANONONLY) && + vma->vm_file)) { + r =3D -EPERM; + goto out_unlock; + } + r =3D hmm_range_fault(range, 0); up_read(&mm->mmap_sem); =20 @@ -865,15 +866,19 @@ int amdgpu_ttm_tt_get_user_pages(struct amdgpu_bo *bo= , struct page **pages) } =20 gtt->range =3D range; + mmput(mm); =20 return 0; =20 +out_unlock: + up_read(&mm->mmap_sem); out_free_pfns: hmm_range_unregister(range); kvfree(pfns); out_free_ranges: kfree(range); out: + mmput(mm); return r; } =20 --=20 2.23.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel