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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5AF39C77B7A for ; Wed, 7 Jun 2023 19:28:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C357F6B0075; Wed, 7 Jun 2023 15:28:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BBE526B007B; Wed, 7 Jun 2023 15:28:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A374A6B007D; Wed, 7 Jun 2023 15:28:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 8BE586B0075 for ; Wed, 7 Jun 2023 15:28:01 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 5B4541C7375 for ; Wed, 7 Jun 2023 19:28:01 +0000 (UTC) X-FDA: 80876937162.19.76A218B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf01.hostedemail.com (Postfix) with ESMTP id ECFFD40014 for ; Wed, 7 Jun 2023 19:27:58 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Y+VdPw39; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686166079; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=CAuZKWxgMnD5I2dUAcxpBa+vUyMeeRszn4FXRAq2g14=; b=p8LYbnMZM3gljgwVUxZxUoh/q61rTB9RHrMGfPuJMsuIKM3OavGeugwLTucenZodW1Ux/K Zwezi21Yn0eQTeb0XkYWzQjYrwNn4R0VXMzfyFCh/yasZy4cZwT+Fa7PwkBCgz8BzFIzDt cuvi14gcSb+Zi51Dd+z4NTX+pkRPGQ8= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Y+VdPw39; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686166079; a=rsa-sha256; cv=none; b=8R+DKaOL4XLMexcx6LbC8vLIOaFErqEyq4wXk1ENf8tJfmO0A/wGpgx7HcHIeb2tFv3XmZ BQ2AIDt/VB4TzXPaBMGRvwY9q7TqTUYP4W8aVC81nIawr779v/vKUOC8agoIVcXCZ3FfcT p9ZrktWeU3i28o5Re7ZHS1pEtcApch4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686166077; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CAuZKWxgMnD5I2dUAcxpBa+vUyMeeRszn4FXRAq2g14=; b=Y+VdPw39bGWCyobzZcbhqXlhvU7tv0bJpoZJcV2f1/IZpMYprjF69Q1suZsNm13+7a/Td8 dpZZoaCsFrmsmJjCR0Zyzrn/kFERH49MAZtfcguCMY+ntfGqfPQSn9xfNQVcv79sHY7dUN tuGCcp4hZxzH+/yKi7afjbQ7Dkx8bnw= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-629-GDeefgfpPT27P8wv6kas1Q-1; Wed, 07 Jun 2023 15:27:56 -0400 X-MC-Unique: GDeefgfpPT27P8wv6kas1Q-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-30ae9cf0178so3465168f8f.1 for ; Wed, 07 Jun 2023 12:27:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686166075; x=1688758075; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=CAuZKWxgMnD5I2dUAcxpBa+vUyMeeRszn4FXRAq2g14=; b=gZIphbiOQHyyVFqoFuuNTlcqwng7AZrGtHBDIJ4vMvLYhN34vUjmoRU7GwJ9MQ14QU MXiiBX66fimXJzaM6SbaaMtMAxBFmk4ua2X2Wz8FDx/H9J8VHasi7v6GIfkbWx11Dfvu yhVghauCmz+KUExOFA1TjQtNq90R8T7GgFMlWqQ/903aCKOiHYM6dx5gjGWsHZHLj4j6 ypOwlsnkP1kI5lL6hG3OVHOdOQm/2TEWpCdq0ZRH078Dde4e6KofLoU2LAaKs252G5cT JnWYDxUYJ0Os6j2QyJZoO/YrVclcpBMyiqIaQ7WvhUIdmICTcgIx+iZmyAr4PJrVbMwn Iblg== X-Gm-Message-State: AC+VfDwPeDu/jLubEip2714j85XSl+TQSrvQ+ZyQVBSPA7dm20JHgt4l J7lTi27MvU9N3tk4FGXoW57oNC97NrynrekGrXa0dtf3g/BGBuHr3uAd5gi2/8rQcUGcBno7WvT WlR2AaaNCt8I= X-Received: by 2002:adf:f212:0:b0:30d:5cce:3bb5 with SMTP id p18-20020adff212000000b0030d5cce3bb5mr5361267wro.60.1686166075671; Wed, 07 Jun 2023 12:27:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ53BZ7epzz2YZH1dV8dbSaXlZkItElGSeMArJqwAMGz80G25ws0g1jH8hMaJauWnUparPOSbg== X-Received: by 2002:adf:f212:0:b0:30d:5cce:3bb5 with SMTP id p18-20020adff212000000b0030d5cce3bb5mr5361244wro.60.1686166075225; Wed, 07 Jun 2023 12:27:55 -0700 (PDT) Received: from ?IPV6:2003:cb:c70e:9c00:8d26:3031:d131:455c? (p200300cbc70e9c008d263031d131455c.dip0.t-ipconnect.de. [2003:cb:c70e:9c00:8d26:3031:d131:455c]) by smtp.gmail.com with ESMTPSA id t3-20020adfe103000000b0030ae6432504sm16252528wrz.38.2023.06.07.12.27.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 07 Jun 2023 12:27:54 -0700 (PDT) Message-ID: Date: Wed, 7 Jun 2023 21:27:53 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH] mm: fix hugetlb page unmap count balance issue To: Mike Kravetz , Gerd Hoffmann Cc: Junxiao Chang , akpm@linux-foundation.org, kirill.shutemov@linux.intel.com, mhocko@suse.com, jmarchan@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, muchun.song@linux.dev, Vivek Kasireddy , Dongwon Kim , James Houghton , dri-devel@lists.freedesktop.org References: <20230512072036.1027784-1-junxiao.chang@intel.com> <20230512232947.GA3927@monkey> <20230515170259.GA3848@monkey> <20230516223440.GA30624@monkey> From: David Hildenbrand Organization: Red Hat In-Reply-To: <20230516223440.GA30624@monkey> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: ECFFD40014 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: fcgnpij6yc8oqt9z16t8wd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Xt4yWZ02Pz6hlyjl9vIRqcY5Mpuy6Q0dWJrYoAQikpEaf21toj9tkXBDQwMuTO5dgPB97d2iPwzE5GwD/h7nC9Vsye/SFjARYhI1jkPDXad6Cl50Q4xX7ryoQJ6VPn5sg2FdOEzfoqgC7FCeAqnFShsuZwnuZyP5t+FhgeOGSM9DO0wMRjzsIe04Vx5RiGZvh++84lrxaubQFkEvLcmFi9nCbxWlFptXTrpbFT1s/jv6Bc2nXqyCOrFrcTXLufDvXC9wCN51YnyMWPkJz1PicuP8U+T2NCeA8ineSkDdFs0o41mj6VSOd3PhIYnmpHI+Q9La3C1FohlmivLdhD52veM66ZAidH0tIbZwU32cZN7n4veF1vA2uEKE3FA1jh7SwGP/Nge+6OnrYk9uP++K7kpOLA3ZUAV6wZd1EkLd8ywWRcqFUo/5tBPjRhE= 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: On 17.05.23 00:34, Mike Kravetz wrote: > On 05/15/23 10:04, Mike Kravetz wrote: >> On 05/12/23 16:29, Mike Kravetz wrote: >>> On 05/12/23 14:26, James Houghton wrote: >>>> On Fri, May 12, 2023 at 12:20 AM Junxiao Chang wrote: >>>> >>>> This alone doesn't fix mapcounting for PTE-mapped HugeTLB pages. You >>>> need something like [1]. I can resend it if that's what we should be >>>> doing, but this mapcounting scheme doesn't work when the page structs >>>> have been freed. >>>> >>>> It seems like it was a mistake to include support for hugetlb memfds in udmabuf. >>> >>> IIUC, it was added with commit 16c243e99d33 udmabuf: Add support for mapping >>> hugepages (v4). Looks like it was never sent to linux-mm? That is unfortunate >>> as hugetlb vmemmap freeing went in at about the same time. And, as you have >>> noted udmabuf will not work if hugetlb vmemmap freeing is enabled. >>> >>> Sigh! >>> >>> Trying to think of a way forward. >>> -- >>> Mike Kravetz >>> >>>> >>>> [1]: https://lore.kernel.org/linux-mm/20230306230004.1387007-2-jthoughton@google.com/ >>>> >>>> - James >> >> Adding people and list on Cc: involved with commit 16c243e99d33. >> >> There are several issues with trying to map tail pages of hugetllb pages >> not taken into account with udmabuf. James spent quite a bit of time trying >> to understand and address all the issues with the HGM code. While using >> the scheme proposed by James, may be an approach to the mapcount issue there >> are also other issues that need attention. For example, I do not see how >> the fault code checks the state of the hugetlb page (such as poison) as none >> of that state is carried in tail pages. >> >> The more I think about it, the more I think udmabuf should treat hugetlb >> pages as hugetlb pages. They should be mapped at the appropriate level >> in the page table. Of course, this would impose new restrictions on the >> API (mmap and ioctl) that may break existing users. I have no idea how >> extensively udmabuf is being used with hugetlb mappings. > > Verified that using udmabug on a hugetlb mapping with vmemmap optimization will > BUG as: > > [14106.812312] BUG: unable to handle page fault for address: ffffea000a7c4030 > [14106.813704] #PF: supervisor write access in kernel mode > [14106.814791] #PF: error_code(0x0003) - permissions violation > [14106.815921] PGD 27fff9067 P4D 27fff9067 PUD 27fff8067 PMD 17ec34067 PTE 8000000285dab021 > [14106.818489] Oops: 0003 [#1] PREEMPT SMP PTI > [14106.819345] CPU: 2 PID: 2313 Comm: udmabuf Not tainted 6.4.0-rc1-next-20230508+ #44 > [14106.820906] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-1.fc37 04/01/2014 > [14106.822679] RIP: 0010:page_add_file_rmap+0x2e/0x270 > > I started looking more closely at the driver and I do not fully understand the > usage model. I took clues from the selftest and driver. It seems the first > step is to create a buffer via the UDMABUF_CREATE ioctl. This will copy 4K > pages from the page cache to an array associated with a file. I did note that > hugetlb and shm behavior is different here as the driver can not add missing > hugetlb pages to the cache as it does with shm. However, what seems more > concerning is that there is nothing to prevent the pages from being replaced > in the cache before being added to a udmabuf mapping. This means udmabuf > mapping and original memfd could be operating on a different set of pages. > Is this acceptable, or somehow prevented? > > In my role, I am more interested in udmabuf handling of hugetlb pages. > Trying to use individual 4K pages of hugetlb pages is something that > should be avoided here. Would it be acceptable to change code so that > only whole hugetlb pages are used by udmabuf? If not, then perhaps the > existing hugetlb support can be removed? I'm wondering if that VMA shouldn't be some kind of special mapping (VM_PFNMAP), such that the struct page is entirely ignored? I'm quite confused and concerned when I read that code (what the hell is it doing with shmem/hugetlb pages? why does the mapcount even get adjusted?) This all has a bad smell to it, I hope I'm missing something important ... -- Cheers, David / dhildenb