Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp3212896ybf; Tue, 3 Mar 2020 01:35:11 -0800 (PST) X-Google-Smtp-Source: ADFU+vtu+zz8wADEGUkN2yP1NwOBBI3Zrb8lLiiAyzyckK3vGPW05KDKBYC+kYcZs4hfLGoqd49V X-Received: by 2002:a9d:68d9:: with SMTP id i25mr2716481oto.135.1583228111683; Tue, 03 Mar 2020 01:35:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583228111; cv=none; d=google.com; s=arc-20160816; b=N6Juy4W2gYW0+m0EbCKw8ZkVhR9cDu9bYjR4K3fZJ7KHZQHQBwlKhjTjna1ThgXHCc USSutI2/+wKetk6tjuCwHjLZIlHmyDKwIUVr77PzwLYBL48MXw9j3N8fIvXmHHDa6Hxg xFPdrdQkO+c+Mj7sTHwi7c4+KJfl/8COkW3zTXFHYURa83W9CXWsfwcn6k1eyjjUGyOG GxvepBLBsRU3JjrK0FlNIN5YK94k/xD++LUymIljwY1mq0+PujVqLBkqjY0baLP/5HI5 4xa0XfMhZ+pVzezGjWKT7pgKas+4AmGDrHVjFKjeuURiPhQRQrqnxJa41GR8zAgtpTUF 2Rmg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ZvzoObnBVzlXL6MM7KZpnEWysdUu+lTn+skS3IgavUM=; b=VlC/M3YmSfEw/FnbCOfYKrGQ6dsUzGceaPq2xuTX/P6uTeIVQ1am1Q48k3lVw3+zCb 6xptt9DZqxomPe2wp7NfD7IU3hyCn0LWZD8jZIOenaSm/ioryS9CXMIwYmtboqBWeJDV r8BydRblGSygJ14gqZRfWSwYUrCwzgakrxKzZvXte9WJ4caitF1zhRhXpot7K2Xs85zd gMfqlG9y5CwrH4XEB44kTjPEt4m4aOCVgFLd910s7i1950gG/8XwC6Vfn8dPMZ9F6fIi ZLKWTKT2wxKhX1aF3s/hVisRjPOXmlLY9zty/rQRNrxGTdM4Ukoc1+MG30y7u6gxpYBK 2z0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=fpjHsJmn; 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 h14si2490744otn.229.2020.03.03.01.34.59; Tue, 03 Mar 2020 01:35:11 -0800 (PST) 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=@sifive.com header.s=google header.b=fpjHsJmn; 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 S1728273AbgCCJef (ORCPT + 99 others); Tue, 3 Mar 2020 04:34:35 -0500 Received: from mail-pj1-f68.google.com ([209.85.216.68]:33470 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725818AbgCCJee (ORCPT ); Tue, 3 Mar 2020 04:34:34 -0500 Received: by mail-pj1-f68.google.com with SMTP id m7so1024356pjs.0 for ; Tue, 03 Mar 2020 01:34:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZvzoObnBVzlXL6MM7KZpnEWysdUu+lTn+skS3IgavUM=; b=fpjHsJmnfVmUfPGfvrMJIa6ugplGKPICLu4RJXOHo7RaSJTcXOU6xdvU/x1V9fDRST BJLsJpki/oC/f9dRHAMFZA1xF6eP0xXFokNg4O757ciUtd0hYZ8+7NIy+yJ+FLifOqUU eCCJlsMz12M376owQxkzYeJqfKI8RhXnu0HqmwLoxZD2g/GTBqK5W9/+mOFZC+rwuAVm mGhtNDIOu4GbdAzVB0pFGppcf8X2uPNu3otLH7wcodCYJAdZdc19t/aS4szxPfzW34Gr CVi0ft0UB/9+hTiN+o1VrOOTPt0MjJQ2FiZ1/k7xRMDkZv/6V0iZG9a6ScYlSKmm3idf UjnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZvzoObnBVzlXL6MM7KZpnEWysdUu+lTn+skS3IgavUM=; b=U6Wnis1AMMmNPSkdfb/PtCHRm0HPo9pLU/B7l2TyeQSFocMxyf8k+EApdwssky3MgB NlEtkyCWcqxGzAGCDJ8ROZ8d3NEJMWKHfhvLz7h4EMjkbI1VrtYV0goALCcRk5PgP7Wj nReW398t2uwd2Sy9VmjKNHrJNWIIHiaP7jirrIWDSGxovzRX67CFfHlDqJFyP97nsydR Ror7KFndWrBu8Fe0B4UPW49EsgzB4z5Mante4Ul2vFdom40aJYOPdxinv++t7Q+8SYa7 iK3b7DZIdZceKUqMgzdK2Vb9rN7XzFf8gCRribmlUJpFO/p3ZsuNGb/WDUwG2rCOIOHe J7xA== X-Gm-Message-State: ANhLgQ3ELbvEqVxTbnhL8jNhHKEkAuBmBNa1lf36hH9jM4SrqkPtuQw4 X32v2pwxlwKQueDwsxLEyJzdhw== X-Received: by 2002:a17:902:8f91:: with SMTP id z17mr3422269plo.234.1583228073577; Tue, 03 Mar 2020 01:34:33 -0800 (PST) Received: from hsinchu02.internal.sifive.com (220-132-236-182.HINET-IP.hinet.net. [220.132.236.182]) by smtp.gmail.com with ESMTPSA id s5sm1494745pfh.47.2020.03.03.01.34.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 01:34:33 -0800 (PST) From: Greentime Hu To: green.hu@gmail.com, greentime@kernel.org, paul.walmsley@sifive.com, palmer@dabbelt.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Greentime Hu Subject: [PATCH 2/2] riscv: fix the IPI missing issue in nommu mode Date: Tue, 3 Mar 2020 17:34:18 +0800 Message-Id: <20200303093418.9180-2-greentime.hu@sifive.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200303093418.9180-1-greentime.hu@sifive.com> References: <20200303093418.9180-1-greentime.hu@sifive.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch fixes the IPI(inner processor interrupt) missing issue. It failed because it used hartid_mask to iterate for_each_cpu(), however the cpu_mask and hartid_mask may not be always the same. It will never send the IPI to hartid 4 because it will be skipped in for_each_cpu loop in my case. We can reproduce this case in Qemu sifive_u machine by this command. qemu-system-riscv64 -nographic -smp 5 -m 1G -M sifive_u -kernel \ arch/riscv/boot/loader It will hang in csd_lock_wait(csd) because the csd_unlock(csd) is not called. It is not called because hartid 4 doesn't receive the IPI to release this lock. The caller hart doesn't send the IPI to hartid 4 is because of hartid 4 is skipped in for_each_cpu(). It will be skipped is because "(cpu) < nr_cpu_ids" is not true. The hartid is 4 and nr_cpu_ids is 4. Therefore it should use cpumask in for_each_cpu() instead of hartid_mask. /* Send a message to all CPUs in the map */ arch_send_call_function_ipi_mask(cfd->cpumask_ipi); if (wait) { for_each_cpu(cpu, cfd->cpumask) { call_single_data_t *csd; csd = per_cpu_ptr(cfd->csd, cpu); csd_lock_wait(csd); } } for ((cpu) = -1; \ (cpu) = cpumask_next((cpu), (mask)), \ (cpu) < nr_cpu_ids;) It could boot to login console after this patch applied. Fixes: b2d36b5668f6 ("riscv: provide native clint access for M-mode") Signed-off-by: Greentime Hu --- arch/riscv/include/asm/clint.h | 8 ++++---- arch/riscv/kernel/smp.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/riscv/include/asm/clint.h b/arch/riscv/include/asm/clint.h index 6eaa2eedd694..a279b17a6aad 100644 --- a/arch/riscv/include/asm/clint.h +++ b/arch/riscv/include/asm/clint.h @@ -15,12 +15,12 @@ static inline void clint_send_ipi_single(unsigned long hartid) writel(1, clint_ipi_base + hartid); } -static inline void clint_send_ipi_mask(const struct cpumask *hartid_mask) +static inline void clint_send_ipi_mask(const struct cpumask *mask) { - int hartid; + int cpu; - for_each_cpu(hartid, hartid_mask) - clint_send_ipi_single(hartid); + for_each_cpu(cpu, mask) + clint_send_ipi_single(cpuid_to_hartid_map(cpu)); } static inline void clint_clear_ipi(unsigned long hartid) diff --git a/arch/riscv/kernel/smp.c b/arch/riscv/kernel/smp.c index eb878abcaaf8..e0a6293093f1 100644 --- a/arch/riscv/kernel/smp.c +++ b/arch/riscv/kernel/smp.c @@ -96,7 +96,7 @@ static void send_ipi_mask(const struct cpumask *mask, enum ipi_message_type op) if (IS_ENABLED(CONFIG_RISCV_SBI)) sbi_send_ipi(cpumask_bits(&hartid_mask)); else - clint_send_ipi_mask(&hartid_mask); + clint_send_ipi_mask(mask); } static void send_ipi_single(int cpu, enum ipi_message_type op) -- 2.25.1