From patchwork Tue Oct 1 22:52:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 13818832 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 39BC9CF3189 for ; Tue, 1 Oct 2024 22:52:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BDC5D680029; Tue, 1 Oct 2024 18:52:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B8B6B6B012D; Tue, 1 Oct 2024 18:52:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A0430680029; Tue, 1 Oct 2024 18:52:29 -0400 (EDT) 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 7794F6B012B for ; Tue, 1 Oct 2024 18:52:29 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id F0935A9CB1 for ; Tue, 1 Oct 2024 22:52:28 +0000 (UTC) X-FDA: 82626533976.13.FDC42BC Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf06.hostedemail.com (Postfix) with ESMTP id 69BDA18000F for ; Tue, 1 Oct 2024 22:52:26 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=CpHdhX2M; spf=pass (imf06.hostedemail.com: domain of andrii@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=andrii@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727823081; a=rsa-sha256; cv=none; b=vI7y1vkzgCrh7ySD2WoBcAkd7fZEIYeQHUiP8SnnZsWrTPVIxmoc8L9/Cf49hEWUatKJBy 125vAMSzhoraMQ+AQHFf4vZIfg3D0hdogbYKPqwcF8mqgxZNkQMVZu4ogLGYYsP4PIED1N mHOfbqi9tvyvXui83x16BTQgbijwA2k= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=CpHdhX2M; spf=pass (imf06.hostedemail.com: domain of andrii@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=andrii@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727823081; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=kj0vkyEpwZweBGsjeOW0IkTQksU+6PEipyZ/5oRsvKs=; b=fMZzpocR26X+eEOKOgbUfRKmHG+ALS0N4SOWeAjFF+eu+ROFv1yzmQ67K/94txkzQAcAr1 YJsxib07+aU/Hgzft0GwzYSGra/sFyj3gcjm9fb/PPD1EUVEQvSrjY9pJl+0L1f/xrNxx+ y8HqnvxaQJ5b8jzzsb/cvqhhacuHEsY= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 713A4A4336F; Tue, 1 Oct 2024 22:52:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4533DC4CEC6; Tue, 1 Oct 2024 22:52:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727823145; bh=Fe0W0B2s6ceCb71LS5xDyOWx4mAiBCLoZvDtud5NppM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CpHdhX2My8bEMExNjtkiCBGzgD/icJoKKBqYiIrUbPzCTfYszjoLtbMmq1dssYj3T Vrwe8b43Ff5XJWhkflBzoIkA4mbw1tW1bc+gdwJ5gHBcaUuGvSIZVtObiyY9gzB6fL 279sn7GDirJgGJM+LjoW+rAaFbP+0qgSw780RGYXJSzkxUeqFy2lbgEVIGwSB2x2EA yVmzNitaw7bjQ8Gxrp5it9ifxi0NkWH3rkKE5gjhUNhD8GF3nt6umR84JDzYdOvj6S 032wn+XUSq9IQVRDNOwPE/ysqQ+e7s8s7xRGN/F99dVabaYTJU5jAaQ7kjjhMvZGTm 9/45fjGcrlZ7g== From: Andrii Nakryiko To: linux-trace-kernel@vger.kernel.org, peterz@infradead.org, oleg@redhat.com Cc: rostedt@goodmis.org, mhiramat@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, jolsa@kernel.org, paulmck@kernel.org, willy@infradead.org, surenb@google.com, akpm@linux-foundation.org, linux-mm@kvack.org, mjguzik@gmail.com, brauner@kernel.org, jannh@google.com, mhocko@kernel.org, vbabka@suse.cz, mingo@kernel.org, Andrii Nakryiko , Amir Goldstein Subject: [PATCH v2 tip/perf/core 3/5] fs: add back RCU-delayed freeing of FMODE_BACKING file Date: Tue, 1 Oct 2024 15:52:05 -0700 Message-ID: <20241001225207.2215639-4-andrii@kernel.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241001225207.2215639-1-andrii@kernel.org> References: <20241001225207.2215639-1-andrii@kernel.org> MIME-Version: 1.0 X-Stat-Signature: y3bxcehjhg897zgeejeeb3i6xrygin7y X-Rspamd-Queue-Id: 69BDA18000F X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1727823146-975454 X-HE-Meta: U2FsdGVkX198cdqoLp7gm9RY789LFhOAFCf+IwHVxrh+VotbJ+tD6+E5QV8FKV8pqT1gT0MiIGHpX5wf78moyWQTiFA2ofyh/2hVEpGZos3V+QtwWXnzSpin81IISzQ98IL1Fzz66nfdHY0b27OG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CVuNFWw1iYWnr+qhC79j0KD0tz8ooPCL3aCLz3MqxM8lNk1i+AgbYzmiqMRvwxj5sgWZ//98Yo9IF5tMjPIRauDgIa1qwb2bZmc= 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: List-Subscribe: List-Unsubscribe: 6cf41fcfe099 ("backing file: free directly") switched FMODE_BACKING files to direct freeing as back then there were no use cases requiring RCU protected access to such files. Now, with speculative lockless VMA-to-uprobe lookup logic, we do need to have a guarantee that struct file memory is not going to be freed from under us during speculative check. So add back RCU-delayed freeing logic. We use headless kfree_rcu_mightsleep() variant, as file_free() is only called for FMODE_BACKING files in might_sleep() context. Suggested-by: Suren Baghdasaryan Cc: Christian Brauner Cc: Amir Goldstein Signed-off-by: Andrii Nakryiko Reviewed-by: Christian Brauner --- fs/file_table.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/file_table.c b/fs/file_table.c index ca7843dde56d..257691d358ee 100644 --- a/fs/file_table.c +++ b/fs/file_table.c @@ -68,7 +68,7 @@ static inline void file_free(struct file *f) put_cred(f->f_cred); if (unlikely(f->f_mode & FMODE_BACKING)) { path_put(backing_file_user_path(f)); - kfree(backing_file(f)); + kfree_rcu_mightsleep(backing_file(f)); } else { kmem_cache_free(filp_cachep, f); }