Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp597831ybl; Wed, 11 Dec 2019 04:39:42 -0800 (PST) X-Google-Smtp-Source: APXvYqzQQIgkxh+09V9K2yIIKpVDbj32ngrOpcJS2RAlNVx69eXKmhqx93A3h8TZCDnUqZEFgvSY X-Received: by 2002:a05:6830:18cd:: with SMTP id v13mr2052973ote.118.1576067982355; Wed, 11 Dec 2019 04:39:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576067982; cv=none; d=google.com; s=arc-20160816; b=wlDyl6+ZDdFhfNgeicKWW5NVoMalI/GkRCEwJ2UnRK22njKyoOA9jN+yzEXl/U+DfZ /w17Af7EMkOm0Tqt1vp9Wghxq2usBP6BMlP9gMeQaj/FHvhrosMV3isjrPaiBWPouvCC 16g1PPFvOmIDBd/6vpZPBrvJ/oVeS01wNmHt6sDXJzFfigB9ukyPlzLKBZlaDdeTccWb arSHCZde0Xv8sRe217LBO6r2bZThr9/DCo7p11/iLUXXErHFSbXlXNQJ2O/ExlvCRZUA sHTkq5khjGkjR9x6SwVYb0wvlCbNvnAK2Nsi0POEbcJApz0fbFgsuYm7qWvmZb79oP+m NRoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:mail-followup-to :message-id:subject:cc:to:from:date:dkim-signature; bh=oilqMrWOmUSWqLKTGEJQYVnIb6Khy8rZQCIwVkV2EgI=; b=VAnkEJhB9Obpdh5Q+IW6uYrpSHDzWOUyqlBHz3XiSxS/x/6gBGlTdCkY9Nbzvou1uf j6owsHBxml7VUB8NswmF+MnEwzuFlW7mlIpXLO/R6vWBurR52zFqT24wxr2NdKaHFwac ln7pkgnKo7DPicwfAjfmw338MEL37sk5Hw4+A+2xHsMF1fK/jT3f/PLO8mAbPdEKwdRy +c5Ou5186TRIyxvuOQUgxIUbgBXdyyiMQqB3PydJbYtUGktzM1f1XsqXSYbTC0nK64pp Zc0w6k+0Gxfs90VcAIjOb7x3ncXhcrfKwLqmfKDof8Me4hCDNdhLq8C26GVXV535+A9O kFIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=KJqVnq80; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 10si1030208oin.212.2019.12.11.04.39.30; Wed, 11 Dec 2019 04:39:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=KJqVnq80; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729222AbfLKMik (ORCPT + 99 others); Wed, 11 Dec 2019 07:38:40 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:41053 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727493AbfLKMik (ORCPT ); Wed, 11 Dec 2019 07:38:40 -0500 Received: by mail-wr1-f68.google.com with SMTP id c9so23874529wrw.8 for ; Wed, 11 Dec 2019 04:38:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=oilqMrWOmUSWqLKTGEJQYVnIb6Khy8rZQCIwVkV2EgI=; b=KJqVnq80OYD3nHpLiKB4RCWguQxg3gbAVtmRJIBQyahJ2cRtyqyDo24gpCh3PvkZOx 6a8X1IW2qjx02ByMsUMiXPy8XLnFUMVkQWttRFIURRebr1Gin1WWVnxvmX3RkhXVr8NA u+L8IgnOyLqjKoBcQNBX5FpGthRxI5USPeFLw= 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 :mail-followup-to:references:mime-version:content-disposition :in-reply-to:user-agent; bh=oilqMrWOmUSWqLKTGEJQYVnIb6Khy8rZQCIwVkV2EgI=; b=QWCUUGOIgbeE2PDV/LcQMFRjilzvT3Qgvg4I/XB8RgnXcV1K8DJkIQ8QUUeE4JPQn6 D985adp8Ov771G4OYG3ZqSyX36HqrvCUyJ9vs4mCqmyaZvUKh6ZJOafU/YgCJwBQlKf/ WphJvtsEWVdeUZsSF3RYXmVhOKi8KVMUUz4rleuagituWS8SIIwgmxNVJ6SZRQLOYPGF jVnljvO/Xiijxz2L3WKKYTcrUTWchKIdJ8NXPcY80axrQhf3TvMTrcvQPfxnhvtMs37Z vJ8VAwZZzdKZp1L1WoV7nINwmqhFKFH0Zg7vGn495lszpHglDD7wjkky6LKGKfhUKYT4 l8nA== X-Gm-Message-State: APjAAAUr/0FrwmOFaAG1VpEECFvGSX0m472hfo9qXuYD357TERkg1ttX 3HuK36fsNWJ0fXc9JfEB9t+G2gG/mZs= X-Received: by 2002:adf:dc8d:: with SMTP id r13mr3767933wrj.357.1576067917745; Wed, 11 Dec 2019 04:38:37 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:564b:0:7567:bb67:3d7f:f863]) by smtp.gmail.com with ESMTPSA id n12sm2200963wmd.1.2019.12.11.04.38.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2019 04:38:37 -0800 (PST) Date: Wed, 11 Dec 2019 13:38:35 +0100 From: Daniel Vetter To: Gerd Hoffmann Cc: dri-devel@lists.freedesktop.org, tzimmermann@suse.de, gurchetansingh@chromium.org, Maarten Lankhorst , Maxime Ripard , David Airlie , Daniel Vetter , open list Subject: Re: [PATCH v3 1/4] drm: add pgprot callback to drm_gem_object_funcs Message-ID: <20191211123835.GZ624164@phenom.ffwll.local> Mail-Followup-To: Gerd Hoffmann , dri-devel@lists.freedesktop.org, tzimmermann@suse.de, gurchetansingh@chromium.org, Maarten Lankhorst , Maxime Ripard , David Airlie , open list References: <20191211121957.18637-1-kraxel@redhat.com> <20191211121957.18637-2-kraxel@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191211121957.18637-2-kraxel@redhat.com> X-Operating-System: Linux phenom 5.3.0-2-amd64 User-Agent: Mutt/1.12.2 (2019-09-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Dec 11, 2019 at 01:19:53PM +0100, Gerd Hoffmann wrote: > The callback allows drivers and helpers to tweak pgprot for mappings. > This is especially helpful when using shmem helpers. It allows drivers > to switch mappings from writecombine (default) to something else (cached > for example) on a per-object base without having to supply their own > mmap() and vmap() functions. > > The patch also adds two implementations for the callback, for cached and > writecombine mappings, and the drm_gem_pgprot() function to update > pgprot for a given object, using the new &drm_gem_object_funcs.pgprot > callback if available. > > Signed-off-by: Gerd Hoffmann > --- > include/drm/drm_gem.h | 15 +++++++++++++ > drivers/gpu/drm/drm_gem.c | 46 ++++++++++++++++++++++++++++++++++++++- > 2 files changed, 60 insertions(+), 1 deletion(-) > > diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h > index 0b375069cd48..5beef7226e69 100644 > --- a/include/drm/drm_gem.h > +++ b/include/drm/drm_gem.h > @@ -163,6 +163,17 @@ struct drm_gem_object_funcs { > */ > int (*mmap)(struct drm_gem_object *obj, struct vm_area_struct *vma); > > + /** > + * @pgprot: > + * > + * Tweak pgprot as needed, typically used to set cache bits. > + * > + * This callback is optional. > + * > + * If unset drm_gem_pgprot_wc() will be used. > + */ > + pgprot_t (*pgprot)(struct drm_gem_object *obj, pgprot_t prot); I kinda prefer v1, mostly because this is a huge can of worms, and solving this properly is going to be real hard (and will necessarily involve dma-buf and dma-api and probably more). Charging ahead here just risks that we dig ourselves into a corner. You're v1 is maybe not the most clean, but just a few code bits here&there should be more flexible and easier to hack on and experiment around with. -Daniel > + > /** > * @vm_ops: > * > @@ -350,6 +361,10 @@ int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size, > struct vm_area_struct *vma); > int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma); > > +pgprot_t drm_gem_pgprot_cached(struct drm_gem_object *obj, pgprot_t prot); > +pgprot_t drm_gem_pgprot_wc(struct drm_gem_object *obj, pgprot_t prot); > +pgprot_t drm_gem_pgprot(struct drm_gem_object *obj, pgprot_t prot); > + > /** > * drm_gem_object_get - acquire a GEM buffer object reference > * @obj: GEM buffer object > diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c > index 56f42e0f2584..1c468fe8e342 100644 > --- a/drivers/gpu/drm/drm_gem.c > +++ b/drivers/gpu/drm/drm_gem.c > @@ -1119,7 +1119,8 @@ int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size, > return -EINVAL; > > vma->vm_flags |= VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP; > - vma->vm_page_prot = pgprot_writecombine(vm_get_page_prot(vma->vm_flags)); > + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); > + vma->vm_page_prot = drm_gem_pgprot(obj, vma->vm_page_prot); > vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot); > } > > @@ -1210,6 +1211,49 @@ int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma) > } > EXPORT_SYMBOL(drm_gem_mmap); > > +/** > + * drm_gem_mmap - update pgprot for objects needing a cachable mapping. > + * @obj: the GEM object. > + * @prot: page attributes. > + * > + * This function can be used as &drm_gem_object_funcs.pgprot callback. > + */ > +pgprot_t drm_gem_pgprot_cached(struct drm_gem_object *obj, pgprot_t prot) > +{ > + return prot; > +} > +EXPORT_SYMBOL(drm_gem_pgprot_cached); > + > +/** > + * drm_gem_mmap - update pgprot for objects needing a wc mapping. > + * @obj: the GEM object. > + * @prot: page attributes. > + * > + * This function can be used as &drm_gem_object_funcs.pgprot callback. > + */ > +pgprot_t drm_gem_pgprot_wc(struct drm_gem_object *obj, pgprot_t prot) > +{ > + return pgprot_writecombine(prot); > +} > +EXPORT_SYMBOL(drm_gem_pgprot_wc); > + > +/** > + * drm_gem_mmap - update pgprot for a given gem object. > + * @obj: the GEM object. > + * @prot: page attributes. > + * > + * This function updates pgprot according to the needs of the given > + * object. If present &drm_gem_object_funcs.pgprot callback will be > + * used, otherwise drm_gem_pgprot_wc() is called. > + */ > +pgprot_t drm_gem_pgprot(struct drm_gem_object *obj, pgprot_t prot) > +{ > + if (obj->funcs->pgprot) > + return obj->funcs->pgprot(obj, prot); > + return drm_gem_pgprot_wc(obj, prot); > +} > +EXPORT_SYMBOL(drm_gem_pgprot); > + > void drm_gem_print_info(struct drm_printer *p, unsigned int indent, > const struct drm_gem_object *obj) > { > -- > 2.18.1 > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch