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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66247C4332F for ; Wed, 19 Oct 2022 08:39:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230370AbiJSIj3 (ORCPT ); Wed, 19 Oct 2022 04:39:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230325AbiJSIi4 (ORCPT ); Wed, 19 Oct 2022 04:38:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC8897E31B; Wed, 19 Oct 2022 01:38:29 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 365F2617D7; Wed, 19 Oct 2022 08:38:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28C1BC433D7; Wed, 19 Oct 2022 08:38:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666168685; bh=++2qBMI08ax4Oz0qKL+h8G0hyr/3cH6JH8Jq+qo8nao=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qgMLAa/q1kjUQPP3TfE0umzY/r4pODjBQ+9CNX8SAMpJRqvcOrSDNrpxIHlQesgFh psoo8pNgoJXjKY8Q88MgNsvABiT8p+JGOm3Og7qts3u2GrrcSpjS5GqPC/H5JDgiGz 8JjcUgDmGmbMvhvooZwFkr+/22B2sJDpLBZ1sfEo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stable@vger.kernel.org, Pavel Begunkov , Jens Axboe Subject: [PATCH 6.0 020/862] io_uring: correct pinned_vm accounting Date: Wed, 19 Oct 2022 10:21:47 +0200 Message-Id: <20221019083250.895836622@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Pavel Begunkov commit 42b6419d0aba47c5d8644cdc0b68502254671de5 upstream. ->mm_account should be released only after we free all registered buffers, otherwise __io_sqe_buffers_unregister() will see a NULL ->mm_account and skip locked_vm accounting. Cc: Signed-off-by: Pavel Begunkov Link: https://lore.kernel.org/r/6d798f65ed4ab8db3664c4d3397d4af16ca98846.1664849932.git.asml.silence@gmail.com Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- io_uring/io_uring.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -2422,12 +2422,6 @@ static void io_req_caches_free(struct io static __cold void io_ring_ctx_free(struct io_ring_ctx *ctx) { io_sq_thread_finish(ctx); - - if (ctx->mm_account) { - mmdrop(ctx->mm_account); - ctx->mm_account = NULL; - } - io_rsrc_refs_drop(ctx); /* __io_rsrc_put_work() may need uring_lock to progress, wait w/o it */ io_wait_rsrc_data(ctx->buf_data); @@ -2470,6 +2464,10 @@ static __cold void io_ring_ctx_free(stru WARN_ON_ONCE(!list_empty(&ctx->ltimeout_list)); WARN_ON_ONCE(ctx->notif_slots || ctx->nr_notif_slots); + if (ctx->mm_account) { + mmdrop(ctx->mm_account); + ctx->mm_account = NULL; + } io_mem_free(ctx->rings); io_mem_free(ctx->sq_sqes);