Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3846463pxj; Mon, 24 May 2021 16:43:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfuCpcLL5M6apgHYvO6RFTQyTrXDKDbb8EVyYl2tBhF+Ip6TH1CTgWWuibpTG5cPmRkLYy X-Received: by 2002:a17:907:9008:: with SMTP id ay8mr26241609ejc.474.1621899830284; Mon, 24 May 2021 16:43:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621899830; cv=none; d=google.com; s=arc-20160816; b=rALckeu0WxS/+BHWik6kWMNdk/32jecTn8y2p3faBl55G9/S7a6qLtKydbuUluu27f IhK+JRnPalwT6aXnJLNDaeWoBJzG2Yg2bu+y1dYgqTj2hlE3CJxVduHRwPeWpZB3CbXo 3s3m4Jsc0ZhhYJ1BqGgFDbdbAYMoXublrcpGU2twvPmWcfnCdZzwf3swuifc9fdfai4p YLT1fOQTu2+t4E+cqb8XD24osHYpE4RjPaOrqGfOWQo8UrjbCXdZHMtDHuT2x61h6/Z6 UpCpGah/4lkxr7wtk+hruVvQsJXV0F+pu4bA6f9gv6zh9Cq+4XjUYmKbYuf2gjgLH6eS M0Eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=SGGhQXqylEVkhGCKs15bdMyTfUKJS20cQoY/lph/3m8=; b=x3HxKCuEotT1j9Op1BvSqt25HKUzvzvQ3Sq3jps/3sjNabjXIrhBtZpNYcibahsdm8 IkTo8LtmFxYp9Pj2rCSRONZ8PfbOoaX9MOhRIdjXyC7pvFEIs6INiKzTD37gKDBrms6X tfNv3ba7nbipXH8eNbhoDtb7RRfcBtar+NGqH83O5v67uS2lk9L//7itW4lRvqw2mLyD WpdJukTQL8KoqFP7I74JFqp9vK1RQKJb/dwWoN3rOOm1tVDORrby6gGDRisZubHLRe2s dkmvA1CyDFWErudkbUvJ05NTOVo8Bm+Fn/RrhObomYQ0qV8BJ+twhF8FAq0HLJfWMCae pnig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=qHeeEQdp; 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 i3si14628800ejr.178.2021.05.24.16.43.28; Mon, 24 May 2021 16:43:50 -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=qHeeEQdp; 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 S230314AbhEXXnW (ORCPT + 99 others); Mon, 24 May 2021 19:43:22 -0400 Received: from mx2.suse.de ([195.135.220.15]:50834 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229926AbhEXXmV (ORCPT ); Mon, 24 May 2021 19:42:21 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1621899648; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SGGhQXqylEVkhGCKs15bdMyTfUKJS20cQoY/lph/3m8=; b=qHeeEQdp+l8oDi/GxEUNr+OTPlCFxJqYKw0Ld1SGleywFtPjGcmkAu0J+PCCnCYm2IqrjR Hhrk/fxiSDKmaaWerViK4RB+XBOJt6wH3ukfyKO8ABMR5Xqp2ZpO35BwMLp2ORVW8rH9Wa 93i745gCo8quEaMRQuJqCxRSR2WOzao= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1621899648; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SGGhQXqylEVkhGCKs15bdMyTfUKJS20cQoY/lph/3m8=; b=Q/9QWO+pniucpKTJDZzw+89IFzM1M0qlXWLpeRR9NabOwiKr/NFXn6QGJuwVLwSum5wmda be6VckW9tHJWk2DA== Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 68FDAAF35; Mon, 24 May 2021 23:40:48 +0000 (UTC) From: Vlastimil Babka To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Christoph Lameter , David Rientjes , Pekka Enberg , Joonsoo Kim Cc: Sebastian Andrzej Siewior , Thomas Gleixner , Mel Gorman , Jesper Dangaard Brouer , Peter Zijlstra , Jann Horn , Vlastimil Babka Subject: [RFC 13/26] mm, slub: validate partial and newly allocated slabs before loading them Date: Tue, 25 May 2021 01:39:33 +0200 Message-Id: <20210524233946.20352-14-vbabka@suse.cz> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210524233946.20352-1-vbabka@suse.cz> References: <20210524233946.20352-1-vbabka@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When we obtain a new slab page from node partial list or page allocator, we assign it to kmem_cache_cpu, perform some checks, and if they fail, we undo the assignment. In order to allow doing the checks without irq disabled, restructure the code so that checks go first, and kmem_cache_cpu assignment only afterwards. Signed-off-by: Vlastimil Babka --- mm/slub.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 47a3438d6a35..78d7eb5be951 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2743,10 +2743,8 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, new_objects: freelist = get_partial(s, gfpflags, node, &page); - if (freelist) { - c->page = page; + if (freelist) goto check_new_page; - } local_irq_restore(flags); migrate_enable(); @@ -2760,9 +2758,6 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, } local_irq_save(flags); - if (c->page) - flush_slab(s, c); - /* * No other reference to the page yet so we can * muck around with it freely without cmpxchg @@ -2771,14 +2766,12 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, page->freelist = NULL; stat(s, ALLOC_SLAB); - c->page = page; check_new_page: if (kmem_cache_debug(s)) { if (!alloc_debug_processing(s, page, freelist, addr)) { /* Slab failed checks. Next slab needed */ - c->page = NULL; local_irq_restore(flags); goto new_slab; } else { @@ -2797,10 +2790,18 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, */ goto return_single; + if (unlikely(c->page)) + flush_slab(s, c); + c->page = page; + goto load_freelist; return_single: + if (unlikely(c->page)) + flush_slab(s, c); + c->page = page; + deactivate_slab(s, page, get_freepointer(s, freelist), c); local_irq_restore(flags); return freelist; -- 2.31.1