Received: by 10.213.65.68 with SMTP id h4csp266413imn; Tue, 13 Mar 2018 03:48:33 -0700 (PDT) X-Google-Smtp-Source: AG47ELtwHk8FnqfSku5sNFCUk7yzuiKiWy489Mq4WVwLxOWeSc8L5svBrVCOU5elwjfsVD/MvljC X-Received: by 10.98.36.25 with SMTP id r25mr155622pfj.106.1520938113466; Tue, 13 Mar 2018 03:48:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520938113; cv=none; d=google.com; s=arc-20160816; b=JpqKS7IHSGvEVte0Y0vI08khQVEQ59zdStc92hQovoqr9rYZoQXkYtiEE42DNmlmVV 5L7nUxNm6LcByDqDev3VW5k/JS1WuGK7YRj9JLgqMhothrGXWcHQis0gKeTA4LDRa5q7 O08Uq3bFD6/sx+0x1YXNu0TE6cs9jLLfMnWJpW5HseqUopnWpOVcndUHvXY6ulTbjntA HW2Y0cMMxs9eSJFivDYtHZoQYRpZFtCh12gcEIPOW8v+qlp6u2/arSatM0jNcEpRUMc/ hZjWnAaGtxzb2Ql0Hz3pGz5rmbQxkwACKa95iq7u9pQ5gROd1znlZPHBTeIfvxZk1bGq rJkg== 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=P0+idFlOHP/rPUHRhkP343S5Hg86PpGT2HvymZ/7Ppw=; b=hCpIXGoa4LQ+Y+KO8ZXlGgcwgXsiqfg8KYG/js3d5i7tCfeBBzwVzhPtm7ux73CFvL tJg9NfrBDSi6p6GREQ7axc4KbRWaotUAHH29IdEMBqYQsqkbsHefaeeteQcchPmwAVKm iJJQU+9sZgpGHvVgj1iW7k01zN0NKDxc5dC9fbdB+DklLfrtSjDFXKqogx47KkHw8UN5 JMtCUBU9pYK7lS4PkB94yYj6d2A4+TPpmHdDHu/WH/CmZlBj6xZYY7pMGLiW/loENQMx AdWoEnUS/rudB0gm0TspsUFoDZoYM9oZ+yHVkWpmYZtcMw3TdcsITplQFpzVOt3uO2Yr LxMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=M+9HxNmw; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h6-v6si48124pll.328.2018.03.13.03.48.18; Tue, 13 Mar 2018 03:48:33 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=M+9HxNmw; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932697AbeCMKq5 (ORCPT + 99 others); Tue, 13 Mar 2018 06:46:57 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:35358 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932514AbeCMKq4 (ORCPT ); Tue, 13 Mar 2018 06:46:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; 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:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=P0+idFlOHP/rPUHRhkP343S5Hg86PpGT2HvymZ/7Ppw=; b=M+9HxNmwqqjhpAsXg7E/9Ao8Z JvdsMlsCIAxYJCpDNLUQgzYwu4gbU/jA1g2T9tU/019SalYdhaXGy99wzL0dLwZjSey1ykgXE0kXq KiGZwVhiAe4DbJdbNymRoVAV9b3SLfiLKHHKD22ZbFM60ln3KCmOGhSmNpggJsr4foyMCYBkEKHEp eLSn/1E78C4JRiJ4CANfH7Gm+1MOkB/7mHcZC9t8I4ciOoIXvzsx5M2xmcfGap3yKHtc9ePnJXdh+ Zs0WGDn40ZcO4QbSc14g9YHCl+cbtffQidjbEf/i2RN8o/u3hjnuaM1y0iINxvR5mktTqua7Hx9YM v8hjWRCiQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1evhSH-0005SE-Us; Tue, 13 Mar 2018 10:46:54 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 691C62029FA14; Tue, 13 Mar 2018 11:46:52 +0100 (CET) Date: Tue, 13 Mar 2018 11:46:52 +0100 From: Peter Zijlstra To: Dmitry Vyukov Cc: 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: <20180313104652.GK4043@hirez.programming.kicks-ass.net> References: <201803122219.vHl3IwRo%fengguang.wu@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.3 (2018-01-21) 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 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. > Off the top of my head I can think of the following solution: > > switch (size) { > case 1: > return arch_cmpxchg((u8 *)ptr, (u8)(old * (size != > 1)), (u8)(new * (size != 1))); > case 2: > return arch_cmpxchg((u16 *)ptr, (u16)(old * (size != > 2)), (u16)(new * (size != 2))); > > But it's too ugly. Yes agreed, that's horrendous.