Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp213920lqt; Thu, 18 Apr 2024 12:48:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXiWyjLZMPcVOCuWl19SR+Bqe9O/Jft2C5pKwdPL336kmlJt/eaNxKjY7mGtJRHsw+aIKV/7qW/GMdSihyiaJd8cVbikTrUIhhnNiXWZQ== X-Google-Smtp-Source: AGHT+IFdlRzy7KIU4qpHf7WcErrp+1TUbNC9fFCD4l8zzivQuZ39Ll/CbGFNss9Zvxc0ATwQPr0z X-Received: by 2002:a17:906:b307:b0:a52:1297:cd2c with SMTP id n7-20020a170906b30700b00a521297cd2cmr56947ejz.63.1713469730953; Thu, 18 Apr 2024 12:48:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713469730; cv=pass; d=google.com; s=arc-20160816; b=VtomH3VtL1NOlUoIseKJ1+WsvFF2rNckT8c9Zv5Nt8YZ/Ckdi+Odh2DZGfbutsj779 RFYmm37pZ4zuDHo3zK9aw9Hdf9Ju0Fc4jzuRu8SdDxqT0JpMYeYIYtdeLq/inZmSfE8B kWfHF2SO4++iR9HZanygBr2YmKVLMp3o/+EvKewAF/093DdXxVVzxV9PlkIX0kgGnOBe VfrzqzksE6e0ezHdfpziI7GyC9j7MZk4AKUo3ld3g1fhDjFPf47J4s/3CN/TOI7hrgMQ a0m7qaqngLZk7hhGhdeqh2fy7XC2vIAWk/h5hqXSUkqcvgRU6qJtRunGAFx2o1i9AhKa FjNQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Po4ib7tb2zu13itIKz0w+xk7zZrKesj8n31HT1tI5Js=; fh=SRka5+vm8yoOA1rjUskRam3/N4AGlZZCHPWQIKmcWuM=; b=ls65CdSg2TtfCXt7mnprEY7rR5thspAB7X9YpQdVXG/OyylQ0uHlrtaSphW7vI5yFl HN1jLlJn6AA0B4GenBXLAPa7E/Bt5PJwYyF5LCkSI/jdP+Zaoal0LLAa3/EoByiuf5wg VG3higgG/sQkfTLtgoP7zAKHfSTWKfU0uNsH3c27eB81QRw46Wlu+BL/+IdqDsXPHjD1 qTrkNwtmUBGshydsEPHXQp5jgIFV35c6P1HfNhkKsNH/dZ5vT0di92Nx/0CYGFvDnMcH Qxud/h6//ReaVWY0XtDc3tctmct53A5edt0cSL4d0JpdZKhUBENDJ94BD3X52qLeCaLd S/XQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CmVx6dRz; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-150703-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150703-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id z1-20020a17090655c100b00a51dfabe269si1217239ejp.545.2024.04.18.12.48.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 12:48:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-150703-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CmVx6dRz; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-150703-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150703-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id AB1941F23876 for ; Thu, 18 Apr 2024 19:48:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 313471A0B11; Thu, 18 Apr 2024 19:45:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CmVx6dRz" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BAC0194C62; Thu, 18 Apr 2024 19:45:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713469549; cv=none; b=VqvR9C6I9hX5kFd3KznBHJpCoHWSkhjfX/p0NTjiqQxRxch5R/y7FGZMZDZRAEQIcGIaHUUDi+0L1QDLUqOL2BGSWH3O8Ak2R6gQeN0pzaC1HVhiNjFAz1qEL4obMskQnCcUbiIk7/6UFt7FWU05EUzhLs5chKh1VKa3lNOhL5M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713469549; c=relaxed/simple; bh=dHO0bamdxUUeACG8WtZho+GCcL4yBYsb4entMWbbmyQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=NeuLydmOy43wm77BprVIRDo9C2R0ZLK1SeQ9zN3+wz0EaAEPlphAvRSyd7M3fb9/ySjonJ1hgZhbmmAO20tH97yReu37Wzf8qSkWXdQIWo/9BPVN481ZQNKdSlBdpj+h7YQ8DVBTKArq/x62lwd6T0IHYsCNuhRNzCIdtEFEEf8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CmVx6dRz; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E87BEC113CC; Thu, 18 Apr 2024 19:45:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713469548; bh=dHO0bamdxUUeACG8WtZho+GCcL4yBYsb4entMWbbmyQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=CmVx6dRzicEYeby+eqehWh43quHdNoBbYY/i36pebwlC3hu3ZmeS4VjBXURj7aNy3 iceEu2pMqBEVdzfyoNs6zYPwdeFEVjMU4daLSOF+34RPv/VgtKgm1TQzPbhCvKJCzp PwHKW3yddAFwEE2clGQPe9VCz0EWlv35PYz4PkEEkLTMMrd+GAZOMmGABmKaUl5Y8d 4udjlt3Z97dUrMWxxJyIATuY3MTqmnZM5WdZYeq2ykeLqUHwwS1ZlLE9RAdOJI4t5m dZHSPXrDPE8q2nmOH9o+Xw5o1ED5ivvKuuyvGRHdoAhgoYmdvYsWWSvRA9smcyAVNW 9J1gVzjdVbV+Q== Date: Thu, 18 Apr 2024 22:44:31 +0300 From: Mike Rapoport To: Nadav Amit Cc: Linux Kernel Mailing List , Andrew Morton , Andy Lutomirski , Arnd Bergmann , Catalin Marinas , Christoph Hellwig , Helge Deller , Lorenzo Stoakes , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Mathieu Desnoyers , Michael Ellerman , Palmer Dabbelt , Peter Zijlstra , Russell King , Song Liu , Steven Rostedt , Thomas Gleixner , Uladzislau Rezki , Will Deacon , bpf , linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, "open list:MEMORY MANAGEMENT" , linux-modules@vger.kernel.org, linux-parisc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-trace-kernel@vger.kernel.org, linuxppc-dev , the arch/x86 maintainers Subject: Re: [RFC PATCH 3/7] module: [ Message-ID: References: <20240411160526.2093408-1-rppt@kernel.org> <20240411160526.2093408-4-rppt@kernel.org> <0C4B9C1A-97DE-4798-8256-158369AF42A4@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Thu, Apr 18, 2024 at 10:31:16PM +0300, Nadav Amit wrote: > > > On 18 Apr 2024, at 13:20, Mike Rapoport wrote: > > > > On Tue, Apr 16, 2024 at 12:36:08PM +0300, Nadav Amit wrote: > >> > >> > >> > >> I might be missing something, but it seems a bit racy. > >> > >> IIUC, module_finalize() calls alternatives_smp_module_add(). At this > >> point, since you don’t hold the text_mutex, some might do text_poke(), > >> e.g., by enabling/disabling static-key, and the update would be > >> overwritten. No? > > > > Right :( > > Even worse, for UP case alternatives_smp_unlock() will "patch" still empty > > area. > > > > So I'm thinking about calling alternatives_smp_module_add() from an > > additional callback after the execmem_update_copy(). > > > > Does it make sense to you? > > Going over the code again - I might have just been wrong: I confused the > alternatives and the jump-label mechanisms (as they do share a lot of > code and characteristics). > > The jump-labels are updated when prepare_coming_module() is called, which > happens after post_relocation() [which means they would be updated using > text_poke() “inefficiently” but should be safe]. > > The “alternatives” appear only to use text_poke() (in contrast for > text_poke_early()) from very specific few flows, e.g., > common_cpu_up() -> alternatives_enable_smp(). > > Are those flows pose a problem after boot? Yes, common_cpu_up is called on CPU hotplug, so it's possible to have a race between alternatives_smp_module_add() and common_cpu_up() -> alternatives_enable_smp(). And in UP case alternatives_smp_module_add() will call alternatives_smp_unlock() that will patch module text before it is updated. > Anyhow, sorry for the noise. On the contrary, I would have missed it. -- Sincerely yours, Mike.