Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1756384rwe; Sat, 27 Aug 2022 16:34:37 -0700 (PDT) X-Google-Smtp-Source: AA6agR71ZOaCkDUOqka6eo08QTW7se0hMOXFd2lstNI2lfqBG5x+S8ddNnbhTtOo3lB7IXeSLBp0 X-Received: by 2002:a17:906:cc14:b0:73d:d230:2aa8 with SMTP id ml20-20020a170906cc1400b0073dd2302aa8mr8461646ejb.218.1661643277667; Sat, 27 Aug 2022 16:34:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661643277; cv=none; d=google.com; s=arc-20160816; b=AslB8/97oOwWcO/aVb8XwW5Azrm1qjDsViw8DipgVChfFl4aURRz+gW9kkIdQSM4p0 KdxtKYw5cTWmg+6jIi9ZuDf8ciUD4sfhzY7CvA5AF3U2LI/hhYQnWw02P0uexWMEeq0O KNBFvhi8Qd+pSQbKWZbliMtvnPpEdnD54xLq/FLiKA4sA5akgjZr9C4jR+sVVhxs4TdY CAWYcAfyTBOR+5DLV87jMCdlPIHBIFlApHunjCPvgwl74RkLruzKsFpcB7i9KHBKdWjl TNZOMbJiayb02HtMEpLYISWyrPeOQzQ44FLinQj8WtoU4egfp8CPrhsJWLfwqpRSIDr4 gPTA== 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=hVrRvUbN6M9WvU2EOUcbBcGzPtuEK4M54qLfxCLgJj8=; b=UWtdQeKvmFRxH4aN+6PoKo1VibdBpd5jZOsiQZ+I2qhgmdLkcpbWFmEsDMmq2adAdc B2NGQQQlgPA0ps3ISqaTdHbSRjezTmnVaqQI0wpxntZeczIdpXr4kTuhttpRrQ5cYAB8 FADBYuY+mRjWgD4Kjf1U6/bPKE72467TwLDEAHZ83+xbOlBAsH0dj7DDAF2hCvTrbhZB M/yJOGAYi3Sh86wbvKN7zyv/kYPp9MIld5nPBLVwH90bI4o2S2U05EJOt9f/Wt5buguh WkVfdugRSfo+dx/E0upGezxLL6UlP3QSGyoHE0fGUTlniARGIQ9fzbZzJzoip0VLuJWW RyRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="S0/6c+dZ"; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j14-20020a05640211ce00b0043c94968998si4971425edw.385.2022.08.27.16.33.51; Sat, 27 Aug 2022 16:34:37 -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=@kernel.org header.s=k20201202 header.b="S0/6c+dZ"; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229852AbiH0W7o (ORCPT + 99 others); Sat, 27 Aug 2022 18:59:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229464AbiH0W7m (ORCPT ); Sat, 27 Aug 2022 18:59:42 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B18694054E; Sat, 27 Aug 2022 15:59:41 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6B08E60EC5; Sat, 27 Aug 2022 22:59:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 794B5C433C1; Sat, 27 Aug 2022 22:59:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661641179; bh=0wKh1+suBHOHM0x8NCY0MJqyrQ71HC2Hlr27mRJ5BOM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=S0/6c+dZgq5SPHEs8no7mHkj7cXoctmlthAFdclJj4MrbTlRbIHW18ojPOW5eYgzj sWvGCmp/waOmKDADhFh5RpuR4Oak5JhY7Hi0lxWCZRh565171FXfvHKq/VtpngvHMo m3HptsN83Br2cz0b8q7rSLlgvSXbpvgJ60LRhwUjy1UfkLtQbMyx16U+bF5U3Ox4I/ vtOIhIqvZMA/2+wrpzp8O+pICXPJG/KdJi0dDVLdaGnsGXk5BWEMsqumM0EfxJg3tH 2caLeMjagFZtWsPLSj9Qh7dwVKfXz3/IGzFFo3AMOcZkBVwBtRz8JW5E7N8UsnsRyn sU2aJDBMydTRQ== Date: Sat, 27 Aug 2022 15:59:37 -0700 From: Josh Poimboeuf To: Heiko Carstens Cc: Vasily Gorbik , Alexander Gordeev , linux-s390@vger.kernel.org, Christian Borntraeger , Sven Schnelle , linux-kernel@vger.kernel.org, Sumanth Korikkar Subject: Re: [PATCH RFC] s390: Fix nospec table alignments Message-ID: <20220827225937.b2mcmvxs7kbrtjda@treble> References: <8719bf1ce4a72ebdeb575200290094e9ce047bcc.1661557333.git.jpoimboe@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Sat, Aug 27, 2022 at 08:23:17PM +0200, Heiko Carstens wrote: > On Fri, Aug 26, 2022 at 04:55:44PM -0700, Josh Poimboeuf wrote: > > Add proper alignment for .nospec_call_table and .nospec_return_table in > > vmlinux. > > > > Fixes: f19fbd5ed642 ("s390: introduce execute-trampolines for branches") > > Signed-off-by: Josh Poimboeuf > > --- > > This is RFC because I don't know anything about s390 behavior for > > unaligned data accesses, but this seemed to fix an issue for me. > > > > While working on another s390 issue, I was getting intermittent boot > > failures in __nospec_revert() when it tried to access 'instr[0]'. I > > noticed the __nospec_call_start address ended in 'ff'. This patch > > seemed to fix it. I have no idea why it was (only sometimes) failing in > > the first place. > > > > The intermittent part of it is probably at least partially explained by > > CONFIG_RANDOMIZE_BASE. Except now I can no longer recreate it :-/ > > > > Regardless, this patch seems correct. I just can't explain what I saw. > > Any ideas? > > > > arch/s390/kernel/vmlinux.lds.S | 1 + > > 1 file changed, 1 insertion(+) > > > > diff --git a/arch/s390/kernel/vmlinux.lds.S b/arch/s390/kernel/vmlinux.lds.S > > index 2e526f11b91e..5ea3830af0cc 100644 > > --- a/arch/s390/kernel/vmlinux.lds.S > > +++ b/arch/s390/kernel/vmlinux.lds.S > > @@ -131,6 +131,7 @@ SECTIONS > > /* > > * Table with the patch locations to undo expolines > > */ > > + . = ALIGN(4); > > .nospec_call_table : { > > __nospec_call_start = . ; > > *(.s390_indirect*) > > On s390 labels must be at an even address due to instructions like > "larl" (load address relative long), which generate a pc-relative > address adding the number of words encoded into the instruction to the > current IP. > > With commit e6ed91fd0768 ("s390/alternatives: remove padding > generation code") I managed to reduce the size of struct alt_instr by > one byte, so it is now only 11 bytes in size. So depending on the size > / number of members of the __alt_instructions array nospec_call_table > starts at an uneven address, which would explain this. > > Unfortunately I was unable to let any compiler generate code, that > would use the larl instruction. Instead the address of > nospec_call_table was loaded indirectly via the GOT, which again works > always, regardless if the table starts at an even or uneven address. > > This needs to be fixed anyway, and your patch certainly is correct. > > Could you maybe share your kernel config + compiler version, if you > are still able to reproduce this? I think the trick is to disable CONFIG_RELOCATABLE. When I compile with CONFIG_RELOCATABLE=n and "gcc version 11.3.1 20220421 (Red Hat 11.3.1-2) (GCC)", I get the following in nospec_init_branches(): 2a8: c0 20 00 00 00 00 larl %r2,2a8 2aa: R_390_PC32DBL __nospec_call_start+0x2 That said, I still haven't been able to figure out how to recreate the program check in __nospec_revert(), even when the nospec_call_table starts at an odd offset. BTW, I only discovered this when testing with my pending patches which propose getting rid of -fPIE for CONFIG_RELOCATABLE, so that more than 64k sections can be supported. But that's a separate topic :-) -- Josh