Received: by 10.213.65.68 with SMTP id h4csp484945imn; Tue, 13 Mar 2018 10:31:13 -0700 (PDT) X-Google-Smtp-Source: AG47ELvFA3D3uWao+iJWyGuAPlJEfGpPjuTr6qUT8siAxQtC3Gc2bu+gtMDxi23qfhrzFAAynI0U X-Received: by 2002:a17:902:8d92:: with SMTP id v18-v6mr1260650plo.21.1520962273192; Tue, 13 Mar 2018 10:31:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520962273; cv=none; d=google.com; s=arc-20160816; b=YVa77+Fpl594Up8aRCGsWZ++1hf7/h0j+3t2vBdcZUPLOY1aCWZ2tCBaQZRshm3GU9 JBVmKVSZpIuIm3j3SG3c/iIiNhyox+o/wG6j5KIWAQUwF65KDtPEXoq/MWlz4xd+HqD6 F6ceXY42tf2EAvEsHJP4mdJ2uRnkog0JkbRZyoC0qZF0swje5DuzFQNxn1zEPLfK+7ot J9fYRgm3Z3GFPQF/k/CPw/ZFGJ2fdWM1McdE97yZbAQnth8cCSvEeagd88/VFQ++pjx0 sMEvIf0Bpni5J8E4mGuvH6IE/HRcdXQk8b1UJO1RvaigrJ/1vb/9JNC8kHpmM23Gm5LA dprQ== 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=SPZK66aXeYq3MnBRpZ0eQSEKtGXqZDiD7isJ0LYYCx8=; b=Y9xf0lS56EsOaoW7uZI0cYoTmAZkMUKk+JS9BrX/GBJJznRobvPFSp6FBLGQ/PXsfB Jc2+PvI2m0s68zwhO+Xb7UCbXNkYJGPIm/HOze+EKjoCQ9Sf1z8oVHO/9JjdM9dCK1X9 TWvkcqFMzwuHTsBOeMQVkO1J96wPyhZlT2/GS7XKeZZgFa6i549yhvbDuKkQq3TX2Ubs bAy0/0W7/XSyZT8qCCCTU3SgRN+F96q5rL3emr8GmmA25gQSq8MSzOxww5Fb0wCFAem1 Cg9F6sgELuGHy72JNOeqUjnxJgnGcup5/Cb/N6RhLWS04NYT7cuXtkujJy0BPHnf4rJR dMaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=MswqE9Ul; 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 g17-v6si410734plo.655.2018.03.13.10.30.58; Tue, 13 Mar 2018 10:31:13 -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=@gmail.com header.s=20161025 header.b=MswqE9Ul; 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 S932383AbeCMR3p (ORCPT + 99 others); Tue, 13 Mar 2018 13:29:45 -0400 Received: from mail-yw0-f193.google.com ([209.85.161.193]:39132 "EHLO mail-yw0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751626AbeCMR3l (ORCPT ); Tue, 13 Mar 2018 13:29:41 -0400 Received: by mail-yw0-f193.google.com with SMTP id l24so283245ywk.6; Tue, 13 Mar 2018 10:29:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=SPZK66aXeYq3MnBRpZ0eQSEKtGXqZDiD7isJ0LYYCx8=; b=MswqE9UlKQIGcYirIlQc8LlEprazHcGYDS/VrN/QPYh0BoEIpSaeC+j/HjQoQUp38w k9Xj+fyLOxX38yn6sek0P9nycsUeoQzkx0rMkJdgfmOgzyUq4f5bLzSW3NaK/nyfv1oN /twVBngwUWO71fOy8H6QBcRUFkav4jI0jvczXv3nZahimzunTtHTTykr4m4egAbYXNIK QWakim2cZ8bBZFkB9LbpzMO+k7Ay/Qs3sG8BlP5ozm9O3e5leRNKK5V4pUyt176aXvxT miw+vBb01y4ezLCVoken8QfdifSCFFhSPHHP1pGGQ989fhCCTHxeFv9zxp0RC2xW6WgN LOLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=SPZK66aXeYq3MnBRpZ0eQSEKtGXqZDiD7isJ0LYYCx8=; b=jOFyJgNs3+T7ZGfACFv3P19b6+mof/mERoHR214AfIgQW+aQtCXWqNB+l+7k1ffLp2 AMF1nKkS7lkpkq8iwf994I3cTMAjqBr3ypJN9rrXhWoVnaUJ3rHT0Ys7EFyXu0fVIyax 6/OwiNePfLxO2DPlDgxCu2brqLIU6htQRkTQt2mWYtjoQ0auuRktLLjd7hkkKBteZtj5 lIzj9frQl7vqN1EX/2+WzsOnnammCZ3Mw5XVaCprU+eNBNoBQX+axAXED54LrmzF76Xx 1Q2xjDdBxYJ0ZudGjSU0o+UK81GqdNmQ3h5KINt/2nFj4TuRStNjJAD5gua7AinmmHd0 OvGg== X-Gm-Message-State: AElRT7ERkvTC8PDC2xv5GdJoPsKHWAmjajth8aoLq04UpnGZ/8dmlkc/ 3lxFPIqBWwZ6sT7WTWSQE9PNTlScDzfbeoefg/al X-Received: by 10.129.30.19 with SMTP id e19mr1218224ywe.44.1520962181187; Tue, 13 Mar 2018 10:29:41 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a25:bf90:0:0:0:0:0 with HTTP; Tue, 13 Mar 2018 10:29:40 -0700 (PDT) In-Reply-To: References: <201803122219.vHl3IwRo%fengguang.wu@intel.com> <20180313104652.GK4043@hirez.programming.kicks-ass.net> From: Christopher Li Date: Tue, 13 Mar 2018 10:29:40 -0700 X-Google-Sender-Auth: ZglCEQh5n-IFE3B0E7xZeGVlhok 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: Dmitry Vyukov Cc: Peter Zijlstra , Linux-Sparse , 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 4:08 AM, Dmitry Vyukov wrote: > On Tue, Mar 13, 2018 at 1:46 PM, Peter Zijlstra wrote: >> >>> >> 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. So you are saying cmpxchg_size() was call with a size==2, however sparse did not do the constant propagation or evaluation properly. So that it did not eliminate the other branch of size==1 case statement. Can you do a "sparse -E" on the original file, then save the result to a new file. That will take care of the pre-processing. Then run the sparse on the pre-processed file to get a smaller test case? Having a smaller test case would make it easier to reproduce what exactly IR was issued during that warning. >>> 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. Let's not do that. If it is a sparse problem, let's try to fix this sparse. Chris