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 C8952EB64DD for ; Fri, 14 Jul 2023 02:40:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 24F75900004; Thu, 13 Jul 2023 22:40:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1FF7B900002; Thu, 13 Jul 2023 22:40:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0C83C900004; Thu, 13 Jul 2023 22:40:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id F087D900002 for ; Thu, 13 Jul 2023 22:40:34 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id A55B0120449 for ; Fri, 14 Jul 2023 02:40:34 +0000 (UTC) X-FDA: 81008663988.12.761D735 Received: from mail-yw1-f173.google.com (mail-yw1-f173.google.com [209.85.128.173]) by imf10.hostedemail.com (Postfix) with ESMTP id C548CC0018 for ; Fri, 14 Jul 2023 02:40:32 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=2AWa9ik7; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf10.hostedemail.com: domain of hughd@google.com designates 209.85.128.173 as permitted sender) smtp.mailfrom=hughd@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689302432; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=fpmWFOXgIkuZyzywTnhMumZEEpfEch01HHv67pOnagE=; b=Q8SETsSQ0NRAA891MwUMNcWL4aWR3wVEPvr5YdGJwiiqsJyjIa6/2LWRBrm+yqHaE1ea/Y YAtY31Lp82reBTmQAIEEpDPhohjSEfic9eG07XHpffA+fS+T98mIaVIKp8bz6QUucVtmzN 8QQunbrNgvpoc+DkU589JJJFFfR/dQ4= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=2AWa9ik7; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf10.hostedemail.com: domain of hughd@google.com designates 209.85.128.173 as permitted sender) smtp.mailfrom=hughd@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689302432; a=rsa-sha256; cv=none; b=tH8w4PkwnJ2geSTnXs045cnmhhDRPGmTLTCmMtwtmpKwRePmUv/fC6whN4NGTOXQLyWCcZ 0tZOCbGE3zDvMrw2Uh3gJnQQcAHv33ut8kTVIcw1ABvpUlrygVofzcumwfvgLrWGpjxF3A oTCbGuhqQZy7Rg6goLjatu6PrAvKyb8= Received: by mail-yw1-f173.google.com with SMTP id 00721157ae682-577497ec6c6so13965787b3.2 for ; Thu, 13 Jul 2023 19:40:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689302432; x=1691894432; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=fpmWFOXgIkuZyzywTnhMumZEEpfEch01HHv67pOnagE=; b=2AWa9ik7tP6HZUy4G9dlR0tBFYb7xNwEapReMO4wqUmCCobrYfRggkuMPZkTObJXRD xa0qZ7bL0xQCWBcrD9f5uvTn5phV7itJYwIx+LUCQCo+WNfERnuWNDjmN0d9wM21ml2Y bYnwGJ0Izwoz3Xj+fbpEEaGHpNSXbpjZf4+xxWxT9Z8kVgshIc4/lrBq7g3rpwpjW4J1 QsuBm7O5NHCpj7FZV36nLiNlaPJzbc5PVX5eQ4HS+oyFnt48+GPiGF7xAp+mf7vmKH+X o5SvJvRqSPALX5OVQhTNiiYiPOe1BdmM8iDflHClNUXxzlCFiyTm6OSEgXXDRKCyg6db RE/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689302432; x=1691894432; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fpmWFOXgIkuZyzywTnhMumZEEpfEch01HHv67pOnagE=; b=ZfYSWeD0ca/zSdx07GhtOCdsjsAzTKVa2np+33e1xFKa1Rbzpz2N09l4FlVvWWdYsy RCfoTWJP4q2R8Q7cxu/+YeO94QTcsUyhOGXrAvddsUOaP8nXkKUalW7/NuWGVszKoCjI 9tibwn6zXZkVPzXv/dbeBX1AOwcqJ+Qqfvd/obs0LANHcOLfAdTsWaFviUgYf96QA+s/ IuO5My/EL2NcZL1aCLCM7VOH8oIInRDvOiGCEh6bgdvwSSKK9a1vgRhNn6dgzTOaWfwh NeqOAkYzCrJSOgFhpbC6FPGBWoJQ0KCulPTCidXiwDjl+QttyulDBWkjF6LACzSMA9+t sijg== X-Gm-Message-State: ABy/qLYQ1JE66a2X0WjE8RWuAqBEw/FVcHvOZcMQmf86YK2KqoUkvc+Y i5ponwjbOjguVXAjmsU8SyTi7A== X-Google-Smtp-Source: APBJJlGF29tkpI5hwJwSOkYmGq4FtQ+YWjMJxqSMF7mHqFAaJ4RgGi7AxilVdlPqF75XbDlTGUDEjA== X-Received: by 2002:a81:9215:0:b0:573:4815:8347 with SMTP id j21-20020a819215000000b0057348158347mr4054884ywg.36.1689302431791; Thu, 13 Jul 2023 19:40:31 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id v186-20020a8161c3000000b005612fc707bfsm2073426ywb.120.2023.07.13.19.40.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 19:40:31 -0700 (PDT) Date: Thu, 13 Jul 2023 19:40:30 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Axel Rasmussen cc: Hugh Dickins , Andrew Morton , Dan Carpenter , Peter Xu , linux-mm@kvack.org Subject: Re: [PATCH mm-unstable fix] mm: userfaultfd: add new UFFDIO_POISON ioctl: fix In-Reply-To: Message-ID: <517aeee1-b4cd-c3fc-3236-e2a33c115af5@google.com> References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="-1463760895-1007370286-1689302431=:3952" X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: C548CC0018 X-Stat-Signature: e5ejufucsb9fqyc34jpr7313o1r9x7wf X-HE-Tag: 1689302432-648501 X-HE-Meta: U2FsdGVkX18/Xvp8B4eeOiSQORyxqOa+WWQ5xi0+LBXcdFfiAQvli57O9GKd1cCRNGeG6Ch0RGafIJoraXv0CBceXv7dZ3BK3a4kAi9HGALStNbhLwRzY7NNrKR8IiB2bFM8rtVJL4Ki3gGM7Le1rbD61gduk7luvuAeZOF5FlWwHSkpHkm1aMZJyYiZzn++rWCIMgwRVA4sX3RFJ81PN3WWuOqYFiFr+IFhHCypD7BubUJMDdVGjRwuCZPs67rN/8BMYNHSk672ApNHM+SnpCK6X0LsECxZblNvvzzaqBBjAUaR+C72c5BEGwcnUdYuhufXcmSTAES9dn2FMFWXkcbnfhVCG4z8YRMoMXZZZ4MK8JCte1orrwgHVF+1xqM5Xk46UECe5L86Q8f9fXRXWVTOQgzRvcePZjUnxbiYDJwSQ82HYgfSbnaSrlNKohwVSRnX0aPWqsJNLV07eG1VgjTLjbIzMqoVn/O8v9HX9Ivh3iU68IQwcyC7s/bCCTi/bTH2tic4v9WExXUpCRAWaTh0uy5rb2R6qhcdYdR1+Ym27haRDTz1Bueu6aSSbu6xppzSCK/+9lJYyBDXTiqaDsQBEQ911Zd6328Zjle/k5e/HfsS8L3Hg+TrN6gFxEUAoaXbW9wSXpWRElWUQr4WKapWrjH4kYqbURAB+SwGGzW9noni8oUFhNX2DZGuPVNNVqMie8J3A4tQBPRUM6O1YYZ9lZWGWKU4wPwH6yJKWPtEiHHAounoqaltwG0qubLEbuEK4X3RXqMtTd9lfJYx+7N7bVt5HdVmtunpKFAkrFSCNp0kYoAq9W+9h62Ra0mzbpNzBt35RZHkmDxIIQnM+XHs3bw9Z+Uz7fnA6Ln7pFTW6KXOrl/uyFcSbyyGw1tnYS1R32E7TrIvTg6LzCwHuuZJr0vUmvCMvbvpcDreFQNvTg1h50/3PVUPc8Ah/a4PQ9AczsvtDAucbwe4IW0 oBsuGrX1 xG4SY6tvAduNZWZqVd9LgHuPKPPtdwcnLBrjwfnR64kQCLGpzxNETT1HqHXHNN5CUZSvRb4cn86a11ktZWLsUJDTlmZ58zs5GxpQ8imcqprU5O7jFii2rIcSbV+kC6l7xR3i4M53vcshRHxGRd2gTCpJ7Xo+SQOKi99hwYdvos6XTcsqdJGENkFmqrdLoZraAK5qNvEDfa0wZonPtAMlSgvL99LNLCk4PIbDwe93mpJ8seV4si1LX7z3Qv2JnGHVqusWvsy3TUvWFB27DX43+79lX1ju9DDIhx4XCpsNkE7El8yZcCHlGRRWZ7KalIwHWZXCvBA8TgtT3gftlvTd7+e4FVwYIwkbuNf1fW6UEOoj5Y1kXNjYCfyg7vWW2pn/3KWsMW2AIHcFjrdw0r74e0qz2niqPkin3SwUok98hgSvR0sMF+gK+lK+glBN/3pxE/VqfHO2dgqMESJig2ZSG6ShmauAcSqJqfW18gAHr+BaREpUxAcpoHoyEYH8QuImkL5QD X-Bogosity: Ham, tests=bogofilter, spamicity=0.000147, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. ---1463760895-1007370286-1689302431=:3952 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE On Wed, 12 Jul 2023, Axel Rasmussen wrote: > On Tue, Jul 11, 2023 at 6:27=E2=80=AFPM Hugh Dickins w= rote: > > > > Smatch has observed that pte_offset_map_lock() is now allowed to fail, > > and then ptl should not be unlocked. Use -EAGAIN here like elsewhere. > > > > Signed-off-by: Hugh Dickins >=20 > Looks correct to me, thanks Hugh! If it's useful, feel free to take: >=20 > Reviewed-by: Axel Rasmussen Thanks, that will have helped Andrew (but would vanish into the merge with your original when it moves from mm-unstable to mm-stable). >=20 > > --- > > Axel, Peter: this seems right as a fix to the patch in mm-unstable; > > but in preparing this, I noticed mfill_atomic()'s code before calling > > mfill_atomic_pte(), and think that my original choice of -EFAULT was > > therefore better than -EAGAIN for all of these; and that mfill_atomic()= 's > > BUG_ONs there would be better deleted (and is its BUG_ON(folio) safe??)= =2E > > Something one of us should address, after this fixup is in akpm's tree. >=20 > Agreed, dealing with the BUG_ONs is something I have been meaning to > do as checkpatch bothers me about it frequently. >=20 > What this code is trying to do is to enforce the contract that: if > mfill_atomic_pte failed, then it must have released *folio and set it > to NULL. But, you're exactly right that if we had such a bug, it would > mean we leaked one page in an unusual error case - not great, but not > worth crashing the kernel either. >=20 > For UFFDIO_POISON this doesn't really apply because it doesn't > allocate or get a reference to a page in any case. >=20 > For other cases like UFFDIO_COPY where it does matter, I think it's > fine as is regardless of the error code returned (as long as it's not > -ENOENT :) ). mfill_atomic_pte_copy() is sure to set `*foliop =3D NULL` > before it attempts this lock (in mfill_atomic_install_pte). So -EAGAIN > or -EFAULT should work equally well at least from that perspective. I > somewhat prefer -EAGAIN, but maybe I'm missing something. Right, when I said -EFAULT better than -EAGAIN, I was only basing that on -EFAULT being the code which was already used for pmd_trans_huge() in the check above mfill_atomic()'s call to mfill_atomic_pte(). I don't disagree with you, and Peter too preferred -EAGAIN: it's just better if they all use the same code (or maybe mfill_atomic()'s first check for pmd_trans_huge() can be deleted along with the BUG_ONs - but I have not checked through the cases, there may be very good reason to keep that preliminary check there). Hugh ---1463760895-1007370286-1689302431=:3952--