Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2499865rdb; Wed, 21 Feb 2024 09:22:49 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXdr1t3lBqNLTitgN5KL9j7lwknl1YKU1OkYnjpzWQhyub52gdzrMAr8+YyG0bjAPS7ULNS6VTETbRBc3zJ1cL/6PAZjSTS2xz7pezXhg== X-Google-Smtp-Source: AGHT+IHmEBlfsmJnTDNWPe5LjDTQ4cHmP+Iq8ZSbAAeLhYKe1EK8C5gm4Vp6ZE5Z5IjLvdZRced7 X-Received: by 2002:a17:906:fa8a:b0:a3e:4404:dc7 with SMTP id lt10-20020a170906fa8a00b00a3e44040dc7mr8805753ejb.23.1708536169341; Wed, 21 Feb 2024 09:22:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708536169; cv=pass; d=google.com; s=arc-20160816; b=I6fQeyPq1oDpHEWSKGlrN6W3PH3yAAhIs+idSIBbN2/kohotqVUSi2YWuWX0mswGzZ vWpu5CaQirm0Sru5MhQhUFjoPRXCiInBBrbXBkS2vmPEgNdMKpPXsQTNV8Ja4IxXkdkg 5/UveSpAQzvd4G9/aOu0gDdGFY3atAnFomly5VBYxcIm83MjooT9apF5p3Iy3quUIl9U vjOhnWH9PROxOq1fpS9MUwGv4kIUF7a6ghfxJSmMwuQsaTtBNvFH0nqV4+rqBqrDIhS8 oeXlUBl1jGvHoAp+218525nsXCUAT/bmvmpYmVrH5k2eSifzqQfeb7Lu56QdR7iM9iyt U3lg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=2a2eAQFLgd0HaWVHtA9PxlBRsxhp82AlgGsFBGArRcg=; fh=HnfsOTxl37B17MrABL8pqAX6uHYSqDh2XRcNOgN5Exw=; b=dA52/bfy1BbdyxGwV0hnBAAQDi0ne5FxNKOQsi8O5uzQqZ18elpcvNQY07MHk0ncUi 911oKQL7pzy9ugU578IWR0I7gv+DJ8xVaQWKahYHtuWEj7E1daJlEgNYNrrGFZ+i2lYk IzcW3lans+Eu32yR8B25ytqvzVmWTbF6R+2snDOr6OvpE/4Jqvr329Vhxe2CzeVAQo5U WShmvlh5FPRhRAy7j2hAy0S60oDfScLqQHUm5FlSnoVN8hLsP0N7S5TM+8Y/RS5oHDxb O8O/s+Gn7PErDnpbCSINUaGAsQhNJ1+ntTAHeLcq6Jnd6fQ1ZgPFzOtwO95NrSMguZWV 439w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uS6BeSvp; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-75191-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75191-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id n2-20020a170906840200b00a3e5952b3ffsi3496601ejx.75.2024.02.21.09.22.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 09:22:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75191-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uS6BeSvp; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-75191-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75191-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 1DC5D1F24054 for ; Wed, 21 Feb 2024 17:22:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C445683CB2; Wed, 21 Feb 2024 17:22:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uS6BeSvp" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E39397F7EA; Wed, 21 Feb 2024 17:22:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708536164; cv=none; b=NMwIovxXcnpJYY+WmxV1vm1KpOboXrzpvTR150GYf2WuOJUe9rFN3SqEUM5AK74UgL9ZXJTqQI5FAZ8RN9LqgchviWeAgmyHsKwmSaAUtALSxEbgXtx37BLnvTFH1yKlI+wrWdP0XJ4yXQjKuJzRk3lGOBUt6S2sEx5aY4/hSQs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708536164; c=relaxed/simple; bh=blg5JU8tDMyTEMnxPmEINNG8w4b5crwe8Ll8EbiY46w=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=JgQDKxVpaOzs8cEwb+TmHyt5zQJufgRRj36oqMPg8/bNNVgSAOsUs3lKfieZ05eMJCeUKr5DhiYoAaZjv2OZGdeBPUDYX71235s15R+C/HIS+eRmGoC1U+b/Aono9rBeDWruLvJdw97cnOr7QtyP66qqeU2N+0H9UfKiMaJPUZc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uS6BeSvp; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE996C433C7; Wed, 21 Feb 2024 17:22:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708536163; bh=blg5JU8tDMyTEMnxPmEINNG8w4b5crwe8Ll8EbiY46w=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=uS6BeSvp5tQGb7tUlatSA/6AdxlnEqgjZPLPhr6LKL2tCyHmyDbdKRfzPS5FAWS9h 5m1LOHkjES0ipSOeDSL5tcJz44ykKBaIkXK8HNmJI96vuZZ3SAnXIoqD45xVPGoOYt o8QzAj15C6JcXC/J6h42DDG/vCskLuUz3ocow7c4bExBhrXzOZumMNiTCvqsInTi5C PvHc0P00mfCSC2JJZ2ksFd/m4QmfmQy5BhzTAnSFHQoJBD1ZndQam64PHic0VPDW9S rI+bVOD5JBrV2noI1rPqGMASyOA+IQuUeceifL3AcwuLzdiwnImYBY46T27+Ob5deH k03G6v925g45Q== From: =?utf-8?B?QmrDtnJuIFTDtnBlbA==?= To: Anup Patel Cc: Palmer Dabbelt , Paul Walmsley , Thomas Gleixner , Rob Herring , Krzysztof Kozlowski , Frank Rowand , Conor Dooley , devicetree@vger.kernel.org, Saravana Kannan , Marc Zyngier , Anup Patel , linux-kernel@vger.kernel.org, Atish Patra , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Andrew Jones Subject: Re: [PATCH v13 06/13] irqchip: Add RISC-V incoming MSI controller early driver In-Reply-To: References: <20240220060718.823229-1-apatel@ventanamicro.com> <20240220060718.823229-7-apatel@ventanamicro.com> <87frxnfj3p.fsf@all.your.base.are.belong.to.us> <874je2yqn9.fsf@all.your.base.are.belong.to.us> Date: Wed, 21 Feb 2024 18:22:40 +0100 Message-ID: <87frxl3f6n.fsf@all.your.base.are.belong.to.us> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Anup Patel writes: > On Wed, Feb 21, 2024 at 5:29=E2=80=AFPM Bj=C3=B6rn T=C3=B6pel wrote: >> >> Anup Patel writes: >> >> >> > +void imsic_vector_mask(struct imsic_vector *vec) >> >> > +{ >> >> > + struct imsic_local_priv *lpriv; >> >> > + >> >> > + lpriv =3D per_cpu_ptr(imsic->lpriv, vec->cpu); >> >> > + if (WARN_ON(&lpriv->vectors[vec->local_id] !=3D vec)) >> >> > + return; >> >> > + >> >> > + /* >> >> > + * This function is called through Linux irq subsystem with >> >> > + * irqs disabled so no need to save/restore irq flags. >> >> > + */ >> >> > + >> >> > + raw_spin_lock(&lpriv->lock); >> >> > + >> >> > + vec->enable =3D false; >> >> > + bitmap_set(lpriv->dirty_bitmap, vec->local_id, 1); >> >> > + __imsic_remote_sync(lpriv, vec->cpu); >> >> > + >> >> > + raw_spin_unlock(&lpriv->lock); >> >> > +} >> >> >> >> Really nice that you're using a timer for the vector affinity change, >> >> and got rid of the special/weird IMSIC/sync IPI. Can you really use a >> >> timer for mask/unmask? That makes the mask/unmask operation >> >> asynchronous! >> >> >> >> That was what I was trying to get though with this comment: >> >> https://lore.kernel.org/linux-riscv/87sf24mo1g.fsf@all.your.base.are.= belong.to.us/ >> >> >> >> Also, using the smp_* IPI functions, you can pass arguments, so you >> >> don't need the dirty_bitmap tracking the changes. >> > >> > The mask/unmask operations are called with irqs disabled so if >> > CPU X does synchronous IPI to another CPU Y from mask/unmask >> > operation then while CPU X is waiting for IPI to complete it cannot >> > receive IPI from other CPUs which can lead to crashes and stalls. >> > >> > In general, we should not do any block/busy-wait work in >> > mask/unmask operation of an irqchip driver. >> >> Hmm, OK. Still, a bit odd that when the .irq_mask callback return, the >> masking is not actually completed. >> >> 1. CPU 0 tries to mask an interrupt tried to CPU 1. >> 2. The timer is queued on CPU 1. >> 3. The call irq_mask returns on CPU 0 >> 4. ...the irq is masked at some future point, determined by the callback >> at CPU 1 >> >> Is that the expected outcome? > > Yes, that's right. > >> >> There are .irq_mask implementation that does seem to go at length >> (blocking) to perform the mask, e.g.: gic_mask_irq() which calls >> gic_{re,}dist_wait_for_rwp that have sleep/retry loops. The GIC3 ITS >> code has similar things going on. > > The gic_{re,}dist_wait_for_rwp() polls on a HW register for completion > which will certainly complete in a predictable time whereas waiting > for IPI to be executed by another CPU is not predictable and fragile. > >> >> I'm not saying you're wrong, I'm just trying to wrap my head around the >> masking semantics. >> >> > The AIA IMSIC spec allows setting ID pending bit using MSI write >> > irrespective whether ID is enabled or not but the interrupt will be >> > taken only after ID is enabled. In other words, there will be no >> > loss of interrupt with delayed mask/unmask using async IPI or >> > lazy timer. >> >> No loss, but we might *get* an interrupt when we explicitly asked not to >> get any. Maybe that's ok? >> > > The delayed spurious interrupt after masking is avoided by additional > masking at the source of interrupt. For wired-to-MSI interrupts, we have > additional masking on the APLIC MSI-mode. For PCI MSI interrupts, we > have additional masking at PCI device level using pci_msi_mask_irq(). Thanks for the clarifications, Anup! Much appreciated!