Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp879074pxk; Thu, 17 Sep 2020 20:08:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNPVtB+8QiV4FQ8FsxEDk/T6uoRos6DOYc3DMMZNsecPI0yAwrFYiHNIPDHR9AIDNrVzgF X-Received: by 2002:a05:6402:202a:: with SMTP id ay10mr26851483edb.36.1600398523326; Thu, 17 Sep 2020 20:08:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600398523; cv=none; d=google.com; s=arc-20160816; b=U3s/aspUnlRqxlKHq2OE35pSvl5MpEJbfPIljmgC+9L70RGcEwjL2XSAqgfG8tkZu+ SwIjPJjbXv99hnSw7dO7RKXjncAZ8p9DchycoitwkKlZ3T+ngc87Zo6SjxCPTcm0/Hb6 v8blm8pIRcBV0Th8e2S2dEc7Rvpc0yM0AAue/8KtnVD2zO5h8f9JPLvG5r3PZu8U10Qr T9DJBnfbpM2e1TKZ+WmJ5j4g9//uJ4SmMf8dFPMmPPjH/dpaXSkGm2WZOc+L4x6tgrEt mxp//N/Q+sW8zPVCe3TGiJg9FpAOKPraYX2zzMoGOdRzGiz2oc86SdVaMp6165NvDfRk j6IA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lUXSMPfeZI4+psTAUrAk9GMVccWUH7uLo3GzSC63Sl8=; b=DUX4KsO4d4o8xJw1Cnf68y2WtyyTj5tI5dtwj2R0bir2kpu/nqvpXsinO4UsnCQV5J VNcFi/iH1milLmy4VDxdw5SQJe5M80rIGIUzP247YbEu0R354gVGKZUwUPQ8AQPB3qL0 6bmETWJxYu2iivwbyO4DSX7ycKCDZmTGYC2wZhYhhWaaExIbL8QPGlukgQ0/aoUCtQuG AX0id5r+4nHimHchqo39fSHcFLeVxcV9JXOQmquNCf8xux6RsltlZkjsZr2OghT/gMKA 1czv2ypO8nug9DYdFTnQ5K7NMwXhdaYLeCEbJpRUMam1UA5FiENMY4M1HEfn48u2HEwm 5z5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=l4I4PRBI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t5si1256178edi.523.2020.09.17.20.08.20; Thu, 17 Sep 2020 20:08:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=l4I4PRBI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730382AbgIRDGK (ORCPT + 99 others); Thu, 17 Sep 2020 23:06:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:51218 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727245AbgIRCEJ (ORCPT ); Thu, 17 Sep 2020 22:04:09 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A2006235F8; Fri, 18 Sep 2020 02:04:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394649; bh=1421uzvkwaBdxLSU4zsKRga+Ar+Yd6i16Q6f6C1NZE0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l4I4PRBIaFCTudYenmXvP4cQ+aCmE0UBzq590Qtfy7Jmfm3Vii9wblfmG/F8t/bEX GASuOrbAiXuQWOey7BG+aB0JPrlYGa45Gfx/heyc/kf1wu7BNYijObjpdm76T0b8Kc dEUoB+5mhyQhiiG8Rl+EkaPC2ZKj21dnPTv2rL5k= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: James Morse , Catalin Marinas , Sasha Levin Subject: [PATCH AUTOSEL 5.4 146/330] firmware: arm_sdei: Use cpus_read_lock() to avoid races with cpuhp Date: Thu, 17 Sep 2020 21:58:06 -0400 Message-Id: <20200918020110.2063155-146-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: James Morse [ Upstream commit 54f529a6806c9710947a4f2cdc15d6ea54121ccd ] SDEI has private events that need registering and enabling on each CPU. CPUs can come and go while we are trying to do this. SDEI tries to avoid these problems by setting the reregister flag before the register call, so any CPUs that come online register the event too. Sticking plaster like this doesn't work, as if the register call fails, a CPU that subsequently comes online will register the event before reregister is cleared. Take cpus_read_lock() around the register and enable calls. We don't want surprise CPUs to do the wrong thing if they race with these calls failing. Signed-off-by: James Morse Signed-off-by: Catalin Marinas Signed-off-by: Sasha Levin --- drivers/firmware/arm_sdei.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/drivers/firmware/arm_sdei.c b/drivers/firmware/arm_sdei.c index eb2df89d4924f..e497785cd99fe 100644 --- a/drivers/firmware/arm_sdei.c +++ b/drivers/firmware/arm_sdei.c @@ -412,14 +412,19 @@ int sdei_event_enable(u32 event_num) return -ENOENT; } - spin_lock(&sdei_list_lock); - event->reenable = true; - spin_unlock(&sdei_list_lock); + cpus_read_lock(); if (event->type == SDEI_EVENT_TYPE_SHARED) err = sdei_api_event_enable(event->event_num); else err = sdei_do_cross_call(_local_event_enable, event); + + if (!err) { + spin_lock(&sdei_list_lock); + event->reenable = true; + spin_unlock(&sdei_list_lock); + } + cpus_read_unlock(); mutex_unlock(&sdei_events_lock); return err; @@ -621,21 +626,18 @@ int sdei_event_register(u32 event_num, sdei_event_callback *cb, void *arg) break; } - spin_lock(&sdei_list_lock); - event->reregister = true; - spin_unlock(&sdei_list_lock); - + cpus_read_lock(); err = _sdei_event_register(event); if (err) { - spin_lock(&sdei_list_lock); - event->reregister = false; - event->reenable = false; - spin_unlock(&sdei_list_lock); - sdei_event_destroy(event); pr_warn("Failed to register event %u: %d\n", event_num, err); + } else { + spin_lock(&sdei_list_lock); + event->reregister = true; + spin_unlock(&sdei_list_lock); } + cpus_read_unlock(); } while (0); mutex_unlock(&sdei_events_lock); -- 2.25.1