From patchwork Thu Jul 30 01:45:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 11692185 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 52C0113B1 for ; Thu, 30 Jul 2020 01:50:53 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1CC392074B for ; Thu, 30 Jul 2020 01:50:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="NCLB7lRE"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="i4IpuXMh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1CC392074B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=57bNI6oO1ntgjkyUZ4YP1WQTOgXqkxfA3So4w6xljTg=; b=NCLB7lREuvn4gc8TAY5mDNThc 0hHeENhm5U1f4Rb9qb0/N0iQx44k3EEbMceojpNiZif3qsj/YSAGFKexnV3uSSZCcyoKOXArlvVe1 fQE0AGq0UtC3ucjQlHPtWfk7QgTdwyV6u8Les6HPaUKLrX63QcMdyMdSCN5Ir+oHFWXHvzjeGqpPk 3hARbKs0K7VtIIgHV0CNiJ59LQCOlD+uY7egpW9CSRPlBaYAQCxYJWHvjt6TPFliVW83Zk+G8znrH Jn98lRtzmICnhphhEPqlymhCXOJi9Mmd4bTXil2m9Ch04RxBaBU0gXF3WDTtcsWYej/8JaP1wPTU6 2tXdCQgUQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1k0xh4-0004Hs-8X; Thu, 30 Jul 2020 01:49:14 +0000 Received: from us-smtp-2.mimecast.com ([207.211.31.81] helo=us-smtp-delivery-1.mimecast.com) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1k0xea-0003AZ-Bk for linux-arm-kernel@lists.infradead.org; Thu, 30 Jul 2020 01:46:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1596073598; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b2lFRE/5gYsAlRZy+KWgGgPB1f8p6u+wl1ZkXYqyJuo=; b=i4IpuXMh021H43K+1sJwtL38jiCY1ZIa8Hw0B3xKm0EfjRenqToQKbCx3WljSBcmKF7xpL QrFQqUgXx09ljHX7XYnXk5S+fdeRGejHKFa3AUh69xHWRGBVgsAiznBAQ+cIz+eWzJJokR Y7m857Xb8WeZiJhbDYDBbnUP4QECHsU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-131-oSSwt3dJO-O1nlumrEKzAg-1; Wed, 29 Jul 2020 21:46:34 -0400 X-MC-Unique: oSSwt3dJO-O1nlumrEKzAg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2A6AB58; Thu, 30 Jul 2020 01:46:33 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-54.bne.redhat.com [10.64.54.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2BAEE60C84; Thu, 30 Jul 2020 01:46:29 +0000 (UTC) From: Gavin Shan To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 14/15] drivers/firmware/sdei: Expose struct sdei_event Date: Thu, 30 Jul 2020 11:45:29 +1000 Message-Id: <20200730014531.310465-15-gshan@redhat.com> In-Reply-To: <20200730014531.310465-1-gshan@redhat.com> References: <20200730014531.310465-1-gshan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200729_214640_886649_0029D4C2 X-CRM114-Status: GOOD ( 26.34 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [207.211.31.81 listed in wl.mailspike.net] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [207.211.31.81 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, catalin.marinas@arm.com, james.morse@arm.com, shan.gavin@gmail.com, Jonathan.Cameron@huawei.com, will@kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org This splits struct sdei_event into two structs: sdei_event and sdei_internal_event. The former one can be dereferenced from external module like arm64/kvm when SDEI virtualization is supported. The later one is used by the client driver only. This also renames local variables from @event to @event_el if their type is "struct sdei_internal_event" to make the variable name a bit meaningful. Note that it's not applied to sdei_do_{local,cross}_call() because CROSSCALL_INIT stops us doing this unless much more changes are needed. I'm avoiding to do that. Besides, @event is added as "struct sdei_event" to cache @event_el->event if it's accessed for multiple times in the particular function to reduce the code change size. This shouldn't cause functional changes. Signed-off-by: Gavin Shan Reviewed-by: Jonathan Cameron --- v4: Rename variable @event to @event_el if it's internal event Use @event to cache @event_el->event if it's used for multiple times --- drivers/firmware/arm_sdei.c | 160 ++++++++++++++++++++---------------- include/linux/arm_sdei.h | 6 ++ 2 files changed, 94 insertions(+), 72 deletions(-) diff --git a/drivers/firmware/arm_sdei.c b/drivers/firmware/arm_sdei.c index 2678475940e6..f9827c096275 100644 --- a/drivers/firmware/arm_sdei.c +++ b/drivers/firmware/arm_sdei.c @@ -44,16 +44,14 @@ static asmlinkage void (*sdei_firmware_call)(unsigned long function_id, /* entry point from firmware to arch asm code */ static unsigned long sdei_entry_point; -struct sdei_event { +struct sdei_internal_event { + struct sdei_event event; + /* These three are protected by the sdei_list_lock */ struct list_head list; bool reregister; bool reenable; - u32 event_num; - u8 type; - u8 priority; - /* This pointer is handed to firmware as the event argument. */ union { /* Shared events */ @@ -73,7 +71,7 @@ static LIST_HEAD(sdei_list); /* Private events are registered/enabled via IPI passing one of these */ struct sdei_crosscall_args { - struct sdei_event *event; + struct sdei_internal_event *event; atomic_t errors; int first_error; }; @@ -86,7 +84,7 @@ struct sdei_crosscall_args { } while (0) static inline int sdei_do_local_call(smp_call_func_t fn, - struct sdei_event *event) + struct sdei_internal_event *event) { struct sdei_crosscall_args arg; @@ -97,7 +95,7 @@ static inline int sdei_do_local_call(smp_call_func_t fn, } static inline int sdei_do_cross_call(smp_call_func_t fn, - struct sdei_event *event) + struct sdei_internal_event *event) { struct sdei_crosscall_args arg; @@ -162,16 +160,16 @@ static int invoke_sdei_fn(unsigned long function_id, unsigned long arg0, } NOKPROBE_SYMBOL(invoke_sdei_fn); -static struct sdei_event *sdei_event_find(u32 event_num) +static struct sdei_internal_event *sdei_event_find(u32 event_num) { - struct sdei_event *e, *found = NULL; + struct sdei_internal_event *event_el, *found = NULL; lockdep_assert_held(&sdei_events_lock); spin_lock(&sdei_list_lock); - list_for_each_entry(e, &sdei_list, list) { - if (e->event_num == event_num) { - found = e; + list_for_each_entry(event_el, &sdei_list, list) { + if (event_el->event.event_num == event_num) { + found = event_el; break; } } @@ -193,24 +191,26 @@ static int sdei_api_event_get_info(u32 event, u32 info, u64 *result) 0, 0, result); } -static struct sdei_event *sdei_event_create(u32 event_num, - sdei_event_callback *cb, - void *cb_arg) +static struct sdei_internal_event *sdei_event_create(u32 event_num, + sdei_event_callback *cb, + void *cb_arg) { int err; u64 result; + struct sdei_internal_event *event_el; struct sdei_event *event; struct sdei_registered_event *reg; lockdep_assert_held(&sdei_events_lock); - event = kzalloc(sizeof(*event), GFP_KERNEL); - if (!event) { + event_el = kzalloc(sizeof(*event_el), GFP_KERNEL); + if (!event_el) { err = -ENOMEM; goto fail; } - INIT_LIST_HEAD(&event->list); + event = &event_el->event; + INIT_LIST_HEAD(&event_el->list); event->event_num = event_num; err = sdei_api_event_get_info(event_num, SDEI_EVENT_INFO_EV_PRIORITY, @@ -237,7 +237,7 @@ static struct sdei_event *sdei_event_create(u32 event_num, reg->callback = cb; reg->callback_arg = cb_arg; - event->registered = reg; + event_el->registered = reg; } else { int cpu; struct sdei_registered_event __percpu *regs; @@ -257,39 +257,39 @@ static struct sdei_event *sdei_event_create(u32 event_num, reg->callback_arg = cb_arg; } - event->private_registered = regs; + event_el->private_registered = regs; } spin_lock(&sdei_list_lock); - list_add(&event->list, &sdei_list); + list_add(&event_el->list, &sdei_list); spin_unlock(&sdei_list_lock); - return event; + return event_el; fail: - kfree(event); + kfree(event_el); return ERR_PTR(err); } -static void sdei_event_destroy_llocked(struct sdei_event *event) +static void sdei_event_destroy_llocked(struct sdei_internal_event *event_el) { lockdep_assert_held(&sdei_events_lock); lockdep_assert_held(&sdei_list_lock); - list_del(&event->list); + list_del(&event_el->list); - if (event->type == SDEI_EVENT_TYPE_SHARED) - kfree(event->registered); + if (event_el->event.type == SDEI_EVENT_TYPE_SHARED) + kfree(event_el->registered); else - free_percpu(event->private_registered); + free_percpu(event_el->private_registered); - kfree(event); + kfree(event_el); } -static void sdei_event_destroy(struct sdei_event *event) +static void sdei_event_destroy(struct sdei_internal_event *event_el) { spin_lock(&sdei_list_lock); - sdei_event_destroy_llocked(event); + sdei_event_destroy_llocked(event_el); spin_unlock(&sdei_list_lock); } @@ -392,7 +392,7 @@ static void _local_event_enable(void *data) WARN_ON_ONCE(preemptible()); - err = sdei_api_event_enable(arg->event->event_num); + err = sdei_api_event_enable(arg->event->event.event_num); sdei_cross_call_return(arg, err); } @@ -400,25 +400,27 @@ static void _local_event_enable(void *data) int sdei_event_enable(u32 event_num) { int err = -EINVAL; + struct sdei_internal_event *event_el; struct sdei_event *event; mutex_lock(&sdei_events_lock); - event = sdei_event_find(event_num); - if (!event) { + event_el = sdei_event_find(event_num); + if (!event_el) { mutex_unlock(&sdei_events_lock); return -ENOENT; } cpus_read_lock(); + event = &event_el->event; if (event->type == SDEI_EVENT_TYPE_SHARED) err = sdei_api_event_enable(event->event_num); else - err = sdei_do_cross_call(_local_event_enable, event); + err = sdei_do_cross_call(_local_event_enable, event_el); if (!err) { spin_lock(&sdei_list_lock); - event->reenable = true; + event_el->reenable = true; spin_unlock(&sdei_list_lock); } cpus_read_unlock(); @@ -438,7 +440,7 @@ static void _ipi_event_disable(void *data) int err; struct sdei_crosscall_args *arg = data; - err = sdei_api_event_disable(arg->event->event_num); + err = sdei_api_event_disable(arg->event->event.event_num); sdei_cross_call_return(arg, err); } @@ -446,23 +448,25 @@ static void _ipi_event_disable(void *data) int sdei_event_disable(u32 event_num) { int err = -EINVAL; + struct sdei_internal_event *event_el; struct sdei_event *event; mutex_lock(&sdei_events_lock); - event = sdei_event_find(event_num); - if (!event) { + event_el = sdei_event_find(event_num); + if (!event_el) { mutex_unlock(&sdei_events_lock); return -ENOENT; } spin_lock(&sdei_list_lock); - event->reenable = false; + event_el->reenable = false; spin_unlock(&sdei_list_lock); + event = &event_el->event; if (event->type == SDEI_EVENT_TYPE_SHARED) err = sdei_api_event_disable(event->event_num); else - err = sdei_do_cross_call(_ipi_event_disable, event); + err = sdei_do_cross_call(_ipi_event_disable, event_el); mutex_unlock(&sdei_events_lock); return err; @@ -482,7 +486,7 @@ static void _local_event_unregister(void *data) WARN_ON_ONCE(preemptible()); - err = sdei_api_event_unregister(arg->event->event_num); + err = sdei_api_event_unregister(arg->event->event.event_num); sdei_cross_call_return(arg, err); } @@ -490,32 +494,34 @@ static void _local_event_unregister(void *data) int sdei_event_unregister(u32 event_num) { int err; + struct sdei_internal_event *event_el; struct sdei_event *event; WARN_ON(in_nmi()); mutex_lock(&sdei_events_lock); - event = sdei_event_find(event_num); - if (!event) { + event_el = sdei_event_find(event_num); + if (!event_el) { pr_warn("Event %u not registered\n", event_num); err = -ENOENT; goto unlock; } spin_lock(&sdei_list_lock); - event->reregister = false; - event->reenable = false; + event_el->reregister = false; + event_el->reenable = false; spin_unlock(&sdei_list_lock); + event = &event_el->event; if (event->type == SDEI_EVENT_TYPE_SHARED) err = sdei_api_event_unregister(event->event_num); else - err = sdei_do_cross_call(_local_event_unregister, event); + err = sdei_do_cross_call(_local_event_unregister, event_el); if (err) goto unlock; - sdei_event_destroy(event); + sdei_event_destroy(event_el); unlock: mutex_unlock(&sdei_events_lock); @@ -529,11 +535,13 @@ int sdei_event_unregister(u32 event_num) static int sdei_unregister_shared(void) { int err = 0; + struct sdei_internal_event *event_el; struct sdei_event *event; mutex_lock(&sdei_events_lock); spin_lock(&sdei_list_lock); - list_for_each_entry(event, &sdei_list, list) { + list_for_each_entry(event_el, &sdei_list, list) { + event = &event_el->event; if (event->type != SDEI_EVENT_TYPE_SHARED) continue; @@ -565,8 +573,8 @@ static void _local_event_register(void *data) WARN_ON(preemptible()); reg = per_cpu_ptr(arg->event->private_registered, smp_processor_id()); - err = sdei_api_event_register(arg->event->event_num, sdei_entry_point, - reg, 0, 0); + err = sdei_api_event_register(arg->event->event.event_num, + sdei_entry_point, reg, 0, 0); sdei_cross_call_return(arg, err); } @@ -574,6 +582,7 @@ static void _local_event_register(void *data) int sdei_event_register(u32 event_num, sdei_event_callback *cb, void *arg) { int err; + struct sdei_internal_event *event_el; struct sdei_event *event; WARN_ON(in_nmi()); @@ -585,33 +594,34 @@ int sdei_event_register(u32 event_num, sdei_event_callback *cb, void *arg) goto unlock; } - event = sdei_event_create(event_num, cb, arg); - if (IS_ERR(event)) { - err = PTR_ERR(event); + event_el = sdei_event_create(event_num, cb, arg); + if (IS_ERR(event_el)) { + err = PTR_ERR(event_el); pr_warn("Failed to create event %u: %d\n", event_num, err); goto unlock; } cpus_read_lock(); + event = &event_el->event; if (event->type == SDEI_EVENT_TYPE_SHARED) { err = sdei_api_event_register(event->event_num, sdei_entry_point, - event->registered, + event_el->registered, SDEI_EVENT_REGISTER_RM_ANY, 0); } else { - err = sdei_do_cross_call(_local_event_register, event); + err = sdei_do_cross_call(_local_event_register, event_el); if (err) - sdei_do_cross_call(_local_event_unregister, event); + sdei_do_cross_call(_local_event_unregister, event_el); } if (err) { - sdei_event_destroy(event); + sdei_event_destroy(event_el); pr_warn("Failed to register event %u: %d\n", event_num, err); goto cpu_unlock; } spin_lock(&sdei_list_lock); - event->reregister = true; + event_el->reregister = true; spin_unlock(&sdei_list_lock); cpu_unlock: cpus_read_unlock(); @@ -623,27 +633,29 @@ int sdei_event_register(u32 event_num, sdei_event_callback *cb, void *arg) static int sdei_reregister_shared(void) { int err = 0; + struct sdei_internal_event *event_el; struct sdei_event *event; mutex_lock(&sdei_events_lock); spin_lock(&sdei_list_lock); - list_for_each_entry(event, &sdei_list, list) { + list_for_each_entry(event_el, &sdei_list, list) { + event = &event_el->event; if (event->type != SDEI_EVENT_TYPE_SHARED) continue; - if (event->reregister) { + if (event_el->reregister) { err = sdei_api_event_register(event->event_num, - sdei_entry_point, event->registered, + sdei_entry_point, event_el->registered, SDEI_EVENT_REGISTER_RM_ANY, 0); if (err) { - sdei_event_destroy_llocked(event); + sdei_event_destroy_llocked(event_el); pr_err("Failed to re-register event %u\n", event->event_num); break; } } - if (event->reenable) { + if (event_el->reenable) { err = sdei_api_event_enable(event->event_num); if (err) { pr_err("Failed to re-enable event %u\n", @@ -660,16 +672,18 @@ static int sdei_reregister_shared(void) static int sdei_cpuhp_down(unsigned int cpu) { + struct sdei_internal_event *event_el; struct sdei_event *event; int err; /* un-register private events */ spin_lock(&sdei_list_lock); - list_for_each_entry(event, &sdei_list, list) { + list_for_each_entry(event_el, &sdei_list, list) { + event = &event_el->event; if (event->type == SDEI_EVENT_TYPE_SHARED) continue; - err = sdei_do_local_call(_local_event_unregister, event); + err = sdei_do_local_call(_local_event_unregister, event_el); if (err) { pr_err("Failed to unregister event %u: %d\n", event->event_num, err); @@ -682,25 +696,27 @@ static int sdei_cpuhp_down(unsigned int cpu) static int sdei_cpuhp_up(unsigned int cpu) { + struct sdei_internal_event *event_el; struct sdei_event *event; int err; /* re-register/enable private events */ spin_lock(&sdei_list_lock); - list_for_each_entry(event, &sdei_list, list) { + list_for_each_entry(event_el, &sdei_list, list) { + event = &event_el->event; if (event->type == SDEI_EVENT_TYPE_SHARED) continue; - if (event->reregister) { - err = sdei_do_local_call(_local_event_register, event); + if (event_el->reregister) { + err = sdei_do_local_call(_local_event_register, event_el); if (err) { pr_err("Failed to re-register event %u: %d\n", event->event_num, err); } } - if (event->reenable) { - err = sdei_do_local_call(_local_event_enable, event); + if (event_el->reenable) { + err = sdei_do_local_call(_local_event_enable, event_el); if (err) { pr_err("Failed to re-enable event %u: %d\n", event->event_num, err); diff --git a/include/linux/arm_sdei.h b/include/linux/arm_sdei.h index 0a241c5c911d..d2464a18b6ff 100644 --- a/include/linux/arm_sdei.h +++ b/include/linux/arm_sdei.h @@ -22,6 +22,12 @@ */ typedef int (sdei_event_callback)(u32 event, struct pt_regs *regs, void *arg); +struct sdei_event { + u32 event_num; + u8 type; + u8 priority; +}; + /* * Register your callback to claim an event. The event must be described * by firmware.