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 00B2FECAAD8 for ; Tue, 20 Sep 2022 09:29:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 29F22940009; Tue, 20 Sep 2022 05:29:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 24E39940007; Tue, 20 Sep 2022 05:29:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1165A940009; Tue, 20 Sep 2022 05:29:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 035A9940007 for ; Tue, 20 Sep 2022 05:29:43 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id D1B9980477 for ; Tue, 20 Sep 2022 09:29:42 +0000 (UTC) X-FDA: 79931941404.09.E14A6BC Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf29.hostedemail.com (Postfix) with ESMTP id 4E501120011 for ; Tue, 20 Sep 2022 09:29:42 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 051B81F8BB; Tue, 20 Sep 2022 09:29:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1663666181; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=v86Gb5apC1XqegEl+G9+nVcNXc/lLIOPGIQ/KR+N2Qg=; b=x3HbK7EijxLI/OHQLM6LUQoQFzf6fLy2x7usS2Byaa9c/OkKBOWFxUx3JEwtv8bxUoV8pT lcirGlTcsIN1OUatgGDMLRAarntWuG7ogEf/+RdKcIBxYboFB65Dthuble1oizonGZd9vO GxYuaJTf6LJzlBQIjtD854zyPGX7OYs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1663666181; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=v86Gb5apC1XqegEl+G9+nVcNXc/lLIOPGIQ/KR+N2Qg=; b=Z5ZeNre0jVeIRQ3XvfdH3oUtX8VVz0sa2D4eDtIk3Z7vpJ02dxfb8pGZqxtIhlksiqWfS1 nFw8KwOmYM7I1aAg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id B87EE1346B; Tue, 20 Sep 2022 09:29:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id pnoaLASIKWN7BwAAMHmgww (envelope-from ); Tue, 20 Sep 2022 09:29:40 +0000 Message-ID: <60111450-d66a-a146-1a70-0c093400f3e5@suse.cz> Date: Tue, 20 Sep 2022 11:29:40 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: [PATCH] mm: Make failslab writable again Content-Language: en-US To: Alexander Atanasov , Jonathan Corbet , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com> Cc: kernel@openvz.org, Kees Cook , Roman Gushchin , Jann Horn , Vijayanand Jitta , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20220920082033.1727374-1-alexander.atanasov@virtuozzo.com> <21646f5c-39ee-a51c-f30c-272de85ee350@suse.cz> <6f5a8f71-3d82-97bf-90e1-0f33546bb59b@virtuozzo.com> From: Vlastimil Babka In-Reply-To: <6f5a8f71-3d82-97bf-90e1-0f33546bb59b@virtuozzo.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=x3HbK7Ei; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=Z5ZeNre0; dmarc=none; spf=pass (imf29.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663666182; a=rsa-sha256; cv=none; b=Aqs9CYSjec4XNEjCTYj/Vfc4EMLV7TOE5N2F56df13j+keIGylbH02lG3DkqUeZn7N9e8z HK2oBCL2tvGJ2x3luiUWZe20QWIDMzuW7kBHacj/NoouzpRgpB52ldZ3dKy0+EtevISad7 kHsLurUa/F0bmNovs3OuIP0jujZp7AM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663666182; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=v86Gb5apC1XqegEl+G9+nVcNXc/lLIOPGIQ/KR+N2Qg=; b=V8jZcWxC9dD1ERtAkEBkcLIVTMcS6cwEl8PP6/6AFE9ElYOHPlczLLSAYXII/6JJw5c6ZT YqY/jLsiYB5HkJd20/1s1wnhvHqgNRcBRS9Z+lapXtvTtySS2WNI+ddazNY82F7Bgzaksn qphYZwQ9crnbHrsTn7mS9ohZn4zDD/o= X-Stat-Signature: 359msbq4xjeg6qwr5pmwjtqfenpmkus9 X-Rspamd-Queue-Id: 4E501120011 Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=x3HbK7Ei; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=Z5ZeNre0; dmarc=none; spf=pass (imf29.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1663666182-231093 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: On 9/20/22 11:17, Alexander Atanasov wrote: > Hello, > > On 20.09.22 11:42, Vlastimil Babka wrote: >> On 9/20/22 10:20, Alexander Atanasov wrote: >>> In (060807f841ac mm, slub: make remaining slub_debug related attributes >>> read-only failslab) it was made RO. >> >> "read-only) failslab was made RO" ? > > Yep. > >>> I think it became a collateral victim to the other two options >>> (sanity_checks and trace) for which the reasons are perfectly valid. >> >> The commit also mentioned that modifying the flags is not protected in any >> way, see below. > > Yes, indeed. > >>> +static ssize_t failslab_store(struct kmem_cache *s, const char *buf, >>> +                size_t length) >>> +{ >>> +    if (s->refcount > 1) >>> +        return -EINVAL; >>> + >>> +    s->flags &= ~SLAB_FAILSLAB; >>> +    if (buf[0] == '1') >>> +        s->flags |= SLAB_FAILSLAB; >> >> Could we at least use a temporary variable to set up the final value and >> then do a WRITE_ONCE() to s->flags, so the compiler is not allowed to do >> some funky stuff? Assuming this is really the only place where we modify >> s->flags during runtime, so we can't miss other updates due to RMW. > > Since it is set or clear - instead of temporary variable and potentially two > writes and RMW issues i would suggest this: > +    if (buf[0] == '1') > +        s->flags |= SLAB_FAILSLAB; > +       else > +        s->flags &= ~SLAB_FAILSLAB; This way also has RMW issues, and also the compiler is allowed to temporarily modify s->flags any way it likes; with WRITE_ONCE() it can't. > If at some point more places need to modify the flags at runtime they can > switch to atomic bit ops.