Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.171 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796269389; b=S9RB4rggAl8PmoTunH94ofKfHdQI2wUteRfNLnSo5HXW/eYuiYzx0tRjjXj37VJnVcYm iR27beEA3DqgWA3rQXqFfXbpIWEyaseXXtssPJV5Jr5H4+B2WBtHzV+ZG1R2FF7Zgo1by WXReQ5orzPgV6qRJOoAak4KExQz3cTnJ2gnTbcWmUkvpSw5R9EIKRE2HHp8y/BvZ2mhgh 8kJqzSrtIVckufTNbx5DH1NyWarfUsjIxzru3OMRVhMvLLANIaI5OvNugrnWyFwJl87yZ b5KZ63V1l4We1Lv1lhJx31PYuRlqIBV1zArIHjqRHbVuWS6ypxwN12IX/TdLo5NS+LQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796269389; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Content-Type:Date: Message-Id:Cc:Subject:From:To:In-Reply-To:References: Content-Transfer-Encoding:MIME-Version; bh=SHpqLzNfw6i6HICnZ+Yem4GiuKVjDLZ4Ov6v30+rm3A=; b=rQrGoiB0AepmfyUdIVn8ze7y1KyLFgv1LOhW7Q/54SKyUMz5uuF+fgBdPTbGvY/yiOER g+QsuQ58MO5Mh2A/gTK4ZMgka88Kfw9c4v4R4os5z3gwjed8lhoPnoWn0qtSFeYLkh03q wnlVi44hJYetOcNlK8iClTLxIp6CWG3BNmnOVJ74it71iNII5oJRjTgUBfEXWYsulXFnU DW+V/8vgQdvIomJkInKoUwlCI6Ky+Nig9qC6/fA46Nn3M0FFCHbuYTgIhkyHNxxGdIVv2 ryFrODVRF3fV0kRcyZWUC7sYMO2R0+Mr/8/X8eCmHqlzlbORnLHSucT3yCVA1j4Vq5A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=KZ0MYUMb; arc=none smtp.remote-ip=209.85.214.171 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 20850606A322 for ; Thu, 3 Dec 2026 03:43:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 20850606A322 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.a=rsa-sha256 header.s=20260707 header.b=KZ0MYUMb Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2f046b0adc0so81588695ad.1 for ; Wed, 02 Dec 2026 19:43:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796269388; x=1796874188; darn=vger.kernel.org; h=mime-version:content-transfer-encoding:references:in-reply-to:to :from:subject:cc:message-id:date:content-type:from:to:cc:subject :date:message-id:reply-to:content-type; bh=SHpqLzNfw6i6HICnZ+Yem4GiuKVjDLZ4Ov6v30+rm3A=; b=KZ0MYUMb60Xln/Kq8pOo/5hoE9QM2u0a/ftOhXUZ36Aj07F5Ar17eezV97cKjBpa/3 W+VlXTQZ8LbUtiqs0K6aC2V6+vdBH0Rjp5SV19tPQtsydsKRmx9niXzekK3rsiHgaVg0 M0v2Pi7oNREApqMl7cHfrYpxIi5tZfS2vV38nkBQC960j2wl8vZeldrw7PiaDllngOQ/ 48bVMqkPoCAX9/UPjcxosR+tPDdYPxNj0LWxCJnDoqBKx7wVVw6OPENBs1QogfsCGs93 fcUKqV+RMTEKBnQYBmSLGIug3OGBNOVz53uBFSVCCOt5YA/SztVUWDJgD1b6gPE8lhLS ubKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796269388; x=1796874188; h=mime-version:content-transfer-encoding:references:in-reply-to:to :from:subject:cc:message-id:date:content-type:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=SHpqLzNfw6i6HICnZ+Yem4GiuKVjDLZ4Ov6v30+rm3A=; b=N5bqDQ3RnNFkVega+s3yoEb1Fx/OPH2LeB9zsZUVWUgQlE9wbD2jDWx1k27fyBg345 Advz8cQH3GEgXxTznBAPOSYBBbt6aQReAEJgev47kXi1C+VgQULj6AqKmEzOV7hzobxX Xskiw9LBVKFt9FFOwG6EUFt9CuCUBoRpXNCyLFk+dd7JK1gp55uE6pxwpyV2F/9a0KVj M/bhhy/vorF0hke+4m06861Qxn+90qlXahWtyATfTGOvpJfi2TAfSqVHKRj1kyR/ogai dUurI/50aI0FiT0OEbogbpMRCxN5KxTO49dY6my9a4PnW4pEZXZRPBFVG1Y30efgD5cn U/Pw== X-Gm-Message-State: APuU4Z/apg0E07fln6jUjeY5HjQgXFomh+TzjDVca5Nns9/G79xl1xJb jIqatkqUzOAepT17CcJaOyuPtitWgHFYHCzTByKrSb0Ai3WXf+jpyj/QVfkqYg== X-Gm-Gg: AZFdTZdhY+5m40/EVONUu+C3rQukV9wepEjOVAKirK/Ba3dsdJ74uni0jX0TT8pn0nS xsYEAUBx/pzIdMl+lz2RriOx3T8ouSNuvrlW9QCqTy66PUli5k8HdPSG1LWkO7qlquUZrsCsRaL wxoRvCSn1162RLgjQ/HK/TfJNPq7pPDM+7tfE58BMgelnk+cFAaxH/qsUWsToeknWkNpCYzlmIX 4Iij+LF2oBhFhqq+ZufxgAoeA8/kLVM2ajGwVvZs+/oUqvHbnog8wIbLzvMwoOmsrBVPEx9VwnU RemqcU7CLEA5aL4Z5RAYHg8se6ggcaDuR+taHNtsaIK4PHSOZaMr79ha+gpIDGDflgcBKNt6ybX aBWBb0Qz+nsN5ZkKrQbZS1AEyFUYCtUdOYuHsWmyMhrrOIMLigIRB//louE+4J8dbahgoA0FVcz Fj37JvQ/sFACnKg8jNB1ZcyiAbLJWEKQV0W/fPzw1H47FXioDq/R9eomCbz04cPS1g9od8I8IhI OGtaiSAg1oAMRWxd4PWQWih3pd2eKa0a0Fmy6wCoT/fh+1VRHRfc0nK+dTeAxmJqCEywcbyYBQh O2m4/xVtJLORw5gwEcQvXqagNB7QoPfKPrfGEIcLXqUWgfZRnm498U7RSoap3eFA/tDHAGncsLu fS9OpECl9K+KKsBAy8JRxj+3NmmWvjO5hRw== X-Received: by 2002:a17:902:e847:b0:2e6:5ef:abe9 with SMTP id d9443c01a7336-2f03f151cf5mr358555755ad.37.1796269388018; Wed, 02 Dec 2026 19:43:08 -0800 (PST) Received: from localhost ([153.61.198.248]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f08d73dfe0sm174258895ad.69.2026.12.02.19.43.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Dec 2026 19:43:07 -0800 (PST) Content-Type: text/plain; charset=UTF-8 Date: Thu, 03 Dec 2026 03:43:07 +0000 Message-Id: Cc: Subject: Re: [PATCH] bpf: Bound the resizable hashtab batch buffers by max_entries From: "Alexei Starovoitov" To: "Peng Hao" , In-Reply-To: <20261202053720.92474-1-flyingpeng@tencent.com> References: <20261202053720.92474-1-flyingpeng@tencent.com> Content-Transfer-Encoding: 8bit X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 On Tue, Dec 01, 2026 at 09:37 PM Peng Hao wrote: > A batch never returns more than max_entries elements, so clamp the > buffer size to that. The regular hash map sizes its buffers by bucket > size instead, so it doesn't have this problem. max_entries is not a useful bound for rhash. rhtab_map_alloc() accepts up to 1 << 31 and allocates nothing based on it. A large max_entries with few elements is what this map is for. One element in the map, 4K value, this patch applied: max_entries count max_count result ----------- ------- --------- ------------------ 1 65536 1 fixed 1048576 65536 65536 257 MB, as before 1048576 1048576 1048576 -ENOMEM, as before It's not "never" either. rht_grow_above_max() runs under the bucket lock. Two CPUs insert into two buckets and both see nelems == 0. Then a map with max_entries == 1 has 2 elements. > Fixes: 16b4d3e2fb24 ("bpf: Implement resizable hashmap basic functions") Wrong tag. There are no batch ops in that commit. It's commit 818e00848227 ("bpf: Implement iteration ops for resizable hashtab") Pls cc Mykyta on respin. > + /* A batch can't return more elements than the map can hold. */ > + max_count = min(max_count, map->max_entries); Use ht.nelems, like rhtab_map_mem_usage() does. Then the buffers follow what the map holds. A short batch is not new. The loop stops early on need_resched() today. More than 2 GB of real values in one batch is still -ENOMEM. On top of the patch. I built hashtab.c, not rhash.c, and ran nothing: diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c index ce46faf..0ff2673 100644 --- a/kernel/bpf/hashtab.c +++ b/kernel/bpf/hashtab.c @@ -3503,8 +3503,8 @@ static int __rhtab_map_lookup_and_delete_batch(struct bpf_map *map, if (put_user(0, &uattr->batch.count)) return -EFAULT; - /* A batch can't return more elements than the map can hold. */ - max_count = min(max_count, map->max_entries); + /* If the map grows after this point the next batch returns the rest. */ + max_count = clamp_t(u32, atomic_read(&rhtab->ht.nelems), 1, max_count); key_size = map->key_size; value_size = map->value_size; pw-bot: cr