Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1744456ybn; Thu, 26 Sep 2019 01:20:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqyVOQTzYLQNmmSwTQvLXtCTShIBwHXuTZ4vdMfO/5OXUoBy/Zwbll20yajjMaNPrKdJckTZ X-Received: by 2002:aa7:d4c5:: with SMTP id t5mr2227372edr.154.1569486029833; Thu, 26 Sep 2019 01:20:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569486029; cv=none; d=google.com; s=arc-20160816; b=cXM+t+f5Hy8kgaOEozU1eIXRPcK2+Qrn5DPsGIGEerUZ+irYKjBKR8jfaZYNBcoWFD i6JYuLNBwIGM7fI4nlxMd6AXSTQ0YgtLqA1Jyh1U7T1QA+X5HEBpNpI+pY/i9vetZOlo 9Ie4KkM49QCPmV5oGNxd9Miux1seYGRvGcC+FM6yLOXm1fuS+XeEJV8T1VPJLZD7Xye4 mAEZF335EuVA4KT8iMw+1lpfhGIzmBlrInTlAHjag6ODU/Yalz4OdrpGNtRdY8Z1/Ys0 ypwUW7cJw9OQORaPDYTo8erT9UCr2u6fdicF58V3eULCKx5Wnv/v57PsOy3l3yPZr8h0 afzQ== 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=stx/ARASz18g40HSrnpvfVOfPMV+atORgWhva2qdnTM=; b=hdCsjQaqqfA6oywAlSJf5rpQhF0c+Jhz2k6123OK/1iY1u1L6W8ufPVNqpEAhQSncM 6Pc+FHhqPH/kOGzAPEKQsovU2BCumq3sBHntkQ0CFBwsTPTCpfjrJOKBQar+xM5pG16K hhBucELA7VbE8k02SDXmc60LfNZyROybfqt9nD+4rE/ufn4NUGueZ9nrvqlb/vpN1srZ NpZgoLVZ+rKsX7OHG+Y9Q8WQuYHJpEAEEFj509z2+KYcDnj3UvR/4iU1QTLW9Q8mA6sL xqSdKEG0u4tFGWwGV9TRq2CpTRFIFvVwrZWq/hH7wvvYVEWdI3SMMI+F+aGurR617k8i cF1w== 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 g22si847613eda.27.2019.09.26.01.20.06; Thu, 26 Sep 2019 01:20:29 -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 S2409755AbfIXQMW (ORCPT + 99 others); Tue, 24 Sep 2019 12:12:22 -0400 Received: from foss.arm.com ([217.140.110.172]:33296 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388230AbfIXQMV (ORCPT ); Tue, 24 Sep 2019 12:12:21 -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 1EAE91570; Tue, 24 Sep 2019 09:12:21 -0700 (PDT) Received: from [10.1.194.37] (e113632-lin.cambridge.arm.com [10.1.194.37]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6C9623F694; Tue, 24 Sep 2019 09:12:20 -0700 (PDT) Subject: Re: [PATCH] sched: fix migration to invalid cpu in __set_cpus_allowed_ptr To: Dietmar Eggemann , 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> <40680310-60b3-589a-d0e8-b4dd723db10a@arm.com> <1d8e6aab-5258-494c-c4cd-1802eda34d59@arm.com> <706581c9-e4ee-967d-b010-4798afd2245e@arm.com> From: Valentin Schneider Message-ID: Date: Tue, 24 Sep 2019 17:12:19 +0100 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: <706581c9-e4ee-967d-b010-4798afd2245e@arm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 24/09/2019 15:09, Dietmar Eggemann wrote: > On 9/23/19 6:06 PM, Valentin Schneider wrote: >> On 23/09/2019 16:43, Dietmar Eggemann wrote: >>> 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(). >>> >> >> It won't warn here because it's still a valid return value, but it should >> warn in the cpumask_test_cpu() that follows (in is_cpu_allowed()) because >> it would be passed a value >= nr_cpu_ids. So at the very least this config >> does catch cpumask_any*() return values being blindly passed to >> cpumask_test_cpu(). > > OK, I see and agree. > > But IMHO, we still don't call cpumask_test_cpu(dest_cpu, ...), right. > > What the patch fixes is that it closes the window between two reads of > cpu_active_mask in which cpuhp can potentially punch a hole into the > cpu_active_mask. > > If p is not running or queued and it's state is unequal to TASK_WAKING, > a 'dest_cpu == nr_cpu_ids' goes unnoticed. In this case we don't need to force it off to another CPU, since that will get sorted out at its next wakeup. However, the patch still catches that , since it does an early if (dest_cpu >= nr_cpu_ids) { ret = -EINVAL; goto out; and that's regardless of the task's state. > Otherwise we see an 'unable > to handle kernel paging request' or 'unable to handle page fault for > address' bug in migration_cpu_stop() or move_queued_task(). > > Do I miss something? > > [...] >