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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E99E8C54EE9 for ; Tue, 20 Sep 2022 12:14:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8825C80009; Tue, 20 Sep 2022 08:14:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8328780007; Tue, 20 Sep 2022 08:14:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7223980009; Tue, 20 Sep 2022 08:14:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 6246D80007 for ; Tue, 20 Sep 2022 08:14:11 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 3E771AB635 for ; Tue, 20 Sep 2022 12:14:11 +0000 (UTC) X-FDA: 79932355902.12.AC7C771 Received: from relay.virtuozzo.com (relay.virtuozzo.com [130.117.225.111]) by imf11.hostedemail.com (Postfix) with ESMTP id EC2B34003D for ; Tue, 20 Sep 2022 12:14:09 +0000 (UTC) Received: from dev011.ch-qa.sw.ru ([172.29.1.16]) by relay.virtuozzo.com with esmtp (Exim 4.95) (envelope-from ) id 1oac55-004fqT-6p; Tue, 20 Sep 2022 14:12:39 +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 v2] mm: Make failslab writable again Date: Tue, 20 Sep 2022 15:11:11 +0300 Message-Id: <20220920121111.1792905-1-alexander.atanasov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of alexander.atanasov@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=alexander.atanasov@virtuozzo.com; dmarc=pass (policy=quarantine) header.from=virtuozzo.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663676050; a=rsa-sha256; cv=none; b=djt2zPdfmHD3xastpHHeUeAIGhaIBV0Aw2KLg16H39A92N+6Mn70Ucdcic6I7O0s3rYxI6 slC8CS3x9T/kbF/ZnngLVmTihrCujRm/m4Jh1ByJ8qaeDzxzgCtRlhCIHMhGSqZjhvBrLv 02HfpPc7bUf/D9psKx37nWAEnMJRMd8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663676050; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=t1Wtjn56+J8nG3r+2kAZ1Zo2UnwX4qH5jDmX+PIJ9fE=; b=czk9x3hf0n/mIqbF/mAr3hd6/NUJ18grgm1ybklZGVjUe0ZDsSFXIMw/XYtqCitYFj3roD 91JAdMNf9qo8CfHmiHpV7sdUsBOivcpOThYzZAYqvIAivwBk3T8joZylEcRPAgiD3kFD0t zfhuA6MaWN4JuuRg3z/a5rCIbaDZ4J8= X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: EC2B34003D X-Rspam-User: Authentication-Results: imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of alexander.atanasov@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=alexander.atanasov@virtuozzo.com; dmarc=pass (policy=quarantine) header.from=virtuozzo.com X-Stat-Signature: 3y8b9bniw5ywwoxprrhp81ips9wztoqh X-HE-Tag: 1663676049-673556 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In (060807f841ac mm, slub: make remaining slub_debug related attributes read-only) failslab was made read-only. I think it became a collateral victim to the two other options 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. And 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 | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) V1->V2: Fixed commit message. Flags are set using WRITE_ONCE. 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 +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. diff --git a/mm/slub.c b/mm/slub.c index 862dbd9af4f5..57cf18936526 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -5617,7 +5617,21 @@ static ssize_t failslab_show(struct kmem_cache *s, char *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; + + if (buf[0] == '1') + WRITE_ONCE(s->flags, s->flags | SLAB_FAILSLAB); + else + WRITE_ONCE(s->flags, s->flags & ~SLAB_FAILSLAB); + + return length; +} +SLAB_ATTR(failslab); #endif static ssize_t shrink_show(struct kmem_cache *s, char *buf) base-commit: 80e78fcce86de0288793a0ef0f6acf37656ee4cf -- 2.31.1