Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp7326179rwi; Mon, 24 Oct 2022 13:01:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4YA0GmnZPMNhc7SEFEgtFL4aTziJnFuihh6p2RKurzes/Ppi8tyNdln/fwnlg/vuInDKAM X-Received: by 2002:a17:907:94c1:b0:792:56d7:2879 with SMTP id dn1-20020a17090794c100b0079256d72879mr24409443ejc.144.1666641705424; Mon, 24 Oct 2022 13:01:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666641705; cv=none; d=google.com; s=arc-20160816; b=hpCRCiCXcd8KxXk5Agb2r4CbVEsf8Od6kXvIW4cB+X8oL+gCeZO2QAm5fgxs3+ckgg uiiVDoLl0x/NCqQQPMOqXlTNPal+mJdPzil6ggccu7KjheGpG6epDso7YLxUSbaCsdK5 /c36LT3R4NmivyDaF+I4Gxs8NbuQma3QONArjpYY9xulV02sOpk7OHUbtF+/3HonL7w4 GHa6pw/WYcUttCcrRQde8zXTpA9BumekAZhelk0dtT3mfho8jcHUhqEo/2CFSWEmrHtD ONpScVuB3TFaUIffNQgar0jDeEIE0xUeghXWhuyX90IUuAx+A9pik0v2dEOrbtmB1OR3 QcWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-signature; bh=NM/KgVrKralP4JTRInKOEYReTClkj2ojL2ILbxVa1Do=; b=gQf2+MoKWnb8KShEruAh03w0DdqHoI2HP/VV0KzEP1zKhPDE0MkRAtI4YCG7rfbX2+ K+aykLXDaKQkgZ+gfEFJXEKKuU/5DQw0cS64MldjfknE50e6cBODZGohkJ5HEkZslShC 3PrNdMQP8zqluuwYtTKMBTDhEo1jIYBNMaQO6h47vF2V7VATxPzJQuAFdTBFw9N/yO7C B69/F0e/oTOa07XbKuG6jxEevLpeqBkzZi2+qUKFEhtw2KjZ3sZ0naE2h2r9zZDpUrBd hT075xZXJAeNdiTRLMMqtZAF5nNT7Pg5i/0ZLygUfuqFrJgnkKVIwzf/8PitGbVOM5y6 5LVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=IR0GqbZQ; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qk6-20020a1709077f8600b007aa784a3cb8si714445ejc.687.2022.10.24.13.01.19; Mon, 24 Oct 2022 13:01:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=IR0GqbZQ; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231318AbiJXTTt (ORCPT + 99 others); Mon, 24 Oct 2022 15:19:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232392AbiJXTTD (ORCPT ); Mon, 24 Oct 2022 15:19:03 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85EB8659F6; Mon, 24 Oct 2022 10:55:28 -0700 (PDT) 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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_SOFTFAIL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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).