Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp1527663pxb; Sat, 23 Apr 2022 09:04:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+jEQOtCYJZPPJngLQ/8T+nndSzA7GbCa+Qc/kaZ8L8GyoQDSAPSpOJItXZyYb9yZQ5MWU X-Received: by 2002:a17:902:f787:b0:152:157:eb7 with SMTP id q7-20020a170902f78700b0015201570eb7mr9721888pln.109.1650729870642; Sat, 23 Apr 2022 09:04:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650729870; cv=none; d=google.com; s=arc-20160816; b=nVXx7UZN6gt0x8ZdEdUG4tlHgcOHWeS86UHEsUfFB8yF1VFBmFYca2fuxuGkfmwK7k IlVbZBWgagN21VhWn6xehdgpAhHTaEC5Jz8pPNBrpv9keRveCKw9KR0ptbc8KUl5eLcu nq4vzdWbZlz28tHFFeoALXoxlMb1WPphmHHP9kqjotxM/A/xeuw3VHMQ2wMIqwITFyBi U7YOMPfc0ie6sEnKe80aZdbH0Ao8NaPoMx5U1kJwaXryKkN+mg7uDFAHkBaxiCJY9Ti8 fVh5627p/YhPYNyQSxHJx/3H116QSnn7j6wZh30Td3+V5gJx6wEqBM+90ePrsrNRIjUM oVFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=IrpG+O4O8YGPLjnEW6ym2q9Ak0YBISr2l1Uzmevi7UU=; b=Fq/fFTCnlGXQN9r+uRzV6tFpPdU8fxSl40Y46TMSAi14Ey7+D5wB4Pmn4vwZPSWElO Z2j+34ROJ2U1XykonbNY/uTIZiHSZTTWz/XXg758qMi5nXBmH7gT6U+MQnlgeAHy5inM kb6df2BgqHUuvVb5h8yjjB5NDpY657hS2cKZFE8lmGMBSDuHLfXlhRaCH7cU23oYoUp9 Ok4r250G0GOPyFmK7X30rVCjbA7d2KoEJFJunSUNo9FtOjfTRvnSC8+9vzzw0nVKiDnf Cja3SHMX3dppzogUuq7hxsxfnM/hM1q9XTWuxeW96Z1Tm6jSWIMFJJ0i3UeAyuE1Nz4J u/HQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=IQIfElwQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d26-20020a630e1a000000b0039db9cfb7bdsi12028574pgl.735.2022.04.23.09.04.14; Sat, 23 Apr 2022 09:04:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=IQIfElwQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233035AbiDWP0Z (ORCPT + 99 others); Sat, 23 Apr 2022 11:26:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232983AbiDWP0X (ORCPT ); Sat, 23 Apr 2022 11:26:23 -0400 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E29D36304 for ; Sat, 23 Apr 2022 08:23:23 -0700 (PDT) Received: by mail-lj1-x229.google.com with SMTP id l19so289425ljb.7 for ; Sat, 23 Apr 2022 08:23:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=IrpG+O4O8YGPLjnEW6ym2q9Ak0YBISr2l1Uzmevi7UU=; b=IQIfElwQ6vipgSII8m7fw6jPT7ARLMUo+GYVfI8Knl2qwcFVEEhcFvD8Om4SSjKAx2 rhHWD/FD4idPYpw6gGmafqjLSO6s5PnKgRub3B+6obIRWzQnvSBJtyJQi3yrabfM/3YH nyMF8uDK1IRSsUIm9AaGjRtkUTA84vsuNJIwUvyB4GNP5y1x7sQZT+c8y4qqZ/6mHAet nubs7NGVFobqf7TGI1y4TrUGgxgSag+RI8iLIe9SEJTQyV0518eyYpKVLK3gEmGFlfzs i97+MmHFuoXsYprc+xZO4DAi1h+VcMtO3Ecc7KkUECH8yT0sSemR7hzD5vvLn3BlyJFZ JNuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=IrpG+O4O8YGPLjnEW6ym2q9Ak0YBISr2l1Uzmevi7UU=; b=Boxa8PKIiWQScriew/uQDYXv4ui3iyIZ8aSX2pcgk7LfIjvtmts8u+cKeTd0meYw6I UqAFGyMJG+kwZWKnjgy/2JNZ+llPWnZsvAKoG1KLFJYqeNMrBmWCv626wIIpIsJZk+gk GymO+rlQlX0sS5EqnuTdsXt+F6PdcU+z25X7tnPusK2hwcLh5P0/c9o1TgKkcixYHYYP Uq/ZV2pbjO6ZZ19zd+yJFwadjnYlKI3Zv2uMtiVu28U5a8etJEQ/0RiUIDuoTHu6zJsm pU+L4uxhfThwSVhFS4/eTLID0NLgjyXh+7yxIL//lIn7ISF4Tj7MGvMBvta0wUQp3gFr +xRg== X-Gm-Message-State: AOAM532jTXtZ1tXV38llvyD/VpqQ1X7ldY4AxgkGDk8H1s9GD7c0/4M3 Yn33l8AJCLOPly0WFD5ASfU= X-Received: by 2002:a2e:b537:0:b0:24f:9dc:28a6 with SMTP id z23-20020a2eb537000000b0024f09dc28a6mr637763ljm.509.1650727401488; Sat, 23 Apr 2022 08:23:21 -0700 (PDT) Received: from [192.168.1.7] ([212.22.223.21]) by smtp.gmail.com with ESMTPSA id x22-20020a19e016000000b00471f7e4f09asm252577lfg.112.2022.04.23.08.23.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 23 Apr 2022 08:23:21 -0700 (PDT) Subject: Re: [PATCH V1 5/6] xen/grant-dma-ops: Retrieve the ID of backend's domain for DT devices To: Stefano Stabellini Cc: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Oleksandr Tyshchenko , Boris Ostrovsky , Juergen Gross , Julien Grall , "Michael S. Tsirkin" , Christoph Hellwig References: <1650646263-22047-1-git-send-email-olekstysh@gmail.com> <1650646263-22047-6-git-send-email-olekstysh@gmail.com> From: Oleksandr Message-ID: <6ac03d9f-a678-60e9-ca6e-fcbe1aee51d3@gmail.com> Date: Sat, 23 Apr 2022 18:23:19 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23.04.22 02:00, Stefano Stabellini wrote: Hello Stefano > On Fri, 22 Apr 2022, Oleksandr Tyshchenko wrote: >> From: Oleksandr Tyshchenko >> >> Use the presence of recently introduced "xen,dev-domid" property >> in the device node as a clear indicator of enabling Xen grant >> mappings scheme for that device and read the ID of Xen domain where >> the corresponding backend resides. The ID (domid) is used as >> an argument to the Xen grant mapping APIs. >> >> Also introduce xen_is_grant_dma_device() to check whether xen-grant >> DMA ops need to be set for a passed device. >> >> Remove the hardcoded domid 0 in xen_grant_setup_dma_ops(). >> >> Signed-off-by: Oleksandr Tyshchenko >> --- >> Changes RFC -> V1: >> - new patch, split required changes from commit: >> "[PATCH 4/6] virtio: Various updates to xen-virtio DMA ops layer" >> - update checks in xen_virtio_setup_dma_ops() to only support >> DT devices for now >> - remove the "virtio,mmio" check from xen_is_virtio_device() >> - remane everything according to the new naming scheme: >> s/virtio/grant_dma >> --- >> drivers/xen/grant-dma-ops.c | 25 ++++++++++++++++++------- >> include/xen/xen-ops.h | 5 +++++ >> 2 files changed, 23 insertions(+), 7 deletions(-) >> >> diff --git a/drivers/xen/grant-dma-ops.c b/drivers/xen/grant-dma-ops.c >> index 0e69aa8..70d5d77 100644 >> --- a/drivers/xen/grant-dma-ops.c >> +++ b/drivers/xen/grant-dma-ops.c >> @@ -66,11 +66,6 @@ static struct xen_grant_dma_data *find_xen_grant_dma_data(struct device *dev) >> * Such a DMA address is formed by using the grant reference as a frame >> * number and setting the highest address bit (this bit is for the backend >> * to be able to distinguish it from e.g. a mmio address). >> - * >> - * Note that for now we hard wire dom0 to be the backend domain. In order >> - * to support any domain as backend we'd need to add a way to communicate >> - * the domid of this backend, e.g. via Xenstore, via the PCI-device's >> - * config space or DT/ACPI. >> */ >> static void *xen_grant_dma_alloc(struct device *dev, size_t size, >> dma_addr_t *dma_handle, gfp_t gfp, >> @@ -277,6 +272,16 @@ static const struct dma_map_ops xen_grant_dma_ops = { >> .dma_supported = xen_grant_dma_supported, >> }; >> >> +bool xen_is_grant_dma_device(struct device *dev) >> +{ >> + /* XXX Handle only DT devices for now */ >> + if (!dev->of_node) >> + return false; >> + >> + return of_property_read_bool(dev->of_node, "xen,dev-domid"); >> +} >> +EXPORT_SYMBOL_GPL(xen_is_grant_dma_device); >> + >> void xen_grant_setup_dma_ops(struct device *dev) >> { >> struct xen_grant_dma_data *data; >> @@ -288,8 +293,14 @@ void xen_grant_setup_dma_ops(struct device *dev) >> return; >> } >> >> - /* XXX The dom0 is hardcoded as the backend domain for now */ >> - dev_domid = 0; >> + /* XXX ACPI and PCI devices unsupported for now */ >> + if (dev_is_pci(dev) || !dev->of_node) >> + goto err; > I think we can remove the "dev_is_pci" check, right? I think, yes (at least for now). I will remove the inclusion of #include as well. > > >> + if (of_property_read_u32(dev->of_node, "xen,dev-domid", &dev_domid)) { >> + dev_err(dev, "xen,dev-domid property is not present\n"); >> + goto err; >> + } >> >> data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); >> if (!data) { >> diff --git a/include/xen/xen-ops.h b/include/xen/xen-ops.h >> index 4f9fad5..62be9dc 100644 >> --- a/include/xen/xen-ops.h >> +++ b/include/xen/xen-ops.h >> @@ -223,10 +223,15 @@ static inline void xen_preemptible_hcall_end(void) { } >> >> #ifdef CONFIG_XEN_GRANT_DMA_OPS >> void xen_grant_setup_dma_ops(struct device *dev); >> +bool xen_is_grant_dma_device(struct device *dev); >> #else >> static inline void xen_grant_setup_dma_ops(struct device *dev) >> { >> } >> +static inline bool xen_is_grant_dma_device(struct device *dev) >> +{ >> + return false; >> +} >> #endif /* CONFIG_XEN_GRANT_DMA_OPS */ >> >> #endif /* INCLUDE_XEN_OPS_H */ >> -- >> 2.7.4 >> >> >> _______________________________________________ >> linux-arm-kernel mailing list >> linux-arm-kernel@lists.infradead.org >> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel >> -- Regards, Oleksandr Tyshchenko