Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4387274ioa; Wed, 27 Apr 2022 02:41:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQM3PnnnxoC2uvyXb7mpEuI100iZwz5mNt/KmitZ1wv/mBD92AYuDDYEOo+QfKczQyJzlp X-Received: by 2002:a63:3d0b:0:b0:37f:ef34:1431 with SMTP id k11-20020a633d0b000000b0037fef341431mr22965793pga.547.1651052503130; Wed, 27 Apr 2022 02:41:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651052503; cv=none; d=google.com; s=arc-20160816; b=AtaE5oEgg0EPbFk1gxmepGadQuJ8mVwaaDd8dS5s4N3dIs1+FPedhQ5sXncqr4TfN9 2Fn7ahKpU3Py9bqlTn2y8qQ1AXIE5k3cGZc9EajfmvmC6F8EXhRbcxGNb05jCpoTYdPQ c7Hdaz4g0lj017TyDVWws46+185KgqCwAndsL6vo3+wS0agqoZu4KwO+h4rC5fWY751j jNIy/Bu4D1HVuyyxlImYVzdh7B+fcfdy+mDrJwoRP0A+tSUexqt5R95ba23F8+BQpgJ/ AmRRkm4AIcJbIFiJKr94s+LrDe8POq2vuBc6VSAFUA7YoOogr1omqUphcpcDifSko2Dy XzUg== 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=wUb4CkOm6VxdQqEa9fW0+fyMhODud2B3lIhoWRM80TQ=; b=SFxmoAB0Tm2h+EYGzD+vxevjfGsIsgKi1ga88SzU+3wZ6mMIn27DYAjD4gNB+SfqKD OrZT6LRk6UyuGKhNKLK1sVH9bSZ+OKp4gzW30HFkD73VGxw3za6bL6nQ210Cl0pi8bFg kDVytwK4XGDq9leQ6tz3jE6P4nPa5SSwm9HXW7RdQapzAFZ00tR+PuxCTlHwGxQZyZzw mcZR0168ZC0oOyMddKr4Ra8NMVX1i4TlblHGUAQin3lMK0X17+usS+6oX78oGsj41XLR t9YGr9jf0Jk8cBhaLtSyv6Qs2Z/cydDKP7G6qd4j619IAUMG2AFc21WVXlL0G2McdmZ4 68+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=Gf0gHdt2; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id h27-20020a63121b000000b003995aee3634si1026736pgl.175.2022.04.27.02.41.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 02:41:43 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=Gf0gHdt2; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 23C82274103; Wed, 27 Apr 2022 02:17:15 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355042AbiDZUh3 (ORCPT + 99 others); Tue, 26 Apr 2022 16:37:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355047AbiDZUhW (ORCPT ); Tue, 26 Apr 2022 16:37:22 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDAA01A8C10 for ; Tue, 26 Apr 2022 13:34:04 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 8C67AB82325 for ; Tue, 26 Apr 2022 20:34:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8AB7C385A0; Tue, 26 Apr 2022 20:34:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1651005242; bh=1nLv2uonWidEFj1pcSTMshyTONddZm1b5bjnp+01fFQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Gf0gHdt2okkMpp8c3Tx2/ENbPLTud5mAngEc563OHINdGlX00/CeEy71BKhr5D90G RVheA6Z6zLvlXxnCmGuoIWUPr0FbXthZk67HezG33K0HZY7ZRy/J3qJoUWlSdqGUs/ 7trds2YehtZeWFn+DTjtjNLZSzjGuplwtaWt1Xh0= Date: Tue, 26 Apr 2022 13:34:01 -0700 From: Andrew Morton To: liusongtang Cc: , , , , Subject: Re: [PATCH] mm/mprotect: reduce Committed_AS if memory protection is changed to PROT_NONE Message-Id: <20220426133401.9404190c5a5c6ff58b694c59@linux-foundation.org> In-Reply-To: <20220426112705.3323-1-liusongtang@huawei.com> References: <20220426112705.3323-1-liusongtang@huawei.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 26 Apr 2022 19:27:05 +0800 liusongtang wrote: > If PROT_WRITE is set, the size of vm area will be added to Committed_AS. > However, if memory protection is changed to PROT_NONE, > the corresponding physical memory will not be used, but Committed_AS still > count the size of the PROT_NONE memory. > > This patch reduce Committed_AS and free the corresponding memory if > memory protection is changed to PROT_NONE. > > ... > > --- a/mm/mprotect.c > +++ b/mm/mprotect.c > @@ -497,6 +497,12 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev, > } > > success: > + if ((newflags & (VM_READ | VM_WRITE | VM_EXEC | VM_LOCKED | VM_ACCOUNT)) == VM_ACCOUNT) { > + zap_page_range(vma, start, end - start); > + newflags &= ~VM_ACCOUNT; > + vm_unacct_memory((end - start) >> PAGE_SHIFT); > + } > + > /* > * vm_flags and vm_page_prot are protected by the mmap_lock > * held in write mode. Surprised. If userspace does mprotect(addr, len. PROT_NONE) then mprotect(addr, len. PROT_READ), what is now at *addr? Zeroes?