From patchwork Wed Oct 19 08:21:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4502 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp202345wrs; Wed, 19 Oct 2022 01:40:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7VMlzP7uL3soCdVThI5GERzFcucv7i9+z7dKhIrfuEYuZeDI/oW5r41YJGrkvttHx+oXpc X-Received: by 2002:a17:907:6d8f:b0:78d:9b5e:1a0f with SMTP id sb15-20020a1709076d8f00b0078d9b5e1a0fmr6069422ejc.23.1666168827099; Wed, 19 Oct 2022 01:40:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666168827; cv=none; d=google.com; s=arc-20160816; b=QfZ8lVira1eFIfy66HnwiUOYzw0eya1e0J6K1JLJsZaFw0eV36c/fj3zialPkCsZNW 2W60Z+sU4p1gi1djXyh6zzTU9PulSediO+ivgHG/Z0ZKOzEH44gF/nq2OTuDiFKiOG0F ehvcXVcjGsy01gNid+WGCXDeQzYsx7+kIwR2MKzxeykcth6GQl0scE+sLvHpWrb6aPrf vtbSHcLqQ/VaKpti2gKxXqFfUDnbeGnyQ8V/cMgvD+4mLGASZHExkl2FlIAN6p8MStyq miC6nu3s+Y/Jks817BYSBVKln6uyyDIRXzIDR83SZU5fCCr7y+kzddbrHXGx8gx3dZ4r s8FQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=XeVumS+NEd+kHc1Bdeb+fiBViZTPt3pAVyRAdVVe9SQ=; b=cr9MjDsUZKbH5SinAYvhbpumY+Zp64XYdsIvqIZfA6XYsI5WMPekWHLFwyS0zks/3B 3e4CNPULPG4lM48zDiw0yaR4jt/5ovs2Wv41JYT/cRrKP8k1z0Swif9wRD0qeqqVyF5E mVMvTxLesP0rc6Vo4QWo3yGfPT0sXTh4JjY44MzHJlLUR4pu0cVotQM6076CP+MrNWeb 1nlR97aGMpvyXrASGuLs8jvAyNAErRRgzc3yOIE3tTASKvaNYV4M7tVdDalCamfvbH7h RhmmDk2gT+NbVPGlhQ0glrLZs2Utd9Ts/B6ZliUS6Vu9r0NlrlTycSFfJipTfX7nSRVV Do4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="qgMLAa/q"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nb21-20020a1709071c9500b007832bdf1856si14266403ejc.740.2022.10.19.01.40.02; Wed, 19 Oct 2022 01:40:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="qgMLAa/q"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230375AbiJSIjd (ORCPT + 99 others); Wed, 19 Oct 2022 04:39:33 -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 X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747104644166533447?= X-GMAIL-MSGID: =?utf-8?q?1747104644166533447?= 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);