From patchwork Wed Jan 22 01:59:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bobby Eshleman X-Patchwork-Id: 11345013 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 3DC7D17EA for ; Wed, 22 Jan 2020 05:15:14 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 1998A2465B for ; Wed, 22 Jan 2020 05:15:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QqvKwHqf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1998A2465B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iu8LF-0005IS-1G; Wed, 22 Jan 2020 05:14:13 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iu5LR-0006CB-7K for xen-devel@lists.xenproject.org; Wed, 22 Jan 2020 02:02:13 +0000 X-Inumbo-ID: 0ba01650-3cbb-11ea-aecd-bc764e2007e4 Received: from mail-yw1-xc44.google.com (unknown [2607:f8b0:4864:20::c44]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 0ba01650-3cbb-11ea-aecd-bc764e2007e4; Wed, 22 Jan 2020 02:01:04 +0000 (UTC) Received: by mail-yw1-xc44.google.com with SMTP id u139so2475016ywf.13 for ; Tue, 21 Jan 2020 18:01:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SKS6qGVQV3GhDkVinOGX23DfUW5cRlK+gPrmn5t+rt8=; b=QqvKwHqfUBDWnaK1t+t8lIPlJ64yT0rqcIgd36G7Z1IgSiu2LqKQksmg4V1t2qiVj1 9NDqsMs7TVl6yo7Lzox4lxongmQAbLqbSd2vYiLL+NOJGL6+Y+YwHysyaw5QjCwEIXmx /2M5D6AWaOah/Pr6mZnWbDhoIjmAamN48dXacpdJyMUisHuJW36BP6+N81B6zRSmV6a9 +ocqm8fqrgSkgEytO2Ueh+Lcb7dJbuLXL+meXOT1LeVDE98rZHaIL1JaqBOU+RzxBgZz Yg1+GRsEzCUEn4JI+SjUD8X/clQLthHXscqQ2ydk/APxFy8LaqJROECxH7Cpo19zxJzs QZ8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SKS6qGVQV3GhDkVinOGX23DfUW5cRlK+gPrmn5t+rt8=; b=DXbWiPznyhI33fo7+tHtVvS0cPCL/Ya5EOfz8rwntx4jJUCdipi/xy7QYpLGD1Shu0 zi0cNCinW16doDGY32RJ5smZS8rmf0SP0wJYejrXyQ6Lca/xOCU6DS1jQZQNzUMD6qE/ mLdQkfg4Zc/XYiHjBQadK0aKgqJODK56G3AnudC2HZzRaktvsXhr4UH/6tNLxWe9MhWP j+tc04ciMpc2JkHVv/SASEquDgYprj8tBl8dxPi/JAler68CbbXvbvvXEJwir+gLyzVL qR/7/JZ75MJftJqT11G7FwGc6jk/+oTAtKQSCCrSHtzOwvugonLRFdr/sS4nNh2sFqlW 4EvQ== X-Gm-Message-State: APjAAAX87inVJMrKdLTojf8F3HK07c+8Ho3W0oAMQywlVUFh8uBLiQfP tMu1ubQKkm1ED7rJ4nRkyNf5EpuHBO7M6Q== X-Google-Smtp-Source: APXvYqwdTZN3WwMYDU3zmoqR6t1y+daSlmYjKiv8apFvQlfQt2X0uaYbhJsNjAFTrpIY3+USD+lXow== X-Received: by 2002:a81:af56:: with SMTP id x22mr6001949ywj.153.1579658463416; Tue, 21 Jan 2020 18:01:03 -0800 (PST) Received: from bobbye-pc.knology.net ([216.186.244.35]) by smtp.gmail.com with ESMTPSA id q185sm17504248ywh.61.2020.01.21.18.01.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jan 2020 18:01:03 -0800 (PST) From: Bobby Eshleman To: xen-devel@lists.xenproject.org Date: Tue, 21 Jan 2020 19:59:00 -0600 Message-Id: X-Mailer: git-send-email 2.25.0 In-Reply-To: References: MIME-Version: 1.0 X-Mailman-Approved-At: Wed, 22 Jan 2020 05:14:01 +0000 Subject: [Xen-devel] [RFC XEN PATCH 21/23] riscv: Add percpu.c X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Bobby Eshleman , Stefano Stabellini , Julien Grall , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Bobby Eshleman , Dan Robertson , Alistair Francis Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Alistair Francis Signed-off-by: Alistair Francis --- xen/arch/riscv/percpu.c | 84 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 xen/arch/riscv/percpu.c diff --git a/xen/arch/riscv/percpu.c b/xen/arch/riscv/percpu.c new file mode 100644 index 0000000000..25442c48fe --- /dev/null +++ b/xen/arch/riscv/percpu.c @@ -0,0 +1,84 @@ +#include +#include +#include +#include +#include + +unsigned long __per_cpu_offset[NR_CPUS]; +#define INVALID_PERCPU_AREA (-(long)__per_cpu_start) +#define PERCPU_ORDER (get_order_from_bytes(__per_cpu_data_end-__per_cpu_start)) + +void __init percpu_init_areas(void) +{ + unsigned int cpu; + for ( cpu = 1; cpu < NR_CPUS; cpu++ ) + __per_cpu_offset[cpu] = INVALID_PERCPU_AREA; +} + +static int init_percpu_area(unsigned int cpu) +{ + char *p; + if ( __per_cpu_offset[cpu] != INVALID_PERCPU_AREA ) + return -EBUSY; + if ( (p = alloc_xenheap_pages(PERCPU_ORDER, 0)) == NULL ) + return -ENOMEM; + memset(p, 0, __per_cpu_data_end - __per_cpu_start); + __per_cpu_offset[cpu] = p - __per_cpu_start; + return 0; +} + +struct free_info { + unsigned int cpu; + struct rcu_head rcu; +}; +static DEFINE_PER_CPU(struct free_info, free_info); + +static void _free_percpu_area(struct rcu_head *head) +{ + struct free_info *info = container_of(head, struct free_info, rcu); + unsigned int cpu = info->cpu; + char *p = __per_cpu_start + __per_cpu_offset[cpu]; + free_xenheap_pages(p, PERCPU_ORDER); + __per_cpu_offset[cpu] = INVALID_PERCPU_AREA; +} + +static void free_percpu_area(unsigned int cpu) +{ + struct free_info *info = &per_cpu(free_info, cpu); + info->cpu = cpu; + call_rcu(&info->rcu, _free_percpu_area); +} + +static int cpu_percpu_callback( + struct notifier_block *nfb, unsigned long action, void *hcpu) +{ + unsigned int cpu = (unsigned long)hcpu; + int rc = 0; + + switch ( action ) + { + case CPU_UP_PREPARE: + rc = init_percpu_area(cpu); + break; + case CPU_UP_CANCELED: + case CPU_DEAD: + free_percpu_area(cpu); + break; + default: + break; + } + + return !rc ? NOTIFY_DONE : notifier_from_errno(rc); +} + +static struct notifier_block cpu_percpu_nfb = { + .notifier_call = cpu_percpu_callback, + .priority = 100 /* highest priority */ +}; + +static int __init percpu_presmp_init(void) +{ + register_cpu_notifier(&cpu_percpu_nfb); + return 0; +} +presmp_initcall(percpu_presmp_init);