From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 623FBC43613 for ; Mon, 24 Jun 2019 15:01:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3792420848 for ; Mon, 24 Jun 2019 15:01:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="KQ2654w6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729707AbfFXPBA (ORCPT ); Mon, 24 Jun 2019 11:01:00 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:44132 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728604AbfFXPBA (ORCPT ); Mon, 24 Jun 2019 11:01:00 -0400 Received: by mail-pf1-f196.google.com with SMTP id t16so7647997pfe.11 for ; Mon, 24 Jun 2019 08:00:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=ZH0KsEpqEXiZL11grL/nW8IzWOxozO/nFecO0TNWzZg=; b=KQ2654w6YgnMZs2At+Zd89XQIqIuYR8jlquNCWJJuIXpWD/HlSd4ZBjLxPQsxGeT2n QOBGSpQkVzrAWhjdNm3L175i3EwkQyprQmoxs6iyZjw9hV5O7BunNQVJJ3RYGgog4Rsr YQVv/8/84su3okC1IPWa+LhVmvUHm4bqUkhyE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=ZH0KsEpqEXiZL11grL/nW8IzWOxozO/nFecO0TNWzZg=; b=g8U78SPEwLRYi7s31rBm1HavUof95eOOv26MeyqrXTolKnvZmz/X7LLFeoSfD0Dymq fJoLeptRqHkOsm1qGSkNaHxfMoCvMt70BTQ0GKVnGNeDmvtXGBz1qfqwQWCiVR5xViVL C035dE+uFedcNDgveKVnhaYA9oojaD43K4vcyjoIZmHYGv5/HxUmcHq4PB0dmztnRi6M 9vrQyWJANrdD415pg8zYvomLs6at1iE70UAHrPpA9yj6yTXn+ORukQ0ohbSwZr3x7bcI 79x/arlTVgjOr0Jfw08y7ELkDoteLfeV9RNWZPiO98jzgcjpNcXHTCbLiGDAU9Xe/b9J 8GqQ== X-Gm-Message-State: APjAAAWnQBdR22kfLJaXo0FQRqBJqqFkVmhE0TrKOvmnHIeVoSB9rI8a cGp2mG7nEnUCAVNgexx8vW56RQ== X-Google-Smtp-Source: APXvYqyXA9qWckeMWJ1FYgTNxW3Kl/SaHQcwWPkv+8Ov9g+q8rZ/yCmpPgqZaQwQyexxau4NGmLb3Q== X-Received: by 2002:a17:90a:338b:: with SMTP id n11mr24999228pjb.21.1561388459522; Mon, 24 Jun 2019 08:00:59 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id e188sm1978374pfh.99.2019.06.24.08.00.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 24 Jun 2019 08:00:58 -0700 (PDT) Date: Mon, 24 Jun 2019 08:00:57 -0700 From: Kees Cook To: Andrey Konovalov Cc: 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, Catalin Marinas , Vincenzo Frascino , Will Deacon , Mark Rutland , Andrew Morton , Greg Kroah-Hartman , 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 Subject: Re: [PATCH v18 09/15] drm/amdgpu: untag user pointers Message-ID: <201906240800.5677E3CF@keescook> References: <1d036fc5bec4be059ee7f4f42bf7417dc44651dd.1561386715.git.andreyknvl@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1d036fc5bec4be059ee7f4f42bf7417dc44651dd.1561386715.git.andreyknvl@google.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Mon, Jun 24, 2019 at 04:32:54PM +0200, Andrey Konovalov wrote: > 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. > > Suggested-by: Felix Kuehling > Acked-by: Felix Kuehling > Signed-off-by: Andrey Konovalov Reviewed-by: Kees Cook -Kees > --- > 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 a6e5184d436c..5d476e9bbc43 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c > @@ -1108,7 +1108,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) { > domain = AMDGPU_GEM_DOMAIN_GTT; > alloc_domain = AMDGPU_GEM_DOMAIN_CPU; > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c > index d4fcf5475464..e91df1407618 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c > @@ -287,6 +287,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; > > -- > 2.22.0.410.gd8fdbe21b5-goog > -- Kees Cook