From nobody Thu Apr 2 21:32:07 2026 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 5B6E7ECAAD8 for ; Tue, 20 Sep 2022 08:28:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230244AbiITI1g (ORCPT ); Tue, 20 Sep 2022 04:27:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231366AbiITI1D (ORCPT ); Tue, 20 Sep 2022 04:27:03 -0400 Received: from relay.virtuozzo.com (relay.virtuozzo.com [130.117.225.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBA6C67CAE; Tue, 20 Sep 2022 01:24:22 -0700 (PDT) Received: from dev011.ch-qa.sw.ru ([172.29.1.16]) by relay.virtuozzo.com with esmtp (Exim 4.95) (envelope-from ) id 1oaYSj-004etn-0W; Tue, 20 Sep 2022 10:20:49 +0200 From: Alexander Atanasov To: Jonathan Corbet , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com> Cc: kernel@openvz.org, Alexander Atanasov , Kees Cook , Roman Gushchin , Jann Horn , Vijayanand Jitta , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH] mm: Make failslab writable again Date: Tue, 20 Sep 2022 11:20:33 +0300 Message-Id: <20220920082033.1727374-1-alexander.atanasov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In (060807f841ac mm, slub: make remaining slub_debug related attributes read-only failslab) it was made RO. I think it became a collateral victim to the other two options (sanity_checks and trace) for which the reasons are perfectly valid. Here is why: - sanity_checks and trace are slab internal debug options, failslab is used for fault injection. - for fault injections, which by presumption are random, it does not matter if it is not set atomically. You need to set atleast one more option to trigger fault injection. - in a testing scenario you may need to change it at runtime example: module loading - you test all allocations limited by the space option. Then you move to test only your module's own slabs. - when set by command line flags it effectively disables all cache merges. Cc: Vlastimil Babka Cc: Andrew Morton Cc: Kees Cook Cc: Roman Gushchin Cc: Christoph Lameter Cc: Jann Horn Cc: Vijayanand Jitta Cc: David Rientjes Cc: Joonsoo Kim Cc: Pekka Enberg Link: http://lkml.kernel.org/r/20200610163135.17364-5-vbabka@suse.cz Signed-off-by: Alexander Atanasov --- Documentation/mm/slub.rst | 2 ++ mm/slub.c | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Documentation/mm/slub.rst b/Documentation/mm/slub.rst index 43063ade737a..86837073a39e 100644 --- a/Documentation/mm/slub.rst +++ b/Documentation/mm/slub.rst @@ -116,6 +116,8 @@ options from the ``slub_debug`` parameter translate to = the following files:: T trace A failslab =20 +failslab file is writable, so writing 1 or 0 will enable or disable +the option at runtime. Write returns -EINVAL if cache is an alias. Careful with tracing: It may spew out lots of information and never stop if used on the wrong slab. =20 diff --git a/mm/slub.c b/mm/slub.c index 862dbd9af4f5..7c15d312e0fb 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -5617,7 +5617,19 @@ static ssize_t failslab_show(struct kmem_cache *s, c= har *buf) { return sysfs_emit(buf, "%d\n", !!(s->flags & SLAB_FAILSLAB)); } -SLAB_ATTR_RO(failslab); + +static ssize_t failslab_store(struct kmem_cache *s, const char *buf, + size_t length) +{ + if (s->refcount > 1) + return -EINVAL; + + s->flags &=3D ~SLAB_FAILSLAB; + if (buf[0] =3D=3D '1') + s->flags |=3D SLAB_FAILSLAB; + return length; +} +SLAB_ATTR(failslab); #endif =20 static ssize_t shrink_show(struct kmem_cache *s, char *buf) base-commit: 80e78fcce86de0288793a0ef0f6acf37656ee4cf --=20 2.31.1