[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] timer: fix NR_CPUS=1 build with gcc13


  • To: George Dunlap <george.dunlap@xxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 13 Sep 2023 12:05:35 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=OinQoExWZMlPc7L6eagJNL3rh8WBAkMS4xivQnrIhDI=; b=euqjFC6alU/Oq7OIDEEKIpsPgpEep72M06xpR7rWq7p6gIER2ppFfwGssbqbWIwbeohgA/Q0j/J6IaC3MwPfu6vsGe6T56Pu8OrbfceKaJEk3y0VqKP+rNVlPsNnkWZYwwtv+IEdoZFBMP6NY7xjumop0gHuX4gQVaX7h3FMJIDqdZfS1uWnsUvLR1/ecRrRRt7xA6wSweoAX8V8ntmLJFz2m5fxuW3U8Jbqv0+VehLo3nCXWTYXZcMSWVI/SgtLl7YxtJtqFlqXA/bTA+fiXIQx2DZT+hpWfecxM8ox37GOiTh3EuJrphg8V8OwYwmqlzvywho9a3raZM6QpukgKQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Nq7HBpIkHhNNpzMeuA7zCfFZIttYbxP8gtsrpH0cS58wu/FyeYTF9+og7RiktynPDc6OSODGh5pjWa1isZvVqn6tH9l1DEhsVN/BR50/QShbJA20lJd+o64ZpFcPuDUa7K5yH4JzcT3qS7O1bZx8amnBYne0gS/s+v20eUMcHFVzdU7ZxZHWMltHsBjw5I54+h3fRMdD1fwoJ7ZVllQH2er7TE4bEU2WilokgjLMkEa59qgfvhxaTTVB8cntQQUVi71keYGwQRgmfTpNjLOiINURRS17DzuWXs7aBrHxzouNIgAZLbpkuvxXndbTtTif3Xvs6mzQLR0m9PfwakrOlw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Wed, 13 Sep 2023 10:05:50 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 13.09.2023 11:44, George Dunlap wrote:
> On Wed, Sep 13, 2023 at 8:32 AM Jan Beulich <jbeulich@xxxxxxxx> wrote:
>>
>> Gcc13 apparently infers from "if ( old_cpu < new_cpu )" that "new_cpu"
>> is >= 1, and then (on x86) complains about "per_cpu(timers, new_cpu)"
>> exceeding __per_cpu_offset[]'s bounds (being an array of 1 in such a
>> configuration). Make the code conditional upon there being at least 2
>> CPUs configured (otherwise there simply is nothing to migrate [to]).
> 
> Hmm, without digging into it, migrate_timer() doesn't seem like very
> robust code: It doesn't check to make sure that new_cpu is valid, nor
> does it give the option of returning an error if anything fails.

Question is - what do you expect the callers to do upon getting back
failure?

> Making migrate_timer() just do nothing on 1-cpu systems seems will
> remove the warning, but not really make things safer.
> 
> Is this a super hot path?

I don't think it is.

>  Would it make more sense to add `||
> (new_cpu > CONFIG_NR_CPUS)` to the early-return  conditional at the
> top of the first `for (; ; )` loop?

But that would mean not doing what was requested without any indication
to the caller. An out-of-range CPU passed in is generally very likely
to result in a crash, I think.

> I guess if we don't expect it ever to be called, it might be better to
> get rid of the code entirely; but maybe in that case we should add
> something like the following?
> 
> ```
> #else
>     WARN_ONCE("migrate_timer: Request to move to %u on a single-core
> system!", new_cpu);
>     ASSERT_UNREACHABLE();
> #endif
> ```

With the old_cpu == new_cpu case explicitly permitted (and that being
the only legal case when NR_CPUS=1, which arguably is an aspect which
makes gcc's diagnostic questionable), perhaps only

#else
    old_cpu = ...;
    if ( old_cpu != TIMER_CPU_status_killed )
        WARN_ON(new_cpu != old_cpu);
#endif

(I'm afraid we have no WARN_ON_ONCE() yet, nor WARN_ONCE())?

Jan



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.