Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3657631rwb; Tue, 20 Sep 2022 02:50:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM79ee7ag6yGDM2NCh+J9ike9EtjSuKrlkUtv9tmmtxDRjI/UT9SEqAvxbWuOtu4oL49azvF X-Received: by 2002:aa7:dc10:0:b0:440:b446:c0cc with SMTP id b16-20020aa7dc10000000b00440b446c0ccmr19436376edu.34.1663667422334; Tue, 20 Sep 2022 02:50:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663667422; cv=none; d=google.com; s=arc-20160816; b=qD0+Z7vh9MlmIXgfBMrAJiLYB63qIGoVXLWDUDbaHq9oEJBvoYXTO0FEAI86XaaAxI HTWxwkGX6GF5adqeau+IC3NPgOqV0Kq93yjdhExmGWgiQicrg5zdfs2L8mqJkFFmBTGM XbaNFgHo7apCh7UBeMmVZAh1APptId89Of2XG5fcPDA0qADRqoEhJZ7j8H9keMQeMgly 5g9qMoTpPMipY9iIoja8ADcu0UFEDK++GqI2+zmk0g4baZWaDPjQDmsDw+RR0xoLUiiL Va+H0hsnjfvv8u7BizUHWwt7l9dtco3IW5ennNhlMRakleUTvvBQODpqjiGqJKCnGZ6a ocTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-signature; bh=v86Gb5apC1XqegEl+G9+nVcNXc/lLIOPGIQ/KR+N2Qg=; b=RPXPAFD3xcWEcUgctaFjIDGUmR/Xkmbs0eldqUmaltxDxFf6iJpZ/yCprnhBvs9D6N ShujlGKrO/EsohpgkXko2apdUevi1uLBpvmYwB5MXU3SZ6ek+4zQTNg+QFgnje3g+1eo uhtifQx4nAEDExlAD3TQL+5QnUUUddMYr4XNyMjyxjE41vgKce9KQ+js3QCSE3rLeB1j t2+gTd98xHrL43o7ecCsz4d0CeM9p1bP0ZFQqdiXnGxbPkCAFQZMDsfZkpfqAYTXaXYh bCmyIGWK50s/BFPdwr8A1kjTsSthSsJ+9vcEJindXkbwSjTvE16cBE0CgmgRc9jomtsj iOLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=x3HbK7Ei; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sh32-20020a1709076ea000b007814c4c81c6si968599ejc.477.2022.09.20.02.49.56; Tue, 20 Sep 2022 02:50:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=x3HbK7Ei; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231172AbiITJbE (ORCPT + 99 others); Tue, 20 Sep 2022 05:31:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231355AbiITJaT (ORCPT ); Tue, 20 Sep 2022 05:30:19 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3222D2B2; Tue, 20 Sep 2022 02:29:42 -0700 (PDT) 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 X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_SOFTFAIL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.