From nobody Sun May 19 05:00:04 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2FAD0CDB465 for ; Mon, 16 Oct 2023 07:11:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231805AbjJPHLw (ORCPT ); Mon, 16 Oct 2023 03:11:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229953AbjJPHLq (ORCPT ); Mon, 16 Oct 2023 03:11:46 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41CF4DC for ; Mon, 16 Oct 2023 00:11:45 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1bdf4752c3cso22695835ad.2 for ; Mon, 16 Oct 2023 00:11:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697440305; x=1698045105; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1YLGlADbqxnWAYarOFVSTI3AQVPhPYl3xWfz7Wse3mA=; b=tC4LY86rkiKKI7EWqWKJsM+GwVlT0koeey0qgnh+rLEx0ghY2KWqiaoXsmuQlR7Cer /w4edLT7YNscZrKIYirqOHJYjeeAjXU8pgeJGctnszKI5dmYBQ8alBTgjvVTf5rT2aAa FereKhnBmdGh5Bxl8Kr0re/2owSQrYwOHapsx0LMMwXzeoX/vdYNhmO3TvirB2OP7ZM1 thudmuzodLd010dITKY/2ldyztJ0cE/HzNmPD4URCDLleVVVG128nk+EXfhrS4kOAh1u OaM/LgHUnq/Oq38lFbTDwk1IO4CjscHjZicfjatgj+jC+b6bseDWUqHCSfMqhluQzmNH AACg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697440305; x=1698045105; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1YLGlADbqxnWAYarOFVSTI3AQVPhPYl3xWfz7Wse3mA=; b=uZD5xOn1MmgIl/sq+tk1Tr1SReVjOppHL5Cs7BDJtisIS+qoriHTdVHJY5njXxthEc i062f/ytUkkDjgZEktojl5xNLXUhSYMGChX06GTVDi/P2msXcdmvGAcRE0waQlU2Mou1 +gkysxOyAZ5gHrMTuD4Xjwxi0haiT6M8F3l08zE0e1+3jdIIFN28MWUfptD6SKxVu/HN Hfx0BOeHf2ep9WUseeSh3VmfoHuB9rGZMmdUSQdI8J9c0TIGV00hVWFo1bK/GtRJU3t3 Sq6klhWq95b/gWsdGAET18wR0w84J+zDmyy6olgxwSJ/ZWLHHPdWUd9P/dpa3tczCTk9 be9w== X-Gm-Message-State: AOJu0YwFoA0SgIF9JBAnp3tD3VZaeQLG4XiXQMEP8M6PbyT43D4X5W3l oXhdrNCobTXYchKpl9axhaopLg== X-Google-Smtp-Source: AGHT+IFiZfXVWLAwWVoc8OY1PxB2vC251spWed6E+sNY8zWNiPL3CrOKRidkLrTNfWcwaUPdKETYTg== X-Received: by 2002:a17:902:ec8c:b0:1c9:b187:4d84 with SMTP id x12-20020a170902ec8c00b001c9b1874d84mr18099691plg.14.1697440304700; Mon, 16 Oct 2023 00:11:44 -0700 (PDT) Received: from localhost ([122.172.80.14]) by smtp.gmail.com with ESMTPSA id o11-20020a170902778b00b001b9dab0397bsm7770391pll.29.2023.10.16.00.11.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 00:11:44 -0700 (PDT) From: Viresh Kumar To: Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , Viresh Kumar Cc: Vincent Guittot , =?UTF-8?q?Alex=20Benn=C3=A9e?= , stratos-dev@op-lists.linaro.org, Erik Schilling , Manos Pitsidianakis , Mathieu Poirier , Arnd Bergmann , xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Subject: [PATCH V4 1/4] xen: Make struct privcmd_irqfd's layout architecture independent Date: Mon, 16 Oct 2023 12:41:24 +0530 Message-Id: X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Using indirect pointers in an ioctl command argument means that the layout is architecture specific, in particular we can't use the same one from 32-bit compat tasks. The general recommendation is to have __u64 members and use u64_to_user_ptr() to access it from the kernel if we are unable to avoid the pointers altogether. Fixes: f8941e6c4c71 ("xen: privcmd: Add support for irqfd") Reported-by: Arnd Bergmann Closes: https://lore.kernel.org/all/268a2031-63b8-4c7d-b1e5-8ab83ca80b4a@ap= p.fastmail.com/ Signed-off-by: Viresh Kumar Reviewed-by: Juergen Gross --- drivers/xen/privcmd.c | 2 +- include/uapi/xen/privcmd.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c index 120af57999fc..5095bd1abea5 100644 --- a/drivers/xen/privcmd.c +++ b/drivers/xen/privcmd.c @@ -935,7 +935,7 @@ static int privcmd_irqfd_assign(struct privcmd_irqfd *i= rqfd) return -ENOMEM; dm_op =3D kirqfd + 1; =20 - if (copy_from_user(dm_op, irqfd->dm_op, irqfd->size)) { + if (copy_from_user(dm_op, u64_to_user_ptr(irqfd->dm_op), irqfd->size)) { ret =3D -EFAULT; goto error_kfree; } diff --git a/include/uapi/xen/privcmd.h b/include/uapi/xen/privcmd.h index 375718ba4ab6..b143fafce84d 100644 --- a/include/uapi/xen/privcmd.h +++ b/include/uapi/xen/privcmd.h @@ -102,7 +102,7 @@ struct privcmd_mmap_resource { #define PRIVCMD_IRQFD_FLAG_DEASSIGN (1 << 0) =20 struct privcmd_irqfd { - void __user *dm_op; + __u64 dm_op; __u32 size; /* Size of structure pointed by dm_op */ __u32 fd; __u32 flags; --=20 2.31.1.272.g89b43f80a514 From nobody Sun May 19 05:00:04 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4306CDB482 for ; Mon, 16 Oct 2023 07:11:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231842AbjJPHL4 (ORCPT ); Mon, 16 Oct 2023 03:11:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231526AbjJPHLu (ORCPT ); Mon, 16 Oct 2023 03:11:50 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EDBDDC for ; Mon, 16 Oct 2023 00:11:48 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6bd73395bceso732560b3a.0 for ; Mon, 16 Oct 2023 00:11:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697440308; x=1698045108; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=c/E6/GLx6ZozVsglJmVw75Y9W/GS8DVZN69OPx54uAk=; b=L+g2IeWtoN3jhZVNhuUIdbOznyrDE5yOrsbAhy2yRl9wwAgOn09n8z81MQ5VIATs5v TyHh8/EbOcyGaeT74LX4jzwu+MjE4MD7c2shGzhTjrfE5sh9xIXLcBfVpJQd2Xlh6b/f Rz4dFUKy3PESCZ0mPZcNsG5xRmN2t4tE+oXP5zIJ/e+HT5vUha4l9wVy7viLyr4QLAhV pHkGBb7ShcwQGySSEWsXiX45XhF/SExTZjeeeJ0AAhINAUaSjMvnug7RS5L2n7zxLqxb 0QXTUfelXHHjiVyb0AGdzWas/t8weeF69sVGoc+3UjdLDoEn9OVZdndOzAU0n9XOkWxl rWpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697440308; x=1698045108; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c/E6/GLx6ZozVsglJmVw75Y9W/GS8DVZN69OPx54uAk=; b=kZL70KhRCSAFDmNAKkGn+hLF6UL+0Zaxlei8NJxRIbyzaqTMfMHm4I3BTl9SigFNXq zSLVqkAVXb/sIEX2E5mwUS/Ys5de5xugupZk/OwIVFRmTyMxSBZvzBrkk1RkSjFKMd4y Gv257JlpTiBi7gfPpBYcCEuGeV28G02tfFulBBiLrigKDjcnsvSHbmIm7AFosrrCaS0O wXNhTLXELIBdlu7ZIrM3PjnYrdxqSl+Y0HdenZx0jxAYeUZgiGt7PlZ9U1k5xIneZ+sq 5kDuZLTlMedLl//1s7YNEzAkAR861t4dA4tCCsHpErUlhljQHDdoClfjMPLbW2i5eC1u 5T8Q== X-Gm-Message-State: AOJu0Yxh5gSnYdlklCV5WK4dc5USr3Ic1m4qMAKCI/Mmflb7aJTPQ6DG 1RZnyDgGARtuFXbBLltJN1cJPw== X-Google-Smtp-Source: AGHT+IE4MLkjnBefAElzY+bdBEEt2z+P5us27ZF3QfmSrVEbRNd3DDmAZ96JnRzreQ+qrlXMVJ0vpw== X-Received: by 2002:a05:6a00:1819:b0:68f:d44c:22f8 with SMTP id y25-20020a056a00181900b0068fd44c22f8mr10614696pfa.1.1697440307784; Mon, 16 Oct 2023 00:11:47 -0700 (PDT) Received: from localhost ([122.172.80.14]) by smtp.gmail.com with ESMTPSA id 4-20020aa79104000000b0069305627491sm17212825pfh.159.2023.10.16.00.11.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 00:11:47 -0700 (PDT) From: Viresh Kumar To: Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , Viresh Kumar Cc: Vincent Guittot , =?UTF-8?q?Alex=20Benn=C3=A9e?= , stratos-dev@op-lists.linaro.org, Erik Schilling , Manos Pitsidianakis , Mathieu Poirier , Arnd Bergmann , xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Subject: [PATCH V4 2/4] xen: irqfd: Use _IOW instead of the internal _IOC() macro Date: Mon, 16 Oct 2023 12:41:25 +0530 Message-Id: <599ca6f1b9dd2f0e6247ea37bee3ea6827404b6d.1697439990.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" _IOC() an internal helper that we should not use in driver code. In particular, we got the data direction wrong here, which breaks a number of tools, as having "_IOC_NONE" should never be paired with a nonzero size. Use _IOW() instead. Fixes: f8941e6c4c71 ("xen: privcmd: Add support for irqfd") Reported-by: Arnd Bergmann Closes: https://lore.kernel.org/all/268a2031-63b8-4c7d-b1e5-8ab83ca80b4a@ap= p.fastmail.com/ Signed-off-by: Viresh Kumar Reviewed-by: Juergen Gross --- include/uapi/xen/privcmd.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/uapi/xen/privcmd.h b/include/uapi/xen/privcmd.h index b143fafce84d..e145bca5105c 100644 --- a/include/uapi/xen/privcmd.h +++ b/include/uapi/xen/privcmd.h @@ -138,6 +138,6 @@ struct privcmd_irqfd { #define IOCTL_PRIVCMD_MMAP_RESOURCE \ _IOC(_IOC_NONE, 'P', 7, sizeof(struct privcmd_mmap_resource)) #define IOCTL_PRIVCMD_IRQFD \ - _IOC(_IOC_NONE, 'P', 8, sizeof(struct privcmd_irqfd)) + _IOW('P', 8, struct privcmd_irqfd) =20 #endif /* __LINUX_PUBLIC_PRIVCMD_H__ */ --=20 2.31.1.272.g89b43f80a514 From nobody Sun May 19 05:00:04 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6D84CDB465 for ; Mon, 16 Oct 2023 07:12:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231980AbjJPHL7 (ORCPT ); Mon, 16 Oct 2023 03:11:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231474AbjJPHLz (ORCPT ); Mon, 16 Oct 2023 03:11:55 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B99FED for ; Mon, 16 Oct 2023 00:11:51 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6b5cac99cfdso1668162b3a.2 for ; Mon, 16 Oct 2023 00:11:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697440311; x=1698045111; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VA2GT8eqbiQpihVq6IatV7jxO70qnqwP/ImeaPQmFQY=; b=c0cmlIbMULuVKRYc3sCOeVmPgo6C7gQDhRNtrKDRqAZWUQ7VbqG87GtMFKJY5i0Vt8 6dC0dZGkYmSUhdjj6pFswkJXL//WqtYSA1jVINPB9mbmLG2OhJCdgevaMGX9UBiqHJ1Q e0IMn8hKO7XxANbzCr48H9ZpF85nzgtR1iXsJDtrAw9x5fBXSzC04w1dGf4i0BHgRM0m ketFLUPdNqdrgx6M+FEHdphDegFZQfc0iZoH/ZcZsfp3Aho+JKNe0Kv6NfebmfIoN6Qu yoCpVuNRRrsol9DdRSJcD8fOfly4Auv9hhfnVyhbZsJ22fpimrY7yVKiRWcg+1gigM38 fNNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697440311; x=1698045111; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VA2GT8eqbiQpihVq6IatV7jxO70qnqwP/ImeaPQmFQY=; b=WHZdcwOLfpn+bSpQ7jexnOe3vOMoR4O6PTt14Xd5D/XHEUx0IsUsRZCKX5GKywdQ8u 1qNFWpk7YUIvbi4gH7xVXOHH6LTmyx3Lv1nvZIxPqmBIZIKRdHrCmGc/nKEp7rUljPxB HYuVVXVp5D6DWi1LgM0wBYzipaEcp8XWMpor887ey7LtwyZxXi2JpLoAdRqIqyIanis3 Cwdeq9522JIsUi54/UvxqFWQVbpnPuwoEi367lRWrbfRdcYe/qNhE/Xfvuy0UxzSK6Rn AMLDNZuNw34VfacIm682zIPllakhqq1m8pnle5RyiXy+0hPOY92S6vIl6mzeldPJFRl+ ugjQ== X-Gm-Message-State: AOJu0YzWkWbxPG+V+Axt6A3r4ih+Vj4Kt1RmcSOqdyJttx0Q7OyHLlrz 1Q+7+a59GJjuwG8U+IDtIIO9qQ== X-Google-Smtp-Source: AGHT+IG/g2mNU9z+9wRsIf1tsYOLUhccvghdEO7aXTxMy+dng7C4gaQ2AOy/3vVl1wB0/a7ioozUXg== X-Received: by 2002:a05:6a00:23ce:b0:68e:3f0b:5e6f with SMTP id g14-20020a056a0023ce00b0068e3f0b5e6fmr35005262pfc.24.1697440311003; Mon, 16 Oct 2023 00:11:51 -0700 (PDT) Received: from localhost ([122.172.80.14]) by smtp.gmail.com with ESMTPSA id k9-20020aa79729000000b006bd6a0a4678sm2187567pfg.80.2023.10.16.00.11.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 00:11:50 -0700 (PDT) From: Viresh Kumar To: Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko Cc: Viresh Kumar , Vincent Guittot , =?UTF-8?q?Alex=20Benn=C3=A9e?= , stratos-dev@op-lists.linaro.org, Erik Schilling , Manos Pitsidianakis , Mathieu Poirier , Arnd Bergmann , xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Subject: [PATCH V4 3/4] xen: evtchn: Allow shared registration of IRQ handers Date: Mon, 16 Oct 2023 12:41:26 +0530 Message-Id: <99b1edfd3147c6b5d22a5139dab5861e767dc34a.1697439990.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Currently the handling of events is supported either in the kernel or userspace, but not both. In order to support fast delivery of interrupts from the guest to the backend, we need to handle the Queue notify part of Virtio protocol in kernel and the rest in userspace. Update the interrupt handler registration flag to IRQF_SHARED for event channels, which would allow multiple entities to bind their interrupt handler for the same event channel port. Also increment the reference count of irq_info when multiple entities try to bind event channel to irqchip, so the unbinding happens only after all the users are gone. Signed-off-by: Viresh Kumar Reviewed-by: Juergen Gross --- drivers/xen/events/events_base.c | 3 ++- drivers/xen/evtchn.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_b= ase.c index c7715f8bd452..d72fb26cc051 100644 --- a/drivers/xen/events/events_base.c +++ b/drivers/xen/events/events_base.c @@ -1238,7 +1238,8 @@ static int bind_evtchn_to_irq_chip(evtchn_port_t evtc= hn, struct irq_chip *chip, bind_evtchn_to_cpu(evtchn, 0, false); } else { struct irq_info *info =3D info_for_irq(irq); - WARN_ON(info =3D=3D NULL || info->type !=3D IRQT_EVTCHN); + if (!WARN_ON(!info || info->type !=3D IRQT_EVTCHN)) + info->refcnt++; } =20 out: diff --git a/drivers/xen/evtchn.c b/drivers/xen/evtchn.c index c99415a70051..43f77915feb5 100644 --- a/drivers/xen/evtchn.c +++ b/drivers/xen/evtchn.c @@ -397,7 +397,7 @@ static int evtchn_bind_to_user(struct per_user_data *u,= evtchn_port_t port) if (rc < 0) goto err; =20 - rc =3D bind_evtchn_to_irqhandler_lateeoi(port, evtchn_interrupt, 0, + rc =3D bind_evtchn_to_irqhandler_lateeoi(port, evtchn_interrupt, IRQF_SHA= RED, u->name, evtchn); if (rc < 0) goto err; --=20 2.31.1.272.g89b43f80a514 From nobody Sun May 19 05:00:04 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1697440346; cv=none; d=zohomail.com; s=zohoarc; b=d57RXZ2CTfArJU7awmlCb/gsmCI5ntV1Cd2PZTjTZ45ohgvG1Hwklfs4OXfEVUVhiVhSvOYjglhhWjl6gjocB2/VcVUcJRLzsx/N9bV8WX/gTEwbnlETmanSsR39+MwCu6VMbqmBx+7P4tEQSxsV4DnjqoNMeJYUon7Lan1XINs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697440346; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=r48g5ldbE+VNNgtF7EF4RNcr/h91kprDVvs75p8vKSI=; b=aAhC8zhqn1WHQyhoiArSn9XRX367bWED1VtO4QGlI0NL8SINDywKWgT8QynvJAcHebmqSw5kj8Z9Owgkl4QOy7whcVhNSWUepuiASYy0GOx/h2ftaWD3up+8+cd2Kx6zzVEthAfwhwIbv9NYm4Rpj6zhyQ6PW+AzQbiaehQI9yk= 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) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1697440346655974.9630239631581; Mon, 16 Oct 2023 00:12:26 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.617263.959754 (Exim 4.92) (envelope-from ) id 1qsHlf-0003EF-2C; Mon, 16 Oct 2023 07:11:59 +0000 Received: by outflank-mailman (output) from mailman id 617263.959754; Mon, 16 Oct 2023 07:11:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qsHle-0003E6-VA; Mon, 16 Oct 2023 07:11:58 +0000 Received: by outflank-mailman (input) for mailman id 617263; Mon, 16 Oct 2023 07:11:57 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qsHld-00027t-81 for xen-devel@lists.xenproject.org; Mon, 16 Oct 2023 07:11:57 +0000 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [2607:f8b0:4864:20::42d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 49b61870-6bf3-11ee-98d4-6d05b1d4d9a1; Mon, 16 Oct 2023 09:11:56 +0200 (CEST) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-692c02adeefso2859800b3a.3 for ; Mon, 16 Oct 2023 00:11:56 -0700 (PDT) Received: from localhost ([122.172.80.14]) by smtp.gmail.com with ESMTPSA id v3-20020aa799c3000000b006934a1c69f8sm395088pfi.24.2023.10.16.00.11.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 00:11:54 -0700 (PDT) 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: 49b61870-6bf3-11ee-98d4-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697440315; x=1698045115; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=r48g5ldbE+VNNgtF7EF4RNcr/h91kprDVvs75p8vKSI=; b=Jo9CnEzQePUxs4UnCs4e73oE80EmWaRwplGxGIDPRwS022rFiwC2++jaZrO+tGaAQd Sp+aPk6vrYz5gKY5UksVBZMt7EqzGaD6xPWtJNdXK0am7iOXfp2x8rM/hhRZpB44YwUu jeS1Gxuwt81eF23fgpUYq31VixDpgXPTNapY/r+xl9PcLCqxkrFzoIj9EVaHW0RhwTkx +w9xLpOI9upKXpGvSuAoB/5mcN3YJ/OOAJaedyrXrsqA4essctv4CbgQJLJm1nUpos9w UZ1RIPVgcoG2wQiZpt4mJzH4L+5DOxrbeeql6Lzy3ou2jRVZ33kd8TvzlvK4K8k1rY1f 8ZfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697440315; x=1698045115; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=r48g5ldbE+VNNgtF7EF4RNcr/h91kprDVvs75p8vKSI=; b=TC5/eTrNlCCxMRIYN5RzOobZnn7qGfUSRzK+fxY+3aHz+XHAwSrQs+/+rtTqjGx15f /vGAeFaB9/4hy7h1DjT4NbI6sEwbIRHBoIHuBvYeJTOjQGd3H5xIRIVZVXU1XiuXqB54 csHQNgxgNsvhlKM/SyV2GDh0e0F9jKrwYiPZaUgccZj3p5Hy7zS3p6N94JOLTWqVsIyj W9DRufWLbehzRcRGfJXiw8X7VWveaCt6PuiTbZ5pI8vLfLRE/pt0acQeXcCIUvoQE36F FDdfNL71YsPFZW7+5Z0WiXD40wwBk0OYiwlX5cY6n9VXJboF9e2B7wJFpxaNwDBYeMi9 VWsA== X-Gm-Message-State: AOJu0YxnRE8wb8fqTYbtiEVjEuneCGtyttqp/ILDPU75YC2sGzwIH/UG qbINERbvLiqNBcT7wGF3x9MIWg== X-Google-Smtp-Source: AGHT+IHHB66MC7xOk5/qdWrNfLmijUWBRPM1EZhOtYwehRCFf1OuZEmS/MMv65bWMHlR1aOg1Du7lw== X-Received: by 2002:a05:6a00:23ca:b0:6be:4228:6970 with SMTP id g10-20020a056a0023ca00b006be42286970mr486317pfc.21.1697440314607; Mon, 16 Oct 2023 00:11:54 -0700 (PDT) From: Viresh Kumar To: Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko Cc: Viresh Kumar , Vincent Guittot , =?UTF-8?q?Alex=20Benn=C3=A9e?= , stratos-dev@op-lists.linaro.org, Erik Schilling , Manos Pitsidianakis , Mathieu Poirier , Arnd Bergmann , linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Subject: [PATCH V4 4/4] xen: privcmd: Add support for ioeventfd Date: Mon, 16 Oct 2023 12:41:27 +0530 Message-Id: X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1697440348163100001 Content-Type: text/plain; charset="utf-8" Virtio guests send VIRTIO_MMIO_QUEUE_NOTIFY notification when they need to notify the backend of an update to the status of the virtqueue. The backend or another entity, polls the MMIO address for updates to know when the notification is sent. It works well if the backend does this polling by itself. But as we move towards generic backend implementations, we end up implementing this in a separate user-space program. Generally, the Virtio backends are implemented to work with the Eventfd based mechanism. In order to make such backends work with Xen, another software layer needs to do the polling and send an event via eventfd to the backend once the notification from guest is received. This results in an extra context switch. This is not a new problem in Linux though. It is present with other hypervisors like KVM, etc. as well. The generic solution implemented in the kernel for them is to provide an IOCTL call to pass the address to poll and eventfd, which lets the kernel take care of polling and raise an event on the eventfd, instead of handling this in user space (which involves an extra context switch). This patch adds similar support for xen. Inspired by existing implementations for KVM, etc.. This also copies ioreq.h header file (only struct ioreq and related macros) from Xen's source tree (Top commit 5d84f07fe6bf ("xen/pci: drop remaining uses of bool_t")). Signed-off-by: Viresh Kumar Reviewed-by: Juergen Gross --- drivers/xen/Kconfig | 8 +- drivers/xen/privcmd.c | 405 +++++++++++++++++++++++++++++- include/uapi/xen/privcmd.h | 18 ++ include/xen/interface/hvm/ioreq.h | 51 ++++ 4 files changed, 476 insertions(+), 6 deletions(-) create mode 100644 include/xen/interface/hvm/ioreq.h diff --git a/drivers/xen/Kconfig b/drivers/xen/Kconfig index d43153fec18e..d5989871dd5d 100644 --- a/drivers/xen/Kconfig +++ b/drivers/xen/Kconfig @@ -269,12 +269,12 @@ config XEN_PRIVCMD disaggregated Xen setups this driver might be needed for other domains, too. =20 -config XEN_PRIVCMD_IRQFD - bool "Xen irqfd support" +config XEN_PRIVCMD_EVENTFD + bool "Xen Ioeventfd and irqfd support" depends on XEN_PRIVCMD && XEN_VIRTIO && EVENTFD help - Using the irqfd mechanism a virtio backend running in a daemon can - speed up interrupt injection into a guest. + Using the ioeventfd / irqfd mechanism a virtio backend running in a + daemon can speed up interrupt delivery from / to a guest. =20 config XEN_ACPI_PROCESSOR tristate "Xen ACPI processor" diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c index 5095bd1abea5..121e258077ea 100644 --- a/drivers/xen/privcmd.c +++ b/drivers/xen/privcmd.c @@ -29,15 +29,18 @@ #include #include #include +#include =20 #include #include =20 #include +#include #include #include #include #include +#include #include #include #include @@ -782,6 +785,7 @@ static long privcmd_ioctl_mmap_resource(struct file *fi= le, goto out; =20 pages =3D vma->vm_private_data; + for (i =3D 0; i < kdata.num; i++) { xen_pfn_t pfn =3D page_to_xen_pfn(pages[i / XEN_PFN_PER_PAGE]); @@ -838,7 +842,7 @@ static long privcmd_ioctl_mmap_resource(struct file *fi= le, return rc; } =20 -#ifdef CONFIG_XEN_PRIVCMD_IRQFD +#ifdef CONFIG_XEN_PRIVCMD_EVENTFD /* Irqfd support */ static struct workqueue_struct *irqfd_cleanup_wq; static DEFINE_MUTEX(irqfds_lock); @@ -1079,6 +1083,389 @@ static void privcmd_irqfd_exit(void) =20 destroy_workqueue(irqfd_cleanup_wq); } + +/* Ioeventfd Support */ +#define QUEUE_NOTIFY_VQ_MASK 0xFFFF + +static DEFINE_MUTEX(ioreq_lock); +static LIST_HEAD(ioreq_list); + +/* per-eventfd structure */ +struct privcmd_kernel_ioeventfd { + struct eventfd_ctx *eventfd; + struct list_head list; + u64 addr; + unsigned int addr_len; + unsigned int vq; +}; + +/* per-guest CPU / port structure */ +struct ioreq_port { + int vcpu; + unsigned int port; + struct privcmd_kernel_ioreq *kioreq; +}; + +/* per-guest structure */ +struct privcmd_kernel_ioreq { + domid_t dom; + unsigned int vcpus; + u64 uioreq; + struct ioreq *ioreq; + spinlock_t lock; /* Protects ioeventfds list */ + struct list_head ioeventfds; + struct list_head list; + struct ioreq_port ports[0]; +}; + +static irqreturn_t ioeventfd_interrupt(int irq, void *dev_id) +{ + struct ioreq_port *port =3D dev_id; + struct privcmd_kernel_ioreq *kioreq =3D port->kioreq; + struct ioreq *ioreq =3D &kioreq->ioreq[port->vcpu]; + struct privcmd_kernel_ioeventfd *kioeventfd; + unsigned int state =3D STATE_IOREQ_READY; + + if (ioreq->state !=3D STATE_IOREQ_READY || + ioreq->type !=3D IOREQ_TYPE_COPY || ioreq->dir !=3D IOREQ_WRITE) + return IRQ_NONE; + + /* + * We need a barrier, smp_mb(), here to ensure reads are finished before + * `state` is updated. Since the lock implementation ensures that + * appropriate barrier will be added anyway, we can avoid adding + * explicit barrier here. + * + * Ideally we don't need to update `state` within the locks, but we do + * that here to avoid adding explicit barrier. + */ + + spin_lock(&kioreq->lock); + ioreq->state =3D STATE_IOREQ_INPROCESS; + + list_for_each_entry(kioeventfd, &kioreq->ioeventfds, list) { + if (ioreq->addr =3D=3D kioeventfd->addr + VIRTIO_MMIO_QUEUE_NOTIFY && + ioreq->size =3D=3D kioeventfd->addr_len && + (ioreq->data & QUEUE_NOTIFY_VQ_MASK) =3D=3D kioeventfd->vq) { + eventfd_signal(kioeventfd->eventfd, 1); + state =3D STATE_IORESP_READY; + break; + } + } + spin_unlock(&kioreq->lock); + + /* + * We need a barrier, smp_mb(), here to ensure writes are finished + * before `state` is updated. Since the lock implementation ensures that + * appropriate barrier will be added anyway, we can avoid adding + * explicit barrier here. + */ + + ioreq->state =3D state; + + if (state =3D=3D STATE_IORESP_READY) { + notify_remote_via_evtchn(port->port); + return IRQ_HANDLED; + } + + return IRQ_NONE; +} + +static void ioreq_free(struct privcmd_kernel_ioreq *kioreq) +{ + struct ioreq_port *ports =3D kioreq->ports; + int i; + + lockdep_assert_held(&ioreq_lock); + + list_del(&kioreq->list); + + for (i =3D kioreq->vcpus - 1; i >=3D 0; i--) + unbind_from_irqhandler(irq_from_evtchn(ports[i].port), &ports[i]); + + kfree(kioreq); +} + +static +struct privcmd_kernel_ioreq *alloc_ioreq(struct privcmd_ioeventfd *ioevent= fd) +{ + struct privcmd_kernel_ioreq *kioreq; + struct mm_struct *mm =3D current->mm; + struct vm_area_struct *vma; + struct page **pages; + unsigned int *ports; + int ret, size, i; + + lockdep_assert_held(&ioreq_lock); + + size =3D struct_size(kioreq, ports, ioeventfd->vcpus); + kioreq =3D kzalloc(size, GFP_KERNEL); + if (!kioreq) + return ERR_PTR(-ENOMEM); + + kioreq->dom =3D ioeventfd->dom; + kioreq->vcpus =3D ioeventfd->vcpus; + kioreq->uioreq =3D ioeventfd->ioreq; + spin_lock_init(&kioreq->lock); + INIT_LIST_HEAD(&kioreq->ioeventfds); + + /* The memory for ioreq server must have been mapped earlier */ + mmap_write_lock(mm); + vma =3D find_vma(mm, (unsigned long)ioeventfd->ioreq); + if (!vma) { + pr_err("Failed to find vma for ioreq page!\n"); + mmap_write_unlock(mm); + ret =3D -EFAULT; + goto error_kfree; + } + + pages =3D vma->vm_private_data; + kioreq->ioreq =3D (struct ioreq *)(page_to_virt(pages[0])); + mmap_write_unlock(mm); + + size =3D sizeof(*ports) * kioreq->vcpus; + ports =3D kzalloc(size, GFP_KERNEL); + if (!ports) { + ret =3D -ENOMEM; + goto error_kfree; + } + + if (copy_from_user(ports, u64_to_user_ptr(ioeventfd->ports), size)) { + ret =3D -EFAULT; + goto error_kfree_ports; + } + + for (i =3D 0; i < kioreq->vcpus; i++) { + kioreq->ports[i].vcpu =3D i; + kioreq->ports[i].port =3D ports[i]; + kioreq->ports[i].kioreq =3D kioreq; + + ret =3D bind_evtchn_to_irqhandler_lateeoi(ports[i], + ioeventfd_interrupt, IRQF_SHARED, "ioeventfd", + &kioreq->ports[i]); + if (ret < 0) + goto error_unbind; + } + + kfree(ports); + + list_add_tail(&kioreq->list, &ioreq_list); + + return kioreq; + +error_unbind: + while (--i >=3D 0) + unbind_from_irqhandler(irq_from_evtchn(ports[i]), &kioreq->ports[i]); +error_kfree_ports: + kfree(ports); +error_kfree: + kfree(kioreq); + return ERR_PTR(ret); +} + +static struct privcmd_kernel_ioreq * +get_ioreq(struct privcmd_ioeventfd *ioeventfd, struct eventfd_ctx *eventfd) +{ + struct privcmd_kernel_ioreq *kioreq; + unsigned long flags; + + list_for_each_entry(kioreq, &ioreq_list, list) { + struct privcmd_kernel_ioeventfd *kioeventfd; + + /* + * kioreq fields can be accessed here without a lock as they are + * never updated after being added to the ioreq_list. + */ + if (kioreq->uioreq !=3D ioeventfd->ioreq) { + continue; + } else if (kioreq->dom !=3D ioeventfd->dom || + kioreq->vcpus !=3D ioeventfd->vcpus) { + pr_err("Invalid ioeventfd configuration mismatch, dom (%u vs %u), vcpus= (%u vs %u)\n", + kioreq->dom, ioeventfd->dom, kioreq->vcpus, + ioeventfd->vcpus); + return ERR_PTR(-EINVAL); + } + + /* Look for a duplicate eventfd for the same guest */ + spin_lock_irqsave(&kioreq->lock, flags); + list_for_each_entry(kioeventfd, &kioreq->ioeventfds, list) { + if (eventfd =3D=3D kioeventfd->eventfd) { + spin_unlock_irqrestore(&kioreq->lock, flags); + return ERR_PTR(-EBUSY); + } + } + spin_unlock_irqrestore(&kioreq->lock, flags); + + return kioreq; + } + + /* Matching kioreq isn't found, allocate a new one */ + return alloc_ioreq(ioeventfd); +} + +static void ioeventfd_free(struct privcmd_kernel_ioeventfd *kioeventfd) +{ + list_del(&kioeventfd->list); + eventfd_ctx_put(kioeventfd->eventfd); + kfree(kioeventfd); +} + +static int privcmd_ioeventfd_assign(struct privcmd_ioeventfd *ioeventfd) +{ + struct privcmd_kernel_ioeventfd *kioeventfd; + struct privcmd_kernel_ioreq *kioreq; + unsigned long flags; + struct fd f; + int ret; + + /* Check for range overflow */ + if (ioeventfd->addr + ioeventfd->addr_len < ioeventfd->addr) + return -EINVAL; + + /* Vhost requires us to support length 1, 2, 4, and 8 */ + if (!(ioeventfd->addr_len =3D=3D 1 || ioeventfd->addr_len =3D=3D 2 || + ioeventfd->addr_len =3D=3D 4 || ioeventfd->addr_len =3D=3D 8)) + return -EINVAL; + + /* 4096 vcpus limit enough ? */ + if (!ioeventfd->vcpus || ioeventfd->vcpus > 4096) + return -EINVAL; + + kioeventfd =3D kzalloc(sizeof(*kioeventfd), GFP_KERNEL); + if (!kioeventfd) + return -ENOMEM; + + f =3D fdget(ioeventfd->event_fd); + if (!f.file) { + ret =3D -EBADF; + goto error_kfree; + } + + kioeventfd->eventfd =3D eventfd_ctx_fileget(f.file); + fdput(f); + + if (IS_ERR(kioeventfd->eventfd)) { + ret =3D PTR_ERR(kioeventfd->eventfd); + goto error_kfree; + } + + kioeventfd->addr =3D ioeventfd->addr; + kioeventfd->addr_len =3D ioeventfd->addr_len; + kioeventfd->vq =3D ioeventfd->vq; + + mutex_lock(&ioreq_lock); + kioreq =3D get_ioreq(ioeventfd, kioeventfd->eventfd); + if (IS_ERR(kioreq)) { + mutex_unlock(&ioreq_lock); + ret =3D PTR_ERR(kioreq); + goto error_eventfd; + } + + spin_lock_irqsave(&kioreq->lock, flags); + list_add_tail(&kioeventfd->list, &kioreq->ioeventfds); + spin_unlock_irqrestore(&kioreq->lock, flags); + + mutex_unlock(&ioreq_lock); + + return 0; + +error_eventfd: + eventfd_ctx_put(kioeventfd->eventfd); + +error_kfree: + kfree(kioeventfd); + return ret; +} + +static int privcmd_ioeventfd_deassign(struct privcmd_ioeventfd *ioeventfd) +{ + struct privcmd_kernel_ioreq *kioreq, *tkioreq; + struct eventfd_ctx *eventfd; + unsigned long flags; + int ret =3D 0; + + eventfd =3D eventfd_ctx_fdget(ioeventfd->event_fd); + if (IS_ERR(eventfd)) + return PTR_ERR(eventfd); + + mutex_lock(&ioreq_lock); + list_for_each_entry_safe(kioreq, tkioreq, &ioreq_list, list) { + struct privcmd_kernel_ioeventfd *kioeventfd, *tmp; + /* + * kioreq fields can be accessed here without a lock as they are + * never updated after being added to the ioreq_list. + */ + if (kioreq->dom !=3D ioeventfd->dom || + kioreq->uioreq !=3D ioeventfd->ioreq || + kioreq->vcpus !=3D ioeventfd->vcpus) + continue; + + spin_lock_irqsave(&kioreq->lock, flags); + list_for_each_entry_safe(kioeventfd, tmp, &kioreq->ioeventfds, list) { + if (eventfd =3D=3D kioeventfd->eventfd) { + ioeventfd_free(kioeventfd); + spin_unlock_irqrestore(&kioreq->lock, flags); + + if (list_empty(&kioreq->ioeventfds)) + ioreq_free(kioreq); + goto unlock; + } + } + spin_unlock_irqrestore(&kioreq->lock, flags); + break; + } + + pr_err("Ioeventfd isn't already assigned, dom: %u, addr: %llu\n", + ioeventfd->dom, ioeventfd->addr); + ret =3D -ENODEV; + +unlock: + mutex_unlock(&ioreq_lock); + eventfd_ctx_put(eventfd); + + return ret; +} + +static long privcmd_ioctl_ioeventfd(struct file *file, void __user *udata) +{ + struct privcmd_data *data =3D file->private_data; + struct privcmd_ioeventfd ioeventfd; + + if (copy_from_user(&ioeventfd, udata, sizeof(ioeventfd))) + return -EFAULT; + + /* No other flags should be set */ + if (ioeventfd.flags & ~PRIVCMD_IOEVENTFD_FLAG_DEASSIGN) + return -EINVAL; + + /* If restriction is in place, check the domid matches */ + if (data->domid !=3D DOMID_INVALID && data->domid !=3D ioeventfd.dom) + return -EPERM; + + if (ioeventfd.flags & PRIVCMD_IOEVENTFD_FLAG_DEASSIGN) + return privcmd_ioeventfd_deassign(&ioeventfd); + + return privcmd_ioeventfd_assign(&ioeventfd); +} + +static void privcmd_ioeventfd_exit(void) +{ + struct privcmd_kernel_ioreq *kioreq, *tmp; + unsigned long flags; + + mutex_lock(&ioreq_lock); + list_for_each_entry_safe(kioreq, tmp, &ioreq_list, list) { + struct privcmd_kernel_ioeventfd *kioeventfd, *tmp; + + spin_lock_irqsave(&kioreq->lock, flags); + list_for_each_entry_safe(kioeventfd, tmp, &kioreq->ioeventfds, list) + ioeventfd_free(kioeventfd); + spin_unlock_irqrestore(&kioreq->lock, flags); + + ioreq_free(kioreq); + } + mutex_unlock(&ioreq_lock); +} #else static inline long privcmd_ioctl_irqfd(struct file *file, void __user *uda= ta) { @@ -1093,7 +1480,16 @@ static inline int privcmd_irqfd_init(void) static inline void privcmd_irqfd_exit(void) { } -#endif /* CONFIG_XEN_PRIVCMD_IRQFD */ + +static inline long privcmd_ioctl_ioeventfd(struct file *file, void __user = *udata) +{ + return -EOPNOTSUPP; +} + +static inline void privcmd_ioeventfd_exit(void) +{ +} +#endif /* CONFIG_XEN_PRIVCMD_EVENTFD */ =20 static long privcmd_ioctl(struct file *file, unsigned int cmd, unsigned long data) @@ -1134,6 +1530,10 @@ static long privcmd_ioctl(struct file *file, ret =3D privcmd_ioctl_irqfd(file, udata); break; =20 + case IOCTL_PRIVCMD_IOEVENTFD: + ret =3D privcmd_ioctl_ioeventfd(file, udata); + break; + default: break; } @@ -1278,6 +1678,7 @@ static int __init privcmd_init(void) =20 static void __exit privcmd_exit(void) { + privcmd_ioeventfd_exit(); privcmd_irqfd_exit(); misc_deregister(&privcmd_dev); misc_deregister(&xen_privcmdbuf_dev); diff --git a/include/uapi/xen/privcmd.h b/include/uapi/xen/privcmd.h index e145bca5105c..8b8c5d1420fe 100644 --- a/include/uapi/xen/privcmd.h +++ b/include/uapi/xen/privcmd.h @@ -110,6 +110,22 @@ struct privcmd_irqfd { __u8 pad[2]; }; =20 +/* For privcmd_ioeventfd::flags */ +#define PRIVCMD_IOEVENTFD_FLAG_DEASSIGN (1 << 0) + +struct privcmd_ioeventfd { + __u64 ioreq; + __u64 ports; + __u64 addr; + __u32 addr_len; + __u32 event_fd; + __u32 vcpus; + __u32 vq; + __u32 flags; + domid_t dom; + __u8 pad[2]; +}; + /* * @cmd: IOCTL_PRIVCMD_HYPERCALL * @arg: &privcmd_hypercall_t @@ -139,5 +155,7 @@ struct privcmd_irqfd { _IOC(_IOC_NONE, 'P', 7, sizeof(struct privcmd_mmap_resource)) #define IOCTL_PRIVCMD_IRQFD \ _IOW('P', 8, struct privcmd_irqfd) +#define IOCTL_PRIVCMD_IOEVENTFD \ + _IOW('P', 9, struct privcmd_ioeventfd) =20 #endif /* __LINUX_PUBLIC_PRIVCMD_H__ */ diff --git a/include/xen/interface/hvm/ioreq.h b/include/xen/interface/hvm/= ioreq.h new file mode 100644 index 000000000000..b02cfeae7eb5 --- /dev/null +++ b/include/xen/interface/hvm/ioreq.h @@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: MIT */ +/* + * ioreq.h: I/O request definitions for device models + * Copyright (c) 2004, Intel Corporation. + */ + +#ifndef __XEN_PUBLIC_HVM_IOREQ_H__ +#define __XEN_PUBLIC_HVM_IOREQ_H__ + +#define IOREQ_READ 1 +#define IOREQ_WRITE 0 + +#define STATE_IOREQ_NONE 0 +#define STATE_IOREQ_READY 1 +#define STATE_IOREQ_INPROCESS 2 +#define STATE_IORESP_READY 3 + +#define IOREQ_TYPE_PIO 0 /* pio */ +#define IOREQ_TYPE_COPY 1 /* mmio ops */ +#define IOREQ_TYPE_PCI_CONFIG 2 +#define IOREQ_TYPE_TIMEOFFSET 7 +#define IOREQ_TYPE_INVALIDATE 8 /* mapcache */ + +/* + * VMExit dispatcher should cooperate with instruction decoder to + * prepare this structure and notify service OS and DM by sending + * virq. + * + * For I/O type IOREQ_TYPE_PCI_CONFIG, the physical address is formatted + * as follows: + * + * 63....48|47..40|39..35|34..32|31........0 + * SEGMENT |BUS |DEV |FN |OFFSET + */ +struct ioreq { + uint64_t addr; /* physical address */ + uint64_t data; /* data (or paddr of data) */ + uint32_t count; /* for rep prefixes */ + uint32_t size; /* size in bytes */ + uint32_t vp_eport; /* evtchn for notifications to/from device model = */ + uint16_t _pad0; + uint8_t state:4; + uint8_t data_is_ptr:1; /* if 1, data above is the guest paddr + * of the real data to use. */ + uint8_t dir:1; /* 1=3Dread, 0=3Dwrite */ + uint8_t df:1; + uint8_t _pad1:1; + uint8_t type; /* I/O type */ +}; + +#endif /* __XEN_PUBLIC_HVM_IOREQ_H__ */ --=20 2.31.1.272.g89b43f80a514