Received: by 10.213.65.68 with SMTP id h4csp276993imn; Tue, 13 Mar 2018 04:10:35 -0700 (PDT) X-Google-Smtp-Source: AG47ELvAsmftNKY+jdLR1Xk1UW0jpeIvgEdwVxXtLDX8FPQUbo4ljj8d0dQ2WXV6ClHBYW+ihi2F X-Received: by 10.98.73.140 with SMTP id r12mr175535pfi.229.1520939435300; Tue, 13 Mar 2018 04:10:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520939435; cv=none; d=google.com; s=arc-20160816; b=H0EowoHK3UphwlOiFZ1Z9jQbgJOBjNPUXzpcdOWIixg+PjW9svoscdmd7tyzz57QG8 1cPC1HUCHpZOpVogba/epNagGU57SiNy0G8KszWm6/AaOiKeE+tm6gdX50lqCuyMQSuI Qx5cfHlJZb0KLC3tRRjL/SgunZ6vwqxoaGoz0SB9X4LWTBdn0G0SybPWFjqjYffq8nTS +lCjRYKuS2CfzkCe3XrZHSbBE4h0Ne1riZ+fDMi7+j38mqdihjJROFU6uoddL7dC1njU HdkQfeRHcFvzxVtSWW21k+yfYqVBgfLKfwz+ce1DwGwrX6Kl+5r+VuM01Br9GIoodW+F G5Ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=ahNOtjixL4tou0lKIpCZRoCmvM8ld4/3O10FTPiprHs=; b=nTxoEZjxZiMb/pPTAC2yOitdPVBJl0cgx4yYnR5j9M9KevJrGmcHFd3xQULDc5D+x+ ieG3vg/LmjrRoBKvDKgHZCTlBTstgTqA1LMCM13XIOObiSsWHhLQGLky79PzZTPNBhu4 byS6iJTvP/fmPanq3EtJTERR40eKoN7mMLmTKjaHfIP8apJzsF963tqRC7Sz0lCIPRxN 8JQazymrwhAI+vmXKb+uVOIqhvt3GJy2sO4Oac/dapty70gmcQLdu0dPMZrX3fpojeWf /bWh1lIW3PMRNswCDregj8RK0fdxCrCkBtnat4SYuH3vKFRbdY4XY3gbglEOBIxARjs2 vJUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=QP2qyiPN; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y15si80884pfe.184.2018.03.13.04.10.20; Tue, 13 Mar 2018 04:10:35 -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=@google.com header.s=20161025 header.b=QP2qyiPN; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932869AbeCMLIt (ORCPT + 99 others); Tue, 13 Mar 2018 07:08:49 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:45953 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932713AbeCMLIf (ORCPT ); Tue, 13 Mar 2018 07:08:35 -0400 Received: by mail-pf0-f195.google.com with SMTP id h19so5689290pfd.12 for ; Tue, 13 Mar 2018 04:08:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=ahNOtjixL4tou0lKIpCZRoCmvM8ld4/3O10FTPiprHs=; b=QP2qyiPNxPvxOK7oPW7/kO9G48/TIEaYzaIQJdI5X+wojlMfeKe0pfrORnUywtH6RO osCgo9Ob1LA7QeTJqB2CxeZKWx9Otx+rctsAU8+4/ZNfY6r3D5EFbdwCGhb522uoUuWF d5+jnElz8zzBCQkKH4qOYQ2uYJpWnsNcf7x+CMs7+XFNDnOsxdC4aMo+J7JpX8fjezaU UzN4WNzFIyrJyumUI7ydgcytxOcHsGNgIQ0+bEiUZDfmlcP0jGvZXb/iZwrqVcBbQmbV wJwV/ZnF/LN9lLCzylPxIM2MBRNHMq7QsqYXeyrPQpbLHeh6VIT8v0wgbKvqCgpAo5O/ JZmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=ahNOtjixL4tou0lKIpCZRoCmvM8ld4/3O10FTPiprHs=; b=okVcnjLgNxZo+O+X5W/gl3aoG8crvwSOAHQ9IoqfX8qeRbzSwoEmWUWeGdM59dGSlW 45y8NIpBB9QO7XV6y/VowUNSg98sAeDA/Dn3/s8SRvUXeN8CnDFTCaxLP0ELEkAINtQx JSE4Tlvrim8WOAr7v72ciUZcegvTpV0UYuyFWPcmb7UAIsQ1rePsyyqQuBKoQojz58Ow 0FmDDMDJBckxxnIxGKrmkl2z6ZevBCF9eCkZad/d/yPGAdYxli2BN1zzELINFVF80uxE uZlcFw7U5JLE2WYjyYXgSUFwlag0jRoUcmP8gaSSf/xUt2zS9r+K97yxvxqB6TL9Cqpz 8Asg== X-Gm-Message-State: AElRT7GLYxkFE8hQ8keB75Dp7BkPQbYbIYxBVLwQ2AfHEvgSr/tVE/9S CfXcJ91KsZ0Cx5QK8NUDfNW7rQ+C1yPqoaz5r5aheg== X-Received: by 10.99.105.202 with SMTP id e193mr172235pgc.84.1520939313644; Tue, 13 Mar 2018 04:08:33 -0700 (PDT) MIME-Version: 1.0 Received: by 10.236.141.12 with HTTP; Tue, 13 Mar 2018 04:08:13 -0700 (PDT) In-Reply-To: <20180313104652.GK4043@hirez.programming.kicks-ass.net> References: <201803122219.vHl3IwRo%fengguang.wu@intel.com> <20180313104652.GK4043@hirez.programming.kicks-ass.net> From: Dmitry Vyukov Date: Tue, 13 Mar 2018 14:08:13 +0300 Message-ID: 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) To: Peter Zijlstra , linux-sparse@vger.kernel.org, Christopher Li Cc: kbuild test robot , kbuild-all@01.org, LKML , tipbuild@zytor.com, Ingo Molnar Content-Type: text/plain; charset="UTF-8" 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 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. That would be best of course. +sparse mailing list and Christopher. >> 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.