Received: by 2002:ab2:2994:0:b0:1ef:ca3e:3cd5 with SMTP id n20csp765904lqb; Fri, 15 Mar 2024 06:07:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWwqTwZMjI7thiNVxDic/mJGKm6hqXu8O/fhp0tD9Wo9HC+88Jf4ofWjN8XQgU2+5ypqZ42dO0eCjOc83U6t6+Xsd5GRjuX0gyfnC944Q== X-Google-Smtp-Source: AGHT+IGzn8yVZvP1vmkZ3c8tAgq3gf2h+oqG7pcalaFUHVstbdv6y/V6hikIuL/25aoIAPAeHraB X-Received: by 2002:ae9:ea04:0:b0:788:3101:b1f0 with SMTP id f4-20020ae9ea04000000b007883101b1f0mr4596420qkg.64.1710508075456; Fri, 15 Mar 2024 06:07:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710508075; cv=pass; d=google.com; s=arc-20160816; b=oqbjvA+5xpQ+VSv7ttqHXzmcyU8KEuLgzNisOC9eKRRCYgVjC5fR8uceS/q7oHJ+Jl PkegnEdTu5gLJ2Kmkg7JMGk1bVAWVEExn5nft/Wl5M75gxZ9XjYDWFMzKQMCTGga/BxU Za1aOCmV6yOI9rPkefs3ungN3sPLJ7T/JzSsfpkUbWv4dhRdk/YaB6AKS7ApfAUM+555 UkcEWUaUi8GkLJwUDn3lT9v/NcmBbCKlExH1Dcw1gyzn7BZL+roRCTC39N/vUuNjSjFJ Npxmwk9Lp3NYWj5hz5dIrDJWl12ZpgKPt2hJstkTnrt11Pkw+HwF7lNqudn/riZ4v/W6 5Rpg== 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:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature :dkim-signature:dkim-signature:dkim-signature; bh=UNb4nW2xcC1S94ZTnXVVn5Q1xi4EnOrvKCc0jSiOkq4=; fh=Y4dxnW1/QzdWwCLFSwRGbbxHIEpEwGYbtdT1xeEyRq4=; b=ZsSQ72k66aKf49jmZvEkniSYup7YzrgshrrSuyJRryaCqAvu3Dii66T90Lf/UzNDYf yV/gpHG2j6EGoAhEzKd8BPVWF8//RfbuGXaGlfkMas/v6TmTagv0zl5LvzJVyRlxEE1c 8wTSOz8EFhYEPVdXDU6XUtxUz2DI4qqzF6oDgE3kIFXnbDcX/84UO9boHFlOL4AjLstr pc5yRCi9HR9dfVMW0S1ama0oZ97JA70c5vqxTIt0s2Zlm/xB2HebhCIGE7thXSNlA8ww WOFSh9DRAdwdkcmb38252LzfndWliLJ/CAJJyutwMHOhxa/I4M/VkIKGlyKLrDXcjrBq f91A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=UOnbzokV; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=UOnbzokV; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; 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-104437-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104437-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id z6-20020ae9e606000000b00788320b6285si3594090qkf.683.2024.03.15.06.07.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 06:07:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-104437-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=UOnbzokV; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=UOnbzokV; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; 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-104437-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104437-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 225CB1C20C6A for ; Fri, 15 Mar 2024 13:07:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6F83D36B15; Fri, 15 Mar 2024 13:07:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="UOnbzokV"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="yqgsxWh4"; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="UOnbzokV"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="yqgsxWh4" 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 7FCFE36AED for ; Fri, 15 Mar 2024 13:07:47 +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=1710508069; cv=none; b=K+kbqjZIpjKp2RmBsfs/02c6Uu5sOgJw48ZMxtG8I6tqSEqnV6rNHqdxRXSOIeODxvz6MvU9ubzPc8mcXO+vmwpyU4/hhFl13lGeeqnuXFi8F+RrgeYqKoRPksn5iUD9Wt64ri5AHgUMC/gVZlMeKvvqiyJzu9j/EVIQu/aySh4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710508069; c=relaxed/simple; bh=mSohghLDJbp7142TrJKBKFeVxl4X6hCtsSehtNibEsw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=fqcYVXn2O32W82EXpt+nlo7kzDbWmJOPj2qiPyV9KQKw7zS359QU7IgvihbHDcTMs2EWbCYO9XNHHCBIk04pF6zA1LTYTsWHCyvUogvGKPL8oac0eS5S5X8S0EaP8yp4GFP5G4id9qjHXgjqeIIl66kQe8WQD39TYs8XQEnP/74= 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=UOnbzokV; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=yqgsxWh4; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=UOnbzokV; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=yqgsxWh4; 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 [IPv6:2a07:de40:b281:104: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 879881FB63; Fri, 15 Mar 2024 13:07:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1710508065; 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=UNb4nW2xcC1S94ZTnXVVn5Q1xi4EnOrvKCc0jSiOkq4=; b=UOnbzokVpaISeHhqtQu7ppsFLwcFl+UAfZyMYUt/+B98tl1wHEyZNnIlS42ZEhjGd87XNb PAWbFqH/cvMcoXtpY3a5BcJ7OxDqcsyQO1b1rPlttp7DrSDAgTke46qzPcvboa4/f33n9f IvSK4R9XvvkERRDKBd3xuiLhTjUu9h0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1710508065; 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=UNb4nW2xcC1S94ZTnXVVn5Q1xi4EnOrvKCc0jSiOkq4=; b=yqgsxWh4wuRpVXb6X+sty568bStfsC/RERcqFnyydjWWv6Kj67cCkABvD8fGbeAnTND9Ai GPfyPfEDhWaTf6Cg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1710508065; 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=UNb4nW2xcC1S94ZTnXVVn5Q1xi4EnOrvKCc0jSiOkq4=; b=UOnbzokVpaISeHhqtQu7ppsFLwcFl+UAfZyMYUt/+B98tl1wHEyZNnIlS42ZEhjGd87XNb PAWbFqH/cvMcoXtpY3a5BcJ7OxDqcsyQO1b1rPlttp7DrSDAgTke46qzPcvboa4/f33n9f IvSK4R9XvvkERRDKBd3xuiLhTjUu9h0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1710508065; 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=UNb4nW2xcC1S94ZTnXVVn5Q1xi4EnOrvKCc0jSiOkq4=; b=yqgsxWh4wuRpVXb6X+sty568bStfsC/RERcqFnyydjWWv6Kj67cCkABvD8fGbeAnTND9Ai GPfyPfEDhWaTf6Cg== 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 748A51368C; Fri, 15 Mar 2024 13:07:45 +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 bd4ZHCFI9GXQIwAAD6G6ig (envelope-from ); Fri, 15 Mar 2024 13:07:45 +0000 Message-ID: <3bd30334-0a46-4050-930f-7f606a72b3e7@suse.cz> Date: Fri, 15 Mar 2024 14:07:45 +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] mm,page_owner: Fix recursion Content-Language: en-US To: Oscar Salvador , Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Marco Elver , Andrey Konovalov , Alexander Potapenko References: <20240313234245.18824-1-osalvador@suse.de> From: Vlastimil Babka In-Reply-To: <20240313234245.18824-1-osalvador@suse.de> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Score: -5.03 X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Flag: NO X-Spamd-Result: default: False [-5.03 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; XM_UA_NO_VERSION(0.01)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; DWL_DNSWL_HI(-3.50)[suse.cz:dkim]; NEURAL_HAM_LONG(-1.00)[-1.000]; BAYES_HAM(-0.03)[55.66%]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.cz:+]; MX_GOOD(-0.01)[]; RCPT_COUNT_SEVEN(0.00)[8]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; NEURAL_HAM_SHORT(-0.20)[-1.000]; FREEMAIL_CC(0.00)[vger.kernel.org,kvack.org,suse.com,google.com,gmail.com]; RCVD_TLS_ALL(0.00)[]; MID_RHS_MATCH_FROM(0.00)[] X-Spam-Level: Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=UOnbzokV; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=yqgsxWh4 X-Rspamd-Queue-Id: 879881FB63 On 3/14/24 00:42, Oscar Salvador wrote: > Prior to 217b2119b9e2 ("mm,page_owner: implement the tracking of the stacks count") > the only place where page_owner could potentially go into recursion due to > its need of allocating more memory was in save_stack(), which ends up calling > into stackdepot code with the possibility of allocating memory. > > We made sure to guard against that by signaling that the current task was > already in page_owner code, so in case a recursion attempt was made, we > could catch that and return dummy_handle. > > After above commit, a new place in page_owner code was introduced where we > could allocate memory, meaning we could go into recursion would we take that > path. > > Make sure to signal that we are in page_owner in that codepath as well. > Move the guard code into two helpers {un}set_current_in_page_owner() > and use them prior to calling in the two functions that might allocate > memory. > > Signed-off-by: Oscar Salvador > Fixes: 217b2119b9e2 ("mm,page_owner: implement the tracking of the stacks count") > --- > mm/page_owner.c | 30 +++++++++++++++++++++--------- > 1 file changed, 21 insertions(+), 9 deletions(-) > > @@ -292,7 +302,9 @@ noinline void __set_page_owner(struct page *page, unsigned short order, > return; > __set_page_owner_handle(page_ext, handle, order, gfp_mask); > page_ext_put(page_ext); > + set_current_in_page_owner(); > inc_stack_record_count(handle, gfp_mask); > + unset_current_in_page_owner(); This is because of the kmalloc() in add_stack_record_to_list() right? Why not wrap just that then? > } > > void __set_page_owner_migrate_reason(struct page *page, int reason)