Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1002091ybn; Wed, 25 Sep 2019 10:49:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqw4lpT/NNDiqLZH1WZ/lJZ+Q0R4Y9ZxRPYr7Upg2H8wvBO/T9Itak69xFhQmQ2acSFtaSN6 X-Received: by 2002:a17:906:a40d:: with SMTP id l13mr369470ejz.237.1569433747746; Wed, 25 Sep 2019 10:49:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569433747; cv=none; d=google.com; s=arc-20160816; b=APnqTfMq0zNQQgK6CS7BNM8pKXIXVNymuvoJjePl07zfCiq6CSKy9bIemq/RVZMlf1 x9DD6mPVViN4mrp16thNQncZBuDOhtj8BZejU686Xbjtt9OVO++zPHltRSrpj/mxamkd RsCqHaRu85EidTYZBOSU9/IJ8Y/XCbOeW4U9qZ34ADke9Vu2Ffwdh5sO2lbRBy5PSRpg bbgiH8cxFRwnUa0gJGeoksTKp/fDQyQFUYkgPJPF6Z27fqkJH4YgJ2QzZ3TdY00xKDxj RNCDZJrpWdZupmRtHsdC4u9u9nACRvyo6BCC1o/jBUg3sdS6U0WbcjjeL7dnwX9C9dmm MI2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=NFUARJVqfK6dLGiT4+OszvPyWdI3oAGZbvUJOollWS0=; b=d8R6DCGax4qeyyY4YJ4IxDkTw+ZLUEN30wiQpJAWKSs+4YKfmZp8+fxMPEyhjH5+H+ Tu0Qwl+qyLJihAxV3pd30lZ8lGebWDTGfT/stcitD/FUFhySbhB/Zf4qbWWx01+vWpz1 yicXdsb//k7I46ippIaRMarSYGGhoF4cc0UrVfw9ONDyIyYnFvkva4Vkb8t8kzvPVMoi L81YT1k58TTCYs0ks/Ud8QqdBY5kIQ4+CWATDsIUxgZ6zmZxZEhqn9pCfw2njKQfp4Ii /Y/ac+9tIhBBDP+bO3/dbg1okvW7ftGIUdXySzopq1ix7i1l8OsmHeNUWdTnYg73D+vK pejw== ARC-Authentication-Results: i=1; mx.google.com; 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 n6si3590870edq.228.2019.09.25.10.48.43; Wed, 25 Sep 2019 10:49:07 -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; 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 S1732099AbfIWPnR (ORCPT + 99 others); Mon, 23 Sep 2019 11:43:17 -0400 Received: from foss.arm.com ([217.140.110.172]:44222 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726922AbfIWPnR (ORCPT ); Mon, 23 Sep 2019 11:43:17 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B75F91000; Mon, 23 Sep 2019 08:43:16 -0700 (PDT) Received: from [10.10.156.175] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D60873F67D; Mon, 23 Sep 2019 08:43:15 -0700 (PDT) Subject: Re: [PATCH] sched: fix migration to invalid cpu in __set_cpus_allowed_ptr To: Valentin Schneider , shikemeng , mingo@redhat.com, peterz@infradead.org Cc: linux-kernel@vger.kernel.org References: <979d57f8-802b-57e5-632a-f94ad0f9d6a1@arm.com> <1568535662-14956-1-git-send-email-shikemeng@huawei.com> <5dfd4844-6c36-3b8d-203b-564d7ad7103d@arm.com> From: Dietmar Eggemann Message-ID: <40680310-60b3-589a-d0e8-b4dd723db10a@arm.com> Date: Mon, 23 Sep 2019 17:43:14 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <5dfd4844-6c36-3b8d-203b-564d7ad7103d@arm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/15/19 4:33 PM, Valentin Schneider wrote: > On 15/09/2019 09:21, shikemeng wrote: >>> It's more thoughtful to add check in cpumask_test_cpu.It can solve this problem and can prevent other potential bugs.I will test it and resend >>> a new patch. >>> >> >> Think again and again. As cpumask_check will fire a warning if cpu >= nr_cpu_ids, it seems that cpumask_check only expects cpu < nr_cpu_ids and it's >> caller's responsibility to very cpu is in valid range. Interfaces like cpumask_test_and_set_cpu, cpumask_test_and_clear_cpu and so on are not checking >> cpu < nr_cpu_ids either and may cause demage if cpu is out of range. >> > > cpumask operations clearly should never be fed CPU numbers > nr_cpu_ids, > but we can get some sneaky mishaps like the one you're fixing. The answer > might just be to have more folks turn on DEBUG_PER_CPU_MAPS in their test > runs (I don't for instance - will do from now on), since I get the feeling > people like to be able to disable these checks for producty kernels. > > In any case, don't feel like you have to fix this globally - your fix is > fine on its own. I'm not sure that CONFIG_DEBUG_PER_CPU_MAPS=y will help you here. __set_cpus_allowed_ptr(...) { ... dest_cpu = cpumask_any_and(...) ... } With: #define cpumask_any_and(mask1, mask2) cpumask_first_and((mask1), (mask2)) #define cpumask_first_and(src1p, src2p) cpumask_next_and(-1, (src1p), (src2p)) cpumask_next_and() is called with n = -1 and in this case does not invoke cpumask_check(). --- BTW, I can recreate the issue quite easily with: qemu-system-x86_64 ... -smp cores=64 ... -enable-kvm with the default kernel config.