From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B377C38A2D for ; Mon, 24 Oct 2022 15:25:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C3AFF940008; Mon, 24 Oct 2022 11:25:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BC472940007; Mon, 24 Oct 2022 11:25:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A40C3940008; Mon, 24 Oct 2022 11:25:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 8EEA3940007 for ; Mon, 24 Oct 2022 11:25:05 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 5AA041608B4 for ; Mon, 24 Oct 2022 15:25:05 +0000 (UTC) X-FDA: 80056216170.28.4725F79 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf18.hostedemail.com (Postfix) with ESMTP id DA0921C0007 for ; Mon, 24 Oct 2022 15:25:01 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 939E521E78; Mon, 24 Oct 2022 15:25:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1666625100; 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=NM/KgVrKralP4JTRInKOEYReTClkj2ojL2ILbxVa1Do=; b=IR0GqbZQTIi+J8BL97b72o11n4G64RRaPTm6Qqg5lsRAG3svoifzLSY7rpPnh8hP00/oN5 UMiIGcQHIHQkYILcwblnXB3127/vw3mSJsg8m6MjtcBJjc3gGSpfzmmv0oZW7AIsPwVEw2 vS6E418MOVXClJL3OLwxOyDIMqEQF8g= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1666625100; 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=NM/KgVrKralP4JTRInKOEYReTClkj2ojL2ILbxVa1Do=; b=6f0QZsVzdtd+WGWoFywA7cc1yelqaD6Coa885+eE0n6EXTcyTOOmrrPfgDT3LCjJUK2OGV aZ9RSKgeX2HHT0AA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 74BD113357; Mon, 24 Oct 2022 15:25:00 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id fefMG0yuVmOpQwAAMHmgww (envelope-from ); Mon, 24 Oct 2022 15:25:00 +0000 Message-ID: Date: Mon, 24 Oct 2022 17:24:59 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.3 Subject: Re: amusing SLUB compaction bug when CC_OPTIMIZE_FOR_SIZE Content-Language: en-US To: Matthew Wilcox Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com>, Hugh Dickins , David Laight , Joel Fernandes , Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, rcu@vger.kernel.org References: <35502bdd-1a78-dea1-6ac3-6ff1bcc073fa@suse.cz> <7dddca4c-bc36-2cf0-de1c-a770bef9e1b7@suse.cz> From: Vlastimil Babka In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=IR0GqbZQ; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=6f0QZsVz; spf=pass (imf18.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666625102; a=rsa-sha256; cv=none; b=1l9Yrm10bZ2cbLfSftdzZ3xORkvxUOpnv8/+gPSRsNmQwcONF2EEVIXH8aJvy6RsXjU08s 8CM4HrSteM5Cvt7E4bfoZWQSE4Y+iVrsmrxDDAZxT8+Zhi2bb7g9iJVb0HjR1soKUU2HZb z2w5N0PB8SXqTSvMqBt1dCWtYzlYHus= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666625102; h=from:from:sender:reply-to:subject:subject: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:dkim-signature; bh=NM/KgVrKralP4JTRInKOEYReTClkj2ojL2ILbxVa1Do=; b=NIDUbJd+HECG5Q2J0dGgEU7leKmwmN1fTZUxudMYf+VtT6pBC5LhBw83F1CZub2lDZdQ0b vxSFDT84KTKzDtO2ro4o0l5cFVjNPY4m18O4aZj0HF+wQU5mKhX8RFTnpNhxR6g1xk/06U QfpIc1wXlDBht3TtemgQR60OGyJkDYE= Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=IR0GqbZQ; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=6f0QZsVz; spf=pass (imf18.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none X-Stat-Signature: ioc918chyqgzaiauy9yzop1u8ojefpx9 X-Rspamd-Queue-Id: DA0921C0007 X-Rspamd-Server: rspam02 X-Rspam-User: X-HE-Tag: 1666625101-384627 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 10/24/22 17:06, Matthew Wilcox wrote: > On Mon, Oct 24, 2022 at 04:35:04PM +0200, Vlastimil Babka wrote: >> I would like to have a working safe version in -next, even if we are able >> simplify it later thanks to frozen refcounts. I've made a formal patch of >> yours, but I'm still convinced the slab check needs to be more paranoid so >> it can't observe a false positive __folio_test_movable() while missing the >> folio_test_slab(), hence I added the barriers as in my previous attempt [1]. >> Does that work for you and can I add your S-o-b? > > Thanks for picking this back up. > >> +++ b/mm/slab.c >> @@ -1370,6 +1370,8 @@ static struct slab *kmem_getpages(struct kmem_cache *cachep, gfp_t flags, >> >> account_slab(slab, cachep->gfporder, cachep, flags); >> __folio_set_slab(folio); >> + /* Make the flag visible before any changes to folio->mapping */ >> + smp_wmb(); > > So what's the point of using __folio_set_slab() only to call smp_wmb() > afterwards? If we call folio_set_slab() instead, don't all the other > barriers go away? (This is a genuine question; I am bad at this kind > of reasoning). Obviously it would still need a comment. AFAIU (which doesn't mean much, TBH :)) folio_set_slab() makes the setting of the flag protected against other flags set operations so our setting is not lost in a non-atomic RMW. But as we are the only one who can be setting any page/folio flag here (isolate_movable_page() for sure doesn't), we don't need it for that kind of atomicity for page/folio flags field. And, simply changing it to folio_set_slab() would not add the sufficient smp_wmb() semantics to order the flags write visibility against a later write to the struct slab field that overlaps page->mapping. Only some atomic operations have that implicit barrier, (per Documentation/memory-barriers.txt and Documentation/atomic_bitops.txt) and set_bit() is not one of those. So we'd still need a smp_mb__after_atomic() AFAIU and at that point, doing the above seems less obscure to me. (Of course if we had the reason to use folio_set_slab() for its own atomic guarantee, then smp_mb__after_atomic() instead of smp_wmb() would be better as on some architectures it would make the barrier no-op).