Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1742867ybi; Wed, 17 Jul 2019 21:09:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqzrv/LzfTUJisE9Fhs055eIvhwchPnOldFaR2iUx6W9HBm8O5Sp8fx4z4VYonh7zXJBq5ZF X-Received: by 2002:a63:5f95:: with SMTP id t143mr44197648pgb.304.1563422960372; Wed, 17 Jul 2019 21:09:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563422960; cv=none; d=google.com; s=arc-20160816; b=HMaCmHwM6yKaVbxewvPenIQiWnA9I8KmErrjLr7mLxji92mZDOc2CSQ/fcHtpEWbi7 iuM87SX+BQAe8cinOx0Cv8oHmwNkPhsQCT/FTjKenLTRTfLDY5MlZ4lc5wWCj+ZoHFcg o3Pd9cBV1GiMONvV3nTRlZAJrsOkF0pZo9oevkoLcjhAQSdoV9XWwYJ8iQLTSYZBql9a 1R+47t0liC+fRa2/tMAhgcExu7q37F30yHn7n7h3M7TDpPQpNpgdii2RVGrwLoPLr0dt 9fqReYi9xFeZzKxllT7gB3/bByL004AhJeUifi2jX3SbAqNu5HogByWKxj7Yr4J6p3pY NDug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=knoKCX55PhQ0en+A33V0OQf+LqeP1gKbcJi8ENBx2k4=; b=Rt/LL+mN/4s9nvzjUKKb94qDpNc1vzD8NRXOSocXFYRAHnxxExLSBivBwJNsRTGJy+ yHnDWlZ/5eRDWBG4bD3QHbTu4IZmS+j9YhB8L7KAIUVqK4Euy3BBTamhp4rrEbLMsKKO +ebfHUk4yBKn1AR9uP0VNWTcVeg8+bP+cD8CD8CLNKQsKsNcumpj3pYso0btxJePrcjd ouRJN61vVDVf9sKoYq48LyoWYo9DAqFEiVe3TJ5Ib+zaPP9FD8Tt7U+l40L7vYQ/1qhf /0PpzMSFK39kA/kR143h3Lj6bYipJPdy8rcw6LrjYfPQP725tclW8EmFWOPBME69JQLl 3mgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=Sa2Z0P88; 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=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r185si1260015pgr.506.2019.07.17.21.09.03; Wed, 17 Jul 2019 21:09:20 -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=@163.com header.s=s110527 header.b=Sa2Z0P88; 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=NONE sp=NONE dis=NONE) header.from=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726604AbfGREGr (ORCPT + 99 others); Thu, 18 Jul 2019 00:06:47 -0400 Received: from m12-17.163.com ([220.181.12.17]:43218 "EHLO m12-17.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725976AbfGREGr (ORCPT ); Thu, 18 Jul 2019 00:06:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=knoKCX55PhQ0en+A33 V0OQf+LqeP1gKbcJi8ENBx2k4=; b=Sa2Z0P88qtO0ECsr8F6/0hxX2ZcqqiCvSn /vGKlpjKhJz7cfMtBEvCmOoLabWKdE9nKtF5mee/OkStkjECsFe0bFWmBw4cpGoz UNz1rtysG4sY37sbfxdGP8O9krRzp+mAlz8vccbOLRwZW/0yuAvjCoRD8LhM0PCU tYKeXk6oA= Received: from e69c04485.et15sqa.tbsite.net (unknown [106.11.237.24]) by smtp13 (Coremail) with SMTP id EcCowADXNREb8C9dJVEiEA--.864S2; Thu, 18 Jul 2019 12:05:51 +0800 (CST) From: luferry@163.com To: Thomas Gleixner Cc: "Peter Zijlstra (Intel)" , Rik van Riel , Greg Kroah-Hartman , Josh Poimboeuf , linux-kernel@vger.kernel.org, luferry Subject: [PATCH] smp: avoid generic_exec_single cause system lockup Date: Thu, 18 Jul 2019 12:04:38 +0800 Message-Id: <20190718040438.62433-1-luferry@163.com> X-Mailer: git-send-email 2.14.1.40.g8e62ba1 X-CM-TRANSID: EcCowADXNREb8C9dJVEiEA--.864S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Ar4DXr1UKr13JrWUWw15Jwb_yoW8uryxpF W8GrnrCw4jqa4Iy3srJw4fZ3yUJw4rJrWakFs5C393Aw42qF95XF9akF4FqayF9wn29FWY vrs5ZFW0yw1UAr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jjPfQUUUUU= X-Originating-IP: [106.11.237.24] X-CM-SenderInfo: poxiv2lu16il2tof0z/xtbBax-1Wletwg-4fAAAso Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: luferry The race can reproduced by sending wait enabled IPI in softirq/irq env src cpu only send ipi when dst cpu with queue empty, if interrupts disturbed between llist_add and send_ipi. Interrupt handler may raise softirq.In irq env, if src cpu try send_ipi to same dst cpu with wait enabled. Since dst cpu's queue is not empty, src cpu won't send ipi and dst cpu won't be waked up. src cpu will stall in csd_lock_wait(csd). Which may cause soft lockup or hard lockup depends on which time other cpus do send IPI to dst cpu. So just send IPI when wait enabled and in_interrupt() if (llist_add(&csd->llist, &per_cpu(call_single_queue, cpu))) // src cpu got interrupt here arch_send_call_function_single_ipi(cpu); CPU0 CPU1 kernel env:smp_call_function call_single_queue empty kernel env:llist_add call_single_queue got csd get interrupt raise softirq irq env:smp_call_function with wait irq env:llist_add irq env:queue not empty and skip send ipi irq env:waiting for csd execution Signed-off-by: luferry --- kernel/smp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel/smp.c b/kernel/smp.c index d155374632eb..de31a49b9fa7 100644 --- a/kernel/smp.c +++ b/kernel/smp.c @@ -142,9 +142,8 @@ static DEFINE_PER_CPU_SHARED_ALIGNED(call_single_data_t, csd_data); static int generic_exec_single(int cpu, call_single_data_t *csd, smp_call_func_t func, void *info) { + unsigned long flags; if (cpu == smp_processor_id()) { - unsigned long flags; - /* * We can unlock early even for the synchronous on-stack case, * since we're doing this from the same CPU.. @@ -176,8 +175,10 @@ static int generic_exec_single(int cpu, call_single_data_t *csd, * locking and barrier primitives. Generic code isn't really * equipped to do the right thing... */ + local_irq_save(flags); if (llist_add(&csd->llist, &per_cpu(call_single_queue, cpu))) arch_send_call_function_single_ipi(cpu); + local_irq_restore(flags); return 0; } -- 2.14.1.40.g8e62ba1