From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yb1-f182.google.com (mail-yb1-f182.google.com [209.85.219.182]) (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 17BD58F6D for ; Sat, 1 Mar 2025 02:23:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740795792; cv=none; b=Y0u17m0r9M/xhkw70k4tXvpwVTzjVPLVX0B664HqnnYNwwJLhbglbOzbR1WgocNMI8zHFqN7IcM4BtnnpRQBXf76mj+8Ox8YR2LO17dx6mUJfXcNY0lBPijVrRui3fWS5ibeGX0wp1FVKY3WXClz3NWL3xu8sJtVbcX01tk0Xnw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740795792; c=relaxed/simple; bh=dN7+jbLvdrjoCYACNXJOboSenKJHSzfm8DdHlgv5eZ0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=A68xjnpcne6S42cB5pJyL6eGpgNK/4HobO4Py70Xv59VjakyZ1MfHobT4FK5FVRBxMAPsnBps2I7YeaaC12lkpyChlJz1M4BI53J7Y8AendbRKqCvSScoN4afyrN/Ya/fT8CX0rA8KrzljIX4MlqUKiXrJyLl/gVK5DLgmiELxw= 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=M4/5VZ5B; arc=none smtp.client-ip=209.85.219.182 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="M4/5VZ5B" Received: by mail-yb1-f182.google.com with SMTP id 3f1490d57ef6-e60aef2711fso1304078276.2 for ; Fri, 28 Feb 2025 18:23:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1740795790; x=1741400590; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=3D2yUW+yXVZtZOlbSSXTDdpZguZmzr8vchGBhO965wE=; b=M4/5VZ5BdQ24KHJufBzAW6ar0figzzxTaDowflwt4U18FOUcwsdLZ7ffBQDXsHHpWM UXzVW8HHdQuiFKWcdqaGUy1qdxXgUoLdEESONrA5TsDVgjJjM1fEuBr+rRlwHdZRbPqd QIYT1pkSI7miYAu6KjqAAYgt9TTF6uEZlFUY1fH+UBn5gvKRhj9QmmdfK6GIy7lj4gRK xeEKLcpSVB2IEmxgGHiWQAQU8y/wYgvpnmNoomFS9J2NT5LUiS2/LMqtWVcfBTRsBMua DFWYAbu+9q7v9W6QbmmpSqub23SGcG8Gagvmf4hrgmQUIMnssk9CVJxKf2mXJI3hxMVr 2cKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740795790; x=1741400590; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=3D2yUW+yXVZtZOlbSSXTDdpZguZmzr8vchGBhO965wE=; b=jQM0jkpviHcgz4GFfGd2dqJrq4IOAc1OdZR7pHozNY7yVa60gOIoN0EU0XQXyH0Ysy 5ikwZbb3KnIKPshqNWJhKRjxFfTMvGy918S88+RlAcJRSin9UsQJrHTEowVwS6sWG7gS DbgDZFgjOcCVtGGjT+qNo4CJDTdFdEOzxzyNo4Zdnhdy5MbikgIy47oDeq/5fqJzz3k6 zSlLFjtILJYSZZ9x9e92AebqYaMzhgrQlkBnkxRBK7wiC+XJVO0Oce+Wpdl5Z1SswV3X 8FiPGGaHU3wzPbjH3ZRa5ZlRiCF9iDtimej+7zgIejLlIww62U/b4rHddTQYklx23KnZ UQNw== X-Forwarded-Encrypted: i=1; AJvYcCVLLBsuu+CiTRK5r5SC+GDCTT3EXn4Sqx5Mu3zIfTjlmHX9AuPzslpg0sMJDJETCly+8EY+sKFDnDf2Bek=@vger.kernel.org X-Gm-Message-State: AOJu0YxO+rqcWDCR4S0u6mfPBnk6gTjMAgHAfPvB2gfwx0MCoi+hnhMF tLRaLspNJddb12SqEc4OZVuL32LZKJOLPAF/ugq16GAfdnheJ7GdoqZmYLNVXQo= X-Gm-Gg: ASbGnct4W0XtaB+e9pQvJaU5zOrf1qbWlkYsC+rcpCNxyRHvHt7pF729mA4+C8vOmZJ iTkXk7G4mDjrbEWBcnUh65O6XjuSlrtHBVhlgQSlQC2ImNWhjWtjQMYu8UfRBGt4T05Fb5Dwafr R+L1t44BW4GwQGvlXWC3b504cmDa/EHswoT5smbOb4wKrEZM0DWWG0CaqVb+vWiUESaDl2isdJt 1ZEZIgtTD04MVPXBrYngXBB5vFrkgzXEkprK5APMTHcS3fBbZJCH102xmXCwEqN0kt7+E+4iOKj KmbDGiniK4JPZDWtD3O2hOyGgLE9zNAFxJ8qUN4K36Td X-Google-Smtp-Source: AGHT+IEQd7OduGMWpWQcg+VgSc9gz9FauvM9ADdGsZN+Br4JB6r2A4KMSGBo1Ww+P+YbAJSnRG/Ecw== X-Received: by 2002:a05:6902:114f:b0:e57:f8cd:f0a4 with SMTP id 3f1490d57ef6-e60b2f3eab7mr6108309276.34.1740795790027; Fri, 28 Feb 2025 18:23:10 -0800 (PST) Received: from [192.168.21.25] ([207.222.175.10]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e60b557d2f7sm777899276.1.2025.02.28.18.23.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 28 Feb 2025 18:23:09 -0800 (PST) Message-ID: <7d64216e-4bf8-4557-b8a8-7285f161a2a7@kernel.dk> Date: Fri, 28 Feb 2025 19:23:08 -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 3/5] io_uring/rsrc: call io_free_node() on io_sqe_buffer_register() failure To: Pavel Begunkov , Caleb Sander Mateos Cc: io-uring@vger.kernel.org, linux-kernel@vger.kernel.org References: <20250228235916.670437-1-csander@purestorage.com> <20250228235916.670437-3-csander@purestorage.com> Content-Language: en-US From: Jens Axboe In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 2/28/25 6:31 PM, Pavel Begunkov wrote: > On 2/28/25 23:59, Caleb Sander Mateos wrote: >> io_sqe_buffer_register() currently calls io_put_rsrc_node() if it fails >> to fully set up the io_rsrc_node. io_put_rsrc_node() is more involved >> than necessary, since we already know the reference count will reach 0 >> and no io_mapped_ubuf has been attached to the node yet. >> >> So just call io_free_node() to release the node's memory. This also >> avoids the need to temporarily set the node's buf pointer to NULL. >> >> Signed-off-by: Caleb Sander Mateos >> --- >> io_uring/rsrc.c | 3 +-- >> 1 file changed, 1 insertion(+), 2 deletions(-) >> >> diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c >> index 748a09cfaeaa..398c6f427bcc 100644 >> --- a/io_uring/rsrc.c >> +++ b/io_uring/rsrc.c >> @@ -780,11 +780,10 @@ static struct io_rsrc_node *io_sqe_buffer_register(struct io_ring_ctx *ctx, >> return NULL; >> node = io_rsrc_node_alloc(ctx, IORING_RSRC_BUFFER); >> if (!node) >> return ERR_PTR(-ENOMEM); >> - node->buf = NULL; > > It's better to have it zeroed than set to a freed / invalid > value, it's a slow path. Agree, let's leave the clear, I don't like passing uninitialized memory around. -- Jens Axboe