From nobody Mon Feb 9 07:06:00 2026 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=1611601776; cv=none; d=zohomail.com; s=zohoarc; b=Vl4ZzTIwdFBwQ4eqzRN0/cLzQhMOV4EuP383oBWE8JdEZVVzG+tk1BdY/SxeMT1C4haIQDTZC0AVujyOyd+VxjSsFKqA1C9Ia7V+Y2uhGHI6p+Ge+54su8hdsSzrVMNPSGIsfBNpbV/dOs2Ro3WIfHLAH+eElZ3JrifLSXRByuU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611601776; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BoY0i+xc8eGVnOTYuk/xVaKxY5o/2NyqxPbuZ81MBYw=; b=aREqfAHvmIKptt4TKq3upiP1mtBSp/c8206Bqi3GBwVK69kMIMT4icUKPpAK7PuVx842opjNaTzvl8U2mfDkPIEX48/lctGCTeuNzNcURHDuLdxvnv/cM7MMZ/v+ySIvPTZrQEl3BqkJenjStbrKw6/aHJYV+r3XHnPCmD7IDH0= 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 161160177623179.9868813294778; Mon, 25 Jan 2021 11:09:36 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.74301.133561 (Exim 4.92) (envelope-from ) id 1l47Eo-0000JA-8K; Mon, 25 Jan 2021 19:09:22 +0000 Received: by outflank-mailman (output) from mailman id 74301.133561; Mon, 25 Jan 2021 19:09:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l47Eo-0000Iy-3P; Mon, 25 Jan 2021 19:09:22 +0000 Received: by outflank-mailman (input) for mailman id 74301; Mon, 25 Jan 2021 19:09:20 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l47Em-0008N7-GT for xen-devel@lists.xenproject.org; Mon, 25 Jan 2021 19:09:20 +0000 Received: from mail-wr1-x42a.google.com (unknown [2a00:1450:4864:20::42a]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b347190a-9f79-4f28-9d72-0066c8359a55; Mon, 25 Jan 2021 19:08:59 +0000 (UTC) Received: by mail-wr1-x42a.google.com with SMTP id l12so14101918wry.2 for ; Mon, 25 Jan 2021 11:08:59 -0800 (PST) Received: from otyshchenko.www.tendawifi.com ([212.22.223.21]) by smtp.gmail.com with ESMTPSA id k6sm12991031wro.27.2021.01.25.11.08.57 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Jan 2021 11:08:58 -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: b347190a-9f79-4f28-9d72-0066c8359a55 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=BoY0i+xc8eGVnOTYuk/xVaKxY5o/2NyqxPbuZ81MBYw=; b=s1nla7VbneAaYxYlqA3tdXVAWfBiEpsHuGdiKzAwNTq5bna17/7bD2ZtSNUcdRy8yr NbE0SQVcbT4WUe6jxii3Vs8PKrQ5FzpvTFprqw1jzZSkwD27FfVXe+UmoNTkA1AD3SPl PvAqFfHqC/Ru0uw+vSkZv4TAi8NpAXNxFXmJNReGMFrUPjtNDi5G0F8mSPCT9LAdQpcb mJHANrNo6/xZcKzxZEFG265rbB7EtC0EMCzd1rwKeBfEOVDh9h1s3s66Hi92M7k+q4d/ HRt5UmUunhmJ7QLj/j0tC268oh50D22Gbrw5nir80ieqKBg9tj8K6+cKr5XE6wA7OyED D4cA== 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=BoY0i+xc8eGVnOTYuk/xVaKxY5o/2NyqxPbuZ81MBYw=; b=W/NSNuIdj7KtOC8T1ntvh8CP0pj5ZHgZoGXbu3QRVhy3NWXZUPk9ylw0Y4BjsxPYOi tb2N6uzygTOgsdjlUMfbYGq8pkI8R/4dmQh07EMbHXtWcsH1Nb0P2nkl4P2SZpHDiZRi uukgrpq2msRma/5BAZ+Nfe6zib9/edY23YhLCdrJN/xLh3z5Qy9c5GFA+O6/vTmdPU9I 7KOd2tfw/CphO2BHm9jekktzc38iR66udytY7SkIenwTI2NjclAAanmtxLm84J+eFmM4 NazyVAKVO2T8jbMLw4CaFv/kShCVCDsr/ezzIjp7JtlXnfJ+BzmN8oXZ1LZh1y8LXDhg /F/A== X-Gm-Message-State: AOAM530SaKKncY+BQaeLxBNAJbMA9v39DmqdwNRbMAkv6B2zhCygG1i2 V+IM38HhtruqGzgbh/6YF0c886KVDH0fpg== X-Google-Smtp-Source: ABdhPJyiSLRJ6NSIB7W89yFmbKIMy676yPxZocuTupN4lW46MeIWve2sPqz817trNF65a6GbuwuNpg== X-Received: by 2002:a5d:452f:: with SMTP id j15mr2598185wra.298.1611601738986; Mon, 25 Jan 2021 11:08:58 -0800 (PST) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Cc: Oleksandr Tyshchenko , Paul Durrant , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Stefano Stabellini , Julien Grall , Julien Grall Subject: [PATCH V5 06/22] xen/ioreq: Make x86's hvm_mmio_first(last)_byte() common Date: Mon, 25 Jan 2021 21:08:13 +0200 Message-Id: <1611601709-28361-7-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1611601709-28361-1-git-send-email-olekstysh@gmail.com> References: <1611601709-28361-1-git-send-email-olekstysh@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) From: Oleksandr Tyshchenko The IOREQ is a common feature now and these helpers will be used on Arm as is. Move them to xen/ioreq.h and replace "hvm" prefixes with "ioreq". Signed-off-by: Oleksandr Tyshchenko Reviewed-by: Paul Durrant Acked-by: Jan Beulich Reviewed-by: Julien Grall Reviewed-by: Alex Benn=C3=A9e CC: Julien Grall [On Arm only] Tested-by: Wei Chen --- 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: - new patch Changes V1 -> V2: - replace "hvm" prefix by "ioreq" Changes V2 -> V3: - add Paul's R-b Changes V3 -> V4: - add Jan's A-b Changes V4 -> V5: - rebase - add Julien's and Alex's R-b --- --- xen/arch/x86/hvm/intercept.c | 5 +++-- xen/arch/x86/hvm/stdvga.c | 4 ++-- xen/common/ioreq.c | 4 ++-- xen/include/asm-x86/hvm/io.h | 16 ---------------- xen/include/xen/ioreq.h | 16 ++++++++++++++++ 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/xen/arch/x86/hvm/intercept.c b/xen/arch/x86/hvm/intercept.c index cd4c4c1..02ca3b0 100644 --- a/xen/arch/x86/hvm/intercept.c +++ b/xen/arch/x86/hvm/intercept.c @@ -17,6 +17,7 @@ * this program; If not, see . */ =20 +#include #include #include #include @@ -34,7 +35,7 @@ static bool_t hvm_mmio_accept(const struct hvm_io_handler *handler, const ioreq_t *p) { - paddr_t first =3D hvm_mmio_first_byte(p), last; + paddr_t first =3D ioreq_mmio_first_byte(p), last; =20 BUG_ON(handler->type !=3D IOREQ_TYPE_COPY); =20 @@ -42,7 +43,7 @@ static bool_t hvm_mmio_accept(const struct hvm_io_handler= *handler, return 0; =20 /* Make sure the handler will accept the whole access. */ - last =3D hvm_mmio_last_byte(p); + last =3D ioreq_mmio_last_byte(p); if ( last !=3D first && !handler->mmio.ops->check(current, last) ) domain_crash(current->domain); diff --git a/xen/arch/x86/hvm/stdvga.c b/xen/arch/x86/hvm/stdvga.c index fd7cadb..17dee74 100644 --- a/xen/arch/x86/hvm/stdvga.c +++ b/xen/arch/x86/hvm/stdvga.c @@ -524,8 +524,8 @@ static bool_t stdvga_mem_accept(const struct hvm_io_han= dler *handler, * deadlock when hvm_mmio_internal() is called from * hvm_copy_to/from_guest_phys() in hvm_process_io_intercept(). */ - if ( (hvm_mmio_first_byte(p) < VGA_MEM_BASE) || - (hvm_mmio_last_byte(p) >=3D (VGA_MEM_BASE + VGA_MEM_SIZE)) ) + if ( (ioreq_mmio_first_byte(p) < VGA_MEM_BASE) || + (ioreq_mmio_last_byte(p) >=3D (VGA_MEM_BASE + VGA_MEM_SIZE)) ) return 0; =20 spin_lock(&s->lock); diff --git a/xen/common/ioreq.c b/xen/common/ioreq.c index 61ddd54..89e75ff 100644 --- a/xen/common/ioreq.c +++ b/xen/common/ioreq.c @@ -1078,8 +1078,8 @@ struct hvm_ioreq_server *hvm_select_ioreq_server(stru= ct domain *d, break; =20 case XEN_DMOP_IO_RANGE_MEMORY: - start =3D hvm_mmio_first_byte(p); - end =3D hvm_mmio_last_byte(p); + start =3D ioreq_mmio_first_byte(p); + end =3D ioreq_mmio_last_byte(p); =20 if ( rangeset_contains_range(r, start, end) ) return s; diff --git a/xen/include/asm-x86/hvm/io.h b/xen/include/asm-x86/hvm/io.h index 9453b9b..6bc80db 100644 --- a/xen/include/asm-x86/hvm/io.h +++ b/xen/include/asm-x86/hvm/io.h @@ -40,22 +40,6 @@ struct hvm_mmio_ops { hvm_mmio_write_t write; }; =20 -static inline paddr_t hvm_mmio_first_byte(const ioreq_t *p) -{ - return unlikely(p->df) ? - p->addr - (p->count - 1ul) * p->size : - p->addr; -} - -static inline paddr_t hvm_mmio_last_byte(const ioreq_t *p) -{ - unsigned long size =3D p->size; - - return unlikely(p->df) ? - p->addr + size - 1: - p->addr + (p->count * size) - 1; -} - typedef int (*portio_action_t)( int dir, unsigned int port, unsigned int bytes, uint32_t *val); =20 diff --git a/xen/include/xen/ioreq.h b/xen/include/xen/ioreq.h index e957b52..6853aa3 100644 --- a/xen/include/xen/ioreq.h +++ b/xen/include/xen/ioreq.h @@ -23,6 +23,22 @@ =20 #include =20 +static inline paddr_t ioreq_mmio_first_byte(const ioreq_t *p) +{ + return unlikely(p->df) ? + p->addr - (p->count - 1ul) * p->size : + p->addr; +} + +static inline paddr_t ioreq_mmio_last_byte(const ioreq_t *p) +{ + unsigned long size =3D p->size; + + return unlikely(p->df) ? + p->addr + size - 1: + p->addr + (p->count * size) - 1; +} + static inline bool ioreq_needs_completion(const ioreq_t *ioreq) { return ioreq->state =3D=3D STATE_IOREQ_READY && --=20 2.7.4