From nobody Tue May 7 02:35:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1dmarc=pass fromdomain=oracle.com); dmarc=pass(p=none dis=none) header.from=oracle.com ARC-Seal: i=2; a=rsa-sha256; t=1612395549; cv=pass; d=zohomail.com; s=zohoarc; b=UAPhikZho+u2FGFOkcK5/olqkz0E+8thHAb6LbZuwKNe2WNzrvOvJTYbYJmeRslYsiXRKGC3bDTYitRPP7uKyy34C4dG89kTJiC6Pj0Q5KXu3HtP0M1IwaHXepqvh9JfLPxWTbPVnZl5rbjX6e1pZPUUhCwxOZW4xmEv9G3uIiw= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612395549; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=cOkwV9kqyN08qwK1NmwlE/kmA1LrE5vAxbf45V3rJbU=; b=Lv4hFXe+sg8GwXwZS7UICoKee2aGo3ZWz8YZujkMfyyrI+okXHd7IAj/W/s9qLyy0zJMDNtQVDZxBCJT9kdX0ir+kjBKtkl4GKbGg9gTypV9+xP+dXZOKB34ZUJImDZum0LjskTBRiIQPS1ALDEn3ovSiIjd1ftqKuXcG0EfBVc= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1dmarc=pass fromdomain=oracle.com); dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 16123955490644.296239764930647; Wed, 3 Feb 2021 15:39:09 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.81093.149194 (Exim 4.92) (envelope-from ) id 1l7Rjb-00060b-EQ; Wed, 03 Feb 2021 23:38:55 +0000 Received: by outflank-mailman (output) from mailman id 81093.149194; Wed, 03 Feb 2021 23:38:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l7Rjb-00060S-BA; Wed, 03 Feb 2021 23:38:55 +0000 Received: by outflank-mailman (input) for mailman id 81093; Wed, 03 Feb 2021 23:38:54 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l7Rja-00060K-O9 for xen-devel@lists.xenproject.org; Wed, 03 Feb 2021 23:38:54 +0000 Received: from aserp2120.oracle.com (unknown [141.146.126.78]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 15696a5c-44f9-4663-b39b-48261f3da0e6; Wed, 03 Feb 2021 23:38:53 +0000 (UTC) Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 113N8wg9103664; Wed, 3 Feb 2021 23:37:46 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 36cydm2q16-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 Feb 2021 23:37:46 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 113NAbHS112134; Wed, 3 Feb 2021 23:37:45 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2171.outbound.protection.outlook.com [104.47.56.171]) by userp3030.oracle.com with ESMTP id 36dhd0h98t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 Feb 2021 23:37:45 +0000 Received: from BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) by SJ0PR10MB4784.namprd10.prod.outlook.com (2603:10b6:a03:2d4::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.19; Wed, 3 Feb 2021 23:37:42 +0000 Received: from BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::b52e:bdd3:d193:4d14]) by BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::b52e:bdd3:d193:4d14%7]) with mapi id 15.20.3805.026; Wed, 3 Feb 2021 23:37:42 +0000 Received: from localhost.localdomain (138.3.200.16) by CH0PR03CA0008.namprd03.prod.outlook.com (2603:10b6:610:b0::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3825.17 via Frontend Transport; Wed, 3 Feb 2021 23:37:36 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 15696a5c-44f9-4663-b39b-48261f3da0e6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=cOkwV9kqyN08qwK1NmwlE/kmA1LrE5vAxbf45V3rJbU=; b=NQGceTWcGnFSzxuNLWlAT7ftp0+qtrFa+QqxyH4luxuOx/4CbpdhaoE1Woq2H+KFeerO qHYOHjtQMoRtQcteMlRdRh0gRMZKRjAll6TtCIhagOKGAtHQK+a4RnXZyZtxYS+eWhO7 Q9zk3YuYVHCYkJer6I5mEs0RWCDyNsLtfty3ihQJahSEH+AOAXeery6C8G+lw+Wve6VO RrakFbj29sTk1eqKCA6k7frw/kNvX2KNbYKUY73dlVBQUUazqqcpjvB7x1UWhf7Oxjls +JVF9g5XDO8m4yApyiGveb+BwV1HXWmNq5cuIY7dNvj4EEXadoMkUTRMO+SamF8ipE9/ zQ== ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dzeUWNcU9Mj4e0TYMjDEEa04Puyz6RPQSjKZYKBWfmB0YwXGpAgYd9oM8VKYP8KXENITMV8yDMjP8CYacJPwv8DWmD4pSTiPOoRhlSV0oSyx0fWkiuokgpZ+MNc10AjBFlPN3fS6+wmdDwxaSMmr3AWXeIHjleiC2b90oOD5l7lecsd4TJ9inlejRmA0LhPrJE+i4qIR9reLEtuATKI0CpBOk/U9dhS+oomHA0MkWrlzRvDNVn3m/crta3/rFfJdhqMD/lwZ4mioO+D+XS7pQ9BYpw2e4rYERQEKbrZv9QIBXA98liYSs+uPxvIe4cpX6aBF1q3jWKa57MKtPPxTeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cOkwV9kqyN08qwK1NmwlE/kmA1LrE5vAxbf45V3rJbU=; b=oRgVV+HDbkWsmdM/NCIX14g0sj7/IHgOUpcV3ziyxhzl7Gd9U6OrO+hsNKg1+9hy5LFfkCdBPZ67Gvymn2hvh0EzIWmwXrCGTGCBKlXzcua2sNyEM6w6d04IriWe5nKG8hbefsrZXYHtfl+nck4edJFi/egB74dCn39TyjYaAlQT5uc3NlHVNJY8OU7o92ZDnbztY0QqnurGr2ImA4x5GETYQOsOk+i8iBEMYO2ycotIs7s6a2T4+epsSq3dofegTAZpSmjSlWo9yQ7cTq2AF75IrKWjRMvAxpe2iczboLVN5wyQgvGjq2ox9eG5EPbYxxMX81tkmyq68p0VkxAEGg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cOkwV9kqyN08qwK1NmwlE/kmA1LrE5vAxbf45V3rJbU=; b=tjvCr9fEZnS/1sygRCnSm5Q2dXA7fAn8eTEtv5NpIiQ6sP2WsjoRLTtl1Z8622ok/gg2EPDiZ56/V2lbBNjHiKgjEsauVAX7RlT/FjXK+64C4N6hsxUAM+k9NP1EKmHYkVkYTH8WDGFNWmhbaiWPaHdLUdqB+5PpwCiQeDtoIs0= Authentication-Results: lists.freedesktop.org; dkim=none (message not signed) header.d=none;lists.freedesktop.org; dmarc=none action=none header.from=oracle.com; From: Dongli Zhang To: dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, iommu@lists.linux-foundation.org, linux-mips@vger.kernel.org, linux-mmc@vger.kernel.org, linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, nouveau@lists.freedesktop.org, x86@kernel.org, xen-devel@lists.xenproject.org Cc: linux-kernel@vger.kernel.org, adrian.hunter@intel.com, akpm@linux-foundation.org, benh@kernel.crashing.org, bskeggs@redhat.com, bhelgaas@google.com, bp@alien8.de, boris.ostrovsky@oracle.com, hch@lst.de, chris@chris-wilson.co.uk, daniel@ffwll.ch, airlied@linux.ie, hpa@zytor.com, mingo@kernel.org, mingo@redhat.com, jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com, jgross@suse.com, konrad.wilk@oracle.com, m.szyprowski@samsung.com, matthew.auld@intel.com, mpe@ellerman.id.au, rppt@kernel.org, paulus@samba.org, peterz@infradead.org, robin.murphy@arm.com, rodrigo.vivi@intel.com, sstabellini@kernel.org, bauerman@linux.ibm.com, tsbogend@alpha.franken.de, tglx@linutronix.de, ulf.hansson@linaro.org, joe.jin@oracle.com, thomas.lendacky@amd.com Subject: [PATCH RFC v1 1/6] swiotlb: define new enumerated type Date: Wed, 3 Feb 2021 15:37:04 -0800 Message-Id: <20210203233709.19819-2-dongli.zhang@oracle.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210203233709.19819-1-dongli.zhang@oracle.com> References: <20210203233709.19819-1-dongli.zhang@oracle.com> X-Originating-IP: [138.3.200.16] X-ClientProxiedBy: CH0PR03CA0008.namprd03.prod.outlook.com (2603:10b6:610:b0::13) To BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 95a27da3-82a5-4fa4-cf2a-08d8c89cb345 X-MS-TrafficTypeDiagnostic: SJ0PR10MB4784: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2657; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kyMvFO94V89ozWj18bC0Vn9q8FAfrj1y9eDdojT3KXhZ3Kb6y0lMwkIUajPU89ixDjx/OGTr/llm3guooQuOtVd+PpQ9YQUQhSfr0VFSEaouKp9j6rQxBc2TDkU3n5TWws0P+gsQ9ClTDsY9obcuVuIpjWx8canMnExyJCp5opcTw4kGqQW+2+W11CZ3GfQA/4/tYYsbBhNweERyMTssLgeMrtTCtHAaB7mU9lopLRJxj2jUoeCAvT2jIcoEdnUPcQsrrvYmOO0jFqky9d3sZhy1e0161Va50YgEy72BmrZriZB7Fl1RBIJTb13rVgOZCbpYnWmPSfKYKtobkI66O/AUHyUDOyZMTNQBR2Mv1wasGM4dt/FVklQoggzHlBFeKpjEo6m1rahep0DWs5s3iFzqE5GbyMkd7KlvzTs1OY1vFoh+bHjv8LoQzMG7W+6nLoal5vB2LR6vIuK2+agcXr4rLiYxXl+a+AkvVQmNmsI6626FXj3SqSvLeM8oEJiQZCJ4U1Q6g3nnWr4d83pSjBwkmZVCAyR8hTQR7DHXcHQnZGjwHSyBmM0W44hGWgRhS7GVj+ds0MKOwrTfTcagGfrroQKUBZjTQBUCad4qCbc= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB2663.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(366004)(39860400002)(396003)(376002)(346002)(83380400001)(6666004)(316002)(5660300002)(956004)(66946007)(6506007)(86362001)(7406005)(4744005)(1076003)(66476007)(8676002)(186003)(26005)(36756003)(7416002)(478600001)(2906002)(66556008)(8936002)(6486002)(16526019)(69590400011)(4326008)(6512007)(44832011)(921005)(2616005)(52116002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?qeAfDC+0fc/jTywdxpwqkCaMRYdTCNWdYfhK/QFffR8uC9UvZ9YkUddjJqj8?= =?us-ascii?Q?LMepJPhT0a36sLGoYCc8pE42XpdTs25YEvJgJbE+r15lAPOhZ2uG8YaqDpie?= =?us-ascii?Q?YBy4aMhXnck5XH46LZbJJ5Bc6YzUGPA/RpT5PCmWbcQzB8peKv+pFSlMP+73?= =?us-ascii?Q?gIpYKWEVF/EtR6TOku8PeSlGV2dRHpAnvJ67O+hahgMBD7bgCaFV694aTg4w?= =?us-ascii?Q?KSujev4hlObPNbItkXf5I4GifCbVNuALJHlzJ8DOx3jIyR3vPyw0wng4LXc+?= =?us-ascii?Q?+9ix1gN2MitGR30SK1CJCpvNbznMmFVfpzPTnriq0kYWtNemlOD6oInjEJhz?= =?us-ascii?Q?lX/MAKiyokUXQ0qit/KLj+zLzuAH3F6pVaMRrXRn4VjzBw0wtn318NY07ege?= =?us-ascii?Q?hHXyWnZhyM9l0kHMf/ze9KlQNE6Sdg2p3vYo/Hq92jn1rRbO59GTtLfvxPn5?= =?us-ascii?Q?QxqO6FkLHZ/88+48rGj194umjw35pFBKx4rrKzuzS4pWSvhkdzyrhRnTCVdM?= =?us-ascii?Q?I7qC6QKCOzWDkQEVzuMBoOZzNkUwie7LrRumo3wMlr/8czcevewuo2IXNIzg?= =?us-ascii?Q?D7TJxw98KoyA2iOs/gldXx3CPC4SiFaEvp6dq7I4fh8GdU0qF1MVOiPdvsoT?= =?us-ascii?Q?rQQ5UWwcFD6h++pJRtaYAs0C+nUc9goj4CFBgjdYM+L4Dlgz5tEzQlMNUsnq?= =?us-ascii?Q?XSXVhlVhkhC9yEZcOc5IrfZuT2dzHSy7+Qbe5nInBellfHBl+CWcEpWn/jjl?= =?us-ascii?Q?wX9HL0m1ighHydAXVY+AV2URNDoOpHzWjwqPs8PpDN+JOoS9P98XRkJjFge+?= =?us-ascii?Q?4Yje34H5B0XWticmtwtHcMefFIsWWY2QXorWYako3rd0RzGNYZyuYX2uCp8i?= =?us-ascii?Q?sVTcOvSqj/a8gFakwJ+4nV154Vi4eug2Wo+C5oGTWB4Hswx1HebZVaMqKvKR?= =?us-ascii?Q?GbCdRkVX22oK6iyaAiiYpf5nB1Ep2AUAYg+Qx7ut96diFZLdXYFfNfoFZwVG?= =?us-ascii?Q?ussF8YCLj236NHMPrisyvb5av6Siy21oV3RqJshiJW95ZfJqpRrmbUTOdTCn?= =?us-ascii?Q?J9a7MZ47?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 95a27da3-82a5-4fa4-cf2a-08d8c89cb345 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2663.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2021 23:37:42.3473 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Zk+fQUFRjPWPo8X09lgguRz1ZQvV/Q3+611J76qZ14X/Exg/9tU5P18MdXg55YsgQonrvMBApO+7wQjpLqZc+A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4784 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9884 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 mlxlogscore=999 phishscore=0 spamscore=0 suspectscore=0 malwarescore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102030143 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9884 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 adultscore=0 priorityscore=1501 impostorscore=0 malwarescore=0 clxscore=1015 spamscore=0 lowpriorityscore=0 phishscore=0 mlxlogscore=999 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102030143 X-ZohoMail-DKIM: pass (identity @oracle.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This is just to define new enumerated type without functional change. The 'SWIOTLB_LO' is to index legacy 32-bit swiotlb buffer, while the 'SWIOTLB_HI' is to index the 64-bit buffer. This is to prepare to enable 64-bit swiotlb. Cc: Joe Jin Signed-off-by: Dongli Zhang --- include/linux/swiotlb.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index d9c9fc9ca5d2..ca125c1b1281 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -17,6 +17,12 @@ enum swiotlb_force { SWIOTLB_NO_FORCE, /* swiotlb=3Dnoforce */ }; =20 +enum swiotlb_t { + SWIOTLB_LO, + SWIOTLB_HI, + SWIOTLB_MAX, +}; + /* * Maximum allowable number of contiguous slabs to map, * must be a power of 2. What is the appropriate value ? --=20 2.17.1 From nobody Tue May 7 02:35:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1dmarc=pass fromdomain=oracle.com); dmarc=pass(p=none dis=none) header.from=oracle.com ARC-Seal: i=2; a=rsa-sha256; t=1612395563; cv=pass; d=zohomail.com; s=zohoarc; b=X/kXe+PhExV639/lnKHtUQdYICn/EhQ+gTJdL8CDRdn6fMpeADJKHMfiEcUY9BUrOMKxnaPgpJZzdPVmy7nBnBzP6V3VJhAkGRXFNczJQ3tFF8NRaPrUC4upGiiayj8iH1ARLSV1N685/Yr+ErEjGNQlRwFu6RT8B/zMwiFITww= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612395563; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=RuMDDnvFCWO4p61oFgjtmLkCJi31pcutirwlqEiaVDs=; b=WV4Vr74NPQEQCdOL0czogpSD0kEesesFBNPHzmsYQckN1esnk36iNhtEtvvrFtMKXXFEdiucAV6qGTr0TYA+pHDYH3IPtsd5b4FzoIFswto1qJJ05x42BP8WabQPh+9XJBCpf/1ICAQDo1ycWSl8DxJ5d8getsg1Zr5LaxzOy2M= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1dmarc=pass fromdomain=oracle.com); dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1612395563620518.5585933919173; Wed, 3 Feb 2021 15:39:23 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.81096.149231 (Exim 4.92) (envelope-from ) id 1l7Rjq-0006LH-Ej; Wed, 03 Feb 2021 23:39:10 +0000 Received: by outflank-mailman (output) from mailman id 81096.149231; Wed, 03 Feb 2021 23:39:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l7Rjq-0006LA-Ae; Wed, 03 Feb 2021 23:39:10 +0000 Received: by outflank-mailman (input) for mailman id 81096; Wed, 03 Feb 2021 23:39:09 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l7Rjp-00060K-GN for xen-devel@lists.xenproject.org; Wed, 03 Feb 2021 23:39:09 +0000 Received: from aserp2120.oracle.com (unknown [141.146.126.78]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id f2930d99-fdfb-415f-9161-dc035662ec49; Wed, 03 Feb 2021 23:38:53 +0000 (UTC) Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 113N94Pp103917; Wed, 3 Feb 2021 23:37:52 GMT Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 36cydm2q1a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 Feb 2021 23:37:52 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 113NB4Nf025252; Wed, 3 Feb 2021 23:37:52 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2174.outbound.protection.outlook.com [104.47.56.174]) by aserp3020.oracle.com with ESMTP id 36dhc1wj64-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 Feb 2021 23:37:51 +0000 Received: from BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) by SJ0PR10MB4784.namprd10.prod.outlook.com (2603:10b6:a03:2d4::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.19; Wed, 3 Feb 2021 23:37:48 +0000 Received: from BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::b52e:bdd3:d193:4d14]) by BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::b52e:bdd3:d193:4d14%7]) with mapi id 15.20.3805.026; Wed, 3 Feb 2021 23:37:48 +0000 Received: from localhost.localdomain (138.3.200.16) by CH0PR03CA0008.namprd03.prod.outlook.com (2603:10b6:610:b0::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3825.17 via Frontend Transport; Wed, 3 Feb 2021 23:37:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: f2930d99-fdfb-415f-9161-dc035662ec49 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=RuMDDnvFCWO4p61oFgjtmLkCJi31pcutirwlqEiaVDs=; b=ymt145DO0qO8TYm1a8EXesRs01fgiJRugSzEz3L8IRKdQBTYNNcfAUB+RSZT40m0lM39 hT0O4IvkHJaQ3YjxBzh7fjBnWopdXNkkdzlGOnCTK+p7wr7kvSY7xYESFGKQfGNX/5AK 4wDAnYH83AMb50mWUSaasQk4TwKZDassXFqS6DbdFsL+GGA9K3Y6JNC3/hybO0fpiY6b cWuYhdxXTgMmDeQ/jHkvmpjk2ufoDbruAHJ73uSOB1/lYzO+9wak7PU7G3VIk9kuUTzE dLPLyCl3O1c3gqLwNfxmUuvWIya8O820xwCbtkv8ZZIA3Mhoy++AsgHriwsanUEndgAM RQ== ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kHORM4V2tKdZdkRvag6BlOp1gQc6R3pnvwq4BJ05MpTLvFoH8CiLTNWzFjD5mORYszDmIQBOy66uGDYUw/owH7Gq5WnziLRoztgLfcjzbML2I+VcP/YmZ0YtqkZ/jFZVAStF00fkT4IIWoSkm3XLUP0A3fCBK727jkxBbw225t6FbWR5ZI6pigIgjU+y5JP5/41iNhRGir209Uew0ZdwkMFuIXIw7q649aWD5mjXE8CmOWPL7j0FynJfZt4k2YHtlMyRP7Z4x9yq85r5eElean/5WxDslhQ5j6ChYGIfDqNiMRfct/zi6i5GBKkjVtocdlyIabR9VdWrHDZU0QfJCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RuMDDnvFCWO4p61oFgjtmLkCJi31pcutirwlqEiaVDs=; b=lYqaTZ1gCuE0IaPruIsmjn+pEnTEG8UFYUTHtgKUmO2pAPbraM8USj+TQyiDb+9OLGoihxSc9KJYD6/rNsGzChdJSAsmu+MtCYS0cdv81qpQ+aMWwBA/wq2Fg0ewMOm3EGbKzJm3c8wGlfQ8ZuLccr0BRBQvtPMqwp2/uc3ftgUyckKQ5XqeAsAPe6wf4dz4he2e3LQ+G77YnSVfS4/LTI6nycd/nitj0KAAXo93Wo1w7JYbQXbkED0bQI6lF4+Thl/u5iUPu4mmmkZYD+6JnnlzUOKt9k6D8BbMtf8k0zU2xUOLeFZNti6gK34KhnAqdHe6ZFFZ83xaV3dEoNPR0w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RuMDDnvFCWO4p61oFgjtmLkCJi31pcutirwlqEiaVDs=; b=KkkR4pWcwFNIbO525g642zO5aq6uRD472cAQzoWX9B9gnmZsp86vDwMDZMJWv9XzLoktBUgh8Q/RhcbTzZI1CrxP3E2z6Q6bsmZ+eV7pczJDUgT/RPy6direwT+yBCBUg0IlsigTH14Aysxhi912DxXdyYxeL+j/nWCHp4XxKag= Authentication-Results: lists.freedesktop.org; dkim=none (message not signed) header.d=none;lists.freedesktop.org; dmarc=none action=none header.from=oracle.com; From: Dongli Zhang To: dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, iommu@lists.linux-foundation.org, linux-mips@vger.kernel.org, linux-mmc@vger.kernel.org, linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, nouveau@lists.freedesktop.org, x86@kernel.org, xen-devel@lists.xenproject.org Cc: linux-kernel@vger.kernel.org, adrian.hunter@intel.com, akpm@linux-foundation.org, benh@kernel.crashing.org, bskeggs@redhat.com, bhelgaas@google.com, bp@alien8.de, boris.ostrovsky@oracle.com, hch@lst.de, chris@chris-wilson.co.uk, daniel@ffwll.ch, airlied@linux.ie, hpa@zytor.com, mingo@kernel.org, mingo@redhat.com, jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com, jgross@suse.com, konrad.wilk@oracle.com, m.szyprowski@samsung.com, matthew.auld@intel.com, mpe@ellerman.id.au, rppt@kernel.org, paulus@samba.org, peterz@infradead.org, robin.murphy@arm.com, rodrigo.vivi@intel.com, sstabellini@kernel.org, bauerman@linux.ibm.com, tsbogend@alpha.franken.de, tglx@linutronix.de, ulf.hansson@linaro.org, joe.jin@oracle.com, thomas.lendacky@amd.com Subject: [PATCH RFC v1 2/6] swiotlb: convert variables to arrays Date: Wed, 3 Feb 2021 15:37:05 -0800 Message-Id: <20210203233709.19819-3-dongli.zhang@oracle.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210203233709.19819-1-dongli.zhang@oracle.com> References: <20210203233709.19819-1-dongli.zhang@oracle.com> X-Originating-IP: [138.3.200.16] X-ClientProxiedBy: CH0PR03CA0008.namprd03.prod.outlook.com (2603:10b6:610:b0::13) To BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6944969b-97db-45a0-60c0-08d8c89cb6bb X-MS-TrafficTypeDiagnostic: SJ0PR10MB4784: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:519; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Nr78D0BKtGfvFg+Zfn+Ls1e+J8xHXLnIJvc4gVLi+ug2eClaIcZ6uhzFtYpjSTwp7e7R5plVXJ8NBrg9zON7LXhMatgSgfyGlEx91DqGFigMBLa4Nmq/47L/XpbNffcydvVTC0kxSIp97xQFN+wQj1yexDtR8ALIiO/dbrPMKOsdPxwSxtOSZoGgo21vH2w2zIPpeitK5rCORhh3jWnaWj/PfWhFWAUAysHzS3e0HzAybFNCXagGOyl4jmAoEWOG+BCGOTBBAkc1HA96vI0nujtkQssrb/WEJlDSa/h/cS+42jr4R2iEsogttCi/42xJGvKGof0y+JmB8c+0RQuGOfh/cmeSJTGOSEmS3xv9JBpUqJu4VWPBGhu288UKCmvW6rsIgd644MWC8WWJvZxQMmZUI8D/uaKp3kL92CaeLj4qk4nYG5n/0JJjnblSYTBdejKWy9hJ31wAgQ9Lu7C0hdDQiUxmZjM23VdjADjiGmUJGAJozKbN4McGomAArxPJWcYNMObna0G4jz412XvSAGLyJqlJ4Juxlc8uRj4OJmaMTg4XXTUAXWfuHXhDlH3yU0+DSq21chBMad/htHBMrEvB60yr4BTBW4ER+x38C3M= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB2663.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(366004)(39860400002)(396003)(376002)(346002)(83380400001)(6666004)(316002)(5660300002)(956004)(66946007)(6506007)(86362001)(7406005)(1076003)(66476007)(8676002)(186003)(26005)(36756003)(7416002)(30864003)(478600001)(2906002)(66556008)(8936002)(6486002)(16526019)(69590400011)(4326008)(6512007)(44832011)(921005)(2616005)(52116002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?WYrdUlsRpAm3qmPfNVC56GiDTxiaAAF5RDWBwCeb1MA7PZAa7AztQi35fgIg?= =?us-ascii?Q?joIVm+NsV+Ah7jJJGlV4C/3sLzdgeF3L222clfsCi59UaNnXDM4oTZRfOt0F?= =?us-ascii?Q?3UmtvFrkybHGvmbWbt6paglrSI3R/dBm0mGWzhWP51NkHkfEsY0QzUaBQ9MI?= =?us-ascii?Q?I5VeiExjTUj3mUkymQUcuJZD67uvmuZlkfAqKNnN6onUgkYRAdghXc8VyYaQ?= =?us-ascii?Q?kw2+Qka/eHlnHvDUdFPSurF2/oEGXe2OkaM4FzGUOO5df5PuqVVzYCsbO5pd?= =?us-ascii?Q?PsvPjOIs5t/ppnFbTmyGjqJewvY8+PM+KV34tZFig6vdx2YTXtsLQSYXOb7b?= =?us-ascii?Q?Xnp+m4waCuEnynwdXSxRIAyD2DM14JPtzR3vtMuklmjsFla3p/wSLj5+TeXa?= =?us-ascii?Q?EACzsAHOM/MXDubyFke02eTC1jtUsNcSnXt51XpDgXgtROTmvVQigPmfoDrJ?= =?us-ascii?Q?ph4CQqa+zNk/LjkzYKIX7GUon18vkSWT+Z69KRioyesR/l2g1mU06fVzLlD4?= =?us-ascii?Q?Nk0KxBGumDhO5E49v/gLbzBJne6BGW9N4STIsLKj3xLwiFbQz4Mhhphw/k/D?= =?us-ascii?Q?dNKtAgmt/SKWp71gjcNdpdgdUVDvOFh2+iCb/IlAOhYTcnbkKmFyuLl/Bjsn?= =?us-ascii?Q?6tOPAQ5K0mSk+3L5Iqpm6Aj9e8aYDi1aReE3eE3ZsPNPqOFS+VVQRUBdiKA+?= =?us-ascii?Q?LWRN/aBP0m8D9w20N6d6nvI21mehLFfnG8KtJrxFy64I06UymiZFX2mZiNPG?= =?us-ascii?Q?+Pq9fErWxR74DBC1KJn/LpDvK1Aoi5dfWK3BMZPPUoPhQD7JMXaCOtSVr7xm?= =?us-ascii?Q?UTi19khibasCepAGlaohSQQWMzSOR9LIqKoWlk/AM1VJgZmQmXRwSe2IR/OG?= =?us-ascii?Q?MsvNEI3rfRIOhwIuHT0xaT8N3qalx33VhrStF+SQCoHvKwT7wL47xmvXUaP2?= =?us-ascii?Q?JoUGpiMn39DHFhMecx22MHUd+nVE/Ty3GireUN5CgFbhJv/Rbh/YTnWUsvqu?= =?us-ascii?Q?exuwJp1rqFe2wPt7gVRWU6wPpFrv/m1BWe6h3K15s8HVGR1g5f4oCessiCAo?= =?us-ascii?Q?G/u7pE2P?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6944969b-97db-45a0-60c0-08d8c89cb6bb X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2663.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2021 23:37:48.2080 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: F2kKZBo1cJuaZ1vlofMVuU/CWkd5ocmk3yTATYVa2qs0VNH9hXYDL5HmeRJwljQjfwSD3en40D8igro5q/vAyg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4784 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9884 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 adultscore=0 suspectscore=0 spamscore=0 mlxscore=0 malwarescore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102030143 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9884 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 adultscore=0 priorityscore=1501 impostorscore=0 malwarescore=0 clxscore=1015 spamscore=0 lowpriorityscore=0 phishscore=0 mlxlogscore=999 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102030143 X-ZohoMail-DKIM: pass (identity @oracle.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch converts several swiotlb related variables to arrays, in order to maintain stat/status for different swiotlb buffers. Here are variables involved: - io_tlb_start and io_tlb_end - io_tlb_nslabs and io_tlb_used - io_tlb_list - io_tlb_index - max_segment - io_tlb_orig_addr - no_iotlb_memory There is no functional change and this is to prepare to enable 64-bit swiotlb. Cc: Joe Jin Signed-off-by: Dongli Zhang --- arch/powerpc/platforms/pseries/svm.c | 6 +- drivers/xen/swiotlb-xen.c | 4 +- include/linux/swiotlb.h | 5 +- kernel/dma/swiotlb.c | 257 ++++++++++++++------------- 4 files changed, 140 insertions(+), 132 deletions(-) diff --git a/arch/powerpc/platforms/pseries/svm.c b/arch/powerpc/platforms/= pseries/svm.c index 7b739cc7a8a9..9f8842d0da1f 100644 --- a/arch/powerpc/platforms/pseries/svm.c +++ b/arch/powerpc/platforms/pseries/svm.c @@ -55,9 +55,9 @@ void __init svm_swiotlb_init(void) if (vstart && !swiotlb_init_with_tbl(vstart, io_tlb_nslabs, false)) return; =20 - if (io_tlb_start) - memblock_free_early(io_tlb_start, - PAGE_ALIGN(io_tlb_nslabs << IO_TLB_SHIFT)); + if (io_tlb_start[SWIOTLB_LO]) + memblock_free_early(io_tlb_start[SWIOTLB_LO], + PAGE_ALIGN(io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT)); panic("SVM: Cannot allocate SWIOTLB buffer"); } =20 diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 2b385c1b4a99..3261880ad859 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -192,8 +192,8 @@ int __ref xen_swiotlb_init(int verbose, bool early) /* * IO TLB memory already allocated. Just use it. */ - if (io_tlb_start !=3D 0) { - xen_io_tlb_start =3D phys_to_virt(io_tlb_start); + if (io_tlb_start[SWIOTLB_LO] !=3D 0) { + xen_io_tlb_start =3D phys_to_virt(io_tlb_start[SWIOTLB_LO]); goto end; } =20 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index ca125c1b1281..777046cd4d1b 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -76,11 +76,12 @@ dma_addr_t swiotlb_map(struct device *dev, phys_addr_t = phys, =20 #ifdef CONFIG_SWIOTLB extern enum swiotlb_force swiotlb_force; -extern phys_addr_t io_tlb_start, io_tlb_end; +extern phys_addr_t io_tlb_start[], io_tlb_end[]; =20 static inline bool is_swiotlb_buffer(phys_addr_t paddr) { - return paddr >=3D io_tlb_start && paddr < io_tlb_end; + return paddr >=3D io_tlb_start[SWIOTLB_LO] && + paddr < io_tlb_end[SWIOTLB_LO]; } =20 void __init swiotlb_exit(void); diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 7c42df6e6100..1fbb65daa2dd 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -69,38 +69,38 @@ enum swiotlb_force swiotlb_force; * swiotlb_tbl_sync_single_*, to see if the memory was in fact allocated b= y this * API. */ -phys_addr_t io_tlb_start, io_tlb_end; +phys_addr_t io_tlb_start[SWIOTLB_MAX], io_tlb_end[SWIOTLB_MAX]; =20 /* * The number of IO TLB blocks (in groups of 64) between io_tlb_start and * io_tlb_end. This is command line adjustable via setup_io_tlb_npages. */ -static unsigned long io_tlb_nslabs; +static unsigned long io_tlb_nslabs[SWIOTLB_MAX]; =20 /* * The number of used IO TLB block */ -static unsigned long io_tlb_used; +static unsigned long io_tlb_used[SWIOTLB_MAX]; =20 /* * This is a free list describing the number of free entries available from * each index */ -static unsigned int *io_tlb_list; -static unsigned int io_tlb_index; +static unsigned int *io_tlb_list[SWIOTLB_MAX]; +static unsigned int io_tlb_index[SWIOTLB_MAX]; =20 /* * Max segment that we can provide which (if pages are contingous) will * not be bounced (unless SWIOTLB_FORCE is set). */ -static unsigned int max_segment; +static unsigned int max_segment[SWIOTLB_MAX]; =20 /* * We need to save away the original address corresponding to a mapped ent= ry * for the sync operations. */ #define INVALID_PHYS_ADDR (~(phys_addr_t)0) -static phys_addr_t *io_tlb_orig_addr; +static phys_addr_t *io_tlb_orig_addr[SWIOTLB_MAX]; =20 /* * Protect the above data structures in the map and unmap calls @@ -113,9 +113,9 @@ static int __init setup_io_tlb_npages(char *str) { if (isdigit(*str)) { - io_tlb_nslabs =3D simple_strtoul(str, &str, 0); + io_tlb_nslabs[SWIOTLB_LO] =3D simple_strtoul(str, &str, 0); /* avoid tail segment of size < IO_TLB_SEGSIZE */ - io_tlb_nslabs =3D ALIGN(io_tlb_nslabs, IO_TLB_SEGSIZE); + io_tlb_nslabs[SWIOTLB_LO] =3D ALIGN(io_tlb_nslabs[SWIOTLB_LO], IO_TLB_SE= GSIZE); } if (*str =3D=3D ',') ++str; @@ -123,40 +123,40 @@ setup_io_tlb_npages(char *str) swiotlb_force =3D SWIOTLB_FORCE; } else if (!strcmp(str, "noforce")) { swiotlb_force =3D SWIOTLB_NO_FORCE; - io_tlb_nslabs =3D 1; + io_tlb_nslabs[SWIOTLB_LO] =3D 1; } =20 return 0; } early_param("swiotlb", setup_io_tlb_npages); =20 -static bool no_iotlb_memory; +static bool no_iotlb_memory[SWIOTLB_MAX]; =20 unsigned long swiotlb_nr_tbl(void) { - return unlikely(no_iotlb_memory) ? 0 : io_tlb_nslabs; + return unlikely(no_iotlb_memory[SWIOTLB_LO]) ? 0 : io_tlb_nslabs[SWIOTLB_= LO]; } EXPORT_SYMBOL_GPL(swiotlb_nr_tbl); =20 unsigned int swiotlb_max_segment(void) { - return unlikely(no_iotlb_memory) ? 0 : max_segment; + return unlikely(no_iotlb_memory[SWIOTLB_LO]) ? 0 : max_segment[SWIOTLB_LO= ]; } EXPORT_SYMBOL_GPL(swiotlb_max_segment); =20 void swiotlb_set_max_segment(unsigned int val) { if (swiotlb_force =3D=3D SWIOTLB_FORCE) - max_segment =3D 1; + max_segment[SWIOTLB_LO] =3D 1; else - max_segment =3D rounddown(val, PAGE_SIZE); + max_segment[SWIOTLB_LO] =3D rounddown(val, PAGE_SIZE); } =20 unsigned long swiotlb_size_or_default(void) { unsigned long size; =20 - size =3D io_tlb_nslabs << IO_TLB_SHIFT; + size =3D io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT; =20 return size ? size : (IO_TLB_DEFAULT_SIZE); } @@ -170,10 +170,10 @@ void __init swiotlb_adjust_size(unsigned long new_siz= e) * architectures such as those supporting memory encryption to * adjust/expand SWIOTLB size for their use. */ - if (!io_tlb_nslabs) { + if (!io_tlb_nslabs[SWIOTLB_LO]) { size =3D ALIGN(new_size, 1 << IO_TLB_SHIFT); - io_tlb_nslabs =3D size >> IO_TLB_SHIFT; - io_tlb_nslabs =3D ALIGN(io_tlb_nslabs, IO_TLB_SEGSIZE); + io_tlb_nslabs[SWIOTLB_LO] =3D size >> IO_TLB_SHIFT; + io_tlb_nslabs[SWIOTLB_LO] =3D ALIGN(io_tlb_nslabs[SWIOTLB_LO], IO_TLB_SE= GSIZE); =20 pr_info("SWIOTLB bounce buffer size adjusted to %luMB", size >> 20); } @@ -181,15 +181,16 @@ void __init swiotlb_adjust_size(unsigned long new_siz= e) =20 void swiotlb_print_info(void) { - unsigned long bytes =3D io_tlb_nslabs << IO_TLB_SHIFT; + unsigned long bytes =3D io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT; =20 - if (no_iotlb_memory) { + if (no_iotlb_memory[SWIOTLB_LO]) { pr_warn("No low mem\n"); return; } =20 - pr_info("mapped [mem %pa-%pa] (%luMB)\n", &io_tlb_start, &io_tlb_end, - bytes >> 20); + pr_info("mapped [mem %pa-%pa] (%luMB)\n", + &io_tlb_start[SWIOTLB_LO], &io_tlb_end[SWIOTLB_LO], + bytes >> 20); } =20 /* @@ -203,11 +204,11 @@ void __init swiotlb_update_mem_attributes(void) void *vaddr; unsigned long bytes; =20 - if (no_iotlb_memory || late_alloc) + if (no_iotlb_memory[SWIOTLB_LO] || late_alloc) return; =20 - vaddr =3D phys_to_virt(io_tlb_start); - bytes =3D PAGE_ALIGN(io_tlb_nslabs << IO_TLB_SHIFT); + vaddr =3D phys_to_virt(io_tlb_start[SWIOTLB_LO]); + bytes =3D PAGE_ALIGN(io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT); set_memory_decrypted((unsigned long)vaddr, bytes >> PAGE_SHIFT); memset(vaddr, 0, bytes); } @@ -219,38 +220,38 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned = long nslabs, int verbose) =20 bytes =3D nslabs << IO_TLB_SHIFT; =20 - io_tlb_nslabs =3D nslabs; - io_tlb_start =3D __pa(tlb); - io_tlb_end =3D io_tlb_start + bytes; + io_tlb_nslabs[SWIOTLB_LO] =3D nslabs; + io_tlb_start[SWIOTLB_LO] =3D __pa(tlb); + io_tlb_end[SWIOTLB_LO] =3D io_tlb_start[SWIOTLB_LO] + bytes; =20 /* * Allocate and initialize the free list array. This array is used * to find contiguous free memory regions of size up to IO_TLB_SEGSIZE * between io_tlb_start and io_tlb_end. */ - alloc_size =3D PAGE_ALIGN(io_tlb_nslabs * sizeof(int)); - io_tlb_list =3D memblock_alloc(alloc_size, PAGE_SIZE); - if (!io_tlb_list) + alloc_size =3D PAGE_ALIGN(io_tlb_nslabs[SWIOTLB_LO] * sizeof(int)); + io_tlb_list[SWIOTLB_LO] =3D memblock_alloc(alloc_size, PAGE_SIZE); + if (!io_tlb_list[SWIOTLB_LO]) panic("%s: Failed to allocate %zu bytes align=3D0x%lx\n", __func__, alloc_size, PAGE_SIZE); =20 - alloc_size =3D PAGE_ALIGN(io_tlb_nslabs * sizeof(phys_addr_t)); - io_tlb_orig_addr =3D memblock_alloc(alloc_size, PAGE_SIZE); - if (!io_tlb_orig_addr) + alloc_size =3D PAGE_ALIGN(io_tlb_nslabs[SWIOTLB_LO] * sizeof(phys_addr_t)= ); + io_tlb_orig_addr[SWIOTLB_LO] =3D memblock_alloc(alloc_size, PAGE_SIZE); + if (!io_tlb_orig_addr[SWIOTLB_LO]) panic("%s: Failed to allocate %zu bytes align=3D0x%lx\n", __func__, alloc_size, PAGE_SIZE); =20 - for (i =3D 0; i < io_tlb_nslabs; i++) { - io_tlb_list[i] =3D IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE); - io_tlb_orig_addr[i] =3D INVALID_PHYS_ADDR; + for (i =3D 0; i < io_tlb_nslabs[SWIOTLB_LO]; i++) { + io_tlb_list[SWIOTLB_LO][i] =3D IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE= ); + io_tlb_orig_addr[SWIOTLB_LO][i] =3D INVALID_PHYS_ADDR; } - io_tlb_index =3D 0; - no_iotlb_memory =3D false; + io_tlb_index[SWIOTLB_LO] =3D 0; + no_iotlb_memory[SWIOTLB_LO] =3D false; =20 if (verbose) swiotlb_print_info(); =20 - swiotlb_set_max_segment(io_tlb_nslabs << IO_TLB_SHIFT); + swiotlb_set_max_segment(io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT); return 0; } =20 @@ -265,25 +266,25 @@ swiotlb_init(int verbose) unsigned char *vstart; unsigned long bytes; =20 - if (!io_tlb_nslabs) { - io_tlb_nslabs =3D (default_size >> IO_TLB_SHIFT); - io_tlb_nslabs =3D ALIGN(io_tlb_nslabs, IO_TLB_SEGSIZE); + if (!io_tlb_nslabs[SWIOTLB_LO]) { + io_tlb_nslabs[SWIOTLB_LO] =3D (default_size >> IO_TLB_SHIFT); + io_tlb_nslabs[SWIOTLB_LO] =3D ALIGN(io_tlb_nslabs[SWIOTLB_LO], IO_TLB_SE= GSIZE); } =20 - bytes =3D io_tlb_nslabs << IO_TLB_SHIFT; + bytes =3D io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT; =20 /* Get IO TLB memory from the low pages */ vstart =3D memblock_alloc_low(PAGE_ALIGN(bytes), PAGE_SIZE); - if (vstart && !swiotlb_init_with_tbl(vstart, io_tlb_nslabs, verbose)) + if (vstart && !swiotlb_init_with_tbl(vstart, io_tlb_nslabs[SWIOTLB_LO], v= erbose)) return; =20 - if (io_tlb_start) { - memblock_free_early(io_tlb_start, - PAGE_ALIGN(io_tlb_nslabs << IO_TLB_SHIFT)); - io_tlb_start =3D 0; + if (io_tlb_start[SWIOTLB_LO]) { + memblock_free_early(io_tlb_start[SWIOTLB_LO], + PAGE_ALIGN(io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT)); + io_tlb_start[SWIOTLB_LO] =3D 0; } pr_warn("Cannot allocate buffer"); - no_iotlb_memory =3D true; + no_iotlb_memory[SWIOTLB_LO] =3D true; } =20 /* @@ -294,22 +295,22 @@ swiotlb_init(int verbose) int swiotlb_late_init_with_default_size(size_t default_size) { - unsigned long bytes, req_nslabs =3D io_tlb_nslabs; + unsigned long bytes, req_nslabs =3D io_tlb_nslabs[SWIOTLB_LO]; unsigned char *vstart =3D NULL; unsigned int order; int rc =3D 0; =20 - if (!io_tlb_nslabs) { - io_tlb_nslabs =3D (default_size >> IO_TLB_SHIFT); - io_tlb_nslabs =3D ALIGN(io_tlb_nslabs, IO_TLB_SEGSIZE); + if (!io_tlb_nslabs[SWIOTLB_LO]) { + io_tlb_nslabs[SWIOTLB_LO] =3D (default_size >> IO_TLB_SHIFT); + io_tlb_nslabs[SWIOTLB_LO] =3D ALIGN(io_tlb_nslabs[SWIOTLB_LO], IO_TLB_SE= GSIZE); } =20 /* * Get IO TLB memory from the low pages */ - order =3D get_order(io_tlb_nslabs << IO_TLB_SHIFT); - io_tlb_nslabs =3D SLABS_PER_PAGE << order; - bytes =3D io_tlb_nslabs << IO_TLB_SHIFT; + order =3D get_order(io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT); + io_tlb_nslabs[SWIOTLB_LO] =3D SLABS_PER_PAGE << order; + bytes =3D io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT; =20 while ((SLABS_PER_PAGE << order) > IO_TLB_MIN_SLABS) { vstart =3D (void *)__get_free_pages(GFP_DMA | __GFP_NOWARN, @@ -320,15 +321,15 @@ swiotlb_late_init_with_default_size(size_t default_si= ze) } =20 if (!vstart) { - io_tlb_nslabs =3D req_nslabs; + io_tlb_nslabs[SWIOTLB_LO] =3D req_nslabs; return -ENOMEM; } if (order !=3D get_order(bytes)) { pr_warn("only able to allocate %ld MB\n", (PAGE_SIZE << order) >> 20); - io_tlb_nslabs =3D SLABS_PER_PAGE << order; + io_tlb_nslabs[SWIOTLB_LO] =3D SLABS_PER_PAGE << order; } - rc =3D swiotlb_late_init_with_tbl(vstart, io_tlb_nslabs); + rc =3D swiotlb_late_init_with_tbl(vstart, io_tlb_nslabs[SWIOTLB_LO]); if (rc) free_pages((unsigned long)vstart, order); =20 @@ -337,10 +338,10 @@ swiotlb_late_init_with_default_size(size_t default_si= ze) =20 static void swiotlb_cleanup(void) { - io_tlb_end =3D 0; - io_tlb_start =3D 0; - io_tlb_nslabs =3D 0; - max_segment =3D 0; + io_tlb_end[SWIOTLB_LO] =3D 0; + io_tlb_start[SWIOTLB_LO] =3D 0; + io_tlb_nslabs[SWIOTLB_LO] =3D 0; + max_segment[SWIOTLB_LO] =3D 0; } =20 int @@ -350,9 +351,9 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nsl= abs) =20 bytes =3D nslabs << IO_TLB_SHIFT; =20 - io_tlb_nslabs =3D nslabs; - io_tlb_start =3D virt_to_phys(tlb); - io_tlb_end =3D io_tlb_start + bytes; + io_tlb_nslabs[SWIOTLB_LO] =3D nslabs; + io_tlb_start[SWIOTLB_LO] =3D virt_to_phys(tlb); + io_tlb_end[SWIOTLB_LO] =3D io_tlb_start[SWIOTLB_LO] + bytes; =20 set_memory_decrypted((unsigned long)tlb, bytes >> PAGE_SHIFT); memset(tlb, 0, bytes); @@ -362,37 +363,37 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long n= slabs) * to find contiguous free memory regions of size up to IO_TLB_SEGSIZE * between io_tlb_start and io_tlb_end. */ - io_tlb_list =3D (unsigned int *)__get_free_pages(GFP_KERNEL, - get_order(io_tlb_nslabs * sizeof(int))); - if (!io_tlb_list) + io_tlb_list[SWIOTLB_LO] =3D (unsigned int *)__get_free_pages(GFP_KERNEL, + get_order(io_tlb_nslabs[SWIOTLB_LO] * sizeof(int))); + if (!io_tlb_list[SWIOTLB_LO]) goto cleanup3; =20 - io_tlb_orig_addr =3D (phys_addr_t *) + io_tlb_orig_addr[SWIOTLB_LO] =3D (phys_addr_t *) __get_free_pages(GFP_KERNEL, - get_order(io_tlb_nslabs * + get_order(io_tlb_nslabs[SWIOTLB_LO] * sizeof(phys_addr_t))); - if (!io_tlb_orig_addr) + if (!io_tlb_orig_addr[SWIOTLB_LO]) goto cleanup4; =20 - for (i =3D 0; i < io_tlb_nslabs; i++) { - io_tlb_list[i] =3D IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE); - io_tlb_orig_addr[i] =3D INVALID_PHYS_ADDR; + for (i =3D 0; i < io_tlb_nslabs[SWIOTLB_LO]; i++) { + io_tlb_list[SWIOTLB_LO][i] =3D IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE= ); + io_tlb_orig_addr[SWIOTLB_LO][i] =3D INVALID_PHYS_ADDR; } - io_tlb_index =3D 0; - no_iotlb_memory =3D false; + io_tlb_index[SWIOTLB_LO] =3D 0; + no_iotlb_memory[SWIOTLB_LO] =3D false; =20 swiotlb_print_info(); =20 late_alloc =3D 1; =20 - swiotlb_set_max_segment(io_tlb_nslabs << IO_TLB_SHIFT); + swiotlb_set_max_segment(io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT); =20 return 0; =20 cleanup4: - free_pages((unsigned long)io_tlb_list, get_order(io_tlb_nslabs * + free_pages((unsigned long)io_tlb_list[SWIOTLB_LO], get_order(io_tlb_nslab= s[SWIOTLB_LO] * sizeof(int))); - io_tlb_list =3D NULL; + io_tlb_list[SWIOTLB_LO] =3D NULL; cleanup3: swiotlb_cleanup(); return -ENOMEM; @@ -400,23 +401,23 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long n= slabs) =20 void __init swiotlb_exit(void) { - if (!io_tlb_orig_addr) + if (!io_tlb_orig_addr[SWIOTLB_LO]) return; =20 if (late_alloc) { - free_pages((unsigned long)io_tlb_orig_addr, - get_order(io_tlb_nslabs * sizeof(phys_addr_t))); - free_pages((unsigned long)io_tlb_list, get_order(io_tlb_nslabs * - sizeof(int))); - free_pages((unsigned long)phys_to_virt(io_tlb_start), - get_order(io_tlb_nslabs << IO_TLB_SHIFT)); + free_pages((unsigned long)io_tlb_orig_addr[SWIOTLB_LO], + get_order(io_tlb_nslabs[SWIOTLB_LO] * sizeof(phys_addr_t))); + free_pages((unsigned long)io_tlb_list[SWIOTLB_LO], + get_order(io_tlb_nslabs[SWIOTLB_LO] * sizeof(int))); + free_pages((unsigned long)phys_to_virt(io_tlb_start[SWIOTLB_LO]), + get_order(io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT)); } else { - memblock_free_late(__pa(io_tlb_orig_addr), - PAGE_ALIGN(io_tlb_nslabs * sizeof(phys_addr_t))); - memblock_free_late(__pa(io_tlb_list), - PAGE_ALIGN(io_tlb_nslabs * sizeof(int))); - memblock_free_late(io_tlb_start, - PAGE_ALIGN(io_tlb_nslabs << IO_TLB_SHIFT)); + memblock_free_late(__pa(io_tlb_orig_addr[SWIOTLB_LO]), + PAGE_ALIGN(io_tlb_nslabs[SWIOTLB_LO] * sizeof(phys_addr_t))); + memblock_free_late(__pa(io_tlb_list[SWIOTLB_LO]), + PAGE_ALIGN(io_tlb_nslabs[SWIOTLB_LO] * sizeof(int))); + memblock_free_late(io_tlb_start[SWIOTLB_LO], + PAGE_ALIGN(io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT)); } swiotlb_cleanup(); } @@ -465,7 +466,7 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev= , phys_addr_t orig_addr, size_t mapping_size, size_t alloc_size, enum dma_data_direction dir, unsigned long attrs) { - dma_addr_t tbl_dma_addr =3D phys_to_dma_unencrypted(hwdev, io_tlb_start); + dma_addr_t tbl_dma_addr =3D phys_to_dma_unencrypted(hwdev, io_tlb_start[S= WIOTLB_LO]); unsigned long flags; phys_addr_t tlb_addr; unsigned int nslots, stride, index, wrap; @@ -475,7 +476,7 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev= , phys_addr_t orig_addr, unsigned long max_slots; unsigned long tmp_io_tlb_used; =20 - if (no_iotlb_memory) + if (no_iotlb_memory[SWIOTLB_LO]) panic("Can not allocate SWIOTLB buffer earlier and can't now provide you= with the DMA bounce buffer"); =20 if (mem_encrypt_active()) @@ -518,11 +519,11 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwd= ev, phys_addr_t orig_addr, */ spin_lock_irqsave(&io_tlb_lock, flags); =20 - if (unlikely(nslots > io_tlb_nslabs - io_tlb_used)) + if (unlikely(nslots > io_tlb_nslabs[SWIOTLB_LO] - io_tlb_used[SWIOTLB_LO]= )) goto not_found; =20 - index =3D ALIGN(io_tlb_index, stride); - if (index >=3D io_tlb_nslabs) + index =3D ALIGN(io_tlb_index[SWIOTLB_LO], stride); + if (index >=3D io_tlb_nslabs[SWIOTLB_LO]) index =3D 0; wrap =3D index; =20 @@ -530,7 +531,7 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev= , phys_addr_t orig_addr, while (iommu_is_span_boundary(index, nslots, offset_slots, max_slots)) { index +=3D stride; - if (index >=3D io_tlb_nslabs) + if (index >=3D io_tlb_nslabs[SWIOTLB_LO]) index =3D 0; if (index =3D=3D wrap) goto not_found; @@ -541,39 +542,42 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwd= ev, phys_addr_t orig_addr, * contiguous buffers, we allocate the buffers from that slot * and mark the entries as '0' indicating unavailable. */ - if (io_tlb_list[index] >=3D nslots) { + if (io_tlb_list[SWIOTLB_LO][index] >=3D nslots) { int count =3D 0; =20 for (i =3D index; i < (int) (index + nslots); i++) - io_tlb_list[i] =3D 0; - for (i =3D index - 1; (OFFSET(i, IO_TLB_SEGSIZE) !=3D IO_TLB_SEGSIZE - = 1) && io_tlb_list[i]; i--) - io_tlb_list[i] =3D ++count; - tlb_addr =3D io_tlb_start + (index << IO_TLB_SHIFT); + io_tlb_list[SWIOTLB_LO][i] =3D 0; + for (i =3D index - 1; + (OFFSET(i, IO_TLB_SEGSIZE) !=3D IO_TLB_SEGSIZE - 1) && + io_tlb_list[SWIOTLB_LO][i]; + i--) + io_tlb_list[SWIOTLB_LO][i] =3D ++count; + tlb_addr =3D io_tlb_start[SWIOTLB_LO] + (index << IO_TLB_SHIFT); =20 /* * Update the indices to avoid searching in the next * round. */ - io_tlb_index =3D ((index + nslots) < io_tlb_nslabs + io_tlb_index[SWIOTLB_LO] =3D ((index + nslots) < io_tlb_nslabs[SWIOTLB_= LO] ? (index + nslots) : 0); =20 goto found; } index +=3D stride; - if (index >=3D io_tlb_nslabs) + if (index >=3D io_tlb_nslabs[SWIOTLB_LO]) index =3D 0; } while (index !=3D wrap); =20 not_found: - tmp_io_tlb_used =3D io_tlb_used; + tmp_io_tlb_used =3D io_tlb_used[SWIOTLB_LO]; =20 spin_unlock_irqrestore(&io_tlb_lock, flags); if (!(attrs & DMA_ATTR_NO_WARN) && printk_ratelimit()) dev_warn(hwdev, "swiotlb buffer is full (sz: %zd bytes), total %lu (slot= s), used %lu (slots)\n", - alloc_size, io_tlb_nslabs, tmp_io_tlb_used); + alloc_size, io_tlb_nslabs[SWIOTLB_LO], tmp_io_tlb_used); return (phys_addr_t)DMA_MAPPING_ERROR; found: - io_tlb_used +=3D nslots; + io_tlb_used[SWIOTLB_LO] +=3D nslots; spin_unlock_irqrestore(&io_tlb_lock, flags); =20 /* @@ -582,7 +586,7 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev= , phys_addr_t orig_addr, * needed. */ for (i =3D 0; i < nslots; i++) - io_tlb_orig_addr[index+i] =3D orig_addr + (i << IO_TLB_SHIFT); + io_tlb_orig_addr[SWIOTLB_LO][index+i] =3D orig_addr + (i << IO_TLB_SHIFT= ); if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC) && (dir =3D=3D DMA_TO_DEVICE || dir =3D=3D DMA_BIDIRECTIONAL)) swiotlb_bounce(orig_addr, tlb_addr, mapping_size, DMA_TO_DEVICE); @@ -599,8 +603,8 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, phy= s_addr_t tlb_addr, { unsigned long flags; int i, count, nslots =3D ALIGN(alloc_size, 1 << IO_TLB_SHIFT) >> IO_TLB_S= HIFT; - int index =3D (tlb_addr - io_tlb_start) >> IO_TLB_SHIFT; - phys_addr_t orig_addr =3D io_tlb_orig_addr[index]; + int index =3D (tlb_addr - io_tlb_start[SWIOTLB_LO]) >> IO_TLB_SHIFT; + phys_addr_t orig_addr =3D io_tlb_orig_addr[SWIOTLB_LO][index]; =20 /* * First, sync the memory before unmapping the entry @@ -619,23 +623,26 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, p= hys_addr_t tlb_addr, spin_lock_irqsave(&io_tlb_lock, flags); { count =3D ((index + nslots) < ALIGN(index + 1, IO_TLB_SEGSIZE) ? - io_tlb_list[index + nslots] : 0); + io_tlb_list[SWIOTLB_LO][index + nslots] : 0); /* * Step 1: return the slots to the free list, merging the * slots with superceeding slots */ for (i =3D index + nslots - 1; i >=3D index; i--) { - io_tlb_list[i] =3D ++count; - io_tlb_orig_addr[i] =3D INVALID_PHYS_ADDR; + io_tlb_list[SWIOTLB_LO][i] =3D ++count; + io_tlb_orig_addr[SWIOTLB_LO][i] =3D INVALID_PHYS_ADDR; } /* * Step 2: merge the returned slots with the preceding slots, * if available (non zero) */ - for (i =3D index - 1; (OFFSET(i, IO_TLB_SEGSIZE) !=3D IO_TLB_SEGSIZE -1)= && io_tlb_list[i]; i--) - io_tlb_list[i] =3D ++count; + for (i =3D index - 1; + (OFFSET(i, IO_TLB_SEGSIZE) !=3D IO_TLB_SEGSIZE - 1) && + io_tlb_list[SWIOTLB_LO][i]; + i--) + io_tlb_list[SWIOTLB_LO][i] =3D ++count; =20 - io_tlb_used -=3D nslots; + io_tlb_used[SWIOTLB_LO] -=3D nslots; } spin_unlock_irqrestore(&io_tlb_lock, flags); } @@ -644,8 +651,8 @@ void swiotlb_tbl_sync_single(struct device *hwdev, phys= _addr_t tlb_addr, size_t size, enum dma_data_direction dir, enum dma_sync_target target) { - int index =3D (tlb_addr - io_tlb_start) >> IO_TLB_SHIFT; - phys_addr_t orig_addr =3D io_tlb_orig_addr[index]; + int index =3D (tlb_addr - io_tlb_start[SWIOTLB_LO]) >> IO_TLB_SHIFT; + phys_addr_t orig_addr =3D io_tlb_orig_addr[SWIOTLB_LO][index]; =20 if (orig_addr =3D=3D INVALID_PHYS_ADDR) return; @@ -716,7 +723,7 @@ bool is_swiotlb_active(void) * When SWIOTLB is initialized, even if io_tlb_start points to physical * address zero, io_tlb_end surely doesn't. */ - return io_tlb_end !=3D 0; + return io_tlb_end[SWIOTLB_LO] !=3D 0; } =20 #ifdef CONFIG_DEBUG_FS @@ -726,8 +733,8 @@ static int __init swiotlb_create_debugfs(void) struct dentry *root; =20 root =3D debugfs_create_dir("swiotlb", NULL); - debugfs_create_ulong("io_tlb_nslabs", 0400, root, &io_tlb_nslabs); - debugfs_create_ulong("io_tlb_used", 0400, root, &io_tlb_used); + debugfs_create_ulong("io_tlb_nslabs", 0400, root, &io_tlb_nslabs[SWIOTLB_= LO]); + debugfs_create_ulong("io_tlb_used", 0400, root, &io_tlb_used[SWIOTLB_LO]); return 0; } =20 --=20 2.17.1 From nobody Tue May 7 02:35:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1dmarc=pass fromdomain=oracle.com); dmarc=pass(p=none dis=none) header.from=oracle.com ARC-Seal: i=2; a=rsa-sha256; t=1612395559; cv=pass; d=zohomail.com; s=zohoarc; b=YU+5OtZqSkqzJcW6mJ4wMLaGF8wQghQcS/azGgDbQrz5mu8fVRRVER8Mm1k1W0MaqxFtGXbrH0o9tS2T2e/MMK4a8RMCdZp5QUXmo/F01lvnAMlQ63gMRVk3uVRazWMRk361hAbX4yegppbItBuvKV3OuhRHb9px5SnpgG3Lh/8= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612395559; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0whQxZzUvZ1N9ogSDF2hvQXVIr9wVe/wZlYPojmN3Dw=; b=fRa4P/6TeKlxRK/vNUjs4HI+IvMbVpDHBB17H5ThRrZwFa6ZgZEhxq5t2VudYRFLRbPFHfzKRtkunN9//8W06vb5+DZ7OQ3z0SPIwla0RqvroZNxGxKdXYUazYWZqIuEitOaHkjtX5p6Gs8ntZ9ySx7ulTyyYzwKpAPmsOECQuI= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1dmarc=pass fromdomain=oracle.com); dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1612395559125273.55813272378055; Wed, 3 Feb 2021 15:39:19 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.81095.149219 (Exim 4.92) (envelope-from ) id 1l7Rjm-0006DZ-6r; Wed, 03 Feb 2021 23:39:06 +0000 Received: by outflank-mailman (output) from mailman id 81095.149219; Wed, 03 Feb 2021 23:39:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l7Rjm-0006DQ-1Q; Wed, 03 Feb 2021 23:39:06 +0000 Received: by outflank-mailman (input) for mailman id 81095; Wed, 03 Feb 2021 23:39:04 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l7Rjk-00060K-GM for xen-devel@lists.xenproject.org; Wed, 03 Feb 2021 23:39:04 +0000 Received: from aserp2120.oracle.com (unknown [141.146.126.78]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id cdbe6280-1a3a-4c32-8b14-6afa799c6e13; Wed, 03 Feb 2021 23:38:53 +0000 (UTC) Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 113N9nvp104113; Wed, 3 Feb 2021 23:37:57 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 36cydm2q1h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 Feb 2021 23:37:57 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 113NBZPD083375; Wed, 3 Feb 2021 23:37:56 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2168.outbound.protection.outlook.com [104.47.56.168]) by aserp3030.oracle.com with ESMTP id 36dh1rp03y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 Feb 2021 23:37:56 +0000 Received: from BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) by SJ0PR10MB4784.namprd10.prod.outlook.com (2603:10b6:a03:2d4::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.19; Wed, 3 Feb 2021 23:37:54 +0000 Received: from BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::b52e:bdd3:d193:4d14]) by BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::b52e:bdd3:d193:4d14%7]) with mapi id 15.20.3805.026; Wed, 3 Feb 2021 23:37:54 +0000 Received: from localhost.localdomain (138.3.200.16) by CH0PR03CA0008.namprd03.prod.outlook.com (2603:10b6:610:b0::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3825.17 via Frontend Transport; Wed, 3 Feb 2021 23:37:48 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: cdbe6280-1a3a-4c32-8b14-6afa799c6e13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=0whQxZzUvZ1N9ogSDF2hvQXVIr9wVe/wZlYPojmN3Dw=; b=zphOpY06kD3+7Df7x1mRIRAudIRvGVbxfV7cm1VVALzVaZSFojCB+pC1TdF6+kyhyfzb zw9oF/i9Jchi8EOMKPzhFIW1kNwc+TDKDxJnkptpBsmZnoaVtsUoiBM7FejgZ6Wb5N2U VvUVF4YiNFcEyDlZHFFYMHqBWlAzWfcK3gbJfhbfLToNfdyKRvjeTLmRoHGcpsXK/P06 YabOHIUEmZ+/pENHIs5BZwh9W6R0gEZns8pQy97rO+ULFv37KBdlsoF47pA3QDP2wFeV pXGKqZ/W+qJrFG46V14gJuom5a/zmWjo4xljodpZnaKmieEerTBfh9roxByjB7vqJvSD yA== ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gEf0apA+fXDQBhkVC7p6RZiPW2beDGTJR3LkceZiUkSsKDlLcNRDEu8E1RUZ3dgWW3myJscl18/EraARgi7vRA5bI07NqJRHhXCRH75UJW8H5ew8k7XI6IKjGY5l1aUeMLYQA9ud84B2ewTHlqDc55qRJPCaIO0PI8C23xF717q5jori67CvUsACD4t/z+b63w8PfWcda/EZE/M9GpNSmIw7FGjsXH2u6t127XHqmaeVW+s4pUYJmTXN/tXZ1W9Jw3YhV5H8eR53Wb5Hm+YXFEIlpeRNwowt6QgMV4Rg+oHWldmDkiXyed3LFNrUTYu20+kHcG5zl9omEJiAOTEfPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0whQxZzUvZ1N9ogSDF2hvQXVIr9wVe/wZlYPojmN3Dw=; b=EiRIIAV+sSfHbA+ePNhanxwPg1PWkEuScf9GKzP3zcbHvD+RyrfCz6G8PQrE2Sv5vKM6R/S8DZuSj/l9X2gUFLSoLZpoD8HGsTBJZEGRitUGeud7S2nUxbRrvLCiTRXSS/A1kLjDwRzY8FJAozzdCmWL5lGIxS7lAY09nbUCTmcEPxji1fV2UBcxH0cuxnJZnx+WNaHvwa84+aVB6sTxxt0lxUo5HPkmyWAH+JKPx9C8vnb3+DFO+V4eFIgg7mdjZ8mOJk+WNq476bTRNxHyKEBhrqxKdYO9opot2nR4drhsRxAEfVBrCnseyftZL6CcWr8QjKkdP2ReukhKdC1KEQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0whQxZzUvZ1N9ogSDF2hvQXVIr9wVe/wZlYPojmN3Dw=; b=fIEZVuK8vikYtyA8/X72InpkX1VCyox7gcB4puyv3oe+AQIFBZB8t7LAmvH/gJtpDdyOUb0CM7ki4FYRV6TQX1ynrT3iJDkCW8ENf6cVoDcVaoMkMQJ7+zib8Mr7Qc1ebqDdOUUaun9cdrR7Z9khq7AC+KgVRdYiQ8b+2cnaA7E= Authentication-Results: lists.freedesktop.org; dkim=none (message not signed) header.d=none;lists.freedesktop.org; dmarc=none action=none header.from=oracle.com; From: Dongli Zhang To: dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, iommu@lists.linux-foundation.org, linux-mips@vger.kernel.org, linux-mmc@vger.kernel.org, linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, nouveau@lists.freedesktop.org, x86@kernel.org, xen-devel@lists.xenproject.org Cc: linux-kernel@vger.kernel.org, adrian.hunter@intel.com, akpm@linux-foundation.org, benh@kernel.crashing.org, bskeggs@redhat.com, bhelgaas@google.com, bp@alien8.de, boris.ostrovsky@oracle.com, hch@lst.de, chris@chris-wilson.co.uk, daniel@ffwll.ch, airlied@linux.ie, hpa@zytor.com, mingo@kernel.org, mingo@redhat.com, jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com, jgross@suse.com, konrad.wilk@oracle.com, m.szyprowski@samsung.com, matthew.auld@intel.com, mpe@ellerman.id.au, rppt@kernel.org, paulus@samba.org, peterz@infradead.org, robin.murphy@arm.com, rodrigo.vivi@intel.com, sstabellini@kernel.org, bauerman@linux.ibm.com, tsbogend@alpha.franken.de, tglx@linutronix.de, ulf.hansson@linaro.org, joe.jin@oracle.com, thomas.lendacky@amd.com Subject: [PATCH RFC v1 3/6] swiotlb: introduce swiotlb_get_type() to calculate swiotlb buffer type Date: Wed, 3 Feb 2021 15:37:06 -0800 Message-Id: <20210203233709.19819-4-dongli.zhang@oracle.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210203233709.19819-1-dongli.zhang@oracle.com> References: <20210203233709.19819-1-dongli.zhang@oracle.com> X-Originating-IP: [138.3.200.16] X-ClientProxiedBy: CH0PR03CA0008.namprd03.prod.outlook.com (2603:10b6:610:b0::13) To BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e2add3f4-4994-4ff3-7c96-08d8c89cba39 X-MS-TrafficTypeDiagnostic: SJ0PR10MB4784: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4714; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RLsEchawOksK0kvC0O+w3T4N1PAe5DU17fjViBpDniy2b9oX4Ufj/Tfq8EWhO4frB7qnX0pHSdDvzHQ0ACCSnNWfnsvXXVueYSMQ5bSKOZehrHUM+9L4t9jd07zu4gKv68MoOqFldDvMmK/RiQtDnCKrSM2k9IjjrO+HS1Rlbcm5FzAPQvsMhdbyVoX7IEnuLpd15jB8NLzIr8vnz81spY0Jx9+eVAjhguDVPT9rRmXtSMC60dsfHS55lCeB2Vj8k4aIvEOCTXTSZp1WxfoYpfjD1hwoDYtSG88vstblEjYKKMuirJd4Js35MVoTNqUwk1P1X1Tj8qKpqNzOOpZRVFed6WoSshwWCHcsJNCGyLxjNYzcVdPLuONOZB908nFsFlXunhMqmi/lRV97Ls5v1hy4GLXqaK3/U1a54rGH4ZkOo5lV264z0LOuJRpB36z47uumkrbQ5UUuslWuE+eRzmwO+YcKeLFn4t+gWi1VYhe4eiRqpTWdJidXGRDw8aGQs8A3hCrTQL7tDzrV5iwAsjl0Ko2cLCh5WY7v/FkOx3gVL/dv/Q+VQhrCbgmuT3dI8Gj5pg09+18zfV4CFs9ZM9xmRdm24wkCCVIxO4FyP+g= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB2663.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(366004)(39860400002)(396003)(376002)(346002)(83380400001)(6666004)(316002)(5660300002)(956004)(66946007)(6506007)(86362001)(7406005)(1076003)(66476007)(8676002)(186003)(26005)(36756003)(7416002)(478600001)(2906002)(66556008)(8936002)(6486002)(16526019)(69590400011)(4326008)(6512007)(44832011)(921005)(2616005)(52116002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?BcXfwKqgNX8nkepJT4kFsuW0EIqFSZAcYDSzc+4S9iOuag1d/bCyiGVHpKCl?= =?us-ascii?Q?0xddX9Vt5u5HL+mT7aWb9G412UZ2PypY26RbGIwvafGZmfYU2ipDw60fgBI+?= =?us-ascii?Q?2vlGJqSUe5+9mVeMO7ZexQhODHbppbGlB0dJiqh0hzET7CtRzkcaPOEBLead?= =?us-ascii?Q?eyD2nlmSlc5No2kjos3hDOdsYfccm3bdhp4+HospEB8JYSFBQXqymJD7f4Rv?= =?us-ascii?Q?f55Ab6RpmXbwmZyMu7dHwmJz3Y8FcNNB0hWUXoaypkZRGSBlRVkZR9EmJd1p?= =?us-ascii?Q?BxOl+Qww8yUt2ra7p1vhgyXbi0uzLhyHb+wMaAk5dmzqIdI6pvJLt2lQ0gmq?= =?us-ascii?Q?XPRM8W01An6c1LGPJt98NXX3Vr2i2Ewg4A/ZYxzQxp8p7EOlopuUkptkk0dT?= =?us-ascii?Q?sJSEkHiLb5d5VGS0uPxWoj2AWBgOtdoUSVkm4wnGdkVUTjl6bICOnosAxKIS?= =?us-ascii?Q?lt/aNZpaJfN1OdoUJDCwvK0FV06TLlUWCvgL7pQ3jkx04TFwALqHEw2h6pY8?= =?us-ascii?Q?UjsnjBGnDqRx5abwprSSt98LprW8Ku7VTHgBjJTpkIS0lmowSvcGN+6GR/Ny?= =?us-ascii?Q?jjxnQLNfehLBjybnbFKE3xBGxAxm7JeEJx2T2+76mWmughTZ8blz9CHrXPVS?= =?us-ascii?Q?jg2y+9HokLfKQTXsYCSR/6EVLJq9uq6awiLWDE0QCQckSWSHGVHuKG6JyAuG?= =?us-ascii?Q?3C7KIfe6ui6VdJZs08ZGxFpymfTPuhIccI4SHGRlfi14K/rYU/MuaFJisAyq?= =?us-ascii?Q?cQNK95FM7wog6nn4BC/mfaofm4rmej2BXxc2lB1iyJbjx1/wM2+GNYv7yTCj?= =?us-ascii?Q?CN0hT5a+kx0Bw7AJfaYQ6O5V9qeLoIf28Y3J2IOqHv7lD3GlMsPXfQiTMPFN?= =?us-ascii?Q?ToBdrV4ZsFelex4fxzffuc7L6v4rbAo0nqBqbXlUY754pa3VgZv5RlUmqSzE?= =?us-ascii?Q?FOPk8qIkDFXXYDZ0OJhx0HlhLiscF+5PyapcsSgifjkTUZkUBcvOV8YJadhJ?= =?us-ascii?Q?2uP7WM1UsT0zHDD99sInRccYSNY1fvpPMQehmQx4uO9DwTC14NuAIjcqgFbu?= =?us-ascii?Q?0tNfNU2D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e2add3f4-4994-4ff3-7c96-08d8c89cba39 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2663.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2021 23:37:53.9367 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: f2I/HMS0YUJZk/sk/Cx1bLMo0oJIxcGZe+VqnPykaL7Pm15QLnMEIREVpFCxosN1Z6mZbgwEQo0EBiVXG7K/oQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4784 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9884 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 spamscore=0 phishscore=0 suspectscore=0 mlxlogscore=999 bulkscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102030143 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9884 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 adultscore=0 priorityscore=1501 impostorscore=0 malwarescore=0 clxscore=1015 spamscore=0 lowpriorityscore=0 phishscore=0 mlxlogscore=999 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102030143 X-ZohoMail-DKIM: pass (identity @oracle.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch introduces swiotlb_get_type() in order to calculate which swiotlb buffer the given DMA address is belong to. This is to prepare to enable 64-bit swiotlb. Cc: Joe Jin Signed-off-by: Dongli Zhang --- include/linux/swiotlb.h | 14 ++++++++++++++ kernel/dma/swiotlb.c | 2 ++ 2 files changed, 16 insertions(+) diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index 777046cd4d1b..3d5980d77810 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -3,6 +3,7 @@ #define __LINUX_SWIOTLB_H =20 #include +#include #include #include #include @@ -23,6 +24,8 @@ enum swiotlb_t { SWIOTLB_MAX, }; =20 +extern int swiotlb_nr; + /* * Maximum allowable number of contiguous slabs to map, * must be a power of 2. What is the appropriate value ? @@ -84,6 +87,17 @@ static inline bool is_swiotlb_buffer(phys_addr_t paddr) paddr < io_tlb_end[SWIOTLB_LO]; } =20 +static inline int swiotlb_get_type(phys_addr_t paddr) +{ + int i; + + for (i =3D 0; i < swiotlb_nr; i++) + if (paddr >=3D io_tlb_start[i] && paddr < io_tlb_end[i]) + return i; + + return -ENOENT; +} + void __init swiotlb_exit(void); unsigned int swiotlb_max_segment(void); size_t swiotlb_max_mapping_size(struct device *dev); diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 1fbb65daa2dd..c91d3d2c3936 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -109,6 +109,8 @@ static DEFINE_SPINLOCK(io_tlb_lock); =20 static int late_alloc; =20 +int swiotlb_nr =3D 1; + static int __init setup_io_tlb_npages(char *str) { --=20 2.17.1 From nobody Tue May 7 02:35:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1dmarc=pass fromdomain=oracle.com); dmarc=pass(p=none dis=none) header.from=oracle.com ARC-Seal: i=2; a=rsa-sha256; t=1612395571; cv=pass; d=zohomail.com; s=zohoarc; b=kcWjwmDPSmHJ007WsOuWSfJTn+VB2wIvMUvV/fAEKYgvP+SVsdcUISkvHj4FDIn8/n1RBzuA0YG9yZZpwF+NlqKZiY9jHmWDk9Pdsnp6OYJqcK+yDnpTbwz7O0PiOkpt8UiaSTXMjcNeUXlqoFlRq6OY5iYMtLZCj9Iap7xtxzs= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612395571; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZgEJ16guRlHHGFLq1GmEa8b8Efy41uKiY1bY40epmsE=; b=C4p0Cg3wrRxb1RGXc5sK/vOv6ZCXO70h8AF1WvNlOtX6Tl9VoMg2MvnCSseFDgLOPuuLT+fQCDbLDNOO0unb7SHqyg5G+dmY4pvtMa1bcG8KbgzxgZq4SPZ281ZLK8jI7fWg0Mu5ckdgOULCM3H1pUcfISNqjioGohZC/WkGbmk= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1dmarc=pass fromdomain=oracle.com); dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1612395571648748.3126022936547; Wed, 3 Feb 2021 15:39:31 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.81097.149243 (Exim 4.92) (envelope-from ) id 1l7Rjw-0006V4-2g; Wed, 03 Feb 2021 23:39:16 +0000 Received: by outflank-mailman (output) from mailman id 81097.149243; Wed, 03 Feb 2021 23:39:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l7Rjv-0006Uu-Uu; Wed, 03 Feb 2021 23:39:15 +0000 Received: by outflank-mailman (input) for mailman id 81097; Wed, 03 Feb 2021 23:39:14 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l7Rju-00060K-Gd for xen-devel@lists.xenproject.org; Wed, 03 Feb 2021 23:39:14 +0000 Received: from aserp2130.oracle.com (unknown [141.146.126.79]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 25ce93c3-4e45-4ecb-b114-469d71a519c6; Wed, 03 Feb 2021 23:38:53 +0000 (UTC) Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 113N9ap2053612; Wed, 3 Feb 2021 23:38:04 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2130.oracle.com with ESMTP id 36cvyb2we9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 Feb 2021 23:38:04 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 113NAc2x112310; Wed, 3 Feb 2021 23:38:03 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2171.outbound.protection.outlook.com [104.47.56.171]) by userp3030.oracle.com with ESMTP id 36dhd0h9qf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 Feb 2021 23:38:03 +0000 Received: from BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) by SJ0PR10MB4784.namprd10.prod.outlook.com (2603:10b6:a03:2d4::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.19; Wed, 3 Feb 2021 23:37:59 +0000 Received: from BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::b52e:bdd3:d193:4d14]) by BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::b52e:bdd3:d193:4d14%7]) with mapi id 15.20.3805.026; Wed, 3 Feb 2021 23:37:59 +0000 Received: from localhost.localdomain (138.3.200.16) by CH0PR03CA0008.namprd03.prod.outlook.com (2603:10b6:610:b0::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3825.17 via Frontend Transport; Wed, 3 Feb 2021 23:37:54 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 25ce93c3-4e45-4ecb-b114-469d71a519c6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=ZgEJ16guRlHHGFLq1GmEa8b8Efy41uKiY1bY40epmsE=; b=PDiUbWCP0RoZ0o+0J6rJ82slOeerEQmqJVyEs8T+MB0fEhBfsGsSWIwqwm28J2BUvfMx 3GhIn5+GC36EMv3B+VM8eymanh0ykin4S75rWtxZb+QFNQX0rDCjGBMkI0gqEpThb/uJ omXeDMO5ZDETMdUqWYPREYpc2NzB5FOvEWNAiPEMQJZsFqltz8PS1ve57hK79BP8KK4b DuinwA5fzl1srAvdpLjmDRpWqzeNS//FSO2lsdaaIJ0gyw1cPeFQNM1t/UvVqio3m+kf z1APfuDaF+0akGUX1oM47qB6e84KdbL6F8Z7kQyYmoztKHNkrwYGfNqY3xw98XA5bYN8 TQ== ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=i2V8N3xyJCDJeonH32RZQlVQ3jWrn+DzvYDIYPRzfZIPKWdEUnvGUWRxVzr3IaA2r5K0sWr+mMda2VvZm7i281mTPMbUVG13mzN/s1k9XOuo9nY2Mg/EwspJQHXt/SHYA+JawBEQKUWA+MsWyURkOC1WPrlN373wWxbwQ+KWI6Gj20e+tE5dawri4ldj4eqRPrL7ukb8LT5zoj0mXIraqp7Lqf5IFNnoMgjoVLFHKIspbQxHqI1LlI/3JnIHz4TC9O/M8oGnoQ5dzAOeKhzaLRy+Tmfy+uCNrDVpV8ifA8EpIuBGZdcF387gqZVG9XCO0PEJndUgfc55JZbpTP+1uQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZgEJ16guRlHHGFLq1GmEa8b8Efy41uKiY1bY40epmsE=; b=BxlqyxLITubnbBrCASW+DgmsD6m5lKdslOGtcgEEA3klheiMkFHvokQofbOz36W3nPGaPJLWwNXiwA2SNvLNV2RUbvx0f01Ng2eqFTCBOKdRGHCimI4mPsEDZUXZJJcoUUrv93VEMkZSDAgTbQGErkEYr8GD+ioPY6hX62SUNgnW4WR4sipV3s89DhfAmy0habEz8BXbBVfXRAWxTD2A83d+RO57WUgWCrDAt/+VAaHzrgGkfCZA71AG4ZvBduMF5ucIdJKeklVOr0xRTEnNRqR8M6k6xcm1QBZ51X52bU+UDDWekmdVMhKv+06hgJ4ttuXReK6uARxAaPBRT7wxGQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZgEJ16guRlHHGFLq1GmEa8b8Efy41uKiY1bY40epmsE=; b=KBGnY6O3w2Ms4RJHjtgtaazCdGmZA33iy4XS3yPOkIcJmhvgtc8iVvTVgW7SHkiLMzZl51Sgkh57gfkguYZmsGZyKFYiaK9TT3/BZLhPsYEJdeeSisnb6COfLtX1Pegj3wHT3kXKurwWCk8QT0mGt6ukgaUqj0X5ph+jt7Buq1U= Authentication-Results: lists.freedesktop.org; dkim=none (message not signed) header.d=none;lists.freedesktop.org; dmarc=none action=none header.from=oracle.com; From: Dongli Zhang To: dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, iommu@lists.linux-foundation.org, linux-mips@vger.kernel.org, linux-mmc@vger.kernel.org, linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, nouveau@lists.freedesktop.org, x86@kernel.org, xen-devel@lists.xenproject.org Cc: linux-kernel@vger.kernel.org, adrian.hunter@intel.com, akpm@linux-foundation.org, benh@kernel.crashing.org, bskeggs@redhat.com, bhelgaas@google.com, bp@alien8.de, boris.ostrovsky@oracle.com, hch@lst.de, chris@chris-wilson.co.uk, daniel@ffwll.ch, airlied@linux.ie, hpa@zytor.com, mingo@kernel.org, mingo@redhat.com, jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com, jgross@suse.com, konrad.wilk@oracle.com, m.szyprowski@samsung.com, matthew.auld@intel.com, mpe@ellerman.id.au, rppt@kernel.org, paulus@samba.org, peterz@infradead.org, robin.murphy@arm.com, rodrigo.vivi@intel.com, sstabellini@kernel.org, bauerman@linux.ibm.com, tsbogend@alpha.franken.de, tglx@linutronix.de, ulf.hansson@linaro.org, joe.jin@oracle.com, thomas.lendacky@amd.com Subject: [PATCH RFC v1 4/6] swiotlb: enable 64-bit swiotlb Date: Wed, 3 Feb 2021 15:37:07 -0800 Message-Id: <20210203233709.19819-5-dongli.zhang@oracle.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210203233709.19819-1-dongli.zhang@oracle.com> References: <20210203233709.19819-1-dongli.zhang@oracle.com> X-Originating-IP: [138.3.200.16] X-ClientProxiedBy: CH0PR03CA0008.namprd03.prod.outlook.com (2603:10b6:610:b0::13) To BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2e551ef0-1c3f-43af-134e-08d8c89cbda4 X-MS-TrafficTypeDiagnostic: SJ0PR10MB4784: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4125; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rbOoLbhvjEiDwHn8YwqCH2Td6GURxyVXGBbpEnzKivEpvSx1TMcc1tDPUXLm2G1iCCYpsHfGcyfK5XIBrrkdNzKgwWpTFllDUfRgGuhXvLvXV58G6oFYWt9hXdgAamvuPUnQbueb9oF8s4k2Ndyd8drmTH/hydLPayryGqY8IUH8ctaWDETvtZEy7xlWb5BaPjsTBQy8RUz4O6XNTteJa4m2yZrDk+fosLMy6sk6ILGjZhDX5dfs9P0N1l30DvDDuxo+gxdjtVqtQIA+KzaCMWiVtnMncLx04xkhSOhSQT7Qnz2cxkJMj74fTGRwZ/almYaVnuS044fZw21O+le6UKYMtMlcqp1ow9Uu6G+N+NXBNOZ+6+hdIlxFSuoeHWx+7RbD6FXUSP0ZGJqzqyCJTjR0vmTxyEkk2KXBPQamjbXTpMAXrWDBI2rwT9R6Qk/ENZ3Oh/c1xo9N0wZ24SeFO7M0dmWM5p9RYdcky2gtp4QKF3VCOb57QH/+F4WKnKPG/ZgKIISMZYgdgb1YGCNAMs5VmFkl8deuxiryaUTVtfdNfljtQG2h/TBV/LTWvwox9MMEmCOlbx4TlyJLcf5+81Fz24zPbZFUUumMxaXSCYvlwv3NrC9Y21FT63IIWAp9s158c5ATJozi/tWiZxsLiw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB2663.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(366004)(39860400002)(396003)(376002)(346002)(83380400001)(6666004)(316002)(5660300002)(956004)(66946007)(6506007)(86362001)(7406005)(1076003)(66476007)(8676002)(186003)(26005)(36756003)(7416002)(30864003)(478600001)(2906002)(66556008)(8936002)(6486002)(16526019)(69590400011)(4326008)(6512007)(44832011)(921005)(2616005)(52116002)(461764006)(309714004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?JhNrVSwnivNA0yGVGvlva5dhTOSQih9UrxRsxZKz4yH6/lyJBR0Ta03BdYsi?= =?us-ascii?Q?Efizf+QiqksJDR/a50wFo0OxP+67Xc1taIThJ0dZoT0SeB10DaYsZxMSyv59?= =?us-ascii?Q?iND8s8vlQIQjB+asig/RVQdH48TcaDcEY2mpYNwLhhcy/IogpyMs3MjbHDtw?= =?us-ascii?Q?OFEvizRSi4XPnJkiA1KEUaA9lRq+0inM0ylqWxOjcSxyW+TxemaemDvNtyG9?= =?us-ascii?Q?H8P/MaJZqNB3g5ypXpOCXXcG5hxXx4N2lQIW1a3T0vL61EIULNSs81ubumzh?= =?us-ascii?Q?tLEwz1FCm4AXZMAXFn0IRkXXj0dVthKKuGFQaoPc9KRZNpSZBMrvEOgdAmPG?= =?us-ascii?Q?svt8Iu6gmUkmQQ4ff4hxoo7/sptgepb3AXrX/1LSl8RtOrzwUczumr2lRkYp?= =?us-ascii?Q?bL77QVcFLWNZbHkfvc8brSIY8Lpbs3EKOHXgOlFjMeETOH6Swou3eXPEvDCU?= =?us-ascii?Q?/6ijLg4w20HRk//A0yOmqeLhhrLn1iUxtFksdQ4ETSlXkpsofHKN6B2pzffC?= =?us-ascii?Q?4NhDRawkeZCnoeoM+I06xOZYnDfawcIMpYCKUPBdcONRVEIPO01LHUQvPAPC?= =?us-ascii?Q?0KvKVI9yINtDl33q3S90op3YH6MWHd3JucEZJeyy0gtk7w8NWmQ6Xd01r262?= =?us-ascii?Q?QP13TUfZkrPwREs3TMnlr9ujfTFZ/BX7txjmf1eDDwJQQZG6iQCKBxROhMAV?= =?us-ascii?Q?fx32ZMYy4GUlunJ++cB6bd5eHgucUERVOXFBQaOlxz8CELVKxm4r8JHJrFgF?= =?us-ascii?Q?mJh9BgiZC0qoLmZR1/VJ6CmJKrhbboog5/COx7T4RcUAN8b34i3dcjhsqdPs?= =?us-ascii?Q?15bBiXV84rDDITpi5ZcztoLQUQrIgZ9uYkXsbCaOHreg6l1SVMUuwUuzkRtQ?= =?us-ascii?Q?j4SbOjDgRCxZB/FGNPv9UUpo7O+5TVxxzpcxTlnwxaB06uzKn7bGkTsMnNON?= =?us-ascii?Q?yPKQbk+muWeYNpIAMVqSHMnVoS+g/0TxEcmkZ/Ypwt+8utMehD9qEZ4rRLdh?= =?us-ascii?Q?Sm1BDIlsIvGoJWYx3QAouthQZOsiA5slqflXe3+vPcLLBXno4lEtbqGRij85?= =?us-ascii?Q?zIrxnGER?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2e551ef0-1c3f-43af-134e-08d8c89cbda4 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2663.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2021 23:37:59.7094 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: o0/PqwuIPm+eM+UxJJTP5oTDHWgjhBJlGqrrr8kTAtm9rHRs7gOc3APX+g8HPiptyPbadCkPBGWyyZPafVE50A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4784 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9884 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 mlxlogscore=999 phishscore=0 spamscore=0 suspectscore=0 malwarescore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102030143 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9884 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1015 impostorscore=0 mlxscore=0 spamscore=0 bulkscore=0 priorityscore=1501 adultscore=0 lowpriorityscore=0 malwarescore=0 phishscore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102030143 X-ZohoMail-DKIM: pass (identity @oracle.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch is to enable the 64-bit swiotlb buffer. The state of the art swiotlb pre-allocates <=3D32-bit memory in order to me= et the DMA mask requirement for some 32-bit legacy device. Considering most devices nowadays support 64-bit DMA and IOMMU is available, the swiotlb is not used for most of the times, except: 1. The xen PVM domain requires the DMA addresses to both (1) less than the dma mask, and (2) continuous in machine address. Therefore, the 64-bit device may still require swiotlb on PVM domain. 2. From source code the AMD SME/SEV will enable SWIOTLB_FORCE. As a result it is always required to allocate from swiotlb buffer even the device dma mask is 64-bit. sme_early_init() -> if (sev_active()) swiotlb_force =3D SWIOTLB_FORCE; Therefore, this patch introduces the 2nd swiotlb buffer for 64-bit DMA access. For instance, the swiotlb_tbl_map_single() allocates from the 2nd 64-bit buffer if the device DMA mask is min_not_zero(*hwdev->dma_mask, hwdev->bus_dma_limit). The example to configure 64-bit swiotlb is "swiotlb=3D65536,524288,force" or "swiotlb=3D,524288,force", where 524288 is the size of 64-bit buffer. With the patch, the kernel will be able to allocate >4GB swiotlb buffer. This patch is only for swiotlb, not including xen-swiotlb. Cc: Joe Jin Signed-off-by: Dongli Zhang --- arch/mips/cavium-octeon/dma-octeon.c | 3 +- arch/powerpc/kernel/dma-swiotlb.c | 2 +- arch/powerpc/platforms/pseries/svm.c | 2 +- arch/x86/kernel/pci-swiotlb.c | 5 +- arch/x86/pci/sta2x11-fixup.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_internal.c | 4 +- drivers/gpu/drm/i915/i915_scatterlist.h | 2 +- drivers/gpu/drm/nouveau/nouveau_ttm.c | 2 +- drivers/mmc/host/sdhci.c | 2 +- drivers/pci/xen-pcifront.c | 2 +- drivers/xen/swiotlb-xen.c | 9 +- include/linux/swiotlb.h | 28 +- kernel/dma/swiotlb.c | 339 +++++++++++-------- 13 files changed, 238 insertions(+), 164 deletions(-) diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon= /dma-octeon.c index df70308db0e6..3480555d908a 100644 --- a/arch/mips/cavium-octeon/dma-octeon.c +++ b/arch/mips/cavium-octeon/dma-octeon.c @@ -245,6 +245,7 @@ void __init plat_swiotlb_setup(void) panic("%s: Failed to allocate %zu bytes align=3D%lx\n", __func__, swiotlbsize, PAGE_SIZE); =20 - if (swiotlb_init_with_tbl(octeon_swiotlb, swiotlb_nslabs, 1) =3D=3D -ENOM= EM) + if (swiotlb_init_with_tbl(octeon_swiotlb, swiotlb_nslabs, + SWIOTLB_LO, 1) =3D=3D -ENOMEM) panic("Cannot allocate SWIOTLB buffer"); } diff --git a/arch/powerpc/kernel/dma-swiotlb.c b/arch/powerpc/kernel/dma-sw= iotlb.c index fc7816126a40..88113318c53f 100644 --- a/arch/powerpc/kernel/dma-swiotlb.c +++ b/arch/powerpc/kernel/dma-swiotlb.c @@ -20,7 +20,7 @@ void __init swiotlb_detect_4g(void) static int __init check_swiotlb_enabled(void) { if (ppc_swiotlb_enable) - swiotlb_print_info(); + swiotlb_print_info(SWIOTLB_LO); else swiotlb_exit(); =20 diff --git a/arch/powerpc/platforms/pseries/svm.c b/arch/powerpc/platforms/= pseries/svm.c index 9f8842d0da1f..77910e4ffad8 100644 --- a/arch/powerpc/platforms/pseries/svm.c +++ b/arch/powerpc/platforms/pseries/svm.c @@ -52,7 +52,7 @@ void __init svm_swiotlb_init(void) bytes =3D io_tlb_nslabs << IO_TLB_SHIFT; =20 vstart =3D memblock_alloc(PAGE_ALIGN(bytes), PAGE_SIZE); - if (vstart && !swiotlb_init_with_tbl(vstart, io_tlb_nslabs, false)) + if (vstart && !swiotlb_init_with_tbl(vstart, io_tlb_nslabs, SWIOTLB_LO, f= alse)) return; =20 if (io_tlb_start[SWIOTLB_LO]) diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c index c2cfa5e7c152..950624fd95a4 100644 --- a/arch/x86/kernel/pci-swiotlb.c +++ b/arch/x86/kernel/pci-swiotlb.c @@ -67,12 +67,15 @@ void __init pci_swiotlb_init(void) =20 void __init pci_swiotlb_late_init(void) { + int i; + /* An IOMMU turned us off. */ if (!swiotlb) swiotlb_exit(); else { printk(KERN_INFO "PCI-DMA: " "Using software bounce buffering for IO (SWIOTLB)\n"); - swiotlb_print_info(); + for (i =3D 0; i < swiotlb_nr; i++) + swiotlb_print_info(i); } } diff --git a/arch/x86/pci/sta2x11-fixup.c b/arch/x86/pci/sta2x11-fixup.c index 7d2525691854..c440520b2055 100644 --- a/arch/x86/pci/sta2x11-fixup.c +++ b/arch/x86/pci/sta2x11-fixup.c @@ -57,7 +57,7 @@ static void sta2x11_new_instance(struct pci_dev *pdev) int size =3D STA2X11_SWIOTLB_SIZE; /* First instance: register your own swiotlb area */ dev_info(&pdev->dev, "Using SWIOTLB (size %i)\n", size); - if (swiotlb_late_init_with_default_size(size)) + if (swiotlb_late_init_with_default_size(size), SWIOTLB_LO) dev_emerg(&pdev->dev, "init swiotlb failed\n"); } list_add(&instance->list, &sta2x11_instance_list); diff --git a/drivers/gpu/drm/i915/gem/i915_gem_internal.c b/drivers/gpu/drm= /i915/gem/i915_gem_internal.c index ad22f42541bd..947683f2e568 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_internal.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_internal.c @@ -42,10 +42,10 @@ static int i915_gem_object_get_pages_internal(struct dr= m_i915_gem_object *obj) =20 max_order =3D MAX_ORDER; #ifdef CONFIG_SWIOTLB - if (swiotlb_nr_tbl()) { + if (swiotlb_nr_tbl(SWIOTLB_LO)) { unsigned int max_segment; =20 - max_segment =3D swiotlb_max_segment(); + max_segment =3D swiotlb_max_segment(SWIOTLB_LO); if (max_segment) { max_segment =3D max_t(unsigned int, max_segment, PAGE_SIZE) >> PAGE_SHIFT; diff --git a/drivers/gpu/drm/i915/i915_scatterlist.h b/drivers/gpu/drm/i915= /i915_scatterlist.h index 9cb26a224034..c63c7f6941f6 100644 --- a/drivers/gpu/drm/i915/i915_scatterlist.h +++ b/drivers/gpu/drm/i915/i915_scatterlist.h @@ -118,7 +118,7 @@ static inline unsigned int i915_sg_page_sizes(struct sc= atterlist *sg) =20 static inline unsigned int i915_sg_segment_size(void) { - unsigned int size =3D swiotlb_max_segment(); + unsigned int size =3D swiotlb_max_segment(SWIOTLB_LO); =20 if (size =3D=3D 0) size =3D UINT_MAX; diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouvea= u/nouveau_ttm.c index a37bc3d7b38b..0919b207ac47 100644 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c @@ -321,7 +321,7 @@ nouveau_ttm_init(struct nouveau_drm *drm) } =20 #if IS_ENABLED(CONFIG_SWIOTLB) && IS_ENABLED(CONFIG_X86) - need_swiotlb =3D !!swiotlb_nr_tbl(); + need_swiotlb =3D !!swiotlb_nr_tbl(SWIOTLB_LO); #endif =20 ret =3D ttm_bo_device_init(&drm->ttm.bdev, &nouveau_bo_driver, diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 646823ddd317..1f7fb912d5a9 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -4582,7 +4582,7 @@ int sdhci_setup_host(struct sdhci_host *host) mmc->max_segs =3D SDHCI_MAX_SEGS; } else if (host->flags & SDHCI_USE_SDMA) { mmc->max_segs =3D 1; - if (swiotlb_max_segment()) { + if (swiotlb_max_segment(SWIOTLB_LO)) { unsigned int max_req_size =3D (1 << IO_TLB_SHIFT) * IO_TLB_SEGSIZE; mmc->max_req_size =3D min(mmc->max_req_size, diff --git a/drivers/pci/xen-pcifront.c b/drivers/pci/xen-pcifront.c index c6fe0cfec0f6..9509ed9b4126 100644 --- a/drivers/pci/xen-pcifront.c +++ b/drivers/pci/xen-pcifront.c @@ -693,7 +693,7 @@ static int pcifront_connect_and_init_dma(struct pcifron= t_device *pdev) =20 spin_unlock(&pcifront_dev_lock); =20 - if (!err && !swiotlb_nr_tbl()) { + if (!err && !swiotlb_nr_tbl(SWIOTLB_LO)) { err =3D pci_xen_swiotlb_init_late(); if (err) dev_err(&pdev->xdev->dev, "Could not setup SWIOTLB!\n"); diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 3261880ad859..662638093542 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -184,7 +184,7 @@ int __ref xen_swiotlb_init(int verbose, bool early) enum xen_swiotlb_err m_ret =3D XEN_SWIOTLB_UNKNOWN; unsigned int repeat =3D 3; =20 - xen_io_tlb_nslabs =3D swiotlb_nr_tbl(); + xen_io_tlb_nslabs =3D swiotlb_nr_tbl(SWIOTLB_LO); retry: bytes =3D xen_set_nslabs(xen_io_tlb_nslabs); order =3D get_order(xen_io_tlb_nslabs << IO_TLB_SHIFT); @@ -245,16 +245,17 @@ int __ref xen_swiotlb_init(int verbose, bool early) } if (early) { if (swiotlb_init_with_tbl(xen_io_tlb_start, xen_io_tlb_nslabs, - verbose)) + SWIOTLB_LO, verbose)) panic("Cannot allocate SWIOTLB buffer"); rc =3D 0; } else - rc =3D swiotlb_late_init_with_tbl(xen_io_tlb_start, xen_io_tlb_nslabs); + rc =3D swiotlb_late_init_with_tbl(xen_io_tlb_start, + xen_io_tlb_nslabs, SWIOTLB_LO); =20 end: xen_io_tlb_end =3D xen_io_tlb_start + bytes; if (!rc) - swiotlb_set_max_segment(PAGE_SIZE); + swiotlb_set_max_segment(PAGE_SIZE, SWIOTLB_LO); =20 return rc; error: diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index 3d5980d77810..8ba45fddfb14 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -43,11 +43,14 @@ extern int swiotlb_nr; #define IO_TLB_DEFAULT_SIZE (64UL<<20) =20 extern void swiotlb_init(int verbose); -int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose); -extern unsigned long swiotlb_nr_tbl(void); +int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, + enum swiotlb_t type, int verbose); +extern unsigned long swiotlb_nr_tbl(enum swiotlb_t type); unsigned long swiotlb_size_or_default(void); -extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs); -extern int swiotlb_late_init_with_default_size(size_t default_size); +extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs, + enum swiotlb_t type); +extern int swiotlb_late_init_with_default_size(size_t default_size, + enum swiotlb_t type); extern void __init swiotlb_update_mem_attributes(void); =20 /* @@ -83,8 +86,13 @@ extern phys_addr_t io_tlb_start[], io_tlb_end[]; =20 static inline bool is_swiotlb_buffer(phys_addr_t paddr) { - return paddr >=3D io_tlb_start[SWIOTLB_LO] && - paddr < io_tlb_end[SWIOTLB_LO]; + int i; + + for (i =3D 0; i < swiotlb_nr; i++) + if (paddr >=3D io_tlb_start[i] && paddr < io_tlb_end[i]) + return true; + + return false; } =20 static inline int swiotlb_get_type(phys_addr_t paddr) @@ -99,7 +107,7 @@ static inline int swiotlb_get_type(phys_addr_t paddr) } =20 void __init swiotlb_exit(void); -unsigned int swiotlb_max_segment(void); +unsigned int swiotlb_max_segment(enum swiotlb_t type); size_t swiotlb_max_mapping_size(struct device *dev); bool is_swiotlb_active(void); void __init swiotlb_adjust_size(unsigned long new_size); @@ -112,7 +120,7 @@ static inline bool is_swiotlb_buffer(phys_addr_t paddr) static inline void swiotlb_exit(void) { } -static inline unsigned int swiotlb_max_segment(void) +static inline unsigned int swiotlb_max_segment(enum swiotlb_t type) { return 0; } @@ -131,7 +139,7 @@ static inline void swiotlb_adjust_size(unsigned long ne= w_size) } #endif /* CONFIG_SWIOTLB */ =20 -extern void swiotlb_print_info(void); -extern void swiotlb_set_max_segment(unsigned int); +extern void swiotlb_print_info(enum swiotlb_t type); +extern void swiotlb_set_max_segment(unsigned int val, enum swiotlb_t type); =20 #endif /* __LINUX_SWIOTLB_H */ diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index c91d3d2c3936..cd28db5b016a 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -111,6 +111,11 @@ static int late_alloc; =20 int swiotlb_nr =3D 1; =20 +static const char * const swiotlb_name[] =3D { + "Low Mem", + "High Mem" +}; + static int __init setup_io_tlb_npages(char *str) { @@ -121,11 +126,25 @@ setup_io_tlb_npages(char *str) } if (*str =3D=3D ',') ++str; + + if (isdigit(*str)) { + io_tlb_nslabs[SWIOTLB_HI] =3D simple_strtoul(str, &str, 0); + /* avoid tail segment of size < IO_TLB_SEGSIZE */ + io_tlb_nslabs[SWIOTLB_HI] =3D ALIGN(io_tlb_nslabs[SWIOTLB_HI], IO_TLB_SE= GSIZE); + + swiotlb_nr =3D 2; + } + + if (*str =3D=3D ',') + ++str; + if (!strcmp(str, "force")) { swiotlb_force =3D SWIOTLB_FORCE; } else if (!strcmp(str, "noforce")) { swiotlb_force =3D SWIOTLB_NO_FORCE; io_tlb_nslabs[SWIOTLB_LO] =3D 1; + if (swiotlb_nr > 1) + io_tlb_nslabs[SWIOTLB_HI] =3D 1; } =20 return 0; @@ -134,24 +153,24 @@ early_param("swiotlb", setup_io_tlb_npages); =20 static bool no_iotlb_memory[SWIOTLB_MAX]; =20 -unsigned long swiotlb_nr_tbl(void) +unsigned long swiotlb_nr_tbl(enum swiotlb_t type) { - return unlikely(no_iotlb_memory[SWIOTLB_LO]) ? 0 : io_tlb_nslabs[SWIOTLB_= LO]; + return unlikely(no_iotlb_memory[type]) ? 0 : io_tlb_nslabs[type]; } EXPORT_SYMBOL_GPL(swiotlb_nr_tbl); =20 -unsigned int swiotlb_max_segment(void) +unsigned int swiotlb_max_segment(enum swiotlb_t type) { - return unlikely(no_iotlb_memory[SWIOTLB_LO]) ? 0 : max_segment[SWIOTLB_LO= ]; + return unlikely(no_iotlb_memory[type]) ? 0 : max_segment[type]; } EXPORT_SYMBOL_GPL(swiotlb_max_segment); =20 -void swiotlb_set_max_segment(unsigned int val) +void swiotlb_set_max_segment(unsigned int val, enum swiotlb_t type) { if (swiotlb_force =3D=3D SWIOTLB_FORCE) - max_segment[SWIOTLB_LO] =3D 1; + max_segment[type] =3D 1; else - max_segment[SWIOTLB_LO] =3D rounddown(val, PAGE_SIZE); + max_segment[type] =3D rounddown(val, PAGE_SIZE); } =20 unsigned long swiotlb_size_or_default(void) @@ -181,18 +200,18 @@ void __init swiotlb_adjust_size(unsigned long new_siz= e) } } =20 -void swiotlb_print_info(void) +void swiotlb_print_info(enum swiotlb_t type) { - unsigned long bytes =3D io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT; + unsigned long bytes =3D io_tlb_nslabs[type] << IO_TLB_SHIFT; =20 - if (no_iotlb_memory[SWIOTLB_LO]) { - pr_warn("No low mem\n"); + if (no_iotlb_memory[type]) { + pr_warn("No low mem with %s\n", swiotlb_name[type]); return; } =20 - pr_info("mapped [mem %pa-%pa] (%luMB)\n", - &io_tlb_start[SWIOTLB_LO], &io_tlb_end[SWIOTLB_LO], - bytes >> 20); + pr_info("%s mapped [mem %pa-%pa] (%luMB)\n", + swiotlb_name[type], + &io_tlb_start[type], &io_tlb_end[type], bytes >> 20); } =20 /* @@ -205,88 +224,104 @@ void __init swiotlb_update_mem_attributes(void) { void *vaddr; unsigned long bytes; + int i; =20 - if (no_iotlb_memory[SWIOTLB_LO] || late_alloc) - return; + for (i =3D 0; i < swiotlb_nr; i++) { + if (no_iotlb_memory[i] || late_alloc) + continue; =20 - vaddr =3D phys_to_virt(io_tlb_start[SWIOTLB_LO]); - bytes =3D PAGE_ALIGN(io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT); - set_memory_decrypted((unsigned long)vaddr, bytes >> PAGE_SHIFT); - memset(vaddr, 0, bytes); + vaddr =3D phys_to_virt(io_tlb_start[i]); + bytes =3D PAGE_ALIGN(io_tlb_nslabs[i] << IO_TLB_SHIFT); + set_memory_decrypted((unsigned long)vaddr, bytes >> PAGE_SHIFT); + memset(vaddr, 0, bytes); + } } =20 -int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verb= ose) +int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, + enum swiotlb_t type, int verbose) { unsigned long i, bytes; size_t alloc_size; =20 bytes =3D nslabs << IO_TLB_SHIFT; =20 - io_tlb_nslabs[SWIOTLB_LO] =3D nslabs; - io_tlb_start[SWIOTLB_LO] =3D __pa(tlb); - io_tlb_end[SWIOTLB_LO] =3D io_tlb_start[SWIOTLB_LO] + bytes; + io_tlb_nslabs[type] =3D nslabs; + io_tlb_start[type] =3D __pa(tlb); + io_tlb_end[type] =3D io_tlb_start[type] + bytes; =20 /* * Allocate and initialize the free list array. This array is used * to find contiguous free memory regions of size up to IO_TLB_SEGSIZE * between io_tlb_start and io_tlb_end. */ - alloc_size =3D PAGE_ALIGN(io_tlb_nslabs[SWIOTLB_LO] * sizeof(int)); - io_tlb_list[SWIOTLB_LO] =3D memblock_alloc(alloc_size, PAGE_SIZE); - if (!io_tlb_list[SWIOTLB_LO]) + alloc_size =3D PAGE_ALIGN(io_tlb_nslabs[type] * sizeof(int)); + io_tlb_list[type] =3D memblock_alloc(alloc_size, PAGE_SIZE); + if (!io_tlb_list[type]) panic("%s: Failed to allocate %zu bytes align=3D0x%lx\n", __func__, alloc_size, PAGE_SIZE); =20 - alloc_size =3D PAGE_ALIGN(io_tlb_nslabs[SWIOTLB_LO] * sizeof(phys_addr_t)= ); - io_tlb_orig_addr[SWIOTLB_LO] =3D memblock_alloc(alloc_size, PAGE_SIZE); - if (!io_tlb_orig_addr[SWIOTLB_LO]) + alloc_size =3D PAGE_ALIGN(io_tlb_nslabs[type] * sizeof(phys_addr_t)); + io_tlb_orig_addr[type] =3D memblock_alloc(alloc_size, PAGE_SIZE); + if (!io_tlb_orig_addr[type]) panic("%s: Failed to allocate %zu bytes align=3D0x%lx\n", __func__, alloc_size, PAGE_SIZE); =20 - for (i =3D 0; i < io_tlb_nslabs[SWIOTLB_LO]; i++) { - io_tlb_list[SWIOTLB_LO][i] =3D IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE= ); - io_tlb_orig_addr[SWIOTLB_LO][i] =3D INVALID_PHYS_ADDR; + for (i =3D 0; i < io_tlb_nslabs[type]; i++) { + io_tlb_list[type][i] =3D IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE); + io_tlb_orig_addr[type][i] =3D INVALID_PHYS_ADDR; } - io_tlb_index[SWIOTLB_LO] =3D 0; - no_iotlb_memory[SWIOTLB_LO] =3D false; + io_tlb_index[type] =3D 0; + no_iotlb_memory[type] =3D false; =20 if (verbose) - swiotlb_print_info(); + swiotlb_print_info(type); =20 - swiotlb_set_max_segment(io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT); + swiotlb_set_max_segment(io_tlb_nslabs[type] << IO_TLB_SHIFT, type); return 0; } =20 -/* - * Statically reserve bounce buffer space and initialize bounce buffer data - * structures for the software IO TLB used to implement the DMA API. - */ -void __init -swiotlb_init(int verbose) +static void __init +swiotlb_init_type(enum swiotlb_t type, int verbose) { size_t default_size =3D IO_TLB_DEFAULT_SIZE; unsigned char *vstart; unsigned long bytes; =20 - if (!io_tlb_nslabs[SWIOTLB_LO]) { - io_tlb_nslabs[SWIOTLB_LO] =3D (default_size >> IO_TLB_SHIFT); - io_tlb_nslabs[SWIOTLB_LO] =3D ALIGN(io_tlb_nslabs[SWIOTLB_LO], IO_TLB_SE= GSIZE); + if (!io_tlb_nslabs[type]) { + io_tlb_nslabs[type] =3D (default_size >> IO_TLB_SHIFT); + io_tlb_nslabs[type] =3D ALIGN(io_tlb_nslabs[type], IO_TLB_SEGSIZE); } =20 - bytes =3D io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT; + bytes =3D io_tlb_nslabs[type] << IO_TLB_SHIFT; + + if (type =3D=3D SWIOTLB_LO) + vstart =3D memblock_alloc_low(PAGE_ALIGN(bytes), PAGE_SIZE); + else + vstart =3D memblock_alloc(PAGE_ALIGN(bytes), PAGE_SIZE); =20 - /* Get IO TLB memory from the low pages */ - vstart =3D memblock_alloc_low(PAGE_ALIGN(bytes), PAGE_SIZE); - if (vstart && !swiotlb_init_with_tbl(vstart, io_tlb_nslabs[SWIOTLB_LO], v= erbose)) + if (vstart && !swiotlb_init_with_tbl(vstart, io_tlb_nslabs[type], type, v= erbose)) return; =20 - if (io_tlb_start[SWIOTLB_LO]) { - memblock_free_early(io_tlb_start[SWIOTLB_LO], - PAGE_ALIGN(io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT)); - io_tlb_start[SWIOTLB_LO] =3D 0; + if (io_tlb_start[type]) { + memblock_free_early(io_tlb_start[type], + PAGE_ALIGN(io_tlb_nslabs[type] << IO_TLB_SHIFT)); + io_tlb_start[type] =3D 0; } - pr_warn("Cannot allocate buffer"); - no_iotlb_memory[SWIOTLB_LO] =3D true; + pr_warn("Cannot allocate buffer %s\n", swiotlb_name[type]); + no_iotlb_memory[type] =3D true; +} + +/* + * Statically reserve bounce buffer space and initialize bounce buffer data + * structures for the software IO TLB used to implement the DMA API. + */ +void __init +swiotlb_init(int verbose) +{ + int i; + + for (i =3D 0; i < swiotlb_nr; i++) + swiotlb_init_type(i, verbose); } =20 /* @@ -295,67 +330,68 @@ swiotlb_init(int verbose) * This should be just like above, but with some error catching. */ int -swiotlb_late_init_with_default_size(size_t default_size) +swiotlb_late_init_with_default_size(size_t default_size, enum swiotlb_t ty= pe) { - unsigned long bytes, req_nslabs =3D io_tlb_nslabs[SWIOTLB_LO]; + unsigned long bytes, req_nslabs =3D io_tlb_nslabs[type]; unsigned char *vstart =3D NULL; unsigned int order; int rc =3D 0; + gfp_t gfp_mask =3D (type =3D=3D SWIOTLB_LO) ? GFP_DMA | __GFP_NOWARN : + GFP_KERNEL | __GFP_NOWARN; =20 - if (!io_tlb_nslabs[SWIOTLB_LO]) { - io_tlb_nslabs[SWIOTLB_LO] =3D (default_size >> IO_TLB_SHIFT); - io_tlb_nslabs[SWIOTLB_LO] =3D ALIGN(io_tlb_nslabs[SWIOTLB_LO], IO_TLB_SE= GSIZE); + if (!io_tlb_nslabs[type]) { + io_tlb_nslabs[type] =3D (default_size >> IO_TLB_SHIFT); + io_tlb_nslabs[type] =3D ALIGN(io_tlb_nslabs[type], IO_TLB_SEGSIZE); } =20 /* * Get IO TLB memory from the low pages */ - order =3D get_order(io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT); - io_tlb_nslabs[SWIOTLB_LO] =3D SLABS_PER_PAGE << order; - bytes =3D io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT; + order =3D get_order(io_tlb_nslabs[type] << IO_TLB_SHIFT); + io_tlb_nslabs[type] =3D SLABS_PER_PAGE << order; + bytes =3D io_tlb_nslabs[type] << IO_TLB_SHIFT; =20 while ((SLABS_PER_PAGE << order) > IO_TLB_MIN_SLABS) { - vstart =3D (void *)__get_free_pages(GFP_DMA | __GFP_NOWARN, - order); + vstart =3D (void *)__get_free_pages(gfp_mask, order); if (vstart) break; order--; } =20 if (!vstart) { - io_tlb_nslabs[SWIOTLB_LO] =3D req_nslabs; + io_tlb_nslabs[type] =3D req_nslabs; return -ENOMEM; } if (order !=3D get_order(bytes)) { pr_warn("only able to allocate %ld MB\n", (PAGE_SIZE << order) >> 20); - io_tlb_nslabs[SWIOTLB_LO] =3D SLABS_PER_PAGE << order; + io_tlb_nslabs[type] =3D SLABS_PER_PAGE << order; } - rc =3D swiotlb_late_init_with_tbl(vstart, io_tlb_nslabs[SWIOTLB_LO]); + rc =3D swiotlb_late_init_with_tbl(vstart, io_tlb_nslabs[type], type); if (rc) free_pages((unsigned long)vstart, order); =20 return rc; } =20 -static void swiotlb_cleanup(void) +static void swiotlb_cleanup(enum swiotlb_t type) { - io_tlb_end[SWIOTLB_LO] =3D 0; - io_tlb_start[SWIOTLB_LO] =3D 0; - io_tlb_nslabs[SWIOTLB_LO] =3D 0; - max_segment[SWIOTLB_LO] =3D 0; + io_tlb_end[type] =3D 0; + io_tlb_start[type] =3D 0; + io_tlb_nslabs[type] =3D 0; + max_segment[type] =3D 0; } =20 int -swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs) +swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs, enum swiotlb_t= type) { unsigned long i, bytes; =20 bytes =3D nslabs << IO_TLB_SHIFT; =20 - io_tlb_nslabs[SWIOTLB_LO] =3D nslabs; - io_tlb_start[SWIOTLB_LO] =3D virt_to_phys(tlb); - io_tlb_end[SWIOTLB_LO] =3D io_tlb_start[SWIOTLB_LO] + bytes; + io_tlb_nslabs[type] =3D nslabs; + io_tlb_start[type] =3D virt_to_phys(tlb); + io_tlb_end[type] =3D io_tlb_start[type] + bytes; =20 set_memory_decrypted((unsigned long)tlb, bytes >> PAGE_SHIFT); memset(tlb, 0, bytes); @@ -365,63 +401,67 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long n= slabs) * to find contiguous free memory regions of size up to IO_TLB_SEGSIZE * between io_tlb_start and io_tlb_end. */ - io_tlb_list[SWIOTLB_LO] =3D (unsigned int *)__get_free_pages(GFP_KERNEL, - get_order(io_tlb_nslabs[SWIOTLB_LO] * sizeof(int))); - if (!io_tlb_list[SWIOTLB_LO]) + io_tlb_list[type] =3D (unsigned int *)__get_free_pages(GFP_KERNEL, + get_order(io_tlb_nslabs[type] * sizeof(int))); + if (!io_tlb_list[type]) goto cleanup3; =20 - io_tlb_orig_addr[SWIOTLB_LO] =3D (phys_addr_t *) + io_tlb_orig_addr[type] =3D (phys_addr_t *) __get_free_pages(GFP_KERNEL, - get_order(io_tlb_nslabs[SWIOTLB_LO] * + get_order(io_tlb_nslabs[type] * sizeof(phys_addr_t))); - if (!io_tlb_orig_addr[SWIOTLB_LO]) + if (!io_tlb_orig_addr[type]) goto cleanup4; =20 - for (i =3D 0; i < io_tlb_nslabs[SWIOTLB_LO]; i++) { - io_tlb_list[SWIOTLB_LO][i] =3D IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE= ); - io_tlb_orig_addr[SWIOTLB_LO][i] =3D INVALID_PHYS_ADDR; + for (i =3D 0; i < io_tlb_nslabs[type]; i++) { + io_tlb_list[type][i] =3D IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE); + io_tlb_orig_addr[type][i] =3D INVALID_PHYS_ADDR; } - io_tlb_index[SWIOTLB_LO] =3D 0; - no_iotlb_memory[SWIOTLB_LO] =3D false; + io_tlb_index[type] =3D 0; + no_iotlb_memory[type] =3D false; =20 - swiotlb_print_info(); + swiotlb_print_info(type); =20 late_alloc =3D 1; =20 - swiotlb_set_max_segment(io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT); + swiotlb_set_max_segment(io_tlb_nslabs[type] << IO_TLB_SHIFT, type); =20 return 0; =20 cleanup4: - free_pages((unsigned long)io_tlb_list[SWIOTLB_LO], get_order(io_tlb_nslab= s[SWIOTLB_LO] * + free_pages((unsigned long)io_tlb_list[type], get_order(io_tlb_nslabs[type= ] * sizeof(int))); - io_tlb_list[SWIOTLB_LO] =3D NULL; + io_tlb_list[type] =3D NULL; cleanup3: - swiotlb_cleanup(); + swiotlb_cleanup(type); return -ENOMEM; } =20 void __init swiotlb_exit(void) { - if (!io_tlb_orig_addr[SWIOTLB_LO]) - return; + int i; =20 - if (late_alloc) { - free_pages((unsigned long)io_tlb_orig_addr[SWIOTLB_LO], - get_order(io_tlb_nslabs[SWIOTLB_LO] * sizeof(phys_addr_t))); - free_pages((unsigned long)io_tlb_list[SWIOTLB_LO], - get_order(io_tlb_nslabs[SWIOTLB_LO] * sizeof(int))); - free_pages((unsigned long)phys_to_virt(io_tlb_start[SWIOTLB_LO]), - get_order(io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT)); - } else { - memblock_free_late(__pa(io_tlb_orig_addr[SWIOTLB_LO]), - PAGE_ALIGN(io_tlb_nslabs[SWIOTLB_LO] * sizeof(phys_addr_t))); - memblock_free_late(__pa(io_tlb_list[SWIOTLB_LO]), - PAGE_ALIGN(io_tlb_nslabs[SWIOTLB_LO] * sizeof(int))); - memblock_free_late(io_tlb_start[SWIOTLB_LO], - PAGE_ALIGN(io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT)); + for (i =3D 0; i < swiotlb_nr; i++) { + if (!io_tlb_orig_addr[i]) + continue; + + if (late_alloc) { + free_pages((unsigned long)io_tlb_orig_addr[i], + get_order(io_tlb_nslabs[i] * sizeof(phys_addr_t))); + free_pages((unsigned long)io_tlb_list[i], + get_order(io_tlb_nslabs[i] * sizeof(int))); + free_pages((unsigned long)phys_to_virt(io_tlb_start[i]), + get_order(io_tlb_nslabs[i] << IO_TLB_SHIFT)); + } else { + memblock_free_late(__pa(io_tlb_orig_addr[i]), + PAGE_ALIGN(io_tlb_nslabs[i] * sizeof(phys_addr_t))); + memblock_free_late(__pa(io_tlb_list[i]), + PAGE_ALIGN(io_tlb_nslabs[i] * sizeof(int))); + memblock_free_late(io_tlb_start[i], + PAGE_ALIGN(io_tlb_nslabs[i] << IO_TLB_SHIFT)); + } + swiotlb_cleanup(i); } - swiotlb_cleanup(); } =20 /* @@ -468,7 +508,7 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev= , phys_addr_t orig_addr, size_t mapping_size, size_t alloc_size, enum dma_data_direction dir, unsigned long attrs) { - dma_addr_t tbl_dma_addr =3D phys_to_dma_unencrypted(hwdev, io_tlb_start[S= WIOTLB_LO]); + dma_addr_t tbl_dma_addr; unsigned long flags; phys_addr_t tlb_addr; unsigned int nslots, stride, index, wrap; @@ -477,8 +517,16 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwde= v, phys_addr_t orig_addr, unsigned long offset_slots; unsigned long max_slots; unsigned long tmp_io_tlb_used; + unsigned long dma_mask =3D min_not_zero(*hwdev->dma_mask, + hwdev->bus_dma_limit); + int type; =20 - if (no_iotlb_memory[SWIOTLB_LO]) + if (swiotlb_nr > 1 && dma_mask =3D=3D DMA_BIT_MASK(64)) + type =3D SWIOTLB_HI; + else + type =3D SWIOTLB_LO; + + if (no_iotlb_memory[type]) panic("Can not allocate SWIOTLB buffer earlier and can't now provide you= with the DMA bounce buffer"); =20 if (mem_encrypt_active()) @@ -490,6 +538,8 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev= , phys_addr_t orig_addr, return (phys_addr_t)DMA_MAPPING_ERROR; } =20 + tbl_dma_addr =3D phys_to_dma_unencrypted(hwdev, io_tlb_start[type]); + mask =3D dma_get_seg_boundary(hwdev); =20 tbl_dma_addr &=3D mask; @@ -521,11 +571,11 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwd= ev, phys_addr_t orig_addr, */ spin_lock_irqsave(&io_tlb_lock, flags); =20 - if (unlikely(nslots > io_tlb_nslabs[SWIOTLB_LO] - io_tlb_used[SWIOTLB_LO]= )) + if (unlikely(nslots > io_tlb_nslabs[type] - io_tlb_used[type])) goto not_found; =20 - index =3D ALIGN(io_tlb_index[SWIOTLB_LO], stride); - if (index >=3D io_tlb_nslabs[SWIOTLB_LO]) + index =3D ALIGN(io_tlb_index[type], stride); + if (index >=3D io_tlb_nslabs[type]) index =3D 0; wrap =3D index; =20 @@ -533,7 +583,7 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev= , phys_addr_t orig_addr, while (iommu_is_span_boundary(index, nslots, offset_slots, max_slots)) { index +=3D stride; - if (index >=3D io_tlb_nslabs[SWIOTLB_LO]) + if (index >=3D io_tlb_nslabs[type]) index =3D 0; if (index =3D=3D wrap) goto not_found; @@ -544,42 +594,42 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwd= ev, phys_addr_t orig_addr, * contiguous buffers, we allocate the buffers from that slot * and mark the entries as '0' indicating unavailable. */ - if (io_tlb_list[SWIOTLB_LO][index] >=3D nslots) { + if (io_tlb_list[type][index] >=3D nslots) { int count =3D 0; =20 for (i =3D index; i < (int) (index + nslots); i++) - io_tlb_list[SWIOTLB_LO][i] =3D 0; + io_tlb_list[type][i] =3D 0; for (i =3D index - 1; (OFFSET(i, IO_TLB_SEGSIZE) !=3D IO_TLB_SEGSIZE - 1) && - io_tlb_list[SWIOTLB_LO][i]; + io_tlb_list[type][i]; i--) - io_tlb_list[SWIOTLB_LO][i] =3D ++count; - tlb_addr =3D io_tlb_start[SWIOTLB_LO] + (index << IO_TLB_SHIFT); + io_tlb_list[type][i] =3D ++count; + tlb_addr =3D io_tlb_start[type] + (index << IO_TLB_SHIFT); =20 /* * Update the indices to avoid searching in the next * round. */ - io_tlb_index[SWIOTLB_LO] =3D ((index + nslots) < io_tlb_nslabs[SWIOTLB_= LO] + io_tlb_index[type] =3D ((index + nslots) < io_tlb_nslabs[type] ? (index + nslots) : 0); =20 goto found; } index +=3D stride; - if (index >=3D io_tlb_nslabs[SWIOTLB_LO]) + if (index >=3D io_tlb_nslabs[type]) index =3D 0; } while (index !=3D wrap); =20 not_found: - tmp_io_tlb_used =3D io_tlb_used[SWIOTLB_LO]; + tmp_io_tlb_used =3D io_tlb_used[type]; =20 spin_unlock_irqrestore(&io_tlb_lock, flags); if (!(attrs & DMA_ATTR_NO_WARN) && printk_ratelimit()) - dev_warn(hwdev, "swiotlb buffer is full (sz: %zd bytes), total %lu (slot= s), used %lu (slots)\n", - alloc_size, io_tlb_nslabs[SWIOTLB_LO], tmp_io_tlb_used); + dev_warn(hwdev, "%s swiotlb buffer is full (sz: %zd bytes), total %lu (s= lots), used %lu (slots)\n", + swiotlb_name[type], alloc_size, io_tlb_nslabs[type], tmp_io_tlb_used); return (phys_addr_t)DMA_MAPPING_ERROR; found: - io_tlb_used[SWIOTLB_LO] +=3D nslots; + io_tlb_used[type] +=3D nslots; spin_unlock_irqrestore(&io_tlb_lock, flags); =20 /* @@ -588,7 +638,7 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev= , phys_addr_t orig_addr, * needed. */ for (i =3D 0; i < nslots; i++) - io_tlb_orig_addr[SWIOTLB_LO][index+i] =3D orig_addr + (i << IO_TLB_SHIFT= ); + io_tlb_orig_addr[type][index+i] =3D orig_addr + (i << IO_TLB_SHIFT); if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC) && (dir =3D=3D DMA_TO_DEVICE || dir =3D=3D DMA_BIDIRECTIONAL)) swiotlb_bounce(orig_addr, tlb_addr, mapping_size, DMA_TO_DEVICE); @@ -605,8 +655,9 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, phy= s_addr_t tlb_addr, { unsigned long flags; int i, count, nslots =3D ALIGN(alloc_size, 1 << IO_TLB_SHIFT) >> IO_TLB_S= HIFT; - int index =3D (tlb_addr - io_tlb_start[SWIOTLB_LO]) >> IO_TLB_SHIFT; - phys_addr_t orig_addr =3D io_tlb_orig_addr[SWIOTLB_LO][index]; + int type =3D swiotlb_get_type(tlb_addr); + int index =3D (tlb_addr - io_tlb_start[type]) >> IO_TLB_SHIFT; + phys_addr_t orig_addr =3D io_tlb_orig_addr[type][index]; =20 /* * First, sync the memory before unmapping the entry @@ -625,14 +676,14 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, p= hys_addr_t tlb_addr, spin_lock_irqsave(&io_tlb_lock, flags); { count =3D ((index + nslots) < ALIGN(index + 1, IO_TLB_SEGSIZE) ? - io_tlb_list[SWIOTLB_LO][index + nslots] : 0); + io_tlb_list[type][index + nslots] : 0); /* * Step 1: return the slots to the free list, merging the * slots with superceeding slots */ for (i =3D index + nslots - 1; i >=3D index; i--) { - io_tlb_list[SWIOTLB_LO][i] =3D ++count; - io_tlb_orig_addr[SWIOTLB_LO][i] =3D INVALID_PHYS_ADDR; + io_tlb_list[type][i] =3D ++count; + io_tlb_orig_addr[type][i] =3D INVALID_PHYS_ADDR; } /* * Step 2: merge the returned slots with the preceding slots, @@ -640,11 +691,11 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, p= hys_addr_t tlb_addr, */ for (i =3D index - 1; (OFFSET(i, IO_TLB_SEGSIZE) !=3D IO_TLB_SEGSIZE - 1) && - io_tlb_list[SWIOTLB_LO][i]; + io_tlb_list[type][i]; i--) - io_tlb_list[SWIOTLB_LO][i] =3D ++count; + io_tlb_list[type][i] =3D ++count; =20 - io_tlb_used[SWIOTLB_LO] -=3D nslots; + io_tlb_used[type] -=3D nslots; } spin_unlock_irqrestore(&io_tlb_lock, flags); } @@ -653,8 +704,9 @@ void swiotlb_tbl_sync_single(struct device *hwdev, phys= _addr_t tlb_addr, size_t size, enum dma_data_direction dir, enum dma_sync_target target) { - int index =3D (tlb_addr - io_tlb_start[SWIOTLB_LO]) >> IO_TLB_SHIFT; - phys_addr_t orig_addr =3D io_tlb_orig_addr[SWIOTLB_LO][index]; + int type =3D swiotlb_get_type(tlb_addr); + int index =3D (tlb_addr - io_tlb_start[type]) >> IO_TLB_SHIFT; + phys_addr_t orig_addr =3D io_tlb_orig_addr[type][index]; =20 if (orig_addr =3D=3D INVALID_PHYS_ADDR) return; @@ -737,6 +789,15 @@ static int __init swiotlb_create_debugfs(void) root =3D debugfs_create_dir("swiotlb", NULL); debugfs_create_ulong("io_tlb_nslabs", 0400, root, &io_tlb_nslabs[SWIOTLB_= LO]); debugfs_create_ulong("io_tlb_used", 0400, root, &io_tlb_used[SWIOTLB_LO]); + + if (swiotlb_nr =3D=3D 1) + return 0; + + debugfs_create_ulong("io_tlb_nslabs-highmem", 0400, + root, &io_tlb_nslabs[SWIOTLB_HI]); + debugfs_create_ulong("io_tlb_used-highmem", 0400, + root, &io_tlb_used[SWIOTLB_HI]); + return 0; } =20 --=20 2.17.1 From nobody Tue May 7 02:35:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1dmarc=pass fromdomain=oracle.com); dmarc=pass(p=none dis=none) header.from=oracle.com ARC-Seal: i=2; a=rsa-sha256; t=1612395603; cv=pass; d=zohomail.com; s=zohoarc; b=cWcHd3FMZu/2VNsN/AcJaE65EzZSUsSDBC1UCGgRoq+T0PAlniTClHi80Ro63L7GqN/QLTZS6SD9tdnhQ9FT5uGpRYm5VDgxEhKcIeizoBJFgdVrjyeEWZOccU1KJDU7DlSHs3557elhSZ8pMSeuckrxIw3xXdxkntM06FA2dUE= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612395603; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ufcarBGag7Sjp5Mq5hX2uNHVicBXg/LdEy+UArhzb+Q=; b=Rrd4oVHBXOgCk+qq1hsO5vA/H7YDPs6t2FjfOlMv/W2X5+cvUOSzKvFnKPfGwe1jKpLtP+OsLA8P5UGxqqbdQAGq0qVzctFHs0D0SHEf2+IxzMs6KoX03DJjjQ/072y9D5P/8SDrUHX3haxZ1I4GW9iFf4jRxLUIGW4BCPPxG6M= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1dmarc=pass fromdomain=oracle.com); dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1612395603126765.7633978803823; Wed, 3 Feb 2021 15:40:03 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.81103.149254 (Exim 4.92) (envelope-from ) id 1l7RkT-0006jL-KO; Wed, 03 Feb 2021 23:39:49 +0000 Received: by outflank-mailman (output) from mailman id 81103.149254; Wed, 03 Feb 2021 23:39:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l7RkT-0006jE-HA; Wed, 03 Feb 2021 23:39:49 +0000 Received: by outflank-mailman (input) for mailman id 81103; Wed, 03 Feb 2021 23:39:48 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l7RkS-0006iz-6b for xen-devel@lists.xenproject.org; Wed, 03 Feb 2021 23:39:48 +0000 Received: from aserp2130.oracle.com (unknown [141.146.126.79]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id a22cfbcb-3358-4927-91d6-092995ce037f; Wed, 03 Feb 2021 23:39:47 +0000 (UTC) Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 113N9lJ4053674; Wed, 3 Feb 2021 23:38:09 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2130.oracle.com with ESMTP id 36cvyb2weg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 Feb 2021 23:38:08 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 113NBZjm083373; Wed, 3 Feb 2021 23:38:08 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2174.outbound.protection.outlook.com [104.47.56.174]) by aserp3030.oracle.com with ESMTP id 36dh1rp0ay-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 Feb 2021 23:38:08 +0000 Received: from BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) by SJ0PR10MB4784.namprd10.prod.outlook.com (2603:10b6:a03:2d4::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.19; Wed, 3 Feb 2021 23:38:05 +0000 Received: from BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::b52e:bdd3:d193:4d14]) by BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::b52e:bdd3:d193:4d14%7]) with mapi id 15.20.3805.026; Wed, 3 Feb 2021 23:38:05 +0000 Received: from localhost.localdomain (138.3.200.16) by CH0PR03CA0008.namprd03.prod.outlook.com (2603:10b6:610:b0::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3825.17 via Frontend Transport; Wed, 3 Feb 2021 23:37:59 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: a22cfbcb-3358-4927-91d6-092995ce037f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=ufcarBGag7Sjp5Mq5hX2uNHVicBXg/LdEy+UArhzb+Q=; b=pnoIjQjRAimCOZGBFABR649EZDLrKxG6Rg+Koe7dVE64t/PjnvnPZt/5g7CWcLP5cu52 P6eBa7EAlCqK/BoeTW6vxGAfUKSPLS3hYYUXkTTMlMMLrZJQygd0WggDf/bNlyJP8Ach upL7IU+DgF9INdgJ9Jy5KwJ94emFs97z0p49t0KEbZLYH0NU/Sb0NQHW/ppSJ3yG26o3 UeDWaKBcm9re+ww+zpHOsdb45vWIIZeVvU1aF7NtPhh3qxt8DftSnQAzVNbztT7vRnVD YMckMHkzfZaqs8LhaE/YbExCu0PPhS2LoJDTbRxu8k6i93v+Qr81JeiCNCaVBw2IXiJY gw== ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JmNqAIq6lFOC9ainynSrQWiPZxnortBSHQvRtJoXz7LQpCjd3M+ye/KymfgLmc4EJeh2XCmLTv7sCAmczKH9xO6EESx5QQPcX+Pi7PAwsZHkIVs9jytyNBNZzT7htfvXU2mXGVhPDPF8lK3ulnVkvhUwo1A5ir4EXEtkyels3vUl6KvXxEcvwIm2MDJFYwcUTqh/UucspnoQEOV8WVWhuFYFSq2XCUiFEB4+Ab3cFD3LxCQ4ykD/RpE+H12AZCxjEr7u/lzXFuPUI8Zv0e3N5tAI592Tt8HieDU7Kvn4pctbe3RetR/iBRoUwm+WRjHjjpFa08O/i2TIZv7u00nzoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ufcarBGag7Sjp5Mq5hX2uNHVicBXg/LdEy+UArhzb+Q=; b=A0ZPOADVVWV+Uj0/W8XGR394r9l5spc0nvzBnJvU0/rTEDb6RY8kZCTqRuBygUm03fprvI9YUgzPZSqNagCDc+RUmdqhN5fGnTrQjiBIWvB/iSZEi9cZNa0Wo+8mJ0cCs/gG2FQ7dICg5b0HcPS/TXK+Oul2GPKEgXO+M9AgitIDNtj+krmSsZ/d16skFak7nXurOhCJV2OykyOc5O43pjwcbIGL0mGuIPyxH7Fh3saJ2ELcsTlsC9i+mJQF5CBt5B9t9dRRTbxRDywZI2QkUHhz2fNRvEnMnX7d3RBnwoXQjwgTdZ4+zhrHBk6KPPfcFnXVslNmWK5xJfg/uCzk/w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ufcarBGag7Sjp5Mq5hX2uNHVicBXg/LdEy+UArhzb+Q=; b=SuQhKsBZuPC3v2+9NTZ3wq0i3I8MSiWjwvz1ZyiiwHaXki6ngpjRZXZixVoFMMxGo7dPX/PYBT1Mt+IFEMuaxqcskcFwb4xhYy3KAWa+xsYaoLVcsDiiDtHDgTrC9Xu95xQBHdW8C8/ibsPNos9Abpi3nPaCoF7GwaiyZTzlIDU= Authentication-Results: lists.freedesktop.org; dkim=none (message not signed) header.d=none;lists.freedesktop.org; dmarc=none action=none header.from=oracle.com; From: Dongli Zhang To: dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, iommu@lists.linux-foundation.org, linux-mips@vger.kernel.org, linux-mmc@vger.kernel.org, linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, nouveau@lists.freedesktop.org, x86@kernel.org, xen-devel@lists.xenproject.org Cc: linux-kernel@vger.kernel.org, adrian.hunter@intel.com, akpm@linux-foundation.org, benh@kernel.crashing.org, bskeggs@redhat.com, bhelgaas@google.com, bp@alien8.de, boris.ostrovsky@oracle.com, hch@lst.de, chris@chris-wilson.co.uk, daniel@ffwll.ch, airlied@linux.ie, hpa@zytor.com, mingo@kernel.org, mingo@redhat.com, jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com, jgross@suse.com, konrad.wilk@oracle.com, m.szyprowski@samsung.com, matthew.auld@intel.com, mpe@ellerman.id.au, rppt@kernel.org, paulus@samba.org, peterz@infradead.org, robin.murphy@arm.com, rodrigo.vivi@intel.com, sstabellini@kernel.org, bauerman@linux.ibm.com, tsbogend@alpha.franken.de, tglx@linutronix.de, ulf.hansson@linaro.org, joe.jin@oracle.com, thomas.lendacky@amd.com Subject: [PATCH RFC v1 5/6] xen-swiotlb: convert variables to arrays Date: Wed, 3 Feb 2021 15:37:08 -0800 Message-Id: <20210203233709.19819-6-dongli.zhang@oracle.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210203233709.19819-1-dongli.zhang@oracle.com> References: <20210203233709.19819-1-dongli.zhang@oracle.com> X-Originating-IP: [138.3.200.16] X-ClientProxiedBy: CH0PR03CA0008.namprd03.prod.outlook.com (2603:10b6:610:b0::13) To BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 55a79f1c-f122-4636-8dd4-08d8c89cc12c X-MS-TrafficTypeDiagnostic: SJ0PR10MB4784: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:173; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: w77riGtFxYZxbwSzlnLDDwaRSpIhQOZiCo7C6NAvJRIvk6fyvrnj5N07AptsCQM8Ls9ytt1iCLVQDJZYrEFBvlTjOhbcE9YJtxeD1SD4ad6x9UmE3mT0P2uDXh8kPTr3JlWDod/q2PNM7LqKgCTowQDE8jXR2bOUVt4ix3LvHciJZ4Xcq7H2GXDhKzdwXTKGu5Mgc/3Qev9FMhOZQ9g17mKuf9xfaYHfo6Dx/rzxrLP/DVQdxytqGBIVhk2jo8iq4rZtbHv6iYSfNqY00vHZ5r8pP9r/N/sEP6WDw/6JBKAm61IGhvf3fQ4beQAIaqw1aErcezXYVibpPmEofuXM6cDBnRgIULXs8zoronpTqW1+mLoTnkuCPvTmeSFbnUNJrCY5zMjfLQ0N8HxWz9APVN7Nik94Ev2ddkvwXkbddkqR7lfedjlniJnS/LArFITW5iqTd/xi5Rd/D2U5fDK3tMSSEh3gesvmGePlvsfgi7IXv3dlgzrdtausINCULlW0JpnJJvTOLkHQAU9XC0cmLmrBmfA2STeUzp5HCTZj+w5DWGhq4YRjzIAX8fbqqj3pDjD9QI5Ij9O9xtbwOV6yI4oi1pFIVamN9ei02syvNXM= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB2663.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(366004)(39860400002)(396003)(376002)(346002)(83380400001)(6666004)(316002)(5660300002)(956004)(66946007)(6506007)(86362001)(7406005)(1076003)(66476007)(8676002)(186003)(26005)(36756003)(7416002)(478600001)(2906002)(66556008)(8936002)(6486002)(16526019)(69590400011)(4326008)(6512007)(44832011)(921005)(2616005)(52116002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?JOaqLB/L6hqA4VUE0kNmiLvAjzCeznvsu3Cr6DfHJWdEzSttbELTyL58Z9LL?= =?us-ascii?Q?ahqD02oPjGOF/MLn+QNete/4x2BQJuL4BmpjZaT5x3TRnVBy3Wlh9xgE8fsV?= =?us-ascii?Q?VVNkDHHxkITVzis4PdWG8B7PXb6R3xPxM0QnENF0AWmWS0HLV//9XazhbpcK?= =?us-ascii?Q?XmpD7trzVCKsUv/WpjcjAGMVXKneA5Yx9kIDfqSh2UhvuP/rH/n+QP8S4tap?= =?us-ascii?Q?ug1ebPrVG9itaWj+Eo7WgCgjWKxoSAvVt+KOeHIWfRLUqo/YZv/PNnGFKZ+y?= =?us-ascii?Q?NRYwucUzawHwv9EQHRyZFuai97VEQVwIwWJ2DLh++ktFL0aowH4Gvmdd8Z90?= =?us-ascii?Q?ZfR5Q7VdIg8DkVImvEfkossqIUJsaLEFQDuZd8Nz+NKlaD0i9iv7xZ94+Hj9?= =?us-ascii?Q?Ief7D+OF+3JggwgSKfljSwLBJL/KWwEDLU2o0d4d7quP9dsYji4Rn3zSQXCX?= =?us-ascii?Q?YHnRjGhSYQlYYS/8C26DWtMF625wdFu5CBgdLqNzwb+3zPvxYRevw5JfCUgW?= =?us-ascii?Q?WFrWq3wn6Q7MAEKly0t06OpKuQ0D+oCxW4p+ne5TOvvdBZtPbsP4j2KQc6L4?= =?us-ascii?Q?pTDqTV9cebXeNKgw6DSqPvEugv2EDgIyLGfD9/zqWV/bhTwdKCyRNx9bhc2E?= =?us-ascii?Q?1OTjvA+ijbnKDcbZyG8qz24UhYVmZ3I9zq5gwD9KSfRvOIYTra0O5OBpz0j4?= =?us-ascii?Q?UQmsYodAQ6aGaxH1t8bAK5xJpBz5YosKCtXuFLJ3woygzLUCpZP18fLGTX0k?= =?us-ascii?Q?Z5i4YGVXoEOHmO6CegU0vYFLYpo8Q7bhGQZZkC/3xIO/eJ3swYnN35uaLnrh?= =?us-ascii?Q?LkALh+TdMNC8nTUvCIKwfWipsx0goweO3wb6MA7OD16mRv9YAvLKVcGdEWhn?= =?us-ascii?Q?29dEIbdkSRoPkfangpUGDOiCXyr1ikK8v7DWDY+Fqy6sP0ws4RBvDBzPZAdK?= =?us-ascii?Q?5pnYA67j39+xPNsLLKTIWA534gYGFUyyumFunSj+nTgjPmhYRHfKLKuwGfQW?= =?us-ascii?Q?CFj1qI/H08Qh4n7CyGJB+7XEsrHq52oARzMGKYALm/GGwT1TOFAH/QKk8Ixg?= =?us-ascii?Q?czp2pmvr?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 55a79f1c-f122-4636-8dd4-08d8c89cc12c X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2663.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2021 23:38:05.6010 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: jUSQZrsRsfIIenrB0i+mXbNWLbyi4KAfiByVhFlKYSye86P0YY8sKEgjzQs4qhhWqfZ1mhwlltkYXlrN55IWjg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4784 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9884 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 spamscore=0 phishscore=0 suspectscore=0 mlxlogscore=999 bulkscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102030143 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9884 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1015 impostorscore=0 mlxscore=0 spamscore=0 bulkscore=0 priorityscore=1501 adultscore=0 lowpriorityscore=0 malwarescore=0 phishscore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102030143 X-ZohoMail-DKIM: pass (identity @oracle.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch converts several xen-swiotlb related variables to arrays, in order to maintain stat/status for different swiotlb buffers. Here are variables involved: - xen_io_tlb_start and xen_io_tlb_end - xen_io_tlb_nslabs - MAX_DMA_BITS There is no functional change and this is to prepare to enable 64-bit xen-swiotlb. Cc: Joe Jin Signed-off-by: Dongli Zhang --- drivers/xen/swiotlb-xen.c | 75 +++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 662638093542..e18cae693cdc 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -39,15 +39,17 @@ #include =20 #include -#define MAX_DMA_BITS 32 /* * Used to do a quick range check in swiotlb_tbl_unmap_single and * swiotlb_tbl_sync_single_*, to see if the memory was in fact allocated b= y this * API. */ =20 -static char *xen_io_tlb_start, *xen_io_tlb_end; -static unsigned long xen_io_tlb_nslabs; +static char *xen_io_tlb_start[SWIOTLB_MAX], *xen_io_tlb_end[SWIOTLB_MAX]; +static unsigned long xen_io_tlb_nslabs[SWIOTLB_MAX]; + +static int max_dma_bits[] =3D {32, 64}; + /* * Quick lookup value of the bus address of the IOTLB. */ @@ -112,8 +114,8 @@ static int is_xen_swiotlb_buffer(struct device *dev, dm= a_addr_t dma_addr) * in our domain. Therefore _only_ check address within our domain. */ if (pfn_valid(PFN_DOWN(paddr))) { - return paddr >=3D virt_to_phys(xen_io_tlb_start) && - paddr < virt_to_phys(xen_io_tlb_end); + return paddr >=3D virt_to_phys(xen_io_tlb_start[SWIOTLB_LO]) && + paddr < virt_to_phys(xen_io_tlb_end[SWIOTLB_LO]); } return 0; } @@ -137,7 +139,7 @@ xen_swiotlb_fixup(void *buf, size_t size, unsigned long= nslabs) p + (i << IO_TLB_SHIFT), get_order(slabs << IO_TLB_SHIFT), dma_bits, &dma_handle); - } while (rc && dma_bits++ < MAX_DMA_BITS); + } while (rc && dma_bits++ < max_dma_bits[SWIOTLB_LO]); if (rc) return rc; =20 @@ -148,12 +150,13 @@ xen_swiotlb_fixup(void *buf, size_t size, unsigned lo= ng nslabs) static unsigned long xen_set_nslabs(unsigned long nr_tbl) { if (!nr_tbl) { - xen_io_tlb_nslabs =3D (64 * 1024 * 1024 >> IO_TLB_SHIFT); - xen_io_tlb_nslabs =3D ALIGN(xen_io_tlb_nslabs, IO_TLB_SEGSIZE); + xen_io_tlb_nslabs[SWIOTLB_LO] =3D (64 * 1024 * 1024 >> IO_TLB_SHIFT); + xen_io_tlb_nslabs[SWIOTLB_LO] =3D ALIGN(xen_io_tlb_nslabs[SWIOTLB_LO], + IO_TLB_SEGSIZE); } else - xen_io_tlb_nslabs =3D nr_tbl; + xen_io_tlb_nslabs[SWIOTLB_LO] =3D nr_tbl; =20 - return xen_io_tlb_nslabs << IO_TLB_SHIFT; + return xen_io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT; } =20 enum xen_swiotlb_err { @@ -184,16 +187,16 @@ int __ref xen_swiotlb_init(int verbose, bool early) enum xen_swiotlb_err m_ret =3D XEN_SWIOTLB_UNKNOWN; unsigned int repeat =3D 3; =20 - xen_io_tlb_nslabs =3D swiotlb_nr_tbl(SWIOTLB_LO); + xen_io_tlb_nslabs[SWIOTLB_LO] =3D swiotlb_nr_tbl(SWIOTLB_LO); retry: - bytes =3D xen_set_nslabs(xen_io_tlb_nslabs); - order =3D get_order(xen_io_tlb_nslabs << IO_TLB_SHIFT); + bytes =3D xen_set_nslabs(xen_io_tlb_nslabs[SWIOTLB_LO]); + order =3D get_order(xen_io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT); =20 /* * IO TLB memory already allocated. Just use it. */ if (io_tlb_start[SWIOTLB_LO] !=3D 0) { - xen_io_tlb_start =3D phys_to_virt(io_tlb_start[SWIOTLB_LO]); + xen_io_tlb_start[SWIOTLB_LO] =3D phys_to_virt(io_tlb_start[SWIOTLB_LO]); goto end; } =20 @@ -201,76 +204,78 @@ int __ref xen_swiotlb_init(int verbose, bool early) * Get IO TLB memory from any location. */ if (early) { - xen_io_tlb_start =3D memblock_alloc(PAGE_ALIGN(bytes), + xen_io_tlb_start[SWIOTLB_LO] =3D memblock_alloc(PAGE_ALIGN(bytes), PAGE_SIZE); - if (!xen_io_tlb_start) + if (!xen_io_tlb_start[SWIOTLB_LO]) panic("%s: Failed to allocate %lu bytes align=3D0x%lx\n", __func__, PAGE_ALIGN(bytes), PAGE_SIZE); } else { #define SLABS_PER_PAGE (1 << (PAGE_SHIFT - IO_TLB_SHIFT)) #define IO_TLB_MIN_SLABS ((1<<20) >> IO_TLB_SHIFT) while ((SLABS_PER_PAGE << order) > IO_TLB_MIN_SLABS) { - xen_io_tlb_start =3D (void *)xen_get_swiotlb_free_pages(order); - if (xen_io_tlb_start) + xen_io_tlb_start[SWIOTLB_LO] =3D (void *)xen_get_swiotlb_free_pages(ord= er); + if (xen_io_tlb_start[SWIOTLB_LO]) break; order--; } if (order !=3D get_order(bytes)) { pr_warn("Warning: only able to allocate %ld MB for software IO TLB\n", (PAGE_SIZE << order) >> 20); - xen_io_tlb_nslabs =3D SLABS_PER_PAGE << order; - bytes =3D xen_io_tlb_nslabs << IO_TLB_SHIFT; + xen_io_tlb_nslabs[SWIOTLB_LO] =3D SLABS_PER_PAGE << order; + bytes =3D xen_io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT; } } - if (!xen_io_tlb_start) { + if (!xen_io_tlb_start[SWIOTLB_LO]) { m_ret =3D XEN_SWIOTLB_ENOMEM; goto error; } /* * And replace that memory with pages under 4GB. */ - rc =3D xen_swiotlb_fixup(xen_io_tlb_start, + rc =3D xen_swiotlb_fixup(xen_io_tlb_start[SWIOTLB_LO], bytes, - xen_io_tlb_nslabs); + xen_io_tlb_nslabs[SWIOTLB_LO]); if (rc) { if (early) - memblock_free(__pa(xen_io_tlb_start), + memblock_free(__pa(xen_io_tlb_start[SWIOTLB_LO]), PAGE_ALIGN(bytes)); else { - free_pages((unsigned long)xen_io_tlb_start, order); - xen_io_tlb_start =3D NULL; + free_pages((unsigned long)xen_io_tlb_start[SWIOTLB_LO], order); + xen_io_tlb_start[SWIOTLB_LO] =3D NULL; } m_ret =3D XEN_SWIOTLB_EFIXUP; goto error; } if (early) { - if (swiotlb_init_with_tbl(xen_io_tlb_start, xen_io_tlb_nslabs, + if (swiotlb_init_with_tbl(xen_io_tlb_start[SWIOTLB_LO], + xen_io_tlb_nslabs[SWIOTLB_LO], SWIOTLB_LO, verbose)) panic("Cannot allocate SWIOTLB buffer"); rc =3D 0; } else - rc =3D swiotlb_late_init_with_tbl(xen_io_tlb_start, - xen_io_tlb_nslabs, SWIOTLB_LO); + rc =3D swiotlb_late_init_with_tbl(xen_io_tlb_start[SWIOTLB_LO], + xen_io_tlb_nslabs[SWIOTLB_LO], + SWIOTLB_LO); =20 end: - xen_io_tlb_end =3D xen_io_tlb_start + bytes; + xen_io_tlb_end[SWIOTLB_LO] =3D xen_io_tlb_start[SWIOTLB_LO] + bytes; if (!rc) swiotlb_set_max_segment(PAGE_SIZE, SWIOTLB_LO); =20 return rc; error: if (repeat--) { - xen_io_tlb_nslabs =3D max(1024UL, /* Min is 2MB */ - (xen_io_tlb_nslabs >> 1)); + xen_io_tlb_nslabs[SWIOTLB_LO] =3D max(1024UL, /* Min is 2MB */ + (xen_io_tlb_nslabs[SWIOTLB_LO] >> 1)); pr_info("Lowering to %luMB\n", - (xen_io_tlb_nslabs << IO_TLB_SHIFT) >> 20); + (xen_io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT) >> 20); goto retry; } pr_err("%s (rc:%d)\n", xen_swiotlb_error(m_ret), rc); if (early) panic("%s (rc:%d)", xen_swiotlb_error(m_ret), rc); else - free_pages((unsigned long)xen_io_tlb_start, order); + free_pages((unsigned long)xen_io_tlb_start[SWIOTLB_LO], order); return rc; } =20 @@ -561,7 +566,7 @@ xen_swiotlb_sync_sg_for_device(struct device *dev, stru= ct scatterlist *sgl, static int xen_swiotlb_dma_supported(struct device *hwdev, u64 mask) { - return xen_virt_to_bus(hwdev, xen_io_tlb_end - 1) <=3D mask; + return xen_virt_to_bus(hwdev, xen_io_tlb_end[SWIOTLB_LO] - 1) <=3D mask; } =20 const struct dma_map_ops xen_swiotlb_dma_ops =3D { --=20 2.17.1 From nobody Tue May 7 02:35:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1dmarc=pass fromdomain=oracle.com); dmarc=pass(p=none dis=none) header.from=oracle.com ARC-Seal: i=2; a=rsa-sha256; t=1612395683; cv=pass; d=zohomail.com; s=zohoarc; b=Y01onz4DnDB/RW2grtt8KsK86ZFz/XHJBDO9Is+dZXzbieE9fqvem7aXSqg3imSfbR0myt80Q1p4ugVTM3dRzQwlYO7Lpf7q+WHGsozW2ni9kpJMRsO5Rd2lTr5Gk48+wh/r0KfYuJgeSms7OcLd+qte5Ci5FbivHwZja/9oq6I= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612395683; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=T1bb0XTc3eHB9TaU/o5/wnJRnLYt5yXAz2mfRftNqPk=; b=JNeEJKTGS76EiLA60LbVSOUtSnmC2fYiWoyx4nm7cwJ6lW2la+1Sm42Dw76zFVFIy/5HgenHROdn5FqO9C69K/pP9xRMvsHKUCT9+mWSZz5b+wPyrkemWGQQwtmoUu+z4Pdz4g6eh7AyJbBA3+yN5UoXafqFXSYsMboQTW9of8I= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1dmarc=pass fromdomain=oracle.com); dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 16123956839761000.013784314989; Wed, 3 Feb 2021 15:41:23 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.81106.149267 (Exim 4.92) (envelope-from ) id 1l7Rlm-0007b7-1D; Wed, 03 Feb 2021 23:41:10 +0000 Received: by outflank-mailman (output) from mailman id 81106.149267; Wed, 03 Feb 2021 23:41:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l7Rll-0007b0-SH; Wed, 03 Feb 2021 23:41:09 +0000 Received: by outflank-mailman (input) for mailman id 81106; Wed, 03 Feb 2021 23:41:09 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l7Rll-0007as-0R for xen-devel@lists.xenproject.org; Wed, 03 Feb 2021 23:41:09 +0000 Received: from userp2130.oracle.com (unknown [156.151.31.86]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ce2f8cf3-523f-4670-ab35-31b8a9e56a40; Wed, 03 Feb 2021 23:41:07 +0000 (UTC) Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 113NAGKe046541; Wed, 3 Feb 2021 23:40:15 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 36cxvr5fk6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 Feb 2021 23:40:15 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 113NBZKB083400; Wed, 3 Feb 2021 23:38:14 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2171.outbound.protection.outlook.com [104.47.56.171]) by aserp3030.oracle.com with ESMTP id 36dh1rp0e3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 Feb 2021 23:38:14 +0000 Received: from BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) by SJ0PR10MB4784.namprd10.prod.outlook.com (2603:10b6:a03:2d4::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.19; Wed, 3 Feb 2021 23:38:11 +0000 Received: from BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::b52e:bdd3:d193:4d14]) by BYAPR10MB2663.namprd10.prod.outlook.com ([fe80::b52e:bdd3:d193:4d14%7]) with mapi id 15.20.3805.026; Wed, 3 Feb 2021 23:38:11 +0000 Received: from localhost.localdomain (138.3.200.16) by CH0PR03CA0008.namprd03.prod.outlook.com (2603:10b6:610:b0::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3825.17 via Frontend Transport; Wed, 3 Feb 2021 23:38:05 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ce2f8cf3-523f-4670-ab35-31b8a9e56a40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=T1bb0XTc3eHB9TaU/o5/wnJRnLYt5yXAz2mfRftNqPk=; b=AQgAsmYNKDuhJEXkKCCLjZ4btVMHNAaabw7AQaLEHjRQ1DxQ6rsmXgUd7yOAwDKP9eE6 /jn8Fue+dSJnNLWUz8OvbspBrcSBTd2mFnhKJJYcoRiHLkKv0pQ8floQsGn4dTpuwT0r XCDo8DnyDk48OzkHCP/OfGRAcLmqeSD7XxwLuh5HakhRJ5fe0Xig1IQqnm5Sxz235Ir8 mKVab/Wc+yzfaXw0POZyJ5aL5Tt0Magst+aUTkPD5NEilXYr61/hnUQYX8qpWRJVIPie lYzpfQkSuh7hAS2ER2mkomqrQd0Q61hS4+sZxC14yRf+48hMe4kXNeamnh4m+vxdT9M4 3w== ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bzvh6TTjCKW6F/TBlPDxODMljmdU5b4U3YAZ35m4YjhLwwteroxdqRsIJXe6JrhtN/uUMUOElMzdZF1C1ENAr/iL1fuHxcW3WJ9TRa2Y0XqOGJ2RXu4LZVIpUtij3CG7vhsmbZ1bGXtFSLQSpltPFLoYkclDIu0iNCjpPLnCFanCiIOQeozHW9gQkSabewgu0PiVkxwh2PAy2tiAC2ZMA4AA/5FujqwuP3Nlw9VXAGOYvJkIEMSbYJTTzYk4PkLiBnJZ210q0KU4xFKDBtqO2M/kgU6/BGf2v2p/32pOyIlvd4KGSKYlFzG8qCSOW5qaNusG35HP52alvI07I30YpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=T1bb0XTc3eHB9TaU/o5/wnJRnLYt5yXAz2mfRftNqPk=; b=NsRvqL3XdcmO+sHJOG6vt9wkb0lFGLkVs6UQrK32rQH1C6R8jsab1XeW9C+xmQrrhtcwtO5GxWPtzwIXzsM8O9wJTXQuqvAStPW7TRG97ZtI5TvX4TDX6474kqE5dKXn6VUYTXneJWWSzuWVrQRtaDNPHYyje0YbkIJyeB0DNXmsHkgkcQhXEOq3Mo/jyelM3Gwashr8bKF3DUTo1jq+QEbtnAJ01VklerV71acJhDvDy7a/Ire8LPupCxJia7la3+S9IN8ZGoTIvoRHTyek2iSGphT1pDOi/CDJt7lme8U5szvXIZQNUyJQ0o071z+guAhUzAl1uYzMbs5TORkCbw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=T1bb0XTc3eHB9TaU/o5/wnJRnLYt5yXAz2mfRftNqPk=; b=SH5E9mnI9UFqO/gUOeqFccVa5MYZdZsvoeyx68oFPHzx3hPsNVbSgm9Rh0xvUBc3Y2BlVvygdWv1haxHsNTj+TY77T6AJnfyqKjAeQADPPtP4bn59/aq76NOgrPOqOgNASnEzJEpRGcsQNg612h1i32PshXf4qIM/gTJXU7V5V8= Authentication-Results: lists.freedesktop.org; dkim=none (message not signed) header.d=none;lists.freedesktop.org; dmarc=none action=none header.from=oracle.com; From: Dongli Zhang To: dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, iommu@lists.linux-foundation.org, linux-mips@vger.kernel.org, linux-mmc@vger.kernel.org, linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, nouveau@lists.freedesktop.org, x86@kernel.org, xen-devel@lists.xenproject.org Cc: linux-kernel@vger.kernel.org, adrian.hunter@intel.com, akpm@linux-foundation.org, benh@kernel.crashing.org, bskeggs@redhat.com, bhelgaas@google.com, bp@alien8.de, boris.ostrovsky@oracle.com, hch@lst.de, chris@chris-wilson.co.uk, daniel@ffwll.ch, airlied@linux.ie, hpa@zytor.com, mingo@kernel.org, mingo@redhat.com, jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com, jgross@suse.com, konrad.wilk@oracle.com, m.szyprowski@samsung.com, matthew.auld@intel.com, mpe@ellerman.id.au, rppt@kernel.org, paulus@samba.org, peterz@infradead.org, robin.murphy@arm.com, rodrigo.vivi@intel.com, sstabellini@kernel.org, bauerman@linux.ibm.com, tsbogend@alpha.franken.de, tglx@linutronix.de, ulf.hansson@linaro.org, joe.jin@oracle.com, thomas.lendacky@amd.com Subject: [PATCH RFC v1 6/6] xen-swiotlb: enable 64-bit xen-swiotlb Date: Wed, 3 Feb 2021 15:37:09 -0800 Message-Id: <20210203233709.19819-7-dongli.zhang@oracle.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210203233709.19819-1-dongli.zhang@oracle.com> References: <20210203233709.19819-1-dongli.zhang@oracle.com> X-Originating-IP: [138.3.200.16] X-ClientProxiedBy: CH0PR03CA0008.namprd03.prod.outlook.com (2603:10b6:610:b0::13) To BYAPR10MB2663.namprd10.prod.outlook.com (2603:10b6:a02:a9::20) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1a6f39ca-831d-4584-1671-08d8c89cc4a6 X-MS-TrafficTypeDiagnostic: SJ0PR10MB4784: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:136; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: g1MdwF09ZQsQBk3V9QOQLj3Q2J4L21DedJnj5zLtjikYKElnwxG4upLd7TjhmJPnAU7VpjSHxPeJkqoPBRqm6qLeK0CHlFugspJnxi0iJI55XYooo19FwHgiOqBWBro0DzURhQTcUKHg2pt6GcgakcdWtajKr7YhF2oMlQ9TwO3PVCjJBIHzVB9ARp0nbm7zuhWes6OM0DRHYiZShiKkwZu7s9DdAyEDvWn/Gl0ZL4waWfYydjw/WkEc5/ennCc9OVPn+TREYJxjo1DWlOpdvMoTMaiSx8AjE+9jEXwuXzWLjL3qbTLDi6ktPwxxXGQs8U3Irr5/M7ar7bmutYlTQ2ed6ghggKY+GkYuKZFNMtieoWviD0NZJ01fhMAb5gbdJWAM4p1gONjFeoyWColerWY0LMjTOXUAp3dPN8tNJCXJ//c8+I3jztzLAk5mNt4e8uVOFDvvw+5Ri8EtVZZgmhOTrLSuo/OqSS6VgrbK7WOcJCGAIwNtW19s81SglVsppCFxB/JYDVlfn/XzOiteTG9HHCwH7jJTeIGHi0vZYowFiLlsq0xIt5bSbDcpMaMnWCnR5Cj//oWPXtmR2wvTgnI8gqLb36wjoJGn9DZCM2o= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB2663.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(366004)(39860400002)(396003)(376002)(346002)(83380400001)(316002)(5660300002)(956004)(66946007)(6506007)(86362001)(7406005)(1076003)(66476007)(8676002)(186003)(26005)(36756003)(7416002)(478600001)(2906002)(66556008)(8936002)(6486002)(16526019)(69590400011)(4326008)(6512007)(44832011)(921005)(2616005)(52116002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?v4+k5MesDHa1MVSGi/UHPtmaF26L/lVN8GcJ71CBITc1I1MM0IDFIyBYytE4?= =?us-ascii?Q?53IGo7YT2EKkghBW/3Sk9E+bozL8K8Q/9nt64yNP1VUKTKWcNXGh0x3n6L54?= =?us-ascii?Q?xVW44nCRVbatRJqN678ro8ZSzYt+2fRymUty+3o8u/17/PwxyEk9Ady2ePJu?= =?us-ascii?Q?MOCoTjqlbeIOOmbEC/N28xw5dHvOPOovzSUgb9BAxSKqZmaCGbKEKN2DT/bR?= =?us-ascii?Q?zqtS1Di8iAHNISKyT5Kia3S5FQ31jIr8lU9eM3naCerZx5CWbllDRJPUggXy?= =?us-ascii?Q?PDUKaAxh4cXAaHrxbUuSXPbWSf2dHDC/0daQlqTmIDOHhAzikT+ON4WOwr19?= =?us-ascii?Q?NAfx9YwHYZjSnq7QmKuypvDXn/4sFWZ036E16UhM22ZhF3yCJSsT3DjLdG8U?= =?us-ascii?Q?tOX4toyIsdgCmi7p5QlaizYNgW+RH61ZTyCbLfrdr/vqHzBb7i9rreaXl+1c?= =?us-ascii?Q?guCiLvEr5Go5xNdVG4uR7NyDFOlzkkVsbMfELRCU0p1mRPrIQdx6GL7zHrWH?= =?us-ascii?Q?LhATraTb6GMS48zXasH4Dla6lHfNT/es/ZkxUzm5az8Zdjsb76SNDY6Qy0U9?= =?us-ascii?Q?dVdWc5Wr/3tykSq/9BWFCam6QyHfXpzywRf5L/GutdWeL2qGZqKhTaUTXeGH?= =?us-ascii?Q?EGF9kybhdDX9WoEPRubZZkhbyNiMckO0VrgM333uXg5hUIhn8B+PqVQen7cM?= =?us-ascii?Q?0Yf1gM25kWnPI3xofo9GasPaYo/sS+suvzIvlhb2ApKpM6Rc4MCuXBM8KsXR?= =?us-ascii?Q?BMlDEGL0r32OC2U3k4ymsoa2g5qKu7wKo3KGE6iz6Ya8AkYKuoW4nUzA9F4P?= =?us-ascii?Q?aSeXvt2DyQABYPMdHHv0KPr9+b4R5tmZoteVrUkzO/IDIxlQAXE/0MOQs2aR?= =?us-ascii?Q?jwCOMJIruq+MmWnpzVoZ5Wkmc8RWspNBAP+lJpmBZcIUeuUp0Z8vKzuqSteA?= =?us-ascii?Q?2Cp+CP+6w/Vxi22Q1FuM16M5VQ0xW2fIukRt0PSMYAsj9qZln0bvBSCk4r32?= =?us-ascii?Q?Tzd2Gh0o0RoulKFMNHy6Y2VjnRy43NW+4INplMPcCZXk7WjQgKv7YOEj3syO?= =?us-ascii?Q?x9uYpUo5?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1a6f39ca-831d-4584-1671-08d8c89cc4a6 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2663.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2021 23:38:11.4626 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: r1RSaXkF0zyFxShGIWuzhyAUNVmLQ3O5X3zrZzuMcrJieYM/HHT4wwktIQz2k01o9UKkfGFBJpMRNiO3jThp5g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4784 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9884 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 spamscore=0 phishscore=0 suspectscore=0 mlxlogscore=999 bulkscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102030143 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9884 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxlogscore=999 mlxscore=0 priorityscore=1501 spamscore=0 impostorscore=0 clxscore=1015 suspectscore=0 lowpriorityscore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102030143 X-ZohoMail-DKIM: pass (identity @oracle.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch is to enable the 64-bit xen-swiotlb buffer. For Xen PVM DMA address, the 64-bit device will be able to allocate from 64-bit swiotlb buffer. Cc: Joe Jin Signed-off-by: Dongli Zhang --- drivers/xen/swiotlb-xen.c | 117 ++++++++++++++++++++++++-------------- 1 file changed, 74 insertions(+), 43 deletions(-) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index e18cae693cdc..c9ab07809e32 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -108,27 +108,36 @@ static int is_xen_swiotlb_buffer(struct device *dev, = dma_addr_t dma_addr) unsigned long bfn =3D XEN_PFN_DOWN(dma_to_phys(dev, dma_addr)); unsigned long xen_pfn =3D bfn_to_local_pfn(bfn); phys_addr_t paddr =3D (phys_addr_t)xen_pfn << XEN_PAGE_SHIFT; + int i; =20 /* If the address is outside our domain, it CAN * have the same virtual address as another address * in our domain. Therefore _only_ check address within our domain. */ - if (pfn_valid(PFN_DOWN(paddr))) { - return paddr >=3D virt_to_phys(xen_io_tlb_start[SWIOTLB_LO]) && - paddr < virt_to_phys(xen_io_tlb_end[SWIOTLB_LO]); - } + if (!pfn_valid(PFN_DOWN(paddr))) + return 0; + + for (i =3D 0; i < swiotlb_nr; i++) + if (paddr >=3D virt_to_phys(xen_io_tlb_start[i]) && + paddr < virt_to_phys(xen_io_tlb_end[i])) + return 1; + return 0; } =20 static int -xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs) +xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs, + enum swiotlb_t type) { int i, rc; int dma_bits; dma_addr_t dma_handle; phys_addr_t p =3D virt_to_phys(buf); =20 - dma_bits =3D get_order(IO_TLB_SEGSIZE << IO_TLB_SHIFT) + PAGE_SHIFT; + if (type =3D=3D SWIOTLB_HI) + dma_bits =3D max_dma_bits[SWIOTLB_HI]; + else + dma_bits =3D get_order(IO_TLB_SEGSIZE << IO_TLB_SHIFT) + PAGE_SHIFT; =20 i =3D 0; do { @@ -139,7 +148,7 @@ xen_swiotlb_fixup(void *buf, size_t size, unsigned long= nslabs) p + (i << IO_TLB_SHIFT), get_order(slabs << IO_TLB_SHIFT), dma_bits, &dma_handle); - } while (rc && dma_bits++ < max_dma_bits[SWIOTLB_LO]); + } while (rc && dma_bits++ < max_dma_bits[type]); if (rc) return rc; =20 @@ -147,16 +156,17 @@ xen_swiotlb_fixup(void *buf, size_t size, unsigned lo= ng nslabs) } while (i < nslabs); return 0; } -static unsigned long xen_set_nslabs(unsigned long nr_tbl) + +static unsigned long xen_set_nslabs(unsigned long nr_tbl, enum swiotlb_t t= ype) { if (!nr_tbl) { - xen_io_tlb_nslabs[SWIOTLB_LO] =3D (64 * 1024 * 1024 >> IO_TLB_SHIFT); - xen_io_tlb_nslabs[SWIOTLB_LO] =3D ALIGN(xen_io_tlb_nslabs[SWIOTLB_LO], + xen_io_tlb_nslabs[type] =3D (64 * 1024 * 1024 >> IO_TLB_SHIFT); + xen_io_tlb_nslabs[type] =3D ALIGN(xen_io_tlb_nslabs[type], IO_TLB_SEGSIZE); } else - xen_io_tlb_nslabs[SWIOTLB_LO] =3D nr_tbl; + xen_io_tlb_nslabs[type] =3D nr_tbl; =20 - return xen_io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT; + return xen_io_tlb_nslabs[type] << IO_TLB_SHIFT; } =20 enum xen_swiotlb_err { @@ -180,23 +190,24 @@ static const char *xen_swiotlb_error(enum xen_swiotlb= _err err) } return ""; } -int __ref xen_swiotlb_init(int verbose, bool early) + +static int xen_swiotlb_init_type(int verbose, bool early, enum swiotlb_t t= ype) { unsigned long bytes, order; int rc =3D -ENOMEM; enum xen_swiotlb_err m_ret =3D XEN_SWIOTLB_UNKNOWN; unsigned int repeat =3D 3; =20 - xen_io_tlb_nslabs[SWIOTLB_LO] =3D swiotlb_nr_tbl(SWIOTLB_LO); + xen_io_tlb_nslabs[type] =3D swiotlb_nr_tbl(type); retry: - bytes =3D xen_set_nslabs(xen_io_tlb_nslabs[SWIOTLB_LO]); - order =3D get_order(xen_io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT); + bytes =3D xen_set_nslabs(xen_io_tlb_nslabs[type], type); + order =3D get_order(xen_io_tlb_nslabs[type] << IO_TLB_SHIFT); =20 /* * IO TLB memory already allocated. Just use it. */ - if (io_tlb_start[SWIOTLB_LO] !=3D 0) { - xen_io_tlb_start[SWIOTLB_LO] =3D phys_to_virt(io_tlb_start[SWIOTLB_LO]); + if (io_tlb_start[type] !=3D 0) { + xen_io_tlb_start[type] =3D phys_to_virt(io_tlb_start[type]); goto end; } =20 @@ -204,81 +215,95 @@ int __ref xen_swiotlb_init(int verbose, bool early) * Get IO TLB memory from any location. */ if (early) { - xen_io_tlb_start[SWIOTLB_LO] =3D memblock_alloc(PAGE_ALIGN(bytes), + xen_io_tlb_start[type] =3D memblock_alloc(PAGE_ALIGN(bytes), PAGE_SIZE); - if (!xen_io_tlb_start[SWIOTLB_LO]) + if (!xen_io_tlb_start[type]) panic("%s: Failed to allocate %lu bytes align=3D0x%lx\n", __func__, PAGE_ALIGN(bytes), PAGE_SIZE); } else { #define SLABS_PER_PAGE (1 << (PAGE_SHIFT - IO_TLB_SHIFT)) #define IO_TLB_MIN_SLABS ((1<<20) >> IO_TLB_SHIFT) while ((SLABS_PER_PAGE << order) > IO_TLB_MIN_SLABS) { - xen_io_tlb_start[SWIOTLB_LO] =3D (void *)xen_get_swiotlb_free_pages(ord= er); - if (xen_io_tlb_start[SWIOTLB_LO]) + xen_io_tlb_start[type] =3D (void *)xen_get_swiotlb_free_pages(order); + if (xen_io_tlb_start[type]) break; order--; } if (order !=3D get_order(bytes)) { pr_warn("Warning: only able to allocate %ld MB for software IO TLB\n", (PAGE_SIZE << order) >> 20); - xen_io_tlb_nslabs[SWIOTLB_LO] =3D SLABS_PER_PAGE << order; - bytes =3D xen_io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT; + xen_io_tlb_nslabs[type] =3D SLABS_PER_PAGE << order; + bytes =3D xen_io_tlb_nslabs[type] << IO_TLB_SHIFT; } } - if (!xen_io_tlb_start[SWIOTLB_LO]) { + if (!xen_io_tlb_start[type]) { m_ret =3D XEN_SWIOTLB_ENOMEM; goto error; } /* * And replace that memory with pages under 4GB. */ - rc =3D xen_swiotlb_fixup(xen_io_tlb_start[SWIOTLB_LO], + rc =3D xen_swiotlb_fixup(xen_io_tlb_start[type], bytes, - xen_io_tlb_nslabs[SWIOTLB_LO]); + xen_io_tlb_nslabs[type], + type); if (rc) { if (early) - memblock_free(__pa(xen_io_tlb_start[SWIOTLB_LO]), + memblock_free(__pa(xen_io_tlb_start[type]), PAGE_ALIGN(bytes)); else { - free_pages((unsigned long)xen_io_tlb_start[SWIOTLB_LO], order); - xen_io_tlb_start[SWIOTLB_LO] =3D NULL; + free_pages((unsigned long)xen_io_tlb_start[type], order); + xen_io_tlb_start[type] =3D NULL; } m_ret =3D XEN_SWIOTLB_EFIXUP; goto error; } if (early) { - if (swiotlb_init_with_tbl(xen_io_tlb_start[SWIOTLB_LO], - xen_io_tlb_nslabs[SWIOTLB_LO], - SWIOTLB_LO, verbose)) + if (swiotlb_init_with_tbl(xen_io_tlb_start[type], + xen_io_tlb_nslabs[type], + type, verbose)) panic("Cannot allocate SWIOTLB buffer"); rc =3D 0; } else - rc =3D swiotlb_late_init_with_tbl(xen_io_tlb_start[SWIOTLB_LO], - xen_io_tlb_nslabs[SWIOTLB_LO], - SWIOTLB_LO); + rc =3D swiotlb_late_init_with_tbl(xen_io_tlb_start[type], + xen_io_tlb_nslabs[type], + type); =20 end: - xen_io_tlb_end[SWIOTLB_LO] =3D xen_io_tlb_start[SWIOTLB_LO] + bytes; + xen_io_tlb_end[type] =3D xen_io_tlb_start[type] + bytes; if (!rc) - swiotlb_set_max_segment(PAGE_SIZE, SWIOTLB_LO); + swiotlb_set_max_segment(PAGE_SIZE, type); =20 return rc; error: if (repeat--) { - xen_io_tlb_nslabs[SWIOTLB_LO] =3D max(1024UL, /* Min is 2MB */ - (xen_io_tlb_nslabs[SWIOTLB_LO] >> 1)); + xen_io_tlb_nslabs[type] =3D max(1024UL, /* Min is 2MB */ + (xen_io_tlb_nslabs[type] >> 1)); pr_info("Lowering to %luMB\n", - (xen_io_tlb_nslabs[SWIOTLB_LO] << IO_TLB_SHIFT) >> 20); + (xen_io_tlb_nslabs[type] << IO_TLB_SHIFT) >> 20); goto retry; } pr_err("%s (rc:%d)\n", xen_swiotlb_error(m_ret), rc); if (early) panic("%s (rc:%d)", xen_swiotlb_error(m_ret), rc); else - free_pages((unsigned long)xen_io_tlb_start[SWIOTLB_LO], order); + free_pages((unsigned long)xen_io_tlb_start[type], order); return rc; } =20 +int __ref xen_swiotlb_init(int verbose, bool early) +{ + int i, rc; + + for (i =3D 0; i < swiotlb_nr; i++) { + rc =3D xen_swiotlb_init_type(verbose, early, i); + if (rc) + return rc; + } + + return 0; +} + static void * xen_swiotlb_alloc_coherent(struct device *hwdev, size_t size, dma_addr_t *dma_handle, gfp_t flags, @@ -566,7 +591,13 @@ xen_swiotlb_sync_sg_for_device(struct device *dev, str= uct scatterlist *sgl, static int xen_swiotlb_dma_supported(struct device *hwdev, u64 mask) { - return xen_virt_to_bus(hwdev, xen_io_tlb_end[SWIOTLB_LO] - 1) <=3D mask; + int i; + + for (i =3D 0; i < swiotlb_nr; i++) + if (xen_virt_to_bus(hwdev, xen_io_tlb_end[i] - 1) <=3D mask) + return true; + + return false; } =20 const struct dma_map_ops xen_swiotlb_dma_ops =3D { --=20 2.17.1