From patchwork Mon Dec 16 19:24:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13910245 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 C52D4E7717F for ; Mon, 16 Dec 2024 19:24:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BEA7F6B0088; Mon, 16 Dec 2024 14:24:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B994E6B008C; Mon, 16 Dec 2024 14:24:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A3B946B0095; Mon, 16 Dec 2024 14:24:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 7FA346B0088 for ; Mon, 16 Dec 2024 14:24:49 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 2ACD445075 for ; Mon, 16 Dec 2024 19:24:49 +0000 (UTC) X-FDA: 82901798280.27.DE6F3D1 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) by imf22.hostedemail.com (Postfix) with ESMTP id 2F5A8C0010 for ; Mon, 16 Dec 2024 19:24:15 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=pclWiwew; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf22.hostedemail.com: domain of 3fn5gZwYKCD8tvsfochpphmf.dpnmjovy-nnlwbdl.psh@flex--surenb.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3fn5gZwYKCD8tvsfochpphmf.dpnmjovy-nnlwbdl.psh@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734377073; a=rsa-sha256; cv=none; b=2ACky+eLoyoQ/1PM5rBF1RS4Tlo5E8bIcAT8jVsYyYCTJxbDNzD1QlxNSxEo/kFRcNrFZA 86wzTRaylhpK7Ewzo3POiRawrdP3DKPsjbhsUK8+T1uN0TwswcGq0pkRasvvZLEKhfKpqK l2RV96Ac7BlQfjJB/5wJoAwlAsEqyMM= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=pclWiwew; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf22.hostedemail.com: domain of 3fn5gZwYKCD8tvsfochpphmf.dpnmjovy-nnlwbdl.psh@flex--surenb.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3fn5gZwYKCD8tvsfochpphmf.dpnmjovy-nnlwbdl.psh@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734377073; 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=nohm0qlZ+D54asZWR+C7SIZfQAywm7JDUn18lM86DfI=; b=SgabJ9bw43IbF3z9LIuzcNq8Cii4YWazI+k1DfFZG8VlGAjd8oNQCUaC1ZIg51jjRXnJAE zdHhuUrSBU8ArEtSzzqGCzJ73+A4tj2g0P8EbsEjAMZAdWV5wYa/lPwARg5p0soOafmiBz YRUp6ATg4mh9ZDxsIdJtB/VuV0hKFi8= Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-725e59e41d2so4106918b3a.0 for ; Mon, 16 Dec 2024 11:24:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734377086; x=1734981886; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=nohm0qlZ+D54asZWR+C7SIZfQAywm7JDUn18lM86DfI=; b=pclWiwewigFNnGxofi1OPwp763hk138cgy4clilITTG2mBGlgObLEoH3kkuelUjmtC KeLbcVToQXPE/xASUOgu2Yq9IQipYh95gLWNSuh6hTpEKH+KOHfgbctreRHt51pEQ/DP B9p/4CXnCsht8dXp5IqtsMLCvmiP1oiist9JgxEev2QPRTomQvor853m4vuYv0xm2lrF Agz1ibHTlFozZ2tEit7WKJSDGy5C4C1d2SDO780pR84Uso3Kb8rsKu4yqzkp+Basl3gb KhSG0MDqE6SrHyLfDYWu9vfcFcaBBA7NJF6XevaUequhohgO4wpMulqD9JhmmHjm05X9 xBYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734377086; x=1734981886; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nohm0qlZ+D54asZWR+C7SIZfQAywm7JDUn18lM86DfI=; b=oSVaDsttCePDFwFETMf7notaWD+S974idad+5i2/LEal2KNye6pShgtBIEn/40ZaEG vC4qybY9QqS2ogp02ccH4Byl1II5F2EPT16rqLHIuVJbcPr9C7ROcJXvvxxEwSwbpK+s t/t4+jhhMW86wExnQHuzyWgsozCjNBxPnuaYABnp8KOQsTHq3Z2KHBcMB6J0KBUIwAAA dAW2OFjA6iqfO+5yMxyN1B5ZN282q37iumgWatN4IDEkZVbMmfmad0NDzUE/82lguJwk mznqQpa8SREIXZmOcnT11tUgEZ6TdqDCp4EySD6/TFgFJ/IInWwr2QE/4lVtg/GFVEI5 CUXQ== X-Forwarded-Encrypted: i=1; AJvYcCX9T3tEr1fy1kWmkdPbbcoxmNoOcadzkx99A65/XzsViov4nTyRkb26mSAhSdMqpoFYSPahFbovVg==@kvack.org X-Gm-Message-State: AOJu0Yz3uVsOz+yCduzr62zpKbuPp5yX9F8DhOXNdIR+Bg0XrB8Oejnu bElcYeyIUzz3O0I/j3W+MaQgb4YpmlDljQa2U8LAMZjE7o8D+XnvylVFUSyAVkONFa6GG/H86oG eog== X-Google-Smtp-Source: AGHT+IF9Nz4fP8YCDWuEvv8HenQUzivi17wIWFTDjOw79pIi9puAuyZi3edh0rN76x0eDFYowMyrfvXvJ/c= X-Received: from pgiz13.prod.google.com ([2002:a63:c04d:0:b0:7fd:585b:babf]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:c88e:b0:1e0:f495:1bd9 with SMTP id adf61e73a8af0-1e45ab17a26mr1379210637.8.1734377086086; Mon, 16 Dec 2024 11:24:46 -0800 (PST) Date: Mon, 16 Dec 2024 11:24:14 -0800 In-Reply-To: <20241216192419.2970941-1-surenb@google.com> Mime-Version: 1.0 References: <20241216192419.2970941-1-surenb@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241216192419.2970941-12-surenb@google.com> Subject: [PATCH v6 11/16] mm: enforce vma to be in detached state before freeing From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: peterz@infradead.org, willy@infradead.org, liam.howlett@oracle.com, lorenzo.stoakes@oracle.com, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, mjguzik@gmail.com, oliver.sang@intel.com, mgorman@techsingularity.net, david@redhat.com, peterx@redhat.com, oleg@redhat.com, dave@stgolabs.net, paulmck@kernel.org, brauner@kernel.org, dhowells@redhat.com, hdanton@sina.com, hughd@google.com, lokeshgidra@google.com, minchan@google.com, jannh@google.com, shakeel.butt@linux.dev, souravpanda@google.com, pasha.tatashin@soleen.com, klarasmodin@gmail.com, corbet@lwn.net, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@android.com, surenb@google.com X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 2F5A8C0010 X-Stat-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4L+TEJQoE5+6Qg8auXS3Z2/0W1rjT6DE8Dyo54jHPlUK+0TK0rj3FDd12u3Z+h51S0PtlhWIFBvvsKLxn9sPNUSn25DJhJ0TCewKP64Lvp3gRR5Yay4TxM6DsK2nkEf80EWeCroruzI+ivMM65fgd38Z7u6PACkWKTCauscX8CBnq+h6sZW2V0i6wxg/L3i7aXoaYCuc1McH/cy0rTDTUWLRBJBQT4ltV0pB3H99cdI/cDFp/gIO/q2DvhHfu5Qzc5PahJ9ZTSWJs7pIiAHXWBOhUBNyW7GTCET+20WPUfgJxOKcrBy9Gf+n21IuGA5u3Qt5/z9OMUDZ5Jf+7xyDLLSTT014ZEejEnmRv57gviO8HkkBcfhmo2p0aOhbtBcm5d+09g1ReCZA7cuZlGY5UE135sEBczmS/xa3koN+mrbiJy8GVbeXvaNSAuppzHuf3huWnbaPcPiVoiqOzQteqhDp3Px1EGQd1IjjRlpsAIGdMbXW4JEP+l9U3s/8NZZma4fWFM2ICZVyPApzcSTmNhVg= X-Bogosity: Ham, tests=bogofilter, spamicity=0.003732, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: exit_mmap() frees vmas without detaching them. This will become a problem when we introduce vma reuse. Ensure that vmas are always detached before being freed. Signed-off-by: Suren Baghdasaryan --- kernel/fork.c | 4 ++++ mm/vma.c | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/kernel/fork.c b/kernel/fork.c index 283909d082cb..f1ddfc7b3b48 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -473,6 +473,10 @@ struct vm_area_struct *vm_area_dup(struct vm_area_struct *orig) void __vm_area_free(struct vm_area_struct *vma) { +#ifdef CONFIG_PER_VMA_LOCK + /* The vma should be detached while being destroyed. */ + VM_BUG_ON_VMA(!is_vma_detached(vma), vma); +#endif vma_numab_state_free(vma); free_anon_vma_name(vma); kmem_cache_free(vm_area_cachep, vma); diff --git a/mm/vma.c b/mm/vma.c index fbd7254517d6..0436a7d21e01 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -413,9 +413,15 @@ void remove_vma(struct vm_area_struct *vma, bool unreachable) if (vma->vm_file) fput(vma->vm_file); mpol_put(vma_policy(vma)); - if (unreachable) + if (unreachable) { +#ifdef CONFIG_PER_VMA_LOCK + if (!is_vma_detached(vma)) { + vma_start_write(vma); + vma_mark_detached(vma); + } +#endif __vm_area_free(vma); - else + } else vm_area_free(vma); }