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 C00C1C4332F for ; Fri, 16 Dec 2022 15:57:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5FA2F8E0005; Fri, 16 Dec 2022 10:57:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5AABD8E0002; Fri, 16 Dec 2022 10:57:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4729B8E0005; Fri, 16 Dec 2022 10:57:41 -0500 (EST) 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 371848E0002 for ; Fri, 16 Dec 2022 10:57:41 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 041921403C9 for ; Fri, 16 Dec 2022 15:57:40 +0000 (UTC) X-FDA: 80248624722.19.FF7054C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf08.hostedemail.com (Postfix) with ESMTP id ED304160017 for ; Fri, 16 Dec 2022 15:57:38 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="bZL/xMxb"; spf=pass (imf08.hostedemail.com: domain of david@redhat.com designates 170.10.133.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=1671206259; a=rsa-sha256; cv=none; b=tLjxkWocqP920LBoewTsJD6EtBoj0d/AFaeseUkb7Al4ctPx3NKMfXIADdn/HD9rtK5ueN bar49bXL8E9wKNo5pjIpsQ/RQyQbC32svaiApBd/60muxH3Kc78GJhMw5Fs4CM8MHZi02G HPoxw40toKRtthcye0//VUY4EWhzHAs= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="bZL/xMxb"; spf=pass (imf08.hostedemail.com: domain of david@redhat.com designates 170.10.133.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=1671206259; 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=6dLsRoolqx1zZhtmb36YfFuBLbtpT274h3r2aL8GL4k=; b=MJAaS126b2ncEeRzMNYimYzBvFemarjTi9e+g/4w58HuBK+XdtHLrOIk+oZBUL5Msa+WPD zaikJHmJIEnDSXiu97vqOiRLIyTDc7lLaYpcqJDRvby/R6RtejeI4mNqMSLRSuHuWEEcLX duRQqaDJlOV3VBB/N0FDAvh4O7vSpuk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671206258; 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=6dLsRoolqx1zZhtmb36YfFuBLbtpT274h3r2aL8GL4k=; b=bZL/xMxbtjroVc5Zpc57+Wocdg/Q0AVf1FPU2RI+wBZbWaIQENWrhmguaz4/fD3AFuHoJJ YCaNkFqZoixBSqAO8r9Dv0CszjwoBJZBSrSPW7SAx60BJKEfFSKxCrcYjCjtfF4k2xM2Y8 yTJxWRBzZPs2dEZbK4sIv+8gcbHDHhY= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-116-nVCDnYIIOrCwMsFThtxEkQ-1; Fri, 16 Dec 2022 10:57:37 -0500 X-MC-Unique: nVCDnYIIOrCwMsFThtxEkQ-1 Received: by mail-wm1-f71.google.com with SMTP id x10-20020a05600c420a00b003cfa33f2e7cso1380973wmh.2 for ; Fri, 16 Dec 2022 07:57:37 -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:subject:organization:from :content-language:references:cc:to:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=6dLsRoolqx1zZhtmb36YfFuBLbtpT274h3r2aL8GL4k=; b=qO+/qOs+merzUTQ9oXfy5VjcrEWv472xcN+NC2l9f3yJ09b8zzqpyHjAsAK2sf+l3W oXTJNTaZtmO6M49wrSZtxRnoixGHETS8eobhhuiyqqcQyejaJ/G9CipJwDzPP0FcP6d8 JZ2ehwQ1yUPxDS2eo1UqkW46aNJ4TEg/h/OZLW6DxI08j81N7iqLYbfLtBkO5yoDfGuz d4jEGNZIid40QX19kXvdZCcYfgQEUXJ69+ST+BGJSeu7Ci2yRNTlYYmVzaYcnD+5xhf2 GrIj0+HGicqnRoatzVFkpcWoWPQDBl/Bckf7hHpbEJ/xMWaFiZsCroW4ZDbeGPDyLhxd cUKg== X-Gm-Message-State: ANoB5plcli74ayL6OYUXb/UrL3H1MUNf4bpUZjbMwOj5F3ttplETOA07 V3lr2V6y6UXOKp8a6NuOCVY4mei7oHV247mG0TYidfvMghSN4c9KmP4x4P2jU78MwPgobcFlJGh 315fhhMOKXug= X-Received: by 2002:a05:600c:3549:b0:3c6:e61e:ae8c with SMTP id i9-20020a05600c354900b003c6e61eae8cmr35406002wmq.28.1671206256121; Fri, 16 Dec 2022 07:57:36 -0800 (PST) X-Google-Smtp-Source: AA0mqf64C2aBB45GXwS++QO6Sr3F4ze8EYUjLXrts0880Hw6xU+tVgHq4xUPJI4/W644ZIm86uv0JQ== X-Received: by 2002:a05:600c:3549:b0:3c6:e61e:ae8c with SMTP id i9-20020a05600c354900b003c6e61eae8cmr35405979wmq.28.1671206255823; Fri, 16 Dec 2022 07:57:35 -0800 (PST) Received: from [192.168.3.108] (p4ff23686.dip0.t-ipconnect.de. [79.242.54.134]) by smtp.gmail.com with ESMTPSA id 8-20020a05600c028800b003c6d21a19a0sm2868815wmk.29.2022.12.16.07.57.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 16 Dec 2022 07:57:35 -0800 (PST) Message-ID: <8c36dd0a-90be-91bf-0ded-55b34ee0a770@redhat.com> Date: Fri, 16 Dec 2022 16:57:33 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 To: Peter Xu Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrea Arcangeli , Pengfei Xu , Nadav Amit , Andrew Morton , Miaohe Lin , Huang Ying , stable@vger.kernel.org References: <20221214200453.1772655-1-peterx@redhat.com> <20221214200453.1772655-2-peterx@redhat.com> <618b69be-0e99-e35f-04b3-9c63d78ece50@redhat.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH 1/2] mm/uffd: Fix pte marker when fork() without fork event 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-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: ED304160017 X-Stat-Signature: mhofix1nrtiept54ig7wswhyhx1fh393 X-HE-Tag: 1671206258-263267 X-HE-Meta: U2FsdGVkX1+ddm/QkrH0JqG2aehD5RsB/OjgTv13DKWLPHPQE9tB124RN7PwOv7AG9HeD+0YWCNnKjPtrj7PwB2dM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dCImPPKC+Uv3mePEcclVouaZ6Q4stErMEA== 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: >> >> Wouldn't it be cleaner to be able to "clean" specific markers from a PTE >> marker without having to special case on each and everyone? I mean, only >> uffd-wp is really special such that it might disappear for the target. > > Quotting the commit message in patch 2: > > Currently there is a priority difference between the uffd-wp bit and the > swapin error entry, in which the swapin error always has higher priority > (e.g. we don't need to wr-protect a swapin error pte marker). > > If there will be a 3rd bit introduced, we'll probably need to consider a > more involved approach so we may need to start operate on the bits. > Let's leave that for later. > > I actually started the fix with something like that, but I noticed it's not > needed to add more code if there's no 3rd bit introduced so I dropped that. > I decided to go the simpler change approach and leave that for later. Okay, makes sense. > >> >> Something like (pseudocode): >> >> if (!userfaultfd_wp(dst_vma)) >> pte_marker_clear_uff_wp(entry); >> if (!pte_marker_empty(entry)) { >> pte = make_pte_marker(pte_marker_get(entry)); >> set_pte_at(dst_mm, addr, dst_pte, pte); >> } >> >> Then this fix would be correct and backport-able even without #2. And it >> would work for new types of markers :) > > When that comes, we may need one set_pte_marker_at() taking care of empty > pte markers, otherwise there can be a lot of such check. Right. In the future it might be cleaner. > >> >> >> I'd prefer a fix that doesn't break something else temporarily, even if the >> stable backport might require 5 additional minutes to do. So squashing #2 >> into #1 would also work. > > The thing is whether do we care about someone: (1) explicitly checkout at > the commit of patch 1, then (2) runs the kernel, hit a swapnin error, (3) > fork(), and (4) access the swapin error page in the child. I'm more concerned about backports, when one backports #1 but not #2. In theory, patch #2 fixes patch #1, because that introduced IMHO a real regression -- a possible memory corruption when discarding a hwpoison marker. Warnings are not nice but at least indicate that something needs a second look. > > To me I don't care even starting from (1).. because it really shouldn't > happen at all in any serious environment. > > The other reason is these are indeed two issues to solve. Even if by > accident we kept the swapin error in old code we'll probably dump an > warning which is not wanted either. It's not something someone will really > get benefit from.. > > So like many other places, I don't have a strong opinion, but personally I > prefer the current approach. Me neither, two patches just felt more complicated than it should be. Anyhow, the final code change LGTM. -- Thanks, David / dhildenb