Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2325077rdb; Wed, 21 Feb 2024 04:24:24 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCX8dIjExkoUlbbMibCH8qjL9cEFGLEwJlXS+mpxWpenfx45ZPcu7IpoU4mMF+8VAUUA4a5SVGxPwDh4vpZ93qKshnOlQe7oWp2vLC2Tjg== X-Google-Smtp-Source: AGHT+IFs1nHk6pIAD1u5CAaV+CuoqpVXS9vY5pMZJ1CmQdItfk9RDKtxY0UrtI6QAiBGY5OfVWiw X-Received: by 2002:a17:902:ce82:b0:1db:f8ef:a9e2 with SMTP id f2-20020a170902ce8200b001dbf8efa9e2mr9601715plg.47.1708518264071; Wed, 21 Feb 2024 04:24:24 -0800 (PST) Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id t3-20020a170902e84300b001dba722cf4csi8217672plg.40.2024.02.21.04.24.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 04:24:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74693-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@ventanamicro.com header.s=google header.b=E1CTr8AD; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-74693-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74693-linux.lists.archive=gmail.com@vger.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id BAC6F2843B3 for ; Wed, 21 Feb 2024 12:24:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 08C5B51004; Wed, 21 Feb 2024 12:24:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="E1CTr8AD" Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4451C4F8A2 for ; Wed, 21 Feb 2024 12:24:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708518257; cv=none; b=IDXrP5SYzW2hye3DGDqx9CwJm42hJcNqkqlZJ7t91/5PQUfj1iKWFHJv/FEGuD62X+DudMqb/LDHMDF7faUV9Prmo7WdODF67kuIZuewQ09jhTKWyeEkieEMI6m/lKZoRFgYUTrEYPLFe+uQ8/rHixXmWI5CU/yX5c1lYYIfugM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708518257; c=relaxed/simple; bh=Ywa3qbXnsG5Boc8jS5oivS1/lcbF/6GrnhNyJpzDnz8=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=A7AfxYFeS4fkWi2LnS0Z2prggGYtNeyMVMC8lQCDjOQlwfh4eQgtFgZoJyC7wH6Gz0+KPuUHe9FaWCKg3QiM8/4Uf/E9wzw38S+71nSgoktqdYxYQS9wts9F7imazzWECBgMCp2gvr/by8KD8XJjI97mAsBfK9GQ/y9piVrY6Lo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=E1CTr8AD; arc=none smtp.client-ip=209.85.208.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Received: by mail-lj1-f179.google.com with SMTP id 38308e7fff4ca-2d109e82bd0so86766461fa.3 for ; Wed, 21 Feb 2024 04:24:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1708518253; x=1709123053; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=rUIme5qeYaRlhQNYTF01QINk6od2pxuGi3LOwUcjfkA=; b=E1CTr8AD/236uyUycex4/GpqF66CVyG+rtdOvyahvwzKVlRtqkfjVuKpCYeN6luLbH 8M6SX+dbij+MmUw7S+7QuhMC9B0A24r640d1atreHBJO+d1hRLyNDhCOvh4jDzW7wI44 LB5Ny8swd8Sv3MlchyYStSWnHyfFh4If0LbMxY6drHydO0oKelmhYp2eibdzfsqIqSsy II0CvhFUmoE12/9/iZcU7c+5IomjQlcfFewfCvekC4DAgAq9lMqpFIxYEy4g2eIRw2RK ycN49KDoqDSqL8HRdf/kLRxLsAJvWrG4iIbiFubNbN3+ONhmPjD8LaxfsxoxwjSK1juU G99Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708518253; x=1709123053; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rUIme5qeYaRlhQNYTF01QINk6od2pxuGi3LOwUcjfkA=; b=NyUWIdqUZvZSzAczDXWnFsuDdOyguGEzcAN7TNz5s9Axj+exqXAVGx+lS6z+ivcPXg BiuADXBTxHf8jTENOAIuN/e8JrmXXTbWD9agcp0FW7B8J9kZDna4x25RXX7uaEACq09G qSogDHKZ959alEqB9umJzSvQg7wqoiYEKVX+SErYI7ELCsAIQSRAE3LxaEHGSMRIehn5 m73eK7dSY1akBtBTZB26Ni7rIrWuzzbcA6XFKRKCvZp/MuVWK9bo6MKxYEvkVJfyUetH NamCDTcg9i5fKLMLL6vdsFeyleQJksvBF8em+eXyIdWRZoRz4YoNlSxEVV5nsQNHt9PU j9gg== X-Forwarded-Encrypted: i=1; AJvYcCUXqBb36e+GQOLGVNgFpK2PgoFEk++UqSyuzDOmCman7xkLwTYfTbEbQD5zVrRE7oLUw+yksuQ4IqXwC0puEriKA+GQIeKA9IV63czn X-Gm-Message-State: AOJu0YzRoAa4oRadJbO2h9A8t/1psTD+zX36yI1xnRYosCsIz6VjxmUa Qb1nUkazWtprBFe9HQ2cXlyduYOcNHrHUP6kHTS75RKcTpwQz3sG9UqKatdlrbDsTc1Bn1y8wdm O35hjorNM/p2Fy4PBCPuTouT/glqF91uQlLsGOw== X-Received: by 2002:a2e:9c84:0:b0:2d2:3ac4:d6e0 with SMTP id x4-20020a2e9c84000000b002d23ac4d6e0mr5799393lji.31.1708518253341; Wed, 21 Feb 2024 04:24:13 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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> In-Reply-To: <874je2yqn9.fsf@all.your.base.are.belong.to.us> From: Anup Patel Date: Wed, 21 Feb 2024 17:53:59 +0530 Message-ID: Subject: Re: [PATCH v13 06/13] irqchip: Add RISC-V incoming MSI controller early driver To: =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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.b= elong.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(). Regards, Anup