Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3710115rwb; Tue, 20 Sep 2022 03:42:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7g1XCCkpi3CGOJmhSbqsQwOB+NDvI+NOXnt55ed+lGWDVJml33szo5Uu87wLPgfcnaUcXK X-Received: by 2002:a17:90b:1b4f:b0:202:b066:322 with SMTP id nv15-20020a17090b1b4f00b00202b0660322mr3076148pjb.226.1663670538915; Tue, 20 Sep 2022 03:42:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1663670538; cv=pass; d=google.com; s=arc-20160816; b=KTlZXIAw6NCh0dS9btwiPmUpg9fDjIllVr/dyTRRpAbYTWAnDyj1Tjv+2virJSiAXp pkB6l3QxZVMN9vyG2rMYunTuD7rSEbXcLpnSxCN9a34zUhqORXcEpZ1APJYuPmR0zoKN JD/d/03WY633rd2OIgyN5mANQH6wIVCOua5+MnObOBH0hNK2wAfS1ydJEGjeTT3avAY1 NETOopsHsdzBvHYw1gIUEBc1Fx4f7mgO7t7jYqIKNYsMVLUXVGlfd1POPPMzed1tKwBk YqndSf55TBGx8WZ0aL0w+ydvUEL8A5AuREAkqXoKTPM5q/U9E9uxY82ieeTtwULj5RQ4 v2SA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :in-reply-to:from:references:cc:to:subject:user-agent:date :message-id:dkim-signature; bh=DbfWY8no3byEqeXwRggJAc4O3PtdGb2Zmjk1FGN3Ab0=; b=Swjis0rL1CVQP0Lu6J4wZEMs/alupnXXRtKe4rxmWRKeYVJPxx+FuSgOsB7Vk1PfTy xGARGsWaFQLfZgmrUkOCFuqdAMez/nbw1+y4kCZLwuMLhOqE1RdoEw3iBMUt4KkBOPkg 1QNOBTvnR0sLk7aTt+lu5Ky1QLH1SPlrluY4S/rb8BloaQXi/iRsOyCeEI0T2n5zbot8 9p2P2/wpyr/UzUIx6Gi6HHzLyg+4wFgEOTJOcCzkTxd9TMRtcTwOp7G4HiNR50DWP5+w 5qEQfAZE9NJsyk0e8L3s8KGh+fJcYAC6/rXGLF6tvWWrmwlWOLzEQhDjqgxY69N5BXjq b+UA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=selector2 header.b=OZoZBa2o; arc=pass (i=1 spf=pass spfdomain=virtuozzo.com dkim=pass dkdomain=virtuozzo.com dmarc=pass fromdomain=virtuozzo.com); 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s8-20020a635248000000b0042b609d62c2si1486103pgl.406.2022.09.20.03.42.06; Tue, 20 Sep 2022 03:42:18 -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=@virtuozzo.com header.s=selector2 header.b=OZoZBa2o; arc=pass (i=1 spf=pass spfdomain=virtuozzo.com dkim=pass dkdomain=virtuozzo.com dmarc=pass fromdomain=virtuozzo.com); 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229793AbiITKVs (ORCPT + 99 others); Tue, 20 Sep 2022 06:21:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229605AbiITKVo (ORCPT ); Tue, 20 Sep 2022 06:21:44 -0400 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2121.outbound.protection.outlook.com [40.107.22.121]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34FD86CF72; Tue, 20 Sep 2022 03:21:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IxK7AHvveOct2MWGECNPklzBz2xmRkRdaVHLt/FEhODSabZFpZ+Ufe9sq9d84QT35aawOrkKHLPwYUaLIF3MygRC/EPyBIx2EaeZ9GxF0D2jmTidcdF8Fl3tTvzfgsbzcGtG/a00shOcYuR7USGff5yny/QpUuTVH92TDBE62xMLmfxZj6ClSO0W6g02ZgW0KIXtDV5t001vsSUNM6yb+pJjVktb0lTyfDayrvrWmDpTmA41IkfB2oNYqWPt4PVKvCBlbFLojEtNcNqjFdFFcAfeYKMiagjE2xrEfMZWesl5ZaWETGACTiYcrW2vwQxj9Kwo0eXfNsdm92BNR940fA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=DbfWY8no3byEqeXwRggJAc4O3PtdGb2Zmjk1FGN3Ab0=; b=JdkIPDUBotwo09pGDTD6Y6n11des/lOmWAFLn4y+0oonxoVoKWdsHId+NEIHHqnbvCL4RZPdnCRaU3Fin6Wsa4Y4m8xwHC7gk3XlJ1M3x5zF2/vH+CZrE+gSavIS3j6DNmaqwzp/GdJw6EGI7gjS/z9azuHryutm96qB9WK8vbmdfXSSbkf0UK+HYCXU89XlEbGkE4hxvASHEwZFtVsTfE2DcX9iBSwZbh+wKKOSt3tRQsPDDLg8LKVnMBWWkSUrAWa2KBvArdr+ioDO0eSLXJt77X7PTH26Tu7xXk5+agVwpjemoW6WO2wi6DsuP/7zCXN8Mjk6vLPaM12UYZohyg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=DbfWY8no3byEqeXwRggJAc4O3PtdGb2Zmjk1FGN3Ab0=; b=OZoZBa2oGbxAyj3tHQF7hrqCuEzyzcTjg2gywDgUiocYQ9IXotMlShYIY1soPfWN+tHVw+jKxhuYQHGfH2P6WBJMOL7o+LD5a4me1cKZg5Skww0fRrlgv5nroZ4GRAIv+wvWqj5hoVMaXGJ+FnlbgcRJmOLeggQB8slsvAJmRLHiBy1sfGk/fvFBPFPreHdjgg9kcJzQvClFWpiQET3CyS3DiEsf5Jod9xa1o9z4h8fJB52eVf4b67tWroTtrnp22aXOlPTZ1wgXO9mWHKH70CwHkeRvh0Od86KFAiKqU63pGe8RTiojLZqtuj+NPYBymhMggZ8XeRU3DmCLOZzLTQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from VE1PR08MB4765.eurprd08.prod.outlook.com (2603:10a6:802:a5::16) by DU0PR08MB8324.eurprd08.prod.outlook.com (2603:10a6:10:40b::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5632.18; Tue, 20 Sep 2022 10:21:34 +0000 Received: from VE1PR08MB4765.eurprd08.prod.outlook.com ([fe80::2846:1df0:88bb:451f]) by VE1PR08MB4765.eurprd08.prod.outlook.com ([fe80::2846:1df0:88bb:451f%3]) with mapi id 15.20.5632.021; Tue, 20 Sep 2022 10:21:34 +0000 Message-ID: <7d79d13b-0579-452f-7a07-4e3eba205d23@virtuozzo.com> Date: Tue, 20 Sep 2022 13:21:33 +0300 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: [PATCH] mm: Make failslab writable again To: Vlastimil Babka , 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> <60111450-d66a-a146-1a70-0c093400f3e5@suse.cz> From: Alexander Atanasov In-Reply-To: <60111450-d66a-a146-1a70-0c093400f3e5@suse.cz> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: VI1PR09CA0148.eurprd09.prod.outlook.com (2603:10a6:803:12c::32) To VE1PR08MB4765.eurprd08.prod.outlook.com (2603:10a6:802:a5::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR08MB4765:EE_|DU0PR08MB8324:EE_ X-MS-Office365-Filtering-Correlation-Id: ee146af9-7759-4944-d05b-08da9af1e505 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HcaUzNbALw8POvG9eY4ZRZSHpgniJsgvJZqx5/QomDv2JL0VJ3l2obmNc4CroBtqIdvDJROM/kghz/OO60zfZbpwXcpUefA2qec7CYV+dLRepqRJ7g3VdTViRJij6lUdeLeEL6AbAQkW2ntREbg9pMnawYlowNkdHTZ2PlEa15Lc1Ju5bJrBihma0GS27//98vVhW88EozEM7mPzdOntqL8kPymqxTG8rLFrcT1h0+2dGDwPcCBeku67gKuS0qje3qexo7EKSqtS1cAJPxwp/saU41NEhDvyF698Y9xQdpPosPEZUsTSw/mhvMhTEsTtT4mSQrqFhbsKgVA3mkG6wtURq8oGTJTBnJ0zxBZkZ0mgX8xv0AX2wPV3UaQY/V5oFFYI2Sv0e2QW//iUQKieJcpdgdBseynaj4sj/TeNBeGd2MKk/pjgFuQ7qlKm7324Z0oNTWQeHE7kkXt5x/omoQe6dloy0MuQV0b8oKJIvVwWzeyJRxHd4Semxm0XReb3TVVbyLelRSu4SwYA6VYYEourbfGNOVhzNrhPyLW1T2HRCLXAd4ge0mU7sydIMod3YgpWiYTHw/PNvP255TTo+i1R2Rq463XAZf32u+aFuZgQa+AI7AzJmch7ps/hp5zFNAVPA2cV10UyDvt5I4K0b8XfGdprK+owz4bN7C+unzXFJLMNGIYZHuaYi8rjI8O/LdBk7+qqTmfyeQCq0nFo/Nl4AEIJOS/BTrhEb9uSgL3B9IMhtgldK9yoU67w79k5VVDvIQQ3cF4uBBMMpZSnopGIpL2qYCd3BDrQjws2V0S5ux9uNp5EIGFAt1fbBd6E X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VE1PR08MB4765.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(39850400004)(346002)(396003)(376002)(366004)(136003)(451199015)(38100700002)(31696002)(86362001)(4326008)(66476007)(8676002)(38350700002)(66946007)(66556008)(54906003)(41300700001)(316002)(110136005)(5660300002)(83380400001)(2906002)(8936002)(44832011)(7416002)(2616005)(478600001)(186003)(6486002)(26005)(6512007)(53546011)(36756003)(6506007)(31686004)(52116002)(45980500001)(43740500002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?WGhZa1lxR252OU9oR2NERGUxdm9wTTV6Vng1TWdSMUFEcUpQVjB0R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Fzb0VieXg1b0tVeEZTSWRtNkhq?= =?utf-8?B?RGUwWTl5TThmTFV5ajhpMnV3V3ZTY2IrSHFCYjJ6U2xHNUJxSFg1TEovckJq?= =?utf-8?B?a1FJNVV5VEhOMHZoU3FmOW1WYytuU0VzQVBOMElvNGZZSTVLM2o1c0hoYm1U?= =?utf-8?B?TWxPaG1hWFNJNE95NVJFbkhsOTlKY2twNytjcFZQSHQvdE5IOGFBWXlxNDEw?= =?utf-8?B?TklDM0x5K2p1eGtUSGpUbjR3d2F6WDJlYW9hZE1xZ1hRekRZeDUvWi92UmEr?= =?utf-8?B?SDJ1bGVMdy9YcFg4Y3RzZkhDWDZWODN3ZGFhSnVabTRQNVpmcVRtRXdIbzBu?= =?utf-8?B?TWc9PQ==?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: ee146af9-7759-4944-d05b-08da9af1e505 X-MS-Exchange-CrossTenant-AuthSource: VE1PR08MB4765.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2022 10:21:34.7599 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: adpbvqB9yiO79tGCCQR5HUaQ/zT109Hf0I/XItlFaXF2YN7yRUrco5Am3gVlVl8HP8yOKjDSG9zzOLZ23w0E5wan8iVyRwsbm2RSEsLljayi/Kbc2ypcKIBixIr8CINJ X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB8324 X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE 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 20.09.22 12:29, Vlastimil Babka wrote: > On 9/20/22 11:17, Alexander Atanasov wrote: >> Hello, >> >> On 20.09.22 11:42, Vlastimil Babka wrote: >>>> +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. Okay, so the safest way is this? if (buf[0] == '1') WRITE_ONCE(s->flags, READ_ONCE(s->flags) | SLAB_FAILSLAB); else WRITE_ONCE(s->flags, READ_ONCE(s->flags) & ~SLAB_FAILSLAB); It got me thinking how many places would break if the compiler starts to temporariliy modify the flags - i hope it never does. -- Regards, Alexander Atanasov