From patchwork Tue Jul 23 17:58:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11054883 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 2442913A4 for ; Tue, 23 Jul 2019 17:59:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 153EF286E0 for ; Tue, 23 Jul 2019 17:59:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 07CD3286F3; Tue, 23 Jul 2019 17:59:41 +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=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7DB3F286F1 for ; Tue, 23 Jul 2019 17:59:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6057F8E0010; Tue, 23 Jul 2019 13:59:39 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5BA6D8E0002; Tue, 23 Jul 2019 13:59:39 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4CD968E0010; Tue, 23 Jul 2019 13:59:39 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by kanga.kvack.org (Postfix) with ESMTP id 2C8728E0002 for ; Tue, 23 Jul 2019 13:59:39 -0400 (EDT) Received: by mail-qt1-f199.google.com with SMTP id l16so32413217qtq.16 for ; Tue, 23 Jul 2019 10:59:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=bNeVrTrPvpjyJWHVtXYqgQlj6F1/0IzkZ0bc3aEFST0=; b=HMh1vdF0jHcMrh5XLeZeiKYktf+hgRwMYmxYAzFFNwwxSZeGnJm40CnuiGdCgGDzL9 PXRFXHizS5HaRYeH6Viw2pOHMCf4AlRfhTmJXbkrLIyzKBKt4AYkAADVXPoKnuyXtB9n WwesP31ZUvPiS5lSPuEa2R/lP1ZK+olR0ZpqXt3NAv4q9bqilskfzbe+aOypRWhyEXwA /iM2s8r4LpNxxRbUmxZLsssvgXvm2YVtpDx3qmAInz4KWbvqrfKNkJ0rsop7oQsagt5J 9GazzCbFlK2IL9Y5jIooZIuo5XaUl7UzjdAWnlXmM9K7jzyp6GjuqjlsRg5xHhZSVzF+ HYcA== X-Gm-Message-State: APjAAAW7bEnlug6Qcc3UrWGpijkfMQoR8ZpUwuJKNxfVedoVwadL3gZZ Hxff16hT4qAXd9/1hqQHPAWrzXTeDKrh7wqAMblKzOa93U55jjKyaVbozjLtKe91V7rTOSFAvON qK92P+h2ZvvqXQASTRmr8K/xx/1xcz9FM08XOj14mbRIRaZHMYugH9pd3qag2+FggLg== X-Received: by 2002:a05:6214:3f0:: with SMTP id cf16mr55329580qvb.211.1563904778937; Tue, 23 Jul 2019 10:59:38 -0700 (PDT) X-Received: by 2002:a05:6214:3f0:: with SMTP id cf16mr55329537qvb.211.1563904775923; Tue, 23 Jul 2019 10:59:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563904775; cv=none; d=google.com; s=arc-20160816; b=OxBOB07l3F1Yexg4XRbuhvMQMr95YWCYMq9kuRcqX5x9HOQ7W3HjEoBGaOhprwtLXp +loN6SbEqie2WaBNe5MCNPX4HteW9r5B/X95+bBsW3ZWqNnUqrq40Z41lw9Gw3M2Sver gSH+f97Nxz7AofteS3Szbg5hWtAD3JupRmup93pZNf/DbKfyxfx1/H0NkYA0fEJGC2Yc 2iEIdKUQ7B/w96B7li+WdrCJfqbmUmSLSI/qfpuGZKwH3MU8OUlA7eFihjqe5Nms23mD V9WLrbJhJ8WC+b+Pc63ELlhpK4ufvRa16E6sA0Pi8ev95tOey730VV/3kuhS8C4jYvpO 7/MQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:dkim-signature; bh=bNeVrTrPvpjyJWHVtXYqgQlj6F1/0IzkZ0bc3aEFST0=; b=Yy4r+5mIbfo1nOySPyquxbb5Bi+Qd0sITHcgjA26tXkqZqvdhwIee7f3YGYYHrimRF 7wFxG+emj6ZUyGI5q8kp6EUG3ls5X0owAErIofChXgWaiOfId65jfJXNnFwAiu63WibV W2iQuzqNH8RZ5U7MCVALm/2PO7OxnpTXFkHhJD4UC+nGkN3dxijOSLgfU8fRxFNhbJah D8mbUBUVvSzPr/VTXe9UJ/367SqV6U1H8wpneA6UyjQdJjTmxOBNmvfnCfufP8k+gKsI vYm2gZz/ACwshAmNl5CTURx/hnbrim6UO5CjC+I6F+XbJQLHYSAbfcmUoDuD0pe1CNtw zyBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=uWaCwrDk; spf=pass (google.com: domain of 3b0s3xqokcgoivlzmgsvdtowwotm.kwutqvcf-uusdiks.wzo@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3B0s3XQoKCGoIVLZMgSVdTOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f73.google.com (mail-sor-f73.google.com. [209.85.220.73]) by mx.google.com with SMTPS id j8sor25114521qkl.7.2019.07.23.10.59.35 for (Google Transport Security); Tue, 23 Jul 2019 10:59:35 -0700 (PDT) Received-SPF: pass (google.com: domain of 3b0s3xqokcgoivlzmgsvdtowwotm.kwutqvcf-uusdiks.wzo@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) client-ip=209.85.220.73; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=uWaCwrDk; spf=pass (google.com: domain of 3b0s3xqokcgoivlzmgsvdtowwotm.kwutqvcf-uusdiks.wzo@flex--andreyknvl.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3B0s3XQoKCGoIVLZMgSVdTOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--andreyknvl.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=bNeVrTrPvpjyJWHVtXYqgQlj6F1/0IzkZ0bc3aEFST0=; b=uWaCwrDkBN5GRSLhaw7WQwMKcK3AhPqO/fzElVN3JcPy98UFLj7JeXsg8P+SLlr/8N uTaOa6VggUuncDHcvq/dm+VjbWoXQVCEMVj3yqEv0lzhkp6ZqhxIJZIXWJox0QqwZPpw oblQlXNCYt4tHVrvlJypYdteLVvehIkVLfAlFHjgdjHvnPpCAD6GJOEurxmklM0IOqwa r3we5GB8/FJKwWzwzqUCJtO6E9+uXUbwxjMkihzlNrMKNzLhjZggf+0ZB/LMAafHfS91 EJUlnCmBt8+isj3aFtdbAWI7Fy268Gzi52Ek2+IZaH/c0AJ5vAsChMY+9qCOx6dYD5bK 14lw== X-Google-Smtp-Source: APXvYqyRt/sslYOExeWvOFH4KfKnKxW+V8w8qG436u1Li2H+fm4BIS46hHRf2O8j3VSTAztC1lSBD2N1vfHNfs72 X-Received: by 2002:a05:620a:522:: with SMTP id h2mr54247961qkh.329.1563904775319; Tue, 23 Jul 2019 10:59:35 -0700 (PDT) Date: Tue, 23 Jul 2019 19:58:46 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.709.g102302147b-goog Subject: [PATCH v19 09/15] drm/amdgpu: untag user pointers From: Andrey Konovalov To: linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-rdma@vger.kernel.org, linux-media@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: Catalin Marinas , Vincenzo Frascino , Will Deacon , Mark Rutland , Andrew Morton , Greg Kroah-Hartman , Kees Cook , Yishai Hadas , Felix Kuehling , Alexander Deucher , Christian Koenig , Mauro Carvalho Chehab , Jens Wiklander , Alex Williamson , Leon Romanovsky , Luc Van Oostenryck , Dave Martin , Khalid Aziz , enh , Jason Gunthorpe , Christoph Hellwig , Dmitry Vyukov , Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Robin Murphy , Kevin Brodsky , Szabolcs Nagy , Andrey Konovalov X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This patch is a part of a series that extends kernel ABI to allow to pass tagged user pointers (with the top byte set to something else other than 0x00) as syscall arguments. In amdgpu_gem_userptr_ioctl() and amdgpu_amdkfd_gpuvm.c/init_user_pages() an MMU notifier is set up with a (tagged) userspace pointer. The untagged address should be used so that MMU notifiers for the untagged address get correctly matched up with the right BO. This patch untag user pointers in amdgpu_gem_userptr_ioctl() for the GEM case and in amdgpu_amdkfd_gpuvm_ alloc_memory_of_gpu() for the KFD case. This also makes sure that an untagged pointer is passed to amdgpu_ttm_tt_get_user_pages(), which uses it for vma lookups. Reviewed-by: Kees Cook Suggested-by: Felix Kuehling Acked-by: Felix Kuehling Signed-off-by: Andrey Konovalov --- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c index 1d3ee9c42f7e..00468ebf8b76 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c @@ -1103,7 +1103,7 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu( alloc_flags = 0; if (!offset || !*offset) return -EINVAL; - user_addr = *offset; + user_addr = untagged_addr(*offset); } else if (flags & (ALLOC_MEM_FLAGS_DOORBELL | ALLOC_MEM_FLAGS_MMIO_REMAP)) { domain = AMDGPU_GEM_DOMAIN_GTT; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c index 939f8305511b..d7855842fd51 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c @@ -291,6 +291,8 @@ int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data, uint32_t handle; int r; + args->addr = untagged_addr(args->addr); + if (offset_in_page(args->addr | args->size)) return -EINVAL;