From nobody Wed Apr 24 15:59:12 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1610488772; cv=none; d=zohomail.com; s=zohoarc; b=ESY8yKJgyrSW0Yrc7GwHcx8r8THobNJPkAxj4b0D0sNAbVx+7oGtrxjWW11/ll/p6dt3UCHZnfSWj/PI95GJB/ja1fySCZuVIEOlf1Bx8vxNruIDoz66guOeC3rVKm3MulPDVJrY1dVsse1KR2q+T0Ha1QDkcX+lOOhg7iqSunc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610488772; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=MIH572tckzyqDgDHK6bJ/MeONG4OmFZM99c4IxUYjYE=; b=XJPxDr+VxPYkHUzeifF1ld9jxqlOMcEy3R0ZwCR94eapu6kgip8gI1bIRAGXllzm46OL5hkiZU38/CKUFGISdLMeoP+B7TYqG3kPnVweYXXcmgLSYchlg2+mkBQFYoenup4tOF1mYVLl7hUU+iZ1ZyQNWfSqSTJL9xyAJiM6Bs8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1610488772158299.4456167084247; Tue, 12 Jan 2021 13:59:32 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.66104.117387 (Exim 4.92) (envelope-from ) id 1kzRh8-0004aJ-Rt; Tue, 12 Jan 2021 21:59:18 +0000 Received: by outflank-mailman (output) from mailman id 66104.117387; Tue, 12 Jan 2021 21:59:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kzRh8-0004Zc-Gu; Tue, 12 Jan 2021 21:59:18 +0000 Received: by outflank-mailman (input) for mailman id 66104; Tue, 12 Jan 2021 21:59:16 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kzRdD-0002PK-KW for xen-devel@lists.xenproject.org; Tue, 12 Jan 2021 21:55:15 +0000 Received: from mail-wr1-x436.google.com (unknown [2a00:1450:4864:20::436]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 261ce1d2-5879-425d-aa15-38c7ac3d5095; Tue, 12 Jan 2021 21:53:16 +0000 (UTC) Received: by mail-wr1-x436.google.com with SMTP id m4so526wrx.9 for ; Tue, 12 Jan 2021 13:53:15 -0800 (PST) Received: from otyshchenko.www.tendawifi.com ([212.22.223.21]) by smtp.gmail.com with ESMTPSA id 138sm6574053wma.41.2021.01.12.13.53.13 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Jan 2021 13:53:14 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 261ce1d2-5879-425d-aa15-38c7ac3d5095 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; bh=MIH572tckzyqDgDHK6bJ/MeONG4OmFZM99c4IxUYjYE=; b=BIagn9PvZ/HwuH3xthBj4COy1oPZhIRA+YxMR8kaA4A4t5Gah8MAA0dU8NOqdojYXD XpX+oDshCS9lWFklfEtfd7gJs6XwyyHlvFjrCBTVJKZwRZP4wJW/61+M62qM9KV/UmR+ +3qqTyNb0MjWrrxym5pc0AKVWHDcV0ek8iInuAR3yQLSzrrmK91nJqn/zPVGoljdZ0dI EXhE5/JRYjGNKgTJEF4iGSu8p9POSruBePkZJMZB1DT57ftiSPMqxB/RMio97JRGdfED R9IvBtv1cchXTHOhfRSGygqydA1WqYwu4c5ImoryE9MXicBhv8GrZ77KT2C/63l0cAtU Zz4g== 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; bh=MIH572tckzyqDgDHK6bJ/MeONG4OmFZM99c4IxUYjYE=; b=lx5chgaAgdOPvli+0CBF5+Ew5z+wgg476GwKIPLcYj5m4J6IJuab8J1TVxVImQ41Op oXeVqeLN8kCLhqQeS2zzvPqWbNFCYsFEHF961AxoBva7hLf3ybAhts3/HzOKiv9HOL1F GZJ7ggKWLMQZlFLqXF/p3xgspTwPuxbLgQqTeHuisEY8mXBHvc1kSoqqErqPrDoa4fN3 S06OOmENwkzmrbAUpd/0gnB1iX2gTEhgG4aIBZ4Lgq9bsTY61KPRddJRUe3abUHVTCvh qzDKBVZyX5ZodDapYzpWj/b7F4UZhSewPLB26hmobpyeaNKEJfwTKVTDfbQMdRxG9ezC 14cQ== X-Gm-Message-State: AOAM531TXDLcwZD6hS5vE2thJclanBrmaL/bvu1dHSeigAtiH9MRMYas rCV1zfRRjySOWYGMS8n7xjRQCzkLi5bzDw== X-Google-Smtp-Source: ABdhPJy3JpnToaWfrCjEpOpi7uYU4eOVdsOkcmAUkT2iwJ4tj7hoOQQyRD30gOSPkpEV9rvJZG8iuw== X-Received: by 2002:adf:ce82:: with SMTP id r2mr795876wrn.181.1610488394917; Tue, 12 Jan 2021 13:53:14 -0800 (PST) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Cc: Oleksandr Tyshchenko , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , George Dunlap , Ian Jackson , Julien Grall , Stefano Stabellini , Paul Durrant , Julien Grall Subject: [PATCH V4 21/24] xen/ioreq: Make x86's send_invalidate_req() common Date: Tue, 12 Jan 2021 23:52:29 +0200 Message-Id: <1610488352-18494-22-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1610488352-18494-1-git-send-email-olekstysh@gmail.com> References: <1610488352-18494-1-git-send-email-olekstysh@gmail.com> X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Oleksandr Tyshchenko As the IOREQ is a common feature now and we also need to invalidate qemu/demu mapcache on Arm when the required condition occurs this patch moves this function to the common code (and remames it to ioreq_signal_mapcache_invalidate). This patch also moves per-domain qemu_mapcache_invalidate variable out of the arch sub-struct (and drops "qemu" prefix). We don't put this variable inside the #ifdef CONFIG_IOREQ_SERVER at the end of struct domain, but in the hole next to the group of 5 bools further up which is more efficient. The subsequent patch will add mapcache invalidation handling on Arm. Signed-off-by: Oleksandr Tyshchenko CC: Julien Grall [On Arm only] Tested-by: Wei Chen Acked-by: Jan Beulich Reviewed-by: Paul Durrant --- Please note, this is a split/cleanup/hardening of Julien's PoC: "Add support for Guest IO forwarding to a device emulator" Changes RFC -> V1: - move send_invalidate_req() to the common code - update patch subject/description - move qemu_mapcache_invalidate out of the arch sub-struct, update checks - remove #if defined(CONFIG_ARM64) from the common code Changes V1 -> V2: - was split into: - xen/ioreq: Make x86's send_invalidate_req() common - xen/arm: Add mapcache invalidation handling - update patch description/subject - move Arm bits to a separate patch - don't alter the common code, the flag is set by arch code - rename send_invalidate_req() to send_invalidate_ioreq() - guard qemu_mapcache_invalidate with CONFIG_IOREQ_SERVER - use bool instead of bool_t - remove blank line blank line between head comment and #include-s Changes V2 -> V3: - update patch description - drop "qemu" prefix from the variable name - rename send_invalidate_req() to ioreq_signal_mapcache_invalidate() Changes V3 -> V4: - change variable location in struct domain --- xen/arch/x86/hvm/hypercall.c | 9 +++++---- xen/arch/x86/hvm/io.c | 14 -------------- xen/common/ioreq.c | 14 ++++++++++++++ xen/include/asm-x86/hvm/domain.h | 1 - xen/include/asm-x86/hvm/io.h | 1 - xen/include/xen/ioreq.h | 1 + xen/include/xen/sched.h | 5 +++++ 7 files changed, 25 insertions(+), 20 deletions(-) diff --git a/xen/arch/x86/hvm/hypercall.c b/xen/arch/x86/hvm/hypercall.c index ac573c8..6d41c56 100644 --- a/xen/arch/x86/hvm/hypercall.c +++ b/xen/arch/x86/hvm/hypercall.c @@ -20,6 +20,7 @@ */ #include #include +#include #include =20 #include @@ -47,7 +48,7 @@ static long hvm_memory_op(int cmd, XEN_GUEST_HANDLE_PARAM= (void) arg) rc =3D compat_memory_op(cmd, arg); =20 if ( (cmd & MEMOP_CMD_MASK) =3D=3D XENMEM_decrease_reservation ) - curr->domain->arch.hvm.qemu_mapcache_invalidate =3D true; + curr->domain->mapcache_invalidate =3D true; =20 return rc; } @@ -326,9 +327,9 @@ int hvm_hypercall(struct cpu_user_regs *regs) =20 HVM_DBG_LOG(DBG_LEVEL_HCALL, "hcall%lu -> %lx", eax, regs->rax); =20 - if ( unlikely(currd->arch.hvm.qemu_mapcache_invalidate) && - test_and_clear_bool(currd->arch.hvm.qemu_mapcache_invalidate) ) - send_invalidate_req(); + if ( unlikely(currd->mapcache_invalidate) && + test_and_clear_bool(currd->mapcache_invalidate) ) + ioreq_signal_mapcache_invalidate(); =20 return curr->hcall_preempted ? HVM_HCALL_preempted : HVM_HCALL_complet= ed; } diff --git a/xen/arch/x86/hvm/io.c b/xen/arch/x86/hvm/io.c index 66a37ee..046a8eb 100644 --- a/xen/arch/x86/hvm/io.c +++ b/xen/arch/x86/hvm/io.c @@ -64,20 +64,6 @@ void send_timeoffset_req(unsigned long timeoff) gprintk(XENLOG_ERR, "Unsuccessful timeoffset update\n"); } =20 -/* Ask ioemu mapcache to invalidate mappings. */ -void send_invalidate_req(void) -{ - ioreq_t p =3D { - .type =3D IOREQ_TYPE_INVALIDATE, - .size =3D 4, - .dir =3D IOREQ_WRITE, - .data =3D ~0UL, /* flush all */ - }; - - if ( ioreq_broadcast(&p, false) !=3D 0 ) - gprintk(XENLOG_ERR, "Unsuccessful map-cache invalidate\n"); -} - bool hvm_emulate_one_insn(hvm_emulate_validate_t *validate, const char *de= scr) { struct hvm_emulate_ctxt ctxt; diff --git a/xen/common/ioreq.c b/xen/common/ioreq.c index 59f4990..050891f 100644 --- a/xen/common/ioreq.c +++ b/xen/common/ioreq.c @@ -35,6 +35,20 @@ #include #include =20 +/* Ask ioemu mapcache to invalidate mappings. */ +void ioreq_signal_mapcache_invalidate(void) +{ + ioreq_t p =3D { + .type =3D IOREQ_TYPE_INVALIDATE, + .size =3D 4, + .dir =3D IOREQ_WRITE, + .data =3D ~0UL, /* flush all */ + }; + + if ( ioreq_broadcast(&p, false) !=3D 0 ) + gprintk(XENLOG_ERR, "Unsuccessful map-cache invalidate\n"); +} + static void set_ioreq_server(struct domain *d, unsigned int id, struct ioreq_server *s) { diff --git a/xen/include/asm-x86/hvm/domain.h b/xen/include/asm-x86/hvm/dom= ain.h index b8be1ad..cf959f6 100644 --- a/xen/include/asm-x86/hvm/domain.h +++ b/xen/include/asm-x86/hvm/domain.h @@ -122,7 +122,6 @@ struct hvm_domain { =20 struct viridian_domain *viridian; =20 - bool_t qemu_mapcache_invalidate; bool_t is_s3_suspended; =20 /* diff --git a/xen/include/asm-x86/hvm/io.h b/xen/include/asm-x86/hvm/io.h index fb64294..3da0136 100644 --- a/xen/include/asm-x86/hvm/io.h +++ b/xen/include/asm-x86/hvm/io.h @@ -97,7 +97,6 @@ bool relocate_portio_handler( unsigned int size); =20 void send_timeoffset_req(unsigned long timeoff); -void send_invalidate_req(void); bool handle_mmio_with_translation(unsigned long gla, unsigned long gpfn, struct npfec); bool handle_pio(uint16_t port, unsigned int size, int dir); diff --git a/xen/include/xen/ioreq.h b/xen/include/xen/ioreq.h index f0908af..dc47ec7 100644 --- a/xen/include/xen/ioreq.h +++ b/xen/include/xen/ioreq.h @@ -101,6 +101,7 @@ struct ioreq_server *ioreq_server_select(struct domain = *d, int ioreq_send(struct ioreq_server *s, ioreq_t *proto_p, bool buffered); unsigned int ioreq_broadcast(ioreq_t *p, bool buffered); +void ioreq_signal_mapcache_invalidate(void); =20 void ioreq_domain_init(struct domain *d); =20 diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 7aea2bb..5139b44 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -444,6 +444,11 @@ struct domain * unpaused for the first time by the systemcontroller. */ bool creation_finished; + /* + * Indicates that mapcache invalidation request should be sent to + * the device emulator. + */ + bool mapcache_invalidate; =20 /* Which guest this guest has privileges on */ struct domain *target; --=20 2.7.4