Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp9150338ioo; Sun, 5 Jun 2022 06:27:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHh+HDcV90GjFrwAc9adciV5idKkucjtJXMbd2EWgM5ZuKDSkFKgVoc1Vi3aXj+hg28Cao X-Received: by 2002:a05:6a00:2cc:b0:51b:f1d3:e5f with SMTP id b12-20020a056a0002cc00b0051bf1d30e5fmr8543845pft.52.1654435669953; Sun, 05 Jun 2022 06:27:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654435669; cv=none; d=google.com; s=arc-20160816; b=WPCVXOr3tpSDaZApu+8OdDj7uLTthRNVzANdCMe6uK+TTElGtM1I5jZw408pscMy6B f+D+H4IZolPOp5PHJ7qKGoFpQZgJzFRojtp8oj/37rWp7makz+eVoJ21KtUv/kPl1qdp ckto3CLdujRXQOZzEM1jIKIgQsRAWkzsGoBF6Of/w+Ly5RDygq7JFhhUR+8Ub+VmFX6y MWN5HMl8G3FVjvMkUegoOWIBjjEKRzYBE8Ok1V6ECZT8b5xVASVjDVdFsNnWM2Z+R6rz YxRJqpkoTR8Bh+5KksXz9+x1zlsJyPI7NlXCnq9tJfrbRCaLp2dlMpWmluPhpo5v9Lw1 5vJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=1vkkmAPV7KLk5lLiYTidlJE/79j9EHin+NPAEwFGGPw=; b=UhYxN+c9x37D1EBYYOYgSz4eR004zR3oNVDG6xAJ75B7ZYnImBBoLCa/8IrKN/szzd Y1LaeJ12svERZdx5KA+QYLlxeY5XZoUQ8Fxe2haxLnDdenl1zE1918nbVCslofuI3lk7 8QBhGsXFAE0lVJFp7rznwo4sI+bnJhCfFOXAPcVW0qSYrEofk/NsmiWW7ePtlZ4vBCgb 5iC150W+f4wayxiOWdOxTf5OPABCBT/CHOeD5MrmrO89onc9BSKLTa1XdyA4DY2oYpg+ 5xWweCZMnQUI4IdL90lIlwprW9F9SxsFsxq2sGdKR8FhY4GrS17SEyaFqD7EZ7nOet6w ZWsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=jmz6IGbz; 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 y7-20020a170902d64700b001639f0ff47esi16128873plh.40.2022.06.05.06.27.23; Sun, 05 Jun 2022 06:27:49 -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=jmz6IGbz; 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 S238560AbiFBTYw (ORCPT + 99 others); Thu, 2 Jun 2022 15:24:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238577AbiFBTYb (ORCPT ); Thu, 2 Jun 2022 15:24:31 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA9AB2DCD for ; Thu, 2 Jun 2022 12:24:26 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id q1so11817780ejz.9 for ; Thu, 02 Jun 2022 12:24:26 -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=1vkkmAPV7KLk5lLiYTidlJE/79j9EHin+NPAEwFGGPw=; b=jmz6IGbzJezrRiTA2mBa10TijR6VR0Wsv+zWCJK861wll6nY+yQF0eqIKkBS5xRnY3 06uO1Xxv/f6WxMrF7ZyLzMMJpLL7T61a9BflqTJ5BPHI2FF2yaJJHfW/bvUVTWX/bfjV TROS8lfNzLEEAzJE9nYscufoMwjo6IO6XfMO3atpb5xGlgWq24wpMqelyhVadYrVknNw V4Dfqy8uPCBCPMqt8EIVIXfDHx1hVqeQ4NxiznFjv2NBcgYhlvr/UPQpIcO2wVH5JkM0 oetd2/yrhmoOzPa4PebgUEMktci6Q0lz4PC7beZD+tIq3arTBN3tTXxehvdl7SduyR5Q 8frg== 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=1vkkmAPV7KLk5lLiYTidlJE/79j9EHin+NPAEwFGGPw=; b=FgNBZ97dYaxOQpqO1UaclcsljLfk3N3rn+BgCk8gRMXgflzPbmzarcBSFny+2e14KX 3XtzFfVChYIRORkD8ovfmfEQet91g4B5Qez8siSzBXtIsBG5Bw/2nFQ1PNinGDhbJvi/ ceI7y8CCqATnrX1XQjlDwNQj9DOBWNJC0tL/kAsI99TU8cu4MIJ3922Z0EACVgfcQPuc 0ouk+tHfVNEeeZ61lgu8trqQuAmstJCNmerYj1hTueVs5TEgiSv1PDNXRv7cF/3Pii0x GTsqurBxI+Y+pIPVmjovj1fJTDDygLTck0pOniH6/SJHLKU5efLtj+ysSQQ8uhugPCwx 4eAw== X-Gm-Message-State: AOAM531il5F9sg46BwX5ZS/noPQbFz8f0ipz9mPbRZU183uxuTbn0ZWr q8RCtr44QYl6wX13050qx8c= X-Received: by 2002:a17:907:7f20:b0:6fe:f0c8:8e6f with SMTP id qf32-20020a1709077f2000b006fef0c88e6fmr5510662ejc.453.1654197865496; Thu, 02 Jun 2022 12:24:25 -0700 (PDT) Received: from otyshchenko.router ([212.22.223.21]) by smtp.gmail.com with ESMTPSA id eg13-20020a056402288d00b0042dce73168csm2938301edb.13.2022.06.02.12.24.24 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Jun 2022 12:24:25 -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 V4 8/8] arm/xen: Assign xen-grant DMA ops for xen-grant DMA devices Date: Thu, 2 Jun 2022 22:23:53 +0300 Message-Id: <1654197833-25362-9-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1654197833-25362-1-git-send-email-olekstysh@gmail.com> References: <1654197833-25362-1-git-send-email-olekstysh@gmail.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 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 Changes V2 -> V3: - no changes Changes V3 -> V4: - no changes --- 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 } -- 2.7.4