public inbox for linux-next@vger.kernel.org 
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead•org>
To: Josh Poimboeuf <jpoimboe@kernel•org>
Cc: Randy Dunlap <rdunlap@infradead•org>,
	Stephen Rothwell <sfr@canb•auug.org.au>,
	Linux Next Mailing List <linux-next@vger•kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger•kernel.org>,
	matz@suse•de
Subject: Re: linux-next: Tree for Sep 13 (objtool)
Date: Thu, 14 Sep 2023 09:23:27 +0200	[thread overview]
Message-ID: <20230914072327.GB16631@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20230913214753.3xqemkqjhxcwqaz4@treble>


On Wed, Sep 13, 2023 at 11:47:53PM +0200, Josh Poimboeuf wrote:
> On Wed, Sep 13, 2023 at 01:34:11PM -0700, Randy Dunlap wrote:
> > 
> > 
> > On 9/12/23 22:04, Stephen Rothwell wrote:
> > > Hi all,
> > > 
> > > Changes since 20230912:
> > > 
> > > The bpf-next tree (I think) gained a boot time warning due to a semantic
> > > interaction with changes in the bpf tree.
> > > 
> > > The drm-misc tree gained a conflict against Linus' tree.
> > > 
> > > Non-merge commits (relative to Linus' tree): 4427
> > >  1907 files changed, 354449 insertions(+), 27039 deletions(-)
> > > 
> > > ----------------------------------------------------------------------------
> > 
> > on x86_64:
> > 
> > drivers/media/common/siano/smscoreapi.o: warning: objtool: .text.unlikely: unexpected end of section
> > 
> > Full randconfig file is attached.
> 
> Objtool is correct:
> 
>   Disassembly of section .text.unlikely:
> 
>   0000000000000000 <smscore_set_device_mode.cold>:
>      0:   48 83 05 00 00 00 00 01         addq   $0x1,0x0(%rip)        # 8 <__UNIQUE_ID___addressable_smscore_unregister_client433>       3: R_X86_64_PC32        .bss+0xa03
> 
> It's not really a functional bug, it's just gcov somehow keeping GCC
> from finishing an optimization.
> 
> In smscore_load_firmware_from_file(), which gets inlined by
> smscore_set_device_mode(), GCC is smart enough to know that
> 
>   'coredev->device_flags & SMS_DEVICE_FAMILY2'
> 
> is always true, so it half-optimizes out the ':' condition:
> 
> 		rc = (coredev->device_flags & SMS_DEVICE_FAMILY2) ?
> 			smscore_load_firmware_family2(coredev, fw_buf, fw_buf_size)
> 			: loadfirmware_handler(coredev->context, fw_buf,
> 			fw_buf_size);
> 
> Though it actually still keeps the branch.  It goes to
> smscore_set_device_mode.cold so it can set the GCOV "branch taken" bit
> for the !SMS_DEVICE_FAMILY2 case.  But then it just falls off the edge
> off .text.unlikely.
> 
> Peter, any opinions how to handle this?

Ask the GCC people to not do this? :-)

> We could just make smscore_load_firmware_from_file() noinline.
> 
> Or we could hard-code the fact that smscore_load_firmware_from_file() is
> only called in the SMS_DEVICE_FAMILY2 case, like:

Yeah, this seems simplest. The code in question doesn't seem overly
complicated and we can simply avoid confusing GCC.

> diff --git a/drivers/media/common/siano/smscoreapi.c b/drivers/media/common/siano/smscoreapi.c
> index 7d4bc2733f2b..58d951903e93 100644
> --- a/drivers/media/common/siano/smscoreapi.c
> +++ b/drivers/media/common/siano/smscoreapi.c
> @@ -1127,19 +1127,19 @@ static char *smscore_get_fw_filename(struct smscore_device_t *coredev,
>   * @param coredev pointer to a coredev object returned by
>   *                smscore_register_device
>   * @param filename null-terminated string specifies firmware file name
> - * @param loadfirmware_handler device handler that loads firmware
>   *
>   * return: 0 on success, <0 on error.
>   */
>  static int smscore_load_firmware_from_file(struct smscore_device_t *coredev,
> -					   int mode,
> -					   loadfirmware_t loadfirmware_handler)
> +					   int mode)
>  {
>  	int rc = -ENOENT;
>  	u8 *fw_buf;
>  	u32 fw_buf_size;
>  	const struct firmware *fw;
>  
> +	BUG_ON(coredev->device_flags != SMS_DEVICE_FAMILY2);
> +
>  	char *fw_filename = smscore_get_fw_filename(coredev, mode);
>  	if (!fw_filename) {
>  		pr_err("mode %d not supported on this device\n", mode);
> @@ -1147,10 +1147,6 @@ static int smscore_load_firmware_from_file(struct smscore_device_t *coredev,
>  	}
>  	pr_debug("Firmware name: %s\n", fw_filename);
>  
> -	if (!loadfirmware_handler &&
> -	    !(coredev->device_flags & SMS_DEVICE_FAMILY2))
> -		return -EINVAL;
> -
>  	rc = request_firmware(&fw, fw_filename, coredev->device);
>  	if (rc < 0) {
>  		pr_err("failed to open firmware file '%s'\n", fw_filename);
> @@ -1166,10 +1162,7 @@ static int smscore_load_firmware_from_file(struct smscore_device_t *coredev,
>  		memcpy(fw_buf, fw->data, fw->size);
>  		fw_buf_size = fw->size;
>  
> -		rc = (coredev->device_flags & SMS_DEVICE_FAMILY2) ?
> -			smscore_load_firmware_family2(coredev, fw_buf, fw_buf_size)
> -			: loadfirmware_handler(coredev->context, fw_buf,
> -			fw_buf_size);
> +		rc = smscore_load_firmware_family2(coredev, fw_buf, fw_buf_size);
>  	}
>  
>  	kfree(fw_buf);
> @@ -1353,8 +1346,7 @@ int smscore_set_device_mode(struct smscore_device_t *coredev, int mode)
>  		}
>  
>  		if (!(coredev->modes_supported & (1 << mode))) {
> -			rc = smscore_load_firmware_from_file(coredev,
> -							     mode, NULL);
> +			rc = smscore_load_firmware_from_file(coredev, mode);
>  			if (rc >= 0)
>  				pr_debug("firmware download success\n");
>  		} else {

  reply	other threads:[~2023-09-14  7:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-13  5:04 linux-next: Tree for Sep 13 Stephen Rothwell
2023-09-13 20:34 ` linux-next: Tree for Sep 13 (objtool) Randy Dunlap
2023-09-13 21:47   ` Josh Poimboeuf
2023-09-14  7:23     ` Peter Zijlstra [this message]
2023-09-14 13:54       ` Josh Poimboeuf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230914072327.GB16631@noisy.programming.kicks-ass.net \
    --to=peterz@infradead$(echo .)org \
    --cc=jpoimboe@kernel$(echo .)org \
    --cc=linux-kernel@vger$(echo .)kernel.org \
    --cc=linux-next@vger$(echo .)kernel.org \
    --cc=matz@suse$(echo .)de \
    --cc=rdunlap@infradead$(echo .)org \
    --cc=sfr@canb$(echo .)auug.org.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox