Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp678918rwi; Mon, 31 Oct 2022 06:23:40 -0700 (PDT) X-Google-Smtp-Source: AMsMyM409ClbVyJNTCdEbaUuHmXSR8j4d2MS/AYUCmgvkuiZU5PwvNKrsPMGt6dpMaaNWIQhQXnY X-Received: by 2002:a05:6a00:2446:b0:52b:e9a8:cb14 with SMTP id d6-20020a056a00244600b0052be9a8cb14mr14407017pfj.32.1667222620082; Mon, 31 Oct 2022 06:23:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667222620; cv=none; d=google.com; s=arc-20160816; b=PYAREA9ih6yJjSLBa4bdINKUziAFW2lwIvrte3CQlPMxHzI42CrJei3A9w/sSfC4OL 5iPPVTAdILPkh3gRUc4Q6M7Z+7+CEWg0w4/DNU3fD/+vmQ0uDklge2rswksJWMuJEh5I mwTsZnVlqp0XcBQ80VN4v/qgtSyu2C2kpfSRA3q4IFgrA65QUVs9aJtgV6Cugzf6uX/l aVSJxO1N6/M7KKica047nRLNH77Lrc4azHGFtrR8gYP/cXQutPImaL8JJGmoCcV+D4Jl L+YJ/rhD+kzNyzaadX8JpjoVzNN86uiMHfp7+X2/u10Kv36dHp3n3YBoD8Yfp2dJZJ9P Zlsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=P91jJYlp3/SRYMEHazqCZDlSoldIH8d9qsUcRa3UgNg=; b=lH7mNU+M15NQ5fQjsUbGcXmfhKM6uI9pAy3zUqRiXfEGgQbu69EfOSFflxFoBVCM3v 8CvF9JtLcUJeWGR7c4IiEKaGSbs+41KdRAfTsdPSsEMZIRhlztWqT0+gQNaWuHmDhRos a1x9xMUGjWjfjP3K+7OpvrB/iU8iDw68iBMpot6dpgVL048SDW8x8m44Y69tgw7vJHuz Vl9VyQMmHARm75h58FUAo1obnjlD6bV9SSe2meimxgAfcbYAs0la9JUlwIVAPTOd1Q/4 V5AI45V9RaMhCf8dLIEuvf1RILUU96RLTeCrVpCvseJTP49lNAqmCKyWNxQMRoo9Z3GM LJsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=bqAwaNQS; 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 o11-20020a63f14b000000b0046ea4ef43ffsi8720888pgk.375.2022.10.31.06.23.26; Mon, 31 Oct 2022 06:23:40 -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=@infradead.org header.s=desiato.20200630 header.b=bqAwaNQS; 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 S230433AbiJaM4z (ORCPT + 98 others); Mon, 31 Oct 2022 08:56:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229457AbiJaM4x (ORCPT ); Mon, 31 Oct 2022 08:56:53 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61710DFD3 for ; Mon, 31 Oct 2022 05:56:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=P91jJYlp3/SRYMEHazqCZDlSoldIH8d9qsUcRa3UgNg=; b=bqAwaNQS9h90H4l8k32eQU6xpb Nd8UZ2+G8LqIuD0JCXWAfORNDnyMd9wqT/lnsVLV8rtXQMxG/nDzPXdUEOIAdl6peZTmBIjki26hI 4ZUQPMlAUppWStN4iM3QLdQ3jVpK8oKeBrpaCwxyu5tcmccSoeHRC1EPWbha38b3Syoj3h5uOlOhf FJZ1lIJNT1YE9tuqh+AkkzNI46FjPAM34EigOzYHYDesGWS1WSUTk39/3IOtbraC2RzMfXIT7KMNn XDx/G7Z2ILHnAhK9FcCkJaPc+pJhtC9sfsX2a75Vyb8CMUCR1IuPZe9WazuzGvy+USGwDH0DLs6JB cjJ6maQA==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1opUL9-007sCg-Qb; Mon, 31 Oct 2022 12:56:34 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 303A730020B; Mon, 31 Oct 2022 13:56:31 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 166202C0B8F9E; Mon, 31 Oct 2022 13:56:31 +0100 (CET) Date: Mon, 31 Oct 2022 13:56:30 +0100 From: Peter Zijlstra To: Julian Pidancet Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , linux-kernel@vger.kernel.org, x86@kernel.org Subject: Re: [PATCH v2] x86/alternative: Consistently patch SMP locks in vmlinux and modules Message-ID: References: <20221027204906.511277-1-julian.pidancet@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221027204906.511277-1-julian.pidancet@oracle.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 Thu, Oct 27, 2022 at 10:49:06PM +0200, Julian Pidancet wrote: > The alternatives_smp_module_add() function restricts patching of SMP > lock prefixes to the text address range passed as an argument. > > For vmlinux, patching all the instructions located between the _text and > _etext symbols is allowed. That includes the .text section but also > other sections such as .text.hot and .text.unlikely. > > As per the comment inside the 'struct smp_alt_module' definition, the > original purpose of this restriction is to avoid patching the init code. Urgh.. so yes. We patch before releasing .init stuff, *however* this thing has a mode where it can change it's mind dynamically. That is, if you boot with just a single CPU and then later do CPU hotplug to bring another CPU online, it will quickly scribble the LOCK prefixes back in. And at *that* time it is important to not scribble .init -- because obviously, it'll be gone by then. > For modules, the current code only allows patching instructions located > inside the .text segment, excluding other sections such as .text.hot or > .text.unlikely, which may need patching. > > Make patching of the kernel core and modules more consistent, by > allowing all text sections of modules except .init.text to be patched in > module_finalize(). > > For that, use mod->core_layout.base/mod->core_layout.text_size as the > address range allowed to be patched, which include all the code sections > except the init code. > > Signed-off-by: Julian Pidancet > --- So while I was initially thinking you could just remove all that 'skip-init' stuff and simplify this code, alas you can't without also taking out that whole uniproc_patched case (which I woudln't mind fwiw). As such; this is indeed the minimal patch to make things consistent. Acked-by: Peter Zijlstra (Intel)