From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) (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 41D643BC4E6 for ; Tue, 20 Jan 2026 21:45:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.65 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768945515; cv=none; b=R46FCQua4yZ2IxW9u7ctVksrOdFBARgDWPnqIo1qrvtqLpqTMuRGDu0JYf2ns0HDMj/2SFLqshNAajGKKdSZxe+4aAIn9W3R29eKE8OaUdb6Go8+cn4vY+wHuVcx+LAOclngj3R9pLWEiuUnTJRhLRr5zCYtRUaZOIiijPuuC8o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768945515; c=relaxed/simple; bh=IA85NpiEAZDIPExWUQuK3efPNcrbbelJ5Re9MvHChCY=; h=Message-ID:Date:MIME-Version:From:Subject:To:Cc:References: In-Reply-To:Content-Type; b=WPiWBCNGbm3xFAC2tIZH4aBT5epQjyUbaL26lTEApUCsQ39fd9OyRe+vv2ZsQBPv9tHjL9MQRU/fBsV0PgnZJdANpIjO/ZygwgpQdaPsSRKgSvUmrJcO1oIqYayRPQCB3JJK95fGF6iSWEkdq3ku6zkx3HYzXeC7lfHz296lIss= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=cOy0STUX; arc=none smtp.client-ip=209.85.128.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cOy0STUX" Received: by mail-wm1-f65.google.com with SMTP id 5b1f17b1804b1-47ff94b46afso2253975e9.1 for ; Tue, 20 Jan 2026 13:45:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768945511; x=1769550311; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:from:user-agent:mime-version:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=76GjIwmmNHDMhjPHVEUL/aP6yXjFQm32bCZZwJGshzI=; b=cOy0STUXyfkIA+payp5Ls08sBadmogXDqpUYqFHgWdikw2AGH9R8qslDu2mrMjaCRW S4RgtluReHUmRKQR+JWkZkD/r5cdaVjjHeIRDlK9wLH4Jq/X/G7L2x+qhbU1MHSh1WxA aek3V90/9CI1Cfi/IeLIFNFPrTlgsSk7YfRiMF4+vUEkr4V18EJlSN/zFjsi6QO1mWS7 wfN/yKa337pDAh4fGByx9Zj2l2c/xwlVDS5i81luAPff9yLdSGksGjPb0RUR5fAAVcNn JS2gTJ6etLB2F6Ss7t+oEIiT7iD8dJqROLlGgg384j9joMu1rkGXJQedNPyNlXHc//Oj XFTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768945511; x=1769550311; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:from:user-agent:mime-version:date:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=76GjIwmmNHDMhjPHVEUL/aP6yXjFQm32bCZZwJGshzI=; b=dcf7pNXE4S6mJEeE+fjG1cnseho37RaFNaDZ815u87M2PWZRxqCJTUCph4dycpPgth 3FNPSPCTz4YAwmIoUTYA7N3eU9Mvl4viumn9ivhIfkBECBbZ2PhjnvJKI0W1Dv5uA0mw xtUZRXvKyqpAB833Ia9nU0zuXYcKr592liUS0+AbJADCStADNQwBZ3OZSXqETsLmXNp7 qnvTpnj+CfTq0wL+D2Gr5J7uBsX6KAdNU/Tva96NohrYG/2EMApzdG0wkru4nLjvTlIa TD72/Loo4NOPRuDutZDSKXu7ElcUiO+oRpFk6Ub1lAxvohjdoxZEYhSH4fwhvevH+gJP aDmg== X-Forwarded-Encrypted: i=1; AJvYcCVeZhzXkza4UXl3LYvu3KMLutC2SZdbsHIZw2yQHNlzEf18QXuOoX+N7Gvj7riLTjuskuL6KfZ32arrBNk=@vger.kernel.org X-Gm-Message-State: AOJu0YwBcaoaKx/9GJyCeDXpdMZr5wZcxaYzqDYlNqfCihGjJhCa4/NH C5Tykqn2qjY/Zp4bmQgxsmPF/3Jk7pkxUYVl7tIEz1Ss+MAT+097tXoJ X-Gm-Gg: AY/fxX7e0yU276yjh/nSwgfjcDTQM5wCxJMThpe0vDFOkgdM2YjfAciRS1xBLaLrR8Z lKNnWTPWmu0c9EypTk96hZK/U19qfWNbopXqgAS2ksUAjzZ7AG5fD2JXaIeovV2TMWhNKwafm+/ WSVb3Eoljv2XGmO2b1APAvL9M6jOM/4WLyxf4FIWag4CusDsB0lntz/QLXSjfWL63IdW6AJ7zb4 ClfrKs9dRktW5RczcyqHqaKeKHRu+u6v0tLbd0KoUElKvM2F/ENIkj6WS8hg4kry579lXTgWrs5 yMpZHQAqV5FogisusQIm1+2OQzFw2whUvPVhhCGzjY3LHP6In0zhbph8uol5lzB1+k5aktjjyK7 gsfn0wcY0RemzdD0CmJtjAF8K3cOYO+B2UFU1HJxwXE4gMQU9kxcXGwVPhMiGxofR7OzMS7FEXw 9moyDcPCLK2T+mIZW+tOlM3Q5ecsaFao4jcXknqXRkZH0SHG3bgtE4KRMvNL0xf74930ackRqHO UVFa+TcWJvPsJKSxQbJi/262T4AU7Uil/pVEUq4obhckhwxBqAeRgufwR8uP8gdhw== X-Received: by 2002:a05:600c:17d6:b0:47e:e97e:11aa with SMTP id 5b1f17b1804b1-47f4289ac52mr168292055e9.4.1768945511265; Tue, 20 Jan 2026 13:45:11 -0800 (PST) Received: from ?IPV6:2a01:4b00:bd21:4f00:7cc6:d3ca:494:116c? ([2a01:4b00:bd21:4f00:7cc6:d3ca:494:116c]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4801e886829sm264939395e9.8.2026.01.20.13.45.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 20 Jan 2026 13:45:07 -0800 (PST) Message-ID: <2be71481-ac35-4ff2-b6a9-a7568f81f728@gmail.com> Date: Tue, 20 Jan 2026 21:45:05 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Pavel Begunkov Subject: Re: [PATCH v2] io_uring/rsrc: fix RLIMIT_MEMLOCK bypass by removing cross-buffer accounting To: Jens Axboe , Yuhao Jiang Cc: io-uring@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org References: <20260119071039.2113739-1-danisjiang@gmail.com> <2919f3c5-2510-4e97-ab7f-c9eef1c76a69@kernel.dk> <8c6a9114-82e9-416e-804b-ffaa7a679ab7@kernel.dk> Content-Language: en-US In-Reply-To: <8c6a9114-82e9-416e-804b-ffaa7a679ab7@kernel.dk> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 1/20/26 17:03, Jens Axboe wrote: > On 1/20/26 5:05 AM, Pavel Begunkov wrote: >> On 1/20/26 07:05, Yuhao Jiang wrote: ... >>> >>> I've been implementing the xarray-based ref tracking approach for v3. >>> While working on it, I discovered an issue with buffer cloning. >>> >>> If ctx1 has two buffers sharing a huge page, ctx1->hpage_acct[page] = 2. >>> Clone to ctx2, now both have a refcount of 2. On cleanup both hit zero >>> and unaccount, so we double-unaccount and user->locked_vm goes negative. >>> >>> The per-context xarray can't coordinate across clones - each context >>> tracks its own refcount independently. I think we either need a global >>> xarray (shared across all contexts), or just go back to v2. What do >>> you think? >> >> The Jens' diff is functionally equivalent to your v1 and has >> exactly same problems. Global tracking won't work well. > > Why not? My thinking was that we just use xa_lock() for this, with > a global xarray. It's not like register+unregister is a high frequency > thing. And if they are, then we've got much bigger problems than the > single lock as the runtime complexity isn't ideal. 1. There could be quite a lot of entries even for a single ring with realistic amount of memory. If lots of threads start up at the same time taking it in a loop, it might become a chocking point for large systems. Should be even more spectacular for some numa setups. 2. Most likely it'll further relax accounting (i.e. one way road), and I don't believe that's the right thing. Could even be unexpected if consolidated w/o any explicit communication b/w rings (like buffer cloning). 3. Map keys will need to be {page, user, mm}, so I suspect impl is not going to be exactly trivial either way. Maybe some nested xarrays + something for counting middle layer entries. -- Pavel Begunkov