From patchwork Mon Nov 30 17:35:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 334722 Delivered-To: patch@linaro.org Received: by 2002:a92:5e16:0:0:0:0:0 with SMTP id s22csp4896782ilb; Mon, 30 Nov 2020 09:42:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJwr/DqIMCUnDBCkOQC5VHN4mMHlrYrZpqCXIVyiJVPY0GlhQLWxfcDxodlLsrUKskqiZrxj X-Received: by 2002:a17:906:4756:: with SMTP id j22mr4096743ejs.353.1606758120688; Mon, 30 Nov 2020 09:42:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606758120; cv=none; d=google.com; s=arc-20160816; b=jrXMXhsZhzodh98BRl7ImxoysKqT4UxlqGAGIVdNLTvMx6gOkNVq1+d9pFr8Xjnhx9 QWXi1elLui5whDfV/Olir9mVlUp2GB1IxiHqkCIcRlSZtsMMdAon1d6QvDZeZUmfz2E7 YjogERTh/a/lZYmd2CvuqpYCT4zxJlnppPjEvEkv+GMbHqgXRbOooO7uSkq4eMm3LZZn 0VC5QDw7752IVwSSsgP1fISQdK+0JAUNTgXvff5fIwZTSdxxZd9S2SSCZePtPrQM4OSh dSpPtt5QNAoT3SKIt0mg9YFF1Q7Uy/Uya33yBwJLIWDMk1Sb8sNig38VO/AF7Lj8Cf/1 5a8A== 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=0Nw2s2omaQOvJ7GAL2qwV7HLlkMeDiyxgPIlYnpzd5M=; b=bdCvavrWoO924tzc2A0VY7OThW7VsBpoE6kLbC+h3Srdk10YevEKSMN+BUAd+LfTzE 4oJ6vOmIheQRtC+ftqkQ7rawy4J9H+y8bkbGrngtLp8ZfR5pH62bavojE4Ec52VXYEYS aKZGV3TeynrOpFsAejwaD7hrFakTLvZ333AVBq/bgt9/IT83tMAdoK/js6OqRPWsQ6ot cCb+gpvYqBZBJeeE84OyyhOC9Vdx17SQBmVeAjTCUYr47yYAC7vxF1Aoh5isUsLDIgKf 25XVr9WGmkd6YDSwGRRvYRYQrOwb+eDa6qRLZSm9BKeplZZkUvtcWcFQKakqWNP6G4OY OCsQ== 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 b27si11520228eje.466.2020.11.30.09.42.00 for ; Mon, 30 Nov 2020 09:42:00 -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 S1729522AbgK3Rkp (ORCPT ); Mon, 30 Nov 2020 12:40:45 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:8888 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729492AbgK3Rkn (ORCPT ); Mon, 30 Nov 2020 12:40:43 -0500 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4ClCCp0JpRz76Mc; Tue, 1 Dec 2020 01:39:34 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.487.0; Tue, 1 Dec 2020 01:39:49 +0800 From: John Garry To: , , , , , , CC: , , , , , "John Garry" Subject: [PATCH v4 1/5] genirq/affinity: Add irq_update_affinity_desc() Date: Tue, 1 Dec 2020 01:35:55 +0800 Message-ID: <1606757759-6076-2-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1606757759-6076-1-git-send-email-john.garry@huawei.com> References: <1606757759-6076-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..791691cb9005 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_activate_irq(&desc->irq_data, false); + +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);