Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1081383pxk; Thu, 3 Sep 2020 23:07:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCz+b62LOWrTIyfHfIQQAnsQchT6bJI24qm/+93F4VZgDom32cTvSFt5K+SewTRtYW+wkI X-Received: by 2002:a17:907:2055:: with SMTP id pg21mr6048107ejb.501.1599199666958; Thu, 03 Sep 2020 23:07:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599199666; cv=none; d=google.com; s=arc-20160816; b=oLmTwXKt7gqxNQdfw0rxCwZY7DxNCAANZefb2ZvOX4/0lpI8mrR7jl5SyfGa1Fz9if SOOGQ0A5k+mN0CXgbGRJIWYNOLzKhyt/NfkFIwmUC8BRArcFtafVGfRM1cPaz0DbMLeh yKWido7dLxX+lKbMmQbtofLpiiWhPtdnR1rE3XpQBWRd7tydzpQlM7LolWGBw58vmupk t5EI4bvjgzntFU0ZNT4WxZsh6nxLbo8y7htIghQRQpK6Q2npZXjiK0/HXQji8o2xTy8a Leic6lYpERh4ysluhzcUtAa6MURf4b0alhzIUgH94Ra6A2ewXY0CSvkayUram4vR/JJj FV3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:organization:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=Y4+nyUm6P1sliqzR8n00yXfDoX7E3MCV3APAcgzk2PM=; b=h4Uh/t9Ju+IkPJM2kcClzuhIXf0Qd2yAbWgJ8AkPdGWucRU4hBOWIXrvkuRut732dh JiGs1HJ9+7/uYNpU4U8F2Urky0yCm0iV9i/qmhQsMa2vG6A34tqjgU7EFJ4K8qI05lc3 clfl253tMJXexYFu5V0gzAbu8mxx1eOO6djX3XIquxluUTusE0HRwUntks19gQ5qurT2 8epCqQ00V0krGbrZJ5NroTQjTjYQx5pwACDwMN9Kpjb0JFmft4NfTR7t7v0uhSy6l58r txf7jKI1vjgHXDFQjZoTLnrhdg5JBFkSJ1rTwdoqijhH1yK8s5SUCzzQ6AqzFL9kCAvb LB/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=tmglZImb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n13si3436892ejz.621.2020.09.03.23.07.24; Thu, 03 Sep 2020 23:07:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=tmglZImb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726613AbgIDGEj (ORCPT + 99 others); Fri, 4 Sep 2020 02:04:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725812AbgIDGEi (ORCPT ); Fri, 4 Sep 2020 02:04:38 -0400 Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24D09C061244 for ; Thu, 3 Sep 2020 23:04:38 -0700 (PDT) Received: by mail-qk1-x742.google.com with SMTP id n133so5354714qkn.11 for ; Thu, 03 Sep 2020 23:04:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:subject:from:to:cc:date:in-reply-to:references :organization:user-agent:mime-version:content-transfer-encoding; bh=Y4+nyUm6P1sliqzR8n00yXfDoX7E3MCV3APAcgzk2PM=; b=tmglZImbSzoU+BhJ6jX9g28qc3bA3Dg4gsr18kTGq4SIswhoONwdW7lTJ37ErdYH0f VKyDWeCmNhGNRuUWPMOfVZvdpsarevt9GZbHmqKNG6BX8v9uCTcz18gw2QfND7xyROPn I5onuGEu9zZ8T7eG1A9YU+Qeda0oJGkZQqSPMAracI4OGeh4zjnr3aDbyk18h7+sgx42 lMlfdjNK7LOhmKh3PC7sGNuJPRJLK1RCRQg7wXFJQcqqokjcOMERWdmR93IHzj/Cc7BO YnFOCZH/UTY9v5tuKcTJYdM5R+c1654bmqEBluKZ5d+j+dy7CHCso8Hbs2vdo/ILThNg RmEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:organization:user-agent:mime-version :content-transfer-encoding; bh=Y4+nyUm6P1sliqzR8n00yXfDoX7E3MCV3APAcgzk2PM=; b=OuQktHOQYl2uNxoADS4MtnwIkX0dJoVqUwAuKl5fzOaFy7S9YSMBArMCuZ0sFn1sfq 6f6Z0/uyoOHYaaJ1kAv94E3/hm2+HzlZsh7aqxMTv2aoun4taENXdX+M+FjuFs/Clsop B147/nPhpa+FEYwVuRl3v9kdGBzxpi1FzGMM4rELV4t8ZogT/yWkSWbzhEH4IXVgRn4p ryVjlwfchXAlXuI49AW1T6+w//CvaKd1JP6ZmLsK1hLnzOrEve7fQ0goPsJLRDnjkI1o nXG48WJvzkMrNLNfHNi2lsCaWLLJcEznNv+hsPcuNpB+mxJpcrPj8idPeQyU2sDIql+m FMsQ== X-Gm-Message-State: AOAM53385nYiefWkzUidFnux4u0efO2w/SlGv3vRxZnaclUhJnPAK0vm sigI4nRqh7iQ2ZftUU7ymcM= X-Received: by 2002:a37:a3cf:: with SMTP id m198mr6676667qke.410.1599199475491; Thu, 03 Sep 2020 23:04:35 -0700 (PDT) Received: from LeoBras (179-125-130-62.dynamic.desktop.com.br. [179.125.130.62]) by smtp.gmail.com with ESMTPSA id 103sm3808531qta.31.2020.09.03.23.04.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2020 23:04:34 -0700 (PDT) Message-ID: Subject: Re: [PATCH v1 02/10] powerpc/kernel/iommu: Align size for IOMMU_PAGE_SIZE on iommu_*_coherent() From: Leonardo Bras To: Alexey Kardashevskiy , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Christophe Leroy , Joel Stanley , Thiago Jung Bauermann , Ram Pai , Brian King , Murilo Fossa Vicentini , David Dai Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Date: Fri, 04 Sep 2020 03:04:28 -0300 In-Reply-To: <8f569f68-5145-676e-50a1-b13f3fbd69cc@ozlabs.ru> References: <20200817234033.442511-1-leobras.c@gmail.com> <20200817234033.442511-3-leobras.c@gmail.com> <7b9640e0-568f-1470-40f4-a3ccec8abcf2@ozlabs.ru> <2aacd45f047489642da1731c92d3555ad101e3c7.camel@gmail.com> <81f106bd-8962-22f2-f14a-378d3486f57e@ozlabs.ru> <39ad3a9c103faf9c5fc2fd5700d8606eb4a2b67e.camel@gmail.com> <8f569f68-5145-676e-50a1-b13f3fbd69cc@ozlabs.ru> Organization: IBM Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.34.4 (3.34.4-1.fc31) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2020-09-03 at 14:41 +1000, Alexey Kardashevskiy wrote: > I am new to this, so I am trying to understand how a memory page mapped > > as DMA, and used for something else could be a problem. > > From the device prospective, there is PCI space and everything from 0 > till 1<<64 is accessible and what is that mapped to - the device does > not know. PHB's IOMMU is the thing to notice invalid access and raise > EEH but PHB only knows about PCI->physical memory mapping (with IOMMU > pages) but nothing about the host kernel pages. Does this help? Thanks, According to our conversation on Slack: 1- There is a problem if a hypervisor gives to it's VMs contiguous memory blocks that are not aligned to IOMMU pages, because then an iommu_map_page() could map some memory in this VM and some memory in other VM / process. 2- To guarantee this, we should have system pagesize >= iommu_pagesize One way to get (2) is by doing this in enable_ddw(): if ((query.page_size & 4) && PAGE_SHIFT >= 24) { page_shift = 24; /* 16MB */ } else if ((query.page_size & 2) && PAGE_SHIFT >= 16 ) { page_shift = 16; /* 64kB */ } else if (query.page_size & 1 && PAGE_SHIFT >= 12) { page_shift = 12; /* 4kB */ [...] Another way of solving this, would be adding in LoPAR documentation that the blocksize of contiguous memory the hypervisor gives a VM should always be aligned to IOMMU pagesize offered. I think the best approach would be first sending the above patch, which is faster, and then get working into adding that to documentation, so hypervisors guarantee this. If this gets into the docs, we can revert the patch. What do you think? Best regards!