Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp3379868ybp; Sun, 6 Oct 2019 10:39:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqy8aPs9EsReuQcmvZcMjkUSnk2lKfWzPFbPGMO7FwwhFwGxCeTGZ5e3YiW2a/JizFoPHS03 X-Received: by 2002:a17:906:fc20:: with SMTP id ov32mr20478646ejb.22.1570383546503; Sun, 06 Oct 2019 10:39:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570383546; cv=none; d=google.com; s=arc-20160816; b=ES7DlzP3Xhtv6XwJv7Im8+HrtOwMjqUyUPdHMTZzlhRryBaQoWYQl12Z0w/gA5FAgt uPX6i8jysnp2/HoYN/nMDYV+Vtt7figuHNPKURnTdLJzHhPDRkvrifRVB3pRuDTuP6so pWI0r/p6bo5WEeCIcL+dMjqqFrDB55yiIvWxqUL7eDClG2kGhoZ4hOkCRhx2FR76hTM5 hFJHcHl5eyVZ3P5ng3HamBSgyPQmRvKk6lYK2j14xMKf/hXHSwyakVY0j8b6Su6tUqxV yI9gT/TcQBeXgMPzHlXRFBAB7AmDApctq7EaIaGpJPKFq/0VQsd1QxCAm589Fimbn+28 Fe+w== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=eEhlzp93ygvZIYJsUyaVOZ4O0FK5R/TCnYmgkXtiqfw=; b=U6OxihJcZeqP+MQS1AFOQjw9Iq9itX4xPfo9ivj/8+IW7Jc5Rwl1V3TE00RmZl+mhR nmYYBcA4zo9nfuIxtXYZtpXhsj2irnRFonXkk2dPg7QsljRLmwgrKIf11Rj+S5sHkUWu 4+5ztyZWi3TROWq6SoWRvQK7K9a+ZFKoHPhIVUjnyN+UCBfJJyxWbmTU+/2mm/4S8ba2 CvVMVuzFE8A6z1LHV6QyeI2lHTLVVyYNri8Q/rkpGsNTR8oMQxdBMlnhEPa3BTELInpe LLtfHxslPcH+ELUYsZbTKCh2BoKH1Q+BiL4Ah22JzrmPEWXiSQSNbaY556Hd1eGrWdLx Hzbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=U6FKPxUH; 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 a14si8150703eda.111.2019.10.06.10.38.42; Sun, 06 Oct 2019 10:39:06 -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=@kernel.org header.s=default header.b=U6FKPxUH; 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 S1728995AbfJFRfK (ORCPT + 99 others); Sun, 6 Oct 2019 13:35:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:33662 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730126AbfJFRfD (ORCPT ); Sun, 6 Oct 2019 13:35:03 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8B0DE2080F; Sun, 6 Oct 2019 17:35:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570383303; bh=+MlfoAtoWLCe3LiiFPezhp7+K5aRv9eFB+47gTDeinA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U6FKPxUHmF++TT1VaJfLvviLhzq2lxPkn+bCoSzRbxeVCW6sF5mpO/DXfDFtAI7Cr /+fFpxhc/eNewBmWLIft2onwKswMSR1y+u688QgGDuIxdsy88rnr/VEajWSCvhWuZO FcC5r/1owpZHnLt6wlw64qy5vH7JCIahGxhozKuY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nathan Lynch , "Gautham R. Shenoy" , Michael Ellerman , Sasha Levin Subject: [PATCH 5.2 055/137] powerpc/rtas: use device model APIs and serialization during LPM Date: Sun, 6 Oct 2019 19:20:39 +0200 Message-Id: <20191006171213.287244692@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191006171209.403038733@linuxfoundation.org> References: <20191006171209.403038733@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nathan Lynch [ Upstream commit a6717c01ddc259f6f73364779df058e2c67309f8 ] The LPAR migration implementation and userspace-initiated cpu hotplug can interleave their executions like so: 1. Set cpu 7 offline via sysfs. 2. Begin a partition migration, whose implementation requires the OS to ensure all present cpus are online; cpu 7 is onlined: rtas_ibm_suspend_me -> rtas_online_cpus_mask -> cpu_up This sets cpu 7 online in all respects except for the cpu's corresponding struct device; dev->offline remains true. 3. Set cpu 7 online via sysfs. _cpu_up() determines that cpu 7 is already online and returns success. The driver core (device_online) sets dev->offline = false. 4. The migration completes and restores cpu 7 to offline state: rtas_ibm_suspend_me -> rtas_offline_cpus_mask -> cpu_down This leaves cpu7 in a state where the driver core considers the cpu device online, but in all other respects it is offline and unused. Attempts to online the cpu via sysfs appear to succeed but the driver core actually does not pass the request to the lower-level cpuhp support code. This makes the cpu unusable until the cpu device is manually set offline and then online again via sysfs. Instead of directly calling cpu_up/cpu_down, the migration code should use the higher-level device core APIs to maintain consistent state and serialize operations. Fixes: 120496ac2d2d ("powerpc: Bring all threads online prior to migration/hibernation") Signed-off-by: Nathan Lynch Reviewed-by: Gautham R. Shenoy Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20190802192926.19277-2-nathanl@linux.ibm.com Signed-off-by: Sasha Levin --- arch/powerpc/kernel/rtas.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/kernel/rtas.c b/arch/powerpc/kernel/rtas.c index fff2eb22427d0..65cd96c3b1d60 100644 --- a/arch/powerpc/kernel/rtas.c +++ b/arch/powerpc/kernel/rtas.c @@ -871,15 +871,17 @@ static int rtas_cpu_state_change_mask(enum rtas_cpu_state state, return 0; for_each_cpu(cpu, cpus) { + struct device *dev = get_cpu_device(cpu); + switch (state) { case DOWN: - cpuret = cpu_down(cpu); + cpuret = device_offline(dev); break; case UP: - cpuret = cpu_up(cpu); + cpuret = device_online(dev); break; } - if (cpuret) { + if (cpuret < 0) { pr_debug("%s: cpu_%s for cpu#%d returned %d.\n", __func__, ((state == UP) ? "up" : "down"), @@ -968,6 +970,8 @@ int rtas_ibm_suspend_me(u64 handle) data.token = rtas_token("ibm,suspend-me"); data.complete = &done; + lock_device_hotplug(); + /* All present CPUs must be online */ cpumask_andnot(offline_mask, cpu_present_mask, cpu_online_mask); cpuret = rtas_online_cpus_mask(offline_mask); @@ -1007,6 +1011,7 @@ out_hotplug_enable: __func__); out: + unlock_device_hotplug(); free_cpumask_var(offline_mask); return atomic_read(&data.error); } -- 2.20.1