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,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 C96E3C4332D for ; Thu, 19 Mar 2020 13:21:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9BCAF21655 for ; Thu, 19 Mar 2020 13:21:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584624067; bh=xbfv7AatQ/8gAwDtOYfKEqRPtW1wAwYMUmExtPt3lV4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=thFeNclCCMqaKEmyqpPTXgUshYRQLoOD/vJsjNjPqYu1EmdU35azJyPR4g6pYotQm vgaUfukwU//PJLrLkvj7i9kxYv6t6BUAWWBjLalw+lhiXVvbokkU+oKSgC6e07ixOQ OIl2nJEPVqCWy1pFefoJs7RqnegagocOV5eoszo8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730068AbgCSNVG (ORCPT ); Thu, 19 Mar 2020 09:21:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:45568 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730043AbgCSNVF (ORCPT ); Thu, 19 Mar 2020 09:21:05 -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 7BC9520724; Thu, 19 Mar 2020 13:21:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584624064; bh=xbfv7AatQ/8gAwDtOYfKEqRPtW1wAwYMUmExtPt3lV4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XocXlM5eaDZeJi80T4WC1xMePw6wp0QK9sk73uNR7VJDThANuashp3fsFjqoJyy8+ zUCuZvCndFn0gpDMEpg7fcTG/5wT8up+BdyKtI3xBrfCRDagUDMFi21O5W5hDbFbRs BgnvMvfHotwwq3gxLk8/x8SNsvTq4j66ZQKq6RXs= 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.19 45/48] mm: slub: add missing TID bump in kmem_cache_alloc_bulk() Date: Thu, 19 Mar 2020 14:04:27 +0100 Message-Id: <20200319123916.969338281@linuxfoundation.org> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200319123902.941451241@linuxfoundation.org> References: <20200319123902.941451241@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 @@ -3104,6 +3104,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 */