Received: by 10.213.65.68 with SMTP id h4csp504386imn; Tue, 13 Mar 2018 11:07:44 -0700 (PDT) X-Google-Smtp-Source: AG47ELvF3eKiMRWAL/JNDxPawICn2SHgVohZiHggqHdDK33grzMxu5QMqPcCqTWeF0AEdAz6OTeZ X-Received: by 10.99.170.5 with SMTP id e5mr1184923pgf.92.1520964464250; Tue, 13 Mar 2018 11:07:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520964464; cv=none; d=google.com; s=arc-20160816; b=ckZQ3yDCsFJrhQn8MzF4gvlthww+Co0Zy/M6TMtbm8CskidGxVP5xA1+1LBvSq0bXl WSwZWXTOQx3HJQ6RFRcRAXZFhfCV1ya7TQ9nMB3PC9v4xppbHFisRuQVaLDPndlB84T6 o8A1remMpn55/AGxOr+lURF6RmvX3lWTDIUGEivrRi2TRwxITWdJCdnbaoG3jr1peRut BjJs5FzjZN7c55Vtfkfg7bjnyNboJYwfZmEFDlvTPpKnyBcs9/Nk5Zl3UBamyIPBEviR PxQ5hN9l1kxQMl0Hb4ZqrnLqPrSsVLdhdcOuC8B9zcxrZwfRvv+FVdhBrc3FKNz4cFv8 tRoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=C7Xt/UGoWDIQxvtDHRZx6B8Cyx1p0moEKoLwI5NmlyY=; b=BjyfteERiLE0Z2tfZ4gHHIjeOqw5AwTd4OAeAZoXt22UrNwfFK9J64KqYvNGWW5qpk 6ds/+g6ym4xDKuParWk0JuMKYKDuinKp7ZueDFvJcg0rzTp2BWl9rgTuH6p85QBqE3sQ D1sJQnwK0qVghkxVwwGb4kEEP/0RVYiKYc+J1JL/AGjRNpPc+4MKlTZBQ3oFJ4oTLy8G ObgLMOcFk9iE6mDGAjRu6+gLl3LrAlY9FsJm7CCtHPB5MrewNZ6FcoeaE01xwbuocS/K pEYS+c//OmFwdWY+Y07ZER9bmt3berBr07dUXyp7O9K05NfkiwjYZiDTMtKQs4H0lDX+ vRXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ebum2MSa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d18si440634pgo.209.2018.03.13.11.07.29; Tue, 13 Mar 2018 11:07:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ebum2MSa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752632AbeCMSA2 (ORCPT + 99 others); Tue, 13 Mar 2018 14:00:28 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:44524 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752451AbeCMSAX (ORCPT ); Tue, 13 Mar 2018 14:00:23 -0400 Received: by mail-wr0-f196.google.com with SMTP id v65so1364219wrc.11; Tue, 13 Mar 2018 11:00:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=C7Xt/UGoWDIQxvtDHRZx6B8Cyx1p0moEKoLwI5NmlyY=; b=ebum2MSaJHTaDNnnfrL93VUrs8X8LaSMIDO44sBs9T8YX64/QmQ2DvZ9NPnOIcPKOG djG5vzrwuI+BvfsYlt7ZDo7ygrS+gyvRD5z7iwtL/KerqDaGmb2G4IAi6HxTXAY9aVn+ lZd4XCXk6XflFbYkYNNyq013LQj81y+TsYbcoNJ4UIc5gGPixQL+P14cV4Cgzd/PnxG/ giZLM5EqZiWYAllUU2JtyqVbAPM9wv9vfin5lOzMjE/7kYb/RDWKmqUl4iIRdFhMEJTy uS3QGhJCgQENv6WKEIAxuNHMViLJKL5EFiNhXj2TfZG+A6D6uwwC+stfHRMTUck6ZEn3 gA/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=C7Xt/UGoWDIQxvtDHRZx6B8Cyx1p0moEKoLwI5NmlyY=; b=thAsznO56jUIxsAvxt32BJP4xlFzJU5aqElCJJ/KMAgXpAAy1zIDhfWS59xMFF051B cULxH4O8jb5HBsO94ZKfvv+7vRpiVjtZUfNgFx2yJwCV8ucGulO9W7RLzSX4dGIbUPft oH2j3UXoyxFtmSY1tYsfJ3lZQIjJfhzH5+ZNLtuaGgHI3vLggONvpvW+PwcCdwZZwfNx bXJ69ouNfB5ASkw8S+bQ6XFTZ6bA9fJt/hg4dtDlsmv7mhCYdGE6+nX4HmWwcE4KP9II 2yh7YXBwd/pmZpcLkvHFyHDqQWRsRIZTa2HPz1xja1UHcoJo+JIKSUWRIB/ExOd01LZn RONg== X-Gm-Message-State: AElRT7GBrlMA0NhUAL67HMRCINC3G26TsDi/CbTdVijSqkAxyYQuzB5k Xu+1udWjsdSH12cG2n3XjsY= X-Received: by 10.28.50.69 with SMTP id y66mr1565152wmy.35.1520964021854; Tue, 13 Mar 2018 11:00:21 -0700 (PDT) Received: from ltop.local (16.107-66-87.adsl-dyn.isp.belgacom.be. [87.66.107.16]) by smtp.gmail.com with ESMTPSA id 55sm988994wrw.87.2018.03.13.11.00.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Mar 2018 11:00:20 -0700 (PDT) Date: Tue, 13 Mar 2018 19:00:17 +0100 From: Luc Van Oostenryck To: Dmitry Vyukov Cc: Peter Zijlstra , linux-sparse@vger.kernel.org, Christopher Li , kbuild test robot , kbuild-all@01.org, LKML , tipbuild@zytor.com, Ingo Molnar Subject: Re: [tip:locking/core 9/11] include/asm-generic/atomic-instrumented.h:288:24: sparse: cast truncates bits from constant value (100 becomes 0) Message-ID: <20180313180016.5axdobx6a624snpp@ltop.local> References: <201803122219.vHl3IwRo%fengguang.wu@intel.com> <20180313104652.GK4043@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20171215 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 13, 2018 at 02:08:13PM +0300, Dmitry Vyukov wrote: > On Tue, Mar 13, 2018 at 1:46 PM, Peter Zijlstra wrote: > > On Tue, Mar 13, 2018 at 11:49:17AM +0300, Dmitry Vyukov wrote: > >> On Mon, Mar 12, 2018 at 6:17 PM, Dmitry Vyukov wrote: > >> > On Mon, Mar 12, 2018 at 5:52 PM, kbuild test robot > >> >> kernel/locking/qspinlock.c:418:22: sparse: incorrect type in assignment (different modifiers) @@ expected struct mcs_spinlock *prev @@ got struct struct mcs_spinlock *prev @@ > >> >> kernel/locking/qspinlock.c:418:22: expected struct mcs_spinlock *prev > >> >> kernel/locking/qspinlock.c:418:22: got struct mcs_spinlock [pure] * > > > >> >> b06ed71a6 Dmitry Vyukov 2018-01-29 283 static __always_inline unsigned long > >> >> b06ed71a6 Dmitry Vyukov 2018-01-29 284 cmpxchg_size(volatile void *ptr, unsigned long old, unsigned long new, int size) > >> >> b06ed71a6 Dmitry Vyukov 2018-01-29 285 { > >> >> b06ed71a6 Dmitry Vyukov 2018-01-29 286 switch (size) { > >> >> b06ed71a6 Dmitry Vyukov 2018-01-29 287 case 1: > >> >> b06ed71a6 Dmitry Vyukov 2018-01-29 @288 return arch_cmpxchg((u8 *)ptr, (u8)old, (u8)new); > >> >> b06ed71a6 Dmitry Vyukov 2018-01-29 289 case 2: > >> >> b06ed71a6 Dmitry Vyukov 2018-01-29 290 return arch_cmpxchg((u16 *)ptr, (u16)old, (u16)new); > >> >> b06ed71a6 Dmitry Vyukov 2018-01-29 291 case 4: > >> >> b06ed71a6 Dmitry Vyukov 2018-01-29 292 return arch_cmpxchg((u32 *)ptr, (u32)old, (u32)new); > >> >> b06ed71a6 Dmitry Vyukov 2018-01-29 293 case 8: > >> >> b06ed71a6 Dmitry Vyukov 2018-01-29 294 BUILD_BUG_ON(sizeof(unsigned long) != 8); > >> >> b06ed71a6 Dmitry Vyukov 2018-01-29 295 return arch_cmpxchg((u64 *)ptr, (u64)old, (u64)new); > >> >> b06ed71a6 Dmitry Vyukov 2018-01-29 296 } > >> >> b06ed71a6 Dmitry Vyukov 2018-01-29 297 BUILD_BUG(); > >> >> b06ed71a6 Dmitry Vyukov 2018-01-29 298 return 0; > >> >> b06ed71a6 Dmitry Vyukov 2018-01-29 299 } > >> >> b06ed71a6 Dmitry Vyukov 2018-01-29 300 > > > >> It seems that this is due to this guy: > >> > >> static __always_inline int trylock_clear_pending(struct qspinlock *lock) > >> { > >> struct __qspinlock *l = (void *)lock; > >> > >> return !READ_ONCE(l->locked) && > >> (cmpxchg_acquire(&l->locked_pending, _Q_PENDING_VAL, > >> _Q_LOCKED_VAL) == _Q_PENDING_VAL); > >> } > >> > >> _Q_PENDING_VAL is 0x100. However, locked_pending is 2 bytes. So it > >> seems that compiler checks all switch cases, this inevitably will lead > >> to such warnings. > >> > >> Any suggestion on how to resolve this? Leave as is? > > > > I'm not sure I understand what it thinks is wrong. Can't we fix sparse > > to not be stupid? The actual compilers don't seem to a have a problem > > with this. The issue here is that sparse has a whole class of warnings that are given very early (here at expansion of constant expressions), before eliminating code from branches that are never taken (which, surprise, need itself to have constant expressions already expanded). It's often annoying like the case here. OTOH, I don't think it's always a bad thing. Sometimes we want to have warnings even from code we know will not be executed (in this config but maybe it will in another one). Several solution would be possible: 1) removing all those early warnings (but then we'll loose more legitimate ones) 2) add an option to not issues those early warnings (ame as above). 3) move those warnings (and thus the expansion of the concerned constants) after trivial dead code elimination 4) add a very early pass to eliminate never taken branches 5) something else ? 1) & 2) are easy but not really acceptable. 3) can be good for some cases but not here, I think. 4) seems to way to go -- Luc Van Oostenryck