From patchwork Wed Nov 25 17:20:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 332380 Delivered-To: patch@linaro.org Received: by 2002:a92:5e16:0:0:0:0:0 with SMTP id s22csp622908ilb; Wed, 25 Nov 2020 09:25:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJx7x7Rb+XAW5mFumL7x3XHUI0H7VvswI5P2hNqxiUpjhiEQL9Ie+YW67fbcY6h4x6/DzxbF X-Received: by 2002:a17:906:4756:: with SMTP id j22mr4102159ejs.315.1606325107357; Wed, 25 Nov 2020 09:25:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606325107; cv=none; d=google.com; s=arc-20160816; b=WOH7+Dsc57sWuR4Vuaw+usYlHluFZ7Mepemf/R6gfoLIXKxWek2QEvHsfBtJ0Pzqjq HeBIN/sIP882Z+BgGcVxZT8hK8FH4/cWM38hRtecQ6rrfLk2CkkhXSK8lwdsEUKnunuK lJQXyrx8sDwfgDZ/5qTv91VU7WckD3hhaaRlR6qzlFUuwVBC769IkkE9wgOGKBEE8ynu pe1q27LCMqMOjf/mtIutDc+drVYy474SByxAwcu7AEt2oUfNeCR/YMZmnZqXRauX4LEs p7PtAlVyfD8DNvz1/syQT4abCksXM5zaWeaxXC72oPA4wu7zD7RutqrcfwpfEQaqmJo5 HSsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=+aC3ykKw9fCG7TeYHja+8D7HSCvquw7rdN7rxKCDF7I=; b=jYH5trpIYeDDDv5j/u5BqWpSDLKnVpcWjoWufeRlsRSVN27mR4F0u5vELOUaPLiSSr pZz8nxs9SruDhXsHLl01dMaZ7rbX2aHdcO3FKEYhcx6c3FD4uI64jjcXYZmA/2WBjlrH qMHlCAIsZ4LDZw7im6jtaq+/BdpdZUBPwL/3NKQ6pBSmy9VK3qjcZgFPh+AZLuu8TxbE RgLkUcb/fRku4OZUfEiukYEY7chM4rlp5lQ5VX2jfOPbG3ruJZkqiiL6dhTmMnH82FbU H42NrBmMPa3wWplPqjbVnf6B1bc8dXPT0OOHHXQbqvUCa+8rP/IfabgLL+1XICtt66gh 01cg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k22si2164875edj.571.2020.11.25.09.25.07 for ; Wed, 25 Nov 2020 09:25:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732700AbgKYRYz (ORCPT ); Wed, 25 Nov 2020 12:24:55 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:8035 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731278AbgKYRYx (ORCPT ); Wed, 25 Nov 2020 12:24:53 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4Ch76f57gkzhcWr; Thu, 26 Nov 2020 01:24:26 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Thu, 26 Nov 2020 01:24:37 +0800 From: John Garry To: , , , , , CC: , , , , , "John Garry" Subject: [PATCH v3 1/5] genirq/affinity: Add irq_update_affinity_desc() Date: Thu, 26 Nov 2020 01:20:37 +0800 Message-ID: <1606324841-217570-2-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1606324841-217570-1-git-send-email-john.garry@huawei.com> References: <1606324841-217570-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add a function to allow the affinity of an interrupt be switched to managed, such that interrupts allocated for platform devices may be managed. Suggested-by: Thomas Gleixner Signed-off-by: John Garry --- include/linux/interrupt.h | 8 +++++ kernel/irq/manage.c | 63 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) -- 2.26.2 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h index ee8299eb1f52..870b3251e174 100644 --- a/include/linux/interrupt.h +++ b/include/linux/interrupt.h @@ -352,6 +352,8 @@ extern int irq_can_set_affinity(unsigned int irq); extern int irq_select_affinity(unsigned int irq); extern int irq_set_affinity_hint(unsigned int irq, const struct cpumask *m); +extern int irq_update_affinity_desc(unsigned int irq, + struct irq_affinity_desc *affinity); extern int irq_set_affinity_notifier(unsigned int irq, struct irq_affinity_notify *notify); @@ -387,6 +389,12 @@ static inline int irq_set_affinity_hint(unsigned int irq, return -EINVAL; } +static inline int irq_update_affinity_desc(unsigned int irq, + struct irq_affinity_desc *affinity) +{ + return -EINVAL; +} + static inline int irq_set_affinity_notifier(unsigned int irq, struct irq_affinity_notify *notify) { diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c index c460e0496006..8201aff639f7 100644 --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c @@ -371,6 +371,69 @@ int irq_set_affinity_locked(struct irq_data *data, const struct cpumask *mask, return ret; } +/** + * irq_update_affinity_desc - Update affinity management for an interrupt + * @irq: The interrupt number to update + * @affinity: Pointer to the affinity descriptor + * + * This interface can be used to configure the affinity management of + * interrupts which have been allocated already. + */ +int irq_update_affinity_desc(unsigned int irq, + struct irq_affinity_desc *affinity) +{ + struct irq_desc *desc; + unsigned long flags; + bool activated; + int ret = 0; + + /* + * Supporting this with the reservation scheme used by x86 needs + * some more thought. Fail it for now. + */ + if (IS_ENABLED(CONFIG_GENERIC_IRQ_RESERVATION_MODE)) + return -EOPNOTSUPP; + + desc = irq_get_desc_buslock(irq, &flags, 0); + if (!desc) + return -EINVAL; + + /* Requires the interrupt to be shut down */ + if (irqd_is_started(&desc->irq_data)) { + ret = -EBUSY; + goto out_unlock; + } + + /* Interrupts which are already managed cannot be modified */ + if (irqd_affinity_is_managed(&desc->irq_data)) { + ret = -EBUSY; + goto out_unlock; + } + + /* + * Deactivate the interrupt. That's required to undo + * anything an earlier activation has established. + */ + activated = irqd_is_activated(&desc->irq_data); + if (activated) + irq_domain_deactivate_irq(&desc->irq_data); + + if (affinity->is_managed) { + irqd_set(&desc->irq_data, IRQD_AFFINITY_MANAGED); + irqd_set(&desc->irq_data, IRQD_MANAGED_SHUTDOWN); + } + + cpumask_copy(desc->irq_common_data.affinity, &affinity->mask); + + /* Restore the activation state */ + if (activated) + irq_domain_deactivate_irq(&desc->irq_data); + +out_unlock: + irq_put_desc_busunlock(desc, flags); + return ret; +} + int __irq_set_affinity(unsigned int irq, const struct cpumask *mask, bool force) { struct irq_desc *desc = irq_to_desc(irq);