From patchwork Wed Jan 22 01:58:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bobby Eshleman X-Patchwork-Id: 11345023 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 14E701820 for ; Wed, 22 Jan 2020 05:15:17 +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 E5A782465B for ; Wed, 22 Jan 2020 05:15:16 +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="FGNwiaj4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E5A782465B 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 1iu8L8-00057g-FY; Wed, 22 Jan 2020 05:14:06 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iu5KT-00067y-5j for xen-devel@lists.xenproject.org; Wed, 22 Jan 2020 02:01:13 +0000 X-Inumbo-ID: fea865a6-3cba-11ea-8e9a-bc764e2007e4 Received: from mail-yw1-xc42.google.com (unknown [2607:f8b0:4864:20::c42]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id fea865a6-3cba-11ea-8e9a-bc764e2007e4; Wed, 22 Jan 2020 02:00:42 +0000 (UTC) Received: by mail-yw1-xc42.google.com with SMTP id i126so2494570ywe.7 for ; Tue, 21 Jan 2020 18:00:42 -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=hPzG//PCqLHO4ojeBNgRN81r9BcFtFqIrb1fV21Zofw=; b=FGNwiaj4AVNFSh212mh20XBZSolIt6ZNVYb9Dk2wYNmgnjXt8jI7/DP6MLOpsCz9GP Yj33MCe5gc6GSnatR2kpZ069jLFjFvkfffX2MBg6p+vIjquibwZzb9OuAwBTNkj+jRZd IDwJTzCb0B4WfjJVuC9rhvui1Orskcf1d8qAe+XZPUBk5lYmKEDwLM1AuDzEcCptsKvA bAnKS3n7mU2N8a0eLqAxRKQFQSLVx17rdRvwPIzfKvgWi/+tYWlwXh80oDcwETamA/DY kqaGXPnAldqozuEVlItd4skyXztgbGRRwJqcsa4HqnwOW1kkLgL0mmeRrwHRJWCAJb67 k4Bw== 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=hPzG//PCqLHO4ojeBNgRN81r9BcFtFqIrb1fV21Zofw=; b=Yl24uKd6aNWJLqWIkxNwJMwuR3eLZyefPrvu+dUBt587pCiauYWeniI5n3JJYCk4WZ XdNJmr++/qZVRNNzt0y6iHLZc0OvFiOjIqofRhj3T46NvyxPXnEu61l+sn0dWTW7Cn02 ZsETI1JpNXUmfnjQUgt5jttTuqUx1y67MmW+tI2LTtknFFkjWPS/JHfMqpPLaUI1J4Eu Kbllm1BB4T4BqX8Hdt7P0chBP56hmJRb1vN4XBE3Goas9ieRv1A6K9odA2muxELrXkvj 7rjOUbjZSKZO3nHb7wvW3a8OhsQPqRzEDJ+L+i0VC/LAtzqWLZ4nQlxI04pYvxtY8XEG g4WQ== X-Gm-Message-State: APjAAAUwG0+d7KUw6pE4kkoL4RsiBzpj3Um808rWjLX7voO/lx+ZJIeN 5vI+ABsn0IcNVHjkmCo4oUJNVuQkQPtvCg== X-Google-Smtp-Source: APXvYqz4BiboNf2rJ3QyV/9KQu9GEtr+/CKitUhpBMgpyb3XJrVEOg2pQEeKH7VmmGyoroh9/d/8iw== X-Received: by 2002:a81:7389:: with SMTP id o131mr5780087ywc.212.1579658441536; Tue, 21 Jan 2020 18:00:41 -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.00.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jan 2020 18:00:41 -0800 (PST) From: Bobby Eshleman To: xen-devel@lists.xenproject.org Date: Tue, 21 Jan 2020 19:58:48 -0600 Message-Id: <4746987465e0685e00c3e55dee58c83e03bea578.1579615303.git.bobbyeshleman@gmail.com> 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 09/23] riscv: Add domain.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/domain.c | 273 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 273 insertions(+) create mode 100644 xen/arch/riscv/domain.c diff --git a/xen/arch/riscv/domain.c b/xen/arch/riscv/domain.c new file mode 100644 index 0000000000..206366abf7 --- /dev/null +++ b/xen/arch/riscv/domain.c @@ -0,0 +1,273 @@ +/****************************************************************************** + * + * Copyright 2019 (C) Alistair Francis + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +DEFINE_PER_CPU(struct vcpu *, curr_vcpu); + +static void do_idle(void) +{ + unsigned int cpu = smp_processor_id(); + + sched_tick_suspend(); + /* sched_tick_suspend() can raise TIMER_SOFTIRQ. Process it now. */ + process_pending_softirqs(); + + local_irq_disable(); + if ( cpu_is_haltable(cpu) ) + { + wait_for_interrupt(); + } + local_irq_enable(); + + sched_tick_resume(); +} + +void idle_loop(void) +{ + unsigned int cpu = smp_processor_id(); + + for ( ; ; ) + { + if ( cpu_is_offline(cpu) ) + stop_cpu(); + + /* Are we here for running vcpu context tasklets, or for idling? */ + if ( unlikely(tasklet_work_to_do(cpu)) ) + do_tasklet(); + /* + * Test softirqs twice --- first to see if should even try scrubbing + * and then, after it is done, whether softirqs became pending + * while we were scrubbing. + */ + else if ( !softirq_pending(cpu) && !scrub_free_pages() && + !softirq_pending(cpu) ) + do_idle(); + + do_softirq(); + /* + * We MUST be last (or before dsb, wfi). Otherwise after we get the + * softirq we would execute dsb,wfi (and sleep) and not patch. + */ + check_for_livepatch_work(); + } +} + + +void context_switch(struct vcpu *prev, struct vcpu *next) +{ + ASSERT(local_irq_is_enabled()); + ASSERT(prev != next); + ASSERT(!vcpu_cpu_dirty(next)); + + local_irq_disable(); + + /* TODO */ + + set_current(next); +} + +void continue_running(struct vcpu *same) +{ + /* Nothing to do */ +} + +void sync_local_execstate(void) +{ + /* Nothing to do -- no lazy switching */ +} + +void sync_vcpu_execstate(struct vcpu *v) +{ + /* Nothing to do -- no lazy switching */ +} + +unsigned long hypercall_create_continuation( + unsigned int op, const char *format, ...) +{ + /* TODO */ + + return 0; +} + +void startup_cpu_idle_loop(void) +{ + struct vcpu *v = current; + + ASSERT(is_idle_vcpu(v)); + + reset_stack_and_jump(idle_loop); +} + +struct domain *alloc_domain_struct(void) +{ + struct domain *d; + BUILD_BUG_ON(sizeof(*d) > PAGE_SIZE); + d = alloc_xenheap_pages(0, 0); + if ( d == NULL ) + return NULL; + + clear_page(d); + return d; +} + +void free_domain_struct(struct domain *d) +{ + free_xenheap_page(d); +} + +void dump_pageframe_info(struct domain *d) +{ + +} + +int arch_sanitise_domain_config(struct xen_domctl_createdomain *config) +{ + /* TODO */ + + return 0; +} + + +int arch_domain_create(struct domain *d, + struct xen_domctl_createdomain *config) +{ + /* TODO */ + + return 0; +} + +void arch_domain_destroy(struct domain *d) +{ +} + +void arch_domain_shutdown(struct domain *d) +{ +} + +void arch_domain_pause(struct domain *d) +{ +} + +void arch_domain_unpause(struct domain *d) +{ +} + +int arch_domain_soft_reset(struct domain *d) +{ + return -ENOSYS; +} + +void arch_domain_creation_finished(struct domain *d) +{ + /* TODO */ +} + +int domain_relinquish_resources(struct domain *d) +{ + /* TODO */ + + return 0; +} + +void arch_dump_domain_info(struct domain *d) +{ + p2m_dump_info(d); +} + +long arch_do_vcpu_op(int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg) +{ + return -ENOSYS; +} + +void arch_dump_vcpu_info(struct vcpu *v) +{ + /* TODO */ +} + +int arch_set_info_guest( + struct vcpu *v, vcpu_guest_context_u c) +{ + /* TODO */ + + return 0; +} + +#define MAX_PAGES_PER_VCPU 2 + +struct vcpu *alloc_vcpu_struct(const struct domain *d) +{ + struct vcpu *v; + + BUILD_BUG_ON(sizeof(*v) > MAX_PAGES_PER_VCPU * PAGE_SIZE); + v = alloc_xenheap_pages(get_order_from_bytes(sizeof(*v)), 0); + if ( v != NULL ) + { + unsigned int i; + + for ( i = 0; i < DIV_ROUND_UP(sizeof(*v), PAGE_SIZE); i++ ) + clear_page((void *)v + i * PAGE_SIZE); + } + + return v; +} + +void free_vcpu_struct(struct vcpu *v) +{ + free_xenheap_pages(v, get_order_from_bytes(sizeof(*v))); +} + +int arch_initialise_vcpu(struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg) +{ + return default_initialise_vcpu(v, arg); +} + +int arch_vcpu_reset(struct vcpu *v) +{ + /* TODO */ + return 0; +} + +int arch_vcpu_create(struct vcpu *v) +{ + int rc = 0; + + /* TODO */ + + return rc; +} + +void arch_vcpu_destroy(struct vcpu *v) +{ + /* TODO */ +}