Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3985973imm; Mon, 14 May 2018 00:29:05 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrCqMnhCq7ESStfvb75y1gszqQfVrpgke0Ub2ZvlyeBTsEIT+U+llE877E1fheVrtENh+mu X-Received: by 2002:a63:41c4:: with SMTP id o187-v6mr2146655pga.7.1526282945088; Mon, 14 May 2018 00:29:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526282945; cv=none; d=google.com; s=arc-20160816; b=lfgw20ICjqWyhph2ZWZdxkUGLsFT8r1AV04jPT4mcByoIp9m7DAQVTZjmyhvt/3ByK 7oWhtLA4f2kStNZtlWBX/wQo0G3Lk7jyskYvRVy/2Ta4cH4TcUfVD6RRnd8uyRbajfBv 6aOxYAYkQ7drZ0t2tJHe2rEqzpfrQL2jNBNx6Z9QT/Jxa9ZpGJtARysmzaQiJ0DdNNAA 2V+CmMKIy0khqKbhM8aaTCp1yx59baqi5ICQbTkMLrh/eaBKMouT+Pr5Kav28JF3h7t6 0JLJUUE3/NhLaG8n3i9c96MsCo/g0MnpoAw9LdKMyGON1QKvEUzfeorxBsTYFdkDLqje YnPA== 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=S0jw+DYfPIbmJJ4dZdi45krwiy1aqz177paBqUVYDH4=; b=Mbw6xcVQQOGAXZ46b3JxC60tKk6AnfMy4GELKQBnWuzhMD788L4WU4s0Snp0j941Gp 0SV9+pOzViSSYks+prsh3I44TDhv9CpPGu3iRuc6fgA5wA+wwHaEVves0+mOU/KlfHtq KkOwEdMd0yIlgtT2/FWpdJ1jSVnQOGZvzJSXbirxfhYbAMugBB2gU6dy7YZIHr2WVBpm p7HZJQWLnMmjmj/mpAPmHltXPqyWInu2wFGqDzBRNG+FHRCHaJqNApH5hyb8stpI1Ns1 Q0QEeKMcS0DboV37sdWoGcKmlTx8JzOmnwginuXOympYZc4mg7N6nJ6u3nAFR45AuHB2 k+5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=SzdRbMlP; 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 q11-v6si8593916pll.15.2018.05.14.00.28.50; Mon, 14 May 2018 00:29:05 -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=SzdRbMlP; 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 S1753362AbeENH2n (ORCPT + 99 others); Mon, 14 May 2018 03:28:43 -0400 Received: from mail-pf0-f178.google.com ([209.85.192.178]:38089 "EHLO mail-pf0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753261AbeENH2l (ORCPT ); Mon, 14 May 2018 03:28:41 -0400 Received: by mail-pf0-f178.google.com with SMTP id o76-v6so5579934pfi.5 for ; Mon, 14 May 2018 00:28:41 -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=S0jw+DYfPIbmJJ4dZdi45krwiy1aqz177paBqUVYDH4=; b=SzdRbMlPGOjLK5NHITZDmeYlIB1SXit9icnMAcKxEaJIidL8djQ3spGxrqvNpITuaj B8dTBy8Uq7HZ72Exc8N80GeAakN0ViIxs6xynG5K3Heaug3Fb1SgsG1uvdiQTDtCsJPb XTuMMcDmjp22Iz3+eoEjAdcLKLACxm04hkh/bjsc5lhBMm061goBNN7GoZMk/6snaABT NqPT0MhhVfIhR/cxbC4IVC9iMiXzclozlw8Cz00u7z18plTe3s4hHLqD3Q0B7n23QDKg jeX+QYmJRcXn/NquRgaqUxRfyRG6x85peBJgvJzyv+6nAJC0SLgTgQq8YMXdWQLxjwgK v7pw== 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=S0jw+DYfPIbmJJ4dZdi45krwiy1aqz177paBqUVYDH4=; b=TwThE2DFdeokcihCcYagpgMpMuVpQ3fMBAyDDzzk8xmDTZkpVMvH65C3gcCgEffOru HNclKpw8m7SxTZ000OaDIqM3JUugkPZlW7y4ymWErkG812meK8KndmwKUvMpNjxHI/ww JHt+ASOJLSjZSE1HGJZcDbcngNXzY2/qwvNZI8ldysqz3lusKAyQqiaffHn6x67qqzKJ QVXRhPeyws3tpAu/DU/ZGy8LL/Y74/QWJdmbUUtQFu4WPLJHUFLCddllKG1sCq+7AJbA 80w5j8e370sTU7aMEMn7JHFHNRAvAM3vFS1L5nRYeUXujujlZNoOICH5lMfirLVUdK2k OAHA== X-Gm-Message-State: ALKqPwfv+w4aIwaKGRPDP/ZbrEnQjVwGNFPgXgNoDROBAzMe8xBBIlXf LxECfYwi3x47Wwhfz/KnZ+5sqHZDY4Hc72BcqXBdnw== X-Received: by 2002:a65:5cc5:: with SMTP id b5-v6mr7335697pgt.84.1526282920164; Mon, 14 May 2018 00:28:40 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a17:90a:d01:0:0:0:0 with HTTP; Mon, 14 May 2018 00:28:19 -0700 (PDT) In-Reply-To: References: From: Dmitry Vyukov Date: Mon, 14 May 2018 09:28:19 +0200 Message-ID: Subject: Re: for_each_cpu() is buggy for UP kernel? To: Linus Torvalds Cc: Dexuan Cui , Ingo Molnar , Alexey Dobriyan , Andrew Morton , Peter Zijlstra , Thomas Gleixner , Greg Kroah-Hartman , Rakib Mullick , Linux Kernel Mailing List , Kostya Serebryany 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 Sun, May 13, 2018 at 8:21 PM, Linus Torvalds wrote: > On Tue, May 8, 2018 at 11:24 PM Dexuan Cui wrote: > >> Should we fix the for_each_cpu() in include/linux/cpumask.h for UP? > > As Thomas points out, this has come up before. > > One of the issues is historical - we tried very hard to make the SMP code > not cause code generation problems for UP, and part of that was just that > all these loops were literally designed to entirely go away under UP. It > still *looks* syntactically like a loop, but an optimizing compiler will > see that there's nothing there, and "for_each_cpu(...) x" essentially just > turns into "x" on UP. An empty mask simply generally doesn't make sense, > since opn UP you also don't have any masking of CPU ops, so the mask is > ignored, and that helps the code generation immensely. > > If you have to load and test the mask, you immediately lose out badly in > code generation. > > So honestly, I'd really prefer to keep our current behavior. Perhaps with a > debug option that actually tests (on SMP - because that's what every > developer is actually _using_ these days) that the mask isn't empty. But > I'm not sure that would find this case, since presumably on SMP it might > never be empty. This looks like the problem automated testing traditionally and effectively solves. If UP is an important config, there must be automated pre/post commit checks for this.