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 7B4B4C5479D for ; Mon, 9 Jan 2023 08:36:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BEA7E8E0002; Mon, 9 Jan 2023 03:36:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B9A2F8E0001; Mon, 9 Jan 2023 03:36:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A62728E0002; Mon, 9 Jan 2023 03:36:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 980FA8E0001 for ; Mon, 9 Jan 2023 03:36:55 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 5DAA840206 for ; Mon, 9 Jan 2023 08:36:54 +0000 (UTC) X-FDA: 80334605148.27.25D40C1 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf28.hostedemail.com (Postfix) with ESMTP id 24320C0008 for ; Mon, 9 Jan 2023 08:36:51 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Gd3sY3+p; spf=pass (imf28.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673253412; a=rsa-sha256; cv=none; b=NB1d8FJn7sRf56uuojK+hEmfGrJ5UQqX2JOL1fbwNL7/CgjwTqOv3IkzRHHC9HVTrbO/0D mNDCt+RBSRmz51SNPMiuhi7idaTVnKk/GPLhYDVGQ/6Dorrf9ajNPsXTt4UNZHq0IxA7+C 1YYvDcIwbKkmGlGgGYdylDf7k9oVK7Y= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Gd3sY3+p; spf=pass (imf28.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673253412; 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=5Kv0tKlHIz61BWkfNwfRuVbsf96Cqd8RpZSvBC6o6BQ=; b=kIsnU9sH3DqTEWiJpBrPEe4QXmnAJ7YZz7/hbSiuQjRS0iCEO0LyD3KWhpUD3R2/GI+2Kw O7QgvFYK9Snp8jATh/2rZHlGFICwWrMecQEKpWym33VO+1XhLEazyn6uATUtHdY0FDBYQq Z6gz9ix+yZhy5KGP8Qo9zk2SjBik5x0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673253411; 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=5Kv0tKlHIz61BWkfNwfRuVbsf96Cqd8RpZSvBC6o6BQ=; b=Gd3sY3+pbTVH3aJnody8s4Yb15hby6uhEOjunQ29/PzvuUcbBVGXzOH171ZWTC2JWuYVGB NAAblMj2WvFlpJCUmdwgv7AVfsREWdBDf+9e8F1GMrHGyJ/rrhF8ydJX0XBdpBy7eyZt4Q B1lmwCwB8ic9fhRhNZrNUDf8oJwb9e0= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-403-XHLOz6QvMDaKzC2p71E0Dw-1; Mon, 09 Jan 2023 03:36:50 -0500 X-MC-Unique: XHLOz6QvMDaKzC2p71E0Dw-1 Received: by mail-wm1-f70.google.com with SMTP id l17-20020a05600c1d1100b003d9a145366cso4417445wms.4 for ; Mon, 09 Jan 2023 00:36:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=5Kv0tKlHIz61BWkfNwfRuVbsf96Cqd8RpZSvBC6o6BQ=; b=2T9Yvg8oWj8Z5I5j5psIZVRzdEGVsJUfHMugnGYtPLgLfhjJAwdp9u4Yw3ByRC4kr4 F355KwS31gFFCgNvlf22S/QS+vkl9L9QKHoc+KFmoiBimPXzMMow8en2SfShHZSW17gc eA6WZCA4qpo9/yE7zJ1bCUBR6surFVxKh1Z8hTu1uPq7t3t3dmXRKJXaioTIOoeWg08d mlwONDwXGwaZlLvAR64xgWj1S91Juqro4frtrwj6xYak3RnKR8epbG7y2z6/Zjco3tOY szmOb3fC92Ra5YRc4iVlJubWdmwzjs0uL1q8U6jrF4Je2nzEJW/46wzOWSabm65id2KR qM2Q== X-Gm-Message-State: AFqh2kpxFjf0fKcgi4j6Tzdo/dwR5ZmYBssDriZjgatepIGfx1jsnLMP jsAgMbI89GjVL4dG8BGBkvkLMfnPGjnsyOZNUShNThmgmAtG68zxE9xjGK7058B1tWq/zOqZBJ0 j/TeAdQnBOuM= X-Received: by 2002:a05:600c:4da0:b0:3d2:3a53:2cd6 with SMTP id v32-20020a05600c4da000b003d23a532cd6mr46060679wmp.9.1673253409117; Mon, 09 Jan 2023 00:36:49 -0800 (PST) X-Google-Smtp-Source: AMrXdXvsvcEWlhawTW11dcgo7sA67lLcZ1eb9qozTyOzhskeQHRDFyAP00PQUHFOlV9jCORBScZ4jg== X-Received: by 2002:a05:600c:4da0:b0:3d2:3a53:2cd6 with SMTP id v32-20020a05600c4da000b003d23a532cd6mr46060667wmp.9.1673253408848; Mon, 09 Jan 2023 00:36:48 -0800 (PST) Received: from ?IPV6:2003:cb:c703:8f00:ba3:7d27:204f:8e29? (p200300cbc7038f000ba37d27204f8e29.dip0.t-ipconnect.de. [2003:cb:c703:8f00:ba3:7d27:204f:8e29]) by smtp.gmail.com with ESMTPSA id g12-20020a05600c310c00b003c70191f267sm15997370wmo.39.2023.01.09.00.36.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Jan 2023 00:36:48 -0800 (PST) Message-ID: Date: Mon, 9 Jan 2023 09:36:47 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: [PATCH 3/3] mm/uffd: Detect pgtable allocation failures To: Nadav Amit Cc: Peter Xu , Linux-MM , kernel list , Mike Kravetz , Muchun Song , Andrea Arcangeli , James Houghton , Axel Rasmussen , Andrew Morton References: <20230104225207.1066932-1-peterx@redhat.com> <20230104225207.1066932-4-peterx@redhat.com> From: David Hildenbrand Organization: Red Hat 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: 8bit X-Rspam-User: X-Rspamd-Queue-Id: 24320C0008 X-Rspamd-Server: rspam01 X-Stat-Signature: mrhsyo8bboj3f8z4q7saiczyepebmb11 X-HE-Tag: 1673253411-929011 X-HE-Meta: U2FsdGVkX1+j6LW2cKAy3ivXDicfRWjwe7n5EditYYdoUXpR6S4injBS/ku1gskO9wsCUhgnIkY7+IV6N5TztRF96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UnWwnsjSn4mLqrwgGSI0YauDsGGJuv6kAsg== 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 05.01.23 19:01, Nadav Amit wrote: > > >> On Jan 5, 2023, at 12:59 AM, David Hildenbrand wrote: >> >> On 05.01.23 04:10, Nadav Amit wrote: >>>> On Jan 4, 2023, at 2:52 PM, Peter Xu wrote: >>>> >>>> Before this patch, when there's any pgtable allocation issues happened >>>> during change_protection(), the error will be ignored from the syscall. >>>> For shmem, there will be an error dumped into the host dmesg. Two issues >>>> with that: >>>> >>>> (1) Doing a trace dump when allocation fails is not anything close to >>>> grace.. >>>> >>>> (2) The user should be notified with any kind of such error, so the user >>>> can trap it and decide what to do next, either by retrying, or stop >>>> the process properly, or anything else. >>>> >>>> For userfault users, this will change the API of UFFDIO_WRITEPROTECT when >>>> pgtable allocation failure happened. It should not normally break anyone, >>>> though. If it breaks, then in good ways. >>>> >>>> One man-page update will be on the way to introduce the new -ENOMEM for >>>> UFFDIO_WRITEPROTECT. Not marking stable so we keep the old behavior on the >>>> 5.19-till-now kernels. >>> I understand that the current assumption is that change_protection() should >>> fully succeed or fail, and I guess this is the current behavior. >>> However, to be more “future-proof” perhaps this needs to be revisited. >>> For instance, UFFDIO_WRITEPROTECT can benefit from the ability to (based on >>> userspace request) prevent write-protection of pages that are pinned. This is >>> necessary to allow userspace uffd monitor to avoid write-protection of >>> O_DIRECT’d memory, for instance, that might change even if a uffd monitor >>> considers it write-protected. >> >> Just a note that this is pretty tricky IMHO, because: >> >> a) We cannot distinguished "pinned readable" from "pinned writable" >> b) We can have false positives ("pinned") even for compound pages due to >> concurrent GUP-fast. >> c) Synchronizing against GUP-fast is pretty tricky ... as we learned. >> Concurrent pinning is usually problematic. >> d) O_DIRECT still uses FOLL_GET and we cannot identify that. (at least >> that should be figured out at one point) > > My prototype used the page-count IIRC, so it had false-positives (but I suspect GUP-fast is still problematic, I might be wrong. > addressed O_DIRECT). And yes, precise refinement is complicated. However, > if you need to uffd-wp memory, then without such a mechanism you need to > ensure no kerenl/DMA write to these pages is possible. The only other > option I can think of is interposing/seccomp on a variety of syscalls, > to prevent uffd-wp of such memory. The whole thing reminds me of MADV_DONTNEED+pinning: an application shouldn't do it, because you can only get it wrong :) I know, that's a bad answer. -- Thanks, David / dhildenb