Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4995952pxv; Tue, 20 Jul 2021 16:39:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQpPZ4p3sMSnUzojZZESBnVXrd+FvqzD8XMsUrE/EDWYm1xKgDrh2lImjpC1LIMBKJw+dN X-Received: by 2002:a17:906:2809:: with SMTP id r9mr6475915ejc.463.1626824350483; Tue, 20 Jul 2021 16:39:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626824350; cv=none; d=google.com; s=arc-20160816; b=J2pUcC2PXJzsxXHsSIC/ebEnEhTnMUeMYhQQ8gLZFxnnbCIi1UiJyMUW2knObWZLCr 79xjgnsuhhBI3Hc8R/U/cHa4svx2V75uS4mA6N2KxAgc2pw37JtRZ6ABSly6fZinaka2 pTlfSJettDWF7WPOAQ7rLXKt9KX6WE8ZkRuZ8D3Wilk+/K5+QKGK9uNV51XYdOOTVhsD 7FmJ53O8idMQ6XUFFHY77QNroVoLXvWL+9m3PuyUNl73dNjeyXMD1eZK/eSrr7zd0NzR IrPWd3wWzEODv+jAXwmV7MNMIPVLIKcRdjF24gd5mNCCSkdCsHlfbcRGEmLczpxqL7Gn aIVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=RuKVvPxuQdpPn9yUJyRUbdduBXtHJ9tIJgbkO10Da38=; b=YXUhjmb9dWStZHC2iHA8HehA0n/eFD819MbxF3zZ3SwZp/0WzoUh9oOc1dN/vGxUAx EMdurbJYP3DcIjbxVAm6An2NJSF2JrPN0cdMGi/Qd83RsE9GESCzTiedSaVXLlvHLJOq DJb06ST8x2gthyxqjudoRp3TLBIvhdp1NZxgWixKHnGvA5tm6kDwCEknkVXZpoT0z89q z5M64pOBmwskTKpPiS+zgnMeE8Ig6Dy0vHNW7gvyHAKzopjXGEGEs7BcjbIroqwnSwkl 7c+p+cWGaf+J7sKN2KgoKvU0bIMdmm2JIDC6mxz6vzKRUu23jA53o4tieGZ0ZZlzuPFc 0ftg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=EdBQodRe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 1si19301374eje.240.2021.07.20.16.38.47; Tue, 20 Jul 2021 16:39:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=EdBQodRe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235788AbhGTWxT (ORCPT + 99 others); Tue, 20 Jul 2021 18:53:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:53086 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236298AbhGTWrh (ORCPT ); Tue, 20 Jul 2021 18:47:37 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 125C661165; Tue, 20 Jul 2021 23:28:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1626823692; bh=pZ4VoRnokIR9onzVreo9fLmob6Y3sBGkp5Ds0EVJjhM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=EdBQodRejK5wyrYq6wz0piYROUp3iT+9dF45XPFy0WI1yovjAjDI+hqIkKGatheg4 gcKjOQMvS9xBmleIESd4gZKxIvF/lYjjsQMSMEsP6tHz0dXWhmirIvQK1S5meOSqCp eRDoig4pKc/LzI07o+djctGoZj3GTL7Aa5SPdG/o= Date: Tue, 20 Jul 2021 16:28:10 -0700 From: Andrew Morton To: Chen Wandun Cc: <0x7f454c46@gmail.com>, , , , Subject: Re: [PATCH] mm/mremap: fix memory account on do_munmap() failure Message-Id: <20210720162810.e4710eebca48e9dc8ce2fa4d@linux-foundation.org> In-Reply-To: <20210717101942.120607-1-chenwandun@huawei.com> References: <20210717101942.120607-1-chenwandun@huawei.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 17 Jul 2021 18:19:42 +0800 Chen Wandun wrote: > mremap will account the delta between new_len and old_len in > vma_to_resize, and then call move_vma when expanding an existing > memory mapping. In function move_vma, there are two scenarios when > calling do_munmap: > 1. move_page_tables from old_addr to new_addr success > 2. move_page_tables from old_addr to new_addr fail > > In first scenario, it should account old_len if do_munmap fail, > because the delta has already been accounted. > > In second scenario, new_addr/new_len will assign to old_addr/old_len > if move_page_table fail, so do_munmap is try to unmap new_addr actually, > if do_munmap fail, it should account the new_len, because error code > will be return from move_vma, and delta will be unaccounted. > What'more, because of new_len == old_len, so account old_len also is > OK. > > In summary, account old_len will be correct if do_munmap fail. Sorry, but I'm having trouble following that description. Dmitry, could you please review this change and then assist in clarifying the changelog text? Also, could it be argued that we're doing this in the wrong place? Should it be the responsibility of do_munmap() to fix up the accounting if it is going to return an error? Rather than expecting the do_munmap() caller to fix up do_munmap()'s mess? Thirdly, is the comment in there true? Does this accounting error only occur due to ENOMEM? If that is the case then I am inclined not to backport this fix into -stable kernels, as the error is so unlikely to be triggered. Thoughts on this?