From patchwork Thu Apr 14 21:18:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 561516 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24DFFC433F5 for ; Thu, 14 Apr 2022 21:18:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244700AbiDNVUm (ORCPT ); Thu, 14 Apr 2022 17:20:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241346AbiDNVUk (ORCPT ); Thu, 14 Apr 2022 17:20:40 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 983207CB02; Thu, 14 Apr 2022 14:18:14 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 077F1CE273A; Thu, 14 Apr 2022 21:18:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 405F0C385A5; Thu, 14 Apr 2022 21:18:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1649971091; bh=es13VYXNe+2WAbC2sQXpF363bAvDsf0OrOPdmbW5uJo=; h=Date:To:From:Subject:From; b=e1kNTw33T5Az69cKz1dkjEQ7tUhLS+/D0UIBUo6Yxr1wJMZao/zEHLEteyeTI9HEK UWU+Y4w8GYp56ewGMcMNP3XhC+y5HMyu8tHVdzlNY4akVxyARoZjudpc4xSEN5x0ex CgvN+vHf4wKSXu9Bp+FVrxfPSdQm45JS3BnjFn9c= Date: Thu, 14 Apr 2022 14:18:10 -0700 To: mm-commits@vger.kernel.org, stable@vger.kernel.org, ryabinin.a.a@gmail.com, glider@google.com, dvyukov@google.com, andreyknvl@gmail.com, qiang1.zhang@intel.com, akpm@linux-foundation.org From: Andrew Morton Subject: + kasan-prevent-cpu_quarantine-corruption-when-cpu-offline-and-cache-shrink-occur-at-same-time.patch added to -mm tree Message-Id: <20220414211811.405F0C385A5@smtp.kernel.org> Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org The patch titled Subject: kasan: prevent cpu_quarantine corruption when CPU offline and cache shrink occur at same time has been added to the -mm tree. Its filename is kasan-prevent-cpu_quarantine-corruption-when-cpu-offline-and-cache-shrink-occur-at-same-time.patch This patch should soon appear at https://ozlabs.org/~akpm/mmots/broken-out/kasan-prevent-cpu_quarantine-corruption-when-cpu-offline-and-cache-shrink-occur-at-same-time.patch and later at https://ozlabs.org/~akpm/mmotm/broken-out/kasan-prevent-cpu_quarantine-corruption-when-cpu-offline-and-cache-shrink-occur-at-same-time.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Zqiang Subject: kasan: prevent cpu_quarantine corruption when CPU offline and cache shrink occur at same time kasan_quarantine_remove_cache() is called in kmem_cache_shrink()/ destroy(). The kasan_quarantine_remove_cache() call is protected by cpuslock in kmem_cache_destroy() to ensure serialization with kasan_cpu_offline(). However the kasan_quarantine_remove_cache() call is not protected by cpuslock in kmem_cache_shrink(). When a CPU is going offline and cache shrink occurs at same time, the cpu_quarantine may be corrupted by interrupt (per_cpu_remove_cache operation). So add a cpu_quarantine offline flags check in per_cpu_remove_cache(). Link: https://lkml.kernel.org/r/20220414025925.2423818-1-qiang1.zhang@intel.com Signed-off-by: Zqiang Cc: Andrey Ryabinin Cc: Dmitry Vyukov Cc: Alexander Potapenko Cc: Andrey Konovalov Cc: Signed-off-by: Andrew Morton --- a/mm/kasan/quarantine.c~kasan-prevent-cpu_quarantine-corruption-when-cpu-offline-and-cache-shrink-occur-at-same-time +++ a/mm/kasan/quarantine.c @@ -315,6 +315,8 @@ static void per_cpu_remove_cache(void *a struct qlist_head *q; q = this_cpu_ptr(&cpu_quarantine); + if (READ_ONCE(q->offline)) + return; qlist_move_cache(q, &to_free, cache); qlist_free_all(&to_free, cache); }