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=-11.3 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, NICE_REPLY_A,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham 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 AE83FC43457 for ; Fri, 9 Oct 2020 07:33:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1AD4F22267 for ; Fri, 9 Oct 2020 07:33:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IwKJFEew" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1AD4F22267 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 42A4C6B005D; Fri, 9 Oct 2020 03:33:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3DBEE900002; Fri, 9 Oct 2020 03:33:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 27CBB6B006C; Fri, 9 Oct 2020 03:33:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0127.hostedemail.com [216.40.44.127]) by kanga.kvack.org (Postfix) with ESMTP id EC14F6B005D for ; Fri, 9 Oct 2020 03:33:08 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 81DF28249980 for ; Fri, 9 Oct 2020 07:33:08 +0000 (UTC) X-FDA: 77351570856.12.legs58_10022ca271de Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id 5BEE518011181 for ; Fri, 9 Oct 2020 07:33:08 +0000 (UTC) X-HE-Tag: legs58_10022ca271de X-Filterd-Recvd-Size: 6762 Received: from mail-ed1-f66.google.com (mail-ed1-f66.google.com [209.85.208.66]) by imf38.hostedemail.com (Postfix) with ESMTP for ; Fri, 9 Oct 2020 07:33:07 +0000 (UTC) Received: by mail-ed1-f66.google.com with SMTP id dn5so8331282edb.10 for ; Fri, 09 Oct 2020 00:33:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=reply-to:subject:to:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=zHLZR+cdQxUXAapkvnhHRxEGDbtuU0jlMqUOlyS9CQ8=; b=IwKJFEewQoSKcdG2YAPPCbvHXC/d2fJCXSoWKxPDWofdhldJOtN8hS/Pi5QmL2msmn fgO0tfHHRvDJp5uq9wMO8PF1j4J3ajDFOYcMFiiaYbCL9NgUHnvdfzApp7sEygo8gHxC XuNUH0cjc2UyhfzR8KOepak+beCJyiDatAyXYrrwq6vTnuio5ewdh3s45qi6I4MnPepn RvfsaAkCY5dUJqRtOzl726dnOvp9VkasIudKgL/r8Bwc1xElpx5geFYNETeMzzNk/itj Se2doJ6dBHD+gWR5v+n062bMQQl2yZI38NO7DfFv72qUtNzYYk4S/7RgNX+cj0ebgjTt XBTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:subject:to:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=zHLZR+cdQxUXAapkvnhHRxEGDbtuU0jlMqUOlyS9CQ8=; b=OLrbI5MUvIu2xXuj98pIg4uejRuEMv14dWHsQ16DpxTYFVqFPhJxPZe4/cwqz6FssD pRsMAecThdh3sftpTwL8O5RyvpLjEOIM/IHQ3sk+wB6zp5jWJKPSKTK0t4ZNjLRqNDAz ACWD6KnnVE4IITn4irL0uiA+7SdvJmU/CAF1Mt7DPmLHvFCzEs6A98BtfOIEN1xxNVP7 fEub07k1Pf4uPIwQYlcC2ZR8IA6ImKKK7DmEB8WkhueNmI3hLWIXzmsxZxa0iBBw/827 yuzZDnkgAK+tVVrd649bpRVfiIOjOd3OrpUhkz2e9OspuaLrLLLBTqZ0Bcb4ki3r436L Mz3A== X-Gm-Message-State: AOAM533jXqsQzMhpDJ9/vlhjZmnR1povRGP9MJmuh74q4ZibeO4MukKd 3kox4IeTQ+dWyReTaMzAUW0= X-Google-Smtp-Source: ABdhPJzXIarjT4XlMBlwIGVzLRN/9SvySlM1kW8J0vZXEormyHb9njn+Y4gL6yZ2ZXkN7zR7BWjQ5A== X-Received: by 2002:aa7:d29a:: with SMTP id w26mr12533300edq.59.1602228786703; Fri, 09 Oct 2020 00:33:06 -0700 (PDT) Received: from ?IPv6:2a02:908:1252:fb60:be8a:bd56:1f94:86e7? ([2a02:908:1252:fb60:be8a:bd56:1f94:86e7]) by smtp.gmail.com with ESMTPSA id gv10sm5824756ejb.46.2020.10.09.00.33.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 09 Oct 2020 00:33:06 -0700 (PDT) Reply-To: christian.koenig@amd.com Subject: Re: [PATCH 1/4] mm: introduce vma_set_file function v2 To: John Hubbard , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linaro-mm-sig@lists.linaro.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, chris@chris-wilson.co.uk, airlied@redhat.com, akpm@linux-foundation.org, daniel@ffwll.ch, sumit.semwal@linaro.org References: <20201008112342.9394-1-christian.koenig@amd.com> From: =?UTF-8?Q?Christian_K=c3=b6nig?= Message-ID: <747e1832-0341-9029-95f6-638f0f1a6f76@gmail.com> Date: Fri, 9 Oct 2020 09:33:04 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Am 08.10.20 um 23:49 schrieb John Hubbard: > On 10/8/20 4:23 AM, Christian K=C3=B6nig wrote: >> Add the new vma_set_file() function to allow changing >> vma->vm_file with the necessary refcount dance. >> >> v2: add more users of this. >> >> Signed-off-by: Christian K=C3=B6nig >> --- >> =C2=A0 drivers/dma-buf/dma-buf.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | 16 ++++= +----------- >> =C2=A0 drivers/gpu/drm/etnaviv/etnaviv_gem.c=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 |=C2=A0 4 +--- >> =C2=A0 drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c |=C2=A0 3 +-- >> =C2=A0 drivers/gpu/drm/i915/gem/i915_gem_mman.c=C2=A0=C2=A0 |=C2=A0 4 = ++-- >> =C2=A0 drivers/gpu/drm/msm/msm_gem.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0 4 +--- >> =C2=A0 drivers/gpu/drm/omapdrm/omap_gem.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 |=C2=A0 3 +-- >> =C2=A0 drivers/gpu/drm/vgem/vgem_drv.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0 3 +-- >> =C2=A0 drivers/staging/android/ashmem.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0 5 ++--- >> =C2=A0 include/linux/mm.h=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0 2 ++ >> =C2=A0 mm/mmap.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | 1= 6 ++++++++++++++++ >> =C2=A0 10 files changed, 32 insertions(+), 28 deletions(-) > > Looks like a nice cleanup. Two comments below. > > ... > >> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_mman.c=20 >> b/drivers/gpu/drm/i915/gem/i915_gem_mman.c >> index 3d69e51f3e4d..c9d5f1a38af3 100644 >> --- a/drivers/gpu/drm/i915/gem/i915_gem_mman.c >> +++ b/drivers/gpu/drm/i915/gem/i915_gem_mman.c >> @@ -893,8 +893,8 @@ int i915_gem_mmap(struct file *filp, struct=20 >> vm_area_struct *vma) >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * requires avoiding extraneous re= ferences to their filp, hence=20 >> why >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * we prefer to use an anonymous f= ile for their mmaps. >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 */ >> -=C2=A0=C2=A0=C2=A0 fput(vma->vm_file); >> -=C2=A0=C2=A0=C2=A0 vma->vm_file =3D anon; >> +=C2=A0=C2=A0=C2=A0 vma_set_file(vma, anon); >> +=C2=A0=C2=A0=C2=A0 fput(anon); > > That's one fput() too many, isn't it? No, the other cases were replacing the vm_file with something=20 pre-allocated and also grabbed a new reference. But this case here uses the freshly allocated anon file and so=20 vma_set_file() grabs another extra reference which we need to drop. The alternative is to just keep it as it is. Opinions? > > > ... > >> diff --git a/drivers/staging/android/ashmem.c=20 >> b/drivers/staging/android/ashmem.c >> index 10b4be1f3e78..a51dc089896e 100644 >> --- a/drivers/staging/android/ashmem.c >> +++ b/drivers/staging/android/ashmem.c >> @@ -450,9 +450,8 @@ static int ashmem_mmap(struct file *file, struct=20 >> vm_area_struct *vma) >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 vma_set_anonymo= us(vma); >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } >> =C2=A0 -=C2=A0=C2=A0=C2=A0 if (vma->vm_file) >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 fput(vma->vm_file); >> -=C2=A0=C2=A0=C2=A0 vma->vm_file =3D asma->file; >> +=C2=A0=C2=A0=C2=A0 vma_set_file(vma, asma->file); >> +=C2=A0=C2=A0=C2=A0 fput(asma->file); > > Same here: that fput() seems wrong, as it was already done within=20 > vma_set_file(). No, that case is correct as well. The Android code here has the matching=20 get_file() a few lines up, see the surrounding code. I didn't wanted to replace that since it does some strange error=20 handling here, so the result is that we need to drop the extra reference=20 as again. We could also keep it like it is or maybe better put a TODO comment on it= . Regards, Christian. > > > > thanks,