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 C0F47EB64D8 for ; Tue, 13 Jun 2023 17:51:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ECDC36B0074; Tue, 13 Jun 2023 13:51:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E56616B0075; Tue, 13 Jun 2023 13:51:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CA98E8E0002; Tue, 13 Jun 2023 13:51:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id B57AA6B0074 for ; Tue, 13 Jun 2023 13:51:13 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 82A6AA058F for ; Tue, 13 Jun 2023 17:51:13 +0000 (UTC) X-FDA: 80898466026.10.5C3D8B1 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 2DFC04000B for ; Tue, 13 Jun 2023 17:51:10 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=B7+Et1Cp; 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=1686678671; 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=juXhP8h8oDmvEUGxpUcem9DQ8p6SNtDcHFetvbuMc3c=; b=yvaFuS3TvWws9QYyeISQtLSwJeCMTWN9fNm+AoTVU1z41eaO+s//MfTBvfZPy4lMheD7Pc ME2RhvnLIse+AbKEA9pyjbxfjUTyK7LHdiP1S9oxDtR1Lm0MVYWb00N8Em3U/NXSRxWOrR AcCJJw92Ac4cBJ3uPktp4odD8x0cOpU= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=B7+Et1Cp; 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=1686678671; a=rsa-sha256; cv=none; b=rkWiT1MgVJS5a6InW4myFfDhxeGPTPvhIeIK/Zw65/OfXqjbTGvbpn7vJ8xXaEs+zjeBdV ICGIw0Ouvde9TOXfUajT8IGFCHfQwtvpDAVjX00bbz86xtnTr8AJnN11+VQBV9nxCVlA6H 7UZ8zN8/GvsCa8YFrIYznhsmEuVNpCM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686678670; 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=juXhP8h8oDmvEUGxpUcem9DQ8p6SNtDcHFetvbuMc3c=; b=B7+Et1Cp6np2W40v23Ml1UC4Mqo7BMHb9E8BPwXJYV7M6tMVUYSeKx5+slSvnb8epOezly 3xm/hkafiVLsRu2WFBz/s0nQc610xgm3j9IXIrj5ImbCE/gCgySHGPw/slLxnpGWffpplm PBEk/PVF1nYVH8AMlhFwxEbfB0kuvmM= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-423-nQ5_kKLBOnKb4yYpcsPZLQ-1; Tue, 13 Jun 2023 13:51:09 -0400 X-MC-Unique: nQ5_kKLBOnKb4yYpcsPZLQ-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-30fb1f3c30aso1414714f8f.0 for ; Tue, 13 Jun 2023 10:51:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686678668; x=1689270668; h=content-transfer-encoding:in-reply-to:subject:organization:from :references:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=juXhP8h8oDmvEUGxpUcem9DQ8p6SNtDcHFetvbuMc3c=; b=NqBozlQt2Bx1VRbBte94wjmAhaG1NKoZcSN5RmdI6XiV5UHTYwps8NIBJhppY6lBXG YBazJ0xtysVK+h88fMLl2pqrQs/vf0hZGoT3lpayOtibT/pC6RFUwQVnTpSNq6A5YOOH Vpb4vM22/Dl0mlk86z2b3Yj7a/2jsIR+tdOcufx27rEPSMdjbj1nJlc9Z7LX5OmySoco FJ2a1KQt+hpccP/xShtx8SJQ2XB0pqwgoAPegR36U/bzEowd65d/Fy2BYe+f4B8PFjTP vSnGnCW3iNbJHpvfMPg+bnrEl3bIL/VaJsk8mKqqmrw9w3b46yBD1tbkn7BMALFGjgKQ TUow== X-Gm-Message-State: AC+VfDyPwC2ce2lrpQS9LX5R4sPeiWtgxMWdBMU0WvThPvdM17o2DbJl zgfPejUIhsRyqTkVuFCoX4o1mFw/DrwHGXOCqUaQ5q22EjHzbE8Ey/kjAeMhzNii5v6R/yyFcfF xbKXZsKLPKQU= X-Received: by 2002:a5d:550f:0:b0:30f:d2a2:4789 with SMTP id b15-20020a5d550f000000b0030fd2a24789mr555646wrv.15.1686678667878; Tue, 13 Jun 2023 10:51:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6lyYhUT4jenaM6rLsrwexVg0v9nokG/WYAFV8FGI+Et386/Ww0vCErRFY7lVfu35C1ypzfbg== X-Received: by 2002:a5d:550f:0:b0:30f:d2a2:4789 with SMTP id b15-20020a5d550f000000b0030fd2a24789mr555631wrv.15.1686678667516; Tue, 13 Jun 2023 10:51:07 -0700 (PDT) Received: from ?IPV6:2003:cb:c710:ff00:1a06:80f:733a:e8c6? (p200300cbc710ff001a06080f733ae8c6.dip0.t-ipconnect.de. [2003:cb:c710:ff00:1a06:80f:733a:e8c6]) by smtp.gmail.com with ESMTPSA id h4-20020adffa84000000b0030647d1f34bsm15965105wrr.1.2023.06.13.10.51.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 13 Jun 2023 10:51:07 -0700 (PDT) Message-ID: <676ee47d-8ca0-94c4-7454-46e9915ea36a@redhat.com> Date: Tue, 13 Jun 2023 19:51:05 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 To: "Kasireddy, Vivek" , Mike Kravetz , "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , "dri-devel@lists.freedesktop.org" , "qemu-devel@nongnu.org" , Hugh Dickins Cc: Gerd Hoffmann , "Kim, Dongwon" , "Chang, Junxiao" , "kirill.shutemov@linux.intel.com" , "Hocko, Michal" , "jmarchan@redhat.com" , "muchun.song@linux.dev" , James Houghton , Greg Kroah-Hartman , Andrew Morton , "stable@vger.kernel.org" References: <20230608204927.88711-1-mike.kravetz@oracle.com> <281caf4f-25da-3a73-554b-4fb252963035@redhat.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH] udmabuf: revert 'Add support for mapping hugepages (v4)' In-Reply-To: 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: 7bit X-Rspamd-Queue-Id: 2DFC04000B X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 59upn5w9ryi3hc36sg5rch6aa18957tu X-HE-Tag: 1686678670-134213 X-HE-Meta: U2FsdGVkX1/SCs5nk4L7WEp1SyU8pcN5gp01TxMa/Q2L9zW6hRBKz3pgvzXYhISnBEoq1X0dk/aQ7RS1OMPxybMVCyzudG0Ne7tVShgMxK/0NCxT2+G6yGon3d/ezKgbuFZYHV1dCIKl5T3pZG4Zzan73OqvkezaGWkjW2J6gv3w0FtPYj1Za0IpGVSqw3uYiLNVp6CInWLZoXPIrTZgeGMP6fO5pG56k5qZvqVs9VENfyFZbtU9eSeNQxovnnugjNKOkM6KbDQH1046C53TwV3l/mwnWRDnzbjZ/acH7YX5JrqL8HxRVWsaShMiTl8PcbxeEGFKtlCjiTGKsleWSJwByXcw98iU9ySZiAKYSj7re5si6/kQUO41uJv4ENvyGdLKzXGQx9bkANDd0zCj+SQhOqsCPY0ju+ppgH64L/NSfwTn7JR5b04EDb2m68/APsheuoaS8AhRfiIBOtaWVMhST0aKfiq29I7njxRNjCFVXF1J9wtwesFGnWIYnvtN5dWQIbWjy+gAMTXMBk9/8zXHvEWdAEZhrINT9gGAl+wVg/upgTXebRxB1u4Xd7A4t0uxf/IvNf8mBPefTxEXiJCx9uNT888um6TjQF7w3Tz7/sPqQQBwLMn2fmbs+y/6nF+PPX7Gjv2mMHBuXyKPJPzT3BbIIZdYGJv5ARx8YHOQ1BdOc/6eM3hhwDYrYwpVQunxUD75v7XQy+U8cpX/CMjVfBlp+SSt5wbs4TAao4OGhgwdvuS0Gorn2KTO286kYyLUyEiuEqALZwb2sGO/GWFLdmrVVec8p/oMuXxy+K4ThGr6u+iw2+TrVw9Rwf6yrjymmvPb/7WCGzx78zEgRH2reS3sX1yUC9VhuGp/zfgF/RaQIZ0cnDt3/PU/vwPn0QmM18nvhqSe/avE8G0oiswEWBx5KCkf23uwiZmCCHA3w+tK+isi0qv9ccYLEUONQM6gxYkG5rISAAVei/D YjAuQD3m Jyrt/aglDSYsyH8n+Jnl5RQbLiboopEiyBc7jEDADWxFnVUyMj+6N37fdS4zRi0XZnKd2e81Pf+u6LAqLGocTfesI77w3eCWM8OLXJfZtl7diIN+CLJVR5UTiymylZs9nPKFOLU0CTnxBO/2HES2YSGMs+/D5IC3XivyegeCVfgjulHWqzTnNOi7TTX3wl94l/GBRrmOzTzeY9oSVmkmb3PmRpyTtdMz6Idow2sAiM1MVyR3l92lTvH2nkgknhQsNX2km+Em3neUL+c/vbmV+aO7hr4qn2sa42nonXBVthk7mO19XbSU2X0S1ZRDonutMFnEqagyKN/D42fyrZfV5OmOH2BSUGgEwYXXin8jC1t8Nqn3y7AG/ahTnn4ekW2Ko16hJMFvRtxs8AU21tpW8PsqJJ1UCVYIRJLZ90GStEnwnRKdGcdI/p7zR268Om/Y2zpZAAvaQgkMtDI5kRzAUW80hSIXp6NL8zo9BkXh392xA+EVwlHXejGDO80jgyNDdQ4OoTu5nbfVM2DVklr4BBiXqN2Ni1n2vHKgAsG/aw2c2o3IS6QIq7/p0yV6TledHDcdX6w3L3nGRiN+L+TmdgogsC2Ifjp+eEedJJ9BXvjaq6aE= 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 13.06.23 10:26, Kasireddy, Vivek wrote: > Hi David, > >> >> On 12.06.23 09:10, Kasireddy, Vivek wrote: >>> Hi Mike, >> >> Hi Vivek, >> >>> >>> Sorry for the late reply; I just got back from vacation. >>> If it is unsafe to directly use the subpages of a hugetlb page, then reverting >>> this patch seems like the only option for addressing this issue immediately. >>> So, this patch is >>> Acked-by: Vivek Kasireddy >>> >>> As far as the use-case is concerned, there are two main users of the >> udmabuf >>> driver: Qemu and CrosVM VMMs. However, it appears Qemu is the only >> one >>> that uses hugetlb pages (when hugetlb=on is set) as the backing store for >>> Guest (Linux, Android and Windows) system memory. The main goal is to >>> share the pages associated with the Guest allocated framebuffer (FB) with >>> the Host GPU driver and other components in a zero-copy way. To that >> end, >>> the guest GPU driver (virtio-gpu) allocates 4k size pages (associated with >>> the FB) and pins them before sharing the (guest) physical (or dma) >> addresses >>> (and lengths) with Qemu. Qemu then translates the addresses into file >>> offsets and shares these offsets with udmabuf. >> >> Is my understanding correct, that we can effectively long-term pin >> (worse than mlock) 64 MiB per UDMABUF_CREATE, allowing eventually !root > The 64 MiB limit is the theoretical upper bound that we have not seen hit in > practice. Typically, for a 1920x1080 resolution (commonly used in Guests), > the size of the FB is ~8 MB (1920x1080x4). And, most modern Graphics > compositors flip between two FBs. > Okay, but users with privileges to open that file can just create as many as they want? I think I'll have to play with it. >> users >> >> ll /dev/udmabuf >> crw-rw---- 1 root kvm 10, 125 12. Jun 08:12 /dev/udmabuf >> >> to bypass there effective MEMLOCK limit, fragmenting physical memory and >> breaking swap? > Right, it does not look like the mlock limits are honored. > That should be added. >> >> Regarding the udmabuf_vm_fault(), I assume we're mapping pages we >> obtained from the memfd ourselves into a special VMA (mmap() of the > mmap operation is really needed only if any component on the Host needs > CPU access to the buffer. But in most scenarios, we try to ensure direct GPU > access (h/w acceleration via gl) to these pages. > >> udmabuf). I'm not sure how well shmem pages are prepared for getting >> mapped by someone else into an arbitrary VMA (page->index?). > Most drm/gpu drivers use shmem pages as the backing store for FBs and > other buffers and also provide mmap capability. What concerns do you see > with this approach? Are these mmaping the pages the way udmabuf maps these pages (IOW, on-demand fault where we core-mm will adjust the mapcount etc)? Skimming over at shmem_read_mapping_page() users, I assume most of them use a VM_PFNMAP mapping (or don't mmap them at all), where we won't be messing with the struct page at all. (That might even allow you to mmap hugetlb sub-pages, because the struct page -- and mapcount -- will be ignored completely and not touched.) > >> >> ... also, just imagine someone doing FALLOC_FL_PUNCH_HOLE / ftruncate() >> on the memfd. What's mapped into the memfd no longer corresponds to >> what's pinned / mapped into the VMA. > IIUC, making use of the DMA_BUF_IOCTL_SYNC ioctl would help with any > coherency issues: > https://www.kernel.org/doc/html/v6.2/driver-api/dma-buf.html#c.dma_buf_sync > Would it as of now? udmabuf_create() pulls the shmem pages out of the memfd, not sure how DMA_BUF_IOCTL_SYNC would help to update that whenever the pages inside the memfd would change (e.g., FALLOC_FL_PUNCH_HOLE + realloc). But that's most probably simply "not supported". >> >> >> Was linux-mm (and especially shmem maintainers, ccing Hugh) involved in >> the upstreaming of udmabuf? > It does not appear so from the link below although other key lists were cc'd: > https://patchwork.freedesktop.org/patch/246100/?series=39879&rev=7 That's unfortunate :( -- Cheers, David / dhildenb