Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5148671pxj; Wed, 9 Jun 2021 10:12:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoCG4INA7nF1HrwtkmBZMZWR9+a18pA81lYz+PLWh9CNNky5CrwTQLJJfBJtZsZQhxIqBx X-Received: by 2002:a17:906:af7b:: with SMTP id os27mr880946ejb.154.1623258772269; Wed, 09 Jun 2021 10:12:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623258772; cv=none; d=google.com; s=arc-20160816; b=WX9HY0NKksRb1pbI6pn3rKNpH1S3h5cNhWSWPfL48c8Nadb0Jr419OstPAE/HV+Y82 huhliFY3F7pBPJga72fhBGw1vvd/YImIr30PUG2+zW+1eX1ZkHSeCim0QTulfSajrwiC 13aluuGrkI5LPsQnQX5/Wng2K6fOh2YK1vXOEQnumNUAuqypXEoAGnZYGxoKUMAG+QtO wL7DsfjNjcO+zpDup4zB+DRJPGYo5FHscZkW6I4wIHWeITzHGv721GhHK5jx6tER4bou i/M/f6nw6T+Sp7fy/rh6NDWo6yKU9HGrY6Fbpry0e9b5XGIFTiw4Lalf9cVGWK5lfnvK 6DHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature:dkim-signature:dkim-signature :dkim-signature; bh=XW50r/dVGSB8GZhYgnYKju32pddbaWM8FKgjyzfxzdc=; b=BKWEcRWMCCwP3XJQF15pAMOaF6Fs7AWDM8NLpU9CSIv62SopddKiKnI8csZv3VCNwi Mp8Y5vysuc2/e6CDYxRLX658YKdatoUH5ujMneNJB6pcxHWcP/Gnlnn5nmoIx28NaLXA KFMEBNhPfzg1SEaDP0njOAU70KGsegXaS7+v7RBKWOdePAg7NI2G7JkXRW7bBNijlB7G pcAlIeIB9XEfzQhxO2/ELOyFBSw8L5tMQRSqlkXf3m8Sc4H2JGxxq5TiiYd6ExW2donQ ePX1bl8myaTjGiCrImpsDqsMMrW4BoCNx2yHqWodpjc6RzWNkKDe05TK6ah+8dNntXEP W5vQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=Ts9zdesH; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=Ts9zdesH; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e5si279157ejl.222.2021.06.09.10.12.28; Wed, 09 Jun 2021 10:12:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=Ts9zdesH; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=Ts9zdesH; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237683AbhFIInj (ORCPT + 99 others); Wed, 9 Jun 2021 04:43:39 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:54644 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235548AbhFIIni (ORCPT ); Wed, 9 Jun 2021 04:43:38 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 85175219B9; Wed, 9 Jun 2021 08:41:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1623228103; 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=XW50r/dVGSB8GZhYgnYKju32pddbaWM8FKgjyzfxzdc=; b=Ts9zdesHFrCvu5FYB1cN8HQJQto0fnqSf/aSkJQY+FL6Ohhrdukw4yupD8JatkUL7qWuoJ 7lcfSuhPzKi0+jDFYQuzlN4OnXxUr4l2bw85HleDo71XLUe8f8JkgXwbhMN39mfgEVckN6 6bLHi58L+BruKadlUR3hsFwqbbGU7WE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1623228103; 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=XW50r/dVGSB8GZhYgnYKju32pddbaWM8FKgjyzfxzdc=; b=lzOofCO4L+MEvzYmZo7eT1zsHFhf4PCx2jkHGSshPy8rKZpE1o65W3t6YRNhLSAdJVB30z SOal9mAK8P1iAfCQ== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 6149B118DD; Wed, 9 Jun 2021 08:41:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1623228103; 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=XW50r/dVGSB8GZhYgnYKju32pddbaWM8FKgjyzfxzdc=; b=Ts9zdesHFrCvu5FYB1cN8HQJQto0fnqSf/aSkJQY+FL6Ohhrdukw4yupD8JatkUL7qWuoJ 7lcfSuhPzKi0+jDFYQuzlN4OnXxUr4l2bw85HleDo71XLUe8f8JkgXwbhMN39mfgEVckN6 6bLHi58L+BruKadlUR3hsFwqbbGU7WE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1623228103; 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=XW50r/dVGSB8GZhYgnYKju32pddbaWM8FKgjyzfxzdc=; b=lzOofCO4L+MEvzYmZo7eT1zsHFhf4PCx2jkHGSshPy8rKZpE1o65W3t6YRNhLSAdJVB30z SOal9mAK8P1iAfCQ== Received: from director1.suse.de ([192.168.254.71]) by imap3-int with ESMTPSA id VP8zF8d+wGD3XwAALh3uQQ (envelope-from ); Wed, 09 Jun 2021 08:41:43 +0000 Subject: Re: [RFC 25/26] mm, slub: use migrate_disable() in put_cpu_partial() To: Jann Horn Cc: Linux-MM , kernel list , Christoph Lameter , David Rientjes , Pekka Enberg , Joonsoo Kim , Sebastian Andrzej Siewior , Thomas Gleixner , Mel Gorman , Jesper Dangaard Brouer , Peter Zijlstra References: <20210524233946.20352-1-vbabka@suse.cz> <20210524233946.20352-26-vbabka@suse.cz> From: Vlastimil Babka Message-ID: <2a5cddf1-100d-9d24-fb98-8a5bd439a804@suse.cz> Date: Wed, 9 Jun 2021 10:41:43 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/25/21 5:33 PM, Jann Horn wrote: > On Tue, May 25, 2021 at 1:40 AM Vlastimil Babka wrote: >> In put_cpu_partial, we need a stable cpu, but being preempted is not an issue. >> So, disable migration instead of preemption. > > I wouldn't say "not an issue", more like "you're not making it worse". > > From what I can tell, the following race can already theoretically happen: > > task A: put_cpu_partial() calls preempt_disable() > task A: oldpage = this_cpu_read(s->cpu_slab->partial) > interrupt: kfree() reaches unfreeze_partials() and discards the page > task B (on another CPU): reallocates page as page cache > task A: reads page->pages and page->pobjects, which are actually > halves of the pointer page->lru.prev > task B (on another CPU): frees page > interrupt: allocates page as SLUB page and places it on the percpu partial list > task A: this_cpu_cmpxchg() succeeds Oops, nice find. Thanks. > which would cause page->pages and page->pobjects to end up containing > halves of pointers that would then influence when put_cpu_partial() > happens and show up in root-only sysfs files. Maybe that's acceptable, > I don't know. But there should probably at least be a comment for now > to point out that we're reading union fields of a page that might be > in a completely different state. > > (Someone should probably fix that code sometime and get rid of > page->pobjects entirely, given how inaccurate it is...) I'll try to address it separately later. Probably just target a number of pages, instead of objects, on the list and store the number as part of struct kmem_cache_cpu, not struct page. The inaccuracy leading to potentially long lists is a good reason enough, the race scenario above is another one...