From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f44.google.com (mail-ot1-f44.google.com [209.85.210.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2014D280A21 for ; Tue, 30 Dec 2025 00:23:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767054236; cv=none; b=qeW/dxebT+LnLLKkHxFJmUd0Xp7VcPn1/43qdJULpzkj1ZaYdREO+juyLBNJQEJsXHeI/WgUMHck1WaAJCvnE4ddF9tCvAdbahp32Vj/ze6K2cff46Ci/Xi4ABqttHaYGzKGvKNHBrYWypQORxy7K8zCb/beLaKGyeRbKtmJn8k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767054236; c=relaxed/simple; bh=iVH/CxM/QXNKRlsj+Gw1DBA7WGit8t/coTgw9urJ74c=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type; b=schH01rqhPE94t7tAMQAuugIWgEFc6kCITHUgpvVX2BTYiajB2DHhvhSCTZMoAFISMvkTh5RwnuOCfzCjPGAStTz1Cd8jzFUmZFGRRg9g4xD32MTZ80vrcL44wyldHoNR+H6pItdHcVG2GeAvVqzzPL16HvOmXDkW1lHlQvuaMY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=a9tLM0hN; arc=none smtp.client-ip=209.85.210.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="a9tLM0hN" Received: by mail-ot1-f44.google.com with SMTP id 46e09a7af769-7c6da42fbd4so5176949a34.1 for ; Mon, 29 Dec 2025 16:23:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1767054231; x=1767659031; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=+RDoRKokANdepIDhyxQyq4vbF925RrxH/Z+QkG4Gbo8=; b=a9tLM0hNjSSE91fzQ1QpeMvpOl0uo5IuX9aGYoC8QWvyBhpVcw0U4Es5coQNRx7Sqd /BgOYW+weO+IHSdWeykh1Ov5ULCUmZJ9SkOjiZOfkNSGsXP5feQdcyKET6lLMs8DPuHg EPUqToApjj1fz3C5rWvHQHCKK4GCVzO9wV3RqwlUmIfel2cWZvPsxgpdGzwX0OoChqEC TBePD7kEeGuoZbc5P2e6GxRgu/5qJq/xmbcAtqjlTco1Lwsi4MPb07bnb7FFae+4Urh9 OEa2b/84kKxyomiFfpkPPtvk9YAxrfKBUMV26elVfR5xdSREkr7UQCizgAml83wy6ato QsFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767054231; x=1767659031; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+RDoRKokANdepIDhyxQyq4vbF925RrxH/Z+QkG4Gbo8=; b=MMreNKKGdHP/8MnWED5F817dFxZSCBPpVR68xbxrRFl/776VlsO9tKxW3z4TxGVR+T KyonzOnMrdFymejY3OMmrlRIGosfNUG7wRPISiME2MO06if8T+Z78agv/jCMLKynZ5VZ MkQVQaPKKaLP1kaqgeCqby3rDsF4KcF5SEdG/F9n6qGYmX4JQLuWhh9v7Rl1lbeoylJq x7yxONkIiLyeSWtba7fihTUPGIeBYyyqUtcYMdKzASFcLPmnbXt+3CdNhDuam/iV4677 dxQhGurIywtyw1YmbxwUC2Ps19m9nDdrS3R1wOLgI5edJ5aoUUZjFojgxMeT1ombRS0F wtiw== X-Forwarded-Encrypted: i=1; AJvYcCXzg4wJaotH2zWt1UfPsB3Ruup1mqEqdjiP+J/EFjoqpdjLwjMLCNVTpllyWfu+/1jsX++2kF5vUFZGjJ4=@vger.kernel.org X-Gm-Message-State: AOJu0Yzlk1t0SaX/hVgLFDCZUgr8RftH4sqs9439jyZGpSGFW0CIAP6d bA7ESoyNCxWXXiBp96xrgFsUw4PumlbnqRLkvnrqTHNVD6L9S+N155u+67/8OmLyyzM= X-Gm-Gg: AY/fxX4yQbU/TH/o0AUWDmxmXKGIrmN0lYMGMED0rdR558PL9LbFIeIV+EpeUC/K5v1 kegLe22242E0w8XhYt797sEYHkdjHAm9hetlubbexOetyUMnwmB5aQFwU+S7x3y4B/YCD1yFx4L LoC/h3osxz8vgD9HS4s9NXLYVX0ZgdfKY1USN+m/uiDAmzyZRnbuN+2blZOC939VjZxBmnpLu2k 7PjbZnDuCp+BiyJDsIMcS3vOwER/s9Td6OqE4+E144ydccdRLtlM2wbSbJQ5ENuDzVX8zHpv+wM bCsX3DVG3NV/wsq0lF72c8wfRsFT02Dn8414/q3+qPAaApqSCI5ra7xiji/VyweN+5zcWJUVeYl 6zdOjzaCeDJ2n94TeLkIeLBy8h9UlmJfNh6lkexsAJC5Oe7CqdT0qJizfcLhDqLf4XdXFnik2ru v25bmMPxGwbRF+xyMK8ho= X-Google-Smtp-Source: AGHT+IF8d1u36Kgc5JwULmVoEra16HWhPwx2HAZ3cAPLcIvJC5K74+6HeI1Ad7eg+rTBQW6akrKe/Q== X-Received: by 2002:a05:6830:923:b0:7c7:2d7d:5d0f with SMTP id 46e09a7af769-7cc66a4b655mr16035254a34.20.1767054230681; Mon, 29 Dec 2025 16:23:50 -0800 (PST) Received: from [192.168.1.150] ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-3fdaac145bcsm17848811fac.22.2025.12.29.16.23.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 29 Dec 2025 16:23:50 -0800 (PST) Message-ID: Date: Mon, 29 Dec 2025 17:23:49 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] io_uring: make overflowing cqe subject to OOM To: Alexandre Negrel , io-uring@vger.kernel.org, linux-kernel@vger.kernel.org References: <20251229201933.515797-1-alexandre@negrel.dev> Content-Language: en-US From: Jens Axboe In-Reply-To: <20251229201933.515797-1-alexandre@negrel.dev> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 12/29/25 1:19 PM, Alexandre Negrel wrote: > diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c > index 6cb24cdf8e68..5ff1a13fed1c 100644 > --- a/io_uring/io_uring.c > +++ b/io_uring/io_uring.c > @@ -545,31 +545,12 @@ void __io_commit_cqring_flush(struct io_ring_ctx *ctx) > io_eventfd_signal(ctx, true); > } > > -static inline void __io_cq_lock(struct io_ring_ctx *ctx) > -{ > - if (!ctx->lockless_cq) > - spin_lock(&ctx->completion_lock); > -} > - > static inline void io_cq_lock(struct io_ring_ctx *ctx) > __acquires(ctx->completion_lock) > { > spin_lock(&ctx->completion_lock); > } > > -static inline void __io_cq_unlock_post(struct io_ring_ctx *ctx) > -{ > - io_commit_cqring(ctx); > - if (!ctx->task_complete) { > - if (!ctx->lockless_cq) > - spin_unlock(&ctx->completion_lock); > - /* IOPOLL rings only need to wake up if it's also SQPOLL */ > - if (!ctx->syscall_iopoll) > - io_cqring_wake(ctx); > - } > - io_commit_cqring_flush(ctx); > -} > - > static void io_cq_unlock_post(struct io_ring_ctx *ctx) > __releases(ctx->completion_lock) > { > @@ -1513,7 +1494,6 @@ void __io_submit_flush_completions(struct io_ring_ctx *ctx) > struct io_submit_state *state = &ctx->submit_state; > struct io_wq_work_node *node; > > - __io_cq_lock(ctx); > __wq_list_for_each(node, &state->compl_reqs) { > struct io_kiocb *req = container_of(node, struct io_kiocb, > comp_list); > @@ -1525,13 +1505,17 @@ void __io_submit_flush_completions(struct io_ring_ctx *ctx) > */ > if (!(req->flags & (REQ_F_CQE_SKIP | REQ_F_REISSUE)) && > unlikely(!io_fill_cqe_req(ctx, req))) { > - if (ctx->lockless_cq) > - io_cqe_overflow(ctx, &req->cqe, &req->big_cqe); > - else > - io_cqe_overflow_locked(ctx, &req->cqe, &req->big_cqe); > + io_cqe_overflow(ctx, &req->cqe, &req->big_cqe); > } > } > - __io_cq_unlock_post(ctx); > + > + io_commit_cqring(ctx); > + if (!ctx->task_complete) { > + /* IOPOLL rings only need to wake up if it's also SQPOLL */ > + if (!ctx->syscall_iopoll) > + io_cqring_wake(ctx); > + } > + io_commit_cqring_flush(ctx); > > if (!wq_list_empty(&state->compl_reqs)) { > io_free_batch_list(ctx, state->compl_reqs.first); You seem to just remove the lock around posting CQEs, and hence then it can use GFP_KERNEL? That's very broken... I'm assuming the issue here is that memcg will look at __GFP_HIGH somehow and allow it to proceed? Surely that should not stop OOM, just defer it? In any case, then below should then do the same. Can you test? diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 6cb24cdf8e68..709943fedaf4 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -864,7 +864,7 @@ static __cold bool io_cqe_overflow_locked(struct io_ring_ctx *ctx, { struct io_overflow_cqe *ocqe; - ocqe = io_alloc_ocqe(ctx, cqe, big_cqe, GFP_ATOMIC); + ocqe = io_alloc_ocqe(ctx, cqe, big_cqe, GFP_NOWAIT); return io_cqring_add_overflow(ctx, ocqe); } -- Jens Axboe