Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4043867pxf; Tue, 23 Mar 2021 00:42:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtoFzAqjUo4apeKReDXw/+qdgYSwIXlJu1Gs3LmewBYQ6t7szW+1c73nHeWQbtZwG6FBKS X-Received: by 2002:a17:906:74c4:: with SMTP id z4mr3667349ejl.512.1616485367530; Tue, 23 Mar 2021 00:42:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616485367; cv=none; d=google.com; s=arc-20160816; b=DclxoMXHBuzgIX4hf4mXFjYZV8oaiW2FFUykepjYTeDDKOvAX6/HiqqyXu0FbF2lkW aMTldw0M5GB/56+Tw+n2Ju2ubzvGkvXearkHAX+OXLaborBh+2fIP01pNEFgfGbo5u8J fIEugSv/Rca6NV1qJ0tuLxCWkb5XbIlbaubXpWzpejz7nxj9Q2TXcWVLNy5W+L41THXT 1ILBmjKKw9B6yitDxemUcvV06BTV1b4Z8yGUZjxOYCrIsoMtsXKbh4o5hrVNxEECdqaB V1NH5bvOlaG3pgXj2ZcgsJRn7WEVdTb1ySCifpRr31ixlwrtex3XZbk6RgWvgfVstWW0 +EqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=gcmI11wouIpDwxdi+NStOdrVppM7cT0Mia1ThanzCd0=; b=DgLs42FU0HDPh0GoBdG7YNHjwUzu0rK5WFsy7HsMe/SIoO5JA0jtZi/xT0SNKj0il6 nHxGKZfIpIdE4i3AtH7wLi/LoY9bna9OG1T2GanrxRjKjc1W/lfFHPSfh5Y8WPyuzT2a IAKggMVUENncluqIrrGAV+mzzFABuyOBtaLfiOZ5OiAx0z+hlP4Z9FHyvuvHL7UQOh2+ JUYjC3etcD1hx+HMRUnARJJMJUvrrBr3kHi63I6lux2L3V+CJ6lUZCYeHt7TpOBahqKW pz616giBXXtZI2CQRuHijYaW5FKscKl0MLwDyvlvf3LBvc5eqAbeYeX/OnmC1IY7N97H OJqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ozlabs-ru.20150623.gappssmtp.com header.s=20150623 header.b=UE5+wbRm; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g4si12742587ejp.171.2021.03.23.00.42.25; Tue, 23 Mar 2021 00:42:47 -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=@ozlabs-ru.20150623.gappssmtp.com header.s=20150623 header.b=UE5+wbRm; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229979AbhCWHla (ORCPT + 99 others); Tue, 23 Mar 2021 03:41:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229658AbhCWHlT (ORCPT ); Tue, 23 Mar 2021 03:41:19 -0400 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D941C061574 for ; Tue, 23 Mar 2021 00:41:19 -0700 (PDT) Received: by mail-pg1-x52a.google.com with SMTP id h25so10830943pgm.3 for ; Tue, 23 Mar 2021 00:41:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ozlabs-ru.20150623.gappssmtp.com; s=20150623; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=gcmI11wouIpDwxdi+NStOdrVppM7cT0Mia1ThanzCd0=; b=UE5+wbRmZdYUdQ0G8bX362ijyRwJ9biLMH7je5sLG9tnGEthPDD8cms1zmPguoF2Vz PdJgmfHFxwX09TuzdZ6OiVb5rBOwbl6JvTiwYJ4ZpFQGLsCHU5fms4JjJqtMYnQ5J+h+ 0ryMxlh8oqxok6IQtckoXOeiOaGx77B4tbt11zmPUMa2vX+O9NFx7zXvpTw1HrFwBztz NPeXe/t0wUwM/uI0Mx8vQuL1oKQIQQhXDwlPgESgSrKwScDtQ3ErlHqczwAUiobBAjDv Y3WAeJwnHB3G8M+PonvwePYXgPUy82uDV+D3i6i9rRjiqTF9B7VfjIRofihNj13QksRB PVcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=gcmI11wouIpDwxdi+NStOdrVppM7cT0Mia1ThanzCd0=; b=iyjiK2m/KpDE+sO56jMEDCAtYEBm+GrckaTAR50arKcueGB1iOxubg1aF1TXFKzjv2 OelsQBRd35gM3DeAcw/uvaNv7UjAhdlW41OkqVourTo3Krr1zejd+8M6LYFd70IRXMse jrw/dExERGMNo1XOjJ6x52mTQSizytJPcq2oz5mjgdLk2VQGfD8J6DQUjVj4Pp/rVn7y 00K/JsnJYJ0jqzNQGr3p2yOhal1CN4BnZNclKCQ2adcbwJ2UjIFs2gmkwlE1Gu7dybz9 EAL1xkotjRfKeLwpY6G4TpZMBq8eFcA4p8ElPD26t6C/RAPEcUtTyy0/rOhPleiIl/EC 3leg== X-Gm-Message-State: AOAM532UCo5vOlbOSQPVL8zrWyH5T0sYuN+VOYIba0gIfns4qWl0L17h edJX59h6YDZkrnJarhEl+Vl2L7f4GsEa91fm X-Received: by 2002:a62:7ed2:0:b029:21d:1806:fe30 with SMTP id z201-20020a627ed20000b029021d1806fe30mr731380pfc.5.1616485277056; Tue, 23 Mar 2021 00:41:17 -0700 (PDT) Received: from [192.168.10.23] (124-171-107-241.dyn.iinet.net.au. [124.171.107.241]) by smtp.gmail.com with UTF8SMTPSA id 4sm1593011pjl.51.2021.03.23.00.41.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 23 Mar 2021 00:41:16 -0700 (PDT) Message-ID: <2088f84c-08fb-fecc-f5d4-5735357dc296@ozlabs.ru> Date: Tue, 23 Mar 2021 18:41:09 +1100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:87.0) Gecko/20100101 Thunderbird/87.0 Subject: Re: [PATCH 1/1] powerpc/iommu: Enable remaining IOMMU Pagesizes present in LoPAR Content-Language: en-US To: Leonardo Bras , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Christophe Leroy , Joel Stanley , brking@linux.vnet.ibm.com Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org References: <20210322190943.715368-1-leobras.c@gmail.com> From: Alexey Kardashevskiy In-Reply-To: <20210322190943.715368-1-leobras.c@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23/03/2021 06:09, Leonardo Bras wrote: > According to LoPAR, ibm,query-pe-dma-window output named "IO Page Sizes" > will let the OS know all possible pagesizes that can be used for creating a > new DDW. > > Currently Linux will only try using 3 of the 8 available options: > 4K, 64K and 16M. According to LoPAR, Hypervisor may also offer 32M, 64M, > 128M, 256M and 16G. > > Enabling bigger pages would be interesting for direct mapping systems > with a lot of RAM, while using less TCE entries. > > Signed-off-by: Leonardo Bras > --- > arch/powerpc/include/asm/iommu.h | 8 ++++++++ > arch/powerpc/platforms/pseries/iommu.c | 28 +++++++++++++++++++------- > 2 files changed, 29 insertions(+), 7 deletions(-) > > diff --git a/arch/powerpc/include/asm/iommu.h b/arch/powerpc/include/asm/iommu.h > index deef7c94d7b6..c170048b7a1b 100644 > --- a/arch/powerpc/include/asm/iommu.h > +++ b/arch/powerpc/include/asm/iommu.h > @@ -19,6 +19,14 @@ > #include > #include > > +#define IOMMU_PAGE_SHIFT_16G 34 > +#define IOMMU_PAGE_SHIFT_256M 28 > +#define IOMMU_PAGE_SHIFT_128M 27 > +#define IOMMU_PAGE_SHIFT_64M 26 > +#define IOMMU_PAGE_SHIFT_32M 25 > +#define IOMMU_PAGE_SHIFT_16M 24 > +#define IOMMU_PAGE_SHIFT_64K 16 These are not very descriptive, these are just normal shifts, could be as simple as __builtin_ctz(SZ_4K) (gcc will optimize this) and so on. OTOH the PAPR page sizes need macros as they are the ones which are weird and screaming for macros. I'd steal/rework spapr_page_mask_to_query_mask() from QEMU. Thanks, > + > #define IOMMU_PAGE_SHIFT_4K 12 > #define IOMMU_PAGE_SIZE_4K (ASM_CONST(1) << IOMMU_PAGE_SHIFT_4K) > #define IOMMU_PAGE_MASK_4K (~((1 << IOMMU_PAGE_SHIFT_4K) - 1)) > diff --git a/arch/powerpc/platforms/pseries/iommu.c b/arch/powerpc/platforms/pseries/iommu.c > index 9fc5217f0c8e..02958e80aa91 100644 > --- a/arch/powerpc/platforms/pseries/iommu.c > +++ b/arch/powerpc/platforms/pseries/iommu.c > @@ -1099,6 +1099,24 @@ static void reset_dma_window(struct pci_dev *dev, struct device_node *par_dn) > ret); > } > > +/* Returns page shift based on "IO Page Sizes" output at ibm,query-pe-dma-window. SeeL LoPAR */ > +static int iommu_get_page_shift(u32 query_page_size) > +{ > + const int shift[] = {IOMMU_PAGE_SHIFT_4K, IOMMU_PAGE_SHIFT_64K, IOMMU_PAGE_SHIFT_16M, > + IOMMU_PAGE_SHIFT_32M, IOMMU_PAGE_SHIFT_64M, IOMMU_PAGE_SHIFT_128M, > + IOMMU_PAGE_SHIFT_256M, IOMMU_PAGE_SHIFT_16G}; > + int i = ARRAY_SIZE(shift) - 1; > + > + /* Looks for the largest page size supported */ > + for (; i >= 0; i--) { > + if (query_page_size & (1 << i)) > + return shift[i]; > + } > + > + /* No valid page size found. */ > + return 0; > +} > + > /* > * If the PE supports dynamic dma windows, and there is space for a table > * that can map all pages in a linear offset, then setup such a table, > @@ -1206,13 +1224,9 @@ static u64 enable_ddw(struct pci_dev *dev, struct device_node *pdn) > goto out_failed; > } > } > - if (query.page_size & 4) { > - page_shift = 24; /* 16MB */ > - } else if (query.page_size & 2) { > - page_shift = 16; /* 64kB */ > - } else if (query.page_size & 1) { > - page_shift = 12; /* 4kB */ > - } else { > + > + page_shift = iommu_get_page_shift(query.page_size); > + if (!page_shift) { > dev_dbg(&dev->dev, "no supported direct page size in mask %x", > query.page_size); > goto out_failed; > -- Alexey