Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1120371pxb; Fri, 1 Apr 2022 05:16:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4wjxil5dKgnEc2cXqZM4dDwBWq/VQSoRCwdWPH48L/KpyV5d5avBTOptfXA/nL7j0TK56 X-Received: by 2002:a17:906:c104:b0:6e4:a223:1af9 with SMTP id do4-20020a170906c10400b006e4a2231af9mr8824654ejc.441.1648815365085; Fri, 01 Apr 2022 05:16:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648815365; cv=none; d=google.com; s=arc-20160816; b=OefDn84pl8FnlH1HIUtbtrEt1NHCxxHdhyqdcSvwDM+GDe42Z2iNm6mQRz2339oXUl X9zdRMKe46QSarXWTQBmnIKhMFaLgaHBLyw1gCHV7032f8CH/jPpjVnKU7if6JoTHjeF SxYzErawKOBAJVY/NgiF9fLFTKgd5vXBC6et43KplT7JXJWfxUbKyHMen48712BbHuLO Nc1yBox3jpYu6ptWAjgPzT0uN4NAmV5TmA2fSyb4tbAkXIxbRD4Ni1OhaSh9QeE1Bt/Z GaZm0jGX4rl5xbOECfqrysEL4DEpwQWxhTIsIEQiwGThF2YHljUtLUt7dsJkSY3or/R2 QdWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=T9+AkiW/4h4A1Ms4Miaw1I42u6H5Nq21dOfaVBmxDOY=; b=KCP3zTarbEwd1LxCmyrzcwApDtAlLlpwxOCdTiG/kEewdT69pHU5aN6DAl7kki1wR4 YLQV7fVLif6bZlG86FQo50xEHu0Z9rRppfDoon8mO0R1FXFULd0s3wZs/ILDLZjJyIcd TuIdsYJlgC5ABhIaihQv+AG6SBxGT9uFV6CLfaJPkbFY8PaNX2BJXwBPvM5j2lzwhy7m p7CtUV/kIUabPuqnfPjnBNGuq91mSF8up5Qxj9yqOFe7lbAB+aHb9v9CI7LXWGifp6/p BFBhioEM1bN/st6bVq8DGMYACaDcjIay4UclWQjah1xFm4RP95hzJGrre9oPHK9EPJ6X PCfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=YhXQSDQN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s16-20020a170906501000b006df76385bdasi1504727ejj.122.2022.04.01.05.15.38; Fri, 01 Apr 2022 05:16:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=YhXQSDQN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238146AbiCaTDe (ORCPT + 99 others); Thu, 31 Mar 2022 15:03:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238038AbiCaTDc (ORCPT ); Thu, 31 Mar 2022 15:03:32 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D31EA20DB01; Thu, 31 Mar 2022 12:01:44 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id u16so1094512wru.4; Thu, 31 Mar 2022 12:01:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=T9+AkiW/4h4A1Ms4Miaw1I42u6H5Nq21dOfaVBmxDOY=; b=YhXQSDQNFt1PUyiQir/KzfA2QkhaB5iXoDEQqrvlYnBuvliALMKTvUF/Tst9kBbB4J 3SNayKANcUSbmkrIBfOB11eokDrjDFeazk5bLvOuuZ4y8rx4zeCDpIi026N2sJjKSBvO MLyPRQCBNRqwW41BtETq9xWEHbm8pmQeI5NYZJD57XBOlNH+RELCfvheG81DDNXbfrW5 9V51RZJSTRfoGOfhBH/9emqzBACiqYXX7x+tMVXyOuVUUFOwQZ2CpUr+Isk4MflSzgt/ lC6ridW1AAiN1lJPO3jwMQmplC3eS2daZ4s+pQGQBaxFHIrfLJFYlsbAsQptf933E6Ba kSfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=T9+AkiW/4h4A1Ms4Miaw1I42u6H5Nq21dOfaVBmxDOY=; b=4mgmH9MKEqNrZDHp7LizhNdyOBrrZyyx4Xd2gFc/DjVvKHBTypPle9q4BXCHWt54ud hjLoFbDrjQcJKxefUsKSUVlAkV06RM0SucDEv2qVrsldqDkOmYTEiW1ctA+PXwXXUrWJ UaINEq/2isvyflF22o8+Tt0QPsByIEGODmJ6bE3pQCjWWgHuNfWL18FPNtqw12/xQ17B qNz6QZ5UY3GrVOWQ/UtuNvzJA7oYEBNqE5ogMqJkEtbYjy6ttftN/h3tBMUwfCklloS5 IipZio20EP1vUgiv3g5Jv9p94nhjDLbSuBlgRcLWN+UN/7Vu5vc9cxSknPKr/ZtRb6OB HSaA== X-Gm-Message-State: AOAM530TQ88MDNASVl3dLAWLTKSHpwqLUoVq3vyWflHAzVdMDjqfVuDE WrXx6fmedT8Gkklrcdg3VGOfs4PAWbFgSq7Wn2g= X-Received: by 2002:adf:f20f:0:b0:203:fc73:a9a0 with SMTP id p15-20020adff20f000000b00203fc73a9a0mr5182581wro.418.1648753303352; Thu, 31 Mar 2022 12:01:43 -0700 (PDT) MIME-Version: 1.0 References: <20220330204804.660819-1-robdclark@gmail.com> <20220330204804.660819-11-robdclark@gmail.com> In-Reply-To: From: Rob Clark Date: Thu, 31 Mar 2022 12:02:35 -0700 Message-ID: Subject: Re: [PATCH v2 10/10] drm/msm: Add a way for userspace to allocate GPU iova To: Dmitry Osipenko Cc: dri-devel , freedreno , linux-arm-msm , Dmitry Baryshkov , Rob Clark , Sean Paul , Abhinav Kumar , David Airlie , Daniel Vetter , Akhil P Oommen , Jonathan Marek , Jordan Crouse , Emma Anholt , Dan Carpenter , open list Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 31, 2022 at 11:52 AM Dmitry Osipenko wrote: > > ... > > +/* > > + * Get the requested iova but don't pin it. Fails if the requested iova is > > + * not available. Doesn't need a put because iovas are currently valid for > > + * the life of the object. > > + * > > + * Setting an iova of zero will clear the vma. > > + */ > > +int msm_gem_set_iova(struct drm_gem_object *obj, > > + struct msm_gem_address_space *aspace, uint64_t iova) > > +{ > > + int ret = 0; > > nit: No need to initialize the ret actually, we do > > + msm_gem_lock(obj); > > + if (!iova) { > > + ret = clear_iova(obj, aspace); > > + } else { > > + struct msm_gem_vma *vma; > > + vma = get_vma_locked(obj, aspace, iova, iova + obj->size); > > + if (IS_ERR(vma)) { > > + ret = PTR_ERR(vma); > > + } else if (GEM_WARN_ON(vma->iova != iova)) { > > + clear_iova(obj, aspace); > > + ret = -ENOSPC; > > The (vma->iova != iova) means that vma is already set, but to a > different address. Is -ENOSPC really appropriate here? -EBUSY or -EINVAL > looks more natural to me. yeah, -EBUSY is better > > + } > > + } > > + msm_gem_unlock(obj); > > + > > + return ret; > > +} > > + > > /* > > * Unpin a iova by updating the reference counts. The memory isn't actually > > * purged until something else (shrinker, mm_notifier, destroy, etc) decides > > diff --git a/drivers/gpu/drm/msm/msm_gem.h b/drivers/gpu/drm/msm/msm_gem.h > > index 38d66e1248b1..efa2e5c19f1e 100644 > > --- a/drivers/gpu/drm/msm/msm_gem.h > > +++ b/drivers/gpu/drm/msm/msm_gem.h > > @@ -38,6 +38,12 @@ struct msm_gem_address_space { > > > > /* @faults: the number of GPU hangs associated with this address space */ > > int faults; > > + > > + /** @va_start: lowest possible address to allocate */ > > + uint64_t va_start; > > + > > + /** @va_size: the size of the address space (in bytes) */ > > + uint64_t va_size; > > }; > > > > struct msm_gem_address_space * > > @@ -144,6 +150,8 @@ struct msm_gem_vma *msm_gem_get_vma_locked(struct drm_gem_object *obj, > > struct msm_gem_address_space *aspace); > > int msm_gem_get_iova(struct drm_gem_object *obj, > > struct msm_gem_address_space *aspace, uint64_t *iova); > > +int msm_gem_set_iova(struct drm_gem_object *obj, > > + struct msm_gem_address_space *aspace, uint64_t iova); > > int msm_gem_get_and_pin_iova_range(struct drm_gem_object *obj, > > struct msm_gem_address_space *aspace, uint64_t *iova, > > u64 range_start, u64 range_end); > nit: There is an odd mix of uint64_t and u64 (and alike) in the MSM code > :) The uint64_t variant shouldn't be used by kernel code in general and > checkpatch should want about it. one of many things that I disagree with checkpatch about ;-) I prefer standard types to custom ones. I _kinda_ get the argument in case of uapi (but IMHO that doesn't apply to how drm uapi headers are used) BR, -R