From patchwork Sat May 7 18:19:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Tyshchenko X-Patchwork-Id: 12842126 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E4600C433FE for ; Sat, 7 May 2022 18:22:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=6sJ3MCPLIjLUWrkz10fG98he/s7ay99RUC5f4cDkKs8=; b=cZIZsrdTEkS+Fh w7Da2fMAWvSjVAm9JFTV/rpG8/myQk7tdyGn8yiiQZZkNlaJI/VKwOLOvmEfC9M3S/XNvBiRlv0gm LB4u1tXYbaQvVKo5F43vhD3Dy9RkxYik9/ldWtLswr2uiVbdImgwM0CpMaC4KFHo+qsme4R0lccyY GXjC/XGhPY6RQxQziJXAPfHVYM/AgheKHV6K7pXI+6j9VQWN43tvEFpb+9++Yl/Xa4OubV6saexH4 h9bPyx5iN314+FHBo5ucYF52Jxio2Tpfv88pO4HWZ0Uy2tUvFQjr03vPSoZNUdNPbB9RNB4ibnjip QILCjuQ+tfdFzLzYmYRg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nnP3J-007w9N-Dm; Sat, 07 May 2022 18:21:14 +0000 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nnP1f-007vL1-Gg for linux-arm-kernel@lists.infradead.org; Sat, 07 May 2022 18:19:33 +0000 Received: by mail-wm1-x32c.google.com with SMTP id r1-20020a1c2b01000000b00394398c5d51so6130854wmr.2 for ; Sat, 07 May 2022 11:19:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=JQ4/wPcUQ3XIBwyiOH+85aEeFtvLk17ZXfaTMabSQhQ=; b=M0nL9AqbUiqgoGeBXuGJocL7BzhM9dpf6lZVm6z1MjjHA7Ksx3fAI6nsxT0Nt1TL05 V9n3RuTkUTnoTUTcWzbDZzYyXq+nDqhodBqF5QWBpLz3KG7WkLCJw+dMLaWXpmXERYF1 Z/ciVWktZyebFps/o8q2Oq5Yq41Pu3hxh+stWpNbBkwcaCkgIOQ5WYEwn7lV+jJsEdSh +HhxY/jdkwpoWo5uCgqY6+fdKmpb5rQY+LpZDKBI6NpE+HUIsQOlFS0+S/WN3zq9WuIL TiiJg4uvRYrYvsi0W51dYzG/nuX5J3xAnuGzn1LhIo6s+ydhszeik8BNC8Hg3Kloj1TO zwOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=JQ4/wPcUQ3XIBwyiOH+85aEeFtvLk17ZXfaTMabSQhQ=; b=NF+0rt+ENSNl5YL3sWoCgNKlIHRA0PAtCMIsYdzQIZWacWnApZbeoMyY+uZavw2InU 1NhSuePK9041IjU/Tm4lRFuVN4B4laD8+WsU2jsTfVcxDJG2a+s6ionwJyGT1tpPRyc0 XKvqGHQ+LVK5L2k/fROBRNhnHqSI/ZgCdI5xYzdgXaw6IU1EwhGpT2Ije+jVrcJ4z8rC 9mnvQkdD772RyWU6/5IydYskKJtr55BK8Rs80RcSoOutksmSRvMEcKI/Zcj5vOUSb2L6 PBno9OxoHGz3X4qqtGhWik7F0N2andRBYSRcsP7N97xK6G0MoCVN95lJCfxjHj76sbBQ Cdtg== X-Gm-Message-State: AOAM533Yj8tCnuOGxLxqZEZVwbco/HKdlsN2A2xovUd4Zj2E+muZAkfs jbU9mF1/bhW507BRJzFKCdE= X-Google-Smtp-Source: ABdhPJx4KKTzPkd6Pb55J8tu0qaETBwCwPrhXqxi1bGV5Mve7UPIQCUHgzJRC6duNfUV/2m203EIIQ== X-Received: by 2002:a1c:3b54:0:b0:394:3910:3c7b with SMTP id i81-20020a1c3b54000000b0039439103c7bmr8718493wma.3.1651947570262; Sat, 07 May 2022 11:19:30 -0700 (PDT) Received: from otyshchenko.router ([212.22.223.21]) by smtp.gmail.com with ESMTPSA id b10-20020a5d4d8a000000b0020c5253d8f3sm8198457wru.63.2022.05.07.11.19.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 07 May 2022 11:19:29 -0700 (PDT) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Oleksandr Tyshchenko , Boris Ostrovsky , Juergen Gross , Stefano Stabellini , Julien Grall , "Michael S. Tsirkin" , Christoph Hellwig Subject: [PATCH V2 7/7] arm/xen: Assign xen-grant DMA ops for xen-grant DMA devices Date: Sat, 7 May 2022 21:19:08 +0300 Message-Id: <1651947548-4055-8-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1651947548-4055-1-git-send-email-olekstysh@gmail.com> References: <1651947548-4055-1-git-send-email-olekstysh@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220507_111931_661610_C6AF7BB5 X-CRM114-Status: GOOD ( 16.75 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Oleksandr Tyshchenko By assigning xen-grant DMA ops we will restrict memory access for passed device using Xen grant mappings. This is needed for using any virtualized device (e.g. virtio) in Xen guests in a safe manner. Please note, for the virtio devices the XEN_VIRTIO config should be enabled (it forces ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS). Signed-off-by: Oleksandr Tyshchenko Reviewed-by: Stefano Stabellini --- Changes RFC -> V1: - update commit subject/description - remove #ifdef CONFIG_XEN_VIRTIO - re-organize the check taking into the account that swiotlb and virtio cases are mutually exclusive - update according to the new naming scheme: s/virtio/grant_dma Changes V1 -> V2: - add Stefano's R-b - remove arch_has_restricted_virtio_memory_access() check - update commit description - remove the inclusion of virtio_config.h --- include/xen/arm/xen-ops.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/xen/arm/xen-ops.h b/include/xen/arm/xen-ops.h index 288deb1..b0766a6 100644 --- a/include/xen/arm/xen-ops.h +++ b/include/xen/arm/xen-ops.h @@ -3,11 +3,14 @@ #define _ASM_ARM_XEN_OPS_H #include +#include static inline void xen_setup_dma_ops(struct device *dev) { #ifdef CONFIG_XEN - if (xen_swiotlb_detect()) + if (xen_is_grant_dma_device(dev)) + xen_grant_setup_dma_ops(dev); + else if (xen_swiotlb_detect()) dev->dma_ops = &xen_swiotlb_dma_ops; #endif }