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 X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 120AAC4332D for ; Thu, 19 Mar 2020 13:13:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CEFAD20722 for ; Thu, 19 Mar 2020 13:13:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584623626; bh=MEAFJ/oPF2BniSS4RFFS+76kZuzglg5LdmRA2oWk27w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=ZctI4MUcqKgKE/ECMiFxd4XQWqEOUhqAEeXI0M7o9Cb224bMpvauS3f3Ys1EjsiRt qQe5bTVeXDKVAlCIdPv04JW3HSZ+RPgmFc2vZSemZPLZ4Qaz+VCN7NJi2nZz5kt5Kw vf9G2246acyiefLREnjDkJfgRCgRfFLvoygGK/JU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729201AbgCSNNp (ORCPT ); Thu, 19 Mar 2020 09:13:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:32792 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729194AbgCSNNl (ORCPT ); Thu, 19 Mar 2020 09:13:41 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 239B12166E; Thu, 19 Mar 2020 13:13:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584623620; bh=MEAFJ/oPF2BniSS4RFFS+76kZuzglg5LdmRA2oWk27w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LptEkpX684BJ0cw/CjPD7Ujsyl4JgVmut+sA7D+q5CVjdvIteBkIRuIDwEvpESa4y l6HbbuGw9BQd6H9Or9ah9cPEYuM085evEMxM3tUSQU3nfc2QaYGo3Q6Isl7+bD+2p1 V5DqZmbTSf/Ilz7nzF/kTeFnm/OjFhz6a57jIPmc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jann Horn , Linus Torvalds Subject: [PATCH 4.9 89/90] mm: slub: add missing TID bump in kmem_cache_alloc_bulk() Date: Thu, 19 Mar 2020 14:00:51 +0100 Message-Id: <20200319123955.702270303@linuxfoundation.org> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200319123928.635114118@linuxfoundation.org> References: <20200319123928.635114118@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jann Horn commit fd4d9c7d0c71866ec0c2825189ebd2ce35bd95b8 upstream. When kmem_cache_alloc_bulk() attempts to allocate N objects from a percpu freelist of length M, and N > M > 0, it will first remove the M elements from the percpu freelist, then call ___slab_alloc() to allocate the next element and repopulate the percpu freelist. ___slab_alloc() can re-enable IRQs via allocate_slab(), so the TID must be bumped before ___slab_alloc() to properly commit the freelist head change. Fix it by unconditionally bumping c->tid when entering the slowpath. Cc: stable@vger.kernel.org Fixes: ebe909e0fdb3 ("slub: improve bulk alloc strategy") Signed-off-by: Jann Horn Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/slub.c | 9 +++++++++ 1 file changed, 9 insertions(+) --- a/mm/slub.c +++ b/mm/slub.c @@ -3115,6 +3115,15 @@ int kmem_cache_alloc_bulk(struct kmem_ca if (unlikely(!object)) { /* + * We may have removed an object from c->freelist using + * the fastpath in the previous iteration; in that case, + * c->tid has not been bumped yet. + * Since ___slab_alloc() may reenable interrupts while + * allocating memory, we should bump c->tid now. + */ + c->tid = next_tid(c->tid); + + /* * Invoking slow path likely have side-effect * of re-populating per CPU c->freelist */