Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp357243lqp; Thu, 21 Mar 2024 03:37:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWIAaJBS0eJ0ZYtP2hAlzWS3RwQ7vZXbts9U9nzxr+3Q3uzcwN9TCw8tfj74PkcAC512+5A+39DHqSpOQyWW/eBHnzk6rAAQlbty+JA4Q== X-Google-Smtp-Source: AGHT+IGilSKfl1JdAbLhvyPDDw9++BUB8thOse4KsykgufeUkjH2+/4sciiyab4fjLzrzG0AmVAI X-Received: by 2002:a17:90a:3481:b0:29d:d93a:d6e7 with SMTP id p1-20020a17090a348100b0029dd93ad6e7mr8697834pjb.26.1711017429030; Thu, 21 Mar 2024 03:37:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711017429; cv=pass; d=google.com; s=arc-20160816; b=wFcWng1ljgI/rM8IDWy54u0P13kWuMX4rWHdyWrR28pjBYrzKYiOpsR+HQJvMk9Sfa nHd8NdjmgS23N5GpzJ8FdcL8rnYqFd+5vV0tkd39p+KFbWfWTLbcG/EyPExKi5NGI83u saUnHksxlQLzd8ObtjLv63ahDWpfFxGYPkVGPnBpsI19tqY5J4YQTHGlXDBXkrqr79n8 KO55SQXir6lzOeQADaDYi3d/bhpy5w24Fq0Df1Lvf7h6YKgFbfs5oyNGjQ9np8o0eK4+ CQLVvASlUjjC/S7NgwYnAkL5UBocpQzb4RQeyg1pVMHdhptiYa1fASrh/YUSWkVD7adg dlxQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature :dkim-signature:dkim-signature:dkim-signature; bh=qrUdzGmZxUrHcwBEsnHbHsFb6putT1o5r8sGWCVKxZE=; fh=Jo6u7g3+m7cx6EQGVKGJrl3rAw6mIF6NolAGmUfoI2U=; b=wOJlZNGXP2VIB98rkWztLYUmH6uOlAI+3C/q07GHrqChYLzvv55/KYtjWb4CVxu8Wg wvWdgLslsLtvdNvsL7UQuJZ1byf18I+u/f2UKG9CsvhDLs23gYZtqJaRXw98teLoFLf/ vUQLZHNUreFe7XIXv+yB591hFX1X4naI3tDRw+hWQ00dgwGYZFj+5iX3znUOQWTaZrRD b8/+csz4o20ElxPLTUPqI75dMOgr6wotUpC/jdkf5iUrYykCw4WlzH6JeSaFBUsQY0LN EcCj+Vqk3OmsaZ0uhvCBLY7IcRvvRxSepNHKkT+xsuyqR8hhjujDX+k0O4z3Sz48RuTQ qaCg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=BbPO6PGh; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=QXQXMhSU; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=T+Ezg7cD; arc=pass (i=1 spf=pass spfdomain=suse.cz dkim=pass dkdomain=suse.cz dkim=pass dkdomain=suse.cz); spf=pass (google.com: domain of linux-kernel+bounces-109903-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109903-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id x90-20020a17090a6c6300b0029958f76832si3284504pjj.179.2024.03.21.03.37.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 03:37:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-109903-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=BbPO6PGh; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=QXQXMhSU; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=T+Ezg7cD; arc=pass (i=1 spf=pass spfdomain=suse.cz dkim=pass dkdomain=suse.cz dkim=pass dkdomain=suse.cz); spf=pass (google.com: domain of linux-kernel+bounces-109903-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109903-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B00CC284528 for ; Thu, 21 Mar 2024 10:37:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9A4B656B9F; Thu, 21 Mar 2024 10:37:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="BbPO6PGh"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="n26LMD+u"; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="QXQXMhSU"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="T+Ezg7cD" Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (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 B630A56766 for ; Thu, 21 Mar 2024 10:37:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711017422; cv=none; b=ZaBlgkSy6g/zJafFZWWb/0d12H2y2uH8islTfL4aO3/VJe3AsCATkBuMEay9NchX5ThiD5T85eELOGRxFLOp/3MWL1tNPEEcLMDds2xWTi+inWMeTFdFnDYS4AOLTNXT325gCp75KonsQ2xUF+4kHZesGSZkesYt/EBOASqlzfc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711017422; c=relaxed/simple; bh=7i50QrITbUsGiZ+KpquvMbAgXC7O2jDc5g3kQXOAhkc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Q/1mc5CjbhIYneIPGNWdKT1DdwA2SxFGbJpj00opwkCt6fL78+G2fSTPBH8r7p0sqJfdjb70V/k56XRRSS6jg1bJVNasxzN4ON+ZxSzU/dE/VjopElbtQLxRs448ewocdk1VBdF3kj0dDts5SIGHw8cXKRU+apWnfAndeXWAuwI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz; spf=pass smtp.mailfrom=suse.cz; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=BbPO6PGh; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=n26LMD+u; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=QXQXMhSU; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=T+Ezg7cD; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.cz Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 01CD05CC60; Thu, 21 Mar 2024 10:36:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1711017419; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qrUdzGmZxUrHcwBEsnHbHsFb6putT1o5r8sGWCVKxZE=; b=BbPO6PGh3EgaMNUVfDcWNqgrBPxVoHeBGq+cDiTyeqGO7bpV4QkaMrHfxIwF37VLoa62AG 1kUUVX5uRiAtTDrAqsF8s0P/xQtuDrcNXVRwgkMbIkM+Xh2rqFygQnd4DeSj+tBJeBngVg ruZjXMovT8N2pLmYJ1lSalnBWUA0GqI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1711017419; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qrUdzGmZxUrHcwBEsnHbHsFb6putT1o5r8sGWCVKxZE=; b=n26LMD+uKQ5LYmwOgYlz3/RzWELw/fdblv83H0njtvrAsU8h04OI4+26z/XnGZItZsjIwU yadLNY+CtzmhdGAQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1711017418; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qrUdzGmZxUrHcwBEsnHbHsFb6putT1o5r8sGWCVKxZE=; b=QXQXMhSUoTyMOk6lCDl8D4amQh693Fkn/Qm1D4p1cwrRvavAmfzglSnbhPsMKLYtz7cGqK RhxZIpBaAflapVNvPnUjVfRgb7+op4tUe5W2+srZPQxjXX5pcCYpwLhHZCaRbm4cdcqACu lb7bOXMqfXyC/jLeqMbAdQlusxZfb28= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1711017418; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qrUdzGmZxUrHcwBEsnHbHsFb6putT1o5r8sGWCVKxZE=; b=T+Ezg7cDMAgwTycg3GetI6HynCAGs7mkbKj2I8iu0LgVsmeCZg5C8DAzmhw4ZGCQaG8cN0 zWX494RdbUryQuCg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id DCA06136AD; Thu, 21 Mar 2024 10:36:57 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id azc/NckN/GVtIQAAD6G6ig (envelope-from ); Thu, 21 Mar 2024 10:36:57 +0000 Message-ID: <71e4b82b-8f32-41f1-afd1-5238e88bf0e7@suse.cz> Date: Thu, 21 Mar 2024 11:36:57 +0100 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 v2 1/2] mm,page_owner: Fix refcount imbalance To: Oscar Salvador , Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Marco Elver , Andrey Konovalov , Alexander Potapenko , Tetsuo Handa , syzbot+41bbfdb8d41003d12c0f@syzkaller.appspotmail.com References: <20240319183212.17156-1-osalvador@suse.de> <20240319183212.17156-2-osalvador@suse.de> Content-Language: en-US From: Vlastimil Babka In-Reply-To: <20240319183212.17156-2-osalvador@suse.de> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Score: -2.79 X-Spamd-Result: default: False [-2.79 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; XM_UA_NO_VERSION(0.01)[]; TO_DN_SOME(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCPT_COUNT_SEVEN(0.00)[10]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; MID_RHS_MATCH_FROM(0.00)[]; BAYES_HAM(-3.00)[100.00%]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TAGGED_RCPT(0.00)[41bbfdb8d41003d12c0f]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-1.00)[-1.000]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.cz:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FREEMAIL_CC(0.00)[vger.kernel.org,kvack.org,suse.com,google.com,gmail.com,i-love.sakura.ne.jp,syzkaller.appspotmail.com]; RCVD_TLS_ALL(0.00)[]; SUSPICIOUS_RECIPS(1.50)[] X-Spam-Level: Authentication-Results: smtp-out2.suse.de; none X-Spam-Flag: NO On 3/19/24 19:32, Oscar Salvador wrote: > Current code does not contemplate scenarios were an allocation and > free operation on the same pages do not handle it in the same amount > at once. > To give an example, page_alloc_exact(), where we will allocate a page > of enough order to stafisfy the size request, but we will free the > remainings right away. > > In the above example, we will increment the stack_record refcount > only once, but we will decrease it the same number of times as number > of unused pages we have to free. > This will lead to a warning because of refcount imbalance. > > Fix this by recording the number of base pages in the refcount field. > > Reported-by: syzbot+41bbfdb8d41003d12c0f@syzkaller.appspotmail.com > Closes: https://lore.kernel.org/linux-mm/00000000000090e8ff0613eda0e5@google.com > Fixes: 217b2119b9e2 ("mm,page_owner: implement the tracking of the stacks count") > Signed-off-by: Oscar Salvador With the fixup, Reviewed-by: Vlastimil Babka But I think you'll need to resend with the missing hunk already applied, it had broken whitespace in your email and IIUC this is was dropped from mm tree. Also I'd suggest a change: > +++ b/mm/page_owner.c > @@ -196,9 +196,11 @@ static void add_stack_record_to_list(struct stack_record *stack_record, > spin_unlock_irqrestore(&stack_list_lock, flags); > } > > -static void inc_stack_record_count(depot_stack_handle_t handle, gfp_t gfp_mask) > +static void inc_stack_record_count(depot_stack_handle_t handle, gfp_t gfp_mask, > + int nr_base_pages) > { > struct stack_record *stack_record = __stack_depot_get_stack_record(handle); > + int old = REFCOUNT_SATURATED; > > if (!stack_record) > return; > @@ -210,22 +212,18 @@ static void inc_stack_record_count(depot_stack_handle_t handle, gfp_t gfp_mask) > * Since we do not use STACK_DEPOT_FLAG_GET API, let us > * set a refcount of 1 ourselves. > */ > - if (refcount_read(&stack_record->count) == REFCOUNT_SATURATED) { > - int old = REFCOUNT_SATURATED; I think this was useful optimization in that most cases the count is not REFCOUNT_SATURATED so we don't have to go for the expensive cmpxchg all the time. Or do I miss a reason why this was changed? > - > - if (atomic_try_cmpxchg_relaxed(&stack_record->count.refs, &old, 1)) > - /* Add the new stack_record to our list */ > - add_stack_record_to_list(stack_record, gfp_mask); > - } > - refcount_inc(&stack_record->count); > + if (atomic_try_cmpxchg_relaxed(&stack_record->count.refs, &old, 1)) > + add_stack_record_to_list(stack_record, gfp_mask); > + refcount_add(nr_base_pages, &stack_record->count); > } >