From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (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 412381EEA58 for ; Wed, 15 Jan 2025 09:44:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736934271; cv=none; b=QqKZqj0bob5YgD+YrB46k2RLPUS6qDgpP3rCV7+VaC0EehDW+AYKxANqURWO1/WMDzpsytQd/zjfy0AaHj3stPS7O4HpbhX3YluY2Hdakjgy7GKmMRuQlJvuSyY92rEqegVxkq3cHnyS6XUzEYyD2kR+IsqfC083aZrrnlYcTLs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736934271; c=relaxed/simple; bh=X4kPC7rGiV3ShVkLtdrJn0SMAMo5x5X5I/8TnJDxYcI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BFsnWbkH7i5MwquglTt9yQsFCnN4K5LQfJ8+7dXw0Ea45bhNJeQDX7GLbduvPan89ZW42UHHsdOEedmp4cq+oQqyWCIrx+Bo8oLbWirXFfD1OwG9yszzO61os1AcZd/0qTTpDO5vsL7DOpJcOhEPYegf4Vfc1BnYNTON1V53a18= 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=LotVHGeT; arc=none smtp.client-ip=209.85.128.51 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="LotVHGeT" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-43634b570c1so46228165e9.0 for ; Wed, 15 Jan 2025 01:44:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1736934267; x=1737539067; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=esAtTk/lpEE2twEw0jUtCey8Py/XgPIAB3dxsOhtpJc=; b=LotVHGeTvWfXP8jIp0CLQpEroopZw8T567PH/cN3hsOM7NEerFajBFRDgQ4fNNHD6m oMnN4DlpCQs/mcY0Mh6cJXBthiSHvDpUipQZZsNVVh0HoUMeWdOFw013wJTDKy4dI394 imZKgxLKJtijf+kvKxGCWyjYb8zM/Kk9VqsqRHGqKyGf2B683SVoKvxQx0wcOwKY+c0F g+AaPWvOeXD1W/j3JQ+3A+JK7Td25jwi3IV+fhNfD4sY2kBTQK4041QKLJes1ouT/RlQ z/OEFBMJiEjIEsm5IbG7hi84rJlAJg6eOoItCSEaMCqqqjYHbucNiMQgti8jtETxQMOP K+Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736934267; x=1737539067; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=esAtTk/lpEE2twEw0jUtCey8Py/XgPIAB3dxsOhtpJc=; b=amWUpVChqsNNkd0gVKdfCUeCsSLwVDe3VrgXWsMygkj/QsjnkGr5RDHVSUGeLNqfTh xlgdzrieuoFTNBuVHNdQ+jYhkh9dToKgmHJzwcGuI6z56/pEmDKQMqpDn1oIVQTMrbKe F28jCT7kVxFXUbBFjBS71Qw3tarFqoDBRyytGupc7C/Zk50ku6e6Mr4vH8CZDlG3A6jx dEpf+Hw9fcNvRZFtEP88O8uj5n6qC0jNYHo34Qmh51cOBP/mCFKEeyymXhw3o5ASAKcu sxfB6YV8C65nLzxyw+bXbszkaQUccq80QpEaTL+YtyOCPwpXVGRICEEkwEKz9i04py/E UDzg== X-Forwarded-Encrypted: i=1; AJvYcCWo4fBC2UjZwEkPf9lra9e6Nh07GHw+1PIOIlqUYpiQnuLBPTRmaGsjAFAmxH4FSbVjVaMsoP8xoshJa/g=@vger.kernel.org X-Gm-Message-State: AOJu0YxVEWIBcd98Cuo3DqVZgMiMI6r2+0BOkqy4RBMMFwmoQblsbzAv JF/v5lZhILun3Was0pq3ue3n2kYRYA/xjVMXduTrunKAIV08meRC5OHiIVgwdoM= X-Gm-Gg: ASbGncvUTrNdjk5YrogLqcCiyDUznBKewAcHEouNLXRX0EFPbWkAIaEECxENo3fcUhV u8Ps2nhTIBbVmxIdcH393948iFPpDlZhmtCAtTjkNF4HBiM03w2J+dByiPBE4arhnW9QNSWhH2/ Ij3dT+a1cBuUAchR10j2lxDvQeEQPvDGlKV9UXY2ZtYdRFqwfYDuydOW8PbwKy4Ps4T8DsoPG4o +rLDlQZJ1PwpEGpsy1SlmGnNg87k7UyAKuoMFVZe2gTjhFS6OS0AlHDNmZw0NIRmdxEf0CHpoMH LwGrLEQtHfwWss2iifpCm8p1se+sWBXr6pKwpJegfg== X-Google-Smtp-Source: AGHT+IGhbkSgvY+dW7yHkdG99m1xQ+qGuWMmxBZmDcAmT3S4qDuCQLsGs5KooVSA8ixJDjHmJigmgw== X-Received: by 2002:a05:600c:3516:b0:436:5165:f206 with SMTP id 5b1f17b1804b1-436e27075eemr265829195e9.31.1736934267210; Wed, 15 Jan 2025 01:44:27 -0800 (PST) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-437c753bee8sm16984215e9.34.2025.01.15.01.44.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jan 2025 01:44:26 -0800 (PST) Date: Wed, 15 Jan 2025 10:44:25 +0100 From: Andrew Jones To: Zong Li Cc: joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, tjeznach@rivosinc.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, luxu.kernel@bytedance.com, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, linux-riscv@lists.infradead.org Subject: Re: [PATCH 2/2] iommu/riscv: support HPM and interrupt handling Message-ID: <20250115-9d8193b7c67eeee41d18a7dd@orel> References: <20250115030306.29735-1-zong.li@sifive.com> <20250115030306.29735-3-zong.li@sifive.com> 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=us-ascii Content-Disposition: inline In-Reply-To: <20250115030306.29735-3-zong.li@sifive.com> On Wed, Jan 15, 2025 at 11:03:06AM +0800, Zong Li wrote: > Initialize the PMU and uninitialize it when driver is removed. > Interrupt handling is also implemented, and the handler needs > to be a primary handler instead of a threaded function because > pt_regs is empty when threading the IRQ. However, pt_regs is > required by perf_event_overflow. > > Signed-off-by: Zong Li > Tested-by: Xu Lu > --- > drivers/iommu/riscv/iommu.c | 65 +++++++++++++++++++++++++++++++++++++ > 1 file changed, 65 insertions(+) > > diff --git a/drivers/iommu/riscv/iommu.c b/drivers/iommu/riscv/iommu.c > index 8a05def774bd..20ae90471484 100644 > --- a/drivers/iommu/riscv/iommu.c > +++ b/drivers/iommu/riscv/iommu.c > @@ -552,6 +552,62 @@ static irqreturn_t riscv_iommu_fltq_process(int irq, void *data) > return IRQ_HANDLED; > } > > +/* > + * IOMMU Hardware performance monitor > + */ > + > +/* HPM interrupt primary handler */ > +static irqreturn_t riscv_iommu_hpm_irq_handler(int irq, void *dev_id) > +{ > + struct riscv_iommu_device *iommu = (struct riscv_iommu_device *)dev_id; > + > + /* Clear performance monitoring interrupt pending */ > + riscv_iommu_writel(iommu, RISCV_IOMMU_REG_IPSR, RISCV_IOMMU_IPSR_PMIP); > + > + /* Process pmu irq */ > + riscv_iommu_pmu_handle_irq(&iommu->pmu); > + > + return IRQ_HANDLED; > +} > + > +/* HPM initialization */ > +static int riscv_iommu_hpm_enable(struct riscv_iommu_device *iommu) > +{ > + int rc; > + > + if (!(iommu->caps & RISCV_IOMMU_CAPABILITIES_HPM)) > + return 0; > + > + /* > + * pt_regs is empty when threading the IRQ, but pt_regs is necessary > + * by perf_event_overflow. Use primary handler instead of thread > + * function for PM IRQ. > + * > + * Set the IRQF_ONESHOT flag because this IRQ might be shared with > + * other threaded IRQs by other queues. > + */ > + rc = devm_request_irq(iommu->dev, > + iommu->irqs[riscv_iommu_queue_vec(iommu, RISCV_IOMMU_IPSR_PMIP)], > + riscv_iommu_hpm_irq_handler, IRQF_ONESHOT | IRQF_SHARED, NULL, iommu); > + if (rc) > + return rc; > + > + return riscv_iommu_pmu_init(&iommu->pmu, iommu->reg, dev_name(iommu->dev)); > +} > + > +/* HPM uninitialization */ > +static void riscv_iommu_hpm_disable(struct riscv_iommu_device *iommu) > +{ > + if (!(iommu->caps & RISCV_IOMMU_CAPABILITIES_HPM)) > + return; > + > + devm_free_irq(iommu->dev, > + iommu->irqs[riscv_iommu_queue_vec(iommu, RISCV_IOMMU_IPSR_PMIP)], > + iommu); > + > + riscv_iommu_pmu_uninit(&iommu->pmu); > +} > + > /* Lookup and initialize device context info structure. */ > static struct riscv_iommu_dc *riscv_iommu_get_dc(struct riscv_iommu_device *iommu, > unsigned int devid) > @@ -1596,6 +1652,9 @@ void riscv_iommu_remove(struct riscv_iommu_device *iommu) > riscv_iommu_iodir_set_mode(iommu, RISCV_IOMMU_DDTP_IOMMU_MODE_OFF); > riscv_iommu_queue_disable(&iommu->cmdq); > riscv_iommu_queue_disable(&iommu->fltq); > + > + if (iommu->caps & RISCV_IOMMU_CAPABILITIES_HPM) > + riscv_iommu_pmu_uninit(&iommu->pmu); This should be riscv_iommu_hpm_disable(iommu); as the cover letter said it would be. > } > > int riscv_iommu_init(struct riscv_iommu_device *iommu) > @@ -1635,6 +1694,10 @@ int riscv_iommu_init(struct riscv_iommu_device *iommu) > if (rc) > goto err_queue_disable; > > + rc = riscv_iommu_hpm_enable(iommu); > + if (rc) > + goto err_hpm_disable; This should be goto err_iodir_off; And the next goto (under sysfs add) should be goto err_hpm_disable; > + > rc = iommu_device_sysfs_add(&iommu->iommu, NULL, NULL, "riscv-iommu@%s", > dev_name(iommu->dev)); > if (rc) { > @@ -1653,6 +1716,8 @@ int riscv_iommu_init(struct riscv_iommu_device *iommu) > err_remove_sysfs: > iommu_device_sysfs_remove(&iommu->iommu); > err_iodir_off: > + riscv_iommu_hpm_disable(iommu); > +err_hpm_disable: > riscv_iommu_iodir_set_mode(iommu, RISCV_IOMMU_DDTP_IOMMU_MODE_OFF); > err_queue_disable: > riscv_iommu_queue_disable(&iommu->fltq); This should be err_remove_sysfs: ... err_hpm_disable: ... err_iodir_off: ... err_queue_disable: ... Thanks, drew