Received: by 2002:a05:7412:bb8d:b0:d7:7d3a:4fe2 with SMTP id js13csp48902rdb; Mon, 14 Aug 2023 09:08:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IER5jRFAhQ0BBQwTHhXeL1og1w5/lLy3pebEFsoJ1WtADmXuQ6LZipa51991RXvtjRxeNAf X-Received: by 2002:a05:6e02:1d9e:b0:348:797d:441a with SMTP id h30-20020a056e021d9e00b00348797d441amr18010428ila.8.1692029330366; Mon, 14 Aug 2023 09:08:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692029330; cv=none; d=google.com; s=arc-20160816; b=Rw6583iNaEsRXFA1IoY9RdMb/V68G0Qq6x5lwVVPxobbmOlaXxcGIgwz+DfTpoZ8cB V6Y50f9N2pApeeyjpDIILaD++5nMB19cDaZPycKyALhPgOVukY3D9RaESpK6wsVH0xng 83iwVcB6peK1zIVzapl2gQhehN7SodCazl+Kk9om+ifTGa4fZewRCfwpcVNe2EDk+9md ohcIU6TcdWk566phIkZM18kGVik4ga2HbWS2+jha+3RhccyCjDKptAdzJGOxx2FvpZWD obcQ21UaEHEQh8lUbKPCmyMU9Jh/FyrUpJr5mvNO7/yYPLeXU5HYyGI/vnYvXXZpqG46 TbBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=coKMnWWCWtqJjCTkHa6gz6tSlFtfIxurPrU2OkeVbd0=; fh=2xCBsnYcE1QD+NKFjiQI17uEseyONT6Uwo9/A2D1FrA=; b=qNnDFQyqPaB7u9InUQ/m7LeZDg0JO7PqOYyUkzO3zImzA8+fH1YYWiDxVwd2o7HOqa o1Wqb6g6XU6lMuJOuSvQTrQHfhdVKRfxXf0ftLtuCGlfKrgjr8wUCKE85lxkSo6Vjl2H ClH1f3JjluRlnkXricEPkIqeG0WYuIqzoM3+ClEXVDwhkuBUzixXS9QLoO+wpsjh1B2y kaH386gO1vjQSUkFKlDjwwDwrcUShtE+oaLtGIKMFqqs7spdDP4ClW4hVrNYeLEfGDvu mqQbIMJ2nuBUGcV7pnsPcIb7nwNymzCfXQ5tNK4wkmUrEQg6QOlAAACx1qIo6GAmRoUz 4jWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=G9sVuXeZ; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a72-20020a63904b000000b00565bf035b25si1648452pge.382.2023.08.14.09.08.33; Mon, 14 Aug 2023 09:08:50 -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=@redhat.com header.s=mimecast20190719 header.b=G9sVuXeZ; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232537AbjHNPHU (ORCPT + 99 others); Mon, 14 Aug 2023 11:07:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232592AbjHNPHJ (ORCPT ); Mon, 14 Aug 2023 11:07:09 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8971BE6A for ; Mon, 14 Aug 2023 08:06:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692025581; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=coKMnWWCWtqJjCTkHa6gz6tSlFtfIxurPrU2OkeVbd0=; b=G9sVuXeZOD3tLO+8exYYE3WAUSbt/nXtWsO0hVyI+oW9Xf5+wKq9VNmP20tfFGbEmy+KPi Ha+jGQc5m6Ra+uQc+DPjnLID6rzhSN/XB1NcTe2SLt95utVUrUX/8WQzglR5wSGaCiaCKe fEkZtdHgHNjInSUyp95E3a1iIsPqk/Y= Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-644-I0CXlIs1MWeF5tyF_66jfg-1; Mon, 14 Aug 2023 11:06:17 -0400 X-MC-Unique: I0CXlIs1MWeF5tyF_66jfg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E7338299E749; Mon, 14 Aug 2023 15:06:16 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.225.27]) by smtp.corp.redhat.com (Postfix) with SMTP id 731A8492C13; Mon, 14 Aug 2023 15:06:14 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Mon, 14 Aug 2023 17:05:34 +0200 (CEST) Date: Mon, 14 Aug 2023 17:05:31 +0200 From: Oleg Nesterov To: Mateusz Guzik Cc: linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, brauner@kernel.org, ebiederm@xmission.com, david@redhat.com, akpm@linux-foundation.org, linux-mm@kvack.org, koct9i@gmail.com, dave@stgolabs.net Subject: Re: [PATCH] kernel/fork: stop playing lockless games for exe_file replacement Message-ID: <20230814150530.GB17738@redhat.com> References: <20230813123333.1705833-1-mjguzik@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230813123333.1705833-1-mjguzik@gmail.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,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 08/13, Mateusz Guzik wrote: > > fe69d560b5bd ("kernel/fork: always deny write access to current MM > exe_file") added another lock trip to synchronize the state of exe_file > against fork, further defeating the point of xchg. > > As such I think the atomic here only adds complexity for no benefit. > > Just write-lock around the replacement. Well, I tend to agree but can't really comment because I forgot everything about these code paths. But I have to admit that I don't understand the code in replace_mm_exe_file() without this patch... old_exe_file = xchg(&mm->exe_file, new_exe_file); if (old_exe_file) { /* * Don't race with dup_mmap() getting the file and disallowing * write access while someone might open the file writable. */ mmap_read_lock(mm); allow_write_access(old_exe_file); fput(old_exe_file); mmap_read_unlock(mm); } Can someone please explain me which exactly race this mmap_read_lock() tries to avoid and how ? Oleg.