Received: by 2002:a25:d783:0:0:0:0:0 with SMTP id o125csp122723ybg; Wed, 18 Mar 2020 18:46:17 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvbamqP//Oe5Qrdq0GuNHAoIKqopiAhUqTfXBzvDWkCFry6fUzwazqpBXM7tB/qYI4xc7ec X-Received: by 2002:a05:6830:1513:: with SMTP id k19mr431837otp.276.1584582376898; Wed, 18 Mar 2020 18:46:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584582376; cv=none; d=google.com; s=arc-20160816; b=CmTYnDIWh0imEYGrswDl9zBdDqAGEz2S837WEM/pz3PJG07sLjucbusoWk8aLPXfyA uFfwekcFvzB3elllRlyBFiBzpCNGTwyuD7vMFQY7DwiJe3UAashmp/jyWDtyTAY5rplC 4x5ubAQIvcm+EASrE0uYhgs9AFbRp5lcRgd/6/I7C5AMGC8hvyGSR+lgQ5WS8pIYLpbh kt8JC0aT0ol6AEvOxeAogZRiMo0ouN5hdcHPnutp1dlxN0D6P8NoDXohSLXqa1SOYEO+ ieYYS0O16DyFPIkem+8ud1fKdBto12pBysiFuUisVLT6iu/JFaLveE4rtiFcWhm0WPIv xl6g== 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 :message-id:to:from:cc:in-reply-to:subject:date:dkim-signature; bh=15Ag1guabbez6fmeIZ+SLDWHfu2CDemRcsM6ytC1rkg=; b=whQywLYhHXEdLH6h+CHub/TJ0sSMKMGtORxZ0fteqkQqS9/R14sSa3cCaoeTqC1HGR t+3J1ZVFZJ2MbnDbum+RMolFm63TAxHF+sLfgj9tysvtfUHtDtN+1fgT5vAlPsbwKNV2 2cOB5PXHTEcsVjEBQIbDube6qzd+yD1Ab0yKivDrqm8YHWfxGM8qCKNdsD/7mbD1LQWD sHkUZr5su03LxalwRp91OmNoaVjO6OxxP7736W82LI+PfHU9UM6j2TTXdn5q7d6JJYsa nmx/guyYvgcj61ax5JJuxgYt68K+mQzLFML7VeLlQE3rBEa2Im4NjoRmYTyrJvvQ2kA6 KBQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dabbelt-com.20150623.gappssmtp.com header.s=20150623 header.b=IZAut0DG; 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 e8si256800oif.218.2020.03.18.18.46.05; Wed, 18 Mar 2020 18:46:16 -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=@dabbelt-com.20150623.gappssmtp.com header.s=20150623 header.b=IZAut0DG; 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 S1726980AbgCSBpP (ORCPT + 99 others); Wed, 18 Mar 2020 21:45:15 -0400 Received: from mail-pj1-f67.google.com ([209.85.216.67]:40167 "EHLO mail-pj1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726663AbgCSBpO (ORCPT ); Wed, 18 Mar 2020 21:45:14 -0400 Received: by mail-pj1-f67.google.com with SMTP id bo3so249507pjb.5 for ; Wed, 18 Mar 2020 18:45:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dabbelt-com.20150623.gappssmtp.com; s=20150623; h=date:subject:in-reply-to:cc:from:to:message-id:mime-version :content-transfer-encoding; bh=15Ag1guabbez6fmeIZ+SLDWHfu2CDemRcsM6ytC1rkg=; b=IZAut0DG7zAsxQUQFAa7FaASbpC1hSxvgO2kLrxR65bUGBYZIGDfHZyg6SguRu7+Hc +NgxVZLHu+g0eHSWuzXh3uqTLfeeaCh9r0pKEL+lkknRUbX6h4TH+dWqScCEHthul4HL 4xQTL5qxE5UVCapvn5U+nqKUunQhUC2wJmud9ZkN3k5IH8+gktuUvtKryvkwLBzh1Urn jNqq5wEp6JHUzmrDsDIKEXoeOtgFkzDmG+TxBS7OBX539OpI/82U5nh94MQxyIrRw+C8 6saDRxVPA/QuByx8WGl1tdedfH8v9KeAdKyKZfF7X5VZigWiep0KY2K/d6lAr1qrFtRc bY9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:subject:in-reply-to:cc:from:to:message-id :mime-version:content-transfer-encoding; bh=15Ag1guabbez6fmeIZ+SLDWHfu2CDemRcsM6ytC1rkg=; b=LGsI4Cdb52Hu0l2ZxW71U2av1GwAGPvDLuBuJgqMKgsZ7RDIfvLRk7UHHjtqC4zuCi XIPGX8tyk5M0k5+TWwNEXNOVxXpLLSH3FK1KdnuuQlwX3cYkr0a0SGMfFK8Vaa2EKSjk WQW8KmKC5/5e8zCBTIwH1NhGFSyQDi+2dfhcorjSWFL8Agiy9ACSb+ofQl5i62i5KIXo VNqaEwTIkncJfIPVbTc8Jte1nC8oODa1Cveizv8GaP7ANsUgOTjRJUUzeXc+3Sra7CYZ y7UwuZNGv/+s+pH29uy49Cw49K2XmF2Cx3XROI8X6M+zdTeZ1FRD/ro1A4g8NG6rA4lp Go3A== X-Gm-Message-State: ANhLgQ0eZ7b81hO6T21ipXHc6/FV1NjX/nfigAdnOEZjsm6uD2MWw4l8 ULdHC/BMgfodtqYP/UmmC5UijSHFQbU= X-Received: by 2002:a17:902:34f:: with SMTP id 73mr1100441pld.50.1584582312362; Wed, 18 Mar 2020 18:45:12 -0700 (PDT) Received: from localhost (c-67-161-15-180.hsd1.ca.comcast.net. [67.161.15.180]) by smtp.gmail.com with ESMTPSA id d3sm262618pfq.126.2020.03.18.18.45.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2020 18:45:11 -0700 (PDT) Date: Wed, 18 Mar 2020 18:45:11 -0700 (PDT) X-Google-Original-Date: Wed, 18 Mar 2020 18:45:05 PDT (-0700) Subject: Re: [PATCH 2/2] riscv: fix the IPI missing issue in nommu mode In-Reply-To: <20200303093418.9180-2-greentime.hu@sifive.com> CC: green.hu@gmail.com, greentime@kernel.org, Paul Walmsley , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, greentime.hu@sifive.com From: Palmer Dabbelt To: greentime.hu@sifive.com Message-ID: Mime-Version: 1.0 (MHng) Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 03 Mar 2020 01:34:18 PST (-0800), greentime.hu@sifive.com wrote: > 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) Thanks. We should really stop putting hart IDs in cpumasks, as that's just nonsense. Reviewed-by: Palmer Dabbelt I'm taking these both onto fixes.